diff --git a/Application/Base/Service/TestingResourceService.class.php b/Application/Base/Service/TestingResourceService.class.php new file mode 100644 index 000000000..161ee1c5b --- /dev/null +++ b/Application/Base/Service/TestingResourceService.class.php @@ -0,0 +1,126 @@ + '待发放', + '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 verify($batch) + { + if ($batch['verify_status'] != 0) { + throw new \Exception('审核状态异常'); + } + + $batchData = []; + $batchData['verify_time'] = time(); + $batchData['update_time'] = time(); + + if (!in_array($batch['game_id'], [229, 230])) { + + $batchData['verify_status'] = 2; + $batchData['verify_remark'] = '该游戏发放功能暂未实现'; + M('testing_resource_batch', 'tab_')->where(['id' => $batch['id']])->save($batchData); + + throw new \Exception('该游戏发放功能暂未实现'); + } + + $batchData['verify_status'] = 1; + $batchData['verify_remark'] = '审核成功'; + M('testing_resource_batch', 'tab_')->where(['id' => $batch['id']])->save($batchData); + } + + public function provide($batch) + { + if ($batch['provide_status'] != 0) { + throw new \Exception('发放状态异常'); + } + + $role = M('user_play_info', 'tab_') + ->field(['id', 'role_id', 'user_id', 'promote_id']) + ->where(['game_id' => $batch['game_id'], 'role_id' => $batch['role_id']]) + ->find(); + $orders = M('testing_resource_order', 'tab_') + ->where(['batch_id' => $batch['id']]) + ->select(); + + $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; + } + $provideAmount += round($order['ref_amount'] * $order['num'], 2); + $orderData['provide_status'] = 1; + $orderData['provide_time'] = time(); + M('testing_resource_order', 'tab_') + ->where(['id' => $order['id']]) + ->save($orderData); + } + + $batchData = []; + if ($hasError) { + $batchData['provide_status'] = 2; + } + $batchData['provide_time'] = time(); + $batchData['provide_amount'] = $provideAmount; + $batchData['update_time'] = time(); + M('testing_resource_batch', 'tab_') + ->where(['id' => $batch['id']]) + ->save($batchData); + } + + public function provideFromGameCat($order, $role) + { + $gameCatClient = new GameCatClient(); + $result = $gameCatClient->api('provide', [ + 'roleId' => $role['role_id'], + 'amount' => $order['ref_amount'], + 'supportItem' => $order['ref_id'], + 'supportType' => 0, + 'channelUid' => $role['user_id'], + 'applyRemark' => $order['remark'], + 'applyId' => $order['order_no'], + 'device_type' => $deviceType, + ]); + if ($result['code'] == 1 && $result['data']) { + return [ + 'status' => true, + 'message' => $result['message'], + 'code' => 1, + ]; + } else { + return [ + 'status' => false, + 'message' => $result['message'], + 'code' => $result['code'], + ]; + } + } +} \ No newline at end of file diff --git a/Application/Base/Service/UserService.class.php b/Application/Base/Service/UserService.class.php index b6ff8f27b..f0d680ed1 100644 --- a/Application/Base/Service/UserService.class.php +++ b/Application/Base/Service/UserService.class.php @@ -3,7 +3,8 @@ namespace Base\Service; use Base\Facade\Request; -class UserService { +class UserService +{ public function isAccountExist($account) { diff --git a/Application/Base/Tool/GameCatClient.class.php b/Application/Base/Tool/GameCatClient.class.php index 11e2bd73d..60b9dbdcb 100644 --- a/Application/Base/Tool/GameCatClient.class.php +++ b/Application/Base/Tool/GameCatClient.class.php @@ -17,7 +17,7 @@ class GameCatClient private $apis = [ 'get-pay-type' => ['uri' => '/game/support/items/v1', 'method' => 'post'], - 'internal-pay' => ['uri' => '/game/support/provide/v1', 'method' => 'post'], + 'provide' => ['uri' => '/game/support/provide/v1', 'method' => 'post'], ]; private $appIds = [ @@ -58,7 +58,7 @@ class GameCatClient return $this->request($api, $params); } catch (\Exception $e) { $env = C('APP_ENV', null, 'prod'); - return ['code' => '1000', 'message' => '接口请求错误。' . ($env == 'prod' ? '' : $e->getMessage()) , 'data' => []]; + return ['code' => 1000, 'state' => 1000, 'message' => '接口请求错误。' . ($env == 'prod' ? '' : $e->getMessage()) , 'data' => []]; } } diff --git a/Application/Home/Controller/TestingResourceController.class.php b/Application/Home/Controller/TestingResourceController.class.php index acd709c92..8b3a16931 100644 --- a/Application/Home/Controller/TestingResourceController.class.php +++ b/Application/Home/Controller/TestingResourceController.class.php @@ -8,6 +8,7 @@ use Base\Service\PromoteService; use OSS\Core\OssException; use Base\Tool\GameCatClient; use Think\Model; +use Base\Service\TestingResourceService; class TestingResourceController extends BaseController { @@ -261,17 +262,7 @@ class TestingResourceController extends BaseController } } - $provideStatusList = [ - '0' => '待发放', - '1' => '已发放', - '2' => '拒绝', - '3' => '异常', - ]; - $verifyStatusList = [ - '0' => '未审核', - '1' => '审核通过', - '2' => '审核拒绝', - ]; + $testingResourceService = new TestingResourceService(); $records = []; foreach ($batches as $batch) { @@ -295,16 +286,17 @@ class TestingResourceController extends BaseController 'apply_amount' => $batch['apply_amount'], 'provide_amount' => $batch['provide_amount'], 'verify_status' => $batch['verify_status'], - 'verify_status_text' => $verifyStatusList[$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' => $provideStatusList[$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('provideStatusList', $provideStatusList); + $this->assign('verifyStatusList', TestingResourceService::$verifyStatusList); + $this->assign('provideStatusList', TestingResourceService::$provideStatusList); $this->assign('servers', $this->getServersByGameId($gameId)); $this->assign('games', $this->getGames()); $this->assign('count', $count); @@ -330,17 +322,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); - $provideStatusList = [ - '0' => '待发放', - '1' => '已发放', - '2' => '拒绝', - '3' => '异常', - ]; - $verifyStatusList = [ - '0' => '未审核', - '1' => '审核通过', - '2' => '审核拒绝', - ]; + $testingResourceService = new TestingResourceService(); foreach ($orders as $order) { $records[] = [ 'id' => $order['id'], @@ -356,10 +338,8 @@ class TestingResourceController extends BaseController 'num' => $order['num'], 'amount' => $order['num'] * $order['ref_amount'], 'remark' => $order['remark'], - 'verify_status' => $batch['provide_status'], - 'verify_status_text' => $verifyStatusList[$batch['verify_status']], - 'provide_status' => $batch['provide_status'], - 'provide_status_text' => $provideStatusList[$batch['provide_status']], + 'provide_status' => $order['provide_status'], + 'provide_status_text' => $testingResourceService->getProvideStatusText($order['provide_status']), ]; } @@ -375,8 +355,13 @@ class TestingResourceController extends BaseController ->where(['game_id' => $gameId, 'game_player_id' => $bindRoleId]) ->group('game_id,game_player_id') ->sum('pay_amount'); - $usedQuota = M('testing_resource_batch', 'tab_')->where(['game_id' => $gameId, 'role_id' => $testingRoleId])->sum('provide_amount'); - return round(floatval($totalQuota) - floatval($usedQuota), 2); + $providedQuota = M('testing_resource_batch', 'tab_') + ->where(['provide_status' => [in, [1, 2]], 'game_id' => $gameId, 'role_id' => $testingRoleId]) + ->sum('provide_amount'); + $providingQuota = M('testing_resource_batch', 'tab_') + ->where(['verify_status' => [in, [0, 1]], 'provide_status' => 0, 'game_id' => $gameId, 'role_id' => $testingRoleId]) + ->sum('provide_amount'); + return round(floatval($totalQuota) - floatval($providedQuota) - floatval($providingQuota), 2); } public function apply() @@ -709,14 +694,6 @@ class TestingResourceController extends BaseController private function getGameCatResources($deviceType) { - /* return [ - 1 => ['ref_id' => 1, 'name' => '礼包钻石6', 'amount' => 6], - 2 => ['ref_id' => 2, 'name' => '礼包钻石18', 'amount' => 18], - 3 => ['ref_id' => 3, 'name' => '礼包钻石30', 'amount' => 30], - 4 => ['ref_id' => 4, 'name' => '礼包钻石98', 'amount' => 98], - 5 => ['ref_id' => 5, 'name' => '礼包钻石128', 'amount' => 128], - 6 => ['ref_id' => 6, 'name' => '礼包钻石648', 'amount' => 648], - ]; */ $resources = []; $gameCatClient = new GameCatClient(); $result = $gameCatClient->api('get-pay-type', ['device_type' => $deviceType]); diff --git a/Application/Home/View/default/Public/promote_base.html b/Application/Home/View/default/Public/promote_base.html index 8c9a800f7..1067b8c35 100644 --- a/Application/Home/View/default/Public/promote_base.html +++ b/Application/Home/View/default/Public/promote_base.html @@ -114,10 +114,8 @@ 发放状态 发放时间 - 资源内容 + 操作 @@ -151,7 +151,7 @@
- {$record.content} + diff --git a/Data/update.sql b/Data/update.sql index a55f711b0..00504fb84 100644 --- a/Data/update.sql +++ b/Data/update.sql @@ -2457,9 +2457,11 @@ CREATE TABLE `tab_testing_resource_order` ( `ref_name` varchar(150) NOT NULL COMMENT '测试资源名称(第三方)', `ref_amount` decimal(12, 2) not null default '0.00' comment '测试资源价值(第三方)', `num` int(11) NOT NULL DEFAULT 0 COMMENT '申请数量', - `provide_status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '0 待发放 1 已经发放 2 拒绝 3 异常', + `provide_status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '0 待发放 1 已经发放 2 拒绝', + `provide_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '发放时间', `amount` decimal(12, 2) not null default '0.00' comment '申请金额', `remark` varchar(255) NOT NULL DEFAULT '' COMMENT '审核备注', + `result` varchar(255) NOT NULL DEFAULT '' COMMENT '发放结果', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -2472,10 +2474,10 @@ CREATE TABLE `tab_testing_resource_batch` ( `role_id` varchar(50) NOT NULL DEFAULT '' COMMENT '角色ID', `apply_amount` decimal(12, 2) not null default '0.00' comment '申请金额', `provide_amount` decimal(12, 2) not null default '0.00' comment '发放金额', - `provide_status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '0 待发放 1 已经发放 2 拒绝 3 异常', - `provide_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '审核时间', + `provide_status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '0 待发放 1 已经发放 2 异常', + `provide_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '发放时间', `apply_promote_id` int(11) NOT NULL DEFAULT '0' COMMENT '申请推广员ID', - `verify_status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '0 未审核 1 审核通过 1 未审核通过', + `verify_status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '0 未审核 1 审核通过 2 未审核通过', `verify_remark` varchar(255) NOT NULL DEFAULT '' COMMENT '审核备注', `verify_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '审核时间', `create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间',