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.

275 lines
10 KiB
PHP

<?php
namespace Admin\Controller;
use Base\Model\PromoteModel;
use Base\Service\PromoteService;
use Base\Service\TestingResourceService;
use Base\Service\PartnerService;
use Base\Repository\TestingResourceRepository;
use Base\Repository\GameRepository;
class TestingResourceController extends ThinkController
{
public function index()
{
$params = I('get.');
$repository = new TestingResourceRepository();
$query = $repository->getTestingUsersQuery($params);
[$roles, $page, $count] = $this->paginate($query);
$records = $repository->makeTestingUserRecords($roles);
$gameRepository = new GameRepository();
$this->assign('games', $gameRepository->getChoiceGames());
$this->assign('servers', $gameRepository->getServersByGameId($gameId));
$this->assign('count', $count);
$this->assign('records', $records);
$this->assign('_page', $page);
$this->display();
}
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 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)->order('create_time desc');
[$items, $page, $count] = $this->paginate($query);
$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'],
];
}
$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()
{
$params = I('get.');
$repository = new TestingResourceRepository();
$query = $repository->getBatchesQuery($params);
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('_page', $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'],
'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' => $repository->getProvideStatusText($order['provide_status']),
];
}
$this->assign('count', $count);
$this->assign('_page', $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;
$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();
$binding = M('testing_binding', 'tab_')->where(['game_id' => $role['game_id'], 'role_id' => $role['role_id']])->find();
if ($binding) {
$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();
}
$repository = new TestingResourceRepository();
$gameSetting = $repository->getGameSettingByGameId($role['game_id']);
$hasItf = $gameSetting ? $gameSetting['has_itf'] : 0;
}
$testingResourceService = new TestingResourceService();
$quota = $testingResourceService->getRemainQuota($role, $bindingRole);
/**
* @todo 目前固定游戏猫
*/
$games = M('game', 'tab_')->field(['id' , 'game_name'])->where(['id' => ['in', [229, 230]]])->select();
$this->assign('hasItf', $hasItf);
$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.');
try {
$testingResourceService = new TestingResourceService();
$testingResourceService->apply($params);
return $this->ajaxReturn(['status' => 1, 'message' => '申请成功,等待审核。']);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
public function verify()
{
$ids = I('ids', []);
$service = new TestingResourceService();
$batches = M('testing_resource_batch', 'tab_')->where(['verify_status' => 0, 'id' => ['in', $ids]])->select();
foreach ($batches as $batch) {
$service->verify($batch);
}
}
}