0 ? $gameId : ['gt', 0]; if (isset($params['server_id'])) { $conditions['server_id'] = $serverId; } $conditions['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1']; return $conditions; } private function getDayGroupConditionsNew($params) { $beginTime = $params['begin_time'] ?? 0; $endTime = $params['end_time'] ?? 0; $gameId = $params['game_id'] ?? 0; $serverId = $params['server_id'] ?? 0; $ids = $params['promote_id'] ?? []; $conditions = []; $conditions['pay_status'] = 1; $conditions['promote_id'] = ['in', $ids]; $conditions['pay_time'] = ['between', [$beginTime, $endTime]]; $conditions['game_id'] = $gameId > 0 ? $gameId : ['gt', 0]; if (isset($params['server_id'])) { $conditions['server_id'] = $serverId; } if (isset($params['pay_way'])) { $conditions['pay_way'] = $params['pay_way']; } return $conditions; } /** * 付费游戏数 */ public function getPayGameCountGroupByDay($params) { $dayList = $params['dayList'] ?? []; $conditions = $this->getDayGroupConditions($params); $field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day, count(DISTINCT game_id) count'; $items = M('spend', 'tab_')->field($field)->where($conditions)->group('day')->select(); return $this->assembleRecords($items, $dayList, 'count'); } /** * 按天统计付款总额 */ public function getPayAmountGroupByDay($params) { $dayList = $params['dayList'] ?? []; $conditions = $this->getDayGroupConditions($params); $field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day, sum(pay_amount) as amount'; $items = M('spend', 'tab_')->field($field)->where($conditions)->group('day')->select(); return $this->assembleRecords($items, $dayList, 'amount'); } /** * 按天统计类型付款总额 */ public function getPayAmountGroupByDayAndType($params) { $dayList = $params['dayList'] ?? []; $conditions = $this->getDayGroupConditionsNew($params); $field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day, sum(pay_amount) as amount'; $items = M('spend', 'tab_')->field($field)->where($conditions)->group('day')->select(); return $this->assembleRecords($items, $dayList, 'amount'); } /** * 按游戏统计付款总额 */ public function getPayAmountGroupByGame($params) { $gameIds = $params['game_ids'] ?? []; $conditions = $this->getGameGroupConditions($params); $field = 'game_id, sum(pay_amount) as amount'; $items = M('spend', 'tab_')->field($field)->where($conditions)->group('game_id')->select(); return $this->assembleRecords($items, $gameIds, 'amount', 'game_id'); } /** * 按游戏统计付款总额--cxj */ public function getPayAmountGroupByGameAndType($params) { $gameIds = $params['game_ids'] ?? []; $conditions = $this->getGameGroupConditionsNew($params); $field = 'game_id, sum(pay_amount) as amount'; $items = M('spend', 'tab_')->field($field)->where($conditions)->group('game_id')->select(); return $this->assembleRecords($items, $gameIds, 'amount', 'game_id'); } /** * 按游戏统计付款总额--cxj */ public function getPayAmountByGameAndType($params) { $conditions = $this->getGameGroupConditionsNew($params); return M('spend', 'tab_')->where($conditions)->sum('pay_amount'); } /** * 按天统计付款用户数 */ public function getPayUserCountGroupByDay($params) { $dayList = $params['dayList'] ?? []; $conditions = $this->getDayGroupConditions($params); $field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day, count(distinct user_id) count'; $items = M('spend', 'tab_')->field($field)->where($conditions)->group('day')->select(); return $this->assembleRecords($items, $dayList, 'count'); } /** * 按天统计付款用户数--cxj */ public function getPayUserCountGroupByDayNew($params) { $dayList = $params['dayList'] ?? []; $conditions = $this->getDayGroupConditions($params); $field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day, count(distinct user_id, game_id) count'; $items = M('spend', 'tab_')->field($field)->where($conditions)->group('day')->select(); return $this->assembleRecords($items, $dayList, 'count'); } /** * 按天统计付款次数 */ public function getPayCountGroupByDay($params) { $dayList = $params['dayList'] ?? []; $conditions = $this->getDayGroupConditions($params); $field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day, count(*) count'; $items = M('spend', 'tab_')->field($field)->where($conditions)->group('day')->select(); return $this->assembleRecords($items, $dayList, 'count'); } /** * 按游戏统计付款次数 */ public function getPayCountGroupByGame($params) { $gameIds = $params['game_ids'] ?? []; $conditions = $this->getGameGroupConditions($params); $field = 'game_id, count(*) count'; $items = M('spend', 'tab_')->field($field)->where($conditions)->group('game_id')->select(); return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); } /** * 按游戏统计付款次数--cxj */ public function getPayCountByGame($params) { $conditions = $this->getGameGroupConditions($params); return M('spend', 'tab_')->where($conditions)->count(); } /** * 游戏统计付款用户数 */ public function getPayUserCountGroupByGame($params) { $gameIds = $params['game_ids'] ?? []; $conditions = $this->getGameGroupConditions($params); $field = 'game_id, count(distinct user_id) count'; $items = M('spend', 'tab_')->field($field)->where($conditions)->group('game_id')->select(); return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); } /** * 游戏统计付款用户数--cxj */ public function getPayUserCountByGame($params) { $conditions = $this->getGameGroupConditions($params); $sql = M('spend', 'tab_')->field('distinct game_id, user_id') ->where($conditions) ->fetchSql(true) ->select(); $model = new \Think\Model(); return $model->query("select count(*) as num from ($sql) as t")[0]['num']; } /** * 按照时间分组统计新增付费用户数 */ public function getNewPayUserCountGroupByDay($params) { $dayList = $params['dayList'] ?? []; $conditions = $this->getDayGroupConditions($params); $oldConditions = $conditions; $records = []; foreach ($dayList as $day) { $time = strtotime($day); $oldConditions['pay_time'] = ['lt', $time]; $conditions['pay_time'] = ['between', [$time, ($time + 24 * 3600 - 1)]]; $oldQuery = M('spend', 'tab_')->field('user_id')->where($oldConditions)->group('user_id')->buildSql(); $conditions['user_id'] = ['exp', ' not in (' . $oldQuery . ')']; $result = M('spend', 'tab_')->field('count(distinct user_id) count')->where($conditions)->find(); $records[$day] = $result['count']; } return $records; } /** * 按照时间分组统计新增付费用户数 */ public function getNewPayUserCountGroupByGame($params) { $beginTime = $params['begin_time'] ?? 0; $gameIds = $params['game_ids'] ?? []; $conditions = $this->getGameGroupConditions($params); $oldConditions = $conditions; $oldConditions['pay_time'] = ['lt', $beginTime]; $oldQuery = M('spend', 'tab_')->field('user_id')->where($oldConditions)->group('user_id')->buildSql(); $conditions['user_id'] = ['exp', ' not in (' . $oldQuery . ')']; $items = M('spend', 'tab_')->field('count(distinct user_id) count, game_id')->where($conditions)->group('game_id')->select(); return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); } /** * 按照时间分组统计新增付费用户付费金额 */ public function getNewPayAmountGroupByDay($params) { $dayList = $params['dayList'] ?? []; $conditions = $this->getDayGroupConditions($params); $oldConditions = $conditions; $records = []; foreach ($dayList as $day) { $time = strtotime($day); $oldConditions['pay_time'] = ['lt', $time]; $conditions['pay_time'] = ['between', [$time, ($time + 24 * 3600 - 1)]]; $oldQuery = M('spend', 'tab_')->field('user_id')->where($oldConditions)->group('user_id')->buildSql(); $conditions['user_id'] = ['exp', ' not in (' . $oldQuery . ')']; $result = M('spend', 'tab_')->field('sum(pay_amount) amount')->where($conditions)->find(); $records[$day] = floatval($result['amount']); } return $records; } /** * 按照游戏统计新增付费用户付费金额 */ public function getNewPayAmountGroupByGame($params) { $beginTime = $params['begin_time'] ?? 0; $gameIds = $params['game_ids'] ?? []; $conditions = $this->getGameGroupConditions($params); $oldConditions = $conditions; $oldConditions['pay_time'] = ['lt', $beginTime]; $oldQuery = M('spend', 'tab_')->field('user_id')->where($oldConditions)->group('user_id')->buildSql(); $conditions['user_id'] = ['exp', ' not in (' . $oldQuery . ')']; $items = M('spend', 'tab_')->field('sum(pay_amount) amount, game_id')->where($conditions)->group('game_id')->find(); return $this->assembleRecords($items, $gameIds, 'amount', 'game_id'); } /** * 统计给定时间前的付费玩家总数 */ public function getHistoryPayCountGroupByDay($params) { $dayList = $params['dayList'] ?? []; $conditions = $this->getDayGroupConditions($params); $records = []; foreach ($dayList as $day) { $time = strtotime($day) + 24 * 3600; $conditions['pay_time'] = ['elt', $time]; $result = M('spend', 'tab_')->field('count(DISTINCT user_id) as count')->where($conditions)->find(); $records[$day] = $result['count']; } return $records; } /** * 统计给定时间前的付费玩家总数 */ public function getHistoryPayCountGroupByGame($params) { $beginTime = $params['begin_time'] ?? 0; $conditions = $this->getGameGroupConditions($params); $conditions['pay_time'] = ['elt', $beginTime]; $items = M('spend', 'tab_')->field('count(DISTINCT user_id) as count, game_id')->where($conditions)->group('game_id')->find(); return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); } public function getCommonQuery($params, $columns = '*') { // return M('spend', 'tab_')->field($columns)->where($map); } public function achievement() { $time = I('time', date('Y-m-d')); if (!empty($time)) { $defaultTime = $time; } else { $defaultTime = date('Y-m-d', time()); } $sdkVersion = I('sdk_version', 0); $relationGameId = I('relation_game_id', 0); $serverId = I('server_id', 0); $parentId = I('parent_id', 0); $promoteId = I('promote_id', 0); $status = I('status', 0); $searchLevel = 0; $searchLevelName = ''; $currentDisplay = ''; $prevParentId = 0; $promoteService = new PromoteService(); $loginPromote = $this->getLoginPromote(); $parent = null; if ($parentId > 0) { $parent = M('promote', 'tab_')->where(['id' => $parentId])->find(); $currentDisplay = $promoteService->getLevelName($parent['level']) . '推广'; $prevParentId = $parent['parent_id'] == $loginPromote['parent_id'] ? 0 : $parent['parent_id']; } else { $parent = $loginPromote; $currentDisplay = '自己'; } $searchLevel = $parent['level'] + 1; $searchLevelName = $promoteService->getLevelName($searchLevel); $games = get_promote_serach_game(); $subPromotes = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'group_remark'])->where(['parent_id' => $parent['id']])->select(); $map = ['parent_id' => $parent['id']]; if ($promoteId > 0) { $map['id'] = $promoteId; } $query = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'level', 'chain'])->where($map); list($promotes, $pagination, $count) = $this->paginate($query); $ids = array_column($promotes, 'id'); $rows = []; if (count($ids) > 0) { $rows = M('promote', 'tab_') ->field(['id', 'chain']) ->where(['chain' => ['like', [$parent['chain'] . $parent['id'] . '/%']], 'level' => ['gt', $parent['level'] + 1]]) ->select(); } $basicPromotes = []; foreach ($ids as $id) { foreach ($rows as $row) { $needChain = $parent['chain'] . $parent['id'] . '/' . $id . '/'; if (strpos($row['chain'], $needChain) !== false) { $basicPromotes[$row['id']] = $id; } } } $params = [ 'isContainSubs' => true, 'basicPromotes' => $basicPromotes, ]; if ($relationGameId != 0 || $sdkVersion != 0) { $gameIds = gameSearch($relationGameId, $sdkVersion); $params['game_id'] = ['in', $gameIds]; } if ($serverId > 0) { $params['server_id'] = $serverId; } if ($status > 0) { $params['lock_status'] = $status; } list($beginTime, $endTime) = $this->getBetweenTime($time); $params['begin_time'] = $beginTime; $params['end_time'] = $endTime; $timeout = 0; $records = []; if (intval($endTime - $beginTime) / (24 * 3600) <= 7) { $promoteRepository = new PromoteRepository(); $createRoleCountList = $promoteRepository->getCreateRoleCountByIds($ids, $params); $createRoleUserCountList = $promoteRepository->getCreateRoleUserCountByIds($ids, $params); $newCreateRoleUserCountList = $promoteRepository->getNewCreateRoleUserCountByIds($ids, $params); // $newCreateRoleDeviceCountList = $promoteRepository->getNewCreateRoleDeviceCountByIds($ids, $params); $newCreateRoleIpCountList = $promoteRepository->getNewCreateRoleIpCountByIds($ids, $params); $loginUserCountList = $promoteRepository->getLoginUserCountByIds($ids, $params); $rechargeCountList = []; $rechargeUserCountList = []; $rechargeAmountList = []; if ($this->canViewUserRecharge) { $rechargeCountList = $promoteRepository->getRechargeCountByIds($ids, $params); $rechargeUserCountList = $promoteRepository->getRechargeUserCountByIds($ids, $params); $rechargeAmountList = $promoteRepository->getRechargeAmountByIds($ids, $params); } $promoteService = new PromoteService(); if (I('p', 1) == 1) { $selfParams = $params; $selfParams['isContainSubs'] = false; $selfCreateRoleCountList = $promoteRepository->getCreateRoleCountByIds([$parent['id']], $selfParams); $selfCreateRoleUserCountList = $promoteRepository->getCreateRoleUserCountByIds([$parent['id']], $selfParams); $selfNewCreateRoleUserCountList = $promoteRepository->getNewCreateRoleUserCountByIds([$parent['id']], $selfParams); // $selfNewCreateRoleDeviceCountList = $promoteRepository->getNewCreateRoleDeviceCountByIds([$parent['id']], $selfParams); $selfNewCreateRoleIpCountList = $promoteRepository->getNewCreateRoleIpCountByIds([$parent['id']], $selfParams); $selfLoginUserCountList = $promoteRepository->getLoginUserCountByIds([$parent['id']], $selfParams); $record = [ 'id' => $parent['id'], 'account' => $parent['account'], 'promote_group' => $promoteService->getGroupNameByChain($parent['chain'], $parent['id']), 'real_name' => hideRealName($parent['real_name']), 'level' => $parent['level'], 'create_role_count' => $selfCreateRoleCountList[$parent['id']], 'create_role_user_count' => $selfCreateRoleUserCountList[$parent['id']], 'new_create_role_user_count' => $selfNewCreateRoleUserCountList[$parent['id']], // 'new_create_role_device_count' => $selfNewCreateRoleDeviceCountList[$parent['id']], 'new_create_role_ip_count' => $selfNewCreateRoleIpCountList[$parent['id']], 'login_user_count' => $selfLoginUserCountList[$parent['id']], 'current_display' => $currentDisplay, ]; if ($this->canViewUserRecharge) { $selfRechargeCountList = $promoteRepository->getRechargeCountByIds([$parent['id']], $selfParams); $selfRechargeUserCountList = $promoteRepository->getRechargeUserCountByIds([$parent['id']], $selfParams); $selfRechargeAmountList = $promoteRepository->getRechargeAmountByIds([$parent['id']], $selfParams); $record['recharge_count'] = $selfRechargeCountList[$parent['id']]; $record['recharge_user_count'] = $selfRechargeUserCountList[$parent['id']]; $record['recharge_amount'] = $selfRechargeAmountList[$parent['id']]['ban_coin'] + $selfRechargeAmountList[$parent['id']]['coin'] + $selfRechargeAmountList[$parent['id']]['cash']; $record['recharge_by_ban_coin'] = $selfRechargeAmountList[$parent['id']]['ban_coin']; $record['recharge_by_coin'] = $selfRechargeAmountList[$parent['id']]['coin']; $record['recharge_by_cash'] = $selfRechargeAmountList[$parent['id']]['cash']; } $records[] = $record; } foreach ($promotes as $promote) { $id = $promote['id']; $record = [ 'id' => $id, 'account' => $promote['account'], 'promote_group' => $promoteService->getGroupNameByChain($promote['chain'], $promote['id']), 'real_name' => hideRealName($promote['real_name']), 'level' => $promote['level'], 'create_role_count' => $createRoleCountList[$id], 'create_role_user_count' => $createRoleUserCountList[$id], 'new_create_role_user_count' => $newCreateRoleUserCountList[$id], // 'new_create_role_device_count' => $newCreateRoleDeviceCountList[$id], 'new_create_role_ip_count' => $newCreateRoleIpCountList[$id], 'login_user_count' => $loginUserCountList[$id], 'current_display' => '', ]; if ($this->canViewUserRecharge) { $record['recharge_count'] = $rechargeCountList[$id]; $record['recharge_user_count'] = $rechargeUserCountList[$id]; $record['recharge_amount'] = $rechargeAmountList[$id]['ban_coin'] + $rechargeAmountList[$id]['coin'] + $rechargeAmountList[$id]['cash']; $record['recharge_by_ban_coin'] = $rechargeAmountList[$id]['ban_coin']; $record['recharge_by_coin'] = $rechargeAmountList[$id]['coin']; $record['recharge_by_cash'] = $rechargeAmountList[$id]['cash']; } $records[] = $record; } } else { $timeout = 1; } }