APPLE 3 лет назад
Родитель
Сommit
a3364987d3
36 измененных файлов с 2122 добавлено и 3338 удалено
  1. 189 198
      app/api/controller/v1/Box.php
  2. 8 1
      app/api/controller/v1/Fragment.php
  3. 499 804
      app/api/controller/v1/Pay.php
  4. 38 172
      app/api/controller/v1/ShopOrder.php
  5. 163 2
      app/api/controller/v1/Test.php
  6. 0 19
      app/api/controller/v1/User.php
  7. 13 6
      app/api/middleware/AuthSignMiddleWare.php
  8. 13 7
      app/api/middleware/AuthTokenMiddleWare.php
  9. 1 19
      app/api/services/AliPayServices.php
  10. 17 14
      app/api/services/BalancePayServices.php
  11. 5 88
      app/api/services/BasePayServices.php
  12. 11 0
      app/api/services/BaseServices.php
  13. 912 1715
      app/api/services/ThirdPayServices.php
  14. 0 8
      app/api/services/UserAuthServices.php
  15. 6 1
      app/api/services/WxPayServices.php
  16. 0 4
      app/common/model/MoneyLogModel.php
  17. 0 16
      app/common/model/ShopCategory.php
  18. 1 16
      app/common/model/ShopGoodsSpecType.php
  19. 0 15
      app/common/model/ShopGoodsTypeModel.php
  20. 2 14
      app/common/model/ShopHotKeywords.php
  21. 10 38
      app/common/model/ShopOrderModel.php
  22. 1 17
      app/common/model/ShopSupplier.php
  23. 1 21
      app/common/model/SystemFaq.php
  24. 42 6
      app/common/model/UserAddressModel.php
  25. 0 10
      app/common/service/AddressService.php
  26. 0 11
      app/common/service/ArticleService.php
  27. 1 11
      app/common/service/AuthService.php
  28. 0 10
      app/common/service/ExpressDeliveryService.php
  29. 0 10
      app/common/service/LevelSettingService.php
  30. 31 12
      app/common/service/MenuService.php
  31. 0 10
      app/common/service/ShopGoodsMenuService.php
  32. 36 14
      app/common/service/ShopGoodsService.php
  33. 0 10
      app/common/service/ShopGoodsSpecRelationService.php
  34. 54 10
      app/common/service/ShopGoodsSpecService.php
  35. 42 16
      app/common/service/SystemConfigService.php
  36. 26 13
      extend/utils/AliPay.php

+ 189 - 198
app/api/controller/v1/Box.php

@@ -17,6 +17,7 @@ use app\common\model\ShopGoodsModel;
 use app\common\model\ShopOrderModel;
 use app\common\model\UserAddressModel;
 use app\common\model\UserModel;
+use app\common\service\SystemConfigService;
 use think\db\Where;
 use think\exception\InvalidArgumentException;
 use think\cache\driver\Redis;
@@ -27,7 +28,7 @@ use utils\RedisCache;
 
 class Box
 {
-    protected  $model = null;
+    protected $model = null;
 
     public function __construct(ChatMessageModel $model)
     {
@@ -36,31 +37,31 @@ class Box
 
 
     // 跑马灯效果
-    public function boxDownMessageList(Request $request){
+    public function boxDownMessageList(Request $request)
+    {
         $messages = [];
         $boxs = [
-            10=>'普通',
-            20=>'稀有',
-            30=>'史诗',
-            40=>'传说',
+            10 => '普通',
+            20 => '稀有',
+            30 => '史诗',
+            40 => '传说',
         ];
         $list = Db::name('box_mid_handle')
             ->alias('m')
             ->where('m.box_type', '>', 10)
             ->leftJoin('user u', 'u.id = m.uid')
             ->limit(20)
-            ->withAttr('box_type', function ($val, $data) use ($boxs, &$messages){
+            ->withAttr('box_type', function ($val, $data) use ($boxs, &$messages) {
 //                $mobile = v;
-                $mobile = '****'.substr($data['mobile'], 7);
-                $messages[] = '恭喜'.$mobile.'拆出'.$boxs[$data['box_type']].'福袋';
+                $mobile = '****' . substr($data['mobile'], 7);
+                $messages[] = '恭喜' . $mobile . '拆出' . $boxs[$data['box_type']] . '福袋';
 
             })
             ->orderRaw("rand() , m.id DESC")
             ->field('m.uid,u.mobile,u.nickname,m.box_type')
             ->select()->toArray();
 
-        return api_succ_return(['msg'=>'成功', 'data'=>$messages]);
-
+        return api_succ_return(['msg' => '成功', 'data' => $messages]);
 
 
 //        return api_succ_return(['msg'=>'请求成功', 'data'=>[
@@ -74,22 +75,27 @@ class Box
     }
 
     // 福袋  泡泡商品
-    public function boxRandGoodsList(){
+    public function boxRandGoodsList()
+    {
 
         $list = Db::name('shop_goods')->where('on_sale', 1)->limit(12)->orderRaw("rand() , goods_id DESC")->field('goods_id,box_pic,goods_sn')->select()->toArray();
-        return api_succ_return(['msg'=>'成功', 'data'=>$list]);
+        return api_succ_return(['msg' => '成功', 'data' => $list]);
     }
 
 
-    // 当前最新一期福袋预约信息
-    public function getNewBoxInfo(){
-        
-    
-        //$id = Db::name('box')->where(['status'=>1])->max('id');
-        $id = Db::name('box')->where(['status'=>1,'open_status'=>1])->max('id');
+    /**
+     * 当前最新一期福袋预约信息
+     * @return \think\Response
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getNewBoxInfo()
+    {
+        $id = Db::name('box')->where(['status' => 1, 'open_status' => 1])->max('id');
 
-        if (empty($id)){
-            return api_error_return(['msg'=>'暂未开启', 'code'=>303]);
+        if (empty($id)) {
+            return api_error_return(['msg' => '暂未开启', 'code' => 303]);
         }
 
         $info = Db::name('box')->where('id', $id)->find();
@@ -97,55 +103,40 @@ class Box
         $time = sr_getcurtime($cur_time, 'Y-m-d ');
         $times = explode('|', $info['time_set']);
         $appoint_status = 1;
-//        1 还未开始   2 进行中   3已结束
+        // 1 还未开始   2 进行中   3已结束
         $dis_time = 0;
 
-        $cur_times = [];
-
-        // 当前时间小于 第一场 开始时间
-//        if ($appoint_status != 1){
-//            $begin_times = explode('-', $times[0]);
-//            $begin_randtime = strtotime($time . $begin_times[0]);
-//            if ($cur_time  < $begin_randtime){
-//                $appoint_status = 1;
-//                $dis_time = $begin_randtime-$cur_time;
-//                return 33;
-//            }
-//        }
-
         // 当前时间大于 最后一场结束时间
-        if ($appoint_status != 3){
-            $end_timesarr = explode('-', $times[count($times)-1]);
+        if ($appoint_status != 3) {
+            $end_timesarr = explode('-', $times[count($times) - 1]);
             $end_randtime = strtotime($time . $end_timesarr[1]);
-            if ($cur_time  > $end_randtime){
+            if ($cur_time > $end_randtime) {
                 $appoint_status = 3;
             }
         }
 
 
         // 是否拿到最近的一场未开始距离时间
-
-        if ($appoint_status != 3){
-            foreach ($times as $key=>$val){
+        if ($appoint_status != 3) {
+            foreach ($times as $key => $val) {
                 $time_cur = explode('-', $val);
-                $time_randbegin = strtotime($time.$time_cur[0]);
-                $time_randend = strtotime($time.$time_cur[1]);
+                $time_randbegin = strtotime($time . $time_cur[0]);
+                $time_randend = strtotime($time . $time_cur[1]);
 
-                if ($cur_time > $time_randbegin && $cur_time < $time_randend){
+                if ($cur_time > $time_randbegin && $cur_time < $time_randend) {
                     // 正在这一场进行中
                     $appoint_status = 2;
                 }
             }
 
 
-            if ($appoint_status!= 2){
+            if ($appoint_status != 2) {
                 $has_get = false;
-                foreach ($times as $key=>$val){
+                foreach ($times as $key => $val) {
                     $time_cur = explode('-', $val);
-                    $time_randbegin = strtotime($time.$time_cur[0]);
-                    $time_randend = strtotime($time.$time_cur[1]);
+                    $time_randbegin = strtotime($time . $time_cur[0]);
 
-                    if ($cur_time < $time_randbegin && !$has_get){
+                    if ($cur_time < $time_randbegin && !$has_get) {
                         // 正在这一场进行中
                         $has_get = true;
                         $dis_time = $time_randbegin - $cur_time;
@@ -154,44 +145,43 @@ class Box
             }
 
 
-
-
-
         }
 
 
-
-        $info['appoint_status'] = $info['open_status'] ==1? $appoint_status: 1;
+        $isOpen = (int)SystemConfigService::make()->getConfigByName('fudai_is_apply',1,'fudai');
+        $info['is_open'] = $isOpen;
+        $info['appoint_status'] = $info['open_status'] == 1 && $isOpen==1? $appoint_status : 4;
         $info['dis_time'] = $dis_time;
-        return api_succ_return(['msg'=>'成功', 'data'=>$info]);
+        return api_succ_return(['msg' => '成功', 'data' => $info]);
     }
 
     // 预约福袋
-     public function beforeBuyBox(Request $request){
+    public function beforeBuyBox(Request $request)
+    {
         $model = new BoxModel();
         $post = $request->post();
         // 这是测试 上线要干掉
 //         return api_error_return('暂未开放');
 
         $user_info = $request->user_info;
-        $userId = isset($user_info['id'])? $user_info['id'] : 0;
+        $userId = isset($user_info['id']) ? $user_info['id'] : 0;
         $cacheKey = "caches:box:apply:u_{$userId}";
-        if(RedisCache::get($cacheKey)){
+        if (RedisCache::get($cacheKey)) {
             return api_succ_return('请不要频繁提交');
         }
-        
-        RedisCache::set($cacheKey,['uid'=> $request->uid, 'data'=> $request->post()], rand(2,3));
+
+        RedisCache::set($cacheKey, ['uid' => $request->uid, 'data' => $request->post()], rand(2, 3));
         Db::startTrans();
         try {
             $model->beforeBuyBox($request->uid, $post, $request->user_info);
             Db::commit();
-        }catch (\Exception $e){
+        } catch (\Exception $e) {
             Db::rollback();
 
             RedisCache::clear($cacheKey);
-            if ($e->getMessage() == '预约失败,还未开始预约、或预约已结束'){
+            if ($e->getMessage() == '预约失败,还未开始预约、或预约已结束') {
                 return api_error_return(
-                    ['msg'=>'预约失败,还未开始预约、或预约已结束', 'code'=>302]);
+                    ['msg' => '预约失败,还未开始预约、或预约已结束', 'code' => 302]);
             }
 
             return api_error_return($e->getMessage());
@@ -199,165 +189,165 @@ class Box
 
         RedisCache::clear($cacheKey);
         return api_succ_return('成功');
-     }
+    }
 
 
-     // 我的预约
-      public function boxBuyRecord(Request $request, BoxRecordModel $model){
-          try {
-              return api_succ_return(['msg'=>'成功', 'data'=>$model->getLog($request)]);
-          } catch (\Exception $e) {
-              return api_error_return('失败');
-          }
-      }
+    // 我的预约
+    public function boxBuyRecord(Request $request, BoxRecordModel $model)
+    {
+        try {
+            return api_succ_return(['msg' => '成功', 'data' => $model->getLog($request)]);
+        } catch (\Exception $e) {
+            return api_error_return('失败');
+        }
+    }
 
-      // 福袋商品列表
-      public function boxOutGoodsList(Request $request){
+    // 福袋商品列表
+    public function boxOutGoodsList(Request $request)
+    {
 
         $box_type = $request->post('box_type');
         $model = new ShopGoodsModel();
 //          $boxs =
-          $where = '';
-          if ($box_type > 0){
-              $where = $box_type;
-          }else{
-              $where = '10,20,30,40';
-          }
-        $list = $model->where('box_type','in', $where)
-            ->withAttr('box_img', function ($val, $data){
-                return getWebUrl().'.'.$val;
+        $where = '';
+        if ($box_type > 0) {
+            $where = $box_type;
+        } else {
+            $where = '10,20,30,40';
+        }
+        $list = $model->where('box_type', 'in', $where)
+            ->withAttr('box_img', function ($val, $data) {
+                return getWebUrl() . '.' . $val;
             })
             ->field('goods_id,box_type,goods_img,price,goods_name,goods_sn')
             ->order('box_type', 'desc')
             ->paginate($request->post('limit'))
             ->toArray();
-        return api_succ_return(['msg'=>'成功', 'data'=>$list['data']]);
+        return api_succ_return(['msg' => '成功', 'data' => $list['data']]);
 
-      }
+    }
 
-      // 福袋商品列表顶部banner
-      public function boxOutBanner(Request $request){
-            $model = new ShopGoodsModel();
-          $list = $model->where('box_type','in', [30,40])
-              ->withAttr('box_img', function ($val, $data){
-                  return getWebUrl().'.'.$val;
-              })
-              ->field('goods_id,box_type,goods_img,price,goods_name,goods_sn')
-              ->order('box_type', 'desc')
-              ->paginate(15)
-              ->toArray();
-          return api_succ_return(['msg'=>'成功', 'data'=>$list['data']]);
-      }
+    // 福袋商品列表顶部banner
+    public function boxOutBanner(Request $request)
+    {
+        $model = new ShopGoodsModel();
+        $list = $model->where('box_type', 'in', [30, 40])
+            ->withAttr('box_img', function ($val, $data) {
+                return getWebUrl() . '.' . $val;
+            })
+            ->field('goods_id,box_type,goods_img,price,goods_name,goods_sn')
+            ->order('box_type', 'desc')
+            ->paginate(15)
+            ->toArray();
+        return api_succ_return(['msg' => '成功', 'data' => $list['data']]);
+    }
 
-      // 拆袋
-      public function openBoxOnline(Request $request){
+    // 拆袋
+    public function openBoxOnline(Request $request)
+    {
 
 
         return api_error_return('已拆开');
         $model = new BoxMidHandleModel();
         $list = [];
-          Db::startTrans();
-          try {
-              $list =  $model->openBoxOnline($request->uid, $request->post(), $request->user_info);
-              Db::commit();
-          }catch (\Exception $e){
-              Db::rollback();
-
-              return api_error_return($e->getMessage());
-          }
+        Db::startTrans();
+        try {
+            $list = $model->openBoxOnline($request->uid, $request->post(), $request->user_info);
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
 
-          return api_succ_return(['msg'=>'成功', 'data'=>$list]);
+            return api_error_return($e->getMessage());
+        }
 
-      }
+        return api_succ_return(['msg' => '成功', 'data' => $list]);
 
-      public function boxHandleList(Request $request){
+    }
 
-        // 这是测试 上线要干掉
-//        sr_testDb($request->header('token'), 45); ;
+    public function boxHandleList(Request $request)
+    {
 
         $type = $request->post('type');
         $keywords = trim($request->post('keywords'));
         $box_type = $request->post('box_type');
-        if (!in_array($type, [1,2])){
-            return api_error_return('参数错误');
+        if (!in_array($type, [1, 2])) {
+            return api_error_return('订单类型参数错误');
+        }
+        $where = array();
+        if (!empty($keywords)) {
+            $where = [['r.h_sn', 'LIKE', '%' . $keywords . '%']];
         }
-          $where = array();
-          if (!empty($keywords)){
-              $where = [['r.h_sn', 'LIKE', '%'.$keywords.'%']];
-          }
-
-        if (!empty($box_type)){
-            if (!in_array($box_type, [10, 20, 30, 40])){
-                sr_throw('参数错误');
+
+        if (!empty($box_type)) {
+            if (!in_array($box_type, [10, 20, 30, 40])) {
+                sr_throw('盒子类型参数错误');
             }
         }
 
-          $where = [];
-          $where[] = ['r.is_delete', '=', 2];  // 修改 by wes 2023-02-19
-          $where[] = ['r.status', '=', $type];
-          $where[] = ['r.uid', '=', $request->uid];
+        $where = [];
+        $where[] = ['r.is_delete', '=', 2];  // 修改 by wes 2023-02-19
+        $where[] = ['r.status', '=', $type];
+        $where[] = ['r.uid', '=', $request->uid];
 
-          if (!empty($box_type)){
-              $where[] = ['r.box_type', '=', $box_type];
-          }
+        if (!empty($box_type)) {
+            $where[] = ['r.box_type', '=', $box_type];
+        }
 
 
         $list = Db::name('box_handle')
             ->alias('r')
             ->where($where)
-//            ->leftJoin('shop_goods g', 'g.goods_id = r.goods_id')
-//            ->withoutField('r.goods_type')
-//            ->field('r.*,g.goods_name,g.goods_sn,g.goods_img,g.price,g.spec_name')
             ->field('r.*')
             ->paginate($request->post('limit'))->toArray();
 
 
-
-          foreach ($list['data'] as $key =>&$val){
-              $goods_info = Db::name('shop_goods')->where('goods_id', $val['goods_id'])->find();
-              $val['goods_name'] = $goods_info['goods_name'];
-              $val['goods_sn'] = $goods_info['goods_sn'];
-              $val['goods_img'] = $goods_info['goods_img'];
-              $val['goods_sn'] = $goods_info['goods_sn'];
-              $val['price'] = $goods_info['price'];
-              $val['spec_name'] = $goods_info['spec_name'];
+        foreach ($list['data'] as $key => &$val) {
+            $goods_info = Db::name('shop_goods')->where('goods_id', $val['goods_id'])->find();
+            $val['goods_name'] = $goods_info['goods_name'];
+            $val['goods_sn'] = $goods_info['goods_sn'];
+            $val['goods_img'] = $goods_info['goods_img'];
+            $val['goods_sn'] = $goods_info['goods_sn'];
+            $val['price'] = $goods_info['price'];
+            $val['spec_name'] = $goods_info['spec_name'];
 //
-              if ($val['box_type'] == 10){
-                  $val['is_canrecycle'] = 0;
-              }else{
-                  $val['is_canrecycle'] = 1;
-              }
+            if ($val['box_type'] == 10) {
+                $val['is_canrecycle'] = 0;
+            } else {
+                $val['is_canrecycle'] = 1;
+            }
 //
-          }
+        }
 
-        return api_succ_return(['msg'=>'成功', 'data'=>$list['data']]);
+        return api_succ_return(['msg' => '成功', 'data' => $list['data']]);
 
-      }
+    }
 
-      public function boxHandleUnread(Request $request){
+    public function boxHandleUnread(Request $request)
+    {
         $data = [];
 
         $model = new BoxHandleModel();
         $data['un_handle'] = [
-            '10'=>$model->where('box_type', 10)->where('uid', $request->uid)->where('status', 1)->where('is_delete', 2)->count(),
-            '20'=>$model->where('box_type', 20)->where('uid', $request->uid)->where('status', 1)->where('is_delete', 2)->count(),
-            '30'=>$model->where('box_type', 30)->where('uid', $request->uid)->where('status', 1)->where('is_delete', 2)->count(),
-            '40'=>$model->where('box_type', 40)->where('uid', $request->uid)->where('status', 1)->where('is_delete', 2)->count()
+            '10' => $model->where('box_type', 10)->where('uid', $request->uid)->where('status', 1)->where('is_delete', 2)->count(),
+            '20' => $model->where('box_type', 20)->where('uid', $request->uid)->where('status', 1)->where('is_delete', 2)->count(),
+            '30' => $model->where('box_type', 30)->where('uid', $request->uid)->where('status', 1)->where('is_delete', 2)->count(),
+            '40' => $model->where('box_type', 40)->where('uid', $request->uid)->where('status', 1)->where('is_delete', 2)->count()
         ];
 
 
         $data['handled'] = [
-            '10'=>$model->where('box_type', 10)->where('uid', $request->uid)->where('status', 2)->where('is_delete', 2)->count(),
-            '20'=>$model->where('box_type', 20)->where('uid', $request->uid)->where('status', 2)->where('is_delete', 2)->count(),
-            '30'=>$model->where('box_type', 30)->where('uid', $request->uid)->where('status', 2)->where('is_delete', 2)->count(),
-            '40'=>$model->where('box_type', 40)->where('uid', $request->uid)->where('status', 2)->where('is_delete', 2)->count()
+            '10' => $model->where('box_type', 10)->where('uid', $request->uid)->where('status', 2)->where('is_delete', 2)->count(),
+            '20' => $model->where('box_type', 20)->where('uid', $request->uid)->where('status', 2)->where('is_delete', 2)->count(),
+            '30' => $model->where('box_type', 30)->where('uid', $request->uid)->where('status', 2)->where('is_delete', 2)->count(),
+            '40' => $model->where('box_type', 40)->where('uid', $request->uid)->where('status', 2)->where('is_delete', 2)->count()
         ];
 
-        return api_succ_return(['msg'=>'成功', 'data'=>$data]);
-      }
+        return api_succ_return(['msg' => '成功', 'data' => $data]);
+    }
 
 
-      public function boxGoodsSurePost(Request $request){
+    public function boxGoodsSurePost(Request $request)
+    {
 
         $model = new ShopOrderModel();
 
@@ -365,45 +355,46 @@ class Box
         try {
             $model->boxGoodsSurePost($request->uid, $request->post());
             Db::commit();
-        }catch (\Exception $e){
+        } catch (\Exception $e) {
             Db::rollback();
             return api_error_return($e->getMessage());
 
         }
 
         return api_succ_return('回收成功');
-      }
-
-      // 一键回收
-      public function boxGoodsReBuy(Request $request){
-          $model = new ShopOrderModel();
-          
-          $user_info = $request->user_info;
-          $userId = isset($user_info['id'])? $user_info['id'] : 0;
-          $cacheKey = "caches:box:rebuy:u_{$userId}";
-          $redis = new Redis();
-          if($redis->get($cacheKey)){
-              return api_succ_return('请不要频繁操作');
-          }
-          
-          $redis->set($cacheKey,['uid'=> $request->uid, 'data'=> $request->post()], rand(2,3));
-          Db::startTrans();
-          try {
-              $res = $model->boxGoodsReBuy($request->uid, $request->post(), $request->user_info);
-              Db::commit();
-          }catch (\Exception $e){
-              Db::rollback();
-              $redis->del($cacheKey);
-              return api_error_return($e->getMessage());
-
-          }
-
-          $redis->del($cacheKey);
-          if ($res){
-              return api_succ_return(['msg'=>'成功', 'data'=>$res]);
-          }
-
-          return api_succ_return('成功');
-
-      }
+    }
+
+    // 一键回收
+    public function boxGoodsReBuy(Request $request)
+    {
+        $model = new ShopOrderModel();
+
+        $user_info = $request->user_info;
+        $userId = isset($user_info['id']) ? $user_info['id'] : 0;
+        $cacheKey = "caches:box:rebuy:u_{$userId}";
+        $redis = new Redis();
+        if ($redis->get($cacheKey)) {
+            return api_succ_return('请不要频繁操作');
+        }
+
+        $redis->set($cacheKey, ['uid' => $request->uid, 'data' => $request->post()], rand(2, 3));
+        Db::startTrans();
+        try {
+            $res = $model->boxGoodsReBuy($request->uid, $request->post(), $request->user_info);
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+            $redis->del($cacheKey);
+            return api_error_return($e->getMessage());
+
+        }
+
+        $redis->del($cacheKey);
+        if ($res) {
+            return api_succ_return(['msg' => '成功', 'data' => $res]);
+        }
+
+        return api_succ_return('成功');
+
+    }
 }

+ 8 - 1
app/api/controller/v1/Fragment.php

@@ -7,6 +7,7 @@ use app\common\model\SystemBannerModel;
 use app\common\model\UserModel;
 use app\common\service\ArticleService;
 use app\common\service\LevelSettingService;
+use app\common\service\SystemConfigService;
 use app\Request;
 use app\api\services\RequestUtilService;
 use Minho\Captcha\CaptchaBuilder;
@@ -59,6 +60,10 @@ class Fragment
             'about_us'=> env('APP.ABOUT_US'),
 
             //福袋参数
+            'box'=> [
+                'is_apply'=> (int)SystemConfigService::make()->getConfigByName('fudai_is_apply',1,'fudai'),
+                'is_retrieve'=> (int)SystemConfigService::make()->getConfigByName('is_retrieve',1,'fudai')
+            ],
             'newhand_url'=> $webUrl.'/api/newhandurl',
             'newguide_url'=> $webUrl.'/api/newguideurl',
             'aboutbox_url'=> $webUrl.'/api/aboutboxurl',
@@ -112,6 +117,8 @@ class Fragment
             'widthdraw'=> [
                 'scale'=>env('WITHDRAW.APP_WITHDRAW_SCALE'),
                 'begin'=>env('WITHDRAW.APP_WITHDRAW_BEGIN'),
+                'withdraw_is_open'=> (int)SystemConfigService::make()->getConfigByName('withdraw_is_open',1,'withdraw'),
+                'service_rate'=> (int)SystemConfigService::make()->getConfigByName('withdraw_service_rate',1,'withdraw'),
                 'desc'=>[
                     '本次提现将收取通证'.env('WITHDRAW.APP_WITHDRAW_SCALE').'%+'.env('WITHDRAW.APP_WITHDRAW_BEGIN').'元手续费',
                     '提现到账时间T+1',
@@ -145,7 +152,7 @@ class Fragment
             'version'=> env('APP.VERSION')
         ];
 
-        RedisCache::set($cacheKey, $data, rand(5, 10));
+        RedisCache::set($cacheKey, $data, rand(300, 600));
         return api_succ_return(['msg'=>'成功', 'data'=>$data]);
     }
 

Разница между файлами не показана из-за своего большого размера
+ 499 - 804
app/api/controller/v1/Pay.php


+ 38 - 172
app/api/controller/v1/ShopOrder.php

@@ -6,9 +6,12 @@ use app\common\model\ShopGoodsModel;
 use app\common\model\ShopOrderModel;
 use app\common\model\UserAddressModel as UserAddress;
 use app\common\service\ShopGoodsService;
+use app\common\service\ShopOrderService;
+use app\common\service\SystemConfigService;
 use app\Request;
 use think\facade\Db;
 use think\Response;
+use utils\RedisCache;
 
 /**
  * 商城订单 by wes
@@ -44,80 +47,28 @@ class ShopOrder
 
     /**
      * 下单商品详情
+     * @param Request $request
+     * @return Response
      */
     public function buyDetail(Request $request)
     {
 
-        $buy_goods = $request->post('buy_goods');
-        $address = $request->post('address_id');
-        if (empty($buy_goods)) {
+        $buyGoods = $request->post('buy_goods');
+        if (empty($buyGoods)) {
             return api_error_return('参数错误');
         }
-        try {
-            $buy_goods = json_decode(html_entity_decode($buy_goods), true);
 
-            if (empty($buy_goods)) {
+        try {
+            $buyGoods = json_decode(html_entity_decode($buyGoods), true);
+            if (empty($buyGoods)) {
                 return api_error_return('商品参数错误,请返回刷新重新下单');
             }
 
-            foreach ($buy_goods as $k => $v) {
-                $goodsInfo = ShopGoodsModel::where(['goods_sn' => $v['goods_sn']])->field('goods_type')->find();
-                if (!$goodsInfo) {
-                    return api_error_return('下单失败,请返回刷新列表');
-                }
-
-            }
-
-            if (empty($address)) {
-                //用户默认收货地址
-                $address = UserAddress::where(['uid' => $request->uid, 'is_default' => 1])->field('id,province,city,county,name,mobile,remark,is_default,mergename')->findOrEmpty()->toArray();
-            } else {
-                $address = UserAddress::where(['uid' => $request->uid, 'id' => $address])->field('id,province,city,county,name,mobile,remark,is_default,mergename')->findOrEmpty()->toArray();
+            if(!$result = ShopOrderService::make()->buyDetail($buyGoods, $request)){
+                return api_error_return('下单失败');
             }
-//            if (!$address){
-//                return api_error_return('地址获取失败');
-//            }
-
-            $data = ShopOrderModel::buyDetails($buy_goods, $address);
-
-
-            if (empty($data)) {
-                return api_error_return('获取失败');
-            }
-            $cur_xzmoney = Db::name('system_config')->where('name', 'xz_cur_money')->where('group', 'xzconfig')->value('value');
-            foreach ($data['details'] as $key => $val) {
-                foreach ($val['goods'] as $k1 => $v1) {
-                    $goods_name = $v1['goods_name'];
-                    $goods_name = str_replace(' ', '', $goods_name);
-                    if (strlen($goods_name) > 20) {
-                        $goods_name = substr($goods_name, 0, 19);
-                    }
-
-//                    $data['details'][$key]['goods'][$k1]['goods_name'] = mb_convert_encoding($goods_name, 'UTF-8', 'UTF-8');
-//                    $data['details'][$key]['goods'][$k1]['goods_name'] = '云德商品购买';
-
-                    if ($v1['goods_type'] == 5) {
-                        $data['details'][$key]['goods'][$k1]['price'] = getXzPirceWithPrice($cur_xzmoney, $data['details'][$key]['goods'][$k1]['price']);
-                        $data['details'][$key]['goods'][$k1]['total_fee'] = getXzPirceWithPrice($cur_xzmoney, $data['details'][$key]['goods'][$k1]['total_fee']);
-
-                    }
-                }
-            }
-
-//            if ($order_type == 5){
-//
-//                foreach ($data['details'] as $key=>$val){
-////                    ['total_price'] = getXzPirceWithPrice($cur_xzmoney, $data['total_price']);
-//                    $data['details'][$key]['total_price']= getXzPirceWithPrice($cur_xzmoney, $val['total_price']);
-//                    $data['details'][$key]['payment']= getXzPirceWithPrice($cur_xzmoney, $val['payment']);
-//
-//                }
-//
-//                $data['total']['count_payment'] = getXzPirceWithPrice($cur_xzmoney, $data['total']['count_payment']);
-//
-//            }
-            return api_succ_return(['msg' => '获取成功', 'data' => ['address' => (object)$address, 'buyDetail' => $data['details'], 'total' => $data['total']]]);
 
+            return api_succ_return(['msg' => '获取成功', 'data' => $result]);
         } catch (\Exception $e) {
             return api_error_return($e->getMessage());
 
@@ -134,14 +85,12 @@ class ShopOrder
      */
     public function createOrder(Request $request)
     {
-        $addressId = $request->post('address', '');
-        $remark = $request->post('order_remark', '');
         $payType = $request->post('pay_type', 0);
         $payType = $payType == 3 ? $payType : 99;  // 因收银台功能过滤支付方式
 
         // 购买商品参数
         $buyGoods = json_decode(html_entity_decode($request->post('buy_goods', '')), true);
-        if ($request->user['status'] == 0) {
+        if ($request->user['status'] != 1) {
             return api_error_return('用户被禁用');
         }
 
@@ -151,107 +100,28 @@ class ShopOrder
 
         // 重复提交拦截
         $cacheKeyLock = "caches:orders:createLock:{$request->uid}";
+        if(RedisCache::exists($cacheKeyLock)){
+            return api_error_return('请不要频繁提交');
+        }
 
         try {
-            $orderGoods = [];
-            $order_type = 1;   //  1 买商品送积分   2积分兑换   3任务包兑换券   4提货券   5 星钻兑换
-            foreach ($buyGoods as $k => $v) {
-                $goodsSn = isset($v['goods_sn'])? trim($v['goods_sn']) : 0;
-                $specId = isset($v['spec_id'])? trim($v['spec_id']) : 0;
-                $orderGoods["{$goodsSn}_{$specId}"][] = $v;
-                $num = isset($v['num']) ? intval($v['num']) : 0;
-                if ($num < 1) {
-                    return api_error_return("请先选择商品数量哦");
-                }
-
-                $goodsInfo = ShopGoodsService::make()->getCacheInfo($v['goods_sn']);
-                if (!$goodsInfo) {
-                    return api_error_return('商品参数错误或已下架,请返回刷新列表');
-                }
-                if ($goodsInfo['goods_type'] == 2) {
-                    return api_error_return('福袋商品不能购买');
-                }
-
-                if ($goodsInfo['restrictions_num'] > 0) {
-                    $count = Db::name('shop_order_goods')
-                        ->alias('og')
-                        ->leftJoin('shop_order o', 'o.order_id = og.order_id')
-                        ->where('o.status', 'in', [1, 2, 4])
-                        ->where('og.uid', $request->uid)
-                        ->count('og.og_id');
-
-                    if ($count > $goodsInfo['restrictions_num']) {
-                        return api_error_return('超过限购');
-                    }
-                    if ($v['num'] + $count > $goodsInfo['restrictions_num']) {
-                        return api_error_return('超过限购数量,还可购买:' . ($goodsInfo['restrictions_num'] - $count) . '件');
-                    }
-
-
-                }
-
-            }
-
-            if (!$userAddress = UserAddress::getAddressIdDetails((int)$addressId)) {
-                return api_error_return('获取收货地址失败');
-            }
-            if ($userAddress['uid'] != $request->user['id']) {
-                return api_error_return('收货地址信息异常');
-            }
-
-            if (empty($buy_goods)) {
-                return api_error_return('参数错误2');
-            }
-
-            foreach ($buy_goods as $key => $value) {
-                $result[$value['goods_sn'] . '_' . $value['spec_id']][] = $value;
-            }
-
-            if (!ShopOrderModel::checkStock($result)) {
-                return api_error_return('下单失败,所选商品含有库存不足的商品');
-            }
-
-            try {
-                $data = ShopOrderModel::buyDetails($buy_goods, $userAddress);
-
-                $supplier_name = $data['details'][0]['supplier_name'];
-
-
-                $paymoney = $data['total']['count_payment'];
-
-                $count = Db::name('shop_order')->where('user_id', $request->uid)->where('order_type', 1)->where('status', 0)->whereTime('created_time', '-2 hours')->count();
-
-                if ($count > 20) {
-                    return api_error_return('未支付的订单太多,创建失败');
-                }
-
-                // 订单处理数据
-                $orderData = [
-                    'order' => $result,
-                    'address' => $userAddress,
-                    'cls' => 0,
-                    'cart_ids' => 0,
-                    'pay_type' => $payType,
-                    'order_remark' => $remark,
-                    'order_type' => $order_type,
-                    'supplier_name' => $supplier_name
-                ];
-                $flag = ShopOrderModel::createOrder($orderData, $request->uid, $request->user, $data, $request->post('cart_id', ''));
-
-                if (!$flag) {
-                    return api_error_return('下单失败');
-                }
-                return api_succ_return(['msg' => '下单成功', 'data' => ['order_ids' => $flag['data']]]);
-            } catch (\Exception $e) {
-
-                return api_error_return('下单失败 ' . $e->getMessage());
+            // 加锁
+            RedisCache::setnx($cacheKeyLock, 1, rand(2,3));
+            if($ids = ShopOrderService::make()->createOrder($request->uid, $buyGoods, $payType, $request)){
+                // 清除缓存
+                RedisCache::clear($cacheKeyLock);
+                RedisCache::keyDel("caches:paymentCall:u{$request->uid}_ot4*");
+                return api_succ_return(['msg'=>'下单成功', 'data'=>['order_ids'=> $ids]]);
+            }else{
+                RedisCache::clear($cacheKeyLock);
+                return api_error_return('下单失败');
             }
 
         } catch (\Exception $e) {
+            RedisCache::clear($cacheKeyLock);
             return api_error_return($e->getMessage());
         }
 
-
     }
 
     /**
@@ -263,18 +133,16 @@ class ShopOrder
             return api_error_return('订单号不能为空');
         }
 
-        Db::startTrans();
         try {
-            ShopOrderModel::cancelOrder($request->only(['order_sn']), $request->uid);
-            Db::commit();
+            if(ShopOrderService::make()->cancelOrder($request->only(['order_sn']), $request->uid)){
+                return api_succ_return('取消成功');
+            }else{
+                return api_error_return('取消失败');
+            }
         } catch (\Exception $e) {
-            Db::rollback();
             return api_error_return('取消失败' . $e->getMessage());
 
         }
-
-        return api_succ_return('取消成功');
-
     }
 
     /**
@@ -286,18 +154,16 @@ class ShopOrder
             return api_error_return('订单号不能为空');
         }
 
-        Db::startTrans();
         try {
-            ShopOrderModel::receiveOrder($request->only(['order_sn']), $request->uid);
-            Db::commit();
+            if(ShopOrderService::make()->receiveOrder($request->only(['order_sn']), $request->uid)){
+                return api_succ_return('确认成功');
+            }else{
+                return api_error_return('确认失败');
+            }
         } catch (\Exception $e) {
-            Db::rollback();
             return api_error_return('确认失败' . $e->getMessage());
 
         }
-
-        return api_succ_return('确认成功');
-
     }
 
 

+ 163 - 2
app/api/controller/v1/Test.php

@@ -46,9 +46,170 @@ use utils\RedisCache;
 
 class Test
 {
-     public function test5(Request $request)
+    public function test(Request $request)
     {
-       var_dump(SystemConfigService::make()->getConfigByGroup('site'));
+        $list = [
+            5351304 => 503.5,
+            5352276 => 266,
+            5350677 => 285,
+            5352212 => 380,
+            5352211 => 1045,
+            5352210 => 760,
+            5352209 => 380,
+            5352208 => 760,
+            5350403 => 114,
+            5349123 => 285,
+            5349372 => 285,
+            5346924 => 285,
+            5352433 => 760,
+            5349713 => 95,
+            5348017 => 199.5,
+            5351411 => 1463,
+            5352535 => 665,
+            5346982 => 769.5,
+            5345774 => 313.5,
+            5352523 => 665,
+            5346478 => 1187.5,
+            5349879 => 475,
+            5352233 => 760,
+            5348700 => 2584,
+            5344662 => 969,
+            5345278 => 209,
+            5351904 => 551,
+            5345493 => 275.5,
+            5349688 => 1748,
+            5351924 => 380,
+            5348026 => 332.5,
+            5348962 => 4750,
+            5346159 => 693.5,
+            5351619 => 1045,
+            5351807 => 2831,
+            5350426 => 95,
+            5344610 => 608,
+            5344515 => 1197,
+            5350443 => 361,
+            5346094 => 950,
+            5350358 => 1187.5,
+            5347725 => 361,
+            5352458 => 1045,
+            5351189 => 361,
+            5348630 => 522.5,
+            5349709 => 1748,
+            5351373 => 684,
+            5345879 => 950,
+            5350359 => 370.5,
+            5351923 => 1045,
+            5345919 => 579.5,
+            5344810 => 237.5,
+            5352455 => 674.5,
+            5348947 => 133,
+            5348622 => 95,
+            5349735 => 1653,
+            5351621 => 380,
+            5349987 => 95,
+            5350010 => 380,
+            5347898 => 114,
+            5344563 => 893,
+            5344861 => 1881,
+            5351491 => 855];
+
+        $ids = array_keys($list);
+        echo "共要处理记录:".count($list).'个,'.count($ids).'个ID<br>';
+        $users = UserModel::whereIn('id', $ids)->field('id,mobile,money,score')->select();
+        echo "实际用户记录:".count($users).'个<br>';
+        $moneyLogs = [];
+        $scoreLogs = [];
+        $noCatchUsers = [];
+        Db::startTrans();
+        foreach($list as $key => $catchMoney){
+
+            $userInfo = UserModel::where('id', $key)->field('id,mobile,money,score')->find();
+            $userId = isset($userInfo['id'])? $userInfo['id'] : 0;
+            $money = isset($userInfo['money'])? $userInfo['money'] : 0;
+            $score = isset($userInfo['score'])? $userInfo['score'] : 0;
+            $mobile = isset($userInfo['mobile'])? $userInfo['mobile'] : '';
+            if($userId && $catchMoney>0){
+                if($money>=$catchMoney){
+                    echo "【扣除余额】用户[{$userId}][{$mobile}],处理金额 {$catchMoney},账户余额[{$money}]-积分[{$score}],扣除后余额 ".max(0,$money-$catchMoney).'<br>';
+                    $moneyLogs[] = [
+                        'uid'=> $userId,
+                        'money'=> $catchMoney,
+                        'type'=> 17,
+                        'create_at'=> date('Y-m-d H:i:s'),
+                        'state'=> 2,
+                        'from_id'=>0,
+                        'before_money'=> $money,
+                        'after_money'=> max(0,$money-$catchMoney),
+                        'remark'=> '提现打款重复扣除',
+                    ];
+
+                    // 扣除
+                    /*if(!UserModel::where('id', $userId)->dec('money', $catchMoney)->update()){
+                        DB::rollback();
+                        return 'fail';
+                    }*/
+                }elseif($score>=$catchMoney){
+                    echo "【扣除积分】用户[{$userId}][{$mobile}],处理金额 {$catchMoney},账户余额[{$money}]-积分[{$score}],扣除后余额 ".($money-$catchMoney).'<br>';
+                    $scoreLogs[] = [
+                        'uid'=> $userId,
+                        'score'=> $catchMoney,
+                        'type'=> 13,
+                        'create_at'=> date('Y-m-d H:i:s'),
+                        'state'=> 2,
+                        'from_id'=>0,
+                        'before_score'=> $score,
+                        'after_score'=> max(0,$score-$catchMoney),
+                        'remark'=> '提现打款重复扣除',
+                    ];
+                    // 处理账户
+                    /*if(!UserModel::where('id', $userId)->dec('score', $catchMoney)->update()){
+                        DB::rollback();
+                        return 'fail';
+                    }*/
+                }elseif(($score+$money)>=$catchMoney){
+                    // 扣除余额后剩余的钱
+                    $money1 = max(0,$catchMoney - $money);
+                    echo "【扣除积分和余额】用户[{$userId}][{$mobile}],处理金额 {$catchMoney},账户余额[{$money}]-积分[{$score}],扣除后余额 ".max(0,$catchMoney-$money).",扣除后积分 ".($score-$money1).'<br>';
+                    $moneyLogs[] = [
+                         'uid'=> $userId,
+                         'money'=> $money,
+                         'type'=> 17,
+                         'create_at'=> date('Y-m-d H:i:s'),
+                         'state'=> 2,
+                         'from_id'=>0,
+                         'before_money'=> $money,
+                         'after_money'=> 0,
+                         'remark'=> '提现打款重复扣除',
+                     ];
+
+                    // 扣积分
+                    $scoreLogs[] = [
+                        'uid'=> $userId,
+                        'score'=> $money1,
+                        'type'=> 13,
+                        'create_at'=> date('Y-m-d H:i:s'),
+                        'state'=> 2,
+                        'from_id'=>0,
+                        'before_score'=> $score,
+                        'after_score'=> max(0,$score-$money1),
+                        'remark'=> '提现打款重复扣除',
+                    ];
+
+                    // 处理账户
+                    /*if(!UserModel::where('id', $userId)->dec('money', $money)->dec('score',$money1)->update()){
+                        DB::rollback();
+                        return 'fail';
+                    }*/
+                }else{
+                    echo "【账户不足】用户[{$userId}][{$mobile}],处理金额 {$catchMoney},账户余额[{$money}]-积分[{$score}],账户不够<br>";
+                    $noCatchUsers[$userId] = "【账户不足】用户[{$userId}][{$mobile}],账户余额[{$money}]-积分[{$score}],处理金额 {$catchMoney},账户不够";
+                }
+            }else{
+                echo "【未做处理】用户[{$userId}][{$mobile}],处理金额 {$catchMoney},账户积分[{$money}]-积分[{$score}],数据错误未处理<br>";
+            }
+        }
+
+        Db::commit();
         return 'success';
 
     }

+ 0 - 19
app/api/controller/v1/User.php

@@ -155,25 +155,7 @@ class User
         $app_version = str_replace('.', '', $app_version);
         $app_version = dispRepair($app_version, 4, '0', '0');
 
-//        if ($app_sources == 'ios'){
-//            if ($curIosVersion > $app_version){
-//                return api_error_return('app版本号过低,请更新');
-//            }
-//        }
-//        if ($app_sources == 'ios'){
-//            if ($curIosVersion > $app_version){
-//                return api_error_return('苹果app版本更新会尽快通知,敬请期待!');
-//            }
-//        }
-
-//        if ($app_sources == 'android'){
-//            if ($curAndroidVersion > $app_version){
-//                return api_error_return('app版本号过低,请更新');
-//            }
-//        }
-
         $param = $request->param();
-//var_dump($param);
         Db::startTrans();
         try {
 
@@ -1299,7 +1281,6 @@ class User
     public function incomeMoneyLog(Request $request){
         $model = new MoneyLogModel();
         try {
-//            $request->data['type'] = 8;
             return api_succ_return(['msg'=>'成功', 'data'=>$model->getLog($request, 8)]);
         } catch (\Exception $e) {
             return api_error_return('失败'.$e->getMessage());

+ 13 - 6
app/api/middleware/AuthSignMiddleWare.php

@@ -2,6 +2,7 @@
 
 namespace app\api\middleware;
 
+use app\common\service\SystemConfigService;
 use app\Request;
 use interfaces\MiddlewareInterface;
 use think\cache\driver\Redis;
@@ -28,13 +29,19 @@ class AuthSignMiddleWare implements MiddlewareInterface
         }
 
         // 站点升级访问验证
-        if (env('APP.WEB_IS_UPDATE')){
-            $testIp = env('APP.TEST_IPS');
-            $testIps = $testIp? $testIp : '';
+        $isUpdate = SystemConfigService::make()->getConfigByName('site_web_is_update');
+        $isUpdate = $isUpdate? $isUpdate : env('APP.WEB_IS_UPDATE');
+        if ($isUpdate==1){
+            // 非测试IP访问,直接拦截
+            $config = SystemConfigService::make()->getConfigByNames(['site_update_tips','site_access_ips']);
+            $updateTip = isset($config['site_update_tips'])? trim($config['site_update_tips']) : '';
+            $accessIps = isset($config['site_access_ips'])? trim($config['site_access_ips']) : '';
+            $updateTip = $updateTip? $updateTip : '网站升级中';
+            $accessIps = $accessIps? $accessIps : env('APP.TEST_IPS');
             $currentIp = get_client_ip();
-           
-            if($testIps && !preg_match("/{$currentIp}/", $testIps)){
-               return api_error_return(['msg'=>'网站正在升级中', 'data'=>['ips'=> $testIps,'ip'=> $currentIp]]); 
+
+            if(empty($accessIps) || ($accessIps && !preg_match("/{$currentIp}/", $accessIps))){
+                return api_error_return(['msg'=> $updateTip, 'data'=>['tips'=>$updateTip,'is_update'=>true,'ip'=> $currentIp]]);
             }
         }
 

+ 13 - 7
app/api/middleware/AuthTokenMiddleWare.php

@@ -3,6 +3,7 @@ declare (strict_types=1);
 
 namespace app\api\middleware;
 
+use app\common\service\SystemConfigService;
 use app\Request;
 use app\api\services\UserAuthServices;
 use interfaces\MiddlewareInterface;
@@ -21,15 +22,20 @@ class AuthTokenMiddleWare implements MiddlewareInterface
     public function handle (Request $request, \Closure $next)
     {
         try {
-            
-            if (env('APP.WEB_IS_UPDATE') ){
+            // 是否更新
+            $isUpdate = SystemConfigService::make()->getConfigByName('site_web_is_update');
+            $isUpdate = $isUpdate? $isUpdate : env('APP.WEB_IS_UPDATE');
+            if ($isUpdate){
                 // 非测试IP访问,直接拦截
-                $testIp = env('APP.TEST_IPS');
-                $testIps = $testIp? $testIp : '';
+                $config = SystemConfigService::make()->getConfigByNames(['site_update_tips','site_access_ips']);
+                $updateTip = isset($config['site_update_tips'])? trim($config['site_update_tips']) : '';
+                $accessIps = isset($config['site_access_ips'])? trim($config['site_access_ips']) : '';
+                $updateTip = $updateTip? $updateTip : '网站升级中';
+                $accessIps = $accessIps? $accessIps : env('APP.TEST_IPS');
                 $currentIp = get_client_ip();
-               
-                if($testIps && !preg_match("/{$currentIp}/", $testIps)){
-                   return api_error_return(['msg'=>'网站正在升级中', 'data'=>['ips'=> $testIps,'ip'=> $currentIp]]); 
+
+                if(empty($accessIps) || ($accessIps && !preg_match("/{$currentIp}/", $accessIps))){
+                    return api_error_return(['msg'=> $updateTip, 'data'=>['tips'=>$updateTip,'is_update'=>true,'ip'=> $currentIp]]);
                 }
             }
 

Разница между файлами не показана из-за своего большого размера
+ 1 - 19
app/api/services/AliPayServices.php


+ 17 - 14
app/api/services/BalancePayServices.php

@@ -1,23 +1,28 @@
 <?php
 /**
- * 支付宝支付
+ * 余额支付
  */
-
 namespace app\api\services;
 
-use AlibabaCloud\SDK\OSS\OSS\GetObjectRequest\header;
-use app\common\model\ShopOrderModel as Order;
-use Rsa\RsaClient;
-use Symfony\Component\Translation\Dumper\IniFileDumper;
+use app\common\service\ShopOrderService;
 use think\facade\Db;
-
 class BalancePayServices extends BasePayServices
 {
+    /**
+     * 余额支付订单处理
+     * @param $uid
+     * @param $order_id
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
     public function balanceToOrder($uid, $order_id){
-        $order_info = Db::name('shop_order')->where('order_sn', $order_id)->where('user_id', $uid)->find();
+        $order_info = ShopOrderService::make()->getInfoBySn($order_id, $uid);
         if ($order_info['status'] != 0){
             sr_throw('订单已支付,不能再次支付');
         }
+
         $user = Db::name('user')->where('id', $uid)->find();
         if (!$order_info){
             sr_throw('订单号错误');
@@ -26,17 +31,15 @@ class BalancePayServices extends BasePayServices
             sr_throw('当前用户余额不足');
         }
 
-//        Db::name('shop_order')->where('order_sn', $order_id)->save([
-//            'status'=>1,
-//            'updated_time'=>sr_getcurtime(time()),
-//            'pay_type'=>3
-//        ]);
-
+        // 扣除余额
         edit_user_money(11, $uid, $order_info['payment']);
+
+        // 发送购买通知信息
         addUserMessage($uid, 3, '余额购买商品成功', '恭喜你已经兑换到心仪的商品,请等待发货,如有疑问请联系客服');
 
         $out_trade_no = 'BA'.$order_id.mt_rand(1, 10000);
 
+        // 支付信息处理
         $insert = [
             'total_fee' => $order_info['payment'],
             'trade_type' => 'app',

+ 5 - 88
app/api/services/BasePayServices.php

@@ -19,6 +19,7 @@ use services\CacheServices;
 use think\Exception;
 use think\facade\Db;
 use think\facade\Env;
+use utils\RedisCache;
 
 abstract class BasePayServices
 {
@@ -59,8 +60,6 @@ abstract class BasePayServices
                 break;
             case 2: // 实名认证
                 $total_amount = Db::name('user_data')->where('uid', $uid)->value('rz_money');
-//                if (!$total_amount || $total_amount < 1.5)
-//                    throw new Exception('认证费用不正确');
                 $body = '实名认证费用';
                 break;
             case 3: // 开通会员
@@ -74,8 +73,6 @@ abstract class BasePayServices
                 break;
             case 4: //购买商品
                 $order_sn = $data['order_id'];
-//                $checkingOrder = Order::checkingOrder($order_sn, $data['money'], $uid);
-                // new
                 $checkingOrder = Order::checkingOrder($order_sn, 0, $uid);
                 if (!$checkingOrder) {
                     throw new Exception('校验订单失败');
@@ -96,8 +93,6 @@ abstract class BasePayServices
         if (!$body || !$total_amount || $total_amount <= 0)
             throw new Exception('配置错误');
 
-        // 这是测试 线要干掉
-//        $total_amount = floatval('0.'.mt_rand(1, 3).mt_rand(1, 9));;
         return [$body, $type == 1 ? $total_amount : bcmul($total_amount, 100, 2), $data['order_type'], $remarks, $data['trade_type'], $data['channel'], isset($data['voucher_img']) ? $data['voucher_img'] : ''];
     }
 
@@ -121,6 +116,10 @@ abstract class BasePayServices
             'voucher_img' => $param['voucher_img'],
             'out_trade_no1'=>(isset($param['out_trade_no1'])?$param['out_trade_no1']:(isset($param[''])))
         ];
+        // 信息
+        $payWays = [1=>'wxpay',2=>'alipay',3=>'balancePay',14=>'huifuPay',15=>'sqzPay',16=>'sqzAliPay',17=>'sqzWxPay',18=>'sqzYljk',19=>'usdtPay',20=>'yswkPay',22=>'dkpay',56=>'ysftyPay'];
+        $payWayCode = isset($payWays[$param['pay_way']])? $payWays[$param['pay_way']] : 'defpay';
+        RedisCache::set("caches:payment:{$payWayCode}:otn_{$param['out_trade_no']}:{$param['uid']}_{$param['remarks']}_payment", $insert, 7200);
         Db::name('payment')->insert($insert);
     }
 
@@ -138,93 +137,11 @@ abstract class BasePayServices
                     Db::name('payment')->where('id', $pay_info['id'])->update(['state' => 6, 'pay_at' => date('Y-m-d H:i:s')]); // 更改订单状态
                     switch ($pay_info['order_type']) {
                         case 1: // 充值
-//                            $pay_num = Db::name('payment')->where(['uid' => $pay_info['uid'], 'state' => 6, 'order_type' => 1])->count('id');
-//                            set_user_money($pay_info['uid'], $pay_info['total_fee'], 1);
-//                            if ($pay_num == 1 && $pay_info['total_fee'] >= 100) { // 首次充值并且金额大于100,送月会员
-//                                $user = Db::name('user')->where('id', $pay_info['uid'])->field('vip,vip_expire_time')->find();
-//                                $date = new \DateTime($user['vip_expire_time']);
-//                                $date->add(new \DateInterval(get_vip_datetime_string('monthly_card')['time']));
-//                                $vip_expire_time = $date->format('Y-m-d H:i:s'); // vip到期时间
-//                                $user_update['vip_expire_time'] = $vip_expire_time;
-//                                $user_update['vip_type'] = 'monthly_card';
-//                                $user['vip'] < 1 && $user_update['vip'] = get_vip_datetime_string('monthly_card')['vip_type'];
-//                                Db::name('user')->where('id', $pay_info['uid'])->update($user_update);
-//                                Db::name('vip_log')->insert(['uid' => $pay_info['uid'], 'type' => 2, 'pay_price' => $pay_info['total_fee'], 'vip_expire_time' => $vip_expire_time, 'vip_type' => 'monthly_card']);
-//                            }
                             break;
                         case 3:
                             // 充值会员
-//                            CacheServices::set('is_lock_vipdata', 2);
-                            // 更改订单状态
-//                            $order = VipOrderModel::where('order_id', $pay_info['remarks'])->find();
-//
-//                            // 更新viporder为支付状态
-//                            VipOrderModel::where('order_id', $pay_info['remarks'])->save(['status' => 2]);
-//
-//                            $buy_info = Db::name('user')->where('id', $order['user_id'])->find();
-//                            Db::name('user')->where('id', $order['user_id'])->inc('vip_count', 1)->update();
-//                            Db::name('user')->where('id', $order['user_id'])->save(['is_vip' => 1]);
-//                            Db::name('user')->where('id', $order['user_id'])->inc('target_inc', 3069)->update();
-//                            $curpid = $buy_info['pid'];
-//                            if ($curpid > 0) {
-//                                while (1) {
-//                                    if ($curpid == 0 || empty($curpid)) {
-//                                        break;
-//                                    }
-//                                    $cur_user = Db::name('user')->where('id', $curpid)->find();
-//                                    Db::name('user')->where('id', $curpid)->inc('group_vip_count', 1)->update();
-//                                    $curpid = $cur_user['pid'];
-//                                }
-//                            }
-//
-////                            $val = CacheServices::get('is_lock_vipdata', 0);
-////                            if ($val == 1){
-////                                return api_error_return('请稍后再试1');
-////                            }
-//
-////                            CacheServices::set('is_lock_vipdata', 1);
-////                            Db::startTrans();
-////                            try {
-//                            $level = Db::name('vip_relation_data')->lock(true)->max('level');
-//                            if (empty($level)) {
-//                                $level = 1;
-//                            } else {
-//                                $maxid = Db::name('vip_relation_data')->lock(true)->max('id');
-//                                if ($maxid >= (pow(2, $level) - 1)) {
-//                                    ++$level;
-//                                };
-//                            }
-//                            if ($level > 1) {
-//                                $curarr = CacheServices::get('vip_level_data' . $level);
-//                                if (!$curarr) {
-//                                    $info = Db::name('vip_level_data')->where(['level' => $level])->find();
-//                                    $curarr = explode(',', $info['value']);
-//                                    CacheServices::set('vip_level_data' . $level, $curarr);
-//                                }
-//                                // 上一层最大的id
-//                                $max_level_info_id = Db::name('vip_relation_data')->where(['level' => $level - 1])->field('id')->lock(true)->max('id');
-//                                $pid = $curarr[$maxid - $max_level_info_id];
-//                            } else {
-//                                $pid = 0;
-//                            }
-//
-//                            $insertData = [
-//                                'create_time' => getCurTimeStamp(),
-//                                'pid' => $pid,
-//                                'level' => $level,
-//                                'uid' => $buy_info['id']
-//                            ];
-//
-//                            Db::name('vip_relation_data')->lock(true)->insertGetId($insertData);
-////                            \utils\Queue::instance()->log('会员VIP订单执行成功' . $buy_info['id'])->do('VipOrderBack')->job(VipOrderJob::class)->push([$level, $buy_info['id'], $pid]);
-//
 //                            break;
                         case 4: //购买商品
-//                            $order = Order::where(['order_sn' => explode(',', $pay_info['remarks'])])->select()->toArray();
-//                            Order::payDoneOrderCallback($order, 3, $pay_info['uid']);
-                            $m_goods = new ShopGoodsModel();
-                            $m_user = new UserModel();
-                            $m_shoporder = new ShopOrderModel();
                             // 更改订单状态
                             $order = ShopOrderModel::where('order_sn', $pay_info['remarks'])->find();
                             $nowTime = date('Y-m-d H:i:s', time());

+ 11 - 0
app/api/services/BaseServices.php

@@ -9,11 +9,22 @@ abstract class BaseServices
 {
     protected  $model = null;
 
+    /**
+     * @param $name
+     * @return Db
+     */
     public function getModel($name){
         return Db::name($name);
     }
 
 
+    /**
+     * 创建Token
+     * @param int $uid
+     * @param null $user
+     * @param string $type
+     * @return mixed
+     */
     public function createToken(int $uid, $user = null, string $type = 'API'){
         $jwt = app()->make(JwtAuth::class);
         return $jwt->createToken($uid, $user, $type);

Разница между файлами не показана из-за своего большого размера
+ 912 - 1715
app/api/services/ThirdPayServices.php


+ 0 - 8
app/api/services/UserAuthServices.php

@@ -33,7 +33,6 @@ class UserAuthServices extends BaseServices
             throw new Exception('请登录', 401);
         }
 
-
         /** @var JwtAuth $jwtAuth */
         $jwtAuth = app()->make(JwtAuth::class);
 
@@ -60,13 +59,11 @@ class UserAuthServices extends BaseServices
 
             $jwt = $jwtAuth->verifyToken($token);
         } catch (\Throwable $e) {
-//            $cacheServices::clearToken($md5Token);
             throw new Exception($e->getMessage(), 401);
         }
 
 
         $user = $this->model->where('id', $uid)->where('status', 1)->find(); // 获取用户信息
-//        $user->service_ratio = getService($user->pledge_level);
         if (empty($user) || $user->id != $tokenData['uid']) {
             $cacheServices::clearToken($md5Token);
             // token过期
@@ -75,14 +72,9 @@ class UserAuthServices extends BaseServices
 
 
         if ($user->login_count != $jwt['user']['login_count']) {
-//            $cacheServices::clearToken($md5Token);
-//            throw new Exception('当前账号在另一设备上登陆,若非本人操作,您的登陆密码可能泄露,请及时修改密码', 402); // 账号在另一设备登录,使用短信登录
-
-
             throw new Exception('登录已过期', 402); // 账号在另一设备登录,使用短信登录
         }
 
-
         return $user;
     }
 }

+ 6 - 1
app/api/services/WxPayServices.php

@@ -5,6 +5,7 @@
 
 namespace app\api\services;
 
+use utils\RedisCache;
 use utils\WxPay;
 
 /**
@@ -46,13 +47,17 @@ class WxPayServices extends BasePayServices
     public function getUnifiedOrder ()
     {
         $uid = $this->uid;
-        if (!$uid || !$this->data)
+        if (!$uid || !$this->data){
             return app('json')->json_error('下单失败');
+        }
         list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way) = $this->_payConf($uid, $this->data, 2);
         $out_trade_no = rand(1000000000, 9999999999) . (string)date('ymdhis', time()) . (int)microtime(true); // 订单号
         /** @var WxPay $pay */
+        $cacheKey = "caches:payment:wxPay:otn_{$out_trade_no}:";
+        RedisCache::set($cacheKey.'params',['data'=> $this->data,'params'=>['uid'=>$uid,'body'=>$body,'out_trade_no'=>$out_trade_no,'total_amount'=>$total_amount]], 7200);
         $pay = app()->make(WxPay::class);
         $rpm = $pay->unifiedOrder(compact('uid', 'body', 'out_trade_no', 'total_amount'));
+        RedisCache::set($cacheKey.'result',['data'=> $this->data,'result'=>$rpm,'params'=>['uid'=>$uid,'body'=>$body,'out_trade_no'=>$out_trade_no,'total_amount'=>$total_amount]], 7200);
         if (!$rpm['flag']) {
             return app('json')->json_error($rpm['msg']);
         }

+ 0 - 4
app/common/model/MoneyLogModel.php

@@ -35,10 +35,6 @@ class MoneyLogModel extends Model
             ->order('id', 'desc')
             ->paginate($param->data['limit'])
             ->toArray();
-//        $history = self::where([
-//            ['uid', '=', $param->uid],
-//            ['state', '=', 1]
-//        ])->sum('money');
         return $list['data'];
         return compact('list', 'history');
     }

+ 0 - 16
app/common/model/ShopCategory.php

@@ -2,25 +2,9 @@
 
 namespace app\common\model;
 
-use app\admin\logic\ShopCategoryLogic;
 use app\common\model\TimeModel;
-use think\Model;
 
 class ShopCategory extends TimeModel
 {
 
-    public static function onAfterUpdate(Model $model)
-    {
-        ShopCategoryLogic::delIdCache($model->id);
-    }
-
-    public static function onAfterInsert(Model $model): void
-    {
-        ShopCategoryLogic::delIdCache($model->id);
-    }
-
-    public static function onAfterDelete(Model $model): void
-    {
-        ShopCategoryLogic::delIdCache($model->id);
-    }
 }

+ 1 - 16
app/common/model/ShopGoodsSpecType.php

@@ -2,10 +2,7 @@
 
 namespace app\common\model;
 
-use app\admin\logic\ShopGoodsSpecTypeLogic;
-use app\admin\logic\ShopGoodsTypeLogic;
 use app\common\model\TimeModel;
-use think\Model;
 
 class ShopGoodsSpecType extends TimeModel
 {
@@ -14,19 +11,7 @@ class ShopGoodsSpecType extends TimeModel
 
     protected $deleteTime = false;
 
-    public static function onAfterUpdate($model){
-        ShopGoodsSpecTypeLogic::delCache();
-    }
-
-    public static function onAfterInsert(Model $model): void
-    {
-        ShopGoodsSpecTypeLogic::delCache();
-    }
-
-    public static function onAfterDelete(Model $model): void
-    {
-        ShopGoodsSpecTypeLogic::delCache();
-    }
+    
     
 
 }

+ 0 - 15
app/common/model/ShopGoodsTypeModel.php

@@ -2,9 +2,7 @@
 
 namespace app\common\model;
 
-use app\admin\logic\ShopGoodsTypeLogic;
 use app\common\model\TimeModel;
-use think\Model;
 
 class ShopGoodsTypeModel extends TimeModel
 {
@@ -12,19 +10,6 @@ class ShopGoodsTypeModel extends TimeModel
     protected $name = "shop_goods_type";
 
 
-    public static function onAfterUpdate($model){
-        ShopGoodsTypeLogic::delCache();
-    }
-
-    public static function onAfterInsert(Model $model): void
-    {
-        ShopGoodsTypeLogic::delCache();
-    }
-
-    public static function onAfterDelete(Model $model): void
-    {
-        ShopGoodsTypeLogic::delCache();
-    }
 
 
 

+ 2 - 14
app/common/model/ShopHotKeywords.php

@@ -2,9 +2,7 @@
 
 namespace app\common\model;
 
-use app\admin\logic\ShopHotKeywordsLogic;
 use app\common\model\TimeModel;
-use think\Model;
 
 class ShopHotKeywords extends TimeModel
 {
@@ -13,17 +11,7 @@ class ShopHotKeywords extends TimeModel
 
     protected $deleteTime = false;
 
-    public static function onAfterUpdate($model){
-        ShopHotKeywordsLogic::delCache();
-    }
+    
+    
 
-    public static function onAfterInsert(Model $model): void
-    {
-        ShopHotKeywordsLogic::delCache();
-    }
-
-    public static function onAfterDelete(Model $model): void
-    {
-        ShopHotKeywordsLogic::delCache();
-    }
 }

+ 10 - 38
app/common/model/ShopOrderModel.php

@@ -298,12 +298,9 @@ class ShopOrderModel extends Model
                     'weight' => $goodsSpec['weight'], //重量
                     'total_fee' => bcmul($num, $goodsSpec['price'], 2), //总价
                     'rebate_score' => $goodsSpec['rebate_score'],//单个返利积分
-//                    'rebate_score_most' => bcmul($num, $goodsBase['rebate_score_most'], 2),//返回积分 马上
-//                    'rebate_score_lock' => bcmul($num, $goodsBase['rebate_score_lock'], 2),//返回积分 锁定
                     'total_items_rebate_score' => bcmul($num, $goodsSpec['rebate_score'], 2),//总返利积分
                     'spec_ids' => $goodsSpec['spec_ids'],
                     'spec_text' => $goodsSpec['spec_text'],
-//                    'coupon_num' => $goodsBase['coupon_num'],
                     'post_template_id' => $goodsBase['post_template_id'], //是否包邮,否就是运费模板ID
                     'stock' => $goodsSpec['stock'],
                     'supplier_name'=>$superlizer['name']
@@ -317,34 +314,13 @@ class ShopOrderModel extends Model
             foreach ($details as $k => $v) {
                 $details_arr[$v['goods_sn']]['goods'][] = $v;
                 $total_rebate_score = multi_array_sum($details_arr[$v['goods_sn']]['goods'], 'total_items_rebate_score');
-//                $total_rebate_most_score = multi_array_sum($details_arr[$v['goods_sn']]['goods'], 'rebate_score_most');
-//                $total_rebate_lock_score = multi_array_sum($details_arr[$v['goods_sn']]['goods'], 'rebate_score_lock');
                 $total_num = multi_array_sum($details_arr[$v['goods_sn']]['goods'], 'num');
                 $total_weight = multi_array_sum($details_arr[$v['goods_sn']]['goods'], 'weight');
                 $total_price = multi_array_sum($details_arr[$v['goods_sn']]['goods'], 'total_fee');
-//                $total_coupon_num = multi_array_sum($details_arr[$v['goods_sn']]['goods'], 'coupon_num');
                 $details_arr[$v['goods_sn']]['total_rebate_score'] = $total_rebate_score; //总返利积分
-//                $details_arr[$v['goods_sn']]['total_rebate_most_score'] = $total_rebate_most_score; // 返利积分马上到账
-//                $details_arr[$v['goods_sn']]['total_rebate_lock_score'] = $total_rebate_lock_score; //总返利积分
                 $details_arr[$v['goods_sn']]['total_num'] = $total_num; //总数量
                 $details_arr[$v['goods_sn']]['total_price'] = $total_price; //总金额
                 $details_arr[$v['goods_sn']]['total_weight'] = $total_weight; //总重量
-//                $details_arr[$v['goods_sn']]['total_coupon_num'] = $total_coupon_num * $total_num; //总抢购值
-                //获取运费
-//                if ($address) {
-//                    $details_arr[$v['goods_sn']]['post_fee'] = self::postFee(
-//                        $address['city'],
-//                        [
-//                            'goods_sn' => $v['goods_sn'],
-//                            'num' => $total_num,
-//                            'total_price' => $total_price,
-//                            'total_weight' => $details_arr
-//                        ],
-//                        $v['post_template_id']
-//                    );
-//                } else {
-//                    $details_arr[$v['goods_sn']]['post_fee'] = '0.00';
-//                }
                 $details_arr[$v['goods_sn']]['post_fee'] = '0.00';
                 $details_arr[$v['goods_sn']]['payment'] = bcadd($details_arr[$v['goods_sn']]['total_price'], $details_arr[$v['goods_sn']]['post_fee'], 2);
                 $details_arr[$v['goods_sn']]['supplier_name'] = $details[$key]['supplier_name'];
@@ -353,10 +329,7 @@ class ShopOrderModel extends Model
             $total = [
                 'count_payment' => sprintf("%.2f", multi_array_sum($details_arr, 'payment')),
                 'count_rebate_score' => (string)multi_array_sum($details_arr, 'total_rebate_score'),
-//                'count_rebate_most_score' => (string)multi_array_sum($details_arr, 'total_rebate_most_score'),
-//                'count_rebate_lock_score' => (string)multi_array_sum($details_arr, 'total_rebate_lock_score'),
                 'count_num' => multi_array_sum($details_arr, 'total_num'),
-//                'total_coupon_num' => multi_array_sum($details_arr, 'total_coupon_num')
             ];
 
             $details_arr = array_values($details_arr);
@@ -572,19 +545,19 @@ class ShopOrderModel extends Model
      */
     public static function checkingOrder ($order_sn, $userPayMoney, $userId)
     {
-        $order = self::where(['order_sn' => explode(',', $order_sn)])->select()->toArray();
+        $orderSnArr = $order_sn? explode(',', $order_sn) : [];
+        if(empty($orderSnArr)){
+            return ['flag' => 110, 'msg' => '订单参数错误'];
+        }
+        $field = 'order_id,payment,order_sn,total_price,ship_postfee,user_id,pay_type,order_type,rebate_score,status';
+        $order = self::where(['order_sn' => $orderSnArr,'user_id'=>$userId])->field($field)->select()->toArray();
         if (empty($order)) {
             return ['flag' => 110, 'msg' => '校验订单失败'];
         }
-        $orderPayment = multi_array_sum($order, 'payment');
-//        if ($orderPayment != $userPayMoney) {
-//            return ['flag' => 111, 'msg' => '金额错误'];
-//        }
-        foreach ($order as $k => $v) {
-            if ($v['user_id'] != $userId) {
-                return ['flag' => 112, 'msg' => '校验订单失败'];
-            }
+        if(count($order) != count($orderSnArr)){
+            return ['flag' => 110, 'msg' => '存在无效的订单'];
         }
+        $orderPayment = multi_array_sum($order, 'payment');
         return ['flag' => 200, 'msg' => '成功', 'orderPayment' => $orderPayment, 'order' => $order];
     }
 
@@ -654,8 +627,6 @@ class ShopOrderModel extends Model
         }
 
         self::where(['order_sn' => $data['order_sn']])->save(['status' => 4, 'updated_time' => $nowTime]);
-
-
     }
 
 
@@ -799,6 +770,7 @@ class ShopOrderModel extends Model
                 'status'=>1,
                 'num'=>1,
                 'order_type'=>5,
+                'order_source'=> '福袋单号:'.$hand_info['h_sn'],
                 'supplier_name'=>$supplier_info['name'],
                 'total_price'=>0,
                 'created_time'=>$cur_time,

+ 1 - 17
app/common/model/ShopSupplier.php

@@ -2,10 +2,7 @@
 
 namespace app\common\model;
 
-use app\admin\logic\ShopHotKeywordsLogic;
-use app\admin\logic\ShopSupplierLogic;
 use app\common\model\TimeModel;
-use think\Model;
 
 class ShopSupplier extends TimeModel
 {
@@ -14,20 +11,7 @@ class ShopSupplier extends TimeModel
 
     protected $deleteTime = false;
 
-
-    public static function onAfterUpdate($model){
-        ShopSupplierLogic::delCache();
-    }
-
-    public static function onAfterInsert(Model $model): void
-    {
-        ShopSupplierLogic::delCache();
-    }
-
-    public static function onAfterDelete(Model $model): void
-    {
-        ShopSupplierLogic::delCache();
-    }
+    
     
 
 }

+ 1 - 21
app/common/model/SystemFaq.php

@@ -6,31 +6,11 @@
 namespace app\common\model;
 
 
-use app\admin\logic\SystemFaqLogic;
-use think\Model;
+use app\common\model\TimeModel;
 
 class SystemFaq extends TimeModel
 {
     protected $name = "system_faq";
 
     protected $deleteTime = false;
-
-
-    public static function onAfterUpdate(Model $model)
-    {
-        SystemFaqLogic::delTitleCache($model->id);
-        SystemFaqLogic::delCache();
-    }
-
-    public static function onAfterInsert(Model $model): void
-    {
-        SystemFaqLogic::delTitleCache($model->id);
-        SystemFaqLogic::delCache();
-    }
-
-    public static function onAfterDelete(Model $model): void
-    {
-        SystemFaqLogic::delTitleCache($model->id);
-        SystemFaqLogic::delCache();
-    }
 }

+ 42 - 6
app/common/model/UserAddressModel.php

@@ -86,11 +86,15 @@ class UserAddressModel extends Model
     public function delUserAddress ($param)
     {
         try {
-            if (!self::where(['id' => $param->data['id']])->find()){
+            $addressId = isset($param->data['id'])? intval($param->data['id']) : 0;
+            if (!self::where(['id' => $addressId])->find()){
                 return api_error_return('参数错误');
             }
-            self::where(['id' => $param->data['id'], 'uid' => $param->uid])->delete();
+            self::where(['id' => $addressId, 'uid' => $param->uid])->delete();
+
+            // 清除缓存
             RedisCache::keyDel("caches:address:user:u_{$param->uid}_*");
+            RedisCache::clear("caches:address:info:{$addressId}");
         } catch (\Exception $e) {
             return api_error_return('删除失败');
         }
@@ -131,12 +135,44 @@ class UserAddressModel extends Model
     }
 
     /**
-     * @param int $addressId
+     * 获取地址信息/或用户默认地址
+     * @param int $addressId 地址ID,
+     * @param int $uid 用户ID,无地址ID必传
+     * @param int $returnDefault 是否返回默认地址
      * @return array
-     * 获取地址信息
      */
-    public static function getAddressIdDetails (int $addressId): array
+    public static function getAddressIdDetails (int $addressId, $uid=0, $returnDefault=0): array
     {
-        return self::where(['id'=>$addressId])->findOrEmpty()->toArray();
+        $cacheKey = "caches:address:info:{$addressId}_{$uid}_{$returnDefault}";
+        $data = RedisCache::get($cacheKey);
+        if($data){
+            return $data;
+        }
+
+        $field = 'a.id,a.uid,a.name,a.mobile,a.province, a1.name as sp_province,a.city,a2.name as sp_city,a.county,a3.name as sp_county,a.mergename,a.remark';
+        $data = self::alias('a')
+            ->leftJoin('area a1','a1.id=a.province')
+            ->leftJoin('area a2','a2.id=a.city')
+            ->leftJoin('area a3','a3.id=a.county')
+            ->where(function($query) use($addressId, $uid, $returnDefault){
+                if($uid){
+                    $query->where('a.uid', $uid);
+                }
+
+                if($addressId){
+                    $query->where('a.id', $addressId);
+                }else if($returnDefault){
+                    $query->where('a.is_default', 1);
+                }
+
+            })
+            ->field($field)
+            ->findOrEmpty()->toArray();
+
+        if($data){
+            RedisCache::set($cacheKey, $data, rand(5,10));
+        }
+
+        return $data;
     }
 }

+ 0 - 10
app/common/service/AddressService.php

@@ -1,15 +1,5 @@
 <?php
 
-// +----------------------------------------------------------------------
-// | EasyAdmin
-// +----------------------------------------------------------------------
-// | PHP交流群: 763822524
-// +----------------------------------------------------------------------
-// | 开源协议  https://mit-license.org 
-// +----------------------------------------------------------------------
-// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
-// +----------------------------------------------------------------------
-
 namespace app\common\service;
 
 use app\common\model\AddressModel;

+ 0 - 11
app/common/service/ArticleService.php

@@ -1,15 +1,4 @@
 <?php
-
-// +----------------------------------------------------------------------
-// | EasyAdmin
-// +----------------------------------------------------------------------
-// | PHP交流群: 763822524
-// +----------------------------------------------------------------------
-// | 开源协议  https://mit-license.org 
-// +----------------------------------------------------------------------
-// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
-// +----------------------------------------------------------------------
-
 namespace app\common\service;
 
 use app\common\model\SystemArticleModel;

+ 1 - 11
app/common/service/AuthService.php

@@ -1,15 +1,5 @@
 <?php
 
-// +----------------------------------------------------------------------
-// | EasyAdmin
-// +----------------------------------------------------------------------
-// | PHP交流群: 763822524
-// +----------------------------------------------------------------------
-// | 开源协议  https://mit-license.org 
-// +----------------------------------------------------------------------
-// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
-// +----------------------------------------------------------------------
-
 namespace app\common\service;
 
 use app\common\constants\AdminConstant;
@@ -17,7 +7,7 @@ use EasyAdmin\tool\CommonTool;
 use think\facade\Db;
 
 /**
- * 权限验证服务
+ * 权限验证服务 by wes
  * Class AuthService
  * @package app\common\service
  */

+ 0 - 10
app/common/service/ExpressDeliveryService.php

@@ -1,15 +1,5 @@
 <?php
 
-// +----------------------------------------------------------------------
-// | EasyAdmin
-// +----------------------------------------------------------------------
-// | PHP交流群: 763822524
-// +----------------------------------------------------------------------
-// | 开源协议  https://mit-license.org 
-// +----------------------------------------------------------------------
-// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
-// +----------------------------------------------------------------------
-
 namespace app\common\service;
 
 use app\common\model\ExpressDeliveryModel;

+ 0 - 10
app/common/service/LevelSettingService.php

@@ -1,15 +1,5 @@
 <?php
 
-// +----------------------------------------------------------------------
-// | EasyAdmin
-// +----------------------------------------------------------------------
-// | PHP交流群: 763822524
-// +----------------------------------------------------------------------
-// | 开源协议  https://mit-license.org 
-// +----------------------------------------------------------------------
-// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
-// +----------------------------------------------------------------------
-
 namespace app\common\service;
 
 use app\common\model\LevelSettingModel;

+ 31 - 12
app/common/service/MenuService.php

@@ -1,20 +1,16 @@
 <?php
 
-// +----------------------------------------------------------------------
-// | EasyAdmin
-// +----------------------------------------------------------------------
-// | PHP交流群: 763822524
-// +----------------------------------------------------------------------
-// | 开源协议  https://mit-license.org 
-// +----------------------------------------------------------------------
-// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
-// +----------------------------------------------------------------------
-
 namespace app\common\service;
 
 use app\common\constants\MenuConstant;
 use think\facade\Db;
+use utils\RedisCache;
 
+/**
+ * 菜单服务 by wes
+ * Class MenuService
+ * @package app\common\service
+ */
 class MenuService
 {
 
@@ -30,6 +26,7 @@ class MenuService
         return $this;
     }
 
+
     /**
      * 获取首页信息
      * @return array|\think\Model|null
@@ -62,6 +59,16 @@ class MenuService
         return $this->buildMenuChild(0, $this->getMenuData(),$authServer);
     }
 
+    /**
+     * 获取子菜单
+     * @param $pid
+     * @param $menuList
+     * @param AuthService $authServer
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
     private function buildMenuChild($pid, $menuList, AuthService $authServer)
     {
         $treeList = [];
@@ -84,13 +91,20 @@ class MenuService
 
     /**
      * 获取所有菜单数据
-     * @return \think\Collection
+     * @param bool $cache
+     * @return array|mixed|\think\Collection|Db[]
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    protected function getMenuData()
+    protected function getMenuData($cache=true)
     {
+        $cacheKey = "caches:temp:menus:all";
+        $data = RedisCache::get($cacheKey);
+        if($data && $cache){
+            return $data;
+        }
+
         $menuData = Db::name('system_menu')
             ->field('id,pid,title,icon,href,target')
             ->where("delete_time is null")
@@ -103,6 +117,11 @@ class MenuService
                 'id'   => 'asc',
             ])
             ->select();
+        if($menuData && $cache){
+            $menuData = $menuData->toArray();
+            RedisCache::set($cacheKey, $menuData, 7200);
+        }
+
         return $menuData;
     }
 

+ 0 - 10
app/common/service/ShopGoodsMenuService.php

@@ -1,15 +1,5 @@
 <?php
 
-// +----------------------------------------------------------------------
-// | EasyAdmin
-// +----------------------------------------------------------------------
-// | PHP交流群: 763822524
-// +----------------------------------------------------------------------
-// | 开源协议  https://mit-license.org 
-// +----------------------------------------------------------------------
-// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
-// +----------------------------------------------------------------------
-
 namespace app\common\service;
 
 use app\common\model\ShopGoodsMenuModel;

+ 36 - 14
app/common/service/ShopGoodsService.php

@@ -1,15 +1,5 @@
 <?php
 
-// +----------------------------------------------------------------------
-// | EasyAdmin
-// +----------------------------------------------------------------------
-// | PHP交流群: 763822524
-// +----------------------------------------------------------------------
-// | 开源协议  https://mit-license.org 
-// +----------------------------------------------------------------------
-// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
-// +----------------------------------------------------------------------
-
 namespace app\common\service;
 
 use app\common\model\GoodsAttensionModel;
@@ -158,7 +148,12 @@ class ShopGoodsService
      */
     public function updateScanCount($goodsId)
     {
-       return $goodsId?$this->model->where(['goods_id'=> $goodsId])->inc('scan_count',1)->update():false;
+        if($goodsId && $this->model->where(['goods_id'=> $goodsId])->inc('scan_count',1)->update()){
+            RedisCache::keyDel('caches:goods:list_*');
+            return true;
+        }
+
+       return false;
     }
 
     /**
@@ -274,13 +269,40 @@ class ShopGoodsService
             return $info;
         }
 
-        $field? $field : 'id,goods_type,restrictions_num';
-        $info = $this->model->where(['goods_sn'=> $goodsSn])->field($field)->find();
+        $field = $field? $field : 'a.goods_id,a.goods_sn,a.post_template_id,a.give_vip,a.goods_type,a.restrictions_num,a.rebate_score,a.goods_name,a.category,a.goods_img,a.supplier,s.name as supplier_name';
+        $info = $this->model->alias('a')
+            ->leftJoin('shop_supplier s','s.id = a.supplier')
+            ->where(['a.goods_sn'=> $goodsSn])
+            ->field($field)
+            ->find();
         $info = $info? $info->toArray() : [];
         if($info && $cache){
-            RedisCache::set($cacheKey, $info, rand(5, 10));
+            RedisCache::set($cacheKey, $info, rand(50, 100));
         }
 
         return $info;
     }
+
+    /**
+     * 按编号获取商品列表
+     * @param $snArr 编号数组
+     * @param string $field
+     * @return ShopGoodsModel|array|mixed|\think\Model
+     */
+    public function getListBySn($snArr, $field='')
+    {
+        $cacheKey = "caches:goods:listSn:".md5(json_encode($snArr, 256).$field);
+        $data = RedisCache::get($cacheKey);
+        if($data){
+            return $data;
+        }
+        $field = $field? $field : 'goods_type';
+        $data = $this->model->whereIn('goods_sn', $snArr)->field($field)->findOrEmpty();
+        if($data){
+            $data = $data->toArray();
+            RedisCache::set($cacheKey, $data, rand(5, 10));
+        }
+
+        return $data;
+    }
 }

+ 0 - 10
app/common/service/ShopGoodsSpecRelationService.php

@@ -1,15 +1,5 @@
 <?php
 
-// +----------------------------------------------------------------------
-// | EasyAdmin
-// +----------------------------------------------------------------------
-// | PHP交流群: 763822524
-// +----------------------------------------------------------------------
-// | 开源协议  https://mit-license.org 
-// +----------------------------------------------------------------------
-// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
-// +----------------------------------------------------------------------
-
 namespace app\common\service;
 
 use app\common\model\ShopGoodsSpecRelationModel;

+ 54 - 10
app/common/service/ShopGoodsSpecService.php

@@ -1,15 +1,5 @@
 <?php
 
-// +----------------------------------------------------------------------
-// | EasyAdmin
-// +----------------------------------------------------------------------
-// | PHP交流群: 763822524
-// +----------------------------------------------------------------------
-// | 开源协议  https://mit-license.org 
-// +----------------------------------------------------------------------
-// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
-// +----------------------------------------------------------------------
-
 namespace app\common\service;
 use app\common\model\ShopGoodsSpec;
 use utils\RedisCache;
@@ -75,5 +65,59 @@ class ShopGoodsSpecService
         return $data;
     }
 
+    /**
+     * 获取商品规格库存
+     * @param $goodsSn 商品编号
+     * @param $specIds
+     * @return array|mixed
+     */
+    public function getStock($goodsSn, $specIds)
+    {
+        $cacheKey = "caches:goodsSpec:stock:{$goodsSn}_".md5($specIds);
+        $data = RedisCache::get($cacheKey);
+        if($data){
+            return $data;
+        }
+
+        $data = $this->model->where(['goods_sn'=> $goodsSn,'spec_ids'=> $specIds])->value('stock');
+        if($data){
+            RedisCache::set($cacheKey, $data, rand(3,5));
+        }
+
+        return $data;
+    }
+
+    /**
+     * 获取商品规格数据
+     * @param $goodsId
+     * @param $specIds
+     * @param string $field
+     * @param bool $cache
+     * @return array|false|mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getDataByGoods($goodsId, $specIds, $field='', $cache=true)
+    {
+        if($goodsId<=0){
+            return false;
+        }
+
+        $cacheKey = "caches:goodsSpec:list_{$goodsId}".($specIds? '_'.md5(json_encode($specIds, 256)):'');
+        $data = RedisCache::get($cacheKey);
+        if($data && $cache){
+            return $data;
+        }
+
+        $where = ['goods_id'=> $goodsId];
+        $field = $field? $field : 'goods_spec_id,spec_ids,spec_text,original_price,price,rebate_score,weight,picture,stock';
+        $data = $this->model->where($where)->field($field)->find();
+        $data = $data? $data->toArray():[];
+        if($data && $cache){
+            RedisCache::set($cacheKey, $data, rand(3, 5));
+        }
 
+        return $data;
+    }
 }

+ 42 - 16
app/common/service/SystemConfigService.php

@@ -1,14 +1,5 @@
 <?php
 
-// +----------------------------------------------------------------------
-// | EasyAdmin
-// +----------------------------------------------------------------------
-// | PHP交流群: 763822524
-// +----------------------------------------------------------------------
-// | 开源协议  https://mit-license.org 
-// +----------------------------------------------------------------------
-// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
-// +----------------------------------------------------------------------
 
 namespace app\common\service;
 
@@ -53,7 +44,7 @@ class SystemConfigService
      */
     public function getConfigByGroup($groupKey)
     {
-        $cacheKey = "caches:config:group:{$groupKey}";
+        $cacheKey = "caches:sysconfig:group:{$groupKey}";
         $data = RedisCache::get($cacheKey);
         if($data){
             return $data;
@@ -61,7 +52,7 @@ class SystemConfigService
         $where = ['group'=> $groupKey];
         $data = $this->model->where($where)->column('id,name,group,value,remark','name');
         if($data){
-            RedisCache::set($cacheKey, $data, rand(10,20));
+            RedisCache::set($cacheKey, $data, 7200);
         }
 
         return $data;
@@ -79,23 +70,58 @@ class SystemConfigService
      */
     public function getConfigByName($name, $type=1, $groupKey='')
     {
-        $cacheKey = "caches:config:info:{$name}_{$type}{$groupKey}";
+        $cacheKey = "caches:sysconfig:info:{$name}_{$type}{$groupKey}";
+        $data = RedisCache::get($cacheKey);
+        if(!RedisCache::exists($cacheKey)) {
+
+            $where = ['name' => $name];
+            if ($groupKey) {
+                $where['group'] = $groupKey;
+            }
+            if ($type == 1) {
+                $data = $this->model->where($where)->value('value');
+            } else {
+                $data = $this->model->where($where)->field('id,name,group,value,remark')->find();
+                $data = $data? $data->toArray() : [];
+            }
+
+            if ($data) {
+                RedisCache::set($cacheKey, $data, 3 * 24 * 3600);
+            }
+        }
+
+        return $data;
+    }
+
+    /**
+     * 按配置名获取配置信息或者值
+     * @param array $names 配置名多个数组
+     * @param int $type 返回类型:1-返回值,2-返回列信息
+     * @param string $groupKey 分组
+     * @return SystemConfig|array|mixed|\think\Model|null
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getConfigByNames(array $names, $type=1, $groupKey='')
+    {
+        $cacheKey = "caches:sysconfig:info:{$type}_{$groupKey}_".md5(json_encode($names));
         $data = RedisCache::get($cacheKey);
         if($data){
             return $data;
         }
-        $where = ['name'=> $name];
+        $where = [];
         if($groupKey){
             $where['group'] = $groupKey;
         }
         if($type == 1){
-            $data = $this->model->where($where)->value('value');
+            $data = $this->model->whereIn('name',$names)->where($where)->column('value','name');
         }else{
-            $data = $this->model->where($where)->field('id,name,group,value,remark')->find();
+            $data = $this->model->whereIn('name',$names)->where($where)->column('id,name,group,value,remark','name');
         }
 
         if($data){
-            RedisCache::set($cacheKey, $data, rand(10,20));
+            RedisCache::set($cacheKey, $data, 3*24*3600);
         }
 
         return $data;

+ 26 - 13
extend/utils/AliPay.php

@@ -12,6 +12,7 @@ use Alipay\EasySDK\Kernel\Util\ResponseChecker;
 use Alipay\EasySDK\Kernel\Config;
 use alipay\request\AlipayFundTransToaccountTransferRequest;
 use alipay\request\AlipayTradeAppPayRequest;
+use app\common\service\PayConfigService;
 use think\Exception;
 use think\facade\Db;
 
@@ -30,7 +31,6 @@ class AliPay
     private static $signType = 'RSA2';
     private static $postCharset = 'utf-8';
     private static $format = 'json';
-//    private static $notifyUrl = 'http://zy.suncorex.com:2080/api/aliResult';
     private static $notifyUrl = 'https://api.meikangjw.com/api/aliResult';
     private $class;
 
@@ -79,16 +79,21 @@ class AliPay
                 'subject' => $param['body'],
                 'out_trade_no' => $param['out_trade_no'],
             ];
-//            $request->setNotifyUrl(self::$notifyUrl);
-            $request->setNotifyUrl(getWebUrl().'/api/aliResult');
+            $notifyUrl = getWebUrl().'/api/aliResult';
+            $cacheKey = "caches:payment:alipay:otn_{$param['out_trade_no']}:";
+            RedisCache::set($cacheKey."unifiedOrder", ['url'=>self::$gatewayUrl,'notifyUrl'=> $notifyUrl,'params'=>$arrData,'date'=>date('Y-m-d H:i:s')], 7200);
+
+            $request->setNotifyUrl($notifyUrl);
             $request->setBizContent(json_encode($arrData, JSON_UNESCAPED_UNICODE));
             $result = $this->class->sdkExecute($request);
+            RedisCache::set($cacheKey."uni_result", ['url'=>self::$gatewayUrl,'notifyUrl'=> $notifyUrl,'params'=>$arrData,'date'=>date('Y-m-d H:i:s')], 7200);
+
             if (!empty($result))
                 return ['flag' => true, 'msg' => '调用成功', 'data' => ['result' => $result]];
             else
                 return ['flag' => false, 'msg' => "统一下单失败"];
         } catch (\Exception $e) {
-//            return ['flag' => false, 'msg' => "统一下单失败"];
+            RedisCache::set("caches:payment:alipay:otn_{$param['out_trade_no']}:uni_error", ['error'=>'调用错误:'.$e->getMessage(),'url'=>self::$gatewayUrl,'params'=>$param,'date'=>date('Y-m-d H:i:s')], 7200);
             return ['flag' => false, 'msg' => $e->getMessage()];
         }
     }
@@ -101,15 +106,19 @@ class AliPay
     public function easyUnifiedOrder (array $param)
     {
         try {
+            $cacheKey = "caches:payment:alipay:otn_{$param['out_trade_no']}:";
+            RedisCache::set($cacheKey."easyUnifiedOrder", ['params'=>$param,'date'=>date('Y-m-d H:i:s')], 7200);
             $result = Factory::payment()->common()->create($param['body'], $param['out_trade_no'], $param['total_amount'], null);
             $responseChecker = new ResponseChecker();
             //3. 处理响应或异常
+            RedisCache::set($cacheKey."easy_result", ['params'=>$param,'result'=>$result,'date'=>date('Y-m-d H:i:s')], 7200);
             if ($responseChecker->success($result)) {
                 return ['flag' => true, 'msg' => '调用成功', 'data' => $result];
             } else {
                 return ['flag' => false, 'msg' => "调用失败,原因:" . $result->msg . "," . $result->subMsg . PHP_EOL];
             }
         } catch (\Exception $e) {
+            RedisCache::set("caches:payment:alipay:otn_{$param['out_trade_no']}:easy_error", ['msg'=>'调用失败:'.$e->getMessage(). PHP_EOL,'params'=>$param,'date'=>date('Y-m-d H:i:s')], 7200);
             return ['flag' => false, 'msg' => "调用失败," . $e->getMessage() . PHP_EOL];
         }
     }
@@ -125,8 +134,7 @@ class AliPay
 
         $aop = new AopClient();
         $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
-        $conf = Db::name('pay_config')->where('status', 1)->where('channel', 1)->field('public_key,app_id,private_key,app_cert_path,pay_root_cert,pay_cert_path,mchid')->find();
-        sr_log(json_encode($conf));
+        $conf = PayConfigService::make()->getInfoByChannel(1);
         $aop->appId = $conf['app_id'];
         $aop->rsaPrivateKey = $conf['private_key']; // 应用私钥
         $aop->alipayrsaPublicKey = $conf['public_key']; // 支付宝公钥
@@ -135,9 +143,9 @@ class AliPay
         $aop->signType = 'RSA2';
         $aop->postCharset = 'utf-8';
         $aop->format = 'json';
-
+        $outBizNo = time() . rand(10000, 99999) . $param['uid'];
         $bizContent = [
-            'out_biz_no' => time() . rand(10000, 99999) . $param['uid'],
+            'out_biz_no' => $outBizNo,
             'trans_amount' => $param['practical_money'],
             'product_code' => 'TRANS_ACCOUNT_NO_PWD',
             'biz_scene' => 'DIRECT_TRANSFER',
@@ -150,11 +158,13 @@ class AliPay
             'remark' => '用户提现'
         ];
 
-
+        // 缓存日志
+        $cacheKey = "caches:withdraw:catchOrder:no_{$outBizNo}:";
+        RedisCache::set($cacheKey.'params', ['url'=>$aop->gatewayUrl,'appid'=>$aop->appId,'params'=>$bizContent], 7200);
         $request = new AlipayFundTransToaccountTransferRequest();
         $request->setBizContent(json_encode($bizContent, JSON_UNESCAPED_UNICODE));
         $result = $aop->execute($request);
-//        sr_log('code'. json_encode($result));
+        RedisCache::set($cacheKey.'result', ['url'=>$aop->gatewayUrl,'appid'=>$aop->appId,'params'=>$bizContent,'result'=>$result], 7200);
         if (!$result) {
             return ['flag' => false, 'msg' => '系统出错'];
         }
@@ -164,7 +174,6 @@ class AliPay
         if (!empty($resultCode) && $resultCode == 10000) {
             return ['flag' => true, 'data' => ['out_biz_no' => $result->{$responseNode}->out_biz_no]];
         } else {
-//            sr_log($request->{$responseNode}->sub_msg);
             return ['flag' => false, 'msg' => $request->{$responseNode}->sub_msg];
         }
     }
@@ -185,6 +194,7 @@ class AliPay
                 return Factory::payment()->common()->verifyNotify($param);
             }
         } catch (\Exception $e) {
+            RedisCache::set('caches:payment:alipay:signError', ['msg'=>'签名错误','date'=>date('Y-m-d H:i:s')], 7200);
             return false;
         }
     }
@@ -216,9 +226,12 @@ class AliPay
      */
     static protected function payConfig ()
     {
-        $conf = Db::name('pay_config')->where('status', 1)->where('channel', 1)->field('app_id,private_key,app_cert_path,pay_root_cert,pay_cert_path,mchid')->find();
-        if (empty($conf))
+        $conf = PayConfigService::make()->getInfoByChannel(1);
+        if (empty($conf)){
+            RedisCache::set('caches:payment:alipay:error', ['msg'=>'获取支付配置错误','date'=>date('Y-m-d H:i:s')], 7200);
             throw new Exception('支付宝配置错误');
+        }
+
         self::$appCertPath = $conf['app_cert_path']; //应用公钥证书
         self::$alipayCertPath = $conf['pay_cert_path'];//支付宝公钥证书
         self::$rootCertPath = $conf['pay_root_cert'];//支付宝根证书