|
|
@@ -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;
|
|
|
}
|
|
|
|
|
|
/**
|