diff --git a/Application/Admin/Controller/GameApiController.class.php b/Application/Admin/Controller/GameApiController.class.php new file mode 100644 index 000000000..47fd29d50 --- /dev/null +++ b/Application/Admin/Controller/GameApiController.class.php @@ -0,0 +1,27 @@ +api('get-pay-type'); + + } +} diff --git a/Application/Base/Tool/GameCatClient.class.php b/Application/Base/Tool/GameCatClient.class.php new file mode 100644 index 000000000..8204dbb3f --- /dev/null +++ b/Application/Base/Tool/GameCatClient.class.php @@ -0,0 +1,84 @@ + ['uri' => '/api/pay/GetPayType', 'method' => 'get'], + 'internal-pay' => ['uri' => '/api/pay/InternalPayOrder/yushi', 'method' => 'post'], + 'check-role' => ['uri' => '/api/pay/CheckActorID', 'method' => 'get'] + ]; + + public function __construct() + { + $this->client = new Client([ + 'base_uri' => C('GAME_CAT_URL'), + 'timeout' => 10.0, + ]); + } + + public function api($api, array $params = []) + { + $api = $this->apis[$api] ?? null; + if (is_null($api)) { + throw new \Exception('接口不存在'); + } + $params[self::SIGN_NAME] = $this->sign($params); + + try { + return $this->request($api, $params); + } catch (\Exception $e) { + $env = C('APP_ENV', null, 'prod'); + return ['code' => '1000', 'message' => '接口请求错误。' . ($env == 'prod' ? '' : $e->getMessage()) , 'data' => []]; + } + } + + public function request($api, $params) + { + if ($api['method'] == 'get') { + return $this->get($api['uri'], $params); + } else { + return $this->post($api['uri'], $params); + } + } + + protected function post($uri, array $params = []) + { + $response = $this->client->post($uri, [ + 'verify' => false, + 'form_params' => $params, + ]); + $result = (string)$response->getBody(); + return json_decode($result, true); + } + + protected function get($uri, array $params = []) + { + $response = $this->client->get($uri, [ + 'verify' => false, + 'query' => $params, + ]); + $result = (string)$response->getBody(); + return json_decode($result, true); + } + + protected function sign($params) + { + unset($params[self::SIGN_NAME]); + ksort($params); + $params['key'] = C('GAME_CAT_KEY'); + return md5(http_build_query($params)); + } +} \ No newline at end of file diff --git a/Application/Home/Controller/TestingResourceController.class.php b/Application/Home/Controller/TestingResourceController.class.php index 564f08db1..06dc7680e 100644 --- a/Application/Home/Controller/TestingResourceController.class.php +++ b/Application/Home/Controller/TestingResourceController.class.php @@ -6,6 +6,8 @@ namespace Home\Controller; use Base\Model\PromoteModel; use Base\Service\PromoteService; use OSS\Core\OssException; +use Base\Tool\GameCatClient; +use Think\Model; class TestingResourceController extends BaseController { @@ -199,6 +201,12 @@ class TestingResourceController extends BaseController { $records = []; $pagination = ''; + + /** + * @todo 目前固定游戏猫 + */ + $games = M('game', 'tab_')->field(['id' , 'game_name'])->where(['id' => ['in', [229, 230]]])->select(); + $this->assign('games', $games); $this->assign('records', $records); $this->assign('pagination', $pagination); $this->display(); @@ -206,21 +214,70 @@ class TestingResourceController extends BaseController public function doApply() { + $gameId = I('game_id', 0); + $roleId = I('role_id', 0); + $serverId = I('server_id', 0); + $userAccount = I('user_account', ''); $records = I('records', []); - $batchNo = ''; $loginPromote = $this->getLoginPromote(); + $resources = []; + /** + * @todo 目前仅限游戏猫 + */ + if (!in_array($gameId, [229, 230])) { + return $this->ajaxReturn(['status' => 0, 'message' => '该游戏不可申请资源']); + } else { + $resources = $this->getGameCatResources(); + } + + $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' => '区服不存在']); + } + + $role = M('user_play_info', 'tab_') + ->field(['id', 'role_id']) + ->where(['user_id' => $user['id'], 'game_id' => $gameId, 'server_id' => $server['server_id']]) + ->find(); + if (is_null($role)) { + return $this->ajaxReturn(['status' => 0, 'message' => '角色不存在']); + } + $amount = 0; - foreach ($records as $record) { - $amount += $record['num'] * $record['value']; + 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' => '含有资源内容不存在']); + } } + $batchNo = date('YmdHis') . substr(md5($loginPromote['id'] . strval(microtime(true)) . rand(0, 9999)), 8, 16); + try { + $model = new Model(); + $model->startTrans(); + $batch = [ 'batch_id' => $batchId, - 'order_no' => $orderNo, - 'user_id' => $record['user_id'], - 'game_id' => $record['game_id'], + 'batch_no' => $batchNo, + 'user_id' => $testingUser['user_id'], + 'game_id' => $gameId, + 'role_id' => $roleId, + 'server_id' => $serverId, 'promote_id' => $loginPromote['id'], 'amount' => $amount, 'status' => 0, @@ -236,39 +293,65 @@ class TestingResourceController extends BaseController $order = [ 'batch_id' => $batchId, 'order_no' => $orderNo, - 'testing_resource_id' => $record['resource_id'], + 'ref_id' => $record['resource_id'], + 'ref_name' => $record['resource_name'], 'num' => $record['num'], 'amount' => $record['num'] * $record['value'], 'remark' => $record['remark'], ]; M('testing_resource_order')->add($order); } + $model->commit(); + return $this->ajaxReturn(['status' => 1, 'message' => '申请成功,等待审核']); } catch (\Exception $e) { - + $model->rollback(); + return $this->ajaxReturn(['status' => 0, 'message' => '系统异常']); } } public function bindRole() { $testingUserId = I('testing_user_id', 0); - $userAccount = I('user_account', ''); - $roleId = I('role_id', ''); + $testingRoleId = I('testing_role_id', 0); + $bindUserId = I('bind_user_id', 0); + $bindRoleId = I('bind_role_id', 0); - $user = M('user', 'tab_')->field(['id', 'account'])->where(['account' => $userAccount])->find(); - if (is_null($user)) { + $bindUser = M('user', 'tab_')->field(['id', 'account'])->where(['id' => $bindUserId])->find(); + if (is_null($bindUser)) { return $this->ajaxReturn(['status' => 0, 'message' => '用户不存在']); } - $existBind = M('testing_user', 'tab_')->field(['id'])->where(['bind_user_id' => $user['id']])->find(); + $testingUser = M('testing_user', 'tab_')->where(['user_id' => $testingUserId])->find(); + if (is_null($testingUser)) { + return $this->ajaxReturn(['status' => 0, 'message' => '测试账号不存在']); + } + + $testingRole = M('user_play_info', 'tab_') + ->field(['id', 'role_id']) + ->where(['id' => $testingRoleId]) + ->find(); + if (is_null($testingRole)) { + return $this->ajaxReturn(['status' => 0, 'message' => '测试账号角色不存在']); + } + $bindRole = M('user_play_info', 'tab_') + ->field(['id', 'role_id']) + ->where(['id' => $bindRoleId]) + ->find(); + if (is_null($bindRole)) { + return $this->ajaxReturn(['status' => 0, 'message' => '玩家角色不存在']); + } + + + $existBind = M('testing_user', 'tab_')->field(['id'])->where(['bind_user_id' => $bindUser['id']])->find(); if ($existBind) { return $this->ajaxReturn(['status' => 0, 'message' => '该玩家账号已被绑定']); } M('testing_user', 'tab_')->where(['user_id' => $testingUserId])->save([ - 'role_id' => $roleId, - 'bind_user_id' => $user['id'], - 'bind_user_account' => $user['account'], - 'bind_role_id' => $roleId, + 'role_id' => $testingRole['id'], + 'bind_user_id' => $bindUser['id'], + 'bind_user_account' => $bindUser['account'], + 'bind_role_id' => $bindRoleId, ]); return $this->ajaxReturn(['status' => 1, 'message' => '绑定成功']); } @@ -277,4 +360,86 @@ class TestingResourceController extends BaseController { } + + public function getServers() + { + $gameId = I('game_id', 0); + $map = []; + $map['game_id'] = $gameId; + $servers = M('server', 'tab_') + ->field('id,server_name,server_id') + ->where($map) + ->order('server_id asc') + ->select(); + return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['servers' => $servers]]); + } + + public function getResourceTypes() + { + $gameId = I('game_id', 0); + $resourceTypes = []; + + /** + * @todo 目前固定游戏猫 + */ + if (in_array($gameId, [229, 230])) { + $resourceTypes[] = ['id' => 1, 'name' => '通用']; + } + return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resourceTypes' => $resourceTypes]]); + } + + public function getResources() + { + $typeId = I('type_id', 0); + + $resources = []; + + /** + * @todo 目前固定游戏猫资源类型ID + */ + if ($typeId == 1) { + $resources = $this->getGameCatResources(); + } + + return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['resources' => $resources]]); + } + + 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' => '区服不存在']); + } + $roles = M('user_play_info', 'tab_') + ->field(['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]]); + } + + private function getGameCatResources() + { + $resources = []; + $gameCatClient = new GameCatClient(); + $result = $gameCatClient->api('get-pay-type'); + if ($result['code'] == 1) { + $payTypeList = $result['paytypelist']; + foreach ($payTypeList as $item) { + $resources[$item['PayType']] = [ + 'ref_id' => $item['PayType'], + 'name' => $item['Text'], + 'amount' => $item['Amount'], + ]; + } + } + return $resources; + } + + private function getRemainAmount($user) + { + + } } \ 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 f1e997459..e0f176b39 100644 --- a/Application/Home/View/default/TestingResource/apply.html +++ b/Application/Home/View/default/TestingResource/apply.html @@ -25,71 +25,434 @@ color: #fff; border: none; border-radius: 4px; + cursor: pointer; } - .normal_table td button.danger-btn { + .normal_table td button.delete-row { background-color: rgb(249,104,104); } + .btn-row { + position: relative; + font-size: 11px; + margin-top: 28px; + text-align: center; + } + .btn-row button { + width: 70px; + height: 35px; + display: block; + background: #409eff; + color: #fff; + border: none; + border-radius: 4px; + cursor: pointer; + display: inline-block; + } + .btn-row button.close-btn { + background: #E5E5E5; + color: #535875; + } + .form-group .static-input { + line-height: 32px; + display: inline-block; + } + .trunk-search button { + width: 70px; + height: 35px; + display: block; + background: #409eff; + color: #fff; + border: none; + border-radius: 4px; + cursor: pointer; + display: inline-block; + } + .info-row { + margin-top: 10px; + } + .info-row button { + width: 120px; + height: 25px; + display: block; + background: #E5E5E5; + color: #535875; + border: none; + border-radius: 4px; + cursor: pointer; + display: inline-block; + margin-left: 10px; + }