Bladeren bron

feat:商户数据

aiden 3 maanden geleden
bovenliggende
commit
4b81575c4f
3 gewijzigde bestanden met toevoegingen van 53 en 5 verwijderingen
  1. 33 1
      app/controller/MerchantStatis.php
  2. 18 4
      app/model/MerchantStatisModel.php
  3. 2 0
      route/app.php

+ 33 - 1
app/controller/MerchantStatis.php

@@ -11,7 +11,7 @@ use think\facade\Request;
 class MerchantStatis extends BaseController
 {
     /**
-     * 获取商户每日数据列表
+     * 获取商户每日数据
      */
     public function Daily()
     {
@@ -51,6 +51,38 @@ class MerchantStatis extends BaseController
             return json_error([], '获取商户每日数据失败:' . $e->getMessage());
         }
     }
+
+    /*
+     * 获取商户时间阶段数据统计
+     */
+    public function Stage()
+    {
+        $userInfo = $this->request->userInfo;
+        
+        // 筛选条件
+        $filters = [
+            // 时间筛选
+            'start_time' => Request::get('start_time', date('Y-m-d', strtotime('-7 days')), 'trim'),
+            'end_time' => Request::get('end_time', date('Y-m-d'), 'trim'),
+        ];
+
+        try {
+            // 获取商户每日数据
+            $result = MerchantStatisModel::getMerchantHistory($userInfo['merchant_id'], $filters);
+            
+            // 格式化数据
+            $result['date_stage'] = implode(' ~ ', $filters);
+            $result['game_profit'] = CommonUtils::convertBalance($result['game_profit'], false);
+            $result['bet_amount'] = CommonUtils::convertBalance($result['bet_amount'], false);
+            $result['commission_amount'] = CommonUtils::convertBalance($result['game_profit'] * 0.08, false);
+            $result['platform_fee'] = CommonUtils::convertBalance($result['bet_amount'] * 0.08, false);
+            $result['buy_free_bet'] = 0;
+            
+            return json_success($result, '获取成功');
+        } catch (\Exception $e) {
+            return json_error([], '获取商户每日数据失败:' . $e->getMessage());
+        }
+    }    
             
     /**
      * 获取商户历史数据统计

+ 18 - 4
app/model/MerchantStatisModel.php

@@ -78,13 +78,27 @@ class MerchantStatisModel extends Model
     /**
      * 获取商户汇总统计
      */
-    public static function getMerchantHistory($merchantId)
+    public static function getMerchantHistory($merchantId, $filters = [])
     {
         $where = [
             ['app_id', '=', $merchantId]
         ];
+
+        $getWhere = function(string $timeField) use ($where, $filters) {
+            // 时间筛选
+            if (!empty($filters['start_time'])) {
+                $startTime = strtotime($filters['start_time']);
+                $where[] = [$timeField, '>=', $startTime];
+            }
+            
+            if (!empty($filters['end_time'])) {
+                $endTime = strtotime($filters['end_time']);
+                $where[] = [$timeField, '<=', $endTime];
+            }            
+            return $where;
+        };
         
-        $query = self::where($where);
+        $query = self::where($getWhere('create_time'));
         // 获取列表数据
         $data = $query->field([
                     'AVG(rtp) AS rtp', // 平均RTP
@@ -97,8 +111,8 @@ class MerchantStatisModel extends Model
             ->find()
             ->toArray();
         // 获取登录用户、注册用户 
-        $data['login_users'] = MerchantsUserModel::where([['login_time', '>', 0]])->count(); 
-        $data['register_users'] = MerchantsUserModel::count();  
+        $data['login_users'] = MerchantsUserModel::where($getWhere('login_time'))->count(); 
+        $data['register_users'] = MerchantsUserModel::where($getWhere('create_time'))->count();  
         
         return $data;
     }

+ 2 - 0
route/app.php

@@ -107,6 +107,8 @@ Route::group('transfer_log', function () {
 
 // 每日数据统计相关路由
 Route::group('merchant_statis', function () {
+    // 商户数据
+    Route::get('stage', 'MerchantStatis/Stage');
     // 商户每日数据
     Route::get('daily', 'MerchantStatis/Daily');
     // Route::get('merchant_summary', 'DailyStatistics/merchantSummary');