Parcourir la source

Merge commit 'cfb0f5263e621f829be2f266540e753ec4b87c37' into dev

ith5 il y a 5 mois
Parent
commit
ad79a2ed25

+ 2 - 1
app/process/CreateTables.php

@@ -346,7 +346,8 @@ class CreateTables
   `pay_channel_id` smallint(6) DEFAULT '0' COMMENT '支付渠道ID',
   `money` float NOT NULL COMMENT '面额(元)',
   `paid_amount` float unsigned NOT NULL COMMENT '净额(元)',
-  `game_id` int(11) NOT NULL DEFAULT '0',
+  `main_id` int(11) NOT NULL DEFAULT '0' COMMENT '主包ID',
+  `game_id` int(11) NOT NULL DEFAULT '0' COMMENT '游戏ID',
   `media_id` int(11) NOT NULL DEFAULT '0' COMMENT '媒体ID',
   `auth_id` int(11) NOT NULL DEFAULT '0' COMMENT '负责人ID',
   `agent_id` int(11) NOT NULL DEFAULT '0',

+ 6 - 6
app/v1/logic/customer/ReconciliationLogic.php

@@ -21,11 +21,11 @@ class ReconciliationLogic extends BaseLogic
         }
 
         if (!empty($params['pay_channel_id'])) {
-            $channelIncomeQuery->where('pay_channel_id', 'in', is_array($params['pay_channel_id']) ? implode(',', $params['pay_channel_id']) : $params['pay_channel_id']);
+            $channelIncomeQuery->where('pay_channel_id', $params['pay_channel_id']);
         }
 
         if (!empty($params['game_id'])) {
-            $channelIncomeQuery->where('game_id', 'in', is_array($params['game_id']) ? implode(',', $params['game_id']) : $params['game_id']);
+            $channelIncomeQuery->where('game_id', $params['game_id']);
         }
 
         $channelIncomeQuery->field('game_id,pay_channel_id,sum(money) as money');
@@ -37,17 +37,17 @@ class ReconciliationLogic extends BaseLogic
             [
                 'title' => '游戏ID',
                 'dataIndex' => 'game_id',
-                'width' => 180,
+                'width' => 100,
             ],
             [
                 'title' => '游戏名称',
                 'dataIndex' => 'game_name',
-                'width' => 180,
+                'width' => 150,
             ],
             [
                 'title' => '合计',
                 'dataIndex' => 'money',
-                'width' => 180,
+                'width' => 100,
             ],
         ];
 
@@ -65,7 +65,7 @@ class ReconciliationLogic extends BaseLogic
             $columns[] = [
                 'title' => $title,
                 'dataIndex' => 'pay_channel_id_' . $payChannelId,
-                'width' => 180,
+                'width' => 120,
             ];
         }
 

+ 26 - 92
app/v1/logic/customer/SdkOrderLogic.php

@@ -26,107 +26,41 @@ class SdkOrderLogic extends BaseLogic
     /**
      * 获取订单列表
      */
-    public function getOrderList($where)
+    public function getOrderList($params)
     {
-        $startDate = $where['pay_date'][0];
-        $endDate = $where['pay_date'][1];
-        $page = max(1, (int)($where['page'] ?? 1));
-        $limit = max(1, (int)($where['limit'] ?? 10));
-        $offset = ($page - 1) * $limit;
-        $orderBy = $where['orderBy'] ?: 'pay_date';
-        $orderType = $where['orderType'] ?: 'DESC';
-        $orderBy = $orderBy . ' ' . $orderType;
+        $orderBy = $params['orderBy'] ?: 'pay_date';
+        $orderType = $params['orderType'] ?: 'DESC';
 
-        // 获取年月
-        $table_name_array = $this->queryOrdersByDateRange($startDate, $endDate);
-
-        // 合并表 union all
-        $where_sql = "";
-        if (!empty($where['game_id'])) {
-            $where_sql .= " AND game_id IN({$where['game_id']})";
-        }
-        if (!empty($where['user_name'])) {
-            $where_sql .= " AND user_name = '{$where['user_name']}'";
-        }
-        if (!empty($where['order_id'])) {
-            $where_sql .= " AND order_id = '{$where['order_id']}'";
-        }
-        if (!empty($where['trade_id'])) {
-            $where_sql .= " AND trade_id = '{$where['trade_id']}'";
-        }
-        if (!empty($where['role_id'])) {
-            $where_sql .= " AND role_id = '{$where['role_id']}'";
+        if(!$params['pay_date']){
+            throw new ApiException('请选择时间范围');
         }
-        if (!empty($where['role_name'])) {
-            $where_sql .= " AND role_name = '{$where['role_name']}'";
-        }
-        if (!empty($where['pay_date'])) {
-            $where_sql .= " AND pay_date BETWEEN '{$startDate} 00:00:00' AND '{$endDate} 23:59:59'";
-        }
-        $sql_parts = [];
-        foreach ($table_name_array as $table_name) {
-            $sql_parts[] = "SELECT * FROM sdk_order_{$table_name} WHERE 1=1 {$where_sql}";
-        }
-        if (empty($sql_parts)) {
-            return []; // 或抛异常,或返回空结果
+        // 获取年月
+        $monthRange = getMonthsBetweenDates($params['pay_date'][0], $params['pay_date'][1]);
+
+        $eqWhere = ["game_id", "user_name", "order_id", "trade_id", "role_id", "role_name"];
+        $where = [];
+        foreach ($eqWhere as $field){
+            if (!empty($params[$field])) {
+                $where[$field] = $params[$field];
+            }
         }
+        $where[] = ['pay_date', 'between', [$params['pay_date'][0]." 00:00:00", $params['pay_date'][1]." 23:59:59"]];
 
-        $unionSql = implode(" UNION ALL ", $sql_parts);
-
-        // 外层包裹分页、排序
-        $finalSql = "
-            SELECT * FROM ( {$unionSql} ) AS all_orders
-            ORDER BY {$orderBy}
-            LIMIT {$offset}, {$limit}
-        ";
-
-        // 统计总数(用于分页)
-        $countSql = "
-            SELECT COUNT(*) AS total FROM ( {$unionSql} ) AS count_orders
-        ";
-
-        // 总金额查询
-        $sumSql = "
-            SELECT ROUND(SUM(money), 2) AS money_sum FROM (
-                {$unionSql}
-            ) AS sum_orders
-        ";
-
-        $count = Db::connect('db_game_log')->query($countSql)[0]['total'] ?? 0;
-
-        $data = Db::connect('db_game_log')->query($finalSql);
-
-        $moneySum = Db::connect('db_game_log')->query($sumSql)[0]['money_sum'] ?? 0;
+        $db = Db::connect('db_game_log');
+        $unionQuery = [];
+        foreach ($monthRange as $month){
+            $tableName = 'sdk_order_' . $month;
+            $unionQuery[] = $db->table($tableName)->where($where)->buildSql();
+        }
+        $fullSql = "(" . implode(' UNION ALL ', $unionQuery) . ") as unTable";
 
-        $data = $this->trandformListColumn($data, ['game', 'pay_channel']);
+        $list = $db->table($fullSql)->order($orderBy, $orderType)->paginate($params['limit'])->toArray();
 
+        $list['data'] = $this->trandformListColumn($list['data'], ['game', 'pay_channel']);
 
-        return [
-            'total' => $count,
-            'current_page' => $page,
-            'per_page' => $limit,
-            'last_page' => ceil($count / $limit),
-            'has_more' => $page < ceil($count / $limit),
-            'data' => $data,
-            'totalRow' => $moneySum
-        ];
-    }
+        $list['totalRow'] = $db->table($fullSql)->where(["sync_status"=>1])->value("round(sum(money), 2)");
 
-    /**
-     * 获取年月
-     */
-    public function queryOrdersByDateRange($start, $end)
-    {
-        $start = new DateTime($start);
-        $end = new DateTime($end);
-        $end->modify('first day of next month');
-
-        $months = [];
-        while ($start < $end) {
-            $months[] = $start->format('Ym'); // 例如 202505
-            $start->modify('+1 month');
-        }
-        return $months;
+        return $list;
     }
 
     /**

+ 4 - 2
app/v1/logic/dataReport/UserLogLogic.php

@@ -15,6 +15,8 @@ class UserLogLogic extends BaseLogic
     // 注册日志
     public function getRegLogList($where): mixed
     {
+        $orderBy = request()->input('orderBy', 'reg_time');
+        $orderType = request()->input('orderType', 'desc');
         $params = $this->searchByAuth($where);
         $limit = request()->input('limit', 10);
 
@@ -46,7 +48,7 @@ class UserLogLogic extends BaseLogic
         }
         $fullSql = "(" . implode(' UNION ALL ', $unionQuery) . ") as unTable";
 
-        return $db->table($fullSql)->paginate($limit)->toArray();
+        return $db->table($fullSql)->order($orderBy, $orderType)->paginate($limit)->toArray();
     }
 
     // 登录日志
@@ -101,7 +103,7 @@ class UserLogLogic extends BaseLogic
         }
         $fullSql = "(" . implode(' UNION ALL ', $unionQuery) . ") as unTable";
 
-        return $db->table($fullSql)->paginate($limit)->toArray();
+        return $db->table($fullSql)->order($orderBy, $orderType)->paginate($limit)->toArray();
     }
 
     // 充值明细