| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace app\controller\merchant;
- use app\extra\basic\Base;
- use app\extra\weMini\Link;
- use app\middleware\AuthMiddleware;
- use app\model\saas\SaasShop;
- use DI\Attribute\Inject;
- use LinFly\Annotation\Route\Controller;
- use LinFly\Annotation\Route\Middleware;
- use LinFly\Annotation\Route\Route;
- use support\Request;
- use support\Response;
- #[Controller(prefix: "/api/mer/shop"),Middleware(AuthMiddleware::class)]
- class Detail extends Base
- {
- #[Inject]
- protected SaasShop $model;
- #[Route(path: "detail",methods: "get")]
- public function getDetail(Request $request): Response
- {
- try {
- $qrcodePath = "/uploads/card/{$request->user['agent_id']}-pay.jpg";
- if (!is_file(public_path().$qrcodePath)) {
- (new Link([
- "appid" => sConf("wechat.mini_appid"),
- "appsecret" => sConf("wechat.mini_secret")
- ]))->createQrcodeWx("/pages/shop/pay","shop={$request->user['agent_id']}",$qrcodePath);
- }
- $qrcode = 'data:image/png;base64,'.base64_encode(file_get_contents(public_path().$qrcodePath));
- $shop = $this->model->where("shop_id",$request->user['agent_id'])->field("shop_name,shop_mobile,start_at,end_at,vip_end,shop_status,shop_notice,line_time,status,shop_address")->withAttr(['vip_end' => function($query,$data) {
- return date("Y-m-d",strtotime($data['vip_end']));
- },'qrcode' => function () use ($qrcode){
- return $qrcode;
- }])->findOrEmpty();
- if ($shop->isEmpty()) return errorTrans("empty.data");
- return success("ok",$shop->toArray());
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- #[Route(path: "save",methods: "post")]
- public function setData(Request $request)
- {
- try {
- $param = $request->post();
- $shop = $this->model->where("shop_id",$request->user['agent_id'])->findOrEmpty();
- if ($shop->isEmpty()) return errorTrans("empty.data");
- $state = $shop->save($param);
- if (!$state) return errorTrans("error.data");
- return successTrans("success.data");
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- }
|