|
@@ -0,0 +1,152 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+// +----------------------------------------------------------------------
|
|
|
|
|
+// | saiadmin [ saiadmin快速开发框架 ]
|
|
|
|
|
+// +----------------------------------------------------------------------
|
|
|
|
|
+// | Author: your name
|
|
|
|
|
+// +----------------------------------------------------------------------
|
|
|
|
|
+namespace app\v1\logic\customer;
|
|
|
|
|
+
|
|
|
|
|
+use plugin\saiadmin\basic\BaseLogic;
|
|
|
|
|
+use plugin\saiadmin\exception\ApiException;
|
|
|
|
|
+use plugin\saiadmin\utils\Helper;
|
|
|
|
|
+use app\v1\model\customer\SdkOrder;
|
|
|
|
|
+use DateTime;
|
|
|
|
|
+use support\Redis;
|
|
|
|
|
+use support\think\Db;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 用户订单记录逻辑层
|
|
|
|
|
+ */
|
|
|
|
|
+class SdkOrderLogic extends BaseLogic
|
|
|
|
|
+{
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 构造函数
|
|
|
|
|
+ */
|
|
|
|
|
+ public function __construct()
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->model = new SdkOrder();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取年月
|
|
|
|
|
+ */
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取订单列表
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getOrderList($where)
|
|
|
|
|
+ {
|
|
|
|
|
+ $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'] ? $where['orderBy'] : 'pay_date';
|
|
|
|
|
+ $orderType = $where['orderType'] ? $where['orderType'] : 'DESC';
|
|
|
|
|
+ $orderBy = $orderBy . ' ' . $orderType;
|
|
|
|
|
+
|
|
|
|
|
+ // 获取年月
|
|
|
|
|
+ $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(!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 注入
|
|
|
|
|
+ if (!preg_match('/^\d{6}$/', $table_name)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ $sql_parts[] = "SELECT * FROM sdk_order_{$table_name} WHERE 1=1 {$where_sql}";
|
|
|
|
|
+ }
|
|
|
|
|
+ if (empty($sql_parts)) {
|
|
|
|
|
+ return []; // 或抛异常,或返回空结果
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $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;
|
|
|
|
|
+
|
|
|
|
|
+ $data = $this->trandformListColumn($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
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 补发
|
|
|
|
|
+ */
|
|
|
|
|
+ public function send($orderid)
|
|
|
|
|
+ {
|
|
|
|
|
+ $res = Redis::lpush("request_cp_callback_queue", $orderid);
|
|
|
|
|
+ return $res;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|