From c5fe80639ffdb4303caac13146a6cc445704dad3 Mon Sep 17 00:00:00 2001 From: ELF <360197197@qq.com> Date: Thu, 15 Oct 2020 19:59:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestingResourceController.class.php | 277 +++++++++++++++++- .../Admin/View/TestingResource/apply.html | 13 +- .../Admin/View/TestingResource/batches.html | 207 ++++++++++++- .../View/TestingResource/gameSettings.html | 2 +- .../Admin/View/TestingResource/index.html | 104 ++++++- .../Admin/View/TestingResource/orders.html | 9 + .../Base/Repository/GameRepository.class.php | 13 +- .../TestingResourceRepository.class.php | 21 +- .../Service/TestingResourceService.class.php | 131 +++++++-- .../TestingResourceController.class.php | 74 ++--- .../View/default/TestingResource/apply.html | 13 +- 11 files changed, 745 insertions(+), 119 deletions(-) diff --git a/Application/Admin/Controller/TestingResourceController.class.php b/Application/Admin/Controller/TestingResourceController.class.php index 3700b87a9..2ea0652f2 100644 --- a/Application/Admin/Controller/TestingResourceController.class.php +++ b/Application/Admin/Controller/TestingResourceController.class.php @@ -15,6 +15,8 @@ class TestingResourceController extends ThinkController public function index() { $params = I('get.'); + $gameId = $params['game_id'] ?? 0; + $repository = new TestingResourceRepository(); $query = $repository->getTestingUsersQuery($params); @@ -81,11 +83,44 @@ class TestingResourceController extends ThinkController $baseGames[$key] = $baseGame; } + $spendList = []; + $provideItems = []; + if (count($items) > 0) { + $pageGameIds = array_merge(array_column($baseGames, 'android_game_id'), array_column($baseGames, 'ios_game_id')); + /* $spendCondition = [ + 'pay_status' => 1, + 'game_id' => ['in', $pageGameIds] + ]; + $spendList = M('spend', 'tab_')->field('sum(pay_amount) amount, game_id')->where($spendCondition)->group('game_id')->select(); + $spendList = index_by_column('game_id', $spendList); */ + + $provideItems = M('testing_resource_batch', 'tab_') + ->field('sum(provide_amount) amount, game_id') + ->where([ + 'verify_status' => 1, + 'game_id' => ['in', $pageGameIds] + ]) + ->group('game_id') + ->select(); + $provideItems = index_by_column('game_id', $provideItems); + } + $records = []; foreach ($items as $item) { $baseGame = $baseGames[$item['base_game_id']] ?? null; $partnerId = $baseGame ? $baseGame['partner_id'] : 0; $partner = $partners[$partnerId] ?? null; + + /* $aSpendItem = $spendList[$baseGame['android_game_id']] ?? null; + $bSpendItem = $spendList[$baseGame['ios_game_id']] ?? null; + $aSpendQuota = $aSpendItem ? $aSpendItem['amount'] : 0; + $bSpendQuota = $bSpendItem ? $bSpendItem['amount'] : 0; */ + + $aProvideItem = $provideItems[$baseGame['ios_game_id']] ?? null; + $bProvideItem = $provideItems[$baseGame['android_game_id']] ?? null; + $aProvideQuota = $aProvideItem ? $aProvideItem['amount'] : 0; + $bProvideQuota = $bProvideItem ? $bProvideItem['amount'] : 0; + $records[] = [ 'id' => $item['id'], 'base_game_id' => $item['base_game_id'], @@ -93,6 +128,8 @@ class TestingResourceController extends ThinkController 'partner_name' => $partner ? $partner['partner'] : '--', 'rate' => $item['rate'], 'base_quota' => $item['base_quota'], + // 'quota' => round(($aSpendQuota + $bSpendQuota) * $item['rate'] / 100, 2), + 'provide_quota' => $aProvideQuota + $bProvideQuota ]; } @@ -139,15 +176,41 @@ class TestingResourceController extends ThinkController public function batches() { $params = I('get.'); - + $isExport = $params['export'] ?? 0; + $repository = new TestingResourceRepository(); $query = $repository->getBatchesQuery($params); + + if ($isExport == 1) { + $batches = $query->select(); + $records = $repository->makeBatchesRecords($batches); + data2csv($records, '申请批次列表', [ + 'batch_no' => '批次号', + 'create_time' => '申请时间', + 'game_name' => '游戏名称', + 'server_name' => '区服名称', + 'role_name' => '角色名称', + 'user_account' => '测试账号', + 'user_phone' => '手机号', + 'promote_account' => '所属推广员', + 'apply_promote_account' => '申请人', + 'apply_amount' => '申请金额', + 'provide_amount' => '发放金额', + 'verify_status_text' => '审核状态', + 'verify_time' => '审核时间', + 'provide_status_text' => '发放状态', + 'provide_time' => '发放时间' + ]); + } + list($batches, $pagination, $count) = $this->paginate($query); $records = $repository->makeBatchesRecords($batches); $gameRepository = new GameRepository(); + $gameId = $params['game_id'] ?? 0; + $this->assign('verifyStatusList', TestingResourceRepository::$verifyStatusList); $this->assign('provideStatusList', TestingResourceRepository::$provideStatusList); $this->assign('servers', $gameRepository->getServersByGameId($gameId)); @@ -235,13 +298,12 @@ class TestingResourceController extends ThinkController $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(); + $games = M('game', 'tab_')->field(['id' , 'game_name'])->select(); + $this->assign('hasItf', $hasItf); $this->assign('games', $games); $this->assign('servers', $servers); @@ -266,10 +328,207 @@ class TestingResourceController extends ThinkController 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); + $status = I('status', 0); + if (count($ids) == 0) { + return $this->ajaxReturn(['status' => 0, 'message' => '请选择要审核的批次']); + } + if (!in_array($status, [1, 2])) { + return $this->ajaxReturn(['status' => 0, 'message' => '请求状态异常']); + } + try { + $service = new TestingResourceService(); + $batches = M('testing_resource_batch', 'tab_')->where(['verify_status' => 0, 'id' => ['in', $ids]])->select(); + if (count($batches) == 0) { + return $this->ajaxReturn(['status' => 0, 'message' => '无未审核批次']); + } + foreach ($batches as $batch) { + if ($status == 1) { + $service->verify($batch); + } elseif ($status == 2) { + $service->verifyRefuse($batch); + } + } + return $this->ajaxReturn(['status' => 1, 'message' => '操作成功']); + } catch (\Throwable $e) { + return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]); + } + } + + public function provide() + { + $ids = I('ids', []); + $status = I('status', 0); + if (count($ids) == 0) { + return $this->ajaxReturn(['status' => 0, 'message' => '请选择要审核的批次']); + } + if (!in_array($status, [1, 2])) { + return $this->ajaxReturn(['status' => 0, 'message' => '请求状态异常']); + } + try { + $service = new TestingResourceService(); + $batches = M('testing_resource_batch', 'tab_')->where(['verify_status' => 1, 'provide_status' => 0, 'id' => ['in', $ids]])->select(); + if (count($batches) == 0) { + return $this->ajaxReturn(['status' => 0, 'message' => '无符合条件的批次']); + } + foreach ($batches as $batch) { + if ($status == 1) { + $service->provide($batch); + } elseif ($status == 2) { + $service->provideRefuse($batch); + } + } + return $this->ajaxReturn(['status' => 1, 'message' => '操作成功']); + } catch (\Throwable $e) { + return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]); + } + } + + public function bindRole() + { + $params = I('post.'); + try { + $testingResourceService = new TestingResourceService(); + $testingResourceService->bindRole($params); + return $this->ajaxReturn(['status' => 1, 'message' => '绑定成功']); + } catch (\Throwable $th) { + return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]); + } + } + + public function unbindRole() + { + $bindingId = I('binding_id', 0); + try { + $testingResourceService = new TestingResourceService(); + $testingResourceService->unbindRole($bindingId); + return $this->ajaxReturn(['status' => 1, 'message' => '解绑成功']); + } catch (\Throwable $th) { + return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]); + } + } + + public function setOtherQuota() + { + $id = I('id', 0); + $otherQuota = I('other_quota', 0); + M('user_play_info', 'tab_')->where(['id' => $id])->save(['testing_other_quota' => $otherQuota]); + return $this->ajaxReturn(['status' => 1, 'message' => '设置成功']); + } + + public function getUserRoles() + { + $gameId = I('game_id', 0); + $serverId = I('server_id', 0); + $userAccount = I('user_account', ''); + $server = M('server', 'tab_')->field(['id', 'server_name', 'server_id'])->where(['id' => $serverId])->find(); + if (is_null($server)) { + return $this->ajaxReturn(['status' => 0, 'message' => '区服不存在']); + } + + $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_account' => $userAccount])->find(); + $isTestingAccount = is_null($testingUser) ? false : true; + + $roles = M('user_play_info', 'tab_') + ->field(['id', 'role_id', 'role_name']) + ->where(['user_account' => $userAccount, 'game_id' => $gameId, 'server_id' => $server['server_id']]) + ->select(); + return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['roles' => $roles, 'is_testing_account' => $isTestingAccount]]); + } + + public function getResourceTypes() + { + $gameId = I('game_id', 0); + $testingResourceService = new TestingResourceService(); + $resourceTypes = $testingResourceService->getResourceTypes($gameId); + return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resourceTypes' => $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]]); + } + + public function exportOrders() + { + $params = I('get.'); + $repository = new TestingResourceRepository(); + $batches = $repository->getBatchesQuery($params)->select(); + $batches = index_by_column('id', $batches); + + $records = []; + if (count($batches)) { + $gameRoleIds = []; + foreach ($batches as $batch) { + $gameRoleIds[] = $repository->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', 'promote_id']) + ->where(['game_role_id' => ['in', $gameRoleIds]]) + ->select(); + $roles = index_by_column('game_role_id', $roles); + + $applyPromotes = M('promote', 'tab_')->field(['id', 'account'])->where(['id' => ['in', array_column($batches, 'apply_promote_id')]])->select(); + $applyPromotes = index_by_column('id', $applyPromotes); + + $promotes = []; + if (count($roles) > 0) { + $promotes = M('promote', 'tab_')->field(['id', 'account'])->where(['id' => ['in', array_column($roles, 'promote_id')]])->select(); + $promotes = index_by_column('id', $promotes); + } + + $orders = M('testing_resource_order', 'tab_')->where(['batch_id' => ['in', array_column($batches, 'id')]])->order('batch_id desc')->select(); + + foreach ($orders as $order) { + + $batch = $batches[$order['batch_id']]; + $roleKey = $repository->getGameRoleId($batch['game_id'], $batch['role_id']); + $role = isset($roles[$roleKey]) ? $roles[$roleKey] : null; + $applyPromote = $applyPromotes[$batch['apply_promote_id']] ?? null; + $promote = $role ? ($promotes[$role['promote_id']] ?? null) : null; + $records[] = [ + 'id' => $order['id'], + 'batch_no' => substr($batch['batch_no'], 14), + 'create_time' => $batch['create_time'] == 0 ? '--' : date('Y-m-d H:i:s', $batch['create_time']), + 'game_name' => $role ? $role['game_name'] : '', + 'user_account' => $role ? $role['user_account'] : '', + 'server_name' => $role ? $role['server_name'] : '', + 'role_name' => $role ? $role['role_name'] : '', + 'apply_promote_account' => $applyPromote ? $applyPromote['account'] : '', + 'promote_account' => $promote ? $promote['account'] : '', + 'ref_name' => $order['ref_name'], + 'ref_amount' => $order['ref_amount'], + 'num' => $order['num'], + 'amount' => $order['num'] * $order['ref_amount'], + 'remark' => $order['remark'], + 'verify_status_text' => $repository->getVerifyStatusText($batch['verify_status']), + 'provide_status_text' => $repository->getProvideStatusText($order['provide_status']), + ]; + } } + data2csv($records, '批次订单列表', [ + 'batch_no' => '批次号', + 'create_time' => '申请时间', + 'game_name' => '游戏名称', + 'server_name' => '区服名称', + 'user_account' => '测试账号', + 'role_name' => '角色名称', + 'apply_promote_account' => '申请人', + 'promote_account' => '所属推广员', + 'ref_name' => '资源名称', + 'ref_amount' => '资源价值', + 'num' => '申请数量', + 'amount' => '申请金额', + 'remark' => '申请备注', + 'verify_status_text' => '审核状态', + 'provide_status_text' => '发放状态' + ]); } } \ No newline at end of file diff --git a/Application/Admin/View/TestingResource/apply.html b/Application/Admin/View/TestingResource/apply.html index 6bab7378c..494a731b6 100644 --- a/Application/Admin/View/TestingResource/apply.html +++ b/Application/Admin/View/TestingResource/apply.html @@ -94,7 +94,7 @@ body { margin-top: 10px; } .info-row button { - width: 120px; + width: auto; height: 25px; display: block; background: #E5E5E5; @@ -284,6 +284,7 @@ body { -
+
- + + + + + +
+
+ +
+
+ +
+
+ + - +
+ + +
+
+
+
- + + $name):?> +
- +
+ +
@@ -133,7 +198,7 @@ - + {$record.batch_no} @@ -178,10 +243,10 @@
- + 导出 - + {$_page|default=''}
@@ -297,6 +362,116 @@ }) return ids; } + $("#game_id").change(function () { + $.ajax({ + url: "{:U('getServers')}", + type: "post", + data: { game_id: $("#game_id option:selected").attr('game-id') }, + dataType: 'json', + success: function (result ) { + if (result.status == 1) { + var servers = result.data.servers + var str = "" + for (var i in servers){ + str += "" + } + $("#server_id").empty() + $("#server_id").append(str) + $("#server_id").select2() + } + } + }) + }) + $('#verify-agree-btn').on({ + click:function () { + var ids = getIds() + if (ids.length == 0) { + return layer.msg('请选择要操作的批次') + } + layer.confirm('确定要审核通过这些批次吗?', { + title: '审核通过', + btn: ['确定'] + }, function(){ + verify(ids, 1) + }) + } + }) + $('#verify-refuse-btn').on({ + click:function () { + var ids = getIds() + if (ids.length == 0) { + return layer.msg('请选择要操作的批次') + } + layer.confirm('确定要审核拒绝这些批次吗?', { + title: '审核拒绝', + btn: ['确定'] + }, function(){ + verify(ids, 2) + }) + } + }) + $('#provide-agree-btn').on({ + click:function () { + var ids = getIds() + if (ids.length == 0) { + return layer.msg('请选择要操作的批次') + } + layer.confirm('确定将这些批次设为已发放吗?', { + title: '设为已发放', + btn: ['确定'] + }, function(){ + provide(ids, 1) + }) + } + }) + $('#provide-refuse-btn').on({ + click:function () { + var ids = getIds() + if (ids.length == 0) { + return layer.msg('请选择要操作的批次') + } + layer.confirm('确定将这些批次设为发放失败吗?', { + title: '设为发放失败', + btn: ['确定'] + }, function(){ + provide(ids, 2) + }) + } + }) + function verify(ids, status) { + $.ajax({ + url: "{:U('verify')}", + type: "post", + data: { ids: ids, status: status }, + dataType: 'json', + success: function (result ) { + if (result.status == 1) { + layer.msg(result.message, function(){ + window.location.href = window.location.href + }) + } else { + layer.msg(result.message) + } + } + }) + } + function provide(ids, status) { + $.ajax({ + url: "{:U('provide')}", + type: "post", + data: { ids: ids, status: status }, + dataType: 'json', + success: function (result ) { + if (result.status == 1) { + layer.msg(result.message, function(){ + window.location.href = window.location.href + }) + } else { + layer.msg(result.message) + } + } + }) + } }); \ No newline at end of file diff --git a/Application/Admin/View/TestingResource/gameSettings.html b/Application/Admin/View/TestingResource/gameSettings.html index 522fe3d78..8c8be4fac 100644 --- a/Application/Admin/View/TestingResource/gameSettings.html +++ b/Application/Admin/View/TestingResource/gameSettings.html @@ -122,7 +122,7 @@ {$data.partner_name} {$data.base_quota} {$data.rate}% - + {$data.provide_quota}
编辑 diff --git a/Application/Admin/View/TestingResource/index.html b/Application/Admin/View/TestingResource/index.html index fa9698c39..0bbec962d 100644 --- a/Application/Admin/View/TestingResource/index.html +++ b/Application/Admin/View/TestingResource/index.html @@ -61,7 +61,7 @@
@@ -104,11 +104,11 @@
- -
-
@@ -145,6 +145,7 @@ 申请总金额 状态 创建时间 + 操作 @@ -154,7 +155,7 @@ aOh! 暂时还没有内容! - + @@ -164,7 +165,9 @@ {$record.user_phone} {$record.role_name} {$record.bind_user_account} - {$record.bind_role_name} + + {$record.bind_role_name} + {$record.base_quota} {$record.other_quota} {$record.quota} @@ -178,6 +181,12 @@
+ + 设置额外额度 + 0):?> + 解绑角色 + +
@@ -216,6 +225,21 @@
+ @@ -282,7 +306,73 @@ area: ['700px', '380px'], zIndex: 250, }) - }); + }) + $('.set-quota-btn').click(function () { + var box = $('#other-quota-box') + var tr = $(this).parents('tr').eq(0) + var id = tr.attr('data-id') + var otherQuota = tr.attr('data-other-quota') + box.find('[name=id]').val(id) + box.find('[name=other_quota]').val(otherQuota) + layer.open({ + title: '设置额外额度', + type: 1, + content: box, + area: ['500px', '200px'], + zIndex: 250, + }) + }) + $('#quota-submit').on({ + click: function() { + var box = $('#other-quota-box') + var id = box.find('[name=id]').val() + var otherQuota = box.find('[name=other_quota]').val() + $.ajax({ + url: "{:U('setOtherQuota')}", + type: "POST", + dataType: "json", + data: { id: id, other_quota: otherQuota }, + success: function (result) { + if (result.status == 0) { + layer.msg(result.message); + } else { + layer.msg(result.message, function(){ + window.location.href = window.location.href + }) + } + }, + error: function () { + + } + }) + } + }) + $('.unbind-btn').click(function () { + var tr = $(this).parents('tr').eq(0) + var bindingId = tr.attr('data-binding-id') + layer.confirm('确定要解绑吗?', { + // closeBtn:0, + title: '解绑', + btn: ['确定'] //按钮 + }, function(){ + $.ajax({ + async: false, + url: "{:U('unbindRole')}", + type: "POST", + dataType: "json", + data: { binding_id: bindingId }, + 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') @@ -309,7 +399,7 @@ error: function () { } - }); + }) } }) diff --git a/Application/Admin/View/TestingResource/orders.html b/Application/Admin/View/TestingResource/orders.html index a93b3f7bf..7a953cc23 100644 --- a/Application/Admin/View/TestingResource/orders.html +++ b/Application/Admin/View/TestingResource/orders.html @@ -20,6 +20,15 @@ html { body { padding: 0px; } +.data_list table td .status-0 { + color: #e6a23c; +} +.data_list table td .status-1 { + color: #67c23a; +} +.data_list table td .status-2 { + color: #f56c6c; +}
diff --git a/Application/Base/Repository/GameRepository.class.php b/Application/Base/Repository/GameRepository.class.php index 556369742..25e3d44e0 100644 --- a/Application/Base/Repository/GameRepository.class.php +++ b/Application/Base/Repository/GameRepository.class.php @@ -16,9 +16,17 @@ class GameRepository return $baseGames; } - public function getBaseGameByGameId($gameId) + public function getBaseGameByGameId($gameId, array $baseGames = null) { - return M('base_game', 'tab_')->where('android_game_id=' . $gameId . ' or ios_game_id=' . $gameId)->find(); + if (is_null($baseGames)) { + return M('base_game', 'tab_')->where('android_game_id=' . $gameId . ' or ios_game_id=' . $gameId)->find(); + } + foreach ($baseGames as $baseGame) { + if ($baseGame['android_game_id'] == $gameId || $baseGame['ios_game_id'] == $gameId) { + return $baseGame; + } + } + return null; } public function getChoiceGames(array $visibleGameIds = null, $fields = ['id', 'game_name']) @@ -40,6 +48,7 @@ class GameRepository $map = []; $map['game_id'] = $gameId; return M('server', 'tab_') + ->field($fields) ->where($map) ->order('server_id asc') ->select(); diff --git a/Application/Base/Repository/TestingResourceRepository.class.php b/Application/Base/Repository/TestingResourceRepository.class.php index da3633a63..83fec07df 100644 --- a/Application/Base/Repository/TestingResourceRepository.class.php +++ b/Application/Base/Repository/TestingResourceRepository.class.php @@ -290,6 +290,7 @@ class TestingResourceRepository $spendItems[$this->getGameRoleId($item['game_id'], $item['game_player_id'])] = $item['amount']; } } + $gameSettings = $this->getGameSettings(); return [ 'users' => $users, 'spendItems' => $spendItems, @@ -299,6 +300,7 @@ class TestingResourceRepository 'provideRecords' => $provideRecords, 'verifyRecords' => $verifyRecords, 'todayProvideRecords' => $todayProvideRecords, + 'gameSettings' => $gameSettings, ]; } @@ -307,6 +309,7 @@ class TestingResourceRepository $result = $this->statByRoles($roles); $users = $result['users']; $spendItems = $result['spendItems']; + $gameSettings = $result['gameSettings']; $bindings = $result['bindings']; $bindingRoles = $result['bindingRoles']; $applyRecords = $result['applyRecords']; @@ -314,6 +317,10 @@ class TestingResourceRepository $verifyRecords = $result['verifyRecords']; $todayProvideRecords = $result['todayProvideRecords']; + $gameSettings = index_by_column('base_game_id', $gameSettings); + $gameRepository = new GameRepository(); + $baseGames = $gameRepository->getBaseGames(); + $records = []; foreach ($roles as $role) { $user = $users[$role['user_id']] ?? null; @@ -323,7 +330,15 @@ class TestingResourceRepository $bindGameRoleId = $this->getGameRoleId($binding['game_id'], $binding['bind_role_id']); $bindingRole = $bindingRoles[$bindGameRoleId] ? $bindingRoles[$bindGameRoleId] : null; } - $gameSetting = $this->getGameSettingByGameId($role['game_id']); + $baseGame = $gameRepository->getBaseGameByGameId($role['game_id'], $baseGames); + $gameSetting = null; + if ($baseGame && isset($gameSettings[$baseGame['id']])) { + $gameSetting = $gameSettings[$baseGame['id']]; + } + + $spendQuota = $bindingRole && isset($spendItems[$bindingRole['game_role_id']]) ? $spendItems[$bindingRole['game_role_id']] : 0; + $quota = $gameSetting ? round($spendQuota * $gameSetting['rate'] / 100, 2) : 0; + $records[] = [ 'id' => $role['id'], 'game_name' => $role['game_name'], @@ -333,11 +348,12 @@ class TestingResourceRepository 'user_account' => $role['user_account'], 'user_phone' => $user ? $user['phone'] : '', 'role_name' => $role['role_name'], + 'binding_id' => $binding ? $binding['id'] : 0, '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, + 'quota' => $quota, 'verify_amount' => $verifyRecords[$role['game_role_id']] ?? 0, 'provide_amount' => $provideRecords[$role['game_role_id']] ?? 0, 'today_amount' => $todayProvideRecords[$role['game_role_id']] ?? 0, @@ -411,7 +427,6 @@ class TestingResourceRepository $conditions['role_name'] = ['like', $roleName . '%']; } $conditions['_string'] = $strCondition; - return M('user_play_info', 'tab_')->where($conditions)->order('create_time desc'); } } \ No newline at end of file diff --git a/Application/Base/Service/TestingResourceService.class.php b/Application/Base/Service/TestingResourceService.class.php index 8288dcc02..15b33344e 100644 --- a/Application/Base/Service/TestingResourceService.class.php +++ b/Application/Base/Service/TestingResourceService.class.php @@ -25,12 +25,11 @@ class TestingResourceService $batchData['verify_time'] = time(); $batchData['update_time'] = time(); - if (!in_array($batch['game_id'], [229, 230])) { - + $gameIds = $this->repository->getHadSettingGameIds(); + if (!in_array($batch['game_id'], $gameIds)) { $batchData['verify_status'] = 2; - $batchData['verify_remark'] = '该游戏发放功能暂未实现'; + $batchData['verify_remark'] = '该游戏暂不支持资源申请!'; M('testing_resource_batch', 'tab_')->where(['id' => $batch['id']])->save($batchData); - throw new \Exception('该游戏发放功能暂未实现'); } @@ -39,6 +38,45 @@ class TestingResourceService M('testing_resource_batch', 'tab_')->where(['id' => $batch['id']])->save($batchData); } + public function verifyRefuse($batch, $remark = '审核拒绝') + { + if ($batch['verify_status'] != 0) { + throw new \Exception('审核状态异常'); + } + + $batchData = []; + $batchData['verify_time'] = time(); + $batchData['update_time'] = time(); + $batchData['verify_status'] = 2; + $batchData['verify_remark'] = $remark; + M('testing_resource_batch', 'tab_')->where(['id' => $batch['id']])->save($batchData); + } + + public function provideRefuse($batch, $remark = '发放失败') + { + if ($batch['verify_status'] != 1) { + throw new \Exception('该申请未审核通过'); + } + if ($batch['provide_status'] != 0) { + throw new \Exception('发放状态异常'); + } + + M('testing_resource_order', 'tab_') + ->where(['batch_id' => $batch['id']]) + ->save([ + 'provide_status' => 2, + 'provide_time' => time(), + ]); + + M('testing_resource_batch', 'tab_') + ->where(['id' => $batch['id']]) + ->save([ + 'provide_status' => 2, + 'provide_time' => time(), + 'update_time' => time() + ]); + } + public function provide($batch) { if ($batch['verify_status'] != 1) { @@ -49,6 +87,10 @@ class TestingResourceService throw new \Exception('发放状态异常'); } + $gameSetting = $this->repository->getGameSettingByGameId($batch['game_id']); + if (is_null($gameSetting)) { + throw new \Exception('该游戏不支持发放测试资源'); + } $role = M('user_play_info', 'tab_') ->field(['id', 'role_id', 'user_id', 'promote_id', 'user_account', 'sdk_version']) ->where(['game_id' => $batch['game_id'], 'role_id' => $batch['role_id']]) @@ -60,17 +102,22 @@ class TestingResourceService $hasError = false; $provideAmount = 0; foreach ($orders as $order) { - $result = $this->provideFromGameCat($order, $role); - $orderData = [ - 'result' => json_encode(['code' => $result['code'], 'message' => $result['message']]), - ]; - if (!$result['status']) { - $hasError = true; - $orderData['provide_status'] = 2; + $orderData = []; + if ($gameSetting['has_itf'] == 1) { + $result = $this->provideFromGameCat($order, $role); + $orderData = [ + 'result' => json_encode(['code' => $result['code'], 'message' => $result['message']]), + ]; + if (!$result['status']) { + $hasError = true; + $orderData['provide_status'] = 2; + } else { + $orderData['provide_status'] = 1; + } } else { $orderData['provide_status'] = 1; } - $provideAmount += round($order['ref_amount'] * $order['num'], 2); + $provideAmount += $order['amount']; $orderData['provide_time'] = time(); M('testing_resource_order', 'tab_') ->where(['id' => $order['id']]) @@ -131,10 +178,11 @@ class TestingResourceService $totalQuota = $role['testing_other_quota'] + ($gameSetting['base_quota'] ?? 0); if (!is_null($bindRole)) { - $totalQuota += M('spend', 'tab_') + $spendQuota += M('spend', 'tab_') ->where(['game_id' => $role['game_id'], 'game_player_id' => $bindRole['role_id'], 'pay_status' => 1]) ->group('game_id,game_player_id') ->sum('pay_amount'); + $totalQuota += round($gameSetting['rate'] / 100 * $spendQuota, 2); } $providedQuota = M('testing_resource_batch', 'tab_') ->where(['provide_status' => [in, [1, 2]], 'game_id' => $role['game_id'], 'role_id' => $role['role_id']]) @@ -159,7 +207,7 @@ class TestingResourceService $strCondition = '1=1'; if ($promote) { $promoteService = new PromoteService(); - $strCondition = ' and promote_id in (' . $promoteService->subInSql($promote) . ')'; + $strCondition .= ' and promote_id in (' . $promoteService->subInSql($promote) . ')'; } $users = M('user', 'tab_')->field(['id', 'account'])->where(['account' => ['in', $newAccounts], '_string' => $strCondition])->select(); @@ -214,7 +262,7 @@ class TestingResourceService } } - public function bindRole($params, $promote) + public function bindRole($params, $promote = null) { $gameId = $params['game_id'] ?? 0; $testingRoleId = $params['testing_role_id'] ?? ''; @@ -238,7 +286,7 @@ class TestingResourceService $promoteService = new PromoteService(); $testPromote = M('promote', 'tab_')->field(['id', 'chain'])->where(['id' => $testingRole['promote_id']])->find(); - if (is_null($testPromote) || !$promoteService->isSubOrSelf($testPromote, $promote)) { + if (is_null($testPromote) || ($promote && !$promoteService->isSubOrSelf($testPromote, $promote))) { throw new \Exception('测试角色所属推广员异常'); } @@ -251,7 +299,7 @@ class TestingResourceService } $bindPromote = M('promote', 'tab_')->field(['id', 'chain'])->where(['id' => $bindRole['promote_id']])->find(); - if (is_null($bindPromote) || !$promoteService->isSubOrSelf($bindPromote, $promote)) { + if (is_null($bindPromote) || ($promote && !$promoteService->isSubOrSelf($bindPromote, $promote))) { throw new \Exception('玩家账号所属推广员异常'); } @@ -288,6 +336,11 @@ class TestingResourceService } } + public function unbindRole($bindingId) + { + return M('testing_binding', 'tab_')->where(['id' => $bindingId])->delete(); + } + public function apply($params, $promote = null) { $gameId = $params['game_id'] ?? 0; @@ -305,8 +358,11 @@ class TestingResourceService $resources = $this->getGameCatResources('android'); } elseif ($gameId == 230) { $resources = $this->getGameCatResources('ios'); - } else { - throw new \Exception('该游戏不可申请资源'); + } + + $gameSetting = $this->repository->getGameSettingByGameId($gameId); + if (is_null($gameSetting)) { + throw new \Exception('该游戏不支持发放测试资源'); } $binding = M('testing_binding', 'tab_')->where(['game_id' => $gameId, 'role_id' => $roleId])->find(); @@ -374,7 +430,7 @@ class TestingResourceService } */ } - $hasItf = false; + $hasItf = ($gameSetting['has_itf'] == 1); $amount = 0; if ($hasItf) { foreach ($records as $key => $record) { @@ -404,9 +460,8 @@ class TestingResourceService $amount += $record['amount']; } } - - $testingResourceService = new TestingResourceService(); - $remainQuota = $testingResourceService->getRemainQuota($role, $bindingRole); + + $remainQuota = $this->getRemainQuota($role, $bindingRole); if ($amount > $remainQuota) { throw new \Exception('额度不足'); } @@ -453,6 +508,36 @@ 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) + { + $resources = []; + + /** + * @todo 目前固定游戏猫资源类型ID + */ + if ($typeId == 2) { + $resources = $this->getGameCatResources('ios'); + } elseif ($typeId == 1) { + $resources = $this->getGameCatResources('andriod'); + } + return $resources; + } + private function getGameCatResources($deviceType) { $resources = []; diff --git a/Application/Home/Controller/TestingResourceController.class.php b/Application/Home/Controller/TestingResourceController.class.php index 24e820ba6..94f1709b8 100644 --- a/Application/Home/Controller/TestingResourceController.class.php +++ b/Application/Home/Controller/TestingResourceController.class.php @@ -14,14 +14,10 @@ use Base\Repository\GameRepository; class TestingResourceController extends BaseController { - private $gameBaseQuota = [ - 229 => 300, - 230 => 300, - ]; - public function index() { $params = I('get.'); + $gameId = $params['game_id'] ?? 0; $loginPromote = $this->getLoginPromote(); $repository = new TestingResourceRepository(); @@ -40,11 +36,6 @@ class TestingResourceController extends BaseController $this->display(); } - private function getGameRoleId($gameId, $roleId) - { - return $gameId . '#' . $roleId; - } - public function addTestingUsers() { $loginPromote = $this->getLoginPromote(); @@ -63,6 +54,8 @@ class TestingResourceController extends BaseController public function batches() { $params = I('get.'); + $gameId = $params['game_id'] ?? 0; + $loginPromote = $this->getLoginPromote(); $repository = new TestingResourceRepository(); $query = $repository->getBatchesQuery($params, $loginPromote); @@ -99,7 +92,7 @@ class TestingResourceController extends BaseController $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'], @@ -116,7 +109,7 @@ class TestingResourceController extends BaseController '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']), ]; } @@ -138,6 +131,8 @@ class TestingResourceController extends BaseController ->find(); } + $hasItf = 0; + $servers = []; $bindingRole = null; if ($role) { @@ -149,15 +144,18 @@ class TestingResourceController extends BaseController ->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); + $this->assign('hasItf', $hasItf); + + $games = M('game', 'tab_')->field(['id' , 'game_name'])->select(); - /** - * @todo 目前固定游戏猫 - */ - $games = M('game', 'tab_')->field(['id' , 'game_name'])->where(['id' => ['in', [229, 230]]])->select(); $this->assign('games', $games); $this->assign('servers', $servers); $this->assign('bindingRole', $bindingRole); @@ -204,34 +202,16 @@ class TestingResourceController extends BaseController public function getResourceTypes() { $gameId = I('game_id', 0); - $resourceTypes = []; - - /** - * @todo 目前固定游戏猫 - */ - if ($gameId == 229) { - $resourceTypes[] = ['id' => 1, 'name' => '通用']; - } elseif ($gameId == 230) { - $resourceTypes[] = ['id' => 2, 'name' => '通用']; - } + $testingResourceService = new TestingResourceService(); + $resourceTypes = $testingResourceService->getResourceTypes($gameId); return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resourceTypes' => $resourceTypes]]); } public function getResources() { $typeId = I('type_id', 0); - - $resources = []; - - /** - * @todo 目前固定游戏猫资源类型ID - */ - if ($typeId == 2) { - $resources = $this->getGameCatResources('ios'); - } elseif ($typeId == 1) { - $resources = $this->getGameCatResources('andriod'); - } - + $testingResourceService = new TestingResourceService(); + $resources = $testingResourceService->getResources($typeId); return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resources' => $resources]]); } @@ -259,22 +239,4 @@ class TestingResourceController extends BaseController ->select(); return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['roles' => $roles, 'is_testing_account' => $isTestingAccount]]); } - - private function getGameCatResources($deviceType) - { - $resources = []; - $gameCatClient = new GameCatClient(); - $result = $gameCatClient->api('get-pay-type', ['device_type' => $deviceType]); - if ($result['state'] == 1) { - $items = $result['data']; - foreach ($items as $item) { - $resources[$item['supportItem']] = [ - 'ref_id' => $item['supportItem'], - 'name' => $item['content'], - 'amount' => $item['amount'], - ]; - } - } - return $resources; - } } \ No newline at end of file diff --git a/Application/Home/View/default/TestingResource/apply.html b/Application/Home/View/default/TestingResource/apply.html index 73b75c152..258efc63f 100644 --- a/Application/Home/View/default/TestingResource/apply.html +++ b/Application/Home/View/default/TestingResource/apply.html @@ -70,7 +70,7 @@ margin-top: 10px; } .info-row button { - width: 120px; + width: auto; height: 25px; display: block; background: #E5E5E5; @@ -240,6 +240,7 @@