| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace app\controller\merchant;
- use app\extra\basic\Base;
- use app\extra\service\saas\ComboLogService;
- use app\extra\tools\CodeExtend;
- use app\extra\weMini\Link;
- use app\middleware\AuthMiddleware;
- use app\model\saas\SaasCombo;
- use app\model\saas\SaasComboLog;
- 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/renew"),Middleware(AuthMiddleware::class)]
- class Renew extends Base
- {
- #[Inject]
- protected ComboLogService $service;
- /**
- *
- * @param Request $request
- * @return Response
- */
- #[Route(path: "detail",methods: "get")]
- public function getRenewDetail(Request $request): Response
- {
- try {
- $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) {
- return date("Y-m-d",strtotime($data['vip_end']));
- }])->findOrEmpty();
- if ($shop->isEmpty()) return errorTrans("empty.data");
- $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")
- ->append(['diff'])
- ->withAttr(['diff' => function($query,$data){
- return $data['f_old_money'] - $data['f_money'];
- }])->select();
- $privacy = htmlspecialchars_decode(sConf("service.privacy"));
- print_r($privacy);
- return success('ok',compact("shop",'combo','privacy'));
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- /**
- * @param Request $request
- * @return Response
- */
- #[Route(path: "qrcode",methods: "post")]
- public function getPayQrcode(Request $request)
- {
- try {
- $param = $this->_valid([
- "comboId.require" => trans("empty.require")
- ],"post");
- if (!is_array($param)) return error($param);
- $combo = (new SaasCombo)->where("id",$param['comboId'])->where("status",1)->findOrEmpty();
- if ($combo->isEmpty()) return errorTrans("empty.data");
- $orderSn = CodeExtend::createNoncestr();
- $state = (new SaasComboLog)->insertGetId([
- "shop_id" => $request->user['agent_id'],
- "order_sn" => $orderSn,
- "time" => $combo['unit']==1?$combo['time']:($combo['time']*365),
- "money" => $combo['money']
- ]);
- if (!$state) return errorTrans("error.data");
- // 生成二维码
- $qrcodePath = "/uploads/card/{$request->user['agent_id']}-renew-{$orderSn}.jpg";
- (new Link([
- "appid" => sConf("wechat.mini_appid"),
- "appsecret" => sConf("wechat.mini_secret")
- ]))->createQrcodeWx("/pages/shop/renew","shop={$request->user['agent_id']}&order={$orderSn}",$qrcodePath);
- $qrcode = 'data:image/png;base64,'.base64_encode(file_get_contents(public_path().$qrcodePath));
- return successTrans("success.data",compact("qrcode"));
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- #[Route(path: "list",methods: "get")]
- public function getRenewList(Request $request)
- {
- try {
- $param = $request->get();
- $param['shop'] = $request->user['agent_id'];
- $list = $this->service->getList($param);
- return successTrans("success.data",pageFormat($list),200);
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- }
|