=', $startTime]; } if (!empty($filters['end_time'])) { $endTime = strtotime($filters['end_time'] . ' 23:59:59'); $where[] = ['create_time', '<=', $endTime]; } // 游戏筛选 if (!empty($filters['game_id'])) { $where[] = ['game_id', '=', $filters['game_id']]; } // 订单原因筛选(动作类型) if (!empty($filters['order_reason'])) { $where[] = ['action_type', '=', $filters['order_reason']]; } // 平台ID筛选 if (!empty($filters['uname'])) { $where[] = ['uname', '=', $filters['uname']]; } // 平台昵称筛选 if (!empty($filters['nickname'])) { $where[] = ['nickname', 'like', '%' . $filters['nickname'] . '%']; } // 玩家id筛选 if (!empty($filters['player_id'])) { $where[] = ['user_id', 'like', '%' . $filters['player_id'] . '%']; } // 订单状态筛选 if ($filters['order_status'] !== '') { $where[] = ['status', '=', $filters['order_status']]; } // 订单编号筛选 if (!empty($filters['third_order_id'])) { $where[] = ['third_order_id', 'like', '%' . $filters['third_order_id'] . '%']; } // 母单号筛选 if (!empty($filters['third_gid'])) { $where[] = ['third_gid', 'like', '%' . $filters['third_gid'] . '%']; } // 牌局编号筛选 if (!empty($filters['third_round_id'])) { $where[] = ['third_round_id', 'like', '%' . $filters['third_round_id'] . '%']; } $query = self::where($where); // 统计总数 $total = $query->count(); // 获取列表数据 $list = $query->field([ 'id', 'user_id', 'app_id', 'uname', 'nickname', 'third_gid', 'third_order_id', 'third_round_id', 'parent_id', 'game_id', 'game_type', 'status', 'message', 'amount', 'bet', 'prev_amount', 'next_amount', 'action_type', 'ip', 'err_desc', 'create_time', 'total_win_amount', 'total_amount' ]) ->order('id', 'desc') ->page($page, $limit) ->select() ->toArray(); return [ 'list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit ]; } /** * 获取订单详情 */ public static function getOrderDetail($id, $appId) { $order = self::where('id', $id) ->where('app_id', $appId) ->find(); if (!$order) { return null; } $order = $order->toArray(); $order = self::formatItemData($order); // 获取相关的子订单 if (!empty($order['third_gid'])) { $childOrders = self::getChildOrders([$order['third_gid']], $appId); $order['children'] = $childOrders; } // 游戏名称 $order['game_name'] = self::getGameName($order['game_id']); return $order; } /** * 获取订单统计信息 */ public static function getOrderStatistics($appId, $filters = []) { $where = [ ['app_id', '=', $appId], ['status', '=', 1] ]; // 时间筛选 if (!empty($filters['start_time'])) { $startTime = strtotime($filters['start_time'] . ' 00:00:00'); $where[] = ['create_time', '>=', $startTime]; } if (!empty($filters['end_time'])) { $endTime = strtotime($filters['end_time'] . ' 23:59:59'); $where[] = ['create_time', '<=', $endTime]; } $statistics = self::where($where) ->field([ 'COUNT(*) as total_orders', 'COUNT(DISTINCT uname) as total_players', 'SUM(CASE WHEN action_type = 1 THEN bet ELSE 0 END) as total_bet_amount', 'SUM(total_win_amount) as total_win_amount', 'SUM(CASE WHEN amount > 0 THEN amount ELSE 0 END) as total_profit', 'SUM(CASE WHEN amount < 0 THEN ABS(amount) ELSE 0 END) as total_loss', 'SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) as success_orders', 'SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END) as failed_orders', 'SUM(CASE WHEN status = 3 THEN 1 ELSE 0 END) as cancelled_orders' ]) ->find() ->toArray(); // 格式化金额 $statistics['total_bet_amount_yuan'] = self::convertBalance($statistics['total_bet_amount']); $statistics['total_win_amount_yuan'] = self::convertBalance($statistics['total_win_amount']); $statistics['total_profit_yuan'] = self::convertBalance($statistics['total_profit']); $statistics['total_loss_yuan'] = self::convertBalance($statistics['total_loss']); $net_amount = $statistics['total_bet_amount'] - $statistics['total_win_amount']; $statistics['net_amount_yuan'] = self::convertBalance($net_amount); // 计算成功率 if ($statistics['total_orders'] > 0) { $statistics['success_rate'] = round(($statistics['success_orders'] / $statistics['total_orders']) * 100, 2); } else { $statistics['success_rate'] = 0; } return $statistics; } /** * 获取所有游戏ID列表 */ public static function getAllGameIds($appId) { return self::where('app_id', $appId) ->distinct(true) ->column('game_id'); } /** * 获取状态文本 */ public static function getStatusText($status) { $statusMap = [ self::STATUS_PENDING => '待处理', self::STATUS_SUCCESS => '成功', self::STATUS_FAILED => '失败', self::STATUS_CANCELLED => '已取消' ]; return $statusMap[$status] ?? '未知'; } /** * 获取动作类型文本 */ public static function getActionTypeText($actionType) { $actionTypeMap = [ self::ACTION_TYPE_BET => '下注', self::ACTION_TYPE_SETTLE => '结算', self::ACTION_TYPE_CANCEL => '取消', self::ACTION_TYPE_CHECK => '检查', self::ACTION_TYPE_RESULT => '结果' ]; return $actionTypeMap[$actionType] ?? '其他'; } /** * 获取游戏名称 */ private static function getGameName($gameId) { // 这里可以根据实际情况配置游戏ID对应的名称 $gameNames = [ 'tiger' => '老虎机', 'fortue_tiger' => '财富老虎', 'dragon_tiger' => '龙虎斗', 'baccarat' => '百家乐', // 可以继续添加其他游戏 ]; return $gameNames[$gameId] ?? $gameId; } }