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.

393 lines
15 KiB
PHP

<?php
namespace Admin\Controller;
use Base\Model\PromoteModel;
use Base\Service\PromoteService;
use Base\Service\TestingResourceService;
use Base\Service\PartnerService;
class TestingResourceController extends ThinkController
{
public function index()
{
$page = I('p', 1);
$row = I('row', 10);
$createTimeStart = I('create_time_start', '');
$createTimeEnd = I('create_time_end', '');
$gameId = I('game_id', 0);
$serverId = I('server_id', '');
$account = I('account');
$roleName = I('role_name');
$conditions = [];
$subConditions = [
'_string' => '1=1'
];
$strCondition = '1=1';
$testingResourceService = new TestingResourceService();
$gameIds = $testingResourceService->getHadSettingGameIds();
if (!empty($gameIds)) {
$strCondition .= ' and game_id in ('. implode(',', $gameIds) . ')';
} else {
$strCondition .= ' and 1=0';
}
if ($createTimeStart) {
$strCondition .= ' and create_time >=' . strtotime($createTimeStart . ' 00:00:00');
}
if ($createTimeEnd) {
$strCondition .= ' and create_time <=' . strtotime($createTimeEnd . ' 23:59:59');
}
$subSql = M('testing_user', 'tab_')->field(['user_id'])->where($subConditions)->select(false);
$strCondition .= ' and user_id in (' . $subSql . ')';
// $strCondition .= ' and promote_id in (' . $promoteService->subInSql($loginPromote) . ')';
if ($account) {
$user = M('user', 'tab_')->field(['id'])->where('account like "' . $account . '%"')->find();
if ($user) {
$conditions['user_id'] = $user['id'];
} else {
$strCondition .= ' and 1<>1';
}
}
if ($gameId) {
$conditions['game_id'] = $gameId;
}
if ($serverId) {
$conditions['server_id'] = $serverId;
}
if ($roleName) {
$conditions['role_name'] = ['like', $roleName . '%'];
}
$conditions['_string'] = $strCondition;
var_dump($conditions);
$query = M('user_play_info', 'tab_')->where($conditions)->order('create_time desc');
$countQuery = clone $query;
$count = $countQuery->count();
$roles = $query->page($page, $row)->select();
$page = set_pagination($count, $row);
if($page) {
$this->assign('_page', $page);
}
$records = $testingResourceService->makeTestingUserRecords($roles);
$this->assign('games', $this->getGames());
$this->assign('servers', $this->getServersByGameId($gameId));
$this->assign('count', $count);
$this->assign('pagination', $pagination);
$this->assign('records', $records);
$this->display();
}
private function getGames(array $visibleGameIds = null)
{
$map = [];
$map['_string'] = '1=1';
if (is_null($visibleGameIds)) {
} elseif (count($visibleGameIds) > 0) {
$map['_string'] = ' and id in (' . implode(',', $visibleGameIds) . ')';
} else {
$map['_string'] = ' and 1=0';
}
return M('game', 'tab_')->field('id,game_name')->where($map)->select();
}
private function getServersByGameId($gameId = 0)
{
if ($gameId == 0) {
return [];
}
$map = [];
$map['game_id'] = $gameId;
return M('server', 'tab_')
->field('id,server_name,server_id')
->where($map)
->order('server_id asc')
->select();
}
public function getServers()
{
$gameId = I('game_id', 0);
$servers = $this->getServersByGameId($gameId);
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['servers' => $servers]]);
}
public function gameSettings()
{
$page = I('p', 1);
$row = I('row', 10);
$gameId = I('base_game_id', 0);
$partnerId = I('partner_id', 0);
$conditions = [];
$conditions['_string'] = '1=1';
if ($partnerId > 0) {
$partnerService = new PartnerService();
$baseGames = $partnerService->findBaseGamesByPartnerId($partnerId);
if (empty($baseGames)) {
$conditions['_string'] = '1=0';
} else {
$conditions['base_game_id'] = ['in', array_column($baseGames, 'id')];
}
}
if ($gameId > 0) {
$conditions['base_game_id'] = $gameId;
}
$query = M('testing_game_setting', 'tab_')->where($conditions);
$countQuery = clone $query;
$items = $query->order('create_time desc')->page($page, $row)->select();
$count = $countQuery->count();
$baseGames = M('base_game', 'tab_')->select();
$baseGames = index_by_column('id', $baseGames);
$partners = M('partner', 'tab_')->field(['id', 'partner'])->select();
$partners = index_by_column('id', $partners);
$games = M('game', 'tab_')->where(['id', 'partner_id'])->select();
$games = index_by_column('id', $games);
foreach ($baseGames as $key => $baseGame) {
if ($baseGame['android_game_id'] > 0) {
$baseGame['partner_id'] = $games[$baseGame['android_game_id']]['partner_id'];
} else {
$baseGame['partner_id'] = $games[$baseGame['ios_game_id']]['partner_id'];
}
$baseGames[$key] = $baseGame;
}
$records = [];
foreach ($items as $item) {
$baseGame = $baseGames[$item['base_game_id']] ?? null;
$partnerId = $baseGame ? $baseGame['partner_id'] : 0;
$partner = $partners[$partnerId] ?? null;
$records[] = [
'id' => $item['id'],
'base_game_id' => $item['base_game_id'],
'game_name' => $baseGame ? $baseGame['name'] : '无此游戏',
'partner_name' => $partner ? $partner['partner'] : '--',
'rate' => $item['rate'],
'base_quota' => $item['base_quota'],
];
}
$page = set_pagination($count, $row);
if($page) {
$this->assign('_page', $page);
}
$this->assign('records', $records);
$this->assign('partners', $partners);
$this->assign('baseGames', $baseGames);
$this->display();
}
public function saveGameSetting()
{
$params = I('post.');
try {
$testingResourceService = new TestingResourceService();
$testingResourceService->saveGameSetting($params);
return $this->ajaxReturn(['status' => 1, 'message' => '保存成功']);
} catch (\Exception $e) {
return $this->ajaxReturn(['status' => 0, 'message' => '保存失败!' . $e->getMessage()]);
}
}
public function deleteGameSetting()
{
$id = I('id', 0);
M('testing_game_setting', 'tab_')->where(['id' => $id])->delete();
return $this->ajaxReturn(['status' => 1, 'message' => '删除成功']);
}
public function addTestingUsers()
{
$accountsStr = trim(I('accounts', ''), ',');
if ($accountsStr == '') {
return $this->ajaxReturn(['status' => 0, 'message' => '请输入测试资源账号']);
}
$accounts = explode(',', $accountsStr);
$testingResourceService = new TestingResourceService();
$result = $testingResourceService->addTestingUsers($accounts);
return $this->ajaxReturn(['status' => 1, 'message' => '请求成功', 'data' => $result]);
}
public function batches()
{
$gameId = I('game_id', 0);
$serverId = I('server_id', '');
$createTimeStart = I('create_time_start', '');
$createTimeEnd = I('create_time_end', '');
$verifyStatus = I('verify_status', -1);
$provideStatus = I('provide_status', -1);
$account = I('account');
$loginPromote = $this->getLoginPromote();
$promoteService = new PromoteService();
$subSql = M('user', 'tab_')
->where('id=tab_testing_resource_batch.user_id and promote_id in (' . $promoteService->subInSql($loginPromote) . ')')
->select(false);
$conditions = [
'_string' => '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;
}
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';
}
}
$query = M('testing_resource_batch', 'tab_')->where($conditions)->order('create_time desc');
list($batches, $pagination, $count) = $this->paginate($query);
$roles = [];
$applyPromotes = [];
$users = [];
$promotes = [];
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'])->where(['id' => ['in', array_column($batches, 'apply_promote_id')]])->select();
$applyPromotes = index_by_column('id', $applyPromotes);
if (count($users) > 0) {
$promotes = M('promote', 'tab_')->field(['id', 'account'])->where(['id' => ['in', array_column($users, 'promote_id')]])->select();
$promotes = index_by_column('id', $promotes);
}
}
$testingResourceService = new TestingResourceService();
$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;
$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'] : '--',
'user_account' => $role ?$role['user_account'] : '--',
'user_phone' => $user ? $user['phone'] : '',
'apply_promote_account' => $applyPromote ? $applyPromote['account'] : '',
'promote_account' => $promote['account'],
// 'history_provide_amount' => 0.00,
'apply_amount' => $batch['apply_amount'],
'provide_amount' => $batch['provide_amount'],
'verify_status' => $batch['verify_status'],
'verify_status_text' => $testingResourceService->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' => $testingResourceService->getProvideStatusText($batch['provide_status']),
'provide_time' => $batch['provide_time'] == 0 ? '--' : date('Y-m-d H:i:s', $batch['provide_time']),
'content' => $content,
];
}
$this->assign('verifyStatusList', TestingResourceService::$verifyStatusList);
$this->assign('provideStatusList', TestingResourceService::$provideStatusList);
$this->assign('servers', $this->getServersByGameId($gameId));
$this->assign('games', $this->getGames());
$this->assign('count', $count);
$this->assign('pagination', $pagination);
$this->assign('records', $records);
$this->display();
}
public function orders()
{
$id = I('id', 0);
$batch = M('testing_resource_batch', 'tab_')->where(['id' => $id])->find();
$role = M('user_play_info', 'tab_')
->field(['id', 'game_name', 'server_name', 'role_name', 'game_role_id', 'user_account'])
->where(['game_id' => $batch['game_id'], 'role_id' => $batch['role_id']])
->find();
$applyPromote = M('promote', 'tab_')->field(['id', 'account'])->where(['id' => $batch['apply_promote_id']])->find();
$promote = M('promote', 'tab_')->field(['id', 'account'])->where(['id' => $role['apply_promote_id']])->find();
$query = M('testing_resource_order', 'tab_')->where(['batch_id' => $id])->order('id desc');
list($orders, $pagination, $count) = $this->paginate($query);
$testingResourceService = new TestingResourceService();
foreach ($orders as $order) {
$records[] = [
'id' => $order['id'],
'create_time' => $batch['create_time'] == 0 ? '--' : date('Y-m-d H:i:s', $batch['create_time']),
'game_name' => $role['game_name'],
'user_account' => $role['user_account'],
'server_name' => $role['server_name'],
'role_name' => $role['role_name'],
'apply_promote_account' => $applyPromote ? $applyPromote['account'] : '',
'promote_account' => $promote['account'],
'ref_name' => $order['ref_name'],
'ref_amount' => $order['ref_amount'],
'num' => $order['num'],
'amount' => $order['num'] * $order['ref_amount'],
'remark' => $order['remark'],
'provide_status' => $order['provide_status'],
'provide_status_text' => $testingResourceService->getProvideStatusText($order['provide_status']),
];
}
$this->assign('count', $count);
$this->assign('pagination', $pagination);
$this->assign('records', $records);
$this->display();
}
}