|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace Home\Controller;
|
|
|
|
|
|
|
|
use Base\Model\PromoteModel;
|
|
|
|
use Base\Service\PromoteService;
|
|
|
|
use OSS\Core\OssException;
|
|
|
|
|
|
|
|
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 = [
|
|
|
|
'promote_id' => $loginPromote['id'],
|
|
|
|
];
|
|
|
|
|
|
|
|
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 . ')';
|
|
|
|
|
|
|
|
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_name'])->where(['id' => ['in', $bindingRoleIds]])->select();
|
|
|
|
$bindingRoles = index_by_column('id', $bindingRoles);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$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[] = [
|
|
|
|
'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'] : 1200,
|
|
|
|
'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)) {
|
|
|
|
$users = M('user', 'tab_')->field(['id', 'account'])->where(['account' => ['in', $newAccounts]])->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,
|
|
|
|
'promote_id' => $loginPromote['id'],
|
|
|
|
'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);
|
|
|
|
|
|
|
|
$this->assign('count', $count);
|
|
|
|
$this->assign('pagination', $pagination);
|
|
|
|
$this->assign('records', $records);
|
|
|
|
$this->display();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function apply()
|
|
|
|
{
|
|
|
|
$records = [];
|
|
|
|
$pagination = '';
|
|
|
|
$this->assign('records', $records);
|
|
|
|
$this->assign('pagination', $pagination);
|
|
|
|
$this->display();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function doApply()
|
|
|
|
{
|
|
|
|
$records = I('records', []);
|
|
|
|
$batchNo = '';
|
|
|
|
$loginPromote = $this->getLoginPromote();
|
|
|
|
|
|
|
|
$amount = 0;
|
|
|
|
foreach ($records as $record) {
|
|
|
|
$amount += $record['num'] * $record['value'];
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$batch = [
|
|
|
|
'batch_id' => $batchId,
|
|
|
|
'order_no' => $orderNo,
|
|
|
|
'user_id' => $record['user_id'],
|
|
|
|
'game_id' => $record['game_id'],
|
|
|
|
'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,
|
|
|
|
'testing_resource_id' => $record['resource_id'],
|
|
|
|
'num' => $record['num'],
|
|
|
|
'amount' => $record['num'] * $record['value'],
|
|
|
|
'remark' => $record['remark'],
|
|
|
|
];
|
|
|
|
M('testing_resource_order')->add($order);
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bindRole()
|
|
|
|
{
|
|
|
|
$testingUserId = I('testing_user_id', 0);
|
|
|
|
$userAccount = I('user_account', '');
|
|
|
|
$roleId = I('role_id', '');
|
|
|
|
|
|
|
|
$user = M('user', 'tab_')->field(['id', 'account'])->where(['account' => $userAccount])->find();
|
|
|
|
if (is_null($user)) {
|
|
|
|
return $this->ajaxReturn(['status' => 0, 'message' => '用户不存在']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$existBind = M('testing_user', 'tab_')->field(['id'])->where(['bind_user_id' => $user['id']])->find();
|
|
|
|
if ($existBind) {
|
|
|
|
return $this->ajaxReturn(['status' => 0, 'message' => '该玩家账号已被绑定']);
|
|
|
|
}
|
|
|
|
|
|
|
|
M('testing_user', 'tab_')->where(['user_id' => $testingUserId])->save([
|
|
|
|
'role_id' => $roleId,
|
|
|
|
'bind_user_id' => $user['id'],
|
|
|
|
'bind_user_account' => $user['account'],
|
|
|
|
'bind_role_id' => $roleId,
|
|
|
|
]);
|
|
|
|
return $this->ajaxReturn(['status' => 1, 'message' => '绑定成功']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRolesByUser()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|