Detail.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\controller\merchant;
  3. use app\extra\basic\Base;
  4. use app\extra\weMini\Link;
  5. use app\middleware\AuthMiddleware;
  6. use app\model\saas\SaasShop;
  7. use DI\Attribute\Inject;
  8. use LinFly\Annotation\Route\Controller;
  9. use LinFly\Annotation\Route\Middleware;
  10. use LinFly\Annotation\Route\Route;
  11. use support\Request;
  12. use support\Response;
  13. #[Controller(prefix: "/api/mer/shop"),Middleware(AuthMiddleware::class)]
  14. class Detail extends Base
  15. {
  16. #[Inject]
  17. protected SaasShop $model;
  18. #[Route(path: "detail",methods: "get")]
  19. public function getDetail(Request $request): Response
  20. {
  21. try {
  22. $qrcodePath = "/uploads/card/{$request->user['agent_id']}-pay.jpg";
  23. if (!is_file(public_path().$qrcodePath)) {
  24. (new Link([
  25. "appid" => sConf("wechat.mini_appid"),
  26. "appsecret" => sConf("wechat.mini_secret")
  27. ]))->createQrcodeWx("/pages/shop/pay","shop={$request->user['agent_id']}",$qrcodePath);
  28. }
  29. $qrcode = 'data:image/png;base64,'.base64_encode(file_get_contents(public_path().$qrcodePath));
  30. $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) {
  31. return date("Y-m-d",strtotime($data['vip_end']));
  32. },'qrcode' => function () use ($qrcode){
  33. return $qrcode;
  34. }])->findOrEmpty();
  35. if ($shop->isEmpty()) return errorTrans("empty.data");
  36. return success("ok",$shop->toArray());
  37. } catch (\Throwable $throwable) {
  38. return error($throwable->getMessage());
  39. }
  40. }
  41. #[Route(path: "save",methods: "post")]
  42. public function setData(Request $request)
  43. {
  44. try {
  45. $param = $request->post();
  46. $shop = $this->model->where("shop_id",$request->user['agent_id'])->findOrEmpty();
  47. if ($shop->isEmpty()) return errorTrans("empty.data");
  48. $state = $shop->save($param);
  49. if (!$state) return errorTrans("error.data");
  50. return successTrans("success.data");
  51. } catch (\Throwable $throwable) {
  52. return error($throwable->getMessage());
  53. }
  54. }
  55. }