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.

273 lines
11 KiB
PHP

<?php
namespace Home\Controller;
use Base\Model\PromoteModel;
use Base\Service\PromoteService;
use OSS\Core\OssException;
use Think\Model;
use Base\Service\TestingResourceService;
use Base\Repository\TestingResourceRepository;
use Base\Repository\GameRepository;
use Base\Service\GameService;
class TestingResourceController extends BaseController
{
public function index()
{
$params = I('get.');
$gameId = $params['game_id'] ?? 0;
$loginPromote = $this->getLoginPromote();
$repository = new TestingResourceRepository();
$query = $repository->getTestingRolesQuery($params, $loginPromote);
[$roles, $pagination, $count] = $this->paginate($query);
$records = $repository->makeTestingRoleRecords($roles);
$gameRepository = new GameRepository();
$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();
}
public function addTestingUsers()
{
$loginPromote = $this->getLoginPromote();
$accountsStr = trim(I('accounts', ''), ',');
if ($accountsStr == '') {
return $this->ajaxReturn(['status' => 0, 'message' => '请输入测试资源账号']);
}
$accounts = explode(',', $accountsStr);
$testingResourceService = new TestingResourceService();
$result = $testingResourceService->addTestingUsers($accounts, $loginPromote);
return $this->ajaxReturn(['status' => 1, 'message' => '请求成功', 'data' => $result]);
}
public function batches()
{
$params = I('get.');
$gameId = $params['game_id'] ?? 0;
$loginPromote = $this->getLoginPromote();
$repository = new TestingResourceRepository();
$query = $repository->getBatchesQuery($params, $loginPromote);
list($batches, $pagination, $count) = $this->paginate($query);
$records = $repository->makeBatchesRecords($batches);
$gameRepository = new GameRepository();
$this->assign('verifyStatusList', TestingResourceRepository::$verifyStatusList);
$this->assign('provideStatusList', TestingResourceRepository::$provideStatusList);
$this->assign('servers', $gameRepository->getServersByGameId($gameId));
$this->assign('games', $gameRepository->getChoiceGames());
$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);
$repository = new TestingResourceRepository();
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'],
'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' => $repository->getProvideStatusText($order['provide_status']),
];
}
$this->assign('count', $count);
$this->assign('pagination', $pagination);
$this->assign('records', $records);
$this->display();
}
public function apply()
{
$id = I('id', 0);
$role = null;
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'])
->where(['id' => $id])
->find();
}
$hasItf = 0;
$isEnableNum = 0;
$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();
$game = M('game', 'tab_')->where(['id' => $role['game_id']])->find(['id', 'data_share']);
$binding = M('testing_binding', 'tab_')->where(['game_id' => $role['game_id'], 'role_id' => $role['role_id']])->find();
if ($binding) {
$gameIds = [$role['game_id']];
if ($game['data_share'] == 1) {
$gameRepository = new GameRepository();
$baseGames = $gameRepository->getBaseGames();
$baseGame = $gameRepository->getBaseGameByGameId($role['game_id'], $baseGames);
$gameIds = $gameRepository->getGameIdsByBaseGame($baseGame);
}
$bindingRole = M('user_play_info', 'tab_')
->field(['id', 'role_id', 'user_id', 'game_id', 'server_id', 'user_account', 'role_name'])
->where(['game_id' => ['in', $gameIds], 'role_id' => $binding['bind_role_id']])
->find();
if ($bindingRole) {
$bindingRole['binding_time'] = $binding['create_time'];
$bindingRole['share_game_ids'] = $gameIds;
}
}
$repository = new TestingResourceRepository();
$gameSetting = $repository->getGameSettingByGameId($role['game_id']);
$hasItf = $gameSetting ? $gameSetting['has_itf'] : 0;
$isEnableNum = $gameSetting ? $gameSetting['is_enable_num'] : 0;
}
$testingResourceService = new TestingResourceService();
$quota = $testingResourceService->getRemainQuota($role, $bindingRole);
$this->assign('hasItf', $hasItf);
$this->assign('isEnableNum', $isEnableNum);
$games = M('game', 'tab_')->field(['id' , 'game_name'])->select();
$this->assign('games', $games);
$this->assign('servers', $servers);
$this->assign('bindingRole', $bindingRole);
$this->assign('role', $role);
$this->assign('quota', $quota);
$this->display();
}
public function doApply()
{
$params = I('post.');
$loginPromote = $this->getLoginPromote();
try {
$testingResourceService = new TestingResourceService();
$testingResourceService->apply($params, $loginPromote);
return $this->ajaxReturn(['status' => 1, 'message' => '申请成功,等待审核。']);
} catch (\Exception $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
public function bindRole()
{
$params = I('post.');
$loginPromote = $this->getLoginPromote();
try {
$testingResourceService = new TestingResourceService();
$testingResourceService->bindRole($params, $loginPromote);
return $this->ajaxReturn(['status' => 1, 'message' => '绑定成功']);
} catch (\Exception $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
public function getServers()
{
$gameId = I('game_id', 0);
$gameRepository = new GameRepository();
$servers = $gameRepository->getServersByGameId($gameId);
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['servers' => $servers]]);
}
public function getResourceTypes()
{
$gameId = I('game_id', 0);
$game = M('game', 'tab_')->field(['id', 'sdk_version'])->where(['id' => $gameId])->find();
try {
$testingResourceService = new TestingResourceService();
$resourceTypes = $testingResourceService->getResourceTypes($game);
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resourceTypes' => $resourceTypes]]);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage(), 'data' => ['resourceTypes' => []]]);
}
}
public function getResources()
{
$typeId = I('type_id', 0);
$gameId = I('game_id', 0);
$game = M('game', 'tab_')->field(['id', 'sdk_version'])->where(['id' => $gameId])->find();
try {
$testingResourceService = new TestingResourceService();
$resources = $testingResourceService->getResources($game, $typeId);
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resources' => $resources]]);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage(), 'data' => ['resources' => []]]);
}
}
public function getUserRoles()
{
$gameId = I('game_id', 0);
$roleId = I('role_id', 0);
$game = M('game', 'tab_')->where(['id' => $gameId])->find();
if (is_null($game)) {
return $this->ajaxReturn(['status' => 0, 'message' => '游戏不存在']);
}
$gameIds = [$gameId];
if ($game['data_share'] == 1) {
$gameRepository = new GameRepository();
$baseGames = $gameRepository->getBaseGames();
$baseGame = $gameRepository->getBaseGameByGameId($gameId, $baseGames);
if (is_null($baseGame)) {
return $this->ajaxReturn(['status' => 0, 'message' => '游戏不存在']);
}
$gameIds = $gameRepository->getGameIdsByBaseGame($baseGame);
}
$roles = M('user_play_info', 'tab_')
->field(['id', 'role_id', 'role_name'])
->where(['role_id' => $roleId, 'game_id' => ['in', $gameIds]])
->select();
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['roles' => $roles]]);
}
}