Renew.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace app\controller\merchant;
  3. use app\extra\basic\Base;
  4. use app\extra\service\saas\ComboLogService;
  5. use app\extra\tools\CodeExtend;
  6. use app\extra\weMini\Link;
  7. use app\middleware\AuthMiddleware;
  8. use app\model\saas\SaasCombo;
  9. use app\model\saas\SaasComboLog;
  10. use app\model\saas\SaasShop;
  11. use DI\Attribute\Inject;
  12. use LinFly\Annotation\Route\Controller;
  13. use LinFly\Annotation\Route\Middleware;
  14. use LinFly\Annotation\Route\Route;
  15. use support\Request;
  16. use support\Response;
  17. #[Controller(prefix: "/api/mer/renew"),Middleware(AuthMiddleware::class)]
  18. class Renew extends Base
  19. {
  20. #[Inject]
  21. protected ComboLogService $service;
  22. /**
  23. *
  24. * @param Request $request
  25. * @return Response
  26. */
  27. #[Route(path: "detail",methods: "get")]
  28. public function getRenewDetail(Request $request): Response
  29. {
  30. try {
  31. $shop = (new SaasShop)->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) {
  32. return date("Y-m-d",strtotime($data['vip_end']));
  33. }])->findOrEmpty();
  34. if ($shop->isEmpty()) return errorTrans("empty.data");
  35. $combo = (new SaasCombo)->where("status",1)->order("sort",'desc')->field("ROUND(money/100,2) as f_money,ROUND(old_money/100,2) as f_old_money,id,unit,time,name")
  36. ->append(['diff'])
  37. ->withAttr(['diff' => function($query,$data){
  38. return $data['f_old_money'] - $data['f_money'];
  39. }])->select();
  40. $privacy = htmlspecialchars_decode(sConf("service.privacy"));
  41. return success('ok',compact("shop",'combo','privacy'));
  42. } catch (\Throwable $throwable) {
  43. return error($throwable->getMessage());
  44. }
  45. }
  46. /**
  47. * @param Request $request
  48. * @return Response
  49. */
  50. #[Route(path: "qrcode",methods: "post")]
  51. public function getPayQrcode(Request $request)
  52. {
  53. try {
  54. $param = $this->_valid([
  55. "comboId.require" => trans("empty.require")
  56. ],"post");
  57. if (!is_array($param)) return error($param);
  58. $combo = (new SaasCombo)->where("id",$param['comboId'])->where("status",1)->findOrEmpty();
  59. if ($combo->isEmpty()) return errorTrans("empty.data");
  60. $orderSn = CodeExtend::createNoncestr();
  61. $state = (new SaasComboLog)->insertGetId([
  62. "shop_id" => $request->user['agent_id'],
  63. "order_sn" => $orderSn,
  64. "time" => $combo['unit']==1?$combo['time']:($combo['time']*365),
  65. "money" => $combo['money']
  66. ]);
  67. if (!$state) return errorTrans("error.data");
  68. // 生成二维码
  69. $qrcodePath = "/uploads/card/{$request->user['agent_id']}-renew-{$orderSn}.jpg";
  70. (new Link([
  71. "appid" => sConf("wechat.mini_appid"),
  72. "appsecret" => sConf("wechat.mini_secret")
  73. ]))->createQrcodeWx("/pages/shop/renew","shop={$request->user['agent_id']}&order={$orderSn}",$qrcodePath);
  74. $qrcode = 'data:image/png;base64,'.base64_encode(file_get_contents(public_path().$qrcodePath));
  75. return successTrans("success.data",compact("qrcode"));
  76. } catch (\Throwable $throwable) {
  77. return error($throwable->getMessage());
  78. }
  79. }
  80. #[Route(path: "list",methods: "get")]
  81. public function getRenewList(Request $request)
  82. {
  83. try {
  84. $param = $request->get();
  85. $param['shop'] = $request->user['agent_id'];
  86. $list = $this->service->getList($param);
  87. return successTrans("success.data",pageFormat($list),200);
  88. } catch (\Throwable $throwable) {
  89. return error($throwable->getMessage());
  90. }
  91. }
  92. }