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
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;
4 years ago
use Base\Service\GameService;
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 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'],
'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;
$isEnableNum = 0;
4 years ago
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
$game = M('game', 'tab_')->where(['id' => $role['game_id']])->find(['id', 'data_share']);
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
$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);
}
4 years ago
$bindingRole = M('user_play_info', 'tab_')
->field(['id', 'role_id', 'user_id', 'game_id', 'server_id', 'user_account', 'role_name'])
4 years ago
->where(['game_id' => ['in', $gameIds], 'role_id' => $binding['bind_role_id']])
4 years ago
->find();
4 years ago
if ($bindingRole) {
$bindingRole['binding_time'] = $binding['create_time'];
4 years ago
$bindingRole['share_game_ids'] = $gameIds;
4 years ago
}
4 years ago
}
4 years ago
$repository = new TestingResourceRepository();
$gameSetting = $repository->getGameSettingByGameId($role['game_id']);
$hasItf = $gameSetting ? $gameSetting['has_itf'] : 0;
$isEnableNum = $gameSetting ? $gameSetting['is_enable_num'] : 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);
$this->assign('isEnableNum', $isEnableNum);
4 years ago
$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
$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' => []]]);
}
4 years ago
}
public function getResources()
{
$typeId = I('type_id', 0);
4 years ago
$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' => []]]);
}
4 years ago
}
public function getUserRoles()
{
$gameId = I('game_id', 0);
4 years ago
$roleId = I('role_id', 0);
4 years ago
4 years ago
$game = M('game', 'tab_')->where(['id' => $gameId])->find();
if (is_null($game)) {
return $this->ajaxReturn(['status' => 0, 'message' => '游戏不存在']);
4 years ago
}
4 years ago
$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);
}
4 years ago
$roles = M('user_play_info', 'tab_')
4 years ago
->field(['id', 'role_id', 'role_name'])
4 years ago
->where(['role_id' => $roleId, 'game_id' => ['in', $gameIds]])
4 years ago
->select();
4 years ago
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['roles' => $roles]]);
4 years ago
}
}