Merge branch 'feature/testing_resource_admin' of wmtx/platform into master

测试资源功能优化
master
廖金灵 4 years ago committed by Gogs
commit 181b22969d

@ -134,21 +134,6 @@ class ConsoleController extends Think {
echo M('game', 'tab_')->where('id>2')->field(['id', 'game_name'])->where('sdk_version=1')->select(false);
}
public function testGameCat()
{
$key = '123456';
$params = [
];
ksort($params);
$paramsStr = http_build_query($params) . '&key=' . $key;
$sign = md5($paramsStr);
$client = new AggregateClient();
$result = $client->api('game-data', ['unique_codes' => ['w123'], 'started_at' => '2019-06-27', 'ended_at' => '2020-07-27']);
var_dump($result);
}
public function initMarketAdmin()
{
$marketService = new MarketService();
@ -616,6 +601,40 @@ class ConsoleController extends Think {
// ARPU (当日充值金额/当日活跃用户数)
// ARRPU (当日充值金额/当日充值用户数)
}
public function checkAndfreezeTestingUser()
{
$pageCount = 100;
$hasNext = true;
$lastId = 0;
do {
$testingUsers = M('testing_user', 'tab_')
->where(['status' => ['in', [1, 2]], 'id' => ['gt', $lastId]])
->order('id asc')
->limit($pageCount)
->select();
if (count($testingUser) < $pageCount) {
$hasNext = false;
}
$userIds = array_column($testingUsers, 'user_id');
$users = M('user', 'tab_')->field(['id', 'account', 'login_time'])->where(['id' => ['in', $userIds]])->select();
$users = index_by_column('id', $users);
$unloginLimitTime = 7 * 24 * 3600;
$unloginUserIds = [];
foreach ($testingUsers as $testingUser) {
$user = $users[$testingUser['user_id']] ?? null;
if ($user && (time() - $user['login_time']) > $unloginLimitTime) {
$unloginUserIds[] = $user['id'];
}
$lastId = $testingUser['id'];
}
if (count($unloginUserIds) > 0) {
M('testing_user', 'tab_')->where(['user_id' => ['in', $unloginUserIds]])->save([
'status' => 3
]);
}
} while($hasNext);
}
public function statUserRetention()
{

@ -10,7 +10,7 @@ use Base\Tool\TaskClient;
use Base\Service\TestingResourceService;
use GuzzleHttp\Client;
use think\Db;
use Base\Tool\GameCatClient;
use Base\Tool\GameResource;
class GameApiController extends Think {
@ -24,13 +24,18 @@ class GameApiController extends Think {
$service = new TestingResourceService();
$gameIds = $service->getHasItfGameIds();
$map = ['verify_status' => 0];
$map = ['verify_status' => 0, 'auto_verify' => 1];
if (count($gameIds) > 0) {
$map['game_id'] = ['in', $gameIds];
}
$batches = M('testing_resource_batch', 'tab_')->where($map)->select();
foreach ($batches as $batch) {
$service->verify($batch);
try {
$service->verify($batch);
echo 'SUCCESS [' . $batch['id'] . ']审核成功' . PHP_EOL;
} catch (\Exception $e) {
echo 'ERROR [' . $batch['id'] . ']审核异常' . PHP_EOL;
}
}
}
@ -46,13 +51,33 @@ class GameApiController extends Think {
}
$batches = M('testing_resource_batch', 'tab_')->where($map)->select();
foreach ($batches as $batch) {
$service->provide($batch);
try {
$service->provide($batch);
echo 'SUCCESS [' . $batch['id'] . ']发放成功' . PHP_EOL;
} catch (\Exception $e) {
echo 'ERROR [' . $batch['id'] . ']发放异常' . PHP_EOL;
}
}
}
public function send()
{
$role = [
// 229
// 231
$game = M('game', 'tab_')->field(['id', 'sdk_version'])->where(['id' => 231])->find();
// $gameResource1 = new GameResource($game);
/* $resources = $gameResource1->getResources(1);
return; */
/* $successCount = 0;
for ($i = 0; $i < 10; $i ++) {
$resources = $gameResource1->getResources(1);
if (count($resources) > 0) {
$successCount ++;
}
}
var_dump($successCount);
return; */
/* $role = [
'role_id' => '6819493',
'user_account' => 'qh11102',
'sdk_version' => 1,
@ -62,9 +87,31 @@ class GameApiController extends Think {
'ref_id' => '8',
'remark' => '测试',
'order_no' => date('YmdHis') . rand(1000, 9999) . '_1',
]; */
$role = [
'role_id' => '9571794000008',
'server_id' => '8',
'sdk_version' => 1,
];
$service = new TestingResourceService();
$result = $service->provideFromGameCat($order, $role);
$order = [
'ref_id' => '9000',
'remark' => '测试',
'order_no' => date('YmdHis') . rand(1000, 9999) . '_1',
];
/* $role = [
'role_id' => '466500506',
'server_id' => '49000152',
'sdk_version' => 2,
];
$order = [
// 'ref_id' => '9000',
'ref_amount' => 6,
'order_no' => date('YmdHis') . rand(1000, 9999) . '_1',
]; */
$gameResource = new GameResource($game);
// $result = $gameResource->getResources();
$result = $gameResource->apply($order, $role);
var_dump($result);
}
}

@ -18,14 +18,15 @@ class TestingResourceController extends ThinkController
$gameId = $params['game_id'] ?? 0;
$repository = new TestingResourceRepository();
$query = $repository->getTestingUsersQuery($params);
$query = $repository->getTestingRolesQuery($params);
[$roles, $page, $count] = $this->paginate($query);
$records = $repository->makeTestingUserRecords($roles);
$records = $repository->makeTestingRoleRecords($roles);
$gameRepository = new GameRepository();
$this->assign('statusList', TestingResourceRepository::$userStatusList);
$this->assign('games', $gameRepository->getChoiceGames());
$this->assign('servers', $gameRepository->getServersByGameId($gameId));
$this->assign('count', $count);
@ -34,6 +35,24 @@ class TestingResourceController extends ThinkController
$this->display();
}
public function users()
{
$params = I('get.');
$repository = new TestingResourceRepository();
$query = $repository->getTestingUsersQuery($params);
[$testingUsers, $page, $count] = $this->paginate($query);
$records = $repository->makeTestingUserRecords($testingUsers);
$this->assign('statusList', TestingResourceRepository::$userStatusList);
$this->assign('count', $count);
$this->assign('records', $records);
$this->assign('_page', $page);
$this->display();
}
public function getServers()
{
$gameId = I('game_id', 0);
@ -277,7 +296,6 @@ class TestingResourceController extends ThinkController
->find();
}
$hasItf = 0;
$servers = [];
@ -290,6 +308,9 @@ class TestingResourceController extends ThinkController
->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();
if ($bindingRole) {
$bindingRole['binding_time'] = $binding['create_time'];
}
}
$repository = new TestingResourceRepository();
@ -443,17 +464,28 @@ class TestingResourceController extends ThinkController
public function getResourceTypes()
{
$gameId = I('game_id', 0);
$testingResourceService = new TestingResourceService();
$resourceTypes = $testingResourceService->getResourceTypes($gameId);
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resourceTypes' => $resourceTypes]]);
$game = M('game', 'tab_')->field(['id', 'sdk_version'])->where(['id' => $gameId])->find();
try {
$testingResourceService = new TestingResourceService();
$resourceTypes = $testingResourceService->getResourceTypes($game);
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resourceTypes' => $resourceTypes]]);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage(), 'data' => ['resourceTypes' => []]]);
}
}
public function getResources()
{
$typeId = I('type_id', 0);
$testingResourceService = new TestingResourceService();
$resources = $testingResourceService->getResources($typeId);
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resources' => $resources]]);
$gameId = I('game_id', 0);
$game = M('game', 'tab_')->field(['id', 'sdk_version'])->where(['id' => $gameId])->find();
try {
$testingResourceService = new TestingResourceService();
$resources = $testingResourceService->getResources($game, $typeId);
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resources' => $resources]]);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage(), 'data' => ['resources' => []]]);
}
}
public function exportOrders()
@ -531,4 +563,53 @@ class TestingResourceController extends ThinkController
'provide_status_text' => '发放状态'
]);
}
public function deleteTestingUser()
{
$userId = I('user_id', 0);
try {
$testingResourceService = new TestingResourceService();
$testingResourceService->deleteTestingUser($userId);
return $this->ajaxReturn(['status' => 1, 'message' => '删除成功']);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
public function verifyTestingUsers()
{
$userIds = I('user_ids', 0);
$verifyStatus = I('verify_status', 1);
try {
$testingResourceService = new TestingResourceService();
$testingResourceService->verifyTestingUser($userIds, $verifyStatus);
return $this->ajaxReturn(['status' => 1, 'message' => '审核成功']);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
public function unfreezeTestingUser()
{
$userId = I('user_id', 0);
try {
$testingResourceService = new TestingResourceService();
$testingResourceService->unfreezeTestingUser($userId);
return $this->ajaxReturn(['status' => 1, 'message' => '解禁成功']);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
public function freezeTestingUser()
{
$userId = I('user_id', 0);
try {
$testingResourceService = new TestingResourceService();
$testingResourceService->freezeTestingUser($userId);
return $this->ajaxReturn(['status' => 1, 'message' => '禁用成功']);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
}

@ -100,10 +100,11 @@ body {
background: #E5E5E5;
color: #535875;
border: none;
border-radius: 4px;
border-radius: 3px;
cursor: pointer;
display: inline-block;
margin-left: 10px;
padding: 0px 10px;
}
.info-row button.bind-btn {
background: #409eff;
@ -365,7 +366,7 @@ body {
$.ajax({
url: "{:U('getResources')}",
type: "post",
data: { type_id: typeId },
data: { game_id: globalGameId, type_id: typeId },
dataType: 'json',
success: function(result){
if (result.status == 1) {

@ -113,6 +113,14 @@
<span class="add-on"><i class="icon-th"></i></span>
</div>
</div>
<div class="input-list input-list-promote search_label_rehab">
<select name="status" class="select_gallery" style="width:120px;">
<option value="0">请选择账号状态</option>
<?php foreach($statusList as $key => $value):?>
<option value="<?=$key?>"><?=$value?></option>
<?php endforeach;?>
</select>
</div>
<div class="input-list">
<a class="sch-btn" href="javascript:;" id="search" url="{:U('TestingResource/index')}">搜索</a>
</div>

@ -0,0 +1,338 @@
<extend name="Public/base"/>
<block name="css">
<link rel="stylesheet" href="__CSS__/select2.min.css" type="text/css" />
<link rel="stylesheet" href="__CSS__/promote.css" type="text/css"/>
<script src="__STATIC__/laydate/laydate.js"></script>
<link rel="stylesheet" type="text/css" href="__STATIC__/webuploader/webuploader.css" media="all">
<style>
.select2-container--open {
z-index: 1001;
}
.select2-container--default .select2-selection--single {
color: #000;
resize: none;
border-width: 1px;
border-style: solid;
border-color: #a7b5bc #ced9df #ced9df #a7b5bc;
box-shadow: 0px 3px 3px #F7F8F9 inset;height:35px;
height:28px;border-radius:3px;font-size:12px;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
line-height:35px;
line-height:28px;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
height:26px;
}
.select2-container--default .select2-search--dropdown .select2-search__field {
height:26px;line-height:26px;font-size:12px;
}
.select2-results__option[aria-selected] {font-size:12px;}
.textarea-style {
width: 200px;
height: 80px;
border-radius: 5px;
padding: 5px;
}
.mustmark {
color: #FF0000;
font-style: normal;
margin: 0 3px;
}
.clearfix:after {
content: "\20";
display: block;
height: 0;
clear: both;
}
.clearfix {
*zoom: 1;
}
</style>
</block>
<block name="body">
<script type="text/javascript" src="__JS__/bootstrap.min.js"></script>
<script type="text/javascript" src="__JS__/select2.min.js"></script>
<script type="text/javascript" src="__JS__/jquery.form.js"></script>
<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
<script src="__STATIC__/md5.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="__STATIC__/webuploader/webuploader.js"></script>
<script src="__STATIC__/layer/layer.js" type="text/javascript"></script>
<script type="text/javascript" src="__STATIC__/layer/extend/layer.ext.js"></script>
<div class="cf main-place top_nav_list navtab_list">
<h3 class="page_title">测试账号</h3>
</div>
<div class="cf top_nav_list">
<!-- 高级搜索 -->
<div class="fl button_list">
<div class="tools">
<empty name="show_status">
<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>
</div>
</div>
<div class="jssearch fl cf search_list">
<div class="input-list search-title-box">
<label>搜索:</label>
</div>
<div class="input-list">
<input type="text" name="account" placeholder="测试账号" class="" value="" style="width: 150px">
</div>
<div class="input-list input-list-promote search_label_rehab">
<select name="status" class="select_gallery" style="width:120px;">
<option value="0">请选择状态</option>
<?php foreach($statusList as $key => $value):?>
<option value="<?=$key?>"><?=$value?></option>
<?php endforeach;?>
</select>
</div>
<div class="input-list input-list-promote search_label_rehab">
<input type="text" readonly name="create_time_start" class="time-select" value="{:I('create_time_start')}"
placeholder="添加开始时间"/>
-
<div class="input-append date" id="datetimepicker" style="display:inline-block">
<input type="text" readonly name="create_time_end" class="time-select" value="{:I('create_time_end')}"
placeholder="添加结束时间"/>
<span class="add-on"><i class="icon-th"></i></span>
</div>
</div>
<div class="input-list">
<a class="sch-btn" href="javascript:;" id="search" url="{:U('TestingResource/users')}">搜索</a>
</div>
</div>
</div>
<!-- 数据列表 -->
<div class="data_list">
<div class="">
<table>
<!-- 表头 -->
<thead>
<tr>
<th>测试账号</th>
<th>账号状态</th>
<th>推广员</th>
<th>添加时间</th>
<th>操作</th>
</tr>
</thead>
<!-- 列表 -->
<tbody>
<empty name ="records">
<td colspan="99" class="text-center">aOh! 暂时还没有内容!</td>
<else />
<volist name="records" id="record">
<tr data-user-id="{$record.user_id}">
<td>{$record.user_account}</td>
<td>{$record.status_text}</td>
<td>{$record.promote_account}</td>
<td>{$record.create_time}</td>
<td>
<?php if($record['status'] == 3):?>
<a href="javascript:;" style="color: #3C95C8" class="unfreeze-btn">解禁</a>
<?php else:?>
<a href="javascript:;" style="color: #f56c6c" class="freeze-btn">禁用</a>
<?php endif;?>
</td>
</tr>
</volist>
</empty>
</tbody>
</table>
</div>
</div>
<div class="page">
<if condition="$role_export_check eq true ">
<a class="sch-btn export-btn"
href="{:U(CONTROLLER_NAME.'/'.ACTION_NAME,array_merge(['export'=>1],I('get.')))}" target="_blank">导出</a>
</if>
{$_page|default=''}
</div>
<div class="common_settings">
<span class="plus_icon"><span><img src="__IMG__/zwmimages/icon_jia.png"></span></span>
<form class="addShortcutIcon">
<input type="hidden" name="title" value="{$m_title}">
<input type="hidden" name="url" value="Query/withdraw">
</form>
<a class="ajax-post add-butn <notempty name='commonset'>addSIsetted</notempty>" href="javascript:;" target-form="addShortcutIcon" url="{:U('Think/addShortcutIcon')}"><img src="__IMG__/zwmimages/icon_jia.png"><span><notempty name='commonset'>已添加<else />添加至常用设置</notempty></span></a>
</div>
<div id="add-box" class="layer-box" style="display: none;">
<form method="post" enctype="multipart/form-data">
<div class="form-group">
<label>用户账号</label>
<div class="form-item" style="width: 400px;">
<textarea name="accounts" placeholder="用户账号以英文逗号(,)隔开" class="form-input" id="" cols="50" rows="10"></textarea>
</div>
</div>
<div class="form-group">
<label></label>
<a id="add-submit" href="javascript:;" class="add-submit btn">确定</a>
</div>
</form>
</div>
</block>
<block name="script">
<script src="__STATIC__/layer/layer.js" type="text/javascript"></script>
<script type="text/javascript" src="__STATIC__/layer/extend/layer.ext.js" ></script>
<script src="__STATIC__/jquery.cookie.js" charset="utf-8"></script>
<script>
<volist name=":I('get.')" id="vo">
Think.setValue('{$key}',"{$vo}");
</volist>
$(".select_gallery").select2();
</script>
<script type="text/javascript">
//导航高亮
highlight_subnav("{:U('TestingResource/users')}");
$(function(){
// 添加全部选项
if ('all' == "{:I('row', 0)}") {
$("#pagechange").prepend("<option value='all' selected>全部</option>");
} else {
$("#pagechange").prepend("<option value='all'>全部</option>");
}
$('.time-select').each(function(){
laydate.render({
elem: this,
type: 'date'
});
});
//搜索功能
$("#search").click(function(){
var url = $(this).attr('url');
var query = $('.jssearch').find('input').serialize();
query += "&"+$('.jssearch').find('select').serialize();
//query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
query = query.replace(/^&/g,'');
if( url.indexOf('?')>0 ){
url += '&' + query;
}else{
url += '?' + query;
}
window.location.href = url;
});
//回车自动提交
$('.jssearch').find('input').keyup(function(event){
if(event.keyCode===13){
$("#search").click();
}
});
function getIds() {
var ids = [];
$('.ids:checked').each(function() {
ids.push($(this).val());
})
return ids;
}
$('#add-test-user').click(function () {
var box = $('#add-box')
layer.open({
title: '新增',
type: 1,
content: box,
area: ['700px', '380px'],
zIndex: 250,
})
})
function isNumber(num){
if(!num) {
return false
}
var strPreg = /^\d+$/
if(!strPreg.test(num)) {
return false
}
return true
}
$('.unfreeze-btn').click(function () {
var tr = $(this).parents('tr').eq(0)
var userId = tr.attr('data-user-id')
layer.confirm('确定要解禁吗?', {
// closeBtn:0,
title: '解禁',
btn: ['确定'] //按钮
}, function(){
$.ajax({
async: false,
url: "{:U('unfreezeTestingUser')}",
type: "POST",
dataType: "json",
data: { user_id: userId },
success: function (result) {
if (result.status == 0) {
layer.msg(result.message);
} else {
layer.msg(result.message, function(){
window.location.href = window.location.href
})
}
}
})
})
})
$('.freeze-btn').click(function () {
var tr = $(this).parents('tr').eq(0)
var userId = tr.attr('data-user-id')
layer.confirm('确定要禁用吗?', {
// closeBtn:0,
title: '禁用',
btn: ['确定'] //按钮
}, function(){
$.ajax({
async: false,
url: "{:U('freezeTestingUser')}",
type: "POST",
dataType: "json",
data: { user_id: userId },
success: function (result) {
if (result.status == 0) {
layer.msg(result.message);
} else {
layer.msg(result.message, function(){
window.location.href = window.location.href
})
}
}
})
})
})
$('#add-submit').on({
click: function () {
var box = $('#add-box')
var accounts = box.find('[name=accounts]').val()
console.log(accounts)
$.ajax({
async: false,
url: "{:U('addTestingUsers')}",
type: "POST",
dataType: "json",
data: { accounts: accounts },
success: function (result) {
if (result.status == 0) {
layer.msg(result.message);
} else {
var message = '成功' + result.data.successCount + '个, 失败' + result.data.errorCount + '个, 已存在' + result.data.existCount + '个。'
layer.confirm(message, {
btn: ['确定'] //按钮
}, function(){
location.reload();
})
}
},
error: function () {
}
})
}
})
});
</script>
</block>

@ -19,6 +19,18 @@ class TestingResourceRepository
'2' => '审核拒绝',
];
public static $userVerifyStatusList = [
'0' => '待审核',
'1' => '审核通过',
'2' => '审核拒绝',
];
public static $userStatusList = [
'1' => '正常',
'2' => '警告',
'3' => '禁用',
];
public function getProvideStatusText($provideStatus)
{
return self::$provideStatusList[$provideStatus] ?? '未知';
@ -208,7 +220,10 @@ class TestingResourceRepository
$bindings = [];
$bindingRoles = [];
$applyRecords = [];
$testingUsers = [];
if (count($roles) > 0) {
$testingUsers = M('testing_user', 'tab_')->where(['user_id' => ['in', $userIds]])->select();
$testingUsers = index_by_column('user_id', $testingUsers);
$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();
@ -285,7 +300,20 @@ class TestingResourceRepository
'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();
$subBindingSql = M('testing_binding', 'tab_')
->where([
'_string' =>
'tab_testing_binding.bind_role_id = tab_spend.game_player_id and ' .
'tab_testing_binding.game_id = tab_spend.game_id and ' .
'UNIX_TIMESTAMP(FROM_UNIXTIME(tab_testing_binding.create_time, "%Y-%m-%d 00:00:00")) <= tab_spend.pay_time'
])
->select(false);
$spendCondition['_string'] .= ' and exists(' . $subBindingSql . ')';
$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'];
}
@ -301,13 +329,15 @@ class TestingResourceRepository
'verifyRecords' => $verifyRecords,
'todayProvideRecords' => $todayProvideRecords,
'gameSettings' => $gameSettings,
'testingUsers' => $testingUsers,
];
}
public function makeTestingUserRecords($roles)
public function makeTestingRoleRecords($roles)
{
$result = $this->statByRoles($roles);
$users = $result['users'];
$testingUsers = $result['testingUsers'];
$spendItems = $result['spendItems'];
$gameSettings = $result['gameSettings'];
$bindings = $result['bindings'];
@ -324,6 +354,7 @@ class TestingResourceRepository
$records = [];
foreach ($roles as $role) {
$user = $users[$role['user_id']] ?? null;
$testingUser = $testingUsers[$role['user_id']] ?? null;
$binding = $bindings[$role['game_role_id']] ?? null;
$bindingRole = null;
if ($binding) {
@ -339,6 +370,21 @@ class TestingResourceRepository
$spendQuota = $bindingRole && isset($spendItems[$bindingRole['game_role_id']]) ? $spendItems[$bindingRole['game_role_id']] : 0;
$quota = $gameSetting ? round($spendQuota * $gameSetting['rate'] / 100, 2) : 0;
$statusText = '正常';
if (is_null($user) || is_null($testingUser)) {
$statusText = '错误';
} elseif ($testingUser['status'] == 2) {
$statusText = '警告';
} elseif ($testingUser['status'] == 3) {
$statusText = '禁用';
}
if (is_null($user)) {
$statusText .= '(账号不存在)';
} elseif ($user['lock_status'] != 1) {
$statusText .= '(账号锁定)';
}
$records[] = [
'id' => $role['id'],
'game_name' => $role['game_name'],
@ -358,20 +404,21 @@ class TestingResourceRepository
'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 ? '正常' : '锁定',
'status' => $statusText,
'create_time' => date('Y-m-d H:i:s', $role['create_time'])
];
}
return $records;
}
public function getTestingUsersQuery($params, array $promote = null)
public function getTestingRolesQuery($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'] ?? '';
$status = $params['status'] ?? 0;
$roleName = $params['role_name'] ?? '';
$conditions = [];
@ -405,7 +452,11 @@ class TestingResourceRepository
if ($createTimeEnd) {
$strCondition .= ' and create_time <=' . strtotime($createTimeEnd . ' 23:59:59');
}
if ($status != 0) {
$subConditions['status'] = $status;
}
$subConditions['verify_status'] = 1;
$subSql = M('testing_user', 'tab_')->field(['user_id'])->where($subConditions)->select(false);
$strCondition .= ' and user_id in (' . $subSql . ')';
@ -429,4 +480,70 @@ class TestingResourceRepository
$conditions['_string'] = $strCondition;
return M('user_play_info', 'tab_')->where($conditions)->order('create_time desc');
}
public function getTestingUsersQuery($params, array $promote = null)
{
$createTimeStart = $params['create_time_start'] ?? '';
$createTimeEnd = $params['create_time_end'] ?? '';
$status = $params['status'] ?? 0;
$verifyStatus = $params['verify_status'] ?? -1;
$account = $params['account'] ?? '';
$conditions = [];
$strCondition = '1=1';
/* $promoteService = new PromoteService();
if ($promote) {
$subSql = M('user', 'tab_')->field('id')->where('promote_id in (' . $promoteService->subInSql($promote) . ')')->select(false);
$strCondition .= ' and user_id in (' . $subSql . ')';
} */
if ($account) {
$conditions['user_account'] = ['like', '%' . $account . '%'];
}
if ($verifyStatus != -1) {
$conditions['verify_status'] = $verifyStatus;
}
if ($status != 0) {
$conditions['status'] = $status;
}
if ($createTimeStart) {
$strCondition .= ' and create_time >=' . strtotime($createTimeStart . ' 00:00:00');
}
if ($createTimeEnd) {
$strCondition .= ' and create_time <=' . strtotime($createTimeEnd . ' 23:59:59');
}
$conditions['_string'] = $strCondition;
return M('testing_user', 'tab_')->where($conditions);
}
public function makeTestingUserRecords($testingUsers)
{
$ids = array_column($testingUsers, 'user_id');
if (count($ids) == 0) {
return [];
}
$users = M('user', 'tab_')->field(['id', 'login_time', 'promote_account'])->where(['id' => ['in', $ids]])->select();
$users = index_by_column('id', $users);
$records = [];
foreach ($testingUsers as $testingUser) {
$user = $users[$testingUser['user_id']] ?? null;
$records[] = [
'user_id' => $testingUser['user_id'],
'user_account' => $testingUser['user_account'],
'status_text' => self::$userStatusList[$testingUser['status']] ?? '未知',
'verify_status_text' => self::$userVerifyStatusList[$testingUser['verify_status']] ?? '未知',
'verify_status' => $testingUser['verify_status'],
'status' => $testingUser['status'],
'verify_time' => $testingUser['verify_time'] == 0 ? '' : date('Y-m-d H:i:s', $testingUser['verify_time']),
'create_time' => date('Y-m-d H:i:s', $testingUser['create_time']),
'promote_account' => $user ? $user['promote_account'] : '--',
'login_time' => $user ? date('Y-m-d H:i:s', $user['login_time']) : '--',
];
}
return $records;
}
}

@ -2,7 +2,6 @@
namespace Base\Service;
use Base\Facade\Request;
use Base\Tool\GameCatClient;
class PromoteGradeService
{

@ -2,7 +2,7 @@
namespace Base\Service;
use Base\Facade\Request;
use Base\Tool\GameCatClient;
use Base\Tool\GameResource;
use Base\Repository\TestingResourceRepository;
use Think\Model;
@ -92,21 +92,24 @@ class TestingResourceService
throw new \Exception('该游戏不支持发放测试资源');
}
$role = M('user_play_info', 'tab_')
->field(['id', 'role_id', 'user_id', 'promote_id', 'user_account', 'sdk_version'])
->field(['id', 'role_id', 'user_id', 'promote_id', 'user_account', 'sdk_version', 'server_id'])
->where(['game_id' => $batch['game_id'], 'role_id' => $batch['role_id']])
->find();
$orders = M('testing_resource_order', 'tab_')
->where(['batch_id' => $batch['id']])
->select();
$game = M('game', 'tab_')->field(['id', 'sdk_version'])->where(['id' => $batch['game_id']])->find();
$hasError = false;
$provideAmount = 0;
foreach ($orders as $order) {
$orderData = [];
if ($gameSetting['has_itf'] == 1) {
$result = $this->provideFromGameCat($order, $role);
$gameResource = new GameResource($game);
$result = $gameResource->apply($order, $role);
$orderData = [
'result' => json_encode(['code' => $result['code'], 'message' => $result['message']]),
'result' => json_encode($result),
];
if (!$result['status']) {
$hasError = true;
@ -138,34 +141,6 @@ class TestingResourceService
->save($batchData);
}
public function provideFromGameCat($order, $role)
{
$gameCatClient = new GameCatClient();
$result = $gameCatClient->api('provide', [
'roleId' => $role['role_id'],
'amount' => intval($order['ref_amount']),
'supportItem' => $order['ref_id'],
'supportType' => '0',
'channelUid' => $role['user_account'],
'applyRemark' => $order['remark'] == '' ? '测试资源申请' : $order['remark'],
'applyId' => $order['order_no'],
'device_type' => $role['sdk_version'] == 1 ? 'andriod' : 'ios',
]);
if ($result['state'] == 1 && $result['data']) {
return [
'status' => true,
'message' => $result['msg'],
'code' => 1,
];
} else {
return [
'status' => false,
'msg' => $result['msg'],
'code' => $result['state'],
];
}
}
public function getRemainQuota($role, $bindRole = null, $gameSetting = null)
{
if (is_null($gameSetting)) {
@ -178,8 +153,14 @@ class TestingResourceService
$totalQuota = $role['testing_other_quota'] + ($gameSetting['base_quota'] ?? 0);
if (!is_null($bindRole)) {
$bindTime = $bindRole['binding_time'] ?? 0;
$spendQuota += M('spend', 'tab_')
->where(['game_id' => $role['game_id'], 'game_player_id' => $bindRole['role_id'], 'pay_status' => 1])
->where([
'game_id' => $role['game_id'],
'game_player_id' => $bindRole['role_id'],
'pay_status' => 1,
'pay_time' => ['egt', strtotime(date('Y-m-d 00:00:00', $bindTime))]
])
->group('game_id,game_player_id')
->sum('pay_amount');
$totalQuota += round($gameSetting['rate'] / 100 * $spendQuota, 2);
@ -195,6 +176,15 @@ class TestingResourceService
public function addTestingUsers($accounts, $promote = null)
{
// 测试账号是否自动审核
$isAutoVerify = true;
$verifyStatus = 0;
$verifyTime = 0;
if ($isAutoVerify) {
$verifyStatus = 1;
$verifyTime = time();
}
$accounts = array_unique($accounts);
$existAccounts = M('testing_user', 'tab_')->where(['user_account' => ['in', $accounts]])->getField('user_account', true);
$existAccounts = $existAccounts ?? [];
@ -221,6 +211,8 @@ class TestingResourceService
'user_id' => $user['id'],
'user_account' => $user['account'],
'status' => 1,
'verify_status' => $verifyStatus,
'verify_time' => $verifyTime,
'create_time' => time(),
'update_time' => time(),
];
@ -284,6 +276,14 @@ class TestingResourceService
throw new \Exception('测试账号不存在');
}
if ($testingUser['verify_status'] != 1) {
throw new \Exception('测试账号未审核通过');
}
if (!in_array($testingUser['status'], [1, 2])) {
throw new \Exception('测试账号已禁用');
}
$promoteService = new PromoteService();
$testPromote = M('promote', 'tab_')->field(['id', 'chain'])->where(['id' => $testingRole['promote_id']])->find();
if (is_null($testPromote) || ($promote && !$promoteService->isSubOrSelf($testPromote, $promote))) {
@ -353,12 +353,8 @@ class TestingResourceService
throw new \Exception('权限不足');
}
$resources = [];
if ($gameId == 229) {
$resources = $this->getGameCatResources('android');
} elseif ($gameId == 230) {
$resources = $this->getGameCatResources('ios');
}
$game = M('game', 'tab_')->where(['id' => $gameId])->find();
$resources = $this->getResources($game);
$gameSetting = $this->repository->getGameSettingByGameId($gameId);
if (is_null($gameSetting)) {
@ -378,7 +374,13 @@ class TestingResourceService
if (is_null($testingUser)) {
throw new \Exception('测试账号不存在');
}
if ($testingUser['verify_status'] != 1) {
throw new \Exception('测试账号未审核通过');
}
if (!in_array($testingUser['status'], [1, 2])) {
throw new \Exception('测试账号已禁用');
}
$server = M('server', 'tab_')->field(['id', 'server_name', 'server_id'])->where(['id' => $serverId])->find();
if (is_null($server)) {
throw new \Exception('区服不存在');
@ -421,6 +423,7 @@ class TestingResourceService
if (is_null($bindingRole)) {
throw new \Exception('绑定玩家角色不存在');
}
$bindingRole['binding_time'] = $binding['create_time'];
$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('绑定角色所属推广员异常');
@ -461,11 +464,15 @@ class TestingResourceService
}
}
$remainQuota = $this->getRemainQuota($role, $bindingRole);
$remainQuota = $this->getRemainQuota($role, $bindingRole, $gameSetting);
if ($amount > $remainQuota) {
throw new \Exception('额度不足');
}
$olderBatch = M('testing_resource_batch', 'tab_')
->field(['id'])
->where(['user_id' => $testingUser['user_id'], 'game_id' => $gameId, 'verify_status' => 1])
->find();
$batchNo = date('YmdHis') . substr(md5($roleId . strval(microtime(true)) . rand(0, 9999)), 8, 16);
try {
@ -482,6 +489,7 @@ class TestingResourceService
'apply_amount' => $amount,
'provide_status' => 0,
'verify_status' => 0,
'auto_verify' => $gameSetting['has_itf'] == 1 && $olderBatch ? 1 : 0,
'create_time' => time(),
'update_time' => time(),
];
@ -508,52 +516,24 @@ class TestingResourceService
}
}
public function getResourceTypes($gameId)
{
$resourceTypes = [];
/**
* @todo 目前固定游戏猫
*/
if ($gameId == 229) {
$resourceTypes[] = ['id' => 1, 'name' => '通用'];
} elseif ($gameId == 230) {
$resourceTypes[] = ['id' => 2, 'name' => '通用'];
}
return $resourceTypes;
}
public function getResources($typeId)
public function getResourceTypes($game)
{
$resources = [];
/**
* @todo 目前固定游戏猫资源类型ID
*/
if ($typeId == 2) {
$resources = $this->getGameCatResources('ios');
} elseif ($typeId == 1) {
$resources = $this->getGameCatResources('andriod');
$gameSetting = $this->repository->getGameSettingByGameId($game['id']);
if ($gameSetting['has_itf'] == 0) {
return [];
}
return $resources;
$gameResource = new GameResource($game);
return $gameResource->getResourceTypes();
}
private function getGameCatResources($deviceType)
public function getResources($game, $typeId = null)
{
$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'],
];
}
$gameSetting = $this->repository->getGameSettingByGameId($game['id']);
if ($gameSetting['has_itf'] == 0) {
return [];
}
return $resources;
$gameResource = new GameResource($game);
return $gameResource->getResources($typeId);
}
public function getHasItfGameIds()
@ -575,4 +555,59 @@ class TestingResourceService
return array_merge(array_column($baseGames, 'android_game_id'), array_column($baseGames, 'ios_game_id'));
}
}
public function verifyTestingUser($userIds, $verifyStatus)
{
if (count($userIds) == 0) {
throw new \Exception('请选择要审核的测试账号');
}
if (!in_array($verifyStatus, [1, 2])) {
throw new \Exception('状态值异常');
}
$testingUsers = M('testing_user', 'tab_')->where(['verify_status' => 0, 'user_id' => ['in', $userIds]])->get();
if (count($testingUsers) == 0) {
throw new \Exception('含有非待审核的测试账号');
}
M('testing_user', 'tab_')->where(['user_id' => ['in', $userIds]])->save([
'status' => $verifyStatus
]);
}
public function freezeTestingUser($userId)
{
$testingUser = M('testing_user', 'tab_')->where(['user_id' => $userId])->find();
if (is_null($testingUser)) {
throw new \Exception('测试账号不存在');
}
M('testing_user', 'tab_')->where(['user_id' => $userId])->save([
'status' => 3
]);
}
public function unfreezeTestingUser($userId)
{
$testingUser = M('testing_user', 'tab_')->where(['user_id' => $userId])->find();
if (is_null($testingUser)) {
throw new \Exception('测试账号不存在');
}
M('testing_user', 'tab_')->where(['user_id' => $userId])->save([
'status' => 1
]);
}
public function deleteTestingUser($userId)
{
$testingUser = M('testing_user', 'tab_')->where(['user_id' => $userId])->find();
if (is_null($testingUser)) {
throw new \Exception('测试账号不存在');
}
if ($testingUser['verify_status'] != 2) {
throw new \Exception('只有审核拒绝的测试账号才能删除');
}
M('testing_user', 'tab_')->where(['user_id' => $userId])->delete();
}
}

@ -0,0 +1,63 @@
<?php
namespace Base\Tool;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Base\Tool\GameResource\YzchzbClient;
use Base\Tool\GameResource\LsxxClient;
use Base\Tool\GameResource\JtxcClient;
/**
* 游戏资源接口
*/
class GameResource
{
private $client;
private $game;
private $clientMap = [
191 => JtxcClient::class,
192 => JtxcClient::class,
231 => LsxxClient::class,
232 => LsxxClient::class,
229 => YzchzbClient::class,
230 => YzchzbClient::class,
];
public function __construct($game)
{
$this->game = $game;
$this->client = $this->createClient();
}
private function createClient()
{
$clientClass = '';
$gameId = intval($this->game['id']);
if (isset($this->clientMap[$gameId])) {
$clientClass = $this->clientMap[$gameId];
} else {
throw new \Exception('游戏资源客户端未配置');
}
return new $clientClass();
}
public function getResourceTypes()
{
$deviceType = $this->game['sdk_version'] == 1 ? 'andriod' : 'ios';
return $this->client->getResourceTypes($deviceType);
}
public function getResources($typeId = null)
{
$deviceType = $this->game['sdk_version'] == 1 ? 'andriod' : 'ios';
return $this->client->getResources($typeId, $deviceType);
}
public function apply($order, $role)
{
return $this->client->apply($order, $role);
}
}

@ -0,0 +1,155 @@
<?php
namespace Base\Tool\GameResource;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
/**
* 九天仙尘-测试资源接口
*/
class JtxcClient
{
const SIGN_NAME = 'sign';
const SUCCESS = '0000';
const KEY = '6c9VLnZFlhEppATKKWeH5vV900K6Nhy5';
protected $client;
// http://chat.leniu.com/api/game/sendGold/zhuimeng/jxlm/57972
private $apis = [
'provide' => ['uri' => '/api/game/sendGold/zhuimeng/jxlm/57972', 'method' => 'post'],
];
public function __construct()
{
$this->client = new Client([
'base_uri' => 'http://chat.leniu.com',
'timeout' => 10.0,
]);
}
public function api($api, array $params = [])
{
$api = $this->apis[$api] ?? null;
if (is_null($api)) {
throw new \Exception('接口不存在');
}
$params[self::SIGN_NAME] = $this->sign($params);
try {
return $this->request($api, $params);
} catch (\Exception $e) {
$env = C('APP_ENV', null, 'prod');
return $e->getMessage();
}
}
public function request($api, $params)
{
if ($api['method'] == 'get') {
return $this->get($api['uri'], $params);
} else {
return $this->post($api['uri'], $params);
}
}
protected function post($uri, array $params = [])
{
$response = $this->client->post($uri, [
'verify' => false,
'form_params' => $params,
]);
return (string)$response->getBody();
}
protected function get($uri, array $params = [])
{
$response = $this->client->get($uri, [
'verify' => false,
'query' => $params,
]);
return (string)$response->getBody();
}
protected function sign($params)
{
unset($params[self::SIGN_NAME]);
ksort($params);
$signRows = [];
foreach ($params as $key => $value) {
$signRows[] = $key . '=' . $value;
}
return md5(implode('&', $signRows) . self::KEY);
}
public function apply($order, $role)
{
$result = $this->api('provide', [
'role_id' => $role['role_id'],
'money' => intval($order['ref_amount']) * 10,
'type' => 2,
// 'goods_id' => 0,
'server_no' => $role['server_id'],
]);
if ($result == 'SUCCESS') {
return [
'status' => true,
'message' => $result,
'result' => ['result' => $result]
];
} else {
return [
'status' => false,
'message' => $result,
'result' => ['result' => $result]
];
}
}
public function getResourceTypes($deviceType)
{
if ($deviceType == 'andriod') {
return [['id' => 1, 'name' => '通用', 'device_type' => 'andriod']];
} elseif ($deviceType == 'ios') {
return [['id' => 2, 'name' => '通用', 'device_type' => 'ios']];
}
}
public function getResources($typeId, $deviceType)
{
return [
1 => ['ref_id' => 1, 'name' => '60元宝', 'amount' => 6],
2 => ['ref_id' => 2, 'name' => '300元宝', 'amount' => 30],
3 => ['ref_id' => 3, 'name' => '980元宝', 'amount' => 98],
4 => ['ref_id' => 4, 'name' => '1280元宝', 'amount' => 128],
5 => ['ref_id' => 5, 'name' => '1980元宝', 'amount' => 198],
6 => ['ref_id' => 6, 'name' => '3280元宝', 'amount' => 328],
7 => ['ref_id' => 7, 'name' => '6480元宝', 'amount' => 648],
8 => ['ref_id' => 8, 'name' => '10000元宝', 'amount' => 1000],
9 => ['ref_id' => 9, 'name' => '20000元宝', 'amount' => 2000],
10 => ['ref_id' => 10, 'name' => '30000元宝', 'amount' => 3000],
11 => ['ref_id' => 11, 'name' => '50000元宝', 'amount' => 5000],
12 => ['ref_id' => 12, 'name' => '100000元宝', 'amount' => 10000],
13 => ['ref_id' => 13, 'name' => '200000元宝', 'amount' => 20000],
14 => ['ref_id' => 14, 'name' => '680元宝', 'amount' => 68],
];
/* return [
['ref_id' => 121209, 'name' => '6元充值卡', 'amount' => 6],
['ref_id' => 121210, 'name' => '30元充值卡', 'amount' => 30],
['ref_id' => 121211, 'name' => '98元充值卡', 'amount' => 98],
['ref_id' => 121212, 'name' => '128元充值卡', 'amount' => 128],
['ref_id' => 121213, 'name' => '198元充值卡', 'amount' => 198],
['ref_id' => 121214, 'name' => '328元充值卡', 'amount' => 328],
['ref_id' => 121215, 'name' => '648元充值卡', 'amount' => 648],
['ref_id' => 121216, 'name' => '1000元充值卡', 'amount' => 1000],
['ref_id' => 121217, 'name' => '2000元充值卡', 'amount' => 2000],
['ref_id' => 121218, 'name' => '3000元充值卡', 'amount' => 3000],
['ref_id' => 121219, 'name' => '5000元充值卡', 'amount' => 5000],
['ref_id' => 121220, 'name' => '10000元充值卡', 'amount' => 10000],
['ref_id' => 121221, 'name' => '20000元充值卡', 'amount' => 20000],
['ref_id' => 121222, 'name' => '68元充值卡', 'amount' => 68],
]; */
}
}

@ -0,0 +1,134 @@
<?php
namespace Base\Tool\GameResource;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
/**
* 乱世枭雄-测试资源接口
*/
class LsxxClient
{
const SIGN_NAME = 'sign';
const KEY = 'vtc5f7q9zp8ztsbf';
protected $client;
private $apis = [
'get-pay-type' => ['uri' => '/wanmeng/prop.php', 'method' => 'get'],
'provide' => ['uri' => '/wanmeng/prop.php?action=prop', 'method' => 'post'],
];
public function __construct()
{
$this->client = new Client([
'base_uri' => 'http://47.114.91.166:1096',
'timeout' => 10.0,
]);
}
public function api($api, array $params = [])
{
$api = $this->apis[$api] ?? null;
if (is_null($api)) {
throw new \Exception('接口不存在');
}
$params[self::SIGN_NAME] = $this->sign($params);
try {
return $this->request($api, $params);
} catch (\Exception $e) {
$env = C('APP_ENV', null, 'prod');
return ['status' => 0, 'msg' => '接口请求错误。' . ($env == 'prod' ? '' : $e->getMessage()) , 'data' => []];
}
}
public function request($api, $params)
{
if ($api['method'] == 'get') {
return $this->get($api['uri'], $params);
} else {
return $this->post($api['uri'], $params);
}
}
protected function post($uri, array $params = [])
{
$response = $this->client->post($uri, [
'verify' => false,
'form_params' => $params,
]);
$result = (string)$response->getBody();
return json_decode($result, true);
}
protected function get($uri, array $params = [])
{
$response = $this->client->get($uri, [
'verify' => false,
'query' => $params,
]);
$result = (string)$response->getBody();
return json_decode($result, true);
}
protected function sign($params)
{
unset($params[self::SIGN_NAME]);
ksort($params);
$signRows = [];
foreach ($params as $key => $value) {
$signRows[] = $key . '=' . $value;
}
return md5(implode('&', $signRows) . self::KEY);
}
public function apply($order, $role)
{
$result = $this->api('provide', [
'role_id' => $role['role_id'],
'goods_id' => $order['ref_id'],
'server_no' => $role['server_id'],
'send_time' => time()
]);
if ($result['status'] == 1) {
return [
'status' => true,
'message' => $result['msg'],
'result' => $result
];
} else {
return [
'status' => false,
'message' => $result['msg'],
'result' => $result ?? []
];
}
}
public function getResourceTypes($deviceType)
{
if ($deviceType == 'andriod') {
return [['id' => 1, 'name' => '通用', 'device_type' => 'andriod']];
} elseif ($deviceType == 'ios') {
return [['id' => 2, 'name' => '通用', 'device_type' => 'ios']];
}
}
public function getResources($typeId, $deviceType)
{
$resources = [];
$result = $this->api('get-pay-type', ['action' => 'getItems']);
if ($result['status'] == 1) {
$items = $result['data'];
foreach ($items as $item) {
$resources[$item['id']] = [
'ref_id' => $item['id'],
'name' => $item['name'],
'amount' => $item['money'],
];
}
}
return $resources;
}
}

@ -1,14 +1,14 @@
<?php
namespace Base\Tool;
namespace Base\Tool\GameResource;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
/**
* 游戏猫接口客户端
* 远征手游之楚汉争霸-测试资源接口
*/
class GameCatClient
class YzchzbClient
{
const SIGN_NAME = 'sign';
const SUCCESS = '0000';
@ -77,9 +77,6 @@ class GameCatClient
'form_params' => $params,
]);
$result = (string)$response->getBody();
/* var_dump($uri);
var_dump($params);
var_dump($result); */
return json_decode($result, true);
}
@ -105,4 +102,57 @@ class GameCatClient
// var_dump(implode('&', $signRows));
return md5(implode('&', $signRows));
}
public function apply($order, $role)
{
$result = $this->api('provide', [
'roleId' => $role['role_id'],
'amount' => intval($order['ref_amount']),
'supportItem' => $order['ref_id'],
'supportType' => '0',
'channelUid' => $role['user_account'],
'applyRemark' => $order['remark'] == '' ? '测试资源申请' : $order['remark'],
'applyId' => $order['order_no'],
'device_type' => $role['sdk_version'] == 1 ? 'andriod' : 'ios',
]);
if ($result['state'] == 1 && $result['data']) {
return [
'status' => true,
'message' => $result['msg'],
'result' => $result
];
} else {
return [
'status' => false,
'message' => $result['msg'],
'result' => $result ?? []
];
}
}
public function getResourceTypes($deviceType)
{
if ($deviceType == 'andriod') {
return [['id' => 1, 'name' => '通用', 'device_type' => 'andriod']];
} elseif ($deviceType == 'ios') {
return [['id' => 2, 'name' => '通用', 'device_type' => 'ios']];
}
}
public function getResources($typeId, $deviceType)
{
$resources = [];
$result = $this->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;
}
}

@ -0,0 +1,41 @@
<?php
namespace Base\Tool;
class IPTool
{
public static function getIpInfo($ip)
{
$host = 'https://api01.aliyun.venuscn.com';
$path = '/ip';
$method = 'GET';
$appcode = '244181f0846541a19e24df409736d3b9';
$headers = [];
array_push($headers, 'Authorization:APPCODE ' . $appcode);
$querys = 'ip=' . $ip;
$bodys = '';
$url = $host . $path . '?' . $querys;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($curl, CURLOPT_HEADER, true);
if (1 == strpos('$'.$host, 'https://')) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
$response = curl_exec($curl);
if (!$response) {
return null;
}
$result = json_decode($response, true);
if ($result['ret'] == 200) {
return $result['data'];
} else {
return null;
}
}
}

@ -6,7 +6,6 @@ namespace Home\Controller;
use Base\Model\PromoteModel;
use Base\Service\PromoteService;
use OSS\Core\OssException;
use Base\Tool\GameCatClient;
use Think\Model;
use Base\Service\TestingResourceService;
use Base\Repository\TestingResourceRepository;
@ -21,10 +20,10 @@ class TestingResourceController extends BaseController
$loginPromote = $this->getLoginPromote();
$repository = new TestingResourceRepository();
$query = $repository->getTestingUsersQuery($params, $loginPromote);
$query = $repository->getTestingRolesQuery($params, $loginPromote);
[$roles, $pagination, $count] = $this->paginate($query);
$records = $repository->makeTestingUserRecords($roles);
$records = $repository->makeTestingRoleRecords($roles);
$gameRepository = new GameRepository();
@ -35,7 +34,7 @@ class TestingResourceController extends BaseController
$this->assign('records', $records);
$this->display();
}
public function addTestingUsers()
{
$loginPromote = $this->getLoginPromote();
@ -143,6 +142,9 @@ class TestingResourceController extends BaseController
->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();
if ($bindingRole) {
$bindingRole['binding_time'] = $binding['create_time'];
}
}
$repository = new TestingResourceRepository();
@ -202,17 +204,28 @@ class TestingResourceController extends BaseController
public function getResourceTypes()
{
$gameId = I('game_id', 0);
$testingResourceService = new TestingResourceService();
$resourceTypes = $testingResourceService->getResourceTypes($gameId);
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resourceTypes' => $resourceTypes]]);
$game = M('game', 'tab_')->field(['id', 'sdk_version'])->where(['id' => $gameId])->find();
try {
$testingResourceService = new TestingResourceService();
$resourceTypes = $testingResourceService->getResourceTypes($game);
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resourceTypes' => $resourceTypes]]);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage(), 'data' => ['resourceTypes' => []]]);
}
}
public function getResources()
{
$typeId = I('type_id', 0);
$testingResourceService = new TestingResourceService();
$resources = $testingResourceService->getResources($typeId);
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resources' => $resources]]);
$gameId = I('game_id', 0);
$game = M('game', 'tab_')->field(['id', 'sdk_version'])->where(['id' => $gameId])->find();
try {
$testingResourceService = new TestingResourceService();
$resources = $testingResourceService->getResources($game, $typeId);
return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resources' => $resources]]);
} catch (\Throwable $e) {
return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage(), 'data' => ['resources' => []]]);
}
}
public function getUserRoles()

@ -76,10 +76,11 @@
background: #E5E5E5;
color: #535875;
border: none;
border-radius: 4px;
border-radius: 3px;
cursor: pointer;
display: inline-block;
margin-left: 10px;
padding: 0px 10px;
}
.info-row button.bind-btn {
background: #409eff;
@ -318,7 +319,7 @@
$.ajax({
url: "{:U('getResources')}",
type: "post",
data: { type_id: typeId },
data: { game_id: globalGameId, type_id: typeId },
dataType: 'json',
success: function(result){
if (result.status == 1) {

@ -2706,4 +2706,11 @@ CREATE TABLE `tab_testing_game_setting` (
ALTER TABLE `tab_promote_grade_setting`
ADD COLUMN `base_game_id` int(11) not NULL DEFAULT 0 COMMENT '游戏ID' AFTER `name`,
ADD COLUMN `month_begin` int(11) not NULL DEFAULT 0 COMMENT '规则截止月份' AFTER `base_game_id`,
ADD COLUMN `month_end` int(11) not NULL DEFAULT 0 COMMENT '规则开始月份' AFTER `month_begin`;
ADD COLUMN `month_end` int(11) not NULL DEFAULT 0 COMMENT '规则开始月份' AFTER `month_begin`;
ALTER TABLE `tab_testing_user`
ADD COLUMN `verify_status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '审核状态' AFTER `status`;
ALTER TABLE `tab_testing_user`
ADD COLUMN `verify_time` int(11) NOT NULL DEFAULT 0 COMMENT '审核时间' AFTER `verify_status`;
ALTER TABLE `tab_testing_resource_batch`
ADD COLUMN `auto_verify` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否需要审核' AFTER `verify_status`;
Loading…
Cancel
Save