diff --git a/Application/Admin/Controller/AdminController.class.php b/Application/Admin/Controller/AdminController.class.php
index 133778918..412a80191 100644
--- a/Application/Admin/Controller/AdminController.class.php
+++ b/Application/Admin/Controller/AdminController.class.php
@@ -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];
+ }
}
diff --git a/Application/Admin/Controller/TestingResourceController.class.php b/Application/Admin/Controller/TestingResourceController.class.php
new file mode 100644
index 000000000..b2f28a187
--- /dev/null
+++ b/Application/Admin/Controller/TestingResourceController.class.php
@@ -0,0 +1,534 @@
+getTestingUsersQuery($params);
+
+ [$roles, $page, $count] = $this->paginate($query);
+
+ $records = $repository->makeTestingUserRecords($roles);
+
+ $gameRepository = new GameRepository();
+
+ $this->assign('games', $gameRepository->getChoiceGames());
+ $this->assign('servers', $gameRepository->getServersByGameId($gameId));
+ $this->assign('count', $count);
+ $this->assign('records', $records);
+ $this->assign('_page', $page);
+ $this->display();
+ }
+
+ public function getServers()
+ {
+ $gameId = I('game_id', 0);
+ $gameRepository = new GameRepository();
+ $servers = $gameRepository->getServersByGameId($gameId);
+ return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['servers' => $servers]]);
+ }
+
+ public function gameSettings()
+ {
+ $page = I('p', 1);
+ $row = I('row', 10);
+
+ $gameId = I('base_game_id', 0);
+ $partnerId = I('partner_id', 0);
+
+ $conditions = [];
+ $conditions['_string'] = '1=1';
+ if ($partnerId > 0) {
+ $partnerService = new PartnerService();
+ $baseGames = $partnerService->findBaseGamesByPartnerId($partnerId);
+ if (empty($baseGames)) {
+ $conditions['_string'] = '1=0';
+ } else {
+ $conditions['base_game_id'] = ['in', array_column($baseGames, 'id')];
+ }
+ }
+ if ($gameId > 0) {
+ $conditions['base_game_id'] = $gameId;
+ }
+ $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);
+ $partners = M('partner', 'tab_')->field(['id', 'partner'])->select();
+ $partners = index_by_column('id', $partners);
+
+ $games = M('game', 'tab_')->where(['id', 'partner_id'])->select();
+ $games = index_by_column('id', $games);
+ foreach ($baseGames as $key => $baseGame) {
+ if ($baseGame['android_game_id'] > 0) {
+ $baseGame['partner_id'] = $games[$baseGame['android_game_id']]['partner_id'];
+ } else {
+ $baseGame['partner_id'] = $games[$baseGame['ios_game_id']]['partner_id'];
+ }
+ $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'],
+ 'game_name' => $baseGame ? $baseGame['name'] : '无此游戏',
+ '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
+ ];
+ }
+
+ $this->assign('_page', $page);
+ $this->assign('records', $records);
+ $this->assign('partners', $partners);
+ $this->assign('baseGames', $baseGames);
+ $this->display();
+ }
+
+ public function saveGameSetting()
+ {
+ $params = I('post.');
+ try {
+ $testingResourceService = new TestingResourceService();
+ $testingResourceService->saveGameSetting($params);
+ return $this->ajaxReturn(['status' => 1, 'message' => '保存成功']);
+ } catch (\Exception $e) {
+ return $this->ajaxReturn(['status' => 0, 'message' => '保存失败!' . $e->getMessage()]);
+ }
+ }
+
+ public function deleteGameSetting()
+ {
+ $id = I('id', 0);
+ M('testing_game_setting', 'tab_')->where(['id' => $id])->delete();
+ return $this->ajaxReturn(['status' => 1, 'message' => '删除成功']);
+ }
+
+ public function addTestingUsers()
+ {
+ $accountsStr = trim(I('accounts', ''), ',');
+ if ($accountsStr == '') {
+ return $this->ajaxReturn(['status' => 0, 'message' => '请输入测试资源账号']);
+ }
+ $accounts = explode(',', $accountsStr);
+
+ $testingResourceService = new TestingResourceService();
+ $result = $testingResourceService->addTestingUsers($accounts);
+
+ return $this->ajaxReturn(['status' => 1, 'message' => '请求成功', 'data' => $result]);
+ }
+
+ 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));
+ $this->assign('games', $gameRepository->getChoiceGames());
+ $this->assign('count', $count);
+ $this->assign('_page', $pagination);
+ $this->assign('records', $records);
+ $this->display();
+ }
+
+ public function orders()
+ {
+ $id = I('id', 0);
+
+ $batch = M('testing_resource_batch', 'tab_')->where(['id' => $id])->find();
+
+ $role = M('user_play_info', 'tab_')
+ ->field(['id', 'game_name', 'server_name', 'role_name', 'game_role_id', 'user_account'])
+ ->where(['game_id' => $batch['game_id'], 'role_id' => $batch['role_id']])
+ ->find();
+
+ $applyPromote = M('promote', 'tab_')->field(['id', 'account'])->where(['id' => $batch['apply_promote_id']])->find();
+ $promote = M('promote', 'tab_')->field(['id', 'account'])->where(['id' => $role['apply_promote_id']])->find();
+
+ $query = M('testing_resource_order', 'tab_')->where(['batch_id' => $id])->order('id desc');
+ list($orders, $pagination, $count) = $this->paginate($query);
+
+ $repository = new TestingResourceRepository();
+ foreach ($orders as $order) {
+ $records[] = [
+ 'id' => $order['id'],
+ 'create_time' => $batch['create_time'] == 0 ? '--' : date('Y-m-d H:i:s', $batch['create_time']),
+ 'game_name' => $role['game_name'],
+ 'user_account' => $role['user_account'],
+ 'server_name' => $role['server_name'],
+ 'role_name' => $role['role_name'],
+ 'apply_promote_account' => $applyPromote ? $applyPromote['account'] : '',
+ 'promote_account' => $promote['account'],
+ 'ref_name' => $order['ref_name'],
+ 'ref_amount' => $order['ref_amount'],
+ 'num' => $order['num'],
+ 'amount' => $order['num'] * $order['ref_amount'],
+ 'remark' => $order['remark'],
+ 'provide_status' => $order['provide_status'],
+ 'provide_status_text' => $repository->getProvideStatusText($order['provide_status']),
+ ];
+ }
+
+ $this->assign('count', $count);
+ $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);
+
+ $games = M('game', 'tab_')->field(['id' , 'game_name'])->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', []);
+ $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 $e) {
+ 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 $e) {
+ 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
new file mode 100644
index 000000000..1a7211ef0
--- /dev/null
+++ b/Application/Admin/View/TestingResource/apply.html
@@ -0,0 +1,746 @@
+
+
+
+
+
+ 游戏登陆列表|----软件管理平台
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Application/Admin/View/TestingResource/batches.html b/Application/Admin/View/TestingResource/batches.html
new file mode 100644
index 000000000..86e067442
--- /dev/null
+++ b/Application/Admin/View/TestingResource/batches.html
@@ -0,0 +1,477 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
测试资源申请批次
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
导出
+
+ {$_page|default=''}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Application/Admin/View/TestingResource/gameSettings.html b/Application/Admin/View/TestingResource/gameSettings.html
new file mode 100644
index 000000000..45b3c2be8
--- /dev/null
+++ b/Application/Admin/View/TestingResource/gameSettings.html
@@ -0,0 +1,352 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
游戏测试资源设置
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 游戏名称 |
+ 游戏合作方 |
+ 初始额度 |
+ 奖金比例 |
+ 当前已申请资源 |
+ 操作 |
+
+
+
+
+
+
+ aOh! 暂时还没有内容! |
+
+
+
+ {$data.game_name} |
+ {$data.partner_name} |
+ {$data.base_quota} |
+ {$data.rate}% |
+ {$data.provide_quota} |
+
+
+ |
+
+
+
+
+
+
+
+
+
+ 导出
+
+ {$_page|default=''}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Application/Admin/View/TestingResource/index.html b/Application/Admin/View/TestingResource/index.html
new file mode 100644
index 000000000..7d82a6907
--- /dev/null
+++ b/Application/Admin/View/TestingResource/index.html
@@ -0,0 +1,463 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
测试账号
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 导出
+
+ {$_page|default=''}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Application/Admin/View/TestingResource/orders.html b/Application/Admin/View/TestingResource/orders.html
new file mode 100644
index 000000000..7a953cc23
--- /dev/null
+++ b/Application/Admin/View/TestingResource/orders.html
@@ -0,0 +1,95 @@
+
+
+
+
+
+ 游戏登陆列表|----软件管理平台
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 申请ID |
+ 申请时间 |
+ 游戏名称 |
+ 玩家账号 |
+ 区服名称 |
+ 角色名称 |
+ 申请人 |
+ 资源内容 |
+ 资源价值 |
+ 申请数量 |
+ 申请金额 |
+ 申请备注 |
+ 发放状态 |
+
+
+
+
+
+
+ 暂无数据 |
+
+
+
+ {$record.id} |
+
+ =substr($record['create_time'], 0, 10)?>
+
+ =substr($record['create_time'], 10)?>
+ |
+ {$record.game_name} |
+ {$record.user_account} |
+ {$record.server_name} |
+ {$record.role_name} |
+ {$record.apply_promote_account} |
+ {$record.ref_name} |
+ {$record.ref_amount} |
+ {$record.num} |
+ {$record.amount} |
+ {$record.remark} |
+ {$record.provide_status_text} |
+
+
+
+
+
+
+
+
+ {$_page}
+
+
+
+
+
diff --git a/Application/Base/Repository/GameRepository.class.php b/Application/Base/Repository/GameRepository.class.php
new file mode 100644
index 000000000..25e3d44e0
--- /dev/null
+++ b/Application/Base/Repository/GameRepository.class.php
@@ -0,0 +1,56 @@
+where('1=1')->select();
+ Registry::set('base_games', $baseGames);
+ }
+ return $baseGames;
+ }
+
+ public function getBaseGameByGameId($gameId, array $baseGames = null)
+ {
+ 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'])
+ {
+ $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_')
+ ->field($fields)
+ ->where($map)
+ ->order('server_id asc')
+ ->select();
+ }
+}
\ No newline at end of file
diff --git a/Application/Base/Repository/TestingResourceRepository.class.php b/Application/Base/Repository/TestingResourceRepository.class.php
new file mode 100644
index 000000000..ec7be34f2
--- /dev/null
+++ b/Application/Base/Repository/TestingResourceRepository.class.php
@@ -0,0 +1,432 @@
+ '待发放',
+ '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'];
+ }
+ }
+ $gameSettings = $this->getGameSettings();
+ return [
+ 'users' => $users,
+ 'spendItems' => $spendItems,
+ 'bindings' => $bindings,
+ 'bindingRoles' => $bindingRoles,
+ 'applyRecords' => $applyRecords,
+ 'provideRecords' => $provideRecords,
+ 'verifyRecords' => $verifyRecords,
+ 'todayProvideRecords' => $todayProvideRecords,
+ 'gameSettings' => $gameSettings,
+ ];
+ }
+
+ public function makeTestingUserRecords($roles)
+ {
+ $result = $this->statByRoles($roles);
+ $users = $result['users'];
+ $spendItems = $result['spendItems'];
+ $gameSettings = $result['gameSettings'];
+ $bindings = $result['bindings'];
+ $bindingRoles = $result['bindingRoles'];
+ $applyRecords = $result['applyRecords'];
+ $provideRecords = $result['provideRecords'];
+ $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;
+ $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;
+ }
+ $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'],
+ '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'],
+ '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' => intval($role['testing_other_quota']),
+ '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,
+ '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');
+ }
+}
\ No newline at end of file
diff --git a/Application/Base/Service/PartnerService.class.php b/Application/Base/Service/PartnerService.class.php
index 5a956d119..576dd24f8 100644
--- a/Application/Base/Service/PartnerService.class.php
+++ b/Application/Base/Service/PartnerService.class.php
@@ -75,4 +75,16 @@ class PartnerService
M('company_relation', 'tab_')->add($data);
}
}
+
+ public function findBaseGamesByPartnerId($partnerId)
+ {
+ $gameIds = M('game', 'tab_')->where(['partner_id' => $partnerId])->getField('id', true);
+ $conditions = ['_string' => '1=1'];
+ if (empty($gameIds)) {
+ $conditions['_string'] .= ' and 1=0';
+ } else {
+ $conditions['_string'] .= ' and (android_game_id in(' . implode(',', $gameIds) . ') or ios_game_id in(' . implode(',', $gameIds) . '))';
+ }
+ return M('base_game', 'tab_')->where($conditions)->select();
+ }
}
\ No newline at end of file
diff --git a/Application/Base/Service/TestingResourceService.class.php b/Application/Base/Service/TestingResourceService.class.php
index 31db4fd23..15b33344e 100644
--- a/Application/Base/Service/TestingResourceService.class.php
+++ b/Application/Base/Service/TestingResourceService.class.php
@@ -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)
@@ -37,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('该游戏发放功能暂未实现');
}
@@ -51,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) {
@@ -61,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']])
@@ -72,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']])
@@ -130,4 +165,394 @@ class TestingResourceService
];
}
}
+
+ public function getRemainQuota($role, $bindRole = null, $gameSetting = null)
+ {
+ if (is_null($gameSetting)) {
+ $gameSetting = $this->repository->getGameSettingByGameId($role['game_id']);
+ }
+
+ if (is_null($gameSetting)) {
+ throw new \Exception('游戏未设置测试资源');
+ }
+
+ $totalQuota = $role['testing_other_quota'] + ($gameSetting['base_quota'] ?? 0);
+ if (!is_null($bindRole)) {
+ $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']])
+ ->sum('provide_amount');
+ $providingQuota = M('testing_resource_batch', 'tab_')
+ ->where(['verify_status' => [in, [0, 1]], 'provide_status' => 0, 'game_id' => $role['game_id'], 'role_id' => $role['role_id']])
+ ->sum('apply_amount');
+ return round(floatval($totalQuota) - floatval($providedQuota) - floatval($providingQuota), 2);
+ }
+
+ public function addTestingUsers($accounts, $promote = null)
+ {
+ $accounts = array_unique($accounts);
+ $existAccounts = M('testing_user', 'tab_')->where(['user_account' => ['in', $accounts]])->getField('user_account', true);
+ $existAccounts = $existAccounts ?? [];
+ $existCount = count($existAccounts);
+ $newAccounts = array_diff($accounts, $existAccounts);
+ $errorCount = 0;
+ $successCount = 0;
+ if (count($newAccounts)) {
+
+ $strCondition = '1=1';
+ if ($promote) {
+ $promoteService = new PromoteService();
+ $strCondition .= ' and promote_id in (' . $promoteService->subInSql($promote) . ')';
+ }
+
+ $users = M('user', 'tab_')->field(['id', 'account'])->where(['account' => ['in', $newAccounts], '_string' => $strCondition])->select();
+ $errorAccounts = array_diff($newAccounts, array_column($users, 'account'));
+ $errorCount = count($errorAccounts);
+ foreach ($users as $user) {
+ if (in_array($user['account'], $errorAccounts)) {
+ continue;
+ }
+ $data = [
+ 'user_id' => $user['id'],
+ 'user_account' => $user['account'],
+ 'status' => 1,
+ 'create_time' => time(),
+ 'update_time' => time(),
+ ];
+ M('testing_user', 'tab_')->add($data);
+ $successCount ++;
+ }
+ }
+ return [
+ 'errorCount' => $errorCount,
+ 'successCount' => $successCount,
+ 'existCount' => $existCount,
+ ];
+ }
+
+ public function saveGameSetting($params)
+ {
+ $gameId = $params['base_game_id'] ?? 0;
+ $baseQuota = $params['base_quota'] ?? 0;
+ $rate = $params['rate'] ?? 0;
+
+ if ($gameId == 0) {
+ throw new \Exception('请选择游戏');
+ }
+
+ $data = [
+ 'base_game_id' => $gameId,
+ 'base_quota' => $baseQuota,
+ 'rate' => $rate,
+ ];
+
+ $setting = M('testing_game_setting', 'tab_')->where(['base_game_id' => $gameId])->find();
+ if ($setting) {
+ $data['update_time'] = time();
+ M('testing_game_setting', 'tab_')->where(['base_game_id' => $gameId])->save($data);
+ } else {
+ $data['create_time'] = time();
+ $data['update_time'] = time();
+ M('testing_game_setting', 'tab_')->add($data);
+ }
+ }
+
+ public function bindRole($params, $promote = null)
+ {
+ $gameId = $params['game_id'] ?? 0;
+ $testingRoleId = $params['testing_role_id'] ?? '';
+ $bindRoleId = $params['bind_role_id'] ?? '';
+
+ $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'])
+ ->where(['game_role_id' => $testingGameRoleId])
+ ->find();
+ if (is_null($testingRole)) {
+ throw new \Exception('测试账号角色不存在');
+ }
+
+ $testingUser = M('testing_user', 'tab_')->where(['user_id' => $testingRole['user_id']])->find();
+ if (is_null($testingUser)) {
+ 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))) {
+ throw new \Exception('测试角色所属推广员异常');
+ }
+
+ $bindRole = M('user_play_info', 'tab_')
+ ->field(['id', 'role_id', 'user_id', 'promote_id'])
+ ->where(['game_role_id' => $bindGameRoleId])
+ ->find();
+ if (is_null($bindRole)) {
+ throw new \Exception('玩家角色不存在');
+ }
+
+ $bindPromote = M('promote', 'tab_')->field(['id', 'chain'])->where(['id' => $bindRole['promote_id']])->find();
+ if (is_null($bindPromote) || ($promote && !$promoteService->isSubOrSelf($bindPromote, $promote))) {
+ throw new \Exception('玩家账号所属推广员异常');
+ }
+
+ /* if ($testPromote['id'] != $bindPromote['id']) {
+ throw new \Exception('玩家账号与测试账号非同一推广员');
+ } */
+
+ $bindIsTesting = M('testing_user', 'tab_')->where(['user_id' => $bindRole['user_id']])->find();
+ if ($bindIsTesting) {
+ throw new \Exception('该玩家账号为测试账号,无法绑定');
+ }
+
+ $existBind = M('testing_binding', 'tab_')->field(['id'])->where(['game_id' => $gameId, 'bind_role_id' => $bindRoleId])->find();
+ if ($existBind) {
+ throw new \Exception('该玩家角色已被绑定');
+ }
+
+ $testExistBind = M('testing_binding', 'tab_')->field(['id'])->where(['game_id' => $gameId, 'role_id' => $testingRoleId])->find();
+ if ($testExistBind) {
+ throw new \Exception('该测试账号角色已绑定有角色');
+ }
+
+ $status = M('testing_binding', 'tab_')->add([
+ 'game_id' => $testingRole['game_id'],
+ 'user_id' => $testingRole['user_id'],
+ 'role_id' => $testingRole['role_id'],
+ 'bind_user_id' => $bindRole['user_id'],
+ 'bind_role_id' => $bindRole['role_id'],
+ 'create_time' => time(),
+ 'update_time' => time()
+ ]);
+ if (!$status) {
+ throw new \Exception('绑定角色异常');
+ }
+ }
+
+ public function unbindRole($bindingId)
+ {
+ return M('testing_binding', 'tab_')->where(['id' => $bindingId])->delete();
+ }
+
+ 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');
+ }
+
+ $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();
+ /* 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 = ($gameSetting['has_itf'] == 1);
+ $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'];
+ }
+ }
+
+ $remainQuota = $this->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());
+ }
+ }
+
+ 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 = [];
+ $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/Controller/TestingResourceController.class.php b/Application/Home/Controller/TestingResourceController.class.php
index c258d711b..83fa00dcb 100644
--- a/Application/Home/Controller/TestingResourceController.class.php
+++ b/Application/Home/Controller/TestingResourceController.class.php
@@ -9,214 +9,33 @@ 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
{
- private $gameBaseQuota = [
- 229 => 300,
- 230 => 300,
- ];
-
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.');
+ $gameId = $params['game_id'] ?? 0;
$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) . ')';
- }
-
- /**
- * @todo 仅有游戏猫
- */
- $strCondition .= ' and game_id in (229, 230)';
-
- 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);
-
- $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'] ;
- }
+ $records = $repository->makeTestingUserRecords($roles);
- $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'];
- }
- }
- $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;
- }
- $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' => $this->gameBaseQuota[$role['game_id']] ?? 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'])
- ];
- }
+ $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);
$this->display();
}
- private function getGameRoleId($gameId, $roleId)
- {
- return $gameId . '#' . $roleId;
- }
-
public function addTestingUsers()
{
$loginPromote = $this->getLoginPromote();
@@ -225,156 +44,31 @@ class TestingResourceController extends BaseController
return $this->ajaxReturn(['status' => 0, 'message' => '请输入测试资源账号']);
}
$accounts = explode(',', $accountsStr);
- $accounts = array_unique($accounts);
- $existAccounts = M('testing_user', 'tab_')->where(['user_account' => ['in', $accounts]])->getField('user_account', true);
- $existAccounts = $existAccounts ?? [];
- $existCount = count($existAccounts);
- $newAccounts = array_diff($accounts, $existAccounts);
- $errorCount = 0;
- $successCount = 0;
- if (count($newAccounts)) {
-
- $promoteService = new PromoteService();
- $strCondition = 'promote_id in (' . $promoteService->subInSql($loginPromote) . ')';
-
- $users = M('user', 'tab_')->field(['id', 'account'])->where(['account' => ['in', $newAccounts], '_string' => $strCondition])->select();
- $errorAccounts = array_diff($newAccounts, array_column($users, 'account'));
- $errorCount = count($errorAccounts);
- foreach ($users as $user) {
- if (in_array($user['account'], $errorAccounts)) {
- continue;
- }
- $data = [
- 'user_id' => $user['id'],
- 'user_account' => $user['account'],
- 'status' => 1,
- 'create_time' => time(),
- 'update_time' => time(),
- ];
- M('testing_user', 'tab_')->add($data);
- $successCount ++;
- }
- }
- return $this->ajaxReturn(['status' => 1, 'message' => '请求成功', 'data' => [
- 'errorCount' => $errorCount,
- 'successCount' => $successCount,
- 'existCount' => $existCount,
- ]]);
+
+ $testingResourceService = new TestingResourceService();
+ $result = $testingResourceService->addTestingUsers($accounts, $loginPromote);
+
+ return $this->ajaxReturn(['status' => 1, 'message' => '请求成功', 'data' => $result]);
}
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.');
+ $gameId = $params['game_id'] ?? 0;
$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);
- }
- }
+ $records = $repository->makeBatchesRecords($batches);
- $testingResourceService = new TestingResourceService();
+ $gameRepository = new GameRepository();
- $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,
- ];
- }
-
- $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);
@@ -398,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'],
@@ -415,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']),
];
}
@@ -425,24 +119,6 @@ class TestingResourceController extends BaseController
$this->display();
}
- private function getRemainQuota($role, $bindRole = null)
- {
- $totalQuota = $role['testing_other_quota'] + ($this->gameBaseQuota[$role['game_id']] ?? 0);
- if (!is_null($bindRole)) {
- $totalQuota += 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');
- }
- $providedQuota = M('testing_resource_batch', 'tab_')
- ->where(['provide_status' => [in, [1, 2]], 'game_id' => $role['game_id'], 'role_id' => $role['role_id']])
- ->sum('provide_amount');
- $providingQuota = M('testing_resource_batch', 'tab_')
- ->where(['verify_status' => [in, [0, 1]], 'provide_status' => 0, 'game_id' => $role['game_id'], 'role_id' => $role['role_id']])
- ->sum('apply_amount');
- return round(floatval($totalQuota) - floatval($providedQuota) - floatval($providingQuota), 2);
- }
-
public function apply()
{
$id = I('id', 0);
@@ -455,6 +131,8 @@ class TestingResourceController extends BaseController
->find();
}
+ $hasItf = 0;
+
$servers = [];
$bindingRole = null;
if ($role) {
@@ -466,316 +144,74 @@ 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;
}
- /**
- * @todo 目前固定游戏猫
- */
- $games = M('game', 'tab_')->field(['id' , 'game_name'])->where(['id' => ['in', [229, 230]]])->select();
+ $testingResourceService = new TestingResourceService();
+ $quota = $testingResourceService->getRemainQuota($role, $bindingRole);
+ $this->assign('hasItf', $hasItf);
+
+ $games = M('game', 'tab_')->field(['id' , 'game_name'])->select();
+
$this->assign('games', $games);
$this->assign('servers', $servers);
$this->assign('bindingRole', $bindingRole);
$this->assign('role', $role);
- $this->assign('quota', $this->getRemainQuota($role, $bindingRole));
+ $this->assign('quota', $quota);
$this->display();
}
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']);
- }
- }
-
- $remainQuota = $this->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' => '申请成功,等待审核']);
+ $testingResourceService = new TestingResourceService();
+ $testingResourceService->apply($params, $loginPromote);
+ return $this->ajaxReturn(['status' => 1, 'message' => '申请成功,等待审核。']);
} catch (\Exception $e) {
- $model->rollback();
- return $this->ajaxReturn(['status' => 0, 'message' => '系统异常' . $e->getMessage()]);
+ return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
}
public function bindRole()
{
- $gameId = I('game_id', 0);
- $testingRoleId = I('testing_role_id', '');
- $bindRoleId = I('bind_role_id', '');
- $loginPromote = $this->getLoginPromote();
-
- $testingGameRoleId = $this->getGameRoleId($gameId, $testingRoleId);
- $bindGameRoleId = $this->getGameRoleId($gameId, $bindRoleId);
-
- $testingRole = M('user_play_info', 'tab_')
- ->field(['id', 'role_id', 'user_id', 'game_id', 'promote_id'])
- ->where(['game_role_id' => $testingGameRoleId])
- ->find();
- if (is_null($testingRole)) {
- return $this->ajaxReturn(['status' => 0, 'message' => '测试账号角色不存在']);
- }
-
- $testingUser = M('testing_user', 'tab_')->where(['user_id' => $testingRole['user_id']])->find();
- if (is_null($testingUser)) {
- return $this->ajaxReturn(['status' => 0, 'message' => '测试账号不存在']);
- }
-
- $promoteService = new PromoteService();
- $testPromote = M('promote', 'tab_')->field(['id', 'chain'])->where(['id' => $testingRole['promote_id']])->find();
- if (is_null($testPromote) || !$promoteService->isSubOrSelf($testPromote, $loginPromote)) {
- return $this->ajaxReturn(['status' => 0, 'message' => '测试角色所属推广员异常']);
- }
-
- $bindRole = M('user_play_info', 'tab_')
- ->field(['id', 'role_id', 'user_id', 'promote_id'])
- ->where(['game_role_id' => $bindGameRoleId])
- ->find();
- if (is_null($bindRole)) {
- return $this->ajaxReturn(['status' => 0, 'message' => '玩家角色不存在']);
- }
-
- $bindPromote = M('promote', 'tab_')->field(['id', 'chain'])->where(['id' => $bindRole['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' => '玩家账号与测试账号非同一推广员']);
- } */
-
- $bindIsTesting = M('testing_user', 'tab_')->where(['user_id' => $bindRole['user_id']])->find();
- if ($bindIsTesting) {
- return $this->ajaxReturn(['status' => 0, 'message' => '该玩家账号为测试账号,无法绑定']);
- }
-
- $existBind = M('testing_binding', 'tab_')->field(['id'])->where(['game_id' => $gameId, 'bind_role_id' => $bindRoleId])->find();
- if ($existBind) {
- return $this->ajaxReturn(['status' => 0, 'message' => '该玩家角色已被绑定']);
- }
-
- $testExistBind = M('testing_binding', 'tab_')->field(['id'])->where(['game_id' => $gameId, 'role_id' => $testingRoleId])->find();
- if ($testExistBind) {
- return $this->ajaxReturn(['status' => 0, 'message' => '该测试账号角色已绑定有角色']);
- }
-
- M('testing_binding', 'tab_')->add([
- 'game_id' => $testingRole['game_id'],
- 'user_id' => $testingRole['user_id'],
- 'role_id' => $testingRole['role_id'],
- 'bind_user_id' => $bindRole['user_id'],
- 'bind_role_id' => $bindRole['role_id'],
- 'create_time' => time(),
- 'update_time' => time()
- ]);
- return $this->ajaxReturn(['status' => 1, 'message' => '绑定成功']);
- }
-
- private function getGames()
- {
- $map = [
- 'id' => ['in', [229, 230]]
- ];
+ $params = I('post.');
$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 [];
+ try {
+ $testingResourceService = new TestingResourceService();
+ $testingResourceService->bindRole($params, $loginPromote);
+ return $this->ajaxReturn(['status' => 1, 'message' => '绑定成功']);
+ } catch (\Exception $e) {
+ return $this->ajaxReturn(['status' => 0, 'message' => $e->getMessage()]);
}
- $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]]);
}
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]]);
}
@@ -803,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 76f9e27e1..56e488239 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;
@@ -136,6 +136,8 @@
+
+
-
+
+
+
+
+
+
+
+
+
@@ -164,6 +174,7 @@