master
ELF 5 years ago
parent 263e35c097
commit 06bd640c79

@ -684,5 +684,17 @@ class AdminController extends Controller {
}
}
protected function paginate($query) {
$page = I('p', 1);
$row = I('row', 10);
$countQuery = clone $query;
$count = $countQuery->count();
$records = $query->page($page, $row)->select();
$page = set_pagination($count, $row);
return [$records, $page, $count];
}
}

@ -7,122 +7,36 @@ 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()
{
$page = I('p', 1);
$row = I('row', 10);
$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');
$conditions = [];
$subConditions = [
'_string' => '1=1'
];
$params = I('get.');
$repository = new TestingResourceRepository();
$query = $repository->getTestingUsersQuery($params);
$strCondition = '1=1';
[$roles, $page, $count] = $this->paginate($query);
$testingResourceService = new TestingResourceService();
$gameIds = $testingResourceService->getHadSettingGameIds();
if (!empty($gameIds)) {
$strCondition .= ' and game_id in ('. implode(',', $gameIds) . ')';
} else {
$strCondition .= ' and 1=0';
}
if ($createTimeStart) {
$strCondition .= ' and create_time >=' . strtotime($createTimeStart . ' 00:00:00');
}
if ($createTimeEnd) {
$strCondition .= ' and create_time <=' . strtotime($createTimeEnd . ' 23:59:59');
}
$records = $repository->makeTestingUserRecords($roles);
$subSql = M('testing_user', 'tab_')->field(['user_id'])->where($subConditions)->select(false);
$strCondition .= ' and user_id in (' . $subSql . ')';
$gameRepository = new GameRepository();
// $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;
var_dump($conditions);
$query = M('user_play_info', 'tab_')->where($conditions)->order('create_time desc');
$countQuery = clone $query;
$count = $countQuery->count();
$roles = $query->page($page, $row)->select();
$page = set_pagination($count, $row);
if($page) {
$this->assign('_page', $page);
}
$records = $testingResourceService->makeTestingUserRecords($roles);
$this->assign('games', $this->getGames());
$this->assign('servers', $this->getServersByGameId($gameId));
$this->assign('games', $gameRepository->getChoiceGames());
$this->assign('servers', $gameRepository->getServersByGameId($gameId));
$this->assign('count', $count);
$this->assign('pagination', $pagination);
$this->assign('records', $records);
$this->assign('_page', $page);
$this->display();
}
private function getGames(array $visibleGameIds = null)
{
$map = [];
$map['_string'] = '1=1';
if (is_null($visibleGameIds)) {
} elseif (count($visibleGameIds) > 0) {
$map['_string'] = ' and id in (' . implode(',', $visibleGameIds) . ')';
} else {
$map['_string'] = ' and 1=0';
}
return M('game', 'tab_')->field('id,game_name')->where($map)->select();
}
private function getServersByGameId($gameId = 0)
{
if ($gameId == 0) {
return [];
}
$map = [];
$map['game_id'] = $gameId;
return M('server', 'tab_')
->field('id,server_name,server_id')
->where($map)
->order('server_id asc')
->select();
}
public function getServers()
{
$gameId = I('game_id', 0);
$servers = $this->getServersByGameId($gameId);
$gameRepository = new GameRepository();
$servers = $gameRepository->getServersByGameId($gameId);
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['servers' => $servers]]);
}
@ -148,11 +62,8 @@ class TestingResourceController extends ThinkController
if ($gameId > 0) {
$conditions['base_game_id'] = $gameId;
}
$query = M('testing_game_setting', 'tab_')->where($conditions);
$countQuery = clone $query;
$items = $query->order('create_time desc')->page($page, $row)->select();
$count = $countQuery->count();
$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);
@ -185,10 +96,7 @@ class TestingResourceController extends ThinkController
];
}
$page = set_pagination($count, $row);
if($page) {
$this->assign('_page', $page);
}
$this->assign('_page', $page);
$this->assign('records', $records);
$this->assign('partners', $partners);
$this->assign('baseGames', $baseGames);
@ -230,119 +138,22 @@ class TestingResourceController extends ThinkController
public function batches()
{
$gameId = I('game_id', 0);
$serverId = I('server_id', '');
$createTimeStart = I('create_time_start', '');
$createTimeEnd = I('create_time_end', '');
$verifyStatus = I('verify_status', -1);
$provideStatus = I('provide_status', -1);
$account = I('account');
$loginPromote = $this->getLoginPromote();
$promoteService = new PromoteService();
$subSql = M('user', 'tab_')
->where('id=tab_testing_resource_batch.user_id and promote_id in (' . $promoteService->subInSql($loginPromote) . ')')
->select(false);
$conditions = [
'_string' => 'exists (' . $subSql . ')'
];
if ($createTimeStart) {
$conditions['_string'] .= ' and create_time >=' . strtotime($createTimeStart . ' 00:00:00');
}
if ($createTimeEnd) {
$conditions['_string'] .= ' and create_time <=' . strtotime($createTimeEnd . ' 23:59:59');
}
if ($verifyStatus != -1) {
$conditions['verify_status'] = $verifyStatus;
}
if ($provideStatus != -1) {
$conditions['provide_status'] = $provideStatus;
}
if ($gameId) {
$conditions['game_id'] = $gameId;
}
if ($serverId) {
$conditions['server_id'] = $serverId;
}
if ($account) {
$user = M('user', 'tab_')->field(['id'])->where('account like "' . $account . '%"')->find();
if ($user) {
$conditions['user_id'] = $user['id'];
} else {
$conditions['_string'] .= ' and 1<>1';
}
}
$query = M('testing_resource_batch', 'tab_')->where($conditions)->order('create_time desc');
$params = I('get.');
$repository = new TestingResourceRepository();
$query = $repository->getBatchesQuery($params);
list($batches, $pagination, $count) = $this->paginate($query);
$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);
}
}
$records = $repository->makeBatchesRecords($batches);
$testingResourceService = new TestingResourceService();
$records = [];
foreach ($batches as $batch) {
$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;
$records[] = [
'id' => $batch['id'],
'batch_no' => substr($batch['batch_no'], 14),
'create_time' => date('Y-m-d H:i:s', $batch['create_time']),
'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,
'apply_amount' => $batch['apply_amount'],
'provide_amount' => $batch['provide_amount'],
'verify_status' => $batch['verify_status'],
'verify_status_text' => $testingResourceService->getVerifyStatusText($batch['verify_status']),
'verify_time' => $batch['verify_time'] == 0 ? '--' : date('Y-m-d H:i:s', $batch['verify_time']),
'provide_status' => $batch['provide_status'],
'provide_status_text' => $testingResourceService->getProvideStatusText($batch['provide_status']),
'provide_time' => $batch['provide_time'] == 0 ? '--' : date('Y-m-d H:i:s', $batch['provide_time']),
'content' => $content,
];
}
$gameRepository = new GameRepository();
$this->assign('verifyStatusList', TestingResourceService::$verifyStatusList);
$this->assign('provideStatusList', TestingResourceService::$provideStatusList);
$this->assign('servers', $this->getServersByGameId($gameId));
$this->assign('games', $this->getGames());
$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('pagination', $pagination);
$this->assign('_page', $pagination);
$this->assign('records', $records);
$this->display();
}
@ -364,7 +175,7 @@ class TestingResourceController extends ThinkController
$query = M('testing_resource_order', 'tab_')->where(['batch_id' => $id])->order('id desc');
list($orders, $pagination, $count) = $this->paginate($query);
$testingResourceService = new TestingResourceService();
$repository = new TestingResourceRepository();
foreach ($orders as $order) {
$records[] = [
'id' => $order['id'],
@ -381,13 +192,84 @@ class TestingResourceController extends ThinkController
'amount' => $order['num'] * $order['ref_amount'],
'remark' => $order['remark'],
'provide_status' => $order['provide_status'],
'provide_status_text' => $testingResourceService->getProvideStatusText($order['provide_status']),
'provide_status_text' => $repository->getProvideStatusText($order['provide_status']),
];
}
$this->assign('count', $count);
$this->assign('pagination', $pagination);
$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);
}
}
}

@ -9,8 +9,12 @@
<link rel="stylesheet" type="text/css" href="__CSS__/common.css" media="all">
<link rel="stylesheet" type="text/css" href="__CSS__/module.css">
<link rel="stylesheet" type="text/css" href="__CSS__/style.css" media="all">
<link rel="stylesheet" href="__CSS__/select2.min.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="__CSS__/default_color.css" media="all">
<script type="text/javascript" src="__STATIC__/jquery-2.0.3.min.js"></script>
<script src="__STATIC__/layer/layer.js" type="text/javascript"></script>
<script type="text/javascript" src="__STATIC__/layer/extend/layer.ext.js"></script>
<script type="text/javascript" src="__JS__/select2.min.js"></script>
</head>
<style>
html {
@ -32,6 +36,7 @@ body {
}
.normal_table td {
padding: 5px;
text-align: center;
}
.normal_table td select {
width: 100%;
@ -58,13 +63,13 @@ body {
.btn-row button {
width: 70px;
height: 35px;
display: block;
background: #409eff;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
display: inline-block;
padding: 0px;
}
.btn-row button.close-btn {
background: #E5E5E5;
@ -104,6 +109,24 @@ body {
background: #409eff;
color: #fff;
}
.form-group {
float: left;
}
.form-group input {
padding: 5px;
border: 1px solid #E5E5E5;
border-radius: 4px;
height: 24px;
}
.clearfix:after {
content: "\20";
display: block;
height: 0;
clear: both;
}
.clearfix {
*zoom: 1;
}
</style>
<body>
<div id="main" class="main" style="min-height: 342px;">
@ -112,7 +135,7 @@ body {
<div class="trunk-search clearfix" style="margin-bottom: 10px;">
<form method="post" class="clearfix">
<div class="clearfix">
<div class="form-group fl">
<div class="form-group">
<select id="game-select" name="" class="select_gallery" style="width:150px" <?php if($role):?>disabled<?php endif;?>>
<option value="0">请选择游戏</option>
<?php foreach($games as $game):?>
@ -122,7 +145,7 @@ body {
<?php endforeach;?>
</select>
</div>
<div class="form-group fl">
<div class="form-group">
<select id="server-select" class="select_gallery" style="width:150px" <?php if($role):?>disabled<?php endif;?>>
<option value="0">请选择区服</option>
<?php foreach($servers as $server):?>
@ -132,10 +155,10 @@ body {
<?php endforeach;?>
</select>
</div>
<div class="form-group fl">
<div class="form-group">
<input id="test_account" type="text" name="account" class="txt normal_txt" placeholder="请输入测试资源账号" value="{$role.user_account}" <?php if($role):?>disabled<?php endif;?>>
</div>
<div class="form-group fl">
<div class="form-group">
<select id="role-select" name="role_id" class="select_gallery" style="width:150px" <?php if($role):?>disabled<?php endif;?>>
<option value="">请选择角色</option>
<?php if($role):?>
@ -156,7 +179,10 @@ body {
</div>
</div>
<?php endif;?>
<div class="clearfix" style="margin-top: 10px;">
<input id="hasItf" type="hidden" value="<?=$hasItf?>" name="has_itf">
<?php if ($hasItf):?>
<div class="form-group fl">
<select id="resource-type-select" name="resource_type_id" style="width:150px" class="select_gallery">
<option value="">请选择资源类型</option>
@ -168,7 +194,7 @@ body {
</select>
</div>
<div class="form-group fl">
<input id="remark-input" type="text" name="remark" class="txt normal_txt" id="uid" placeholder="请输入备注" value="">
<input id="remark-input" type="text" name="remark" class="txt normal_txt" placeholder="请输入备注" value="">
</div>
<div class="form-group fl">
<p id="resource-amount" class="static-input">资源价值: --</p>
@ -177,15 +203,24 @@ body {
<p class="static-input">资源数量: 1</p>
<!-- <input id="num-input" type="text" name="num" class="txt normal_txt" id="uid" placeholder="请输入资源数量" value=""> -->
</div>
<?php else:?>
<div class="form-group fl">
<input id="remark-input" type="text" name="remark" class="txt normal_txt" placeholder="请输入资源备注" value="">
</div>
<div class="form-group fl">
<input id="remark-amount" type="text" name="amount" class="txt normal_txt" placeholder="请输入资源价值" value="">
</div>
<?php endif;?>
<div class="form-group fl">
<button id="add-row" class="add-row" type="button">增加</button>
</div>
</div>
</form>
</div>
<div class="trunk-list list_normal">
<div class="table-wrapper" style="height: 280px;">
<table id="resource-table" class="table normal_table">
<div class="trunk-list list_normal data_list" style="margin-top: 20px">
<div class="table-wrapper" style="height: 315px;">
<?php if($hasItf):?>
<table id="resource-table" class="table normal_table ">
<thead>
<tr class="table-header">
<th width="150">资源类型</th>
@ -200,6 +235,20 @@ body {
</tbody>
</table>
<?php else:?>
<table id="resource-table" class="table normal_table ">
<thead>
<tr class="table-header">
<th>资源备注</th>
<th>资源价值</th>
<th>操作</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<?php endif;?>
</div>
<div class="btn-row clearfix">
<button id="submit-btn" class="submit-btn" type="button">提交</button>
@ -340,6 +389,35 @@ body {
if (rowCount >= 5) {
return layer.msg('最多同时只能添加5条')
}
var hasItf = $('#hasItf').val()
if (hasItf == 1) {
addRowItf()
} else {
addRow()
}
})
function addRow() {
var remark = $('#remark-input').val()
var amount = $('#remark-amount').val()
if (remark == '') {
return layer.msg('请输入资源备注')
}
if (amount == '') {
return layer.msg('请输入资源价值')
}
var html = '<tr class="normal-row" >' +
'<td style="width:420px" class="remark"><input name="remark" type="text" style="width:400px" value="' + remark + '"></td>' +
'<td class="amount"><input name="amount" type="text" value="' + amount + '"></td>' +
'<td><button class="delete-row" type="button" class="danger-btn">删除</button></td>' +
'</tr>';
$('#resource-table tbody').append(html)
rowCount ++
$(".select_gallery").select2()
statQuota()
}
function addRowItf() {
var resourceTypeId = $('#resource-type-select').val()
var resourceId = $('#resource-select').val()
var resourceTypeName = $('#resource-type-select option:selected').html()
@ -373,7 +451,8 @@ body {
rowCount ++
$(".select_gallery").select2()
statQuota()
})
}
$('#resource-table').on('click', '.delete-row', function () {
var tr = $(this).parents('tr').eq(0)
rowCount --
@ -389,10 +468,19 @@ body {
})
function statQuota() {
var quota = $('#quota').attr('data-quota')
var hasItf = $('#hasItf').val()
var verifyQuota = 0
$('#resource-table').find('.normal-row').each(function (index, ele) {
verifyQuota += $(ele).find('.amount').html() * $(ele).find('.num').children('input').val()
})
if (hasItf == 1) {
$('#resource-table').find('.normal-row').each(function (index, ele) {
verifyQuota += $(ele).find('.amount').html() * $(ele).find('.num').children('input').val()
})
} else {
$('#resource-table').find('.normal-row').each(function (index, ele) {
verifyQuota += parseInt($(ele).find('.amount').children('input').val())
})
}
$('#verify-quota').html(verifyQuota)
$('#quota').html(quota-verifyQuota)
}
@ -478,18 +566,30 @@ body {
function getRecords() {
var records = []
$('#resource-table tbody tr').each(function (index, tr) {
var num = $(tr).find('input[name=num]').val()
var remark = $(tr).find('input[name=remark]').val()
var resourceId = $(tr).attr('data-resource-id')
var resourceTypeId = $(tr).attr('data-resource-type-id')
records.push({
resource_id: resourceId,
resource_type_id: resourceTypeId,
num: num,
remark: remark,
var hasItf = $('#hasItf').val()
if (hasItf == 1) {
$('#resource-table tbody tr').each(function (index, tr) {
var num = $(tr).find('input[name=num]').val()
var remark = $(tr).find('input[name=remark]').val()
var resourceId = $(tr).attr('data-resource-id')
var resourceTypeId = $(tr).attr('data-resource-type-id')
records.push({
resource_id: resourceId,
resource_type_id: resourceTypeId,
num: num,
remark: remark,
})
})
})
} else {
$('#resource-table tbody tr').each(function (index, tr) {
var amount = $(tr).find('input[name=amount]').val()
var remark = $(tr).find('input[name=remark]').val()
records.push({
amount: amount,
remark: remark,
})
})
}
return records
}

@ -105,11 +105,23 @@
<th>
<input class="check-all" type="checkbox">
</th>
<th width="125px">批次号</th>
<th>申请时间</th>
<th>游戏名称</th>
<th>游戏合作方</th>
<th>初始额度</th>
<th>奖金比例</th>
<th>当前已申请资源</th>
<th>区服名称</th>
<th>角色名称</th>
<th>测试账号</th>
<th>手机号</th>
<th>所属推广员</th>
<th>申请人</th>
<!-- <th>发放总金额</th> -->
<th>申请金额</th>
<th>发放金额</th>
<th>审核状态</th>
<th>审核时间</th>
<th>发放状态</th>
<th>发放时间</th>
<!-- <th>资源内容</th> -->
<th>操作</th>
</tr>
</thead>
@ -118,28 +130,47 @@
<tbody>
<empty name ="records">
<td colspan="99" class="text-center">aOh! 暂时还没有内容!</td>
<else />
<volist name="records" id="data">
<tr data-id="<?=$data['id']?>">
<td>
<?php if($data['has_record'] && in_array($data['status'], [0, 1])):?>
<input class="ids" type="checkbox" value="{$data['id']}" name="ids[]">
<?php else:?>
<input class="ids disabled" disabled="disabled" type="checkbox" value="{$data['id']}" name="ids[]">
<?php endif;?>
</td>
<td>{$data.game_name}</td>
<td>{$data.partner_name}</td>
<td>{$data.base_quota}</td>
<td>{$data.rate}</td>
<td></td>
<td>
<div class="partakebtn">
<a href="<?=U('edit', ['id' => $data['id']])?>">编辑</a>
<a class="delete-btn">删除</a>
</div>
</td>
</tr>
<else />
<volist name="records" id="record" mod="2">
<tr data-id="{$record.id}" class="<eq name='mod' value='1'>odd</eq>">
<td><input class="ids" type="checkbox" value="{$data['id']}" name="ids[]"></td>
<td style="word-wrap:break-word;">{$record.batch_no}</td>
<td>
<?=substr($record['create_time'], 0, 10)?>
<br>
<?=substr($record['create_time'], 10)?>
</td>
<td>{$record.game_name}</td>
<td>{$record.server_name}</td>
<td>{$record.role_name}</td>
<td>{$record.user_account}</td>
<td>{$record.user_phone}</td>
<td>{$record.promote_account}</td>
<td>{$record.apply_promote_account}</td>
<!-- <td>{$record.history_provide_amount}</td> -->
<td>{$record.apply_amount}</td>
<td>{$record.provide_amount}</td>
<td>
<span class="status-{$record.verify_status}">{$record.verify_status_text}</span>
</td>
<td>
<?=substr($record['verify_time'], 0, 10)?>
<br>
<?=substr($record['verify_time'], 10)?>
</td>
<td>
<span class="status-{$record.provide_status}">{$record.provide_status_text}</span>
</td>
<td>
<?=substr($record['provide_time'], 0, 10)?>
<br>
<?=substr($record['provide_time'], 10)?>
</td>
<!-- <td>{$record.content}</td> -->
<td>
<a href="javascript:;" class="view-detail">查看</a>
</td>
</tr>
</volist>
</empty>
</tbody>
@ -244,6 +275,21 @@
$("#search").click();
}
});
$('.view-detail').on({
click:function () {
var url = "{:U('TestingResource/orders', '', '')}"
var id = $(this).parents('tr').eq(0).attr('data-id')
url += '/id/' + id
layer.open({
title: '查看申请订单',
type: 2,
content: [url , 'no'],
area: ['1200px', '400px'],
zIndex: 250,
scrollbar: false,
})
}
})
function getIds() {
var ids = [];
$('.ids:checked').each(function() {
@ -251,63 +297,6 @@
})
return ids;
}
$('.delete-btn').on({
click: function() {
var id = $(this).parents('tr').eq(0).attr('data-id');
$.ajax({
url: '{:U("delete")}',
type: 'post',
dataType: 'json',
data: {id: id},
success: function(result) {
if (result.status == 1) {
layer.msg(result.message)
setTimeout(function() {
window.location.href = window.location.href
}, 200)
} else {
layer.msg(result.message)
}
}
})
}
})
$('#add-btn').click(function () {
var box = $('#add-box')
layer.open({
title: '新增',
type: 1,
content: box,
area: ['500px', '300px'],
zIndex: 250,
})
$(".select_gallery").select2();
});
$('.add-submit').on({
click: function() {
var box = $('#add-box')
var baseGameId = box.find('[name=base_game_id]').val()
var baseQuota = box.find('[name=base_quota]').val()
var rate = box.find('[name=rate]').val()
$.ajax({
url: '{:U("saveGameSetting")}',
type: 'post',
dataType: 'json',
data: { base_game_id: baseGameId, base_quota: baseQuota, rate: rate },
success: function(result) {
if (result.status == 1) {
layer.msg(result.message)
setTimeout(function() {
window.location.href = window.location.href
}, 200)
} else {
layer.msg(result.message)
}
}
})
}
})
});
</script>
</block>

@ -69,7 +69,7 @@
<div class="tools">
<empty name="show_status">
<a class="fr" id="batch_add" href="javascript:;"><span class="button_icon button_icon9"></span>批量申请后续</a>
<a class="fr" id="apply" href="javascript:;"><span class="button_icon button_icon9"></span>批量申请后续</a>
<a class="fr" id="add-test-user" href="javascript:;"><span class="button_icon button_icon1"></span>新增测试账号</a>
<!-- <a class="fr" id="batch_freeze"><span class="button_icon button_icon5 "></span>批量锁定</a>-->
</empty>
@ -127,7 +127,7 @@
<thead>
<tr>
<th>
<input class="check-all" type="checkbox">
选择
</th>
<th>游戏名称</th>
<th>区服名称</th>
@ -156,7 +156,7 @@
<volist name="records" id="record">
<tr data-id="<?=$record['id']?>">
<td>
<input class="ids" type="checkbox" value="{$record['id']}" name="ids[]">
<input class="ids" type="radio" value="{$record['id']}" name="role_id">
</td>
<td>{$record.game_name}</td>
<td>{$record.server_name}</td>
@ -312,6 +312,29 @@
});
}
})
$('#apply').click(function () {
var title = '添加测试资源申请'
var url = "{:U('TestingResource/apply', '', '')}"
var id = $('input[name=role_id]:checked').val()
id = id == undefined ? 0 : id;
if (id > 0) {
url += '/id/' + id
} else {
return layer.msg('请选择测试账号角色')
}
layer.open({
title: title,
type: 2,
content: [url , 'no'],
area: ['1000px', '600px'],
zIndex: 250,
scrollbar: false,
})
})
$("#game_id").change(function () {
$.ajax({
url: "{:U('getServers')}",

@ -0,0 +1,86 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="UTF-8">
<title>游戏登陆列表|----软件管理平台</title>
<link href="http://admin.vlcms.com/Public/icon.ico" type="image/x-icon" rel="shortcut icon">
<link rel="stylesheet" type="text/css" href="__CSS__/base.css" media="all">
<link rel="stylesheet" type="text/css" href="__CSS__/common.css" media="all">
<link rel="stylesheet" type="text/css" href="__CSS__/module.css">
<link rel="stylesheet" type="text/css" href="__CSS__/style.css" media="all">
<link rel="stylesheet" type="text/css" href="__CSS__/default_color.css" media="all">
<script type="text/javascript" src="__STATIC__/jquery-2.0.3.min.js"></script>
</head>
<style>
html {
min-width:100%;
height: 1000px;
}
body {
padding: 0px;
}
</style>
<body>
<div id="main" class="main" style="min-height: 342px;">
<!-- 数据列表 -->
<div class="data_list box_mt">
<div class="">
<table>
<!-- 表头 -->
<thead>
<tr>
<th>申请ID</th>
<th>申请时间</th>
<th>游戏名称</th>
<th>玩家账号</th>
<th>区服名称</th>
<th>角色名称</th>
<th>申请人</th>
<th>资源内容</th>
<th>资源价值</th>
<th>申请数量</th>
<th>申请金额</th>
<th>申请备注</th>
<th>发放状态</th>
</tr>
</thead>
<!-- 列表 -->
<tbody>
<empty name="records">
<tr><td colspan="14" style="text-align: center;height: 45vh;"><img src="__IMG__/20180207/icon_wushujv2.png"/><p style="line-height: 40px;color: #A5A5A5;">暂无数据</p></td></tr>
<else />
<volist name="records" id="record" mod="2">
<tr data-id="{$record.id}" class="<eq name='mod' value='1'>odd</eq>">
<td>{$record.id}</td>
<td>
<?=substr($record['create_time'], 0, 10)?>
<br>
<?=substr($record['create_time'], 10)?>
</td>
<td>{$record.game_name}</td>
<td>{$record.user_account}</td>
<td>{$record.server_name}</td>
<td>{$record.role_name}</td>
<td>{$record.apply_promote_account}</td>
<td>{$record.ref_name}</td>
<td>{$record.ref_amount}</td>
<td>{$record.num}</td>
<td>{$record.amount}</td>
<td>{$record.remark}</td>
<td><span class="status-{$record.provide_status}">{$record.provide_status_text}</span></td>
</tr>
</volist>
</empty>
</tbody>
</table>
</div>
</div>
<div class="page">
{$_page}
</div>

</div>
</body>
</html>

@ -0,0 +1,47 @@
<?php
namespace Base\Repository;
use Base\Tool\Registry;
class GameRepository
{
public function getBaseGames($isRefresh = false)
{
$baseGames = Registry::get('base_games');
if ($isRefresh || is_null($baseGames)) {
$baseGames = M('base_game', 'tab_')->where('1=1')->select();
Registry::set('base_games', $baseGames);
}
return $baseGames;
}
public function getBaseGameByGameId($gameId)
{
return M('base_game', 'tab_')->where('android_game_id=' . $gameId . ' or ios_game_id=' . $gameId)->find();
}
public function getChoiceGames(array $visibleGameIds = null, $fields = ['id', 'game_name'])
{
$map = [];
$map['_string'] = '1=1';
if (is_null($visibleGameIds)) {
} elseif (count($visibleGameIds) > 0) {
$map['_string'] = ' and id in (' . implode(',', $visibleGameIds) . ')';
} else {
$map['_string'] = ' and 1=0';
}
return M('game', 'tab_')->field($fields)->where($map)->select();
}
public function getServersByGameId($gameId, $fields = ['id', 'server_name', 'server_id'])
{
$map = [];
$map['game_id'] = $gameId;
return M('server', 'tab_')
->where($map)
->order('server_id asc')
->select();
}
}

@ -0,0 +1,417 @@
<?php
namespace Base\Repository;
use Base\Tool\Registry;
use Base\Service\PromoteService;
class TestingResourceRepository
{
public static $provideStatusList = [
'0' => '待发放',
'1' => '已发放',
'2' => '异常',
];
public static $verifyStatusList = [
'0' => '未审核',
'1' => '审核通过',
'2' => '审核拒绝',
];
public function getProvideStatusText($provideStatus)
{
return self::$provideStatusList[$provideStatus] ?? '未知';
}
public function getVerifyStatusText($verifyStatus)
{
return self::$verifyStatusList[$verifyStatus] ?? '未知';
}
public function getGameRoleId($gameId, $roleId)
{
return $gameId . '#' . $roleId;
}
public function getGameSettings($isRefresh = false)
{
$settings = Registry::get('testing_game_settings');
if ($isRefresh || is_null($settings)) {
$settings = M('testing_game_setting', 'tab_')->where('1=1')->select();
Registry::set('testing_game_settings', $settings);
}
return $settings;
}
public function getGameSetting($baseGameId)
{
return M('testing_game_setting', 'tab_')->where(['base_game_id' => $baseGameId])->find();
}
public function getGameSettingByGameId($gameId)
{
$gameRepository = new GameRepository();
$baseGame = $gameRepository->getBaseGameByGameId($gameId);
$baseGameId = $baseGame ? $baseGame['id'] : 0;
return $this->getGameSetting($baseGameId);
}
public function getHadSettingGameIds()
{
$baseGameIds = M('testing_game_setting', 'tab_')->getField('base_game_id', true);
if (empty($baseGameIds)) {
return [];
}
$baseGames = M('base_game', 'tab_')->where(['id' => ['in', $baseGameIds]])->select();
return array_merge(array_column($baseGames, 'android_game_id'), array_column($baseGames, 'ios_game_id'));
}
public function getBatchesQuery($params, $promote = null)
{
$gameId = $params['game_id'] ?? 0;
$serverId = $params['server_id'] ?? '';
$createTimeStart = $params['create_time_start'] ?? '';
$createTimeEnd = $params['create_time_end'] ?? '';
$verifyStatus = $params['verify_status'] ?? -1;
$provideStatus = $params['provide_status'] ?? -1;
$account = $params['account'] ?? '';
$conditions = [];
$conditions['_string'] = '1=1';
if (!is_null($promote)) {
$promoteService = new PromoteService();
$subSql = M('user', 'tab_')
->where('id=tab_testing_resource_batch.user_id and promote_id in (' . $promoteService->subInSql($promote) . ')')
->select(false);
$conditions['_string'] .= ' and exists (' . $subSql . ')';
}
if ($createTimeStart) {
$conditions['_string'] .= ' and create_time >=' . strtotime($createTimeStart . ' 00:00:00');
}
if ($createTimeEnd) {
$conditions['_string'] .= ' and create_time <=' . strtotime($createTimeEnd . ' 23:59:59');
}
if ($verifyStatus != -1) {
$conditions['verify_status'] = $verifyStatus;
}
if ($provideStatus != -1) {
$conditions['provide_status'] = $provideStatus;
}
if ($gameId) {
$conditions['game_id'] = $gameId;
}
if ($serverId) {
$conditions['server_id'] = $serverId;
}
if ($account) {
$user = M('user', 'tab_')->field(['id'])->where('account like "' . $account . '%"')->find();
if ($user) {
$conditions['user_id'] = $user['id'];
} else {
$conditions['_string'] .= ' and 1<>1';
}
}
return M('testing_resource_batch', 'tab_')->where($conditions)->order('create_time desc');
}
private function getBatchesRelations($batches)
{
$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);
}
}
return [
'roles' => $roles,
'applyPromotes' => $applyPromotes,
'users' => $users,
'promotes' => $promotes,
];
}
public function makeBatchesRecords($batches)
{
$result = $this->getBatchesRelations($batches);
$roles = $result['roles'];
$applyPromotes = $result['applyPromotes'];
$users = $result['users'];
$promotes = $result['promotes'];
$records = [];
foreach ($batches as $batch) {
$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;
$records[] = [
'id' => $batch['id'],
'batch_no' => substr($batch['batch_no'], 14),
'create_time' => date('Y-m-d H:i:s', $batch['create_time']),
'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,
'apply_amount' => $batch['apply_amount'],
'provide_amount' => $batch['provide_amount'],
'verify_status' => $batch['verify_status'],
'verify_status_text' => $this->getVerifyStatusText($batch['verify_status']),
'verify_time' => $batch['verify_time'] == 0 ? '--' : date('Y-m-d H:i:s', $batch['verify_time']),
'provide_status' => $batch['provide_status'],
'provide_status_text' => $this->getProvideStatusText($batch['provide_status']),
'provide_time' => $batch['provide_time'] == 0 ? '--' : date('Y-m-d H:i:s', $batch['provide_time']),
'content' => $content,
];
}
return $records;
}
private function statByRoles($roles)
{
$bindingOrWhere = [];
foreach ($roles as $role) {
$bindingOrWhere[] = '(role_id="' . $role['role_id'] . '" and game_id=' . $role['game_id'] . ')';
}
$userIds = array_unique(array_column($roles, 'user_id'));
$users = [];
$bindings = [];
$bindingRoles = [];
$applyRecords = [];
if (count($roles) > 0) {
$users = M('user', 'tab_')->field(['id', 'phone', 'lock_status'])->where(['id' => ['in', $userIds]])->select();
$users = index_by_column('id', $users);
$bindingRows = M('testing_binding', 'tab_')->where(['_string' => implode(' or ', $bindingOrWhere)])->select();
$bindingRoleIds = [];
foreach ($bindingRows as $bindingRow) {
$bindings[$this->getGameRoleId($bindingRow['game_id'], $bindingRow['role_id'])] = $bindingRow;
$bindingRoleIds[] = $this->getGameRoleId($bindingRow['game_id'], $bindingRow['bind_role_id']);
}
if (count($bindings) > 0) {
$bindingRoles = M('user_play_info', 'tab_')
->field(['id', 'role_id', 'role_name', 'user_account', 'game_id', 'game_role_id'])
->where(['game_role_id' => ['in', $bindingRoleIds]])
->select();
$bindingRoles = index_by_column('game_role_id', $bindingRoles);
}
$verifyItems = M('testing_resource_batch', 'tab_')
->field('sum(apply_amount) amount, game_id, role_id')
->where([
'verify_status' => 0,
'_string' => implode(' or ', $bindingOrWhere)
])
->group('game_id,role_id')->select();
$verifyRecords = [];
foreach ($verifyItems as $item) {
$verifyRecords[$this->getGameRoleId($item['game_id'], $item['role_id'])] = $item['amount'] ;
}
$provideItems = M('testing_resource_batch', 'tab_')
->field('sum(provide_amount) amount, game_id, role_id')
->where([
'verify_status' => 1,
'_string' => implode(' or ', $bindingOrWhere)
])
->group('game_id,role_id')->select();
$provideRecords = [];
foreach ($provideItems as $item) {
$provideRecords[$this->getGameRoleId($item['game_id'], $item['role_id'])] = $item['amount'] ;
}
$todayProvideItems = M('testing_resource_batch', 'tab_')
->field('sum(provide_amount) amount, game_id, role_id')
->where([
'verify_status' => 1,
'_string' => implode(' or ', $bindingOrWhere),
'provide_time' => ['egt', strtotime(date('Y-m-d 00:00:00'))],
'provide_time' => ['elt', strtotime(date('Y-m-d 23:59:59'))],
])
->group('game_id,role_id')->select();
$todayProvideRecords = [];
foreach ($todayProvideItems as $item) {
$todayProvideRecords[$this->getGameRoleId($item['game_id'], $item['role_id'])] = $item['amount'] ;
}
$applyItems = M('testing_resource_batch', 'tab_')
->field('sum(apply_amount) amount, game_id, role_id')
->where([
'_string' => implode(' or ', $bindingOrWhere),
])
->group('game_id,role_id')->select();
$applyRecords = [];
foreach ($applyItems as $item) {
$applyRecords[$this->getGameRoleId($item['game_id'], $item['role_id'])] = $item['amount'] ;
}
}
$spendItems = [];
if (count($bindingRoles) > 0) {
$spendOrWhere = [];
foreach ($bindingRoles as $bindingRole) {
$spendOrWhere[] = '(game_player_id="' . $bindingRole['role_id'] . '" and game_id=' . $bindingRole['game_id'] . ')';
}
$spendCondition = [
'pay_status' => 1,
'_string' => '(' . implode(' or ', $spendOrWhere) . ')',
];
$spendList = M('spend', 'tab_')->field('sum(pay_amount) amount, game_id, game_player_id')->where($spendCondition)->group('game_id,game_player_id')->select();
foreach ($spendList as $item) {
$spendItems[$this->getGameRoleId($item['game_id'], $item['game_player_id'])] = $item['amount'];
}
}
return [
'users' => $users,
'spendItems' => $spendItems,
'bindings' => $bindings,
'bindingRoles' => $bindingRoles,
'applyRecords' => $applyRecords,
'provideRecords' => $provideRecords,
'verifyRecords' => $verifyRecords,
'todayProvideRecords' => $todayProvideRecords,
];
}
public function makeTestingUserRecords($roles)
{
$result = $this->statByRoles($roles);
$users = $result['users'];
$spendItems = $result['spendItems'];
$bindings = $result['bindings'];
$bindingRoles = $result['bindingRoles'];
$applyRecords = $result['applyRecords'];
$provideRecords = $result['provideRecords'];
$verifyRecords = $result['verifyRecords'];
$todayProvideRecords = $result['todayProvideRecords'];
$records = [];
foreach ($roles as $role) {
$user = $users[$role['user_id']] ?? null;
$binding = $bindings[$role['game_role_id']] ?? null;
$bindingRole = null;
if ($binding) {
$bindGameRoleId = $this->getGameRoleId($binding['game_id'], $binding['bind_role_id']);
$bindingRole = $bindingRoles[$bindGameRoleId] ? $bindingRoles[$bindGameRoleId] : null;
}
$gameSetting = $this->getGameSettingByGameId($role['game_id']);
$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' => $gameSetting ? $gameSetting['base_quota'] : 0,
'other_quota' => $role['testing_other_quota'],
'quota' => $bindingRole && isset($spendItems[$bindingRole['game_role_id']]) ? $spendItems[$bindingRole['game_role_id']] : 0,
'verify_amount' => $verifyRecords[$role['game_role_id']] ?? 0,
'provide_amount' => $provideRecords[$role['game_role_id']] ?? 0,
'today_amount' => $todayProvideRecords[$role['game_role_id']] ?? 0,
'apply_amount' => $applyRecords[$role['game_role_id']] ?? 0,
'status' => $user && $user['lock_status'] == 1 ? '正常' : '锁定',
'create_time' => date('Y-m-d H:i:s', $role['create_time'])
];
}
return $records;
}
public function getTestingUsersQuery($params, array $promote = null)
{
$createTimeStart = $params['create_time_start'] ?? '';
$createTimeEnd = $params['create_time_end'] ?? '';
$gameId = $params['game_id'] ?? 0;
$serverId = $params['server_id'] ?? '';
$account = $params['account'] ?? '';
$roleName = $params['role_name'] ?? '';
$conditions = [];
$subConditions = [
'_string' => '1=1'
];
$strCondition = '1=1';
$promoteService = new PromoteService();
if ($promote) {
$visibleGameIds = $promoteService->getVisibleGameIds($promote);
if (count($visibleGameIds) > 0) {
$strCondition .= ' and game_id in (' . implode(',', $visibleGameIds) . ')';
} else {
$strCondition .= ' and 1=0';
}
$strCondition .= ' and promote_id in (' . $promoteService->subInSql($promote) . ')';
}
$gameIds = $this->getHadSettingGameIds();
if (!empty($gameIds)) {
$strCondition .= ' and game_id in ('. implode(',', $gameIds) . ')';
} else {
$strCondition .= ' and 1=0';
}
if ($createTimeStart) {
$strCondition .= ' and create_time >=' . strtotime($createTimeStart . ' 00:00:00');
}
if ($createTimeEnd) {
$strCondition .= ' and create_time <=' . strtotime($createTimeEnd . ' 23:59:59');
}
$subSql = M('testing_user', 'tab_')->field(['user_id'])->where($subConditions)->select(false);
$strCondition .= ' and 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;
return M('user_play_info', 'tab_')->where($conditions)->order('create_time desc');
}
}

@ -3,28 +3,16 @@ namespace Base\Service;
use Base\Facade\Request;
use Base\Tool\GameCatClient;
use Base\Repository\TestingResourceRepository;
use Think\Model;
class TestingResourceService
{
public static $provideStatusList = [
'0' => '待发放',
'1' => '已发放',
'2' => '异常',
];
public static $verifyStatusList = [
'0' => '未审核',
'1' => '审核通过',
'2' => '审核拒绝',
];
public function getProvideStatusText($provideStatus)
{
return self::$provideStatusList[$provideStatus] ?? '未知';
}
public $repository;
public function getVerifyStatusText($verifyStatus)
public function __construct()
{
return self::$verifyStatusList[$verifyStatus] ?? '未知';
$this->repository = new TestingResourceRepository();
}
public function verify($batch)
@ -132,9 +120,9 @@ class TestingResourceService
}
public function getRemainQuota($role, $bindRole = null, $gameSetting = null)
{
{
if (is_null($gameSetting)) {
$gameSetting = $this->getGameSettingByGameId($role['game_id']);
$gameSetting = $this->repository->getGameSettingByGameId($role['game_id']);
}
if (is_null($gameSetting)) {
@ -157,17 +145,6 @@ class TestingResourceService
return round(floatval($totalQuota) - floatval($providedQuota) - floatval($providingQuota), 2);
}
public function getGameSetting($baseGameId)
{
return M('testing_game_setting', 'tab_')->where(['base_game_id' => $baseGameId])->find();
}
public function getGameSettingByGameId($gameId)
{
$baseGameId = M('base_game', 'tab_')->where('android_game_id=' . $gameId . ' or ios_game_id=' . $gameId)->getField('id');
return $this->getGameSetting($baseGameId);
}
public function addTestingUsers($accounts, $promote = null)
{
$accounts = array_unique($accounts);
@ -237,182 +214,14 @@ class TestingResourceService
}
}
public function getHadSettingGameIds()
{
$baseGameIds = M('testing_game_setting', 'tab_')->getField('base_game_id', true);
if (empty($baseGameIds)) {
return [];
}
$baseGames = M('base_game', 'tab_')->where(['id' => ['in', $baseGameIds]])->select();
return array_merge(array_column($baseGames, 'android_game_id'), array_column($baseGames, 'ios_game_id'));
}
private function getGameRoleId($gameId, $roleId)
{
return $gameId . '#' . $roleId;
}
public function statByRoles($roles)
{
$bindingOrWhere = [];
foreach ($roles as $role) {
$bindingOrWhere[] = '(role_id="' . $role['role_id'] . '" and game_id=' . $role['game_id'] . ')';
}
$userIds = array_unique(array_column($roles, 'user_id'));
$users = [];
$bindings = [];
$bindingRoles = [];
$applyRecords = [];
if (count($roles) > 0) {
$users = M('user', 'tab_')->field(['id', 'phone', 'lock_status'])->where(['id' => ['in', $userIds]])->select();
$users = index_by_column('id', $users);
$bindingRows = M('testing_binding', 'tab_')->where(['_string' => implode(' or ', $bindingOrWhere)])->select();
$bindingRoleIds = [];
foreach ($bindingRows as $bindingRow) {
$bindings[$this->getGameRoleId($bindingRow['game_id'], $bindingRow['role_id'])] = $bindingRow;
$bindingRoleIds[] = $this->getGameRoleId($bindingRow['game_id'], $bindingRow['bind_role_id']);
}
if (count($bindings) > 0) {
$bindingRoles = M('user_play_info', 'tab_')
->field(['id', 'role_id', 'role_name', 'user_account', 'game_id', 'game_role_id'])
->where(['game_role_id' => ['in', $bindingRoleIds]])
->select();
$bindingRoles = index_by_column('game_role_id', $bindingRoles);
}
$verifyItems = M('testing_resource_batch', 'tab_')
->field('sum(apply_amount) amount, game_id, role_id')
->where([
'verify_status' => 0,
'_string' => implode(' or ', $bindingOrWhere)
])
->group('game_id,role_id')->select();
$verifyRecords = [];
foreach ($verifyItems as $item) {
$verifyRecords[$this->getGameRoleId($item['game_id'], $item['role_id'])] = $item['amount'] ;
}
$provideItems = M('testing_resource_batch', 'tab_')
->field('sum(provide_amount) amount, game_id, role_id')
->where([
'verify_status' => 1,
'_string' => implode(' or ', $bindingOrWhere)
])
->group('game_id,role_id')->select();
$provideRecords = [];
foreach ($provideItems as $item) {
$provideRecords[$this->getGameRoleId($item['game_id'], $item['role_id'])] = $item['amount'] ;
}
$todayProvideItems = M('testing_resource_batch', 'tab_')
->field('sum(provide_amount) amount, game_id, role_id')
->where([
'verify_status' => 1,
'_string' => implode(' or ', $bindingOrWhere),
'provide_time' => ['egt', strtotime(date('Y-m-d 00:00:00'))],
'provide_time' => ['elt', strtotime(date('Y-m-d 23:59:59'))],
])
->group('game_id,role_id')->select();
$todayProvideRecords = [];
foreach ($todayProvideItems as $item) {
$todayProvideRecords[$this->getGameRoleId($item['game_id'], $item['role_id'])] = $item['amount'] ;
}
$applyItems = M('testing_resource_batch', 'tab_')
->field('sum(apply_amount) amount, game_id, role_id')
->where([
'_string' => implode(' or ', $bindingOrWhere),
])
->group('game_id,role_id')->select();
$applyRecords = [];
foreach ($applyItems as $item) {
$applyRecords[$this->getGameRoleId($item['game_id'], $item['role_id'])] = $item['amount'] ;
}
}
$spendItems = [];
if (count($bindingRoles) > 0) {
$spendOrWhere = [];
foreach ($bindingRoles as $bindingRole) {
$spendOrWhere[] = '(game_player_id="' . $bindingRole['role_id'] . '" and game_id=' . $bindingRole['game_id'] . ')';
}
$spendCondition = [
'pay_status' => 1,
'_string' => '(' . implode(' or ', $spendOrWhere) . ')',
];
$spendList = M('spend', 'tab_')->field('sum(pay_amount) amount, game_id, game_player_id')->where($spendCondition)->group('game_id,game_player_id')->select();
foreach ($spendList as $item) {
$spendItems[$this->getGameRoleId($item['game_id'], $item['game_player_id'])] = $item['amount'];
}
}
return [
'users' => $users,
'spendItems' => $spendItems,
'bindings' => $bindings,
'bindingRoles' => $bindingRoles,
'applyRecords' => $applyRecords,
'provideRecords' => $provideRecords,
'verifyRecords' => $verifyRecords,
'todayProvideRecords' => $todayProvideRecords,
];
}
public function makeTestingUserRecords($roles)
{
$result = $this->statByRoles($roles);
$users = $result['users'];
$spendItems = $result['spendItems'];
$bindings = $result['bindings'];
$bindingRoles = $result['bindingRoles'];
$applyRecords = $result['applyRecords'];
$provideRecords = $result['provideRecords'];
$verifyRecords = $result['verifyRecords'];
$todayProvideRecords = $result['todayProvideRecords'];
$records = [];
foreach ($roles as $role) {
$user = $users[$role['user_id']] ?? null;
$binding = $bindings[$role['game_role_id']] ?? null;
$bindingRole = null;
if ($binding) {
$bindGameRoleId = $this->getGameRoleId($binding['game_id'], $binding['bind_role_id']);
$bindingRole = $bindingRoles[$bindGameRoleId] ? $bindingRoles[$bindGameRoleId] : null;
}
$gameSetting = $this->getGameSettingByGameId($role['game_id']);
$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' => $gameSetting ? $gameSetting['base_quota'] : 0,
'other_quota' => $role['testing_other_quota'],
'quota' => $bindingRole && isset($spendItems[$bindingRole['game_role_id']]) ? $spendItems[$bindingRole['game_role_id']] : 0,
'verify_amount' => $verifyRecords[$role['game_role_id']] ?? 0,
'provide_amount' => $provideRecords[$role['game_role_id']] ?? 0,
'today_amount' => $todayProvideRecords[$role['game_role_id']] ?? 0,
'apply_amount' => $applyRecords[$role['game_role_id']] ?? 0,
'status' => $user && $user['lock_status'] == 1 ? '正常' : '锁定',
'create_time' => date('Y-m-d H:i:s', $role['create_time'])
];
}
return $records;
}
public function bindRole($params, $promote)
{
$gameId = $params['game_id'] ?? 0;
$testingRoleId = $params['testing_role_id'] ?? '';
$bindRoleId = $params['bind_role_id'] ?? '';
$testingGameRoleId = $this->getGameRoleId($gameId, $testingRoleId);
$bindGameRoleId = $this->getGameRoleId($gameId, $bindRoleId);
$testingGameRoleId = $this->repository->getGameRoleId($gameId, $testingRoleId);
$bindGameRoleId = $this->repository->getGameRoleId($gameId, $bindRoleId);
$testingRole = M('user_play_info', 'tab_')
->field(['id', 'role_id', 'user_id', 'game_id', 'promote_id'])
@ -479,8 +288,186 @@ class TestingResourceService
}
}
public function getBatches()
public function apply($params, $promote = null)
{
$gameId = $params['game_id'] ?? 0;
$roleId = $params['role_id'] ?? '';
$serverId = $params['server_id'] ?? 0;
$userAccount = $params['user_account'] ?? '';
$records = $params['records'] ?? [];
if ($promote && $promote['level'] > 2) {
throw new \Exception('权限不足');
}
$resources = [];
if ($gameId == 229) {
$resources = $this->getGameCatResources('android');
} elseif ($gameId == 230) {
$resources = $this->getGameCatResources('ios');
} else {
throw new \Exception('该游戏不可申请资源');
}
$binding = M('testing_binding', 'tab_')->where(['game_id' => $gameId, 'role_id' => $roleId])->find();
/* if (is_null($binding)) {
throw new \Exception('该角色未绑定玩家角色');
} */
$user = M('user', 'tab_')->field(['id', 'promote_id'])->where(['account' => $userAccount])->find();
if (is_null($user)) {
throw new \Exception('玩家账号不存在');
}
$testingUser = M('testing_user', 'tab_')->where(['user_id' => $user['id']])->find();
if (is_null($testingUser)) {
throw new \Exception('测试账号不存在');
}
$server = M('server', 'tab_')->field(['id', 'server_name', 'server_id'])->where(['id' => $serverId])->find();
if (is_null($server)) {
throw new \Exception('区服不存在');
}
$promoteService = new PromoteService();
$role = M('user_play_info', 'tab_')
->field(['id', 'role_id', 'promote_id', 'game_id', 'testing_other_quota'])
->where(['user_id' => $user['id'], 'game_id' => $gameId, 'server_id' => $server['server_id'], 'role_id' => $roleId])
->find();
if (is_null($role)) {
throw new \Exception('角色不存在');
}
$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) {
throw new \Exception('每个账号同区服只能申请一个角色');
}
$testPromote = M('promote', 'tab_')->field(['id', 'chain'])->where(['id' => $role['promote_id']])->find();
if (is_null($testPromote) || ($promote && !$promoteService->isSubOrSelf($testPromote, $promote))) {
throw new \Exception('测试角色所属推广员异常');
}
$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)) {
throw new \Exception('绑定玩家角色不存在');
}
$bindPromote = M('promote', 'tab_')->field(['id', 'chain'])->where(['id' => $bindingRole['promote_id']])->find();
if (is_null($bindPromote) || ($promote && !$promoteService->isSubOrSelf($bindPromote, $promote))) {
throw new \Exception('绑定角色所属推广员异常');
}
/* if ($testPromote['id'] != $bindPromote['id']) {
throw new \Exception('测试账号与玩家账号所属推广员不同');
} */
}
$hasItf = false;
$amount = 0;
if ($hasItf) {
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 {
throw new \Exception('含有资源内容不存在');
}
/**
* @todo 游戏猫只能每个资源数量只能为1
*/
if ($record['num'] != 1) {
throw new \Exception('该游戏每次申请单项资源数量只能为1');
}
}
} else {
foreach ($records as $key => $record) {
if (empty($record['amount'])) {
throw new \Exception('请输入资源价值');
}
if (empty($record['remark'])) {
throw new \Exception('请输入资源备注');
}
$amount += $record['amount'];
}
}
$testingResourceService = new TestingResourceService();
$remainQuota = $testingResourceService->getRemainQuota($role, $bindingRole);
if ($amount > $remainQuota) {
throw new \Exception('额度不足');
}
$batchNo = date('YmdHis') . substr(md5($roleId . strval(microtime(true)) . rand(0, 9999)), 8, 16);
try {
$model = new Model();
$model->startTrans();
$batch = [
'batch_no' => $batchNo,
'user_id' => $testingUser['user_id'],
'game_id' => $gameId,
'role_id' => $roleId,
'server_id' => $serverId,
'apply_promote_id' => $promote ? $promote['id'] : 0,
'apply_amount' => $amount,
'provide_status' => 0,
'verify_status' => 0,
'create_time' => time(),
'update_time' => time(),
];
$batchId = M('testing_resource_batch', 'tab_')->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' => isset($record['resource_name']) ? $record['resource_name'] : ($record['remark'] ?? ''),
'ref_amount' => isset($record['amount']) ? $record['amount'] : $record['value'],
'num' => $record['num'] ?? 1,
'amount' => isset($record['amount']) ? $record['amount'] : ($record['num'] * $record['value']),
'remark' => $record['remark'],
];
M('testing_resource_order', 'tab_')->add($order);
}
$model->commit();
} catch (\Exception $e) {
$model->rollback();
throw new \Exception('系统异常' . $e->getMessage());
}
}
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;
}
}

@ -9,6 +9,8 @@ use OSS\Core\OssException;
use Base\Tool\GameCatClient;
use Think\Model;
use Base\Service\TestingResourceService;
use Base\Repository\TestingResourceRepository;
use Base\Repository\GameRepository;
class TestingResourceController extends BaseController
{
@ -19,67 +21,19 @@ 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');
$params = I('get.');
$loginPromote = $this->getLoginPromote();
$repository = new TestingResourceRepository();
$query = $repository->getTestingUsersQuery($params, $loginPromote);
[$roles, $pagination, $count] = $this->paginate($query);
$conditions = [];
$subConditions = [
'_string' => '1=1'
];
$promoteService = new PromoteService();
$visibleGameIds = $promoteService->getVisibleGameIds($loginPromote);
$strCondition = 'game_id in (0)';
if (count($visibleGameIds) > 0) {
$strCondition = 'game_id in (' . implode(',', $visibleGameIds) . ')';
}
if ($createTimeStart) {
$strCondition .= ' and create_time >=' . strtotime($createTimeStart . ' 00:00:00');
}
if ($createTimeEnd) {
$strCondition .= ' and create_time <=' . strtotime($createTimeEnd . ' 23:59:59');
}
$subSql = M('testing_user', 'tab_')->field(['user_id'])->where($subConditions)->select(false);
$strCondition .= ' and user_id in (' . $subSql . ')';
$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);
$records = $repository->makeTestingUserRecords($roles);
$testingResourceService = new TestingResourceService();
$records = $testingResourceService->makeTestingUserRecords($roles);
$gameRepository = new GameRepository();
$this->assign('games', $this->getGames());
$this->assign('servers', $this->getServersByGameId($gameId));
$this->assign('games', $gameRepository->getChoiceGames());
$this->assign('servers', $gameRepository->getServersByGameId($gameId));
$this->assign('count', $count);
$this->assign('pagination', $pagination);
$this->assign('records', $records);
@ -108,117 +62,20 @@ class TestingResourceController extends BaseController
public function batches()
{
$gameId = I('game_id', 0);
$serverId = I('server_id', '');
$createTimeStart = I('create_time_start', '');
$createTimeEnd = I('create_time_end', '');
$verifyStatus = I('verify_status', -1);
$provideStatus = I('provide_status', -1);
$account = I('account');
$params = I('get.');
$loginPromote = $this->getLoginPromote();
$promoteService = new PromoteService();
$subSql = M('user', 'tab_')
->where('id=tab_testing_resource_batch.user_id and promote_id in (' . $promoteService->subInSql($loginPromote) . ')')
->select(false);
$conditions = [
'_string' => 'exists (' . $subSql . ')'
];
if ($createTimeStart) {
$conditions['_string'] .= ' and create_time >=' . strtotime($createTimeStart . ' 00:00:00');
}
if ($createTimeEnd) {
$conditions['_string'] .= ' and create_time <=' . strtotime($createTimeEnd . ' 23:59:59');
}
if ($verifyStatus != -1) {
$conditions['verify_status'] = $verifyStatus;
}
if ($provideStatus != -1) {
$conditions['provide_status'] = $provideStatus;
}
if ($gameId) {
$conditions['game_id'] = $gameId;
}
if ($serverId) {
$conditions['server_id'] = $serverId;
}
if ($account) {
$user = M('user', 'tab_')->field(['id'])->where('account like "' . $account . '%"')->find();
if ($user) {
$conditions['user_id'] = $user['id'];
} else {
$conditions['_string'] .= ' and 1<>1';
}
}
$query = M('testing_resource_batch', 'tab_')->where($conditions)->order('create_time desc');
$repository = new TestingResourceRepository();
$query = $repository->getBatchesQuery($params, $loginPromote);
list($batches, $pagination, $count) = $this->paginate($query);
$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);
}
}
$testingResourceService = new TestingResourceService();
$records = $repository->makeBatchesRecords($batches);
$records = [];
foreach ($batches as $batch) {
$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;
$records[] = [
'id' => $batch['id'],
'batch_no' => substr($batch['batch_no'], 14),
'create_time' => date('Y-m-d H:i:s', $batch['create_time']),
'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,
'apply_amount' => $batch['apply_amount'],
'provide_amount' => $batch['provide_amount'],
'verify_status' => $batch['verify_status'],
'verify_status_text' => $testingResourceService->getVerifyStatusText($batch['verify_status']),
'verify_time' => $batch['verify_time'] == 0 ? '--' : date('Y-m-d H:i:s', $batch['verify_time']),
'provide_status' => $batch['provide_status'],
'provide_status_text' => $testingResourceService->getProvideStatusText($batch['provide_status']),
'provide_time' => $batch['provide_time'] == 0 ? '--' : date('Y-m-d H:i:s', $batch['provide_time']),
'content' => $content,
];
}
$gameRepository = new GameRepository();
$this->assign('verifyStatusList', TestingResourceService::$verifyStatusList);
$this->assign('provideStatusList', TestingResourceService::$provideStatusList);
$this->assign('servers', $this->getServersByGameId($gameId));
$this->assign('games', $this->getGames());
$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('pagination', $pagination);
$this->assign('records', $records);
@ -311,158 +168,15 @@ class TestingResourceController extends BaseController
public function doApply()
{
$gameId = I('game_id', 0);
$roleId = I('role_id', '');
$serverId = I('server_id', 0);
$userAccount = I('user_account', '');
$records = I('records', []);
$params = I('post.');
$loginPromote = $this->getLoginPromote();
if ($loginPromote['level'] > 2) {
return $this->ajaxReturn(['status' => 0, 'message' => '权限不足']);
}
$resources = [];
/**
* @todo 目前仅限游戏猫
*/
if ($gameId == 229) {
$resources = $this->getGameCatResources('android');
} elseif ($gameId == 230) {
$resources = $this->getGameCatResources('ios');
} else {
return $this->ajaxReturn(['status' => 0, 'message' => '该游戏不可申请资源']);
}
$binding = M('testing_binding', 'tab_')->where(['game_id' => $gameId, 'role_id' => $roleId])->find();
/* if (is_null($binding)) {
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_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' => '区服不存在']);
}
$promoteService = new PromoteService();
$role = M('user_play_info', 'tab_')
->field(['id', 'role_id', 'promote_id', 'game_id', 'testing_other_quota'])
->where(['user_id' => $user['id'], 'game_id' => $gameId, 'server_id' => $server['server_id'], 'role_id' => $roleId])
->find();
if (is_null($role)) {
return $this->ajaxReturn(['status' => 0, 'message' => '角色不存在']);
}
$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' => '每个账号同区服只能申请一个角色']);
}
$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' => '测试角色所属推广员异常']);
}
$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' => '测试账号与玩家账号所属推广员不同']);
} */
}
$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' => '含有资源内容不存在']);
}
/**
* @todo 游戏猫只能每个资源数量只能为1
*/
if ($record['num'] != 1) {
return $this->ajaxReturn(['status' => 0, 'message' => '该游戏每次申请单项资源数量只能为1']);
}
}
$testingResourceService = new TestingResourceService();
$remainQuota = $testingResourceService->getRemainQuota($role, $bindingRole);
if ($amount > $remainQuota) {
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_no' => $batchNo,
'user_id' => $testingUser['user_id'],
'game_id' => $gameId,
'role_id' => $roleId,
'server_id' => $serverId,
'apply_promote_id' => $loginPromote['id'],
'apply_amount' => $amount,
'provide_status' => 0,
'verify_status' => 0,
'create_time' => time(),
'update_time' => time(),
];
$batchId = M('testing_resource_batch', 'tab_')->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'],
'ref_amount' => $record['value'],
'num' => $record['num'],
'amount' => $record['num'] * $record['value'],
'remark' => $record['remark'],
];
M('testing_resource_order', 'tab_')->add($order);
}
$model->commit();
return $this->ajaxReturn(['status' => 1, 'message' => '申请成功,等待审核']);
} catch (\Exception $e) {
$model->rollback();
return $this->ajaxReturn(['status' => 0, 'message' => '系统异常' . $e->getMessage()]);
$testingResourceService = new TestingResourceService();
$testingResourceService->apply($params, $loginPromote);
return $this->ajaxReturn(['status' => 1, 'message' => '申请成功,等待审核。']);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
@ -479,39 +193,11 @@ class TestingResourceController extends BaseController
}
}
private function getGames()
{
$map = [
'id' => ['in', [229, 230]]
];
$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) . ')';
}
return M('game', 'tab_')->field('id,game_name')->where($map)->select();
}
private function getServersByGameId($gameId = 0)
{
if ($gameId == 0) {
return [];
}
$map = [];
$map['game_id'] = $gameId;
return M('server', 'tab_')
->field('id,server_name,server_id')
->where($map)
->order('server_id asc')
->select();
}
public function getServers()
{
$gameId = I('game_id', 0);
$servers = $this->getServersByGameId($gameId);
$gameRepository = new GameRepository();
$servers = $gameRepository->getServersByGameId($gameId);
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['servers' => $servers]]);
}

@ -136,6 +136,8 @@
</div>
<?php endif;?>
<div class="clearfix" style="margin-top: 10px;">
<input id="hasItf" type="hidden" value="<?=$hasItf?>" name="has_itf">
<?php if ($hasItf):?>
<div class="form-group fl">
<select id="resource-type-select" name="resource_type_id" style="width:150px" class="select_gallery">
<option value="">请选择资源类型</option>
@ -147,7 +149,7 @@
</select>
</div>
<div class="form-group fl">
<input id="remark-input" type="text" name="remark" class="txt normal_txt" id="uid" placeholder="请输入备注" value="">
<input id="remark-input" type="text" name="remark" class="txt normal_txt" placeholder="请输入备注" value="">
</div>
<div class="form-group fl">
<p id="resource-amount" class="static-input">资源价值: --</p>
@ -156,6 +158,14 @@
<p class="static-input">资源数量: 1</p>
<!-- <input id="num-input" type="text" name="num" class="txt normal_txt" id="uid" placeholder="请输入资源数量" value=""> -->
</div>
<?php else:?>
<div class="form-group fl">
<input id="remark-input" type="text" name="remark" class="txt normal_txt" placeholder="请输入资源备注" value="">
</div>
<div class="form-group fl">
<input id="remark-amount" type="text" name="amount" class="txt normal_txt" placeholder="请输入资源价值" value="">
</div>
<?php endif;?>
<div class="form-group fl">
<button id="add-row" class="add-row" type="button">增加</button>
</div>
@ -164,6 +174,7 @@
</div>
<div class="trunk-list list_normal">
<div class="table-wrapper" style="height: 280px;">
<?php if($hasItf):?>
<table id="resource-table" class="table normal_table">
<thead>
<tr class="table-header">
@ -179,6 +190,20 @@
</tbody>
</table>
<?php else:?>
<table id="resource-table" class="table normal_table ">
<thead>
<tr class="table-header">
<th>资源备注</th>
<th>资源价值</th>
<th>操作</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<?php endif;?>
</div>
<div class="btn-row clearfix">
<button id="submit-btn" class="submit-btn" type="button">提交</button>
@ -320,6 +345,35 @@
if (rowCount >= 5) {
return layer.msg('最多同时只能添加5条')
}
var hasItf = $('#hasItf').val()
if (hasItf == 1) {
addRowItf()
} else {
addRow()
}
})
function addRow() {
var remark = $('#remark-input').val()
var amount = $('#remark-amount').val()
if (remark == '') {
return layer.msg('请输入资源备注')
}
if (amount == '') {
return layer.msg('请输入资源价值')
}
var html = '<tr class="normal-row" >' +
'<td style="width:420px" class="remark"><input name="remark" type="text" style="width:400px" value="' + remark + '"></td>' +
'<td class="amount"><input name="amount" type="text" value="' + amount + '"></td>' +
'<td><button class="delete-row" type="button" class="danger-btn">删除</button></td>' +
'</tr>';
$('#resource-table tbody').append(html)
rowCount ++
$(".select_gallery").select2()
statQuota()
}
function addRowItf() {
var resourceTypeId = $('#resource-type-select').val()
var resourceId = $('#resource-select').val()
var resourceTypeName = $('#resource-type-select option:selected').html()
@ -353,7 +407,8 @@
rowCount ++
$(".select_gallery").select2()
statQuota()
})
}
$('#resource-table').on('click', '.delete-row', function () {
var tr = $(this).parents('tr').eq(0)
rowCount --
@ -369,10 +424,19 @@
})
function statQuota() {
var quota = $('#quota').attr('data-quota')
var hasItf = $('#hasItf').val()
var verifyQuota = 0
$('#resource-table').find('.normal-row').each(function (index, ele) {
verifyQuota += $(ele).find('.amount').html() * $(ele).find('.num').children('input').val()
})
if (hasItf == 1) {
$('#resource-table').find('.normal-row').each(function (index, ele) {
verifyQuota += $(ele).find('.amount').html() * $(ele).find('.num').children('input').val()
})
} else {
$('#resource-table').find('.normal-row').each(function (index, ele) {
verifyQuota += parseInt($(ele).find('.amount').children('input').val())
})
}
$('#verify-quota').html(verifyQuota)
$('#quota').html(quota-verifyQuota)
}
@ -458,18 +522,30 @@
function getRecords() {
var records = []
$('#resource-table tbody tr').each(function (index, tr) {
var num = $(tr).find('input[name=num]').val()
var remark = $(tr).find('input[name=remark]').val()
var resourceId = $(tr).attr('data-resource-id')
var resourceTypeId = $(tr).attr('data-resource-type-id')
records.push({
resource_id: resourceId,
resource_type_id: resourceTypeId,
num: num,
remark: remark,
var hasItf = $('#hasItf').val()
if (hasItf == 1) {
$('#resource-table tbody tr').each(function (index, tr) {
var num = $(tr).find('input[name=num]').val()
var remark = $(tr).find('input[name=remark]').val()
var resourceId = $(tr).attr('data-resource-id')
var resourceTypeId = $(tr).attr('data-resource-type-id')
records.push({
resource_id: resourceId,
resource_type_id: resourceTypeId,
num: num,
remark: remark,
})
})
})
} else {
$('#resource-table tbody tr').each(function (index, tr) {
var amount = $(tr).find('input[name=amount]').val()
var remark = $(tr).find('input[name=remark]').val()
records.push({
amount: amount,
remark: remark,
})
})
}
return records
}

@ -2668,8 +2668,9 @@ ADD COLUMN `detail` longtext NULL COMMENT '审批详情' AFTER `remark`;
CREATE TABLE `tab_testing_game_setting` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`base_game_id` int(11) NOT NULL COMMENT '游戏ID',
`base_quota` int(11) NOT NULL default 0 COMMENT '初始额度',
`base_quota` int(11) NOT NULL DEFAULT '0' COMMENT '初始额度',
`rate` int(11) NOT NULL DEFAULT '0' COMMENT '额度比例(百分比)',
`has_itf` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否发放接口',
`create_time` int(11) NOT NULL DEFAULT '0',
`update_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)

Loading…
Cancel
Save