You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

745 lines
33 KiB
PHTML

4 years ago
<?php
namespace Base\Repository;
4 years ago
use Base\Service\GameService;
4 years ago
use Base\Tool\Registry;
use Base\Service\PromoteService;
class TestingResourceRepository
{
public static $provideStatusList = [
'0' => '待发放',
'1' => '已发放',
'2' => '异常',
];
public static $verifyStatusList = [
'0' => '未审核',
'1' => '审核通过',
'2' => '审核拒绝',
];
4 years ago
public static $userVerifyStatusList = [
'0' => '待审核',
'1' => '审核通过',
'2' => '审核拒绝',
];
public static $userStatusList = [
'1' => '正常',
'2' => '警告',
'3' => '禁用',
];
4 years ago
public function getProvideStatusText($provideStatus)
{
return self::$provideStatusList[$provideStatus] ?? '未知';
}
public function getVerifyStatusText($verifyStatus)
{
return self::$verifyStatusList[$verifyStatus] ?? '未知';
}
public function getGameRoleId($gameId, $roleId)
{
return $gameId . '#' . $roleId;
}
public function getGameSettings($isRefresh = false)
{
$settings = Registry::get('testing_game_settings');
if ($isRefresh || is_null($settings)) {
$settings = M('testing_game_setting', 'tab_')->where('1=1')->select();
Registry::set('testing_game_settings', $settings);
}
return $settings;
}
public function getGameSetting($baseGameId)
{
return M('testing_game_setting', 'tab_')->where(['base_game_id' => $baseGameId])->find();
}
public function getGameSettingByGameId($gameId)
{
$gameRepository = new GameRepository();
$baseGame = $gameRepository->getBaseGameByGameId($gameId);
$baseGameId = $baseGame ? $baseGame['id'] : 0;
return $this->getGameSetting($baseGameId);
}
public function getHadSettingGameIds()
{
$baseGameIds = M('testing_game_setting', 'tab_')->getField('base_game_id', true);
if (empty($baseGameIds)) {
return [];
}
$baseGames = M('base_game', 'tab_')->where(['id' => ['in', $baseGameIds]])->select();
return array_merge(array_column($baseGames, 'android_game_id'), array_column($baseGames, 'ios_game_id'));
}
public function getBatchesQuery($params, $promote = null)
{
$gameId = $params['game_id'] ?? 0;
$serverId = $params['server_id'] ?? '';
$createTimeStart = $params['create_time_start'] ?? '';
$createTimeEnd = $params['create_time_end'] ?? '';
$verifyStatus = $params['verify_status'] ?? -1;
$provideStatus = $params['provide_status'] ?? -1;
$account = $params['account'] ?? '';
4 years ago
$adminId = $params['verify_admin_id'] ?? -1;
4 years ago
$conditions = [];
$conditions['_string'] = '1=1';
if (!is_null($promote)) {
$promoteService = new PromoteService();
4 years ago
$permissionPromote = $promoteService->getTSPermPromote($promote);
4 years ago
$subSql = M('user', 'tab_')
4 years ago
->where('id=tab_testing_resource_batch.user_id and promote_id in (' . $promoteService->subInSql($permissionPromote) . ')')
4 years ago
->select(false);
$conditions['_string'] .= ' and exists (' . $subSql . ')';
}
if ($createTimeStart) {
$conditions['_string'] .= ' and create_time >=' . strtotime($createTimeStart . ' 00:00:00');
}
if ($createTimeEnd) {
$conditions['_string'] .= ' and create_time <=' . strtotime($createTimeEnd . ' 23:59:59');
}
if ($verifyStatus != -1) {
$conditions['verify_status'] = $verifyStatus;
}
if ($provideStatus != -1) {
$conditions['provide_status'] = $provideStatus;
}
4 years ago
if ($adminId != -1) {
$conditions['verify_admin_id'] = $adminId;
}
4 years ago
if ($gameId) {
$conditions['game_id'] = $gameId;
}
if ($serverId) {
$conditions['server_id'] = $serverId;
}
if ($account) {
$user = M('user', 'tab_')->field(['id'])->where('account like "' . $account . '%"')->find();
if ($user) {
$conditions['user_id'] = $user['id'];
} else {
$conditions['_string'] .= ' and 1<>1';
}
}
return M('testing_resource_batch', 'tab_')->where($conditions)->order('create_time desc');
}
public function getBatchesRelations($batches)
4 years ago
{
$roles = [];
$applyPromotes = [];
$applyTopPromotes = [];
4 years ago
$users = [];
$promotes = [];
4 years ago
$verifyAdmins = [];
$applyAdmins = [];
4 years ago
if (count($batches) > 0) {
$gameRoleIds = [];
foreach ($batches as $batch) {
$gameRoleIds[] = $this->getGameRoleId($batch['game_id'], $batch['role_id']);
}
$roles = M('user_play_info', 'tab_')
->field(['id', 'game_name', 'server_name', 'role_name', 'game_role_id', 'user_account'])
->where(['game_role_id' => ['in', $gameRoleIds]])
->select();
$roles = index_by_column('game_role_id', $roles);
$users = M('user', 'tab_')->field(['id', 'account', 'phone', 'promote_id'])->where(['id' => ['in', array_column($batches, 'user_id')]])->select();
$users = index_by_column('id', $users);
$applyPromotes = M('promote', 'tab_')->field(['id', 'account', 'level1_id'])->where(['id' => ['in', array_column($batches, 'apply_promote_id')]])->select();
4 years ago
$applyPromotes = index_by_column('id', $applyPromotes);
if (count($applyPromotes) > 0) {
$applyTopPromotes = M('promote', 'tab_')->field(['id', 'account'])->where(['id' => ['in', array_column($applyPromotes, 'level1_id')]])->select();
$applyTopPromotes = index_by_column('id', $applyTopPromotes);
}
$applyAdminIds = array_column($batches, 'apply_admin_id');
4 years ago
$applyAdmins = M('ucenter_member', 'sys_')->field(['id', 'username'])->where(['id' => ['in', $applyAdminIds]])->select();
$applyAdmins = index_by_column('id', $applyAdmins);
4 years ago
if (count($users) > 0) {
$promotes = M('promote', 'tab_')->field(['id', 'account', 'level1_id'])->where(['id' => ['in', array_column($users, 'promote_id')]])->select();
4 years ago
$promotes = index_by_column('id', $promotes);
}
$verifyAdminIds = array_column($batches, 'verify_admin_id');
4 years ago
$verifyAdmins = M('ucenter_member', 'sys_')->field(['id', 'username'])->where(['id' => ['in', $verifyAdminIds]])->select();
$verifyAdmins = index_by_column('id', $verifyAdmins);
4 years ago
}
return [
'roles' => $roles,
'applyPromotes' => $applyPromotes,
'users' => $users,
'promotes' => $promotes,
4 years ago
'verifyAdmins' => $verifyAdmins,
'applyAdmins' => $applyAdmins,
'applyTopPromotes' => $applyTopPromotes,
4 years ago
];
}
public function makeBatchesRecords($batches)
{
$result = $this->getBatchesRelations($batches);
$roles = $result['roles'];
$applyPromotes = $result['applyPromotes'];
$users = $result['users'];
$promotes = $result['promotes'];
4 years ago
$verifyAdmins = $result['verifyAdmins'];
$applyAdmins = $result['applyAdmins'];
$applyTopPromotes = $result['applyTopPromotes'];
4 years ago
$records = [];
foreach ($batches as $batch) {
$roleKey = $this->getGameRoleId($batch['game_id'], $batch['role_id']);
$role = isset($roles[$roleKey]) ? $roles[$roleKey] : null;
$user = $users[$batch['user_id']] ?? null;
$applyPromote = $applyPromotes[$batch['apply_promote_id']] ?? null;
$promote = $user && isset($promotes[$user['promote_id']]) ? $promotes[$user['promote_id']] : null;
4 years ago
$verifyAdmin = $verifyAdmins[$batch['verify_admin_id']] ?? null;
$applyAdmin = $applyAdmins[$batch['apply_admin_id']] ?? null;
4 years ago
$records[] = [
'id' => $batch['id'],
'batch_no' => substr($batch['batch_no'], 14),
'create_time' => date('Y-m-d H:i:s', $batch['create_time']),
'game_name' => $role ? $role['game_name'] : '--',
'server_name' => $role ? $role['server_name'] : '--',
'role_name' => $role ? $role['role_name'] : '--',
3 years ago
'user_account' => $role ? $this->encodeStr($role['user_account']) : '--',
'user_phone' => $user ? $this->encodeStr($user['phone']) : '',
'apply_top_username' => $applyPromote ? $this->encodeStr($applyTopPromotes[$applyPromote['level1_id']]['account']) : '--',
3 years ago
'apply_username' => $applyPromote ? $this->encodeStr($applyPromote['account']) . '[推广员]' : ($applyAdmin ? $this->encodeStr($applyAdmin['username']) . '[管理员]' : ''),
'promote_account' => $this->encodeStr($promote['account']),
4 years ago
'verify_admin_username' => $batch['verify_status'] == 0 ? '--' : ($verifyAdmin ? $verifyAdmin['username'] : '系統'),
4 years ago
// 'history_provide_amount' => 0.00,
'apply_amount' => $batch['apply_amount'],
'provide_amount' => $batch['provide_amount'],
'verify_status' => $batch['verify_status'],
'verify_status_text' => $this->getVerifyStatusText($batch['verify_status']),
'verify_time' => $batch['verify_time'] == 0 ? '--' : date('Y-m-d H:i:s', $batch['verify_time']),
'provide_status' => $batch['provide_status'],
'provide_status_text' => $this->getProvideStatusText($batch['provide_status']),
'provide_time' => $batch['provide_time'] == 0 ? '--' : date('Y-m-d H:i:s', $batch['provide_time']),
4 years ago
'content' => '',
4 years ago
];
}
return $records;
}
public function makeDailyCountData($items)
{
$result = $this->getBatchesRelations($items);
$roles = $result['roles'];
$applyPromotes = $result['applyPromotes'];
$users = $result['users'];
$promotes = $result['promotes'];
$verifyAdmins = $result['verifyAdmins'];
$applyAdmins = $result['applyAdmins'];
if(!empty($promotes)){
$levelTopPromotes = M('promote', 'tab_')->where(['id' => ['in', array_unique(array_column($promotes,'level1_id'))]])->getField('id,account',true);
}else{
$levelTopPromotes = [];
}
//获取申请人
$records = [];
foreach ($items as $batch) {
$roleKey = $this->getGameRoleId($batch['game_id'], $batch['role_id']);
$role = isset($roles[$roleKey]) ? $roles[$roleKey] : null;
$user = $users[$batch['user_id']] ?? null;
$applyPromote = $applyPromotes[$batch['apply_promote_id']] ?? null;
$promote = $user && isset($promotes[$user['promote_id']]) ? $promotes[$user['promote_id']] : null;
$levelTopPromote = $promote && isset($levelTopPromotes[$promote['level1_id']]) ? $levelTopPromotes[$promote['level1_id']] : null;
$verifyAdmin = $verifyAdmins[$batch['verify_admin_id']] ?? null;
$applyAdmin = $applyAdmins[$batch['apply_admin_id']] ?? null;
$jumpParm = [
'game_id'=>$batch['game_id'],
'server_id'=>$batch['server_id'],
'account'=> $role ? $role['user_account'] : '',
'create_time_start'=>$batch['create_day_time'],
'create_time_end'=>$batch['create_day_time']
];
$jumpUrl = U("TestingResource/batches",$jumpParm);
$records[] = [
'create_day_time' => $batch['create_day_time'],
'role_name' => $role ? $role['role_name'] : '--',
'game_name' => $role ? $role['game_name'] : '--',
'server_name' => $role ? $role['server_name'] : '--',
'user_account' => $role ?$role['user_account'] : '--',
'apply_username' => $applyPromote ? $applyPromote['account'] . '[推广员]' : ($applyAdmin ? $applyAdmin['username'] . '[管理员]' : ''),
'promote_account' => $promote['account'],
'level_top_promote'=>$levelTopPromote,
'apply_amount' => $batch['apply_amount'],
'provide_amount' => $batch['provide_amount'],
'jump_url'=>$jumpUrl
];
}
return $records;
}
public function makeDailyCountTipData($items)
{
$result = $this->getBatchesRelations($items);
$roles = $result['roles'];
$applyPromotes = $result['applyPromotes'];
$users = $result['users'];
$promotes = $result['promotes'];
$verifyAdmins = $result['verifyAdmins'];
$applyAdmins = $result['applyAdmins'];
//获取申请人
$records = [];
foreach ($items as $batch) {
$roleKey = $this->getGameRoleId($batch['game_id'], $batch['role_id']);
$role = isset($roles[$roleKey]) ? $roles[$roleKey] : null;
$user = $users[$batch['user_id']] ?? null;
$applyPromote = $applyPromotes[$batch['apply_promote_id']] ?? null;
$promote = $user && isset($promotes[$user['promote_id']]) ? $promotes[$user['promote_id']] : null;
$verifyAdmin = $verifyAdmins[$batch['verify_admin_id']] ?? null;
$applyAdmin = $applyAdmins[$batch['apply_admin_id']] ?? null;
$records[$roleKey] = [
'create_day_time' => $batch['create_day_time'],
'role_name' => $role ? $role['role_name'] : '--',
'game_name' => $role ? $role['game_name'] : '--',
'server_name' => $role ? $role['server_name'] : '--',
'user_account' => $role ?$role['user_account'] : '--',
'apply_username' => $applyPromote ? $applyPromote['account'] . '[推广员]' : ($applyAdmin ? $applyAdmin['username'] . '[管理员]' : ''),
'promote_account' => $promote['account'],
'apply_amount' => $batch['apply_amount'],
'provide_amount' => $batch['provide_amount'],
];
}
return $records;
}
4 years ago
private function statByRoles($roles)
{
$bindingOrWhere = [];
foreach ($roles as $role) {
$bindingOrWhere[] = '(role_id="' . $role['role_id'] . '" and game_id=' . $role['game_id'] . ')';
}
4 years ago
$bindingOrWhereStr = '(' . implode(' or ', $bindingOrWhere) . ')';
4 years ago
$userIds = array_unique(array_column($roles, 'user_id'));
$users = [];
$bindings = [];
$bindingRoles = [];
$applyRecords = [];
4 years ago
$testingUsers = [];
4 years ago
if (count($roles) > 0) {
4 years ago
$games = M('game', 'tab_')->field(['id', 'data_share'])->where(['id' => ['in', array_column($roles, 'game_id')]])->select();
$games = index_by_column('id', $games);
$gameRepository = new GameRepository();
$baseGames = $gameRepository->getBaseGames();
4 years ago
$testingUsers = M('testing_user', 'tab_')->where(['user_id' => ['in', $userIds]])->select();
$testingUsers = index_by_column('user_id', $testingUsers);
4 years ago
$users = M('user', 'tab_')->field(['id', 'phone', 'lock_status'])->where(['id' => ['in', $userIds]])->select();
$users = index_by_column('id', $users);
4 years ago
$bindingRows = M('testing_binding', 'tab_')->where(['_string' => $bindingOrWhereStr])->select();
4 years ago
$bindingRoleIds = [];
foreach ($bindingRows as $bindingRow) {
$bindings[$this->getGameRoleId($bindingRow['game_id'], $bindingRow['role_id'])] = $bindingRow;
$bindingRoleIds[] = $this->getGameRoleId($bindingRow['game_id'], $bindingRow['bind_role_id']);
4 years ago
$game = $games[$bindingRow['game_id']];
$gameIds = [$bindingRow['game_id']];
if ($game['data_share'] == 1) {
$baseGame = $gameRepository->getBaseGameByGameId($bindingRow['game_id'], $baseGames);
$gameIds = $gameRepository->getGameIdsByBaseGame($baseGame);
}
foreach ($gameIds as $gameId) {
$bindingRoleIds[] = $this->getGameRoleId($gameId, $bindingRow['bind_role_id']);
}
4 years ago
}
if (count($bindings) > 0) {
$bindingRoles = M('user_play_info', 'tab_')
->field(['id', 'role_id', 'role_name', 'user_account', 'game_id', 'game_role_id'])
->where(['game_role_id' => ['in', $bindingRoleIds]])
->select();
$bindingRoles = index_by_column('game_role_id', $bindingRoles);
}
$verifyItems = M('testing_resource_batch', 'tab_')
->field('sum(apply_amount) amount, game_id, role_id')
->where([
'verify_status' => 0,
4 years ago
'_string' => $bindingOrWhereStr,
4 years ago
])
->group('game_id,role_id')->select();
$verifyRecords = [];
foreach ($verifyItems as $item) {
$verifyRecords[$this->getGameRoleId($item['game_id'], $item['role_id'])] = $item['amount'] ;
}
$provideItems = M('testing_resource_batch', 'tab_')
->field('sum(provide_amount) amount, game_id, role_id')
->where([
'verify_status' => 1,
4 years ago
'_string' => $bindingOrWhereStr,
4 years ago
])
->group('game_id,role_id')->select();
$provideRecords = [];
foreach ($provideItems as $item) {
$provideRecords[$this->getGameRoleId($item['game_id'], $item['role_id'])] = $item['amount'] ;
}
$todayProvideItems = M('testing_resource_batch', 'tab_')
->field('sum(provide_amount) amount, game_id, role_id')
->where([
'verify_status' => 1,
4 years ago
'_string' => $bindingOrWhereStr,
'provide_time' => ['between', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]],
4 years ago
])
->group('game_id,role_id')->select();
$todayProvideRecords = [];
foreach ($todayProvideItems as $item) {
$todayProvideRecords[$this->getGameRoleId($item['game_id'], $item['role_id'])] = $item['amount'] ;
}
$applyItems = M('testing_resource_batch', 'tab_')
->field('sum(apply_amount) amount, game_id, role_id')
->where([
4 years ago
'_string' => $bindingOrWhereStr,
4 years ago
])
->group('game_id,role_id')->select();
$applyRecords = [];
foreach ($applyItems as $item) {
$applyRecords[$this->getGameRoleId($item['game_id'], $item['role_id'])] = $item['amount'] ;
}
}
4 years ago
$spendItems = [];
4 years ago
$revGameIdMap = [];
$gameIdMap = [];
4 years ago
if (count($bindingRoles) > 0) {
4 years ago
$games = M('game', 'tab_')->field(['id', 'data_share'])->where(['id' => ['in', array_column($bindingRoles, 'game_id')]])->select();
foreach ($games as $game) {
if ($game['data_share'] == 1) {
$baseGame = $gameRepository->getBaseGameByGameId($game['id'], $baseGames);
$gameIds = $gameRepository->getGameIdsByBaseGame($baseGame);
$gameIdMap[$game['id']] = $gameIds;
foreach ($gameIds as $gameId) {
$revGameIdMap[$gameId] = $game['id'];
}
} else {
$gameIdMap[$game['id']] = [$game['id']];
$revGameIdMap[$game['id']] = $game['id'];
}
}
4 years ago
$spendOrWhere = [];
foreach ($bindingRoles as $bindingRole) {
4 years ago
$gameIds = $gameIdMap[$bindingRole['game_id']];
$spendOrWhere[] = '(game_player_id="' . $bindingRole['role_id'] . '" and game_id in (' . implode(',', $gameIds) . '))';
4 years ago
}
$spendCondition = [
'pay_status' => 1,
'_string' => '(' . implode(' or ', $spendOrWhere) . ')',
];
$subBindingCondition = [
'_string' =>
'tab_testing_binding.bind_role_id = tab_spend.game_player_id and ' .
4 years ago
'tab_testing_binding.bind_user_id = tab_spend.user_id and ' .
'UNIX_TIMESTAMP(FROM_UNIXTIME(tab_testing_binding.create_time, "%Y-%m-%d 00:00:00")) <= tab_spend.pay_time'
];
$spendRepository = new SpendRepository();
$subBindingCondition = $spendRepository->withIsCheck($subBindingCondition, 'tab_spend.is_check');
$spendCondition = $spendRepository->withIsCheck($spendCondition);
4 years ago
$subBindingSql = M('testing_binding', 'tab_')
->where($subBindingCondition)
4 years ago
->select(false);
$spendCondition['_string'] .= ' and exists(' . $subBindingSql . ')';
$spendList = M('spend', 'tab_')
->field('sum(pay_amount) amount, game_id, game_player_id')
->where($spendCondition)
->group('game_id,game_player_id')
->select();
4 years ago
foreach ($spendList as $item) {
4 years ago
$mainGameId = $revGameIdMap[$item['game_id']];
$itemKey = $this->getGameRoleId($mainGameId, $item['game_player_id']);
if (isset($spendItems[$itemKey])) {
$spendItems[$itemKey] += $item['amount'];
} else {
$spendItems[$itemKey] = $item['amount'];
}
4 years ago
}
}
4 years ago
$gameSettings = $this->getGameSettings();
4 years ago
return [
'users' => $users,
'spendItems' => $spendItems,
'bindings' => $bindings,
'bindingRoles' => $bindingRoles,
'applyRecords' => $applyRecords,
'provideRecords' => $provideRecords,
'verifyRecords' => $verifyRecords,
'todayProvideRecords' => $todayProvideRecords,
4 years ago
'gameSettings' => $gameSettings,
4 years ago
'testingUsers' => $testingUsers,
4 years ago
'revGameIdMap' => $revGameIdMap
4 years ago
];
}
3 years ago
private function encodeStr($str)
{
# 判断字符串长度
$length = strlen($str);
if ($length == 1) {
# 长度为 1 前后拼接 * 号
$newStr = $str.'*'.rand(1,6);
}else{
# 长度超过1随机插入 * 号
$newStr = substr_replace($str,str_repeat('*',$length/2),ceil($length/2),$length).mb_substr($str,$length-2,$length,"utf-8");
// str_repeat('*',$length/2) 星号重复字符长度的一半长度
// ceil($length/2) 算出从第几个字符开始
}
return $newStr;
}
4 years ago
public function makeTestingRoleRecords($roles)
4 years ago
{
$result = $this->statByRoles($roles);
$users = $result['users'];
4 years ago
$testingUsers = $result['testingUsers'];
4 years ago
$spendItems = $result['spendItems'];
4 years ago
$gameSettings = $result['gameSettings'];
4 years ago
$bindings = $result['bindings'];
$bindingRoles = $result['bindingRoles'];
4 years ago
$revGameIdMap = $result['revGameIdMap'];
4 years ago
$applyRecords = $result['applyRecords'];
$provideRecords = $result['provideRecords'];
$verifyRecords = $result['verifyRecords'];
$todayProvideRecords = $result['todayProvideRecords'];
4 years ago
$gameSettings = index_by_column('base_game_id', $gameSettings);
$gameRepository = new GameRepository();
$baseGames = $gameRepository->getBaseGames();
4 years ago
$records = [];
foreach ($roles as $role) {
$user = $users[$role['user_id']] ?? null;
4 years ago
$testingUser = $testingUsers[$role['user_id']] ?? null;
4 years ago
$binding = $bindings[$role['game_role_id']] ?? null;
$bindingRole = null;
4 years ago
$baseGame = $gameRepository->getBaseGameByGameId($role['game_id'], $baseGames);
4 years ago
$gameSetting = null;
if ($baseGame && isset($gameSettings[$baseGame['id']])) {
$gameSetting = $gameSettings[$baseGame['id']];
}
4 years ago
4 years ago
$spendQuota = 0;
4 years ago
$quota = 0;
4 years ago
if ($binding) {
4 years ago
$gameIds = $gameRepository->getGameIdsByBaseGame($baseGame);
foreach ($gameIds as $gameId) {
$bindGameRoleId = $this->getGameRoleId($gameId, $binding['bind_role_id']);
if (isset($bindingRoles[$bindGameRoleId])) {
$bindingRole = $bindingRoles[$bindGameRoleId];
break;
}
}
4 years ago
4 years ago
if ($bindingRole) {
$mainGameId = $revGameIdMap[$binding['game_id']];
$mainGameRoleId = $this->getGameRoleId($mainGameId, $binding['bind_role_id']);
$spendQuota = isset($spendItems[$mainGameRoleId]) ? $spendItems[$mainGameRoleId] : 0;
}
$quota = $gameSetting ? round($spendQuota * $gameSetting['rate'] / 100, 2) : 0;
}
4 years ago
4 years ago
$statusText = '正常';
if (is_null($user) || is_null($testingUser)) {
$statusText = '错误';
} elseif ($testingUser['status'] == 2) {
$statusText = '警告';
} elseif ($testingUser['status'] == 3) {
$statusText = '禁用';
4 years ago
}
if (is_null($user)) {
$statusText .= '(账号不存在)';
} elseif ($user['lock_status'] != 1) {
$statusText .= '(账号锁定)';
}
4 years ago
4 years ago
$records[] = [
'id' => $role['id'],
'game_name' => $role['game_name'],
'server_name' => $role['server_name'],
'server_id' => $role['server_id'],
'role_id' => $role['role_id'],
3 years ago
'user_account' => $this->encodeStr($role['user_account']),
4 years ago
'user_phone' => $user ? $user['phone'] : '',
'role_name' => $role['role_name'],
4 years ago
'binding_id' => $binding ? $binding['id'] : 0,
3 years ago
'bind_user_account' => $bindingRole ? $this->encodeStr($bindingRole['user_account']) : '',
4 years ago
'bind_role_name' => $bindingRole ? $bindingRole['role_name'] : '',
'base_quota' => $gameSetting ? $gameSetting['base_quota'] : 0,
4 years ago
'other_quota' => intval($role['testing_other_quota']),
'other_quota_remark' => $role['testing_other_quota_remark'],
4 years ago
'quota' => $quota,
4 years ago
'verify_amount' => $verifyRecords[$role['game_role_id']] ?? 0,
'provide_amount' => $provideRecords[$role['game_role_id']] ?? 0,
'today_amount' => $todayProvideRecords[$role['game_role_id']] ?? 0,
'apply_amount' => $applyRecords[$role['game_role_id']] ?? 0,
4 years ago
'status' => $statusText,
4 years ago
'create_time' => date('Y-m-d H:i:s', $role['create_time'])
];
}
return $records;
}
4 years ago
public function getTestingRolesQuery($params, array $promote = null)
4 years ago
{
$createTimeStart = $params['create_time_start'] ?? '';
$createTimeEnd = $params['create_time_end'] ?? '';
$gameId = $params['game_id'] ?? 0;
$serverId = $params['server_id'] ?? '';
$account = $params['account'] ?? '';
4 years ago
$status = $params['status'] ?? 0;
4 years ago
$roleName = $params['role_name'] ?? '';
$conditions = [];
3 years ago
/* $subConditions = [
4 years ago
'_string' => '1=1'
3 years ago
]; */
4 years ago
$strCondition = '1=1';
$promoteService = new PromoteService();
4 years ago
$permissionPromote = $promoteService->getTSPermPromote($promote);
if ($permissionPromote) {
$visibleGameIds = $promoteService->getVisibleGameIds($permissionPromote);
4 years ago
if (count($visibleGameIds) > 0) {
3 years ago
$strCondition .= ' and r.game_id in (' . implode(',', $visibleGameIds) . ')';
4 years ago
} else {
$strCondition .= ' and 1=0';
}
3 years ago
$strCondition .= ' and r.promote_id in (' . $promoteService->subInSql($permissionPromote) . ')';
4 years ago
}
$gameIds = $this->getHadSettingGameIds();
if (!empty($gameIds)) {
3 years ago
$strCondition .= ' and r.game_id in ('. implode(',', $gameIds) . ')';
4 years ago
} else {
$strCondition .= ' and 1=0';
}
if ($createTimeStart) {
3 years ago
$strCondition .= ' and r.create_time >=' . strtotime($createTimeStart . ' 00:00:00');
4 years ago
}
if ($createTimeEnd) {
3 years ago
$strCondition .= ' and r.create_time <=' . strtotime($createTimeEnd . ' 23:59:59');
4 years ago
}
4 years ago
if ($status != 0) {
3 years ago
$conditions['u.status'] = $status;
4 years ago
}
4 years ago
3 years ago
/* $subConditions['verify_status'] = 1;
4 years ago
$subSql = M('testing_user', 'tab_')->field(['user_id'])->where($subConditions)->select(false);
3 years ago
$strCondition .= ' and user_id in (' . $subSql . ')'; */
$conditions['u.verify_status'] = 1;
$strCondition .= ' and u.id is not null';
4 years ago
if ($account) {
$user = M('user', 'tab_')->field(['id'])->where('account like "' . $account . '%"')->find();
if ($user) {
3 years ago
$conditions['r.user_id'] = $user['id'];
4 years ago
} else {
$strCondition .= ' and 1<>1';
}
}
if ($gameId) {
3 years ago
$conditions['r.game_id'] = $gameId;
4 years ago
}
if ($serverId) {
3 years ago
$conditions['r.server_id'] = $serverId;
4 years ago
}
if ($roleName) {
3 years ago
$conditions['r.role_name'] = ['like', $roleName . '%'];
4 years ago
}
$conditions['_string'] = $strCondition;
3 years ago
return M('user_play_info', 'tab_')
->alias('r')
->field('r.*')
->join("left join tab_testing_user u on r.user_id=u.user_id")
->where($conditions)
->order('r.create_time desc');
4 years ago
}
4 years ago
public function getTestingUsersQuery($params, array $promote = null)
{
$createTimeStart = $params['create_time_start'] ?? '';
$createTimeEnd = $params['create_time_end'] ?? '';
$status = $params['status'] ?? 0;
$verifyStatus = $params['verify_status'] ?? -1;
$account = $params['account'] ?? '';
$conditions = [];
$strCondition = '1=1';
/* $promoteService = new PromoteService();
if ($promote) {
$subSql = M('user', 'tab_')->field('id')->where('promote_id in (' . $promoteService->subInSql($promote) . ')')->select(false);
$strCondition .= ' and user_id in (' . $subSql . ')';
} */
if ($account) {
$conditions['user_account'] = ['like', '%' . $account . '%'];
}
if ($verifyStatus != -1) {
$conditions['verify_status'] = $verifyStatus;
}
if ($status != 0) {
$conditions['status'] = $status;
}
if ($createTimeStart) {
$strCondition .= ' and create_time >=' . strtotime($createTimeStart . ' 00:00:00');
}
if ($createTimeEnd) {
$strCondition .= ' and create_time <=' . strtotime($createTimeEnd . ' 23:59:59');
}
$conditions['_string'] = $strCondition;
return M('testing_user', 'tab_')->where($conditions);
}
public function makeTestingUserRecords($testingUsers)
{
$ids = array_column($testingUsers, 'user_id');
if (count($ids) == 0) {
return [];
}
$users = M('user', 'tab_')->field(['id', 'login_time', 'promote_account'])->where(['id' => ['in', $ids]])->select();
$users = index_by_column('id', $users);
$records = [];
foreach ($testingUsers as $testingUser) {
$user = $users[$testingUser['user_id']] ?? null;
$records[] = [
'user_id' => $testingUser['user_id'],
3 years ago
'user_account' => $this->encodeStr($testingUser['user_account']),
4 years ago
'status_text' => self::$userStatusList[$testingUser['status']] ?? '未知',
'verify_status_text' => self::$userVerifyStatusList[$testingUser['verify_status']] ?? '未知',
'verify_status' => $testingUser['verify_status'],
'status' => $testingUser['status'],
'verify_time' => $testingUser['verify_time'] == 0 ? '' : date('Y-m-d H:i:s', $testingUser['verify_time']),
'create_time' => date('Y-m-d H:i:s', $testingUser['create_time']),
3 years ago
'promote_account' => $user ? $this->encodeStr($user['promote_account']) : '--',
4 years ago
'login_time' => $user ? date('Y-m-d H:i:s', $user['login_time']) : '--',
];
}
return $records;
}
4 years ago
}