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.

594 lines
24 KiB
PHTML

<?php
namespace Home\Controller;
use Base\Model\PromoteModel;
use Base\Service\PromoteService;
use OSS\Core\OssException;
4 years ago
use Base\Tool\GameCatClient;
use Think\Model;
4 years ago
use Base\Service\TestingResourceService;
class TestingResourceController extends BaseController
{
private $gameBaseQuota = [
229 => 300,
230 => 300,
];
public function index()
{
$createTimeStart = I('create_time_start', '');
$createTimeEnd = I('create_time_end', '');
$gameId = I('game_id', 0);
$serverId = I('server_id', '');
$account = I('account');
$roleName = I('role_name');
$loginPromote = $this->getLoginPromote();
$conditions = [];
4 years ago
$subConditions = [
'_string' => '1=1'
];
4 years ago
$promoteService = new PromoteService();
$visibleGameIds = $promoteService->getVisibleGameIds($loginPromote);
$strCondition = 'game_id in (0)';
if (count($visibleGameIds) > 0) {
$strCondition = 'game_id in (' . implode(',', $visibleGameIds) . ')';
}
4 years ago
if ($createTimeStart) {
$strCondition .= ' and create_time >=' . strtotime($createTimeStart . ' 00:00:00');
}
if ($createTimeEnd) {
$strCondition .= ' and create_time <=' . strtotime($createTimeEnd . ' 23:59:59');
}
4 years ago
$subSql = M('testing_user', 'tab_')->field(['user_id'])->where($subConditions)->select(false);
4 years ago
$strCondition .= ' and user_id in (' . $subSql . ')';
4 years ago
$strCondition .= ' and promote_id in (' . $promoteService->subInSql($loginPromote) . ')';
if ($account) {
4 years ago
$user = M('user', 'tab_')->field(['id'])->where('account like "' . $account . '%"')->find();
if ($user) {
$conditions['user_id'] = $user['id'];
} else {
$strCondition .= ' and 1<>1';
}
}
if ($gameId) {
$conditions['game_id'] = $gameId;
}
if ($serverId) {
$conditions['server_id'] = $serverId;
}
if ($roleName) {
$conditions['role_name'] = ['like', $roleName . '%'];
}
$conditions['_string'] = $strCondition;
$query = M('user_play_info', 'tab_')->where($conditions)->order('create_time desc');
list($roles, $pagination, $count) = $this->paginate($query);
4 years ago
$testingResourceService = new TestingResourceService();
$records = $testingResourceService->makeTestingUserRecords($roles);
4 years ago
$this->assign('games', $this->getGames());
$this->assign('servers', $this->getServersByGameId($gameId));
$this->assign('count', $count);
$this->assign('pagination', $pagination);
$this->assign('records', $records);
$this->display();
}
4 years ago
private function getGameRoleId($gameId, $roleId)
{
return $gameId . '#' . $roleId;
}
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
$gameId = I('game_id', 0);
$serverId = I('server_id', '');
$createTimeStart = I('create_time_start', '');
$createTimeEnd = I('create_time_end', '');
$verifyStatus = I('verify_status', -1);
4 years ago
$provideStatus = I('provide_status', -1);
$account = I('account');
$loginPromote = $this->getLoginPromote();
$promoteService = new PromoteService();
4 years ago
$subSql = M('user', 'tab_')
->where('id=tab_testing_resource_batch.user_id and promote_id in (' . $promoteService->subInSql($loginPromote) . ')')
->select(false);
$conditions = [
4 years ago
'_string' => 'exists (' . $subSql . ')'
];
4 years ago
if ($createTimeStart) {
4 years ago
$conditions['_string'] .= ' and create_time >=' . strtotime($createTimeStart . ' 00:00:00');
}
4 years ago
if ($createTimeEnd) {
4 years ago
$conditions['_string'] .= ' and create_time <=' . strtotime($createTimeEnd . ' 23:59:59');
}
if ($verifyStatus != -1) {
$conditions['verify_status'] = $verifyStatus;
}
4 years ago
if ($provideStatus != -1) {
$conditions['provide_status'] = $provideStatus;
}
4 years ago
if ($gameId) {
$conditions['game_id'] = $gameId;
}
if ($serverId) {
$conditions['server_id'] = $serverId;
}
if ($account) {
4 years ago
$user = M('user', 'tab_')->field(['id'])->where('account like "' . $account . '%"')->find();
if ($user) {
$conditions['user_id'] = $user['id'];
} else {
4 years ago
$conditions['_string'] .= ' and 1<>1';
}
}
4 years ago
$query = M('testing_resource_batch', 'tab_')->where($conditions)->order('create_time desc');
list($batches, $pagination, $count) = $this->paginate($query);
4 years ago
$roles = [];
$applyPromotes = [];
$users = [];
$promotes = [];
if (count($batches) > 0) {
$gameRoleIds = [];
foreach ($batches as $batch) {
$gameRoleIds[] = $this->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'])
->where(['game_role_id' => ['in', $gameRoleIds]])
->select();
$roles = index_by_column('game_role_id', $roles);
$users = M('user', 'tab_')->field(['id', 'account', 'phone', 'promote_id'])->where(['id' => ['in', array_column($batches, 'user_id')]])->select();
$users = index_by_column('id', $users);
$applyPromotes = M('promote', 'tab_')->field(['id', 'account'])->where(['id' => ['in', array_column($batches, 'apply_promote_id')]])->select();
$applyPromotes = index_by_column('id', $applyPromotes);
if (count($users) > 0) {
$promotes = M('promote', 'tab_')->field(['id', 'account'])->where(['id' => ['in', array_column($users, 'promote_id')]])->select();
$promotes = index_by_column('id', $promotes);
}
}
4 years ago
$testingResourceService = new TestingResourceService();
4 years ago
4 years ago
$records = [];
foreach ($batches as $batch) {
4 years ago
$roleKey = $this->getGameRoleId($batch['game_id'], $batch['role_id']);
$role = isset($roles[$roleKey]) ? $roles[$roleKey] : null;
$user = $users[$batch['user_id']] ?? null;
$applyPromote = $applyPromotes[$batch['apply_promote_id']] ?? null;
$promote = $user && isset($promotes[$user['promote_id']]) ? $promotes[$user['promote_id']] : null;
4 years ago
$records[] = [
'id' => $batch['id'],
4 years ago
'batch_no' => substr($batch['batch_no'], 14),
4 years ago
'create_time' => date('Y-m-d H:i:s', $batch['create_time']),
4 years ago
'game_name' => $role ? $role['game_name'] : '--',
'server_name' => $role ? $role['server_name'] : '--',
'role_name' => $role ? $role['role_name'] : '--',
'user_account' => $role ?$role['user_account'] : '--',
'user_phone' => $user ? $user['phone'] : '',
'apply_promote_account' => $applyPromote ? $applyPromote['account'] : '',
'promote_account' => $promote['account'],
// 'history_provide_amount' => 0.00,
4 years ago
'apply_amount' => $batch['apply_amount'],
'provide_amount' => $batch['provide_amount'],
4 years ago
'verify_status' => $batch['verify_status'],
4 years ago
'verify_status_text' => $testingResourceService->getVerifyStatusText($batch['verify_status']),
4 years ago
'verify_time' => $batch['verify_time'] == 0 ? '--' : date('Y-m-d H:i:s', $batch['verify_time']),
'provide_status' => $batch['provide_status'],
4 years ago
'provide_status_text' => $testingResourceService->getProvideStatusText($batch['provide_status']),
4 years ago
'provide_time' => $batch['provide_time'] == 0 ? '--' : date('Y-m-d H:i:s', $batch['provide_time']),
4 years ago
'content' => $content,
];
}
4 years ago
$this->assign('verifyStatusList', TestingResourceService::$verifyStatusList);
$this->assign('provideStatusList', TestingResourceService::$provideStatusList);
4 years ago
$this->assign('servers', $this->getServersByGameId($gameId));
$this->assign('games', $this->getGames());
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
$testingResourceService = new TestingResourceService();
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'],
'provide_status_text' => $testingResourceService->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
}
$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
}
}
4 years ago
4 years ago
$testingResourceService = new TestingResourceService();
$quota = $testingResourceService->getRemainQuota($role, $bindingRole);
4 years ago
/**
* @todo 目前固定游戏猫
*/
$games = M('game', 'tab_')->field(['id' , 'game_name'])->where(['id' => ['in', [229, 230]]])->select();
$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
$gameId = I('game_id', 0);
4 years ago
$roleId = I('role_id', '');
4 years ago
$serverId = I('server_id', 0);
$userAccount = I('user_account', '');
$records = I('records', []);
$loginPromote = $this->getLoginPromote();
if ($loginPromote['level'] > 2) {
4 years ago
return $this->ajaxReturn(['status' => 0, 'message' => '权限不足']);
}
4 years ago
$resources = [];
/**
* @todo 目前仅限游戏猫
*/
4 years ago
if ($gameId == 229) {
$resources = $this->getGameCatResources('android');
} elseif ($gameId == 230) {
$resources = $this->getGameCatResources('ios');
4 years ago
} else {
4 years ago
return $this->ajaxReturn(['status' => 0, 'message' => '该游戏不可申请资源']);
}
$binding = M('testing_binding', 'tab_')->where(['game_id' => $gameId, 'role_id' => $roleId])->find();
4 years ago
/* if (is_null($binding)) {
4 years ago
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' => '玩家账号不存在']);
}
$testingUser = M('testing_user', 'tab_')->where(['user_id' => $user['id']])->find();
if (is_null($testingUser)) {
return $this->ajaxReturn(['status' => 0, 'message' => '测试账号不存在']);
}
$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
$promoteService = new PromoteService();
4 years ago
$role = M('user_play_info', 'tab_')
->field(['id', 'role_id', 'promote_id', 'game_id', 'testing_other_quota'])
4 years ago
->where(['user_id' => $user['id'], 'game_id' => $gameId, 'server_id' => $server['server_id'], 'role_id' => $roleId])
4 years ago
->find();
if (is_null($role)) {
return $this->ajaxReturn(['status' => 0, 'message' => '角色不存在']);
}
4 years ago
$otherRoleBatch = M('testing_resource_batch', 'tab_')
->where([
'user_id' => $user['id'],
'game_id' => $gameId,
'server_id' => $server['server_id'],
'role_id' => ['neq', $roleId],
'verify_status' => ['in', [0, 1]],
])
->find();
if ($otherRoleBatch) {
return $this->ajaxReturn(['status' => 0, 'message' => '每个账号同区服只能申请一个角色']);
}
4 years ago
$testPromote = M('promote', 'tab_')->field(['id', 'chain'])->where(['id' => $role['promote_id']])->find();
if (is_null($testPromote) || !$promoteService->isSubOrSelf($testPromote, $loginPromote)) {
return $this->ajaxReturn(['status' => 0, 'message' => '测试角色所属推广员异常']);
}
4 years ago
$bindingRole = null;
if ($binding) {
$bindingRole = M('user_play_info', 'tab_')
->field(['id', 'role_id', 'user_id', 'promote_id', 'game_id'])
->where(['game_id' => $gameId, 'role_id' => $binding['bind_role_id']])
->find();
if (is_null($bindingRole)) {
return $this->ajaxReturn(['status' => 0, 'message' => '绑定玩家角色不存在']);
}
$bindPromote = M('promote', 'tab_')->field(['id', 'chain'])->where(['id' => $bindingRole['promote_id']])->find();
if (is_null($bindPromote) || !$promoteService->isSubOrSelf($bindPromote, $loginPromote)) {
return $this->ajaxReturn(['status' => 0, 'message' => '绑定角色所属推广员异常']);
}
/* if ($testPromote['id'] != $bindPromote['id']) {
return $this->ajaxReturn(['status' => 0, 'message' => '测试账号与玩家账号所属推广员不同']);
} */
4 years ago
}
$amount = 0;
4 years ago
foreach ($records as $key => $record) {
if (isset($resources[$record['resource_id']])) {
$value = $resources[$record['resource_id']]['amount'];
$records[$key]['value'] = $value;
$records[$key]['resource_name'] = $resources[$record['resource_id']]['name'];
$amount += $record['num'] * $value;
} else {
return $this->ajaxReturn(['status' => 0, 'message' => '含有资源内容不存在']);
}
4 years ago
/**
* @todo 游戏猫只能每个资源数量只能为1
*/
if ($record['num'] != 1) {
return $this->ajaxReturn(['status' => 0, 'message' => '该游戏每次申请单项资源数量只能为1']);
}
}
4 years ago
$testingResourceService = new TestingResourceService();
$remainQuota = $testingResourceService->getRemainQuota($role, $bindingRole);
4 years ago
if ($amount > $remainQuota) {
4 years ago
return $this->ajaxReturn(['status' => 0, 'message' => '额度不足']);
4 years ago
}
4 years ago
$batchNo = date('YmdHis') . substr(md5($loginPromote['id'] . strval(microtime(true)) . rand(0, 9999)), 8, 16);
try {
4 years ago
$model = new Model();
$model->startTrans();
$batch = [
4 years ago
'batch_no' => $batchNo,
'user_id' => $testingUser['user_id'],
'game_id' => $gameId,
'role_id' => $roleId,
'server_id' => $serverId,
4 years ago
'apply_promote_id' => $loginPromote['id'],
'apply_amount' => $amount,
'provide_status' => 0,
'verify_status' => 0,
'create_time' => time(),
'update_time' => time(),
];
4 years ago
$batchId = M('testing_resource_batch', 'tab_')->add($batch);
$i = 1;
foreach ($records as $record) {
$orderNo = $batchNo . '_' . $i;
$order = [
'batch_id' => $batchId,
'order_no' => $orderNo,
4 years ago
'ref_id' => $record['resource_id'],
'ref_name' => $record['resource_name'],
4 years ago
'ref_amount' => $record['value'],
'num' => $record['num'],
'amount' => $record['num'] * $record['value'],
'remark' => $record['remark'],
];
4 years ago
M('testing_resource_order', 'tab_')->add($order);
}
4 years ago
$model->commit();
return $this->ajaxReturn(['status' => 1, 'message' => '申请成功,等待审核']);
} catch (\Exception $e) {
4 years ago
$model->rollback();
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' => '绑定成功']);
} catch (\Throwable $th) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
4 years ago
private function getGames()
4 years ago
{
4 years ago
$map = [
'id' => ['in', [229, 230]]
];
4 years ago
$loginPromote = $this->getLoginPromote();
$promoteService = new PromoteService();
$visibleGameIds = $promoteService->getVisibleGameIds($loginPromote);
$map['_string'] = 'id in (0)';
if (count($visibleGameIds) > 0) {
$map['_string'] = 'id in (' . implode(',', $visibleGameIds) . ')';
}
4 years ago
return M('game', 'tab_')->field('id,game_name')->where($map)->select();
}
private function getServersByGameId($gameId = 0)
{
if ($gameId == 0) {
return [];
}
4 years ago
$map = [];
$map['game_id'] = $gameId;
4 years ago
return M('server', 'tab_')
4 years ago
->field('id,server_name,server_id')
->where($map)
->order('server_id asc')
4 years ago
->select();
}
public function getServers()
{
$gameId = I('game_id', 0);
$servers = $this->getServersByGameId($gameId);
4 years ago
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['servers' => $servers]]);
}
public function getResourceTypes()
{
$gameId = I('game_id', 0);
$resourceTypes = [];
/**
* @todo 目前固定游戏猫
*/
4 years ago
if ($gameId == 229) {
4 years ago
$resourceTypes[] = ['id' => 1, 'name' => '通用'];
4 years ago
} elseif ($gameId == 230) {
$resourceTypes[] = ['id' => 2, 'name' => '通用'];
4 years ago
}
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resourceTypes' => $resourceTypes]]);
}
public function getResources()
{
$typeId = I('type_id', 0);
$resources = [];
/**
* @todo 目前固定游戏猫资源类型ID
*/
4 years ago
if ($typeId == 2) {
$resources = $this->getGameCatResources('ios');
} elseif ($typeId == 1) {
$resources = $this->getGameCatResources('andriod');
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
}
4 years ago
private function getGameCatResources($deviceType)
4 years ago
{
$resources = [];
$gameCatClient = new GameCatClient();
4 years ago
$result = $gameCatClient->api('get-pay-type', ['device_type' => $deviceType]);
if ($result['state'] == 1) {
$items = $result['data'];
foreach ($items as $item) {
$resources[$item['supportItem']] = [
'ref_id' => $item['supportItem'],
'name' => $item['content'],
'amount' => $item['amount'],
4 years ago
];
}
}
return $resources;
}
}