From 670dd8f057b6d88b642eca5ee020a1760c89590c Mon Sep 17 00:00:00 2001 From: elf <360197197@qq.com> Date: Sun, 23 Apr 2023 00:18:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Base/Service/GameRebateService.class.php | 37 +----- ...lient.class.php => JhBaseClient.class.php} | 124 ++++++++++-------- .../Tool/GameResource/ZzylClient.class.php | 19 +++ 3 files changed, 95 insertions(+), 85 deletions(-) rename Application/Base/Tool/GameResource/{TzjClient.class.php => JhBaseClient.class.php} (61%) create mode 100644 Application/Base/Tool/GameResource/ZzylClient.class.php diff --git a/Application/Base/Service/GameRebateService.class.php b/Application/Base/Service/GameRebateService.class.php index 4911af1e9..49f3fa541 100644 --- a/Application/Base/Service/GameRebateService.class.php +++ b/Application/Base/Service/GameRebateService.class.php @@ -1,15 +1,7 @@ 'openSevenDay', ]; - public $rebateBaseGameIds = [70, 73, 75, 79, 81, 84, 91]; + public $rebateBaseGameIds = [11]; public function isGiftItemSend($order, $item) { @@ -120,29 +112,8 @@ class GameRebateService { $client = null; switch ($baseGameId) { - case 70: - $client = new XyyXmjsClient(); - break; - case 73: - $client = new SbcqClient(); - break; - case 75: - $client = new XlqyClient(); - break; - case 79: - $client = new ZxjClient(); - break; - case 81: - $client = new SlzqClient(); - break; - case 9: - $client = new XlqyClient(); - break; - case 84: - $client = new YjzxClient(); - break; - case 91: - $client = new MhxlClient(); + case 11: + $client = new ZzylClient(); break; default: throw new \Exception('客户端未实现'); diff --git a/Application/Base/Tool/GameResource/TzjClient.class.php b/Application/Base/Tool/GameResource/JhBaseClient.class.php similarity index 61% rename from Application/Base/Tool/GameResource/TzjClient.class.php rename to Application/Base/Tool/GameResource/JhBaseClient.class.php index a5cd0afa2..fb29b371c 100644 --- a/Application/Base/Tool/GameResource/TzjClient.class.php +++ b/Application/Base/Tool/GameResource/JhBaseClient.class.php @@ -6,30 +6,28 @@ use Base\Tool\PlatformLog; use GuzzleHttp\Client; use Think\Log; -/** - * 天之禁2-测试资源接口 - */ -class TzjClient +abstract class JhBaseClient { const SIGN_NAME = 'sign'; const SUCCESS = 1; + protected $baseUri; protected $key; protected $brAppId; protected $brPCode; protected $client; - private $apis = [ + protected $apis = [ 'mail' => ['url' => '/wf/m/mail/brRom/1/brPCode/{brPCode}/brAppId/{brAppId}', 'method' => 'post'], 'prop' => ['url' => '/wf/m/prop/brRom/1/brPCode/{brPCode}/brAppId/{brAppId}', 'method' => 'post'], 'pay' => ['url' => '/wf/m/pay/brRom/1/brPCode/{brPCode}/brAppId/{brAppId}', 'method' => 'post'], ]; - public function __construct($game = null) + public function __construct() { $this->client = new Client([ - 'base_uri' => 'http://club.game.267zf.com', + 'base_uri' => $this->baseUri, 'timeout' => 10.0, ]); } @@ -112,25 +110,70 @@ class TzjClient public function apply($order, $role) { + $data = [ 'userId' => $role['user_id'], 'roleId' => $role['role_id'], 'serverId' => $role['server_id'], - 'orderNum' => $order['order_no'], + 'orderNum' => $this->generateOrderNumber($order), + 'moneyFen' => $order['amount'], 'time' => time(), ]; - - $refId = $order['ref_id']; - $api = ''; - if ($api == 'mail') { - $data['mailData'] = $refId; - } elseif ($api == 'prop') { - $data['propData'] = $refId; - } elseif ($api == 'pay') { - $data['moneyFen'] = intval($order['ref_amount'] * 100); + } + + public function sendProps($order) + { + $props = []; + $order['props'] = json_decode($order['props'], true); + foreach ($order['props'] as $prop) { + $props[] = [ + 'propId' => $prop['ref_id'], + 'count' => $prop['num'], + ]; } + $data = [ + 'userId' => $order['user_id'], + 'roleId' => $order['role_id'], + 'serverId' => $order['server_id'], + 'orderNum' => $this->generateOrderNumber($order), + 'propData' => $props, + 'time' => time(), + ]; + $result = $this->api('prop', $data); + return $this->getCommonResult($result, 200); + } - $result = $this->api($api, $data); + public function sendGold($gold, $order) + { + $data = [ + 'userId' => $order['user_id'], + 'roleId' => $order['role_id'], + 'serverId' => $order['server_id'], + 'orderNum' => $this->generateOrderNumber($order), + 'moneyFen' => $gold, + 'time' => time(), + ]; + + $result = $this->api('pay', $data); + return $this->getCommonResult($result); + } + + public function sendEmail($giftItem, $order) + { + $data = [ + 'userId' => $order['user_id'], + 'roleId' => $order['role_id'], + 'serverId' => $order['server_id'], + 'orderNum' => $this->generateOrderNumber($order, $giftItem['index']), + 'mailData' => [$giftItem['id']], + 'time' => time(), + ]; + + $result = $this->api('mail', $data); + return $this->getCommonResult($result); + } + + protected function getCommonResult($result) { if ($result == self::SUCCESS) { return [ 'status' => true, @@ -146,47 +189,24 @@ class TzjClient } } + protected function generateOrderNumber($order, $index = 0) + { + $length = 8 - strlen(strval($order['id'])); + $indexLength = 3 - strlen(strval($index)); + return date('Ymd') . str_repeat('0', $length) . $order['id'] . str_repeat('0', $indexLength) . $index; + } + public function getResourceTypes($deviceType) { - if ($deviceType == 'andriod') { - return [ - ['id' => 1, 'name' => '邮件', 'device_type' => 'andriod'], - ['id' => 2, 'name' => '道具', 'device_type' => 'andriod'], - ['id' => 3, 'name' => '元宝', 'device_type' => 'andriod'], - ]; - } elseif ($deviceType == 'ios') { - return [ - ['id' => 1, 'name' => '邮件', 'device_type' => 'andriod'], - ['id' => 2, 'name' => '道具', 'device_type' => 'andriod'], - ['id' => 3, 'name' => '元宝', 'device_type' => 'andriod'], - ]; - } + return []; } public function getResources($typeId, $deviceType) { - if ($typeId == 3) { - return [ - 1 => ['ref_id' => 1, 'name' => '6元宝', 'amount' => 6], - 2 => ['ref_id' => 2, 'name' => '30元宝', 'amount' => 30], - 3 => ['ref_id' => 3, 'name' => '98元宝', 'amount' => 98], - // 4 => ['ref_id' => 4, 'name' => '128元宝', 'amount' => 128], - 5 => ['ref_id' => 5, 'name' => '198元宝', 'amount' => 198], - 6 => ['ref_id' => 6, 'name' => '328元宝', 'amount' => 328], - 7 => ['ref_id' => 7, 'name' => '648元宝', 'amount' => 648], - 8 => ['ref_id' => 8, 'name' => '1000元宝', 'amount' => 1000], - 9 => ['ref_id' => 9, 'name' => '2000元宝', 'amount' => 2000], - // 10 => ['ref_id' => 10, 'name' => '3000元宝', 'amount' => 3000], - 11 => ['ref_id' => 11, 'name' => '5000元宝', 'amount' => 5000], - // 12 => ['ref_id' => 12, 'name' => '10000元宝', 'amount' => 10000], - // 13 => ['ref_id' => 13, 'name' => '20000元宝', 'amount' => 20000], - ]; - } else { - return []; - } + return []; } - public function log($message, $level = Log::INFO) { - PlatformLog::write($message, 'game_api/tzj', $level); + protected function log($message, $level = Log::INFO) { + PlatformLog::write($message, 'game_api/jh_base', $level); } } \ No newline at end of file diff --git a/Application/Base/Tool/GameResource/ZzylClient.class.php b/Application/Base/Tool/GameResource/ZzylClient.class.php new file mode 100644 index 000000000..ababc4402 --- /dev/null +++ b/Application/Base/Tool/GameResource/ZzylClient.class.php @@ -0,0 +1,19 @@ +