Bläddra i källkod

wesmiler 报恩寺项目提交

wesmiler 4 år sedan
förälder
incheckning
307548c832

+ 10 - 0
app/Http/Controllers/IndexController.php

@@ -20,6 +20,7 @@ use App\Models\AdminRomModel;
 use App\Services\AdminService;
 use App\Services\AdminService;
 use App\Services\MenuService;
 use App\Services\MenuService;
 use App\Services\RedisService;
 use App\Services\RedisService;
+use App\Services\TradeService;
 use App\Services\UserService;
 use App\Services\UserService;
 
 
 /**
 /**
@@ -155,6 +156,15 @@ class IndexController extends Backend
         return message(MESSAGE_OK,true, $datas);
         return message(MESSAGE_OK,true, $datas);
     }
     }
 
 
+    /**
+     * 获取消费排名
+     * @return array
+     */
+    public function tradeRank(){
+        $datas = TradeService::make()->ranks();
+        return message(MESSAGE_OK,true, $datas);
+    }
+
 
 
     public function statisticsTable(){
     public function statisticsTable(){
         $type = request()->get('type', 'trade');
         $type = request()->get('type', 'trade');

+ 24 - 3
app/Services/NotifyService.php

@@ -255,11 +255,11 @@ class NotifyService extends BaseService
         $data = [
         $data = [
             'user_id'=> $userId,
             'user_id'=> $userId,
             'type'=> 2,
             'type'=> 2,
-            'coin_type'=> 1,
+            'coin_type'=> 2,
             'pay_type'=> 2,
             'pay_type'=> 2,
             'money'=> moneyFormat($payMoney/100),
             'money'=> moneyFormat($payMoney/100),
-            'change_type'=> 1,
-            'balance'=> $memberInfo->coupon? $memberInfo->coupon : 0,
+            'change_type'=> 2,
+            'balance'=> 0,
             'create_time'=> time(),
             'create_time'=> time(),
             'remark'=> '充值订单支付',
             'remark'=> '充值订单支付',
             'status'=> 1
             'status'=> 1
@@ -271,6 +271,27 @@ class NotifyService extends BaseService
             return NotifyService::rebackMsg('处理交易明细失败', 'error');
             return NotifyService::rebackMsg('处理交易明细失败', 'error');
         }
         }
 
 
+        if($num>0){
+            $data = [
+                'user_id'=> $userId,
+                'type'=> 2,
+                'coin_type'=> 1,
+                'pay_type'=> 1,
+                'money'=> $num,
+                'change_type'=> 1,
+                'balance'=> $memberInfo->coupon? $memberInfo->coupon : 0,
+                'create_time'=> time(),
+                'remark'=> '充值花灯券到账',
+                'status'=> 1
+            ];
+            if(!TradeModel::insertGetId($data)){
+                RedisService::set($errorKey.':error_account',['notify'=> $notifyData, 'error'=> '处理交易明细失败','order'=> $orderInfo
+                ], 3600);
+                DB::rollBack();
+                return NotifyService::rebackMsg('处理花灯券交易明细失败', 'error');
+            }
+        }
+
         DB::commit();
         DB::commit();
 
 
         return NotifyService::rebackMsg('支付处理成功','success');
         return NotifyService::rebackMsg('支付处理成功','success');

+ 39 - 0
app/Services/TradeService.php

@@ -14,6 +14,7 @@ namespace App\Services;
 use App\Models\ActionLogModel;
 use App\Models\ActionLogModel;
 use App\Models\MemberModel;
 use App\Models\MemberModel;
 use App\Models\TradeModel;
 use App\Models\TradeModel;
+use Illuminate\Support\Facades\DB;
 use function GuzzleHttp\Psr7\str;
 use function GuzzleHttp\Psr7\str;
 
 
 /**
 /**
@@ -25,6 +26,8 @@ use function GuzzleHttp\Psr7\str;
  */
  */
 class TradeService extends BaseService
 class TradeService extends BaseService
 {
 {
+    protected  static $instance = null;
+
     /**
     /**
      * 构造函数
      * 构造函数
      * @author wesmiler
      * @author wesmiler
@@ -37,6 +40,18 @@ class TradeService extends BaseService
     }
     }
 
 
     /**
     /**
+     * 静态入口
+     * @return TradeService|null
+     */
+    public static function make(){
+        if(!self::$instance){
+            self::$instance = new TradeService();
+        }
+
+        return self::$instance;
+    }
+
+    /**
      * 获取列表
      * 获取列表
      * @return array
      * @return array
      * @since 2020/11/11
      * @since 2020/11/11
@@ -162,6 +177,30 @@ class TradeService extends BaseService
     }
     }
 
 
     /**
     /**
+     * 消费排名
+     * @return mixed
+     */
+    public function ranks(){
+        $dataList = $this->model::from('account_logs as a')
+            ->leftJoin('member as m', 'm.id', '=', 'a.user_id')
+            ->where(['a.mark'=> 1,'m.mark'=> 1,'a.status'=> 1,'a.coin_type'=> 2,'a.pay_type'=> 2,'a.change_type'=> 2])
+            ->select(['m.avatar','m.nickname','a.id','a.user_id', \DB::raw('sum(a.money) as total')])
+            ->group('a.user_id')
+            ->orderBy(\DB::raw('sum(a.money)'),'desc')
+            ->orderBy('m.create_time','asc')
+            ->take(50)
+            ->get();
+        if($dataList){
+            foreach ($dataList as &$item){
+                $item['avatar'] = $item['avatar']? get_image_url($item['avatar']) : '';
+            }
+            unset($item);
+        }
+
+        return $dataList;
+    }
+
+    /**
      * 统计
      * 统计
      * @param $params
      * @param $params
      * @return mixed
      * @return mixed

+ 1 - 0
routes/web.php

@@ -77,6 +77,7 @@ Route::post('/index/updatePwd', [IndexController::class, 'updatePwd']);
 Route::post('/index/clearCache', [IndexController::class, 'clearCache']);
 Route::post('/index/clearCache', [IndexController::class, 'clearCache']);
 Route::post('/index/statistics', [IndexController::class, 'statistics']);
 Route::post('/index/statistics', [IndexController::class, 'statistics']);
 Route::post('/index/counts', [IndexController::class, 'counts']);
 Route::post('/index/counts', [IndexController::class, 'counts']);
+Route::post('/index/tradeRank', [IndexController::class, 'tradeRank']);
 
 
 // 用户管理
 // 用户管理
 Route::get('/user/index', [UserController::class, 'index']);
 Route::get('/user/index', [UserController::class, 'index']);