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.

627 lines
26 KiB
PHTML

4 years ago
<?php
namespace Admin\Controller;
use Base\Model\PromoteModel;
use Base\Service\PromoteService;
use Base\Service\TestingResourceService;
use Base\Service\PartnerService;
4 years ago
use Base\Repository\TestingResourceRepository;
use Base\Repository\GameRepository;
4 years ago
class TestingResourceController extends ThinkController
{
public function index()
{
4 years ago
$params = I('get.');
4 years ago
$gameId = $params['game_id'] ?? 0;
4 years ago
$repository = new TestingResourceRepository();
4 years ago
$query = $repository->getTestingRolesQuery($params);
4 years ago
4 years ago
[$roles, $page, $count] = $this->paginate($query);
4 years ago
4 years ago
$records = $repository->makeTestingRoleRecords($roles);
4 years ago
4 years ago
$gameRepository = new GameRepository();
4 years ago
4 years ago
$this->assign('statusList', TestingResourceRepository::$userStatusList);
4 years ago
$this->assign('games', $gameRepository->getChoiceGames());
$this->assign('servers', $gameRepository->getServersByGameId($gameId));
4 years ago
$this->assign('count', $count);
$this->assign('records', $records);
4 years ago
$this->assign('_page', $page);
4 years ago
$this->display();
}
4 years ago
public function users()
{
$params = I('get.');
$repository = new TestingResourceRepository();
$query = $repository->getTestingUsersQuery($params);
[$testingUsers, $page, $count] = $this->paginate($query);
$records = $repository->makeTestingUserRecords($testingUsers);
$this->assign('statusList', TestingResourceRepository::$userStatusList);
$this->assign('count', $count);
$this->assign('records', $records);
$this->assign('_page', $page);
$this->display();
}
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 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;
}
4 years ago
$query = M('testing_game_setting', 'tab_')->where($conditions)->order('create_time desc');
[$items, $page, $count] = $this->paginate($query);
4 years ago
$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;
}
4 years ago
$spendList = [];
$provideItems = [];
if (count($items) > 0) {
$pageGameIds = array_merge(array_column($baseGames, 'android_game_id'), array_column($baseGames, 'ios_game_id'));
/* $spendCondition = [
'pay_status' => 1,
'game_id' => ['in', $pageGameIds]
];
$spendList = M('spend', 'tab_')->field('sum(pay_amount) amount, game_id')->where($spendCondition)->group('game_id')->select();
$spendList = index_by_column('game_id', $spendList); */
$provideItems = M('testing_resource_batch', 'tab_')
->field('sum(provide_amount) amount, game_id')
->where([
'verify_status' => 1,
'game_id' => ['in', $pageGameIds]
])
->group('game_id')
->select();
$provideItems = index_by_column('game_id', $provideItems);
}
4 years ago
$records = [];
foreach ($items as $item) {
$baseGame = $baseGames[$item['base_game_id']] ?? null;
$partnerId = $baseGame ? $baseGame['partner_id'] : 0;
$partner = $partners[$partnerId] ?? null;
4 years ago
/* $aSpendItem = $spendList[$baseGame['android_game_id']] ?? null;
$bSpendItem = $spendList[$baseGame['ios_game_id']] ?? null;
$aSpendQuota = $aSpendItem ? $aSpendItem['amount'] : 0;
$bSpendQuota = $bSpendItem ? $bSpendItem['amount'] : 0; */
$aProvideItem = $provideItems[$baseGame['ios_game_id']] ?? null;
$bProvideItem = $provideItems[$baseGame['android_game_id']] ?? null;
$aProvideQuota = $aProvideItem ? $aProvideItem['amount'] : 0;
$bProvideQuota = $bProvideItem ? $bProvideItem['amount'] : 0;
4 years ago
$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'],
4 years ago
// 'quota' => round(($aSpendQuota + $bSpendQuota) * $item['rate'] / 100, 2),
'provide_quota' => $aProvideQuota + $bProvideQuota
4 years ago
];
}
4 years ago
$this->assign('_page', $page);
4 years ago
$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()
{
4 years ago
$params = I('get.');
4 years ago
$isExport = $params['export'] ?? 0;
4 years ago
$repository = new TestingResourceRepository();
$query = $repository->getBatchesQuery($params);
4 years ago
if ($isExport == 1) {
$batches = $query->select();
$records = $repository->makeBatchesRecords($batches);
data2csv($records, '申请批次列表', [
'batch_no' => '批次号',
'create_time' => '申请时间',
'game_name' => '游戏名称',
'server_name' => '区服名称',
'role_name' => '角色名称',
'user_account' => '测试账号',
'user_phone' => '手机号',
'promote_account' => '所属推广员',
4 years ago
'apply_username' => '申请人',
'verify_admin_username' => '审核人',
4 years ago
'apply_amount' => '申请金额',
'provide_amount' => '发放金额',
'verify_status_text' => '审核状态',
'verify_time' => '审核时间',
'provide_status_text' => '发放状态',
'provide_time' => '发放时间'
]);
}
4 years ago
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
$gameId = $params['game_id'] ?? 0;
4 years ago
$admins = M('ucenter_member', 'sys_')->field(['id', 'username'])->select();
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('admins', $admins);
4 years ago
$this->assign('count', $count);
4 years ago
$this->assign('_page', $pagination);
4 years ago
$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);
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'],
'provide_status' => $order['provide_status'],
4 years ago
'provide_status_text' => $repository->getProvideStatusText($order['provide_status']),
4 years ago
];
}
$this->assign('count', $count);
4 years ago
$this->assign('_page', $pagination);
4 years ago
$this->assign('records', $records);
$this->display();
}
4 years ago
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();
4 years ago
if ($bindingRole) {
$bindingRole['binding_time'] = $binding['create_time'];
}
4 years ago
}
$repository = new TestingResourceRepository();
$gameSetting = $repository->getGameSettingByGameId($role['game_id']);
$hasItf = $gameSetting ? $gameSetting['has_itf'] : 0;
}
4 years ago
4 years ago
$testingResourceService = new TestingResourceService();
$quota = $testingResourceService->getRemainQuota($role, $bindingRole);
4 years ago
$games = M('game', 'tab_')->field(['id' , 'game_name'])->select();
4 years ago
$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.');
4 years ago
$userAuth = session('user_auth');
4 years ago
try {
$testingResourceService = new TestingResourceService();
4 years ago
$testingResourceService->apply($params, null, $userAuth['uid']);
4 years ago
return $this->ajaxReturn(['status' => 1, 'message' => '申请成功,等待审核。']);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
public function verify()
{
$ids = I('ids', []);
4 years ago
$status = I('status', 0);
if (count($ids) == 0) {
return $this->ajaxReturn(['status' => 0, 'message' => '请选择要审核的批次']);
}
if (!in_array($status, [1, 2])) {
return $this->ajaxReturn(['status' => 0, 'message' => '请求状态异常']);
}
try {
$service = new TestingResourceService();
$batches = M('testing_resource_batch', 'tab_')->where(['verify_status' => 0, 'id' => ['in', $ids]])->select();
if (count($batches) == 0) {
return $this->ajaxReturn(['status' => 0, 'message' => '无未审核批次']);
}
4 years ago
$userAuth = session('user_auth');
4 years ago
foreach ($batches as $batch) {
if ($status == 1) {
4 years ago
$service->verify($batch, $userAuth['uid']);
4 years ago
} elseif ($status == 2) {
4 years ago
$remark = '审核拒绝';
$service->verifyRefuse($batch, $remark, $userAuth['uid']);
4 years ago
}
}
return $this->ajaxReturn(['status' => 1, 'message' => '操作成功']);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
public function provide()
{
$ids = I('ids', []);
$status = I('status', 0);
if (count($ids) == 0) {
return $this->ajaxReturn(['status' => 0, 'message' => '请选择要审核的批次']);
}
if (!in_array($status, [1, 2])) {
return $this->ajaxReturn(['status' => 0, 'message' => '请求状态异常']);
}
try {
$service = new TestingResourceService();
$batches = M('testing_resource_batch', 'tab_')->where(['verify_status' => 1, 'provide_status' => 0, 'id' => ['in', $ids]])->select();
if (count($batches) == 0) {
return $this->ajaxReturn(['status' => 0, 'message' => '无符合条件的批次']);
}
foreach ($batches as $batch) {
if ($status == 1) {
$service->provide($batch);
} elseif ($status == 2) {
$service->provideRefuse($batch);
}
}
return $this->ajaxReturn(['status' => 1, 'message' => '操作成功']);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
public function bindRole()
{
$params = I('post.');
try {
$testingResourceService = new TestingResourceService();
$testingResourceService->bindRole($params);
return $this->ajaxReturn(['status' => 1, 'message' => '绑定成功']);
4 years ago
} catch (\Throwable $e) {
4 years ago
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
public function unbindRole()
{
$bindingId = I('binding_id', 0);
try {
$testingResourceService = new TestingResourceService();
$testingResourceService->unbindRole($bindingId);
return $this->ajaxReturn(['status' => 1, 'message' => '解绑成功']);
4 years ago
} catch (\Throwable $e) {
4 years ago
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
public function setOtherQuota()
{
$id = I('id', 0);
$otherQuota = I('other_quota', 0);
M('user_play_info', 'tab_')->where(['id' => $id])->save(['testing_other_quota' => $otherQuota]);
return $this->ajaxReturn(['status' => 1, 'message' => '设置成功']);
}
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' => '区服不存在']);
}
$user = M('user', 'tab_')->field(['id', 'promote_id'])->where(['account' => $userAccount])->find();
if (is_null($user)) {
return $this->ajaxReturn(['status' => 0, 'message' => '账号不存在']);
}
$testingUser = M('testing_user', 'tab_')->where(['user_account' => $userAccount])->find();
$isTestingAccount = is_null($testingUser) ? false : true;
$roles = M('user_play_info', 'tab_')
->field(['id', 'role_id', 'role_name'])
->where(['user_account' => $userAccount, 'game_id' => $gameId, 'server_id' => $server['server_id']])
->select();
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['roles' => $roles, 'is_testing_account' => $isTestingAccount]]);
}
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 exportOrders()
{
$params = I('get.');
$repository = new TestingResourceRepository();
$batches = $repository->getBatchesQuery($params)->select();
$batches = index_by_column('id', $batches);
$records = [];
if (count($batches)) {
$gameRoleIds = [];
foreach ($batches as $batch) {
$gameRoleIds[] = $repository->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', 'promote_id'])
->where(['game_role_id' => ['in', $gameRoleIds]])
->select();
$roles = index_by_column('game_role_id', $roles);
$applyPromotes = M('promote', 'tab_')->field(['id', 'account'])->where(['id' => ['in', array_column($batches, 'apply_promote_id')]])->select();
$applyPromotes = index_by_column('id', $applyPromotes);
$verifyAdminIds = array_column($batches, 'verify_admin_id');
$verifyAdmins = M('ucenter_member', 'sys_')->field(['id', 'username'])->where(['id' => ['in', $verifyAdminIds]])->select();
$verifyAdmins = index_by_column('id', $verifyAdmins);
4 years ago
$promotes = [];
if (count($roles) > 0) {
$promotes = M('promote', 'tab_')->field(['id', 'account'])->where(['id' => ['in', array_column($roles, 'promote_id')]])->select();
$promotes = index_by_column('id', $promotes);
}
$orders = M('testing_resource_order', 'tab_')->where(['batch_id' => ['in', array_column($batches, 'id')]])->order('batch_id desc')->select();
foreach ($orders as $order) {
$batch = $batches[$order['batch_id']];
$roleKey = $repository->getGameRoleId($batch['game_id'], $batch['role_id']);
$role = isset($roles[$roleKey]) ? $roles[$roleKey] : null;
$applyPromote = $applyPromotes[$batch['apply_promote_id']] ?? null;
$promote = $role ? ($promotes[$role['promote_id']] ?? null) : null;
$verifyAdmin = $verifyAdmins[$batch['verify_admin_id']] ?? null;
4 years ago
$records[] = [
'id' => $order['id'],
'batch_no' => substr($batch['batch_no'], 14),
'create_time' => $batch['create_time'] == 0 ? '--' : date('Y-m-d H:i:s', $batch['create_time']),
'game_name' => $role ? $role['game_name'] : '',
'user_account' => $role ? $role['user_account'] : '',
'server_name' => $role ? $role['server_name'] : '',
'role_name' => $role ? $role['role_name'] : '',
'promote_account' => $promote ? $promote['account'] : '',
'verify_admin_username' => $verifyAdmin ? $verifyAdmin['username'] : '系統',
4 years ago
'ref_name' => $order['ref_name'],
'ref_amount' => $order['ref_amount'],
'num' => $order['num'],
'amount' => $order['num'] * $order['ref_amount'],
'remark' => $order['remark'],
'verify_status_text' => $repository->getVerifyStatusText($batch['verify_status']),
'provide_status_text' => $repository->getProvideStatusText($order['provide_status']),
];
}
4 years ago
}
4 years ago
data2csv($records, '批次订单列表', [
'batch_no' => '批次号',
'create_time' => '申请时间',
'game_name' => '游戏名称',
'server_name' => '区服名称',
'user_account' => '测试账号',
'role_name' => '角色名称',
'promote_account' => '所属推广员',
'verify_admin_username' => '审核人',
4 years ago
'ref_name' => '资源名称',
'ref_amount' => '资源价值',
'num' => '申请数量',
'amount' => '申请金额',
'remark' => '申请备注',
'verify_status_text' => '审核状态',
'provide_status_text' => '发放状态'
]);
4 years ago
}
4 years ago
public function deleteTestingUser()
{
$userId = I('user_id', 0);
try {
$testingResourceService = new TestingResourceService();
$testingResourceService->deleteTestingUser($userId);
return $this->ajaxReturn(['status' => 1, 'message' => '删除成功']);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
public function verifyTestingUsers()
{
$userIds = I('user_ids', 0);
$verifyStatus = I('verify_status', 1);
try {
$testingResourceService = new TestingResourceService();
$testingResourceService->verifyTestingUser($userIds, $verifyStatus);
return $this->ajaxReturn(['status' => 1, 'message' => '审核成功']);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
public function unfreezeTestingUser()
{
$userId = I('user_id', 0);
try {
$testingResourceService = new TestingResourceService();
$testingResourceService->unfreezeTestingUser($userId);
return $this->ajaxReturn(['status' => 1, 'message' => '解禁成功']);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
public function freezeTestingUser()
{
$userId = I('user_id', 0);
try {
$testingResourceService = new TestingResourceService();
$testingResourceService->freezeTestingUser($userId);
return $this->ajaxReturn(['status' => 1, 'message' => '禁用成功']);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
4 years ago
}