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.

263 lines
10 KiB
PHTML

<?php
namespace Home\Controller;
use Base\Model\PromoteModel;
use Base\Service\PromoteService;
use OSS\Core\OssException;
4 years ago
use Think\Model;
4 years ago
use Base\Service\TestingResourceService;
4 years ago
use Base\Repository\TestingResourceRepository;
use Base\Repository\GameRepository;
class TestingResourceController extends BaseController
{
public function index()
{
4 years ago
$params = I('get.');
4 years ago
$gameId = $params['game_id'] ?? 0;
$loginPromote = $this->getLoginPromote();
4 years ago
$repository = new TestingResourceRepository();
4 years ago
$query = $repository->getTestingRolesQuery($params, $loginPromote);
4 years ago
[$roles, $pagination, $count] = $this->paginate($query);
4 years ago
$records = $repository->makeTestingRoleRecords($roles);
4 years ago
$gameRepository = new GameRepository();
4 years ago
$this->assign('games', $gameRepository->getChoiceGames());
$this->assign('servers', $gameRepository->getServersByGameId($gameId));
$this->assign('count', $count);
$this->assign('pagination', $pagination);
$this->assign('records', $records);
$this->display();
}
4 years ago
public function testingUsers()
{
$params = I('get.');
$loginPromote = $this->getLoginPromote();
$repository = new TestingResourceRepository();
$query = $repository->getTestingUsersQuery($params, $loginPromote);
[$testingUsers, $pagination, $count] = $this->paginate($query);
$records = $repository->makeTestingUserRecords($testingUsers);
$this->assign('count', $count);
$this->assign('records', $records);
$this->assign('pagination', $pagination);
$this->display();
}
public function addTestingUsers()
{
$loginPromote = $this->getLoginPromote();
$accountsStr = trim(I('accounts', ''), ',');
4 years ago
if ($accountsStr == '') {
return $this->ajaxReturn(['status' => 0, 'message' => '请输入测试资源账号']);
}
$accounts = explode(',', $accountsStr);
4 years ago
$testingResourceService = new TestingResourceService();
$result = $testingResourceService->addTestingUsers($accounts, $loginPromote);
return $this->ajaxReturn(['status' => 1, 'message' => '请求成功', 'data' => $result]);
}
public function batches()
{
4 years ago
$params = I('get.');
4 years ago
$gameId = $params['game_id'] ?? 0;
$loginPromote = $this->getLoginPromote();
4 years ago
$repository = new TestingResourceRepository();
$query = $repository->getBatchesQuery($params, $loginPromote);
list($batches, $pagination, $count) = $this->paginate($query);
4 years ago
$records = $repository->makeBatchesRecords($batches);
4 years ago
4 years ago
$gameRepository = new GameRepository();
4 years ago
4 years ago
$this->assign('verifyStatusList', TestingResourceRepository::$verifyStatusList);
$this->assign('provideStatusList', TestingResourceRepository::$provideStatusList);
$this->assign('servers', $gameRepository->getServersByGameId($gameId));
$this->assign('games', $gameRepository->getChoiceGames());
4 years ago
$this->assign('count', $count);
$this->assign('pagination', $pagination);
$this->assign('records', $records);
$this->display();
}
public function orders()
{
4 years ago
$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();
4 years ago
4 years ago
$query = M('testing_resource_order', 'tab_')->where(['batch_id' => $id])->order('id desc');
4 years ago
list($orders, $pagination, $count) = $this->paginate($query);
4 years ago
$repository = new TestingResourceRepository();
4 years ago
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'],
4 years ago
'provide_status' => $order['provide_status'],
4 years ago
'provide_status_text' => $repository->getProvideStatusText($order['provide_status']),
4 years ago
];
}
4 years ago
$this->assign('count', $count);
$this->assign('pagination', $pagination);
$this->assign('records', $records);
$this->display();
}
public function apply()
4 years ago
{
4 years ago
$id = I('id', 0);
4 years ago
$role = null;
4 years ago
if ($id != 0) {
$role = M('user_play_info', 'tab_')
->field(['id', 'role_id', 'user_id', 'game_id', 'server_id', 'user_account', 'role_name', 'testing_other_quota'])
4 years ago
->where(['id' => $id])
->find();
4 years ago
}
4 years ago
$hasItf = 0;
4 years ago
$servers = [];
$bindingRole = null;
if ($role) {
$servers = M('server', 'tab_')->field('id,server_name,server_id')->where(['game_id' => $role['game_id']])->order('server_id asc')->select();
4 years ago
$binding = M('testing_binding', 'tab_')->where(['game_id' => $role['game_id'], 'role_id' => $role['role_id']])->find();
4 years ago
if ($binding) {
4 years ago
$bindingRole = M('user_play_info', 'tab_')
->field(['id', 'role_id', 'user_id', 'game_id', 'server_id', 'user_account', 'role_name'])
->where(['game_id' => $binding['game_id'], 'role_id' => $binding['bind_role_id']])
->find();
4 years ago
if ($bindingRole) {
$bindingRole['binding_time'] = $binding['create_time'];
}
4 years ago
}
4 years ago
$repository = new TestingResourceRepository();
$gameSetting = $repository->getGameSettingByGameId($role['game_id']);
$hasItf = $gameSetting ? $gameSetting['has_itf'] : 0;
4 years ago
}
4 years ago
4 years ago
$testingResourceService = new TestingResourceService();
$quota = $testingResourceService->getRemainQuota($role, $bindingRole);
4 years ago
$this->assign('hasItf', $hasItf);
$games = M('game', 'tab_')->field(['id' , 'game_name'])->select();
4 years ago
4 years ago
$this->assign('games', $games);
4 years ago
$this->assign('servers', $servers);
$this->assign('bindingRole', $bindingRole);
$this->assign('role', $role);
4 years ago
$this->assign('quota', $quota);
4 years ago
$this->display();
}
public function doApply()
{
4 years ago
$params = I('post.');
$loginPromote = $this->getLoginPromote();
4 years ago
try {
4 years ago
$testingResourceService = new TestingResourceService();
$testingResourceService->apply($params, $loginPromote);
return $this->ajaxReturn(['status' => 1, 'message' => '申请成功,等待审核。']);
4 years ago
} catch (\Exception $e) {
4 years ago
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
public function bindRole()
{
4 years ago
$params = I('post.');
4 years ago
$loginPromote = $this->getLoginPromote();
4 years ago
try {
$testingResourceService = new TestingResourceService();
$testingResourceService->bindRole($params, $loginPromote);
return $this->ajaxReturn(['status' => 1, 'message' => '绑定成功']);
4 years ago
} catch (\Exception $e) {
4 years ago
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
4 years ago
public function getServers()
{
$gameId = I('game_id', 0);
4 years ago
$gameRepository = new GameRepository();
$servers = $gameRepository->getServersByGameId($gameId);
4 years ago
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['servers' => $servers]]);
}
public function getResourceTypes()
{
$gameId = I('game_id', 0);
4 years ago
$testingResourceService = new TestingResourceService();
$resourceTypes = $testingResourceService->getResourceTypes($gameId);
4 years ago
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resourceTypes' => $resourceTypes]]);
}
public function getResources()
{
$typeId = I('type_id', 0);
4 years ago
$testingResourceService = new TestingResourceService();
$resources = $testingResourceService->getResources($typeId);
4 years ago
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resources' => $resources]]);
}
public function getUserRoles()
{
$gameId = I('game_id', 0);
$serverId = I('server_id', 0);
$userAccount = I('user_account', '');
$server = M('server', 'tab_')->field(['id', 'server_name', 'server_id'])->where(['id' => $serverId])->find();
if (is_null($server)) {
return $this->ajaxReturn(['status' => 0, 'message' => '区服不存在']);
}
4 years ago
4 years ago
$user = M('user', 'tab_')->field(['id', 'promote_id'])->where(['account' => $userAccount])->find();
if (is_null($user)) {
return $this->ajaxReturn(['status' => 0, 'message' => '账号不存在']);
}
4 years ago
$testingUser = M('testing_user', 'tab_')->where(['user_account' => $userAccount])->find();
$isTestingAccount = is_null($testingUser) ? false : true;
4 years ago
$roles = M('user_play_info', 'tab_')
4 years ago
->field(['id', 'role_id', 'role_name'])
4 years ago
->where(['user_account' => $userAccount, 'game_id' => $gameId, 'server_id' => $server['server_id']])
->select();
4 years ago
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['roles' => $roles, 'is_testing_account' => $isTestingAccount]]);
4 years ago
}
}