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.
520 lines
20 KiB
PHP
520 lines
20 KiB
PHP
<?php
|
|
|
|
|
|
namespace Home\Controller;
|
|
|
|
use Base\Model\PromoteModel;
|
|
use Base\Service\PromoteService;
|
|
use OSS\Core\OssException;
|
|
use Base\Tool\GameCatClient;
|
|
use Think\Model;
|
|
|
|
class TestingResourceController extends BaseController
|
|
{
|
|
|
|
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 = [];
|
|
$subConditions = [];
|
|
|
|
if ($createTimeStart) {
|
|
$subConditions['create_time'] = ['egt', strtotime($createTimeStart . ' 00:00:00')];
|
|
}
|
|
if ($createTimeEnd) {
|
|
$subConditions['create_time'] = ['elt', strtotime($createTimeEnd . ' 23:59:59')];
|
|
}
|
|
|
|
$subSql = M('testing_user', 'tab_')->field(['user_id'])->where($subConditions)->select(false);
|
|
$strCondition = 'user_id in (' . $subSql . ')';
|
|
|
|
$promoteService = new PromoteService();
|
|
$strCondition .= ' and promote_id in (' . $promoteService->subInSql($loginPromote) . ')';
|
|
|
|
if ($account) {
|
|
$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);
|
|
|
|
$roleIds = array_column($roles, 'id');
|
|
$userIds = array_unique(array_column($roles, 'user_id'));
|
|
|
|
$users = [];
|
|
$bindings = [];
|
|
$bindingRoles = [];
|
|
if (count($roles) > 0) {
|
|
$users = M('user', 'tab_')->field(['id', 'phone'])->where(['id' => ['in', $userIds]])->select();
|
|
$uesrs = index_by_column('id', $users);
|
|
$bindings = M('testing_binding', 'tab_')->where(['role_id' => ['in', $roleIds]])->select();
|
|
$bindings = index_by_column('role_id', $bindings);
|
|
$bindingRoleIds = array_column($bindings, 'bind_role_id');
|
|
if (count($bindings) > 0) {
|
|
$bindingRoles = M('user_play_info', 'tab_')->field(['id', 'role_id', 'role_name', 'user_account'])->where(['id' => ['in', $bindingRoleIds]])->select();
|
|
$bindingRoles = index_by_column('id', $bindingRoles);
|
|
}
|
|
}
|
|
|
|
if (count($bindingRoles) > 0) {
|
|
M('spend', 'tab_')->where();
|
|
}
|
|
|
|
|
|
$records = [];
|
|
foreach ($roles as $role) {
|
|
$user = $users[$role['user_id']] ?? null;
|
|
$binding = $bindings[$role['id']] ?? null;
|
|
$bindingRole = $binding && $bindingRoles[$binding['bind_role_id']] ? $bindingRoles[$binding['bind_role_id']] : null;
|
|
$records[] = [
|
|
'id' => $role['id'],
|
|
'game_name' => $role['game_name'],
|
|
'server_name' => $role['server_name'],
|
|
'server_id' => $role['server_id'],
|
|
'role_id' => $role['role_id'],
|
|
'user_account' => $role['user_account'],
|
|
'user_phone' => $user ? $user['phone'] : '',
|
|
'role_name' => $role['role_name'],
|
|
'bind_user_account' => $bindingRole ? $bindingRole['user_account'] : '',
|
|
'bind_role_name' => $bindingRole ? $bindingRole['role_name'] : '',
|
|
'base_quota' => $binding ? $binding['base_quota'] : 0,
|
|
'other_quota' => $binding ? $binding['other_quota'] : 0,
|
|
'quota' => 0,
|
|
'verify_amount' => 0,
|
|
'provide_amount' => 0,
|
|
'today_amount' => 0,
|
|
'apply_amount' => 0,
|
|
'status' => '可用',
|
|
'create_time' => date('Y-m-d H:i:s', $role['create_time'])
|
|
];
|
|
}
|
|
|
|
$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);
|
|
$accounts = array_unique($accounts);
|
|
$existAccounts = M('testing_user', 'tab_')->where(['user_account' => ['in', $accounts]])->getField('user_account', true);
|
|
$existAccounts = $existAccounts ?? [];
|
|
$existCount = count($existAccounts);
|
|
$newAccounts = array_diff($accounts, $existAccounts);
|
|
$errorCount = 0;
|
|
$successCount = 0;
|
|
if (count($newAccounts)) {
|
|
|
|
$promoteService = new PromoteService();
|
|
$strCondition = 'promote_id in (' . $promoteService->subInSql($loginPromote) . ')';
|
|
|
|
$users = M('user', 'tab_')->field(['id', 'account'])->where(['account' => ['in', $newAccounts], '_string' => $strCondition])->select();
|
|
$errorAccounts = array_diff($newAccounts, array_column($users, 'account'));
|
|
$errorCount = count($errorAccounts);
|
|
foreach ($users as $user) {
|
|
if (in_array($user['account'], $errorAccounts)) {
|
|
continue;
|
|
}
|
|
$data = [
|
|
'user_id' => $user['id'],
|
|
'user_account' => $user['account'],
|
|
'status' => 1,
|
|
'create_time' => time(),
|
|
'update_time' => time(),
|
|
];
|
|
M('testing_user', 'tab_')->add($data);
|
|
$successCount ++;
|
|
}
|
|
}
|
|
return $this->ajaxReturn(['status' => 1, 'message' => '请求成功', 'data' => [
|
|
'errorCount' => $errorCount,
|
|
'successCount' => $successCount,
|
|
'existCount' => $existCount,
|
|
]]);
|
|
}
|
|
|
|
public function batches()
|
|
{
|
|
$verifyTimeStart = I('verify_time_start', '');
|
|
$verifyTimeEnd = I('verify_time_end', '');
|
|
$verifyStatus = I('verify_status', -1);
|
|
$status = I('status', -1);
|
|
$account = I('account');
|
|
|
|
$loginPromote = $this->getLoginPromote();
|
|
$promoteService = new PromoteService();
|
|
|
|
$conditions = [
|
|
'_string' => 'promote_id in (' . $promoteService->subInSql($loginPromote) . ')',
|
|
];
|
|
if ($verifyTimeStart) {
|
|
$conditions['verify_time'] = ['egt', strtotime($verifyTimeStart . ' 00:00:00')];
|
|
}
|
|
if ($verifyTimeEnd) {
|
|
$conditions['verify_time'] = ['elt', strtotime($verifyTimeEnd . ' 23:59:59')];
|
|
}
|
|
if ($verifyStatus != -1) {
|
|
$conditions['verify_status'] = $verifyStatus;
|
|
}
|
|
if ($status != -1) {
|
|
$conditions['status'] = $status;
|
|
}
|
|
if ($account) {
|
|
$user = M('user', 'tab_')->field(['id'])->where('account like ' . $account . '%')->find();
|
|
if ($user) {
|
|
$conditions['user_id'] = $user['id'];
|
|
} else {
|
|
$conditions['_string'] = '1<>1';
|
|
}
|
|
}
|
|
$query = M('testing_resource_batch', 'tab_')->where($conditions)->order('create_time desc')->select();
|
|
list($batches, $pagination, $count) = $this->paginate($query);
|
|
|
|
$records = [];
|
|
foreach ($batches as $batch) {
|
|
$records[] = [
|
|
'id' => $batch['id'],
|
|
'batch_no' => $batch['batch_no'],
|
|
'create_time' => date('Y-m-d H:i:s', $batch['create_time']),
|
|
'game_name' => $batch['game_id'],
|
|
'server_name' => $batch['server_id'],
|
|
'role_name' => $batch['role_id'],
|
|
'user_account' => $batch['user_id'],
|
|
'user_phone' => $batch['batch_no'],
|
|
'creator_account' => $batch['batch_no'],
|
|
'history_provide_amount' => 0.00,
|
|
'apply_amount' => $batch['apply_amount'],
|
|
'provide_amount' => $batch['provide_amount'],
|
|
'remark' => $batch['remark'],
|
|
'verify_status_text' => $batch['verify_status'],
|
|
'verify_time' => date('Y-m-d H:i:s', $batch['verify_time']),
|
|
'status_text' => $batch['status'],
|
|
'provide_status_text' => $batch['provide_status'],
|
|
'provide_time' => date('Y-m-d H:i:s', $batch['provide_time']),
|
|
'content' => $content,
|
|
];
|
|
}
|
|
|
|
$this->assign('count', $count);
|
|
$this->assign('pagination', $pagination);
|
|
$this->assign('records', $records);
|
|
$this->display();
|
|
}
|
|
|
|
public function orders()
|
|
{
|
|
$batchId = I('batch_id', 0);
|
|
|
|
$query = M('testing_resource_order', 'tab_')->where(['batch_id' => $batchId])->order('create_time desc')->select();
|
|
list($orders, $pagination, $count) = $this->paginate($query);
|
|
|
|
/**
|
|
* @todo
|
|
*/
|
|
|
|
$this->assign('count', $count);
|
|
$this->assign('pagination', $pagination);
|
|
$this->assign('records', $records);
|
|
$this->display();
|
|
}
|
|
|
|
public function apply()
|
|
{
|
|
$roleId = I('role_id', 0);
|
|
|
|
$role = null;
|
|
if ($roleId > 0) {
|
|
$role = M('user_play_info', 'tab_')->field(['id', 'role_id', 'user_id', 'game_id', 'server_id', 'user_account', 'role_name'])->where(['id' => $roleId])->find();
|
|
}
|
|
|
|
$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(['role_id' => $roleId])->find();
|
|
if ($binding) {
|
|
$bindingRole = M('user_play_info', 'tab_')->field(['id', 'role_id', 'user_id', 'game_id', 'server_id', 'user_account', 'role_name'])->where(['id' => $binding['bind_role_id']])->find();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @todo 目前固定游戏猫
|
|
*/
|
|
$games = M('game', 'tab_')->field(['id' , 'game_name'])->where(['id' => ['in', [229, 230]]])->select();
|
|
$this->assign('games', $games);
|
|
$this->assign('servers', $servers);
|
|
$this->assign('bindingRole', $bindingRole);
|
|
$this->assign('role', $role);
|
|
$this->display();
|
|
}
|
|
|
|
public function doApply()
|
|
{
|
|
$gameId = I('game_id', 0);
|
|
$roleId = I('role_id', 0);
|
|
$serverId = I('server_id', 0);
|
|
$userAccount = I('user_account', '');
|
|
$records = I('records', []);
|
|
$loginPromote = $this->getLoginPromote();
|
|
|
|
$resources = [];
|
|
/**
|
|
* @todo 目前仅限游戏猫
|
|
*/
|
|
if (!in_array($gameId, [229, 230])) {
|
|
return $this->ajaxReturn(['status' => 0, 'message' => '该游戏不可申请资源']);
|
|
} else {
|
|
$resources = $this->getGameCatResources();
|
|
}
|
|
|
|
$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' => '区服不存在']);
|
|
}
|
|
|
|
$role = M('user_play_info', 'tab_')
|
|
->field(['id', 'role_id'])
|
|
->where(['user_id' => $user['id'], 'game_id' => $gameId, 'server_id' => $server['server_id']])
|
|
->find();
|
|
if (is_null($role)) {
|
|
return $this->ajaxReturn(['status' => 0, 'message' => '角色不存在']);
|
|
}
|
|
|
|
$amount = 0;
|
|
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' => '含有资源内容不存在']);
|
|
}
|
|
}
|
|
|
|
$batchNo = date('YmdHis') . substr(md5($loginPromote['id'] . strval(microtime(true)) . rand(0, 9999)), 8, 16);
|
|
|
|
try {
|
|
$model = new Model();
|
|
$model->startTrans();
|
|
|
|
$batch = [
|
|
'batch_id' => $batchId,
|
|
'batch_no' => $batchNo,
|
|
'user_id' => $testingUser['user_id'],
|
|
'game_id' => $gameId,
|
|
'role_id' => $roleId,
|
|
'server_id' => $serverId,
|
|
'promote_id' => $loginPromote['id'],
|
|
'amount' => $amount,
|
|
'status' => 0,
|
|
'verify_status' => 0,
|
|
'remark' => $record['remark'],
|
|
'create_time' => time(),
|
|
'update_time' => time(),
|
|
];
|
|
$batchId = M('testing_resource_batch')->add($batch);
|
|
$i = 1;
|
|
foreach ($records as $record) {
|
|
$orderNo = $batchNo . '_' . $i;
|
|
$order = [
|
|
'batch_id' => $batchId,
|
|
'order_no' => $orderNo,
|
|
'ref_id' => $record['resource_id'],
|
|
'ref_name' => $record['resource_name'],
|
|
'num' => $record['num'],
|
|
'amount' => $record['num'] * $record['value'],
|
|
'remark' => $record['remark'],
|
|
];
|
|
M('testing_resource_order')->add($order);
|
|
}
|
|
$model->commit();
|
|
return $this->ajaxReturn(['status' => 1, 'message' => '申请成功,等待审核']);
|
|
} catch (\Exception $e) {
|
|
$model->rollback();
|
|
return $this->ajaxReturn(['status' => 0, 'message' => '系统异常']);
|
|
}
|
|
}
|
|
|
|
public function bindRole()
|
|
{
|
|
$testingRoleId = I('testing_role_id', 0);
|
|
$bindRoleId = I('bind_role_id', 0);
|
|
|
|
$testingRole = M('user_play_info', 'tab_')
|
|
->field(['id', 'role_id', 'user_id'])
|
|
->where(['id' => $testingRoleId])
|
|
->find();
|
|
if (is_null($testingRole)) {
|
|
return $this->ajaxReturn(['status' => 0, 'message' => '测试账号角色不存在']);
|
|
}
|
|
|
|
$testingUser = M('testing_user', 'tab_')->where(['user_id' => $testingRole['user_id']])->find();
|
|
if (is_null($testingUser)) {
|
|
return $this->ajaxReturn(['status' => 0, 'message' => '测试账号不存在']);
|
|
}
|
|
|
|
$bindRole = M('user_play_info', 'tab_')
|
|
->field(['id', 'role_id', 'user_id'])
|
|
->where(['id' => $bindRoleId])
|
|
->find();
|
|
if (is_null($bindRole)) {
|
|
return $this->ajaxReturn(['status' => 0, 'message' => '玩家角色不存在']);
|
|
}
|
|
|
|
$bindIsTesting = M('testing_user', 'tab_')->where(['user_id' => $bindRole['user_id']])->find();
|
|
if ($bindIsTesting) {
|
|
return $this->ajaxReturn(['status' => 0, 'message' => '该玩家账号为测试账号,无法绑定']);
|
|
}
|
|
|
|
$existBind = M('testing_binding', 'tab_')->field(['id'])->where(['bind_role_id' => $bindRoleId])->find();
|
|
if ($existBind) {
|
|
return $this->ajaxReturn(['status' => 0, 'message' => '该玩家角色已被绑定']);
|
|
}
|
|
|
|
$testExistBind = M('testing_binding', 'tab_')->field(['id'])->where(['role_id' => $testingRoleId])->find();
|
|
if ($testExistBind) {
|
|
return $this->ajaxReturn(['status' => 0, 'message' => '该测试账号角色已绑定有角色']);
|
|
}
|
|
|
|
M('testing_binding', 'tab_')->add([
|
|
'user_id' => $testingRole['user_id'],
|
|
'role_id' => $testingRole['id'],
|
|
'bind_user_id' => $bindRole['user_id'],
|
|
'bind_role_id' => $bindRole['id'],
|
|
'create_time' => time(),
|
|
'update_time' => time()
|
|
]);
|
|
return $this->ajaxReturn(['status' => 1, 'message' => '绑定成功']);
|
|
}
|
|
|
|
public function getServers()
|
|
{
|
|
$gameId = I('game_id', 0);
|
|
$map = [];
|
|
$map['game_id'] = $gameId;
|
|
$servers = M('server', 'tab_')
|
|
->field('id,server_name,server_id')
|
|
->where($map)
|
|
->order('server_id asc')
|
|
->select();
|
|
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['servers' => $servers]]);
|
|
}
|
|
|
|
public function getResourceTypes()
|
|
{
|
|
$gameId = I('game_id', 0);
|
|
$resourceTypes = [];
|
|
|
|
/**
|
|
* @todo 目前固定游戏猫
|
|
*/
|
|
if ($gameId == 229) {
|
|
$resourceTypes[] = ['id' => 1, 'name' => '通用'];
|
|
} elseif ($gameId == 230) {
|
|
$resourceTypes[] = ['id' => 2, 'name' => '通用'];
|
|
}
|
|
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resourceTypes' => $resourceTypes]]);
|
|
}
|
|
|
|
public function getResources()
|
|
{
|
|
$typeId = I('type_id', 0);
|
|
|
|
$resources = [];
|
|
|
|
/**
|
|
* @todo 目前固定游戏猫资源类型ID
|
|
*/
|
|
if ($typeId == 2) {
|
|
$resources = $this->getGameCatResources('ios');
|
|
} elseif ($typeId == 1) {
|
|
$resources = $this->getGameCatResources('andriod');
|
|
}
|
|
|
|
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' => '区服不存在']);
|
|
}
|
|
|
|
$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_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]]);
|
|
}
|
|
|
|
private function getGameCatResources($deviceType)
|
|
{
|
|
$resources = [];
|
|
$gameCatClient = new GameCatClient();
|
|
$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'],
|
|
];
|
|
}
|
|
}
|
|
return $resources;
|
|
}
|
|
|
|
private function getRemainAmount($user)
|
|
{
|
|
|
|
}
|
|
} |