From 6422a83e2104091c716a3f1a9e7b8f3a4cb9a3aa Mon Sep 17 00:00:00 2001 From: songliang Date: Wed, 7 Jun 2023 12:59:10 +0800 Subject: [PATCH 01/20] ... --- webapp/controller/ShopController.class.php | 253 +++++++++++++++++++++ 1 file changed, 253 insertions(+) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 151f655d..1f264daa 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -48,6 +48,59 @@ class ShopController extends BaseAuthedController const WEEKLY_BUY_LIMIT = 2; const TOTAL_BUY_LIMIT = 3; + public function _handlePre() + { +// if (SERVER_ENV == _ONLINE) { +// if (getReqVal('client_uuid', '') != '499af8a0-a1bc-0b0e-dc79-a42cb3f103dc') { +// if ((getReqVal('c', '') != 'Battle')) { +// phpcommon\sendError(1001, 'session expiration'); +// die(); +// } +// } +// } + + if (getReqVal('c', '') == 'Shop' && getReqVal('a', '') == 'buyGoodsDirect') { + $this->_userLvRestriction(); + return; + } + + $this->accountId = getReqVal('account_id', ''); + $this->sessionId = getReqVal('session_id', ''); + if (!phpcommon\isValidSessionId($this->accountId, + $this->sessionId)) { + phpcommon\sendError(500, 'invalid session_id'); + die(); + } + if (!(getReqVal('c', '') == 'User' && getReqVal('a', '') == 'login')) { + if ((getReqVal('c', '') == 'Battle')) { + return; + } + $r = $this->_getRedis($this->_getAccountId()); + $sessionId = $r->get(LAST_SESSION_KEY . $this->_getAccountId()); + if (empty($sessionId)) { + $this->updateSession(myself()->_getAccountId(), + myself()->_getSessionId()); + } else if ($sessionId != $this->_getSessionId()) { + error_log('session expiration' . json_encode( + $_REQUEST + )); + phpcommon\sendError(1001, 'session expiration'); + die(); + } + + $this->_userLvRestriction(); + } + + /*if (SERVER_ENV == _ONLINE) { + if (phpcommon\cmpVersion(getReqVal('_version', ''), '0.2.0') > 0) { + if (!$this->isWhiteList() || myself()->_getChannel() != BC_CHANNEL) { + phpcommon\sendError(1002, ''); + die(); + } + } + }*/ + } + public function getGoodsList() { $goodsList = mt\ShopGoods::all(); @@ -248,6 +301,206 @@ class ShopController extends BaseAuthedController } } + public function buyGoodsDirect() + { + $id = getReqVal('id', 0); + $token_type = getReqVal('token_type', ''); + $goods_num = getReqVal('goods_num', 0); + + $row = mt\ShopGoods::get($id); + + $desired_token_type = $row['token_type']; + $check_token_type = splitStr1($desired_token_type); + $token_pos = array_search($token_type, $check_token_type, true); + if (!in_array($token_type, $check_token_type)) { + $this->_rspErr(1, "token_type parameter error, desired_token_type: {$desired_token_type}"); + return; + } + + if ($goods_num > $row['max_amount']) { + $this->_rspErr(1, "goods_num parameter error, max_amount: {$row['max_amount']}"); + return; + } + + // 这里命名混乱了, 购买个数,一捆个数命名冲突 + $goods_count = $row['goods_num']; + + $buyRecordHash = ShopBuyRecord::allToHash(); + $boughtTimes = 1; + switch ($row['limit_type']) { + case ShopController::DAILY_BUY_LIMIT: { + $buyRecord = getXVal($buyRecordHash, $id); + $boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1 : 1; + if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $row['limit_num']) { + $this->_rspErr(2, 'Has reached the maximum number of purchase restrictions today'); + return; + } + if ($row['limit_num'] <= 0) { + $this->_rspErr(2, 'The maximum number of purchase restrictions has been reached'); + return; + } + } + break; + case ShopController::WEEKLY_BUY_LIMIT: { + $buyRecord = getXVal($buyRecordHash, $id); + $boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1; + if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $row['limit_num']) { + $this->_rspErr(2, 'The maximum number of purchase restrictions this week has been reached'); + return; + } + if ($row['limit_num'] <= 0) { + $this->_rspErr(2, 'The maximum number of purchase restrictions has been reached'); + return; + } + } + break; + case ShopController::TOTAL_BUY_LIMIT: { + $buyRecord = getXVal($buyRecordHash, $id); + $boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1; + if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $row['limit_num']) { + $this->_rspErr(2, 'The maximum number of purchase restrictions has been reached'); + return; + } + if ($row['limit_num'] <= 0) { + $this->_rspErr(2, 'he maximum number of purchase restrictions has been reached'); + return; + } + } + break; + default: { + } + break; + } + + $price_array = splitStr1($row['price']); + $discount_array = splitStr1($row['discount']); + + $need_price = $price_array[$token_pos]; + $discount = $discount_array[$token_pos]; + + $discount_begin = strtotime($row['discount_begin'] . ' UTC'); + $discount_end = strtotime($row['discount_end'] . ' UTC'); + $nowTime = $this->_getNowTime(); + + if ($nowTime >= $discount_begin && $nowTime < $discount_end) { + + $need_price = ceil($need_price * ($discount / 100.0)); + } + + $costItemId = $this->getCostItemIdByTokenType($token_type); + + switch ($token_type) { + case ShopController::TOKEN_TYPE_CEG: + case ShopController::TOKEN_TYPE_CEC: + $costItems = $this->makeCostItems($costItemId, $goods_num * $need_price); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); + return; + } + + $itemMeta = mt\Item::get($row['goods_id']); + $propertyChgService = new services\PropertyChgService(); + for ($i = 0; $i < $goods_num; $i++) { + $this->internalAddItem($propertyChgService, $itemMeta, $goods_count); + } + $awardService = new services\AwardService(); + $awardService->addItem($row['goods_id'], $goods_num); + ShopBuyRecord::add($id, $goods_num); + $this->_decItems($costItems); + $goodsDto = array( + 'goods_id' => $id, + 'item_id' => $row['goods_id'], + 'price_info' => array( + 'item_id' => $row['goods_id'], + 'cost_list' => array(), + 'discount_begin_time' => phpcommon\datetimeToTimestamp($row['discount_begin']), + 'discount_end_time' => phpcommon\datetimeToTimestamp($row['discount_end']) + ), + 'flag_icon' => $row['tag'], + 'limit_type' => $row['limit_type'], + 'bought_times' => $boughtTimes, + 'total_buy_times' => $row['limit_num'], + ); { + $priceInfo = mt\Item::getPriceInfo($itemMeta); + if (!empty($priceInfo)) { + $goodsDto['price_info'] = $priceInfo['price_info']; + } + } + $propertyChgService->addUserChg(); + $this->_rspData( + array( + 'award' => $awardService->toDto(), + 'property_chg' => $propertyChgService->toDto(), + 'goods_chg' => $goodsDto + ) + ); + break; + + case ShopController::TOKEN_TYPE_BCEG: + break; + + case ShopController::TOKEN_TYPE_USDT: + case ShopController::TOKEN_TYPE_USDC: + + $itemMeta = mt\Item::get($row['goods_id']); + $propertyChgService = new services\PropertyChgService(); + for ($i = 0; $i < $goods_num; $i++) { + $this->internalAddItem($propertyChgService, $itemMeta, $goods_count); + } + $awardService = new services\AwardService(); + $awardService->addItem($row['goods_id'], $goods_num); + ShopBuyRecord::add($id, $goods_num); + + $goodsDto = array( + 'goods_id' => $id, + 'item_id' => $row['goods_id'], + 'price_info' => array( + 'item_id' => $row['goods_id'], + 'cost_list' => array(), + 'discount_begin_time' => phpcommon\datetimeToTimestamp($row['discount_begin']), + 'discount_end_time' => phpcommon\datetimeToTimestamp($row['discount_end']) + ), + 'flag_icon' => $row['tag'], + 'limit_type' => $row['limit_type'], + 'bought_times' => $boughtTimes, + 'total_buy_times' => $row['limit_num'], + ); { + $priceInfo = mt\Item::getPriceInfo($itemMeta); + if (!empty($priceInfo)) { + $goodsDto['price_info'] = $priceInfo['price_info']; + } + } + $propertyChgService->addUserChg(); + + $aa = $awardService->toDto(); + $bb = $propertyChgService->toDto(); + $cc = $goodsDto; + + $this->_rspData( + array( + 'award' => $aa, + 'property_chg' => $bb, + 'goods_chg' => $cc + ) + ); + + // $this->_rspData( + // array( + // 'award' => $awardService->toDto(), + // 'property_chg' => $propertyChgService->toDto(), + // 'goods_chg' => $goodsDto + // ) + // ); + break; + case ShopController::TOKEN_TYPE_BUSD: + case ShopController::TOKEN_TYPE_MATIC: + case ShopController::TOKEN_TYPE_BNB: + default: + $this->_rspErr(1, "token_type is unsupport, {$token_type}"); + } + } + private function getCostItemIdByTokenType($token_type) { switch ($token_type) { From c12d585d8c63ce5208a0c36c9901fb78fdf42d94 Mon Sep 17 00:00:00 2001 From: songliang Date: Wed, 7 Jun 2023 13:51:45 +0800 Subject: [PATCH 02/20] ... --- doc/Shop.py | 16 +++ .../controller/BaseAuthedController.class.php | 4 +- webapp/controller/ShopController.class.php | 108 ++++++++---------- 3 files changed, 68 insertions(+), 60 deletions(-) diff --git a/doc/Shop.py b/doc/Shop.py index eb20a346..ec2c3f7e 100644 --- a/doc/Shop.py +++ b/doc/Shop.py @@ -96,5 +96,21 @@ class Shop(object): ['goods_chg', _common.NewGoods(), '购买后更新商品的最新信息(可能为null客户端需要做容错处理)'], ] }, + { + 'name': 'buyGoodsDirect', + 'desc': '直接购买(充值,gold)', + 'group': 'Shop', + 'url': 'webapp/index.php?c=Shop&a=buyGoodsDirect', + 'params': [ + _common.ReqHead(), + ['id', 0, '商品唯一id,参见shopGoods表'], + ['token_type', '', "选用币种"], + ['goods_num', 0, '商品数量'], + ], + 'response': [ + _common.RspHead(), + ] + }, + ] diff --git a/webapp/controller/BaseAuthedController.class.php b/webapp/controller/BaseAuthedController.class.php index e435fd0a..7323e755 100644 --- a/webapp/controller/BaseAuthedController.class.php +++ b/webapp/controller/BaseAuthedController.class.php @@ -35,7 +35,7 @@ use models\Chip; class BaseAuthedController extends BaseController { - private $accountId = ''; + protected $accountId = ''; private $sessionId = ''; private $mysqlConn = null; private $address = null; @@ -106,7 +106,7 @@ class BaseAuthedController extends BaseController { }*/ } - private function _userLvRestriction(){ + protected function _userLvRestriction(){ $userDb = $this->_getOrmUserInfo(); $controller = getReqVal('c', ''); switch ($controller){ diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 1f264daa..58146cbf 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -50,24 +50,27 @@ class ShopController extends BaseAuthedController public function _handlePre() { -// if (SERVER_ENV == _ONLINE) { -// if (getReqVal('client_uuid', '') != '499af8a0-a1bc-0b0e-dc79-a42cb3f103dc') { -// if ((getReqVal('c', '') != 'Battle')) { -// phpcommon\sendError(1001, 'session expiration'); -// die(); -// } -// } -// } - + // if (SERVER_ENV == _ONLINE) { + // if (getReqVal('client_uuid', '') != '499af8a0-a1bc-0b0e-dc79-a42cb3f103dc') { + // if ((getReqVal('c', '') != 'Battle')) { + // phpcommon\sendError(1001, 'session expiration'); + // die(); + // } + // } + // } + + $this->accountId = getReqVal('account_id', ''); if (getReqVal('c', '') == 'Shop' && getReqVal('a', '') == 'buyGoodsDirect') { $this->_userLvRestriction(); return; } - $this->accountId = getReqVal('account_id', ''); + // $this->accountId = getReqVal('account_id', ''); $this->sessionId = getReqVal('session_id', ''); - if (!phpcommon\isValidSessionId($this->accountId, - $this->sessionId)) { + if (!phpcommon\isValidSessionId( + $this->accountId, + $this->sessionId + )) { phpcommon\sendError(500, 'invalid session_id'); die(); } @@ -78,8 +81,10 @@ class ShopController extends BaseAuthedController $r = $this->_getRedis($this->_getAccountId()); $sessionId = $r->get(LAST_SESSION_KEY . $this->_getAccountId()); if (empty($sessionId)) { - $this->updateSession(myself()->_getAccountId(), - myself()->_getSessionId()); + $this->updateSession( + myself()->_getAccountId(), + myself()->_getSessionId() + ); } else if ($sessionId != $this->_getSessionId()) { error_log('session expiration' . json_encode( $_REQUEST @@ -452,46 +457,28 @@ class ShopController extends BaseAuthedController $awardService->addItem($row['goods_id'], $goods_num); ShopBuyRecord::add($id, $goods_num); - $goodsDto = array( - 'goods_id' => $id, - 'item_id' => $row['goods_id'], - 'price_info' => array( - 'item_id' => $row['goods_id'], - 'cost_list' => array(), - 'discount_begin_time' => phpcommon\datetimeToTimestamp($row['discount_begin']), - 'discount_end_time' => phpcommon\datetimeToTimestamp($row['discount_end']) - ), - 'flag_icon' => $row['tag'], - 'limit_type' => $row['limit_type'], - 'bought_times' => $boughtTimes, - 'total_buy_times' => $row['limit_num'], - ); { - $priceInfo = mt\Item::getPriceInfo($itemMeta); - if (!empty($priceInfo)) { - $goodsDto['price_info'] = $priceInfo['price_info']; - } - } - $propertyChgService->addUserChg(); - - $aa = $awardService->toDto(); - $bb = $propertyChgService->toDto(); - $cc = $goodsDto; + // $goodsDto = array( + // 'goods_id' => $id, + // 'item_id' => $row['goods_id'], + // 'price_info' => array( + // 'item_id' => $row['goods_id'], + // 'cost_list' => array(), + // 'discount_begin_time' => phpcommon\datetimeToTimestamp($row['discount_begin']), + // 'discount_end_time' => phpcommon\datetimeToTimestamp($row['discount_end']) + // ), + // 'flag_icon' => $row['tag'], + // 'limit_type' => $row['limit_type'], + // 'bought_times' => $boughtTimes, + // 'total_buy_times' => $row['limit_num'], + // ); { + // $priceInfo = mt\Item::getPriceInfo($itemMeta); + // if (!empty($priceInfo)) { + // $goodsDto['price_info'] = $priceInfo['price_info']; + // } + // } + // $propertyChgService->addUserChg(); - $this->_rspData( - array( - 'award' => $aa, - 'property_chg' => $bb, - 'goods_chg' => $cc - ) - ); - - // $this->_rspData( - // array( - // 'award' => $awardService->toDto(), - // 'property_chg' => $propertyChgService->toDto(), - // 'goods_chg' => $goodsDto - // ) - // ); + $this->_rspOk(); break; case ShopController::TOKEN_TYPE_BUSD: case ShopController::TOKEN_TYPE_MATIC: @@ -983,11 +970,16 @@ class ShopController extends BaseAuthedController } break; default: { - Bag::addItem($itemMeta['id'], $count); - $propertyChgService->addBagChg(); - // 充值就尝试开启首充活动 - if ($itemMeta['id'] == 10001) { - $this->beginFirstTupop(); + if ($this->_isVirtualItem($itemMeta['id'])) { + $this->_addVirtualItem($itemMeta['id'], $count, null, $propertyChgService); + $propertyChgService->addUserChg(); + // 充值就尝试开启首充活动 + if ($itemMeta['id'] == 10001) { + $this->beginFirstTupop(); + } + } else { + Bag::addItem($itemMeta['id'], $count); + $propertyChgService->addBagChg(); } } break; From e90035915b35d77f1f3943bf594ffef0e1a53e67 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 7 Jun 2023 14:54:27 +0800 Subject: [PATCH 03/20] 1 --- doc/BlockChain.py | 101 +- .../controller/BlockChainController.class.php | 910 +----------------- 2 files changed, 6 insertions(+), 1005 deletions(-) diff --git a/doc/BlockChain.py b/doc/BlockChain.py index 0f38918e..45c6cf0d 100644 --- a/doc/BlockChain.py +++ b/doc/BlockChain.py @@ -59,71 +59,10 @@ class BlockChain(object): ] }, { - 'name': 'active721Nft', - 'desc': '激活721nft', + 'name': 'mint', + 'desc': '激活nft', 'group': 'BlockChain', - 'url': 'webapp/index.php?c=BlockChain&a=active721Nft', - 'params': [ - ['type', 0, '1:英雄 2:枪械'], - ['uniid', 0, '唯一id'], - ], - 'response': [ - _common.RspHead(), - ['trans_id', '', '事务id'], - ['!params', [''], '合约参数列表'], - ] - }, - { - 'name': 'evolve721Nft', - 'desc': 'nft进阶(英雄,武器)', - 'group': 'BlockChain', - 'url': 'webapp/index.php?c=BlockChain&a=evolve721Nft', - 'params': [ - ['type', 0, '1:英雄 2:枪械'], - ['token_id1', 0, 'tokenid1'], - ['token_id2', 0, 'tokenid2'], - ], - 'response': [ - _common.RspHead(), - ['trans_id', '', '事务id'], - ['!params', [''], '合约参数列表'], - ] - }, - { - 'name': 'evolveChip', - 'desc': '芯片进阶', - 'group': 'BlockChain', - 'url': 'webapp/index.php?c=BlockChain&a=evolveChip', - 'params': [ - ['token_id1', 0, 'tokenid1'], - ['token_ids', '', 'tokenids材料id(|分割)'], - ], - 'response': [ - _common.RspHead(), - ['trans_id', '', '事务id'], - ['!params', [''], '合约参数列表'], - ] - }, - { - 'name': 'mintShardBatchUser', - 'desc': '碎片生成', - 'group': 'BlockChain', - 'url': 'webapp/index.php?c=BlockChain&a=mintShardBatchUser', - 'params': [ - ['item_uniid', 0, '道具唯一id'], - ['num', 0, '使用数量'], - ], - 'response': [ - _common.RspHead(), - ['trans_id', '', '事务id'], - ['!params', [''], '合约参数列表'], - ] - }, - { - 'name': 'shardMixByUser', - 'desc': '碎片合成', - 'group': 'BlockChain', - 'url': 'webapp/index.php?c=BlockChain&a=shardMixByUser', + 'url': 'webapp/index.php?c=BlockChain&a=mint', 'params': [ ['item_id', '', '指定的英雄id或者武器id'], ['token_ids', '', 'token_ids多个用|分割'], @@ -133,39 +72,5 @@ class BlockChain(object): ['trans_id', '', '事务id'], ['!params', [''], '合约参数列表'], ] - }, - { - 'name': 'pluginChipBatch', - 'desc': '批量装上芯片', - 'group': 'BlockChain', - 'url': 'webapp/index.php?c=BlockChain&a=pluginChipBatch', - 'params': [ - ['type', 0, '1:英雄 2:枪械'], - ['token_id', '', 'token_id'], - ['chip_ids', '', '需要卸下的chip token_ids多个用|分割'], - ['slot_ids', '', '槽位0-3多个用|分割'], - ], - 'response': [ - _common.RspHead(), - ['trans_id', '', '事务id'], - ['!params', [''], '合约参数列表'], - ] - }, - { - 'name': 'unplugChip', - 'desc': '卸下芯片', - 'group': 'BlockChain', - 'url': 'webapp/index.php?c=BlockChain&a=unplugChip', - 'params': [ - ['type', 0, '1:英雄 2:枪械'], - ['token_id', '', 'token_id'], - ['chip_ids', '', '需要卸下的chip token_ids多个用|分割'], - ['slot_ids', '', '槽位0-3多个用|分割'], - ], - 'response': [ - _common.RspHead(), - ['trans_id', '', '事务id'], - ['!params', [''], '合约参数列表'], - ] } ] diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index d5300edb..ecf3fdc7 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -69,82 +69,6 @@ class BlockChainController extends BaseAuthedController { )); } - public function active721Nft() - { - $type = getReqVal('type', 0); - $uniid = getReqVal('uniid', 0); - switch ($type) { - case 1: - { - $heroDb = Hero::find($uniid); - if (!$heroDb) { - myself()->_rspErr(1, 'hero not found'); - return; - } - if ($heroDb['token_id']) { - myself()->_rspErr(1, 'already activated'); - return; - } - $tokenId = $heroDb['active_token_id']; - if (!$tokenId) { - $tokenId = BuyRecord::genOrderId - ( - 2006, - phpcommon\BC_FUNC_CREATION, - myself()->_getNowTime(), - myself()->_getOpenId() - ); - Hero::Update($heroDb['hero_uniid'], - array( - 'active_token_id' => $tokenId, - 'active_count' => function () { - return 'active_count + 1'; - } - )); - } - $this->internalActivate721Nft($tokenId, Nft::HERO_TYPE, $heroDb['hero_uniid'], $heroDb['hero_id']); - } - break; - case 2: - { - $gunDb = Gun::find($uniid); - if (!$gunDb) { - myself()->_rspErr(1, 'gun not found'); - return; - } - if ($gunDb['token_id']) { - myself()->_rspErr(1, 'already activated'); - return; - } - $tokenId = $gunDb['active_token_id']; - if (!$tokenId) { - $tokenId = BuyRecord::genOrderId - ( - 2006, - phpcommon\BC_FUNC_CREATION, - myself()->_getNowTime(), - myself()->_getOpenId() - ); - Gun::Update($gunDb['gun_uniid'], - array( - 'active_token_id' => $tokenId, - 'active_count' => function () { - return 'active_count + 1'; - } - )); - } - $this->internalActivate721Nft($tokenId, Nft::EQUIP_TYPE, $gunDb['gun_uniid'], $gunDb['gun_id']); - } - break; - default: - { - myself()->_rspErr(1, 'type param error'); - return; - } - break; - } - } - public function reportResult() { $transId = getReqVal('trans_id', ''); @@ -154,666 +78,8 @@ class BlockChainController extends BaseAuthedController { myself()->_rspOk(); } - public function evolve721Nft() + public function getJumpInfo() { - error_log(json_encode($_REQUEST)); - $type = getReqVal('type', ''); - $tokenId1 = getReqVal('token_id1', ''); - $tokenId2 = getReqVal('token_id2', ''); - switch ($type) { - case 1: - { - $nft1 = Hero::findByTokenId($tokenId1); - $nft2 = Hero::findByTokenId($tokenId2); - if (!$nft1 || !$nft2) { - myself()->_rspErr(1, 'token paramater error'); - return; - } - //CEG扣除 - { - $costItems = array( - array( - 'item_id' => V_ITEM_GOLD, - 'item_num' => \services\FormulaService::Hero_Advanced_CEG_Expend($nft1['quality']+1) - ), - array( - 'item_id' => V_ITEM_DIAMOND, - 'item_num' => \services\FormulaService::Hero_Advanced_CEC_Expend($nft1['quality']+1) - ) - ); - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); - return; - } - $decFeeCb = function ($transId) use ($costItems){ - myself()->_decItems($costItems); - foreach ($costItems as $costItem){ - TransactionPrefee::add($transId,$costItem); - } - }; - } - //英雄进阶概率 - $rnd = rand(1, 100); - $probability = \services\FormulaService::Hero_Advanced_Probability($nft1['quality'] + 1)*100; - if ($rnd > $probability) { - $result = 0; - }else{ - $result = 1; - } - error_log( - json_encode( - array( - 'NftEvent'=> 'Hero', - 'nft' => $nft1, - 'probability' => $probability, - 'result' => $result - ) - ) - ); - $this->internalBcCall( - array( - 'c' => 'BcService', - 'a' => 'evolve721Nft', - 'account_id' => myself()->_getAccountId(), - 'session_id' => myself()->_getSessionId(), - 'account' => myself()->_getOpenId(), - 'type' => $type, - 'token_id1' => $tokenId1, - 'token_id2' => $tokenId2 - ), - array( - 'action' => Transaction::EVOLVE_721_ACTION_TYPE, - 'tokenId' => $nft1['token_id'], - 'tokenType' => Nft::HERO_TYPE, - 'itemUniId' => $nft1['hero_uniid'], - 'itemId' => $nft1['hero_id'], - 'result' => $result, - ), - $decFeeCb - ); - } - break; - case 2: - { - $nft1 = Gun::findByTokenId($tokenId1); - $nft2 = Gun::findByTokenId($tokenId2); - if (!$nft1 || !$nft2) { - myself()->_rspErr(1, 'token paramater error'); - return; - } - //CEG扣除 - { - $costItems = array( - array( - 'item_id' => V_ITEM_GOLD, - 'item_num' => \services\FormulaService::Weapon_Advanced_CEG_Expend($nft1['quality']+1) - ), - array( - 'item_id' => V_ITEM_DIAMOND, - 'item_num' => \services\FormulaService::Weapon_Advanced_CEC_Expend($nft1['quality']+1) - ) - ); - - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); - return; - } - $decFeeCb = function ($transId) use ($costItems){ - myself()->_decItems($costItems); - foreach ($costItems as $costItem){ - TransactionPrefee::add($transId,$costItem); - } - }; - } - //武器进阶概率 - $rnd = rand(1, 100); - $probability = \services\FormulaService::Weapon_Advanced_Probability($nft1['quality'] + 1)*100; - if ($rnd > $probability) { - $result = 0; - }else{ - $result = 1; - } - error_log( - json_encode( - array( - 'NftEvent'=> 'Gun', - 'nft' => $nft1, - 'probability' => $probability, - 'result' => $result - ) - ) - ); - - $this->internalBcCall( - array( - 'c' => 'BcService', - 'a' => 'evolve721Nft', - 'account_id' => myself()->_getAccountId(), - 'session_id' => myself()->_getSessionId(), - 'account' => myself()->_getOpenId(), - 'type' => $type, - 'token_id1' => $tokenId1, - 'token_id2' => $tokenId2 - ), - array( - 'action' => Transaction::EVOLVE_721_ACTION_TYPE, - 'tokenId' => $nft1['token_id'], - 'tokenType' => Nft::EQUIP_TYPE, - 'itemUniId' => $nft1['gun_uniid'], - 'itemId' => $nft1['gun_id'], - 'result' => $result, - ), - $decFeeCb - ); - } - break; - default: - { - myself()->_rspErr(1, 'type param error'); - return; - } - } - } - - public function evolveChip() - { - $tokenId1 = getReqVal('token_id1', ''); - $tokenIds = explode('|', getReqVal('token_ids', '')); - - if (in_array($tokenId1, $tokenIds) || count($tokenIds) <= 0) { - myself()->_rspErr(1, 'token_ids paramater error'); - return; - } - - $nftDb = Chip::findByTokenId($tokenId1); - if (!$nftDb) { - myself()->_rspErr(1, 'token_id1 paramater error'); - return; - } - //芯片进阶概率 - $upgrade_cost = \services\FormulaService::getChipUpgradeCost($nftDb['chip_grade']+1); - if ($upgrade_cost==0){ - $this->_rspErr(1, 'token_id1 Error in calculation formula'); - return; - } - $cumulative_cost = 0; - foreach ($tokenIds as $val){ - $chip_param = Chip::findByTokenId($val); - $cumulative_cost += \services\FormulaService::getChipCumulativeCost($chip_param['chip_grade']); - } - $rnd = rand(1,100); - $probability = $cumulative_cost/$upgrade_cost * 100; - if ($rnd > $probability) { - $result = 0; - }else{ - $result = 1; - } - error_log( - json_encode( - array( - 'NftEvent'=> 'Chip', - 'nft' => $nftDb, - 'upgrade_cost' => $upgrade_cost, - 'cumulative_cost' => $cumulative_cost, - 'probability' => $probability, - 'result' => $result - ) - ) - ); - - $this->internalBcCall( - array( - 'c' => 'BcService', - 'a' => 'evolveChip', - 'account_id' => myself()->_getAccountId(), - 'session_id' => myself()->_getSessionId(), - 'account' => myself()->_getOpenId(), - 'token_id' => $tokenId1, - 'token_ids' => implode('|', $tokenIds) - ), - array( - 'action' => Transaction::EVOLVE_CHIP_ACTION_TYPE, - 'tokenId' => $tokenId1, - 'tokenType' => 0, - 'itemUniId' => $nftDb['chip_uniid'], - 'itemId' => $nftDb['item_id'], - 'result' => $result, - ) - ); - } - - public function mintShardBatchUser() - { - $itemUniId = getReqVal('item_uniid', 0); - $num = getReqVal('num', 0); - $itemDb = Bag::findByUniId($itemUniId); - if ($num <= 0) { - myself()->_rspErr(1, 'num paramater error'); - return; - } - error_log(json_encode( - $_REQUEST - )); - if (!$itemDb || $itemDb['item_num'] < $num) { - myself()->_rspErr(1, 'item not enough'); - return; - } - $itemMeta = mt\Item::get($itemDb['item_id']); - switch ($itemMeta['type']) { - case mt\Item::FRAGMENT_BOX_TYPE: - { - $this->internalOpenFragmentBox($itemDb, $itemMeta, $num); - } - break; - case mt\Item::CHIP_BOX_TYPE: - { - $this->internalOpenChipBox($itemDb, $itemMeta, $num); - } - break; - default: - { - myself()->_rspErr(1, 'item type error'); - return; - } - break; - } - } - - public function shardMixByUser() - { - $tokenIds = explode('|', getReqVal('token_ids', '')); - $itemId = getReqVal('item_id', ''); - - $tokenId = ''; - $tokenType = ''; - - { - $heros = array(); - $guns = array(); - $specHeros = array(); - $specGuns = array(); - mt\Item::groupFragment($tokenIds, $heros, $guns, $specHeros, $specGuns); - error_log(json_encode(array( - $tokenIds, - $heros, - $guns, - $specHeros, - $specGuns, - json_encode($_REQUEST) - ))); - if (count($tokenIds) != ( - count($heros) + count($guns) + count($specHeros) + count($specGuns) - )) { - myself()->_rspErr(101, 'token_ids paramater error'); - return; - } - if (count($specHeros) + count($specGuns) > 1) { - myself()->_rspErr(101, 'token_ids paramater error'); - return; - } - if (count($heros) > 0 && count($guns) > 0) { - myself()->_rspErr(101, 'token_ids paramater error'); - return; - } - if (count($heros) > 0) { - if (count($heros) != 8 || count($specGuns) > 0) { - myself()->_rspErr(101, 'token_ids paramater error'); - return; - } - $tokenType = Nft::HERO_TYPE; - } else if (count($guns) > 0) { - if (count($guns) != 8 || count($specHeros) > 0) { - myself()->_rspErr(101, 'token_ids paramater error'); - return; - } - $tokenType = Nft::EQUIP_TYPE; - } else { - myself()->_rspErr(101, 'token_ids paramater error'); - return; - } - } - - $tokenId = BuyRecord::genOrderId - ( - 2006, - phpcommon\BC_FUNC_CREATION, - myself()->_getNowTime(), - myself()->_getOpenId() - ); - //CEG扣除 - { - if ($tokenType == Nft::HERO_TYPE){ - $costItems = array( - array( - 'item_id' => V_ITEM_GOLD, - 'item_num' => 100 - ), - ); - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); - return; - } - $decFeeCb = function ($transId) use ($costItems){ - myself()->_decItems($costItems); - foreach ($costItems as $costItem){ - TransactionPrefee::add($transId,$costItem); - } - }; -// $this->_decItems($costItems); - } - if ($tokenType == Nft::EQUIP_TYPE){ - $costItems = array( - array( - 'item_id' => V_ITEM_GOLD, - 'item_num' => 30 - ), - ); - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); - return; - } - $decFeeCb = function ($transId) use ($costItems){ - myself()->_decItems($costItems); - foreach ($costItems as $costItem){ - TransactionPrefee::add($transId,$costItem); - } - }; -// $this->_decItems($costItems); - } - } - - $params = array( - 'c' => 'BcService', - 'a' => 'shardMixByUser', - 'account_id' => myself()->_getAccountId(), - 'session_id' => myself()->_getSessionId(), - 'account' => myself()->_getOpenId(), - 'token_id' => $tokenId, - 'token_type' => $tokenType, - 'item_id' => $itemId, - 'token_ids' => implode('|', $tokenIds) - ); - { - error_log(3333333); - $url = self::getWeb3ServiceUrl(); - $response = ''; - if (!phpcommon\HttpClient::get - ($url, - $params, - $response)) { - error_log(444444); - myself()->_rspErr(500, 'server internal error'); - return; - } - error_log($response); - $rspObj = json_decode($response, true); - if ($rspObj['errcode'] == 0) { - $transId = $rspObj['trans_id']; - Transaction::add( - $transId, - Transaction::SHARD_MIX_BY_USER_ACTION_TYPE, - $tokenId, - $tokenType, - 0, - $itemId, - 1 - ); - $propertyChgService = new services\PropertyChgService(); - $propertyChgService->addUserChg(); - $decFeeCb($transId); - myself()->_rspData(array( - 'trans_id' => $transId, - 'params' => $rspObj['params'], - 'property_chg' => $propertyChgService->toDto(), - )); - error_log(5555555555); - } else { - error_log(22222222222222); - myself()->_rspErr(500, 'server internal error'); - return; - } - } - } - - public function pluginChipBatch() - { - $type = getReqVal('type', ''); - $tokenId = getReqVal('token_id', ''); - $chipIds = explode('|', getReqVal('chip_ids', '')); - $slotIds = explode('|', getReqVal('slot_ids', '')); - - error_log(json_encode($_REQUEST)); - if (count($chipIds) != count($slotIds) || - count($chipIds) < 0) { - myself()->_rspErr(101, 'chip_ids paramater error'); - return; - } - - switch ($type) { - case 1: - { - $heroDb = Hero::findByTokenId($tokenId); - foreach ($chipIds as $chipId) { - $chipDb = Chip::findByTokenId($chipId); - if (!$chipDb) { - myself()->_rspErr(101, 'chip_ids paramater error'); - return; - } - } - if (!$heroDb) { - myself()->_rspErr(101, 'token_id paramater error'); - return; - } - - $this->internalBcCall( - array( - 'c' => 'BcService', - 'a' => 'pluginChip', - 'account_id' => myself()->_getAccountId(), - 'session_id' => myself()->_getSessionId(), - 'account' => myself()->_getOpenId(), - 'token_id' => $tokenId, - 'token_type' => Nft::HERO_TYPE, - 'chip_ids' => implode('|', $chipIds), - 'slot_ids' => implode('|', $slotIds), - ), - array( - 'action' => Transaction::PLUGIN_CHIP_ACTION_TYPE, - 'tokenId' => $tokenId, - 'tokenType' => Nft::HERO_TYPE, - 'itemUniId' => $heroDb['hero_uniid'], - 'itemId' => $heroDb['hero_id'], - 'result' => 1, - ) - ); - - } - break; - case 2: - { - $gunDb = Gun::findByTokenId($tokenId); - foreach ($chipIds as $chipId) { - $chipDb = Chip::findByTokenId($chipId); - if (!$chipDb) { - myself()->_rspErr(101, 'chip_ids paramater error'); - return; - } - } - if (!$gunDb) { - myself()->_rspErr(101, 'token_id paramater error'); - return; - } - - $this->internalBcCall( - array( - 'c' => 'BcService', - 'a' => 'pluginChip', - 'account_id' => myself()->_getAccountId(), - 'session_id' => myself()->_getSessionId(), - 'account' => myself()->_getOpenId(), - 'token_id' => $tokenId, - 'token_type' => Nft::EQUIP_TYPE, - 'chip_ids' => implode('|', $chipIds), - 'slot_ids' => implode('|', $slotIds), - ), - array( - 'action' => Transaction::PLUGIN_CHIP_ACTION_TYPE, - 'tokenId' => $tokenId, - 'tokenType' => Nft::EQUIP_TYPE, - 'itemUniId' => $gunDb['gun_uniid'], - 'itemId' => $gunDb['gun_id'], - 'result' => 1, - ) - ); - } - break; - default: - { - } - break; - } - } - - public function unplugChip() - { - $type = getReqVal('type', ''); - $tokenId = getReqVal('token_id', ''); - $chipIds = explode('|', getReqVal('chip_ids', '')); - $slotIds = explode('|', getReqVal('slot_ids', '')); - - if (count($chipIds) != count($slotIds) || - count($chipIds) < 0) { - myself()->_rspErr(101, 'chip_ids paramater error'); - return; - } - - //CEG扣除 - { - $costSum = 0; - foreach ($chipIds as $chipId){ - $chipDb = Chip::getChipByTokenId($chipId); - if ($chipDb){ - $tiliDiff = $chipDb['strength_max'] - $chipDb['strength']; - $costSum += \services\FormulaService::Chip_Demount_Mint($tiliDiff); - } - } - $decFeeCb = null; - if ($costSum > 0){ - $costItems = array( - array( - 'item_id' => V_ITEM_GOLD, - 'item_num' => $costSum - ), - ); - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); - return; - } - $decFeeCb = function ($transId) use ($costItems, $chipIds){ - myself()->_decItems($costItems); - error_log(json_encode($costItems)); - foreach ($costItems as $costItem){ - TransactionPrefee::add($transId,$costItem); - } - - foreach ($chipIds as $chipId){ - $chipDb = Chip::getChipByTokenId($chipId); - $items = array( - 'token_id' => $chipDb['token_id'], - 'token_type' => $chipDb['chip_type'], - 'item_id' => self::TEST_ITEM_ID, - 'item_num' => $chipDb['strength_max'] - $chipDb['strength'] - ); - Chip::update($chipId,array( - 'strength'=>$chipDb['strength_max'] - )); - TransactionPrefee::add($transId,$items); - } - }; - } - } - - switch ($type) { - case 1: - { - $heroDb = Hero::findByTokenId($tokenId); - if (!$heroDb) { - myself()->_rspErr(101, 'token_id paramater error'); - return; - } - - $this->internalBcCall( - array( - 'c' => 'BcService', - 'a' => 'unplugChip', - 'account_id' => myself()->_getAccountId(), - 'session_id' => myself()->_getSessionId(), - 'account' => myself()->_getOpenId(), - 'token_id' => $tokenId, - 'token_type' => Nft::HERO_TYPE, - 'chip_ids' => implode('|', $chipIds), - 'slot_ids' => implode('|', $slotIds), - ), - array( - 'action' => Transaction::UNPLUG_CHIP_ACTION_TYPE, - 'tokenId' => $tokenId, - 'tokenType' => Nft::HERO_TYPE, - 'itemUniId' => $heroDb['hero_uniid'], - 'itemId' => $heroDb['hero_id'], - 'result' => 1, - ), - $decFeeCb - ); - - } - break; - case 2: - { - $gunDb = Gun::findByTokenId($tokenId); - if (!$gunDb) { - myself()->_rspErr(101, 'token_id paramater error'); - return; - } - - $this->internalBcCall( - array( - 'c' => 'BcService', - 'a' => 'unplugChip', - 'account_id' => myself()->_getAccountId(), - 'session_id' => myself()->_getSessionId(), - 'account' => myself()->_getOpenId(), - 'token_id' => $tokenId, - 'token_type' => Nft::EQUIP_TYPE, - 'chip_ids' => implode('|', $chipIds), - 'slot_ids' => implode('|', $slotIds), - ), - array( - 'action' => Transaction::UNPLUG_CHIP_ACTION_TYPE, - 'tokenId' => $tokenId, - 'tokenType' => Nft::EQUIP_TYPE, - 'itemUniId' => $gunDb['gun_uniid'], - 'itemId' => $gunDb['gun_id'], - 'result' => 1, - ), - $decFeeCb - ); - } - break; - default: - { - myself()->_rspErr(101, 'type paramater error'); - return; - } - break; - } - } - - public function getJumpInfo(){ $transId = getReqVal('trans_id', ''); if (!$transId){ myself()->_rspErr(101, 'trans_id paramater error'); @@ -828,7 +94,8 @@ class BlockChainController extends BaseAuthedController { myself()->_rspData($data); } - public function getTransactionInfo(){ + public function getTransactionInfo() + { $transId = getReqVal('trans_id', ''); if (!$transId){ myself()->_rspErr(101, 'trans_id paramater error'); @@ -846,177 +113,6 @@ class BlockChainController extends BaseAuthedController { )); } - private function internalActivate721Nft($tokenId, $tokenType, $itemUniId, $itemId) - { - $params = array( - 'c' => 'BcService', - 'a' => 'activate721Nft', - 'account_id' => myself()->_getAccountId(), - 'session_id' => myself()->_getSessionId(), - 'account' => myself()->_getOpenId(), - 'token_id' => $tokenId, - 'token_type' => $tokenType, - 'item_uniid' => $itemUniId, - 'item_id' => $itemId - ); - { - $url = self::getWeb3ServiceUrl(); - $response = ''; - if (!phpcommon\HttpClient::get - ($url, - $params, - $response)) { - myself()->_rspErr(500, 'server internal error'); - die(); - return; - } - error_log($response); - $rspObj = json_decode($response, true); - if ($rspObj['errcode'] == 0) { - $transId = $rspObj['trans_id']; - Transaction::add( - $transId, - Transaction::MINT_721_ACTION_TYPE, - $tokenId, - $tokenType, - $itemUniId, - $itemId, - 1 - ); - myself()->_rspData(array( - 'trans_id' => $transId, - 'params' => $rspObj['params'] - )); - } else { - myself()->_rspErr(500, 'server internal error'); - return; - } - } - } - - private function internalOpenChipBox($itemDb, $itemMeta, $num) { - $tokenId = BuyRecord::genOrderId - ( - 2006, - phpcommon\BC_FUNC_CREATION, - myself()->_getNowTime(), - myself()->_getOpenId() - ); - $params = array( - 'c' => 'BcService', - 'a' => 'activate1155Nft', - 'account_id' => myself()->_getAccountId(), - 'session_id' => myself()->_getSessionId(), - 'account' => myself()->_getOpenId(), - 'token_id' => $tokenId, - 'item_uniid' => $itemDb['item_uniid'], - 'item_id' => $itemDb['item_id'], - 'num' => $num, - ); - { - $url = self::getWeb3ServiceUrl(); - $response = ''; - if (!phpcommon\HttpClient::get - ($url, - $params, - $response)) { - myself()->_rspErr(500, 'server internal error'); - die(); - return; - } - error_log($response); - $tokenType = Nft::CHIP_TYPE; - $rspObj = json_decode($response, true); - if ($rspObj['errcode'] == 0) { - $transId = $rspObj['trans_id']; - Transaction::add( - $transId, - Transaction::MINT_1155_ACTION_TYPE, - $tokenId, - Nft::CHIP_TYPE, - $itemDb['item_uniid'], - $itemDb['item_id'], - 1 - ); - Bag::decItemByUnIid($itemDb['item_uniid'], $num); - TransactionPrefee::add($transId, array( - 'item_uniid' => $itemDb['item_uniid'], - 'item_id' => $itemDb['item_id'], - 'item_num' => $num, - )); - $propertyChgService = new services\PropertyChgService(); - $propertyChgService->addBagChg(); - myself()->_rspData(array( - 'trans_id' => $transId, - 'params' => $rspObj['params'], - 'property_chg' => $propertyChgService->toDto() - )); - } else { - myself()->_rspErr(500, 'server internal error'); - return; - } - } - } - - private function internalOpenFragmentBox($itemDb, $itemMeta, $num) { - $tokenId = $itemMeta['include_item_id']; - $itemId = $itemMeta['include_item_id']; - $params = array( - 'c' => 'BcService', - 'a' => 'mintShardBatchUser', - 'account_id' => myself()->_getAccountId(), - 'session_id' => myself()->_getSessionId(), - 'account' => myself()->_getOpenId(), - 'token_id' => $tokenId, - 'item_uniid' => $itemDb['item_uniid'], - 'item_id' => $itemId, - 'num' => $num - ); - { - $url = self::getWeb3ServiceUrl(); - $response = ''; - if (!phpcommon\HttpClient::get - ($url, - $params, - $response)) { - myself()->_rspErr(500, 'server internal error'); - die(); - return; - } - error_log($response); - $tokenType = Nft::FRAGMENT_TYPE; - $rspObj = json_decode($response, true); - if ($rspObj['errcode'] == 0) { - $transId = $rspObj['trans_id']; - Transaction::add( - $transId, - Transaction::MINT_SHARD_BATCH_ACTION_TYPE, - $tokenId, - $tokenType, - $itemDb['item_uniid'], - $itemId, - 1 - ); - Bag::decItemByUnIid($itemDb['item_uniid'], $num); - TransactionPrefee::add($transId, array( - 'item_uniid' => $itemDb['item_uniid'], - 'item_id' => $itemDb['item_id'], - 'item_num' => $num, - )); - $propertyChgService = new services\PropertyChgService(); - $propertyChgService->addBagChg(); - myself()->_rspData(array( - 'trans_id' => $transId, - 'params' => $rspObj['params'], - 'property_chg' => $propertyChgService->toDto() - )); - } else { - myself()->_rspErr(500, 'server internal error'); - return; - } - } - } - private function internalBcCall($params, $transParams, $cb = null) { $propertyChgService = new services\PropertyChgService(); $propertyChgService->addUserChg(); From 293b30cb65f9d5fb6e818475ef0e55d257d750d0 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 7 Jun 2023 15:07:31 +0800 Subject: [PATCH 04/20] 1 --- webapp/controller/BaseAuthedController.class.php | 9 ++++++++- webapp/controller/BlockChainController.class.php | 3 +-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/webapp/controller/BaseAuthedController.class.php b/webapp/controller/BaseAuthedController.class.php index 7323e755..77cade55 100644 --- a/webapp/controller/BaseAuthedController.class.php +++ b/webapp/controller/BaseAuthedController.class.php @@ -165,10 +165,17 @@ class BaseAuthedController extends BaseController { return phpcommon\extractChannel($this->_getAccountId()); } - public function _getAddress(){ + public function _getAddress() + { return $this->_getOpenId(); } + public function _isValidAddress() + { + $address = $this->_getAddress(); + return !empty($address); + } + public function _getSessionId() { return $this->sessionId; diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index ecf3fdc7..ee5995d0 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -36,8 +36,7 @@ class BlockChainController extends BaseAuthedController { public function _handlePre() { parent::_handlePre(); - if (getReqVal('a', '') != 'getTransactionList' && - myself()->_getChannel() != BC_CHANNEL) { + if (getReqVal('a', '') != 'getTransactionList' && !myself()->_isValidAddress()) { die(json_encode(array( 'errcode' => 501, 'errmsg' => 'you are not a wallet user' From 0db0f994baff1b8e0ca4220b4d5a649eddfb7174 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 7 Jun 2023 15:48:19 +0800 Subject: [PATCH 05/20] 1 --- doc/BlockChain.py | 12 +-- sql/gamedb.sql | 2 + sql/migrate_230607_01.sql | 8 ++ .../controller/BlockChainController.class.php | 76 +++++++++++++++++++ 4 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 sql/migrate_230607_01.sql diff --git a/doc/BlockChain.py b/doc/BlockChain.py index 45c6cf0d..610fe762 100644 --- a/doc/BlockChain.py +++ b/doc/BlockChain.py @@ -59,18 +59,18 @@ class BlockChain(object): ] }, { - 'name': 'mint', - 'desc': '激活nft', + 'name': 'active721Nft', + 'desc': '激活721nft', 'group': 'BlockChain', - 'url': 'webapp/index.php?c=BlockChain&a=mint', + 'url': 'webapp/index.php?c=BlockChain&a=active721Nft', 'params': [ - ['item_id', '', '指定的英雄id或者武器id'], - ['token_ids', '', 'token_ids多个用|分割'], + ['type', 0, '1:英雄 2:枪械 3:芯片'], + ['uniid', '', '唯一id'], ], 'response': [ _common.RspHead(), ['trans_id', '', '事务id'], ['!params', [''], '合约参数列表'], ] - } + }, ] diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 452409bf..17f240c7 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -246,6 +246,8 @@ CREATE TABLE `t_chip` ( `state` int(11) NOT NULL DEFAULT '0' COMMENT '0:已购买 1:免费(GIFT标签)', `inlay_state` varchar(60) COMMENT '所镶嵌的芯片页id:1|2|3', `rand_attr` mediumblob COMMENT '随机属性', + `active_token_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'active_token_id', + `active_count` int(11) NOT NULL DEFAULT '0' COMMENT 'active_count', `activate` int(11) NOT NULL DEFAULT '0' COMMENT '是否激活 1:已初始激活', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', diff --git a/sql/migrate_230607_01.sql b/sql/migrate_230607_01.sql new file mode 100644 index 00000000..27e7e468 --- /dev/null +++ b/sql/migrate_230607_01.sql @@ -0,0 +1,8 @@ +begin; + +alter table t_chip add column `active_token_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'active_token_id'; +alter table t_chip add column `active_count` int(11) NOT NULL DEFAULT '0' COMMENT 'active_count'; + +insert into version (version) values(2023060701); + +commit; diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index ee5995d0..e7ecad32 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -112,6 +112,82 @@ class BlockChainController extends BaseAuthedController { )); } + public function active721Nft() + { + $type = getReqVal('type', 0); + $uniid = getReqVal('uniid', 0); + switch ($type) { + case 1: + { + $heroDb = Hero::find($uniid); + if (!$heroDb) { + myself()->_rspErr(1, 'hero not found'); + return; + } + if ($heroDb['token_id']) { + myself()->_rspErr(1, 'already activated'); + return; + } + $tokenId = $heroDb['active_token_id']; + if (!$tokenId) { + $tokenId = BuyRecord::genOrderId + ( + 2006, + phpcommon\BC_FUNC_CREATION, + myself()->_getNowTime(), + myself()->_getOpenId() + ); + Hero::Update($heroDb['hero_uniid'], + array( + 'active_token_id' => $tokenId, + 'active_count' => function () { + return 'active_count + 1'; + } + )); + } + $this->internalActivate721Nft($tokenId, Nft::HERO_TYPE, $heroDb['hero_uniid'], $heroDb['hero_id']); + } + break; + case 2: + { + $gunDb = Gun::find($uniid); + if (!$gunDb) { + myself()->_rspErr(1, 'gun not found'); + return; + } + if ($gunDb['token_id']) { + myself()->_rspErr(1, 'already activated'); + return; + } + $tokenId = $gunDb['active_token_id']; + if (!$tokenId) { + $tokenId = BuyRecord::genOrderId + ( + 2006, + phpcommon\BC_FUNC_CREATION, + myself()->_getNowTime(), + myself()->_getOpenId() + ); + Gun::Update($gunDb['gun_uniid'], + array( + 'active_token_id' => $tokenId, + 'active_count' => function () { + return 'active_count + 1'; + } + )); + } + $this->internalActivate721Nft($tokenId, Nft::EQUIP_TYPE, $gunDb['gun_uniid'], $gunDb['gun_id']); + } + break; + default: + { + myself()->_rspErr(1, 'type param error'); + return; + } + break; + } + } + private function internalBcCall($params, $transParams, $cb = null) { $propertyChgService = new services\PropertyChgService(); $propertyChgService->addUserChg(); From be38ed2e1bdba4ede2497a719018d08f64ac139f Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 7 Jun 2023 15:54:02 +0800 Subject: [PATCH 06/20] 1 --- .../controller/BlockChainController.class.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index e7ecad32..002002dc 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -179,6 +179,37 @@ class BlockChainController extends BaseAuthedController { $this->internalActivate721Nft($tokenId, Nft::EQUIP_TYPE, $gunDb['gun_uniid'], $gunDb['gun_id']); } break; + case 3: + { + $chipDb = Chip::find($uniid); + if (!$chipDb) { + myself()->_rspErr(1, 'chip not found'); + return; + } + if ($chipDb['token_id']) { + myself()->_rspErr(1, 'already activated'); + return; + } + $tokenId = $chipDb['active_token_id']; + if (!$tokenId) { + $tokenId = BuyRecord::genOrderId + ( + 2006, + phpcommon\BC_FUNC_CREATION, + myself()->_getNowTime(), + myself()->_getOpenId() + ); + Chip::Update($chipDb['chip_uniid'], + array( + 'active_token_id' => $tokenId, + 'active_count' => function () { + return 'active_count + 1'; + } + )); + } + $this->internalActivate721Nft($tokenId, Nft::CHIP_TYPE, $chipDb['chip_uniid'], $chipDb['item_id']); + } + break; default: { myself()->_rspErr(1, 'type param error'); From 966678fd568db1699a6c5e8b4ef42978713933cd Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 7 Jun 2023 15:58:22 +0800 Subject: [PATCH 07/20] 1 --- webapp/models/Transaction.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/webapp/models/Transaction.php b/webapp/models/Transaction.php index f6a9222e..b4b02954 100644 --- a/webapp/models/Transaction.php +++ b/webapp/models/Transaction.php @@ -152,6 +152,16 @@ class Transaction extends BaseModel { ); } break; + case Nft::EQUIP_CHIP: + { + $jumpInfo = array( + 'action' => 3,//武器激活(武器详情) + 'params' => array( + $transDb['token_id'] + ) + ); + } + break; } } From 7a00d8755c301f212b04dbff6d7cfbd5c0b22515 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 7 Jun 2023 16:01:54 +0800 Subject: [PATCH 08/20] 1 --- webapp/controller/BlockChainController.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index 002002dc..cb2dcffc 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -135,7 +135,7 @@ class BlockChainController extends BaseAuthedController { 2006, phpcommon\BC_FUNC_CREATION, myself()->_getNowTime(), - myself()->_getOpenId() + myself()->_getAddress() ); Hero::Update($heroDb['hero_uniid'], array( @@ -166,7 +166,7 @@ class BlockChainController extends BaseAuthedController { 2006, phpcommon\BC_FUNC_CREATION, myself()->_getNowTime(), - myself()->_getOpenId() + myself()->_getAddress() ); Gun::Update($gunDb['gun_uniid'], array( @@ -197,7 +197,7 @@ class BlockChainController extends BaseAuthedController { 2006, phpcommon\BC_FUNC_CREATION, myself()->_getNowTime(), - myself()->_getOpenId() + myself()->_getAddress() ); Chip::Update($chipDb['chip_uniid'], array( From 3293255b3c815c982f9517a2aafea36e9f4c7c2a Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 7 Jun 2023 16:07:19 +0800 Subject: [PATCH 09/20] 1 --- sql/gamedb.sql | 4 +++- sql/gamedb2006_migrate_230605_01.sql | 2 +- sql/migrate_230607_01.sql | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 17f240c7..4f4c7a2a 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -847,6 +847,7 @@ DROP TABLE IF EXISTS `t_transaction`; CREATE TABLE `t_transaction` ( `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', + `address` varchar(60) NOT NULL DEFAULT '' COMMENT 'address', `trans_id` varchar(255) NOT NULL DEFAULT '' COMMENT '事务id', `action` int(11) NOT NULL DEFAULT '0' COMMENT 'action', `token_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'token_id', @@ -861,7 +862,8 @@ CREATE TABLE `t_transaction` ( `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), UNIQUE KEY `trans_id` (`trans_id`), - KEY `account_id` (`account_id`) + KEY `account_id` (`account_id`), + KEY `address` (`address`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/sql/gamedb2006_migrate_230605_01.sql b/sql/gamedb2006_migrate_230605_01.sql index 3f766e41..61369448 100644 --- a/sql/gamedb2006_migrate_230605_01.sql +++ b/sql/gamedb2006_migrate_230605_01.sql @@ -1,7 +1,7 @@ begin; alter table t_user add column `address` varchar(60) COMMENT 'address'; -alter table t_user add KEY `address` (`address`); +alter table t_user add UNIQUE KEY `address` (`address`); insert into version (version) values(2023060501); diff --git a/sql/migrate_230607_01.sql b/sql/migrate_230607_01.sql index 27e7e468..e9d7cedd 100644 --- a/sql/migrate_230607_01.sql +++ b/sql/migrate_230607_01.sql @@ -3,6 +3,9 @@ begin; alter table t_chip add column `active_token_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'active_token_id'; alter table t_chip add column `active_count` int(11) NOT NULL DEFAULT '0' COMMENT 'active_count'; +alter table t_transaction add column `address` varchar(60) NOT NULL DEFAULT '' COMMENT 'address'; +alter table t_transaction add KEY `address` (`address`); + insert into version (version) values(2023060701); commit; From 76089824602ec969e01166d82b9bd2a3375a6c0a Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 7 Jun 2023 16:15:11 +0800 Subject: [PATCH 10/20] 1 --- webapp/models/Transaction.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/webapp/models/Transaction.php b/webapp/models/Transaction.php index b4b02954..75432b4e 100644 --- a/webapp/models/Transaction.php +++ b/webapp/models/Transaction.php @@ -26,7 +26,7 @@ class Transaction extends BaseModel { myself()->_getSelfMysql(), 't_transaction', array( - 'account_id' => myself()->_getAccountId(), + 'address' => myself()->_getAddress(), 'client_confirmed' => 1 ) ); @@ -39,7 +39,7 @@ class Transaction extends BaseModel { myself()->_getSelfMysql(), 't_transaction', array( - 'account_id' => myself()->_getAccountId(), + 'address' => myself()->_getAddress(), 'trans_id' => $transId, ) ); @@ -65,6 +65,7 @@ class Transaction extends BaseModel { 't_transaction', array( 'account_id' => myself()->_getAccountId(), + 'address' => myself()->_getAddress(), 'trans_id' => $transId, 'action' => $action, 'token_id' => $tokenId, @@ -335,7 +336,7 @@ class Transaction extends BaseModel { myself()->_getSelfMysql(), 't_transaction', array( - 'account_id' => myself()->_getAccountId(), + 'address' => myself()->_getAddress(), 'trans_id' => $transId ), array( From 5918b2a7e3d9823fef35e94e3a04736b960c4129 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 7 Jun 2023 16:56:20 +0800 Subject: [PATCH 11/20] 1 --- .../controller/BlockChainController.class.php | 81 ++++++++++--------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index cb2dcffc..778b2071 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -219,44 +219,51 @@ class BlockChainController extends BaseAuthedController { } } - private function internalBcCall($params, $transParams, $cb = null) { - $propertyChgService = new services\PropertyChgService(); - $propertyChgService->addUserChg(); - $url = self::getWeb3ServiceUrl(); - $response = ''; - if (!phpcommon\HttpClient::get - ($url, - $params, - $response)) { - myself()->_rspErr(500, 'server internal error'); - die(); - return; - } - error_log($response); - $rspObj = json_decode($response, true); - if ($rspObj['errcode'] == 0) { - $transId = $rspObj['trans_id']; - Transaction::add( - $transId, - $transParams['action'], - $transParams['tokenId'], - $transParams['tokenType'], - $transParams['itemUniId'], - $transParams['itemId'], - $transParams['result'] - ); - if ($cb) { - $cb($transId); + private function internalActivate721Nft($tokenId, $tokenType, $itemUniId, $itemId) + { + $params = array( + 'c' => 'BcService', + 'a' => 'activate721Nft', + 'account_id' => myself()->_getAccountId(), + 'session_id' => myself()->_getSessionId(), + 'account' => myself()->_getAddress(), + 'token_id' => $tokenId, + 'token_type' => $tokenType, + 'item_uniid' => $itemUniId, + 'item_id' => $itemId + ); + { + $url = self::getWeb3ServiceUrl(); + $response = ''; + if (!phpcommon\HttpClient::get + ($url, + $params, + $response)) { + myself()->_rspErr(500, 'server internal error'); + die(); + return; + } + error_log($response); + $rspObj = json_decode($response, true); + if ($rspObj['errcode'] == 0) { + $transId = $rspObj['trans_id']; + Transaction::add( + $transId, + Transaction::MINT_721_ACTION_TYPE, + $tokenId, + $tokenType, + $itemUniId, + $itemId, + 1 + ); + myself()->_rspData(array( + 'trans_id' => $transId, + 'params' => $rspObj['params'] + )); + } else { + myself()->_rspErr(500, 'server internal error'); + return; } - myself()->_rspData(array( - 'trans_id' => $transId, - 'params' => $rspObj['params'], - 'property_chg' => $propertyChgService->toDto(), - )); - } else { - myself()->_rspErr(500, 'server internal error'); - die(); - return; } } From cc5b053f4746a0a648eed09f0569d5628ba46788 Mon Sep 17 00:00:00 2001 From: songliang Date: Wed, 7 Jun 2023 17:57:06 +0800 Subject: [PATCH 12/20] ... --- doc/Shop.py | 3 ++- .../controller/FirstTopupController.class.php | 20 +++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/doc/Shop.py b/doc/Shop.py index ec2c3f7e..2bd85ece 100644 --- a/doc/Shop.py +++ b/doc/Shop.py @@ -102,7 +102,8 @@ class Shop(object): 'group': 'Shop', 'url': 'webapp/index.php?c=Shop&a=buyGoodsDirect', 'params': [ - _common.ReqHead(), + ['account_id', '', '账号id'], + ['order_id', '', '订单id'], ['id', 0, '商品唯一id,参见shopGoods表'], ['token_type', '', "选用币种"], ['goods_num', 0, '商品数量'], diff --git a/webapp/controller/FirstTopupController.class.php b/webapp/controller/FirstTopupController.class.php index 6f4ff4af..a9a0edcc 100644 --- a/webapp/controller/FirstTopupController.class.php +++ b/webapp/controller/FirstTopupController.class.php @@ -113,7 +113,7 @@ class FirstTopupController extends BaseAuthedController if ($complete == 1) { $this->_setV(TN_FIRST_TUPOP_STATUS, 0, 1); } - + $this->_rspData( array( 'group' => $group, @@ -152,14 +152,18 @@ class FirstTopupController extends BaseAuthedController array('account_id' => myself()->_getAccountId()) ); - // 0 未领取 1 可领取 2 已领取 - $status = [(int)$row['status1'], (int)$row['status2'], (int)$row['status3']]; - $time = $row['createtime']; + $status = [0, 0, 0]; - for ($i = 0; $i < 3; $i++) { - if ($status[$i] < 2) { - // 检测是否到了可以领取的时间 - $status[$i] = $this->getStatus($i, $time); + if ($row) { + // 0 未领取 1 可领取 2 已领取 + $status = [(int)$row['status1'], (int)$row['status2'], (int)$row['status3']]; + $time = $row['createtime']; + + for ($i = 0; $i < 3; $i++) { + if ($status[$i] < 2) { + // 检测是否到了可以领取的时间 + $status[$i] = $this->getStatus($i, $time); + } } } From 4d316d1d96522aca431612989b23488311b4f0fe Mon Sep 17 00:00:00 2001 From: songliang Date: Thu, 8 Jun 2023 10:28:35 +0800 Subject: [PATCH 13/20] ... --- doc/Shop.py | 30 ++++++++ .../controller/FirstTopupController.class.php | 2 +- webapp/controller/ShopController.class.php | 73 +++++++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) diff --git a/doc/Shop.py b/doc/Shop.py index 2bd85ece..5ffbe191 100644 --- a/doc/Shop.py +++ b/doc/Shop.py @@ -112,6 +112,36 @@ class Shop(object): _common.RspHead(), ] }, + { + 'name': 'startGoodsDirect', + 'desc': '发起一个 直接购买(充值,gold)', + 'group': 'Shop', + 'url': 'webapp/index.php?c=Shop&a=buyGoodsDirect', + 'params': [ + _common.ReqHead(), + ['id', 0, '商品唯一id,参见shopGoods表'], + ['token_type', '', "选用币种"], + ['goods_num', 0, '商品数量'], + ], + 'response': [ + _common.RspHead(), + ['order_id', '', '订单id'], + ] + }, + { + 'name': 'statusGoodsDirect', + 'desc': '查询 直接购买(充值,gold) 状态', + 'group': 'Shop', + 'url': 'webapp/index.php?c=Shop&a=buyGoodsDirect', + 'params': [ + _common.ReqHead(), + ['order_id', '', '订单id'], + ], + 'response': [ + _common.RspHead(), + ['status', 0, '订单状态 0:未支付 1:已支付 2:支付失败'], + ] + }, ] diff --git a/webapp/controller/FirstTopupController.class.php b/webapp/controller/FirstTopupController.class.php index a9a0edcc..4c7ad4ff 100644 --- a/webapp/controller/FirstTopupController.class.php +++ b/webapp/controller/FirstTopupController.class.php @@ -39,7 +39,7 @@ class FirstTopupController extends BaseAuthedController ); } - private function begin() + public function begin() { $conn = myself()->_getMysql(''); diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 58146cbf..4dafa836 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -308,6 +308,16 @@ class ShopController extends BaseAuthedController public function buyGoodsDirect() { + // let repdata = { + // account_id: string + // order_id: string + // status: string + // id: string + // txhash: string + // } + // 我返回给你这些数据和一个sign字段, + // sign使用上面 repdata 按key 顺序排后, 组成key1=val1&key2=val2后, 使用hmac_sha256 hash, key是 iG4Rpsa)6U31$H#^T85$^^3 + error_log("buyGoodsDirect"); $id = getReqVal('id', 0); $token_type = getReqVal('token_type', ''); $goods_num = getReqVal('goods_num', 0); @@ -488,6 +498,62 @@ class ShopController extends BaseAuthedController } } + public function startGoodsDirect() { + $id = getReqVal('id', 0); + $token_type = getReqVal('token_type', ''); + $goods_num = getReqVal('goods_num', 0); + + $conn = myself()->_getMysql(''); + + $chk = SqlHelper::insert( + $conn, + 't_shop_buy_order', + array( + 'account_id' => myself()->_getAccountId(), + 'createtime' => myself()->_getNowTime(), + 'item_id' => $id, + 'goods_num' => $goods_num, + 'status' => 0, // 0-客户端申请了订单 1-订单完成 2-订单失败 + ) + ); + if ($chk) { + $lastId = $this->lastInsertId($conn); + $this->_rspData( + array( + 'order_id' => $lastId, + ) + ); + } + } + + public function statusGoodsDirect() { + $order_id = getReqVal('order_id', ''); + + $conn = myself()->_getMysql(''); + + $row = SqlHelper::selectOne( + $conn, + 't_shop_buy_order', + array('status'), + array( + 'idx' => $order_id, + ) + ); + if ($row) { + $this->_rspData( + array( + 'status' => $row['status'], + ) + ); + } else { + $this->_rspData( + array( + 'status' => 0, + ) + ); + } + } + private function getCostItemIdByTokenType($token_type) { switch ($token_type) { @@ -1056,4 +1122,11 @@ class ShopController extends BaseAuthedController return; } } + + private function lastInsertId($conn) + { + $row = $conn->execQueryOne('SELECT LAST_INSERT_ID() as lastId;', array()); + return $row['lastId']; + } + } From 66fc85b61f21a4a4a1730b184ea5bbfcdf567629 Mon Sep 17 00:00:00 2001 From: songliang Date: Thu, 8 Jun 2023 10:31:16 +0800 Subject: [PATCH 14/20] ... --- doc/Shop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/Shop.py b/doc/Shop.py index 5ffbe191..a957e753 100644 --- a/doc/Shop.py +++ b/doc/Shop.py @@ -116,7 +116,7 @@ class Shop(object): 'name': 'startGoodsDirect', 'desc': '发起一个 直接购买(充值,gold)', 'group': 'Shop', - 'url': 'webapp/index.php?c=Shop&a=buyGoodsDirect', + 'url': 'webapp/index.php?c=Shop&a=startGoodsDirect', 'params': [ _common.ReqHead(), ['id', 0, '商品唯一id,参见shopGoods表'], @@ -132,7 +132,7 @@ class Shop(object): 'name': 'statusGoodsDirect', 'desc': '查询 直接购买(充值,gold) 状态', 'group': 'Shop', - 'url': 'webapp/index.php?c=Shop&a=buyGoodsDirect', + 'url': 'webapp/index.php?c=Shop&a=statusGoodsDirect', 'params': [ _common.ReqHead(), ['order_id', '', '订单id'], From 4cf3b4ac3ae4c9aa6cb97f8ace7bc541cff9abcd Mon Sep 17 00:00:00 2001 From: songliang Date: Thu, 8 Jun 2023 10:33:17 +0800 Subject: [PATCH 15/20] ... --- doc/Shop.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/Shop.py b/doc/Shop.py index a957e753..c95cc6d9 100644 --- a/doc/Shop.py +++ b/doc/Shop.py @@ -142,6 +142,4 @@ class Shop(object): ['status', 0, '订单状态 0:未支付 1:已支付 2:支付失败'], ] }, - - ] From 2a6fa5be836eb7bb16514220b76942a4b29ba24a Mon Sep 17 00:00:00 2001 From: songliang Date: Thu, 8 Jun 2023 11:33:21 +0800 Subject: [PATCH 16/20] ... USD --- webapp/controller/ShopController.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 4dafa836..f019cbf6 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -43,6 +43,8 @@ class ShopController extends BaseAuthedController const TOKEN_TYPE_MATIC = '101'; const TOKEN_TYPE_BNB = '102'; + const TOKEN_TYPE_DSD = '99'; + // 限购类型 const DAILY_BUY_LIMIT = 1; const WEEKLY_BUY_LIMIT = 2; From 2c2d5ca9b96d769dc00a4ad5c6115dc386c67e01 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 8 Jun 2023 13:11:55 +0800 Subject: [PATCH 17/20] 1 --- doc/User.py | 2 ++ webapp/controller/UserController.class.php | 33 +++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/doc/User.py b/doc/User.py index e5e2a325..5a8ab150 100644 --- a/doc/User.py +++ b/doc/User.py @@ -205,6 +205,8 @@ class User(object): ], 'response': [ _common.RspHead(), + ['is_retry', 0, '是否重试 0:不用重试 1:重试'], + ['retry_time', 0, '重试时间(单位秒)'], ] }, ] diff --git a/webapp/controller/UserController.class.php b/webapp/controller/UserController.class.php index e5077a67..fb9687ba 100644 --- a/webapp/controller/UserController.class.php +++ b/webapp/controller/UserController.class.php @@ -805,7 +805,38 @@ class UserController extends BaseAuthedController { public function updateAddressBind() { - $hero_uniid = getReqVal('jwt', ''); + error_log(json_encode($_REQUEST)); + $jwt = getReqVal('jwt', ''); + + $arr = explode('.', $jwt); + if (count($arr) < 3) { + phpcommon\sendError(1, 'token error'); + die(); + return; + } + $header = base64_decode($arr[0]); + $payload = base64_decode($arr[1]); + $sign = base64_decode($arr[2]); + $data = json_decode($payload, true); + + $url = 'https://pay.cebggame.com/wallet/info?'; + $params = array( + 'token' => $jwt + ); + $response = ''; + if (!phpcommon\HttpClient::get + ($url, + $params, + $response)) { + myself()->_rspErr(500, 'server internal error'); + die(); + return; + } + error_log($response); + $rspObj = json_decode($response, true); + User::Update(array( + 'address' => $rspObj['address'] + )); $this->_rspOk(); } From 15f446afd2e540ec7eaf1455458ce07a5042d882 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 8 Jun 2023 13:19:57 +0800 Subject: [PATCH 18/20] 1 --- webapp/controller/UserController.class.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/webapp/controller/UserController.class.php b/webapp/controller/UserController.class.php index fb9687ba..55451d5a 100644 --- a/webapp/controller/UserController.class.php +++ b/webapp/controller/UserController.class.php @@ -835,9 +835,13 @@ class UserController extends BaseAuthedController { error_log($response); $rspObj = json_decode($response, true); User::Update(array( - 'address' => $rspObj['address'] + 'address' => $rspObj['data']['address'] + )); + $propertyChgService = new services\PropertyChgService(); + $propertyChgService->addUserChg(); + $this->_rspData(array( + 'property_chg' => $propertyChgService->toDto(), )); - $this->_rspOk(); } private function dampingElo($userInfo){ From 863bcb5f00ec6c0418688f9d2820730b757d0e73 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 8 Jun 2023 13:58:46 +0800 Subject: [PATCH 19/20] 1 --- webapp/controller/ShopController.class.php | 46 +--------------------- 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index f019cbf6..3c6e10bc 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -61,51 +61,9 @@ class ShopController extends BaseAuthedController // } // } - $this->accountId = getReqVal('account_id', ''); - if (getReqVal('c', '') == 'Shop' && getReqVal('a', '') == 'buyGoodsDirect') { - $this->_userLvRestriction(); - return; + if(getReqVal('a', '') != 'buyGoodsDirect'){ + parent::_handlePre(); } - - // $this->accountId = getReqVal('account_id', ''); - $this->sessionId = getReqVal('session_id', ''); - if (!phpcommon\isValidSessionId( - $this->accountId, - $this->sessionId - )) { - phpcommon\sendError(500, 'invalid session_id'); - die(); - } - if (!(getReqVal('c', '') == 'User' && getReqVal('a', '') == 'login')) { - if ((getReqVal('c', '') == 'Battle')) { - return; - } - $r = $this->_getRedis($this->_getAccountId()); - $sessionId = $r->get(LAST_SESSION_KEY . $this->_getAccountId()); - if (empty($sessionId)) { - $this->updateSession( - myself()->_getAccountId(), - myself()->_getSessionId() - ); - } else if ($sessionId != $this->_getSessionId()) { - error_log('session expiration' . json_encode( - $_REQUEST - )); - phpcommon\sendError(1001, 'session expiration'); - die(); - } - - $this->_userLvRestriction(); - } - - /*if (SERVER_ENV == _ONLINE) { - if (phpcommon\cmpVersion(getReqVal('_version', ''), '0.2.0') > 0) { - if (!$this->isWhiteList() || myself()->_getChannel() != BC_CHANNEL) { - phpcommon\sendError(1002, ''); - die(); - } - } - }*/ } public function getGoodsList() From e198f3d7f8748dd30a25e55b04f11a0ecf82a5cc Mon Sep 17 00:00:00 2001 From: songliang Date: Thu, 8 Jun 2023 13:59:50 +0800 Subject: [PATCH 20/20] ... --- webapp/controller/ShopController.class.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 3c6e10bc..11e0ae31 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -44,7 +44,7 @@ class ShopController extends BaseAuthedController const TOKEN_TYPE_BNB = '102'; const TOKEN_TYPE_DSD = '99'; - + // 限购类型 const DAILY_BUY_LIMIT = 1; const WEEKLY_BUY_LIMIT = 2; @@ -277,11 +277,22 @@ class ShopController extends BaseAuthedController // } // 我返回给你这些数据和一个sign字段, // sign使用上面 repdata 按key 顺序排后, 组成key1=val1&key2=val2后, 使用hmac_sha256 hash, key是 iG4Rpsa)6U31$H#^T85$^^3 - error_log("buyGoodsDirect"); - $id = getReqVal('id', 0); + + $token_type = getReqVal('token_type', ''); $goods_num = getReqVal('goods_num', 0); + $order_id = 28; + error_log("buyGoodsDirect"); + + $conn = myself()->_getMysql(''); + + $order = SqlHelper::selectOne($conn, 't_shop_buy_order', array('account_id', 'item_id', 'goods_num', 'status'), array('idx' => $order_id)); + + $id = $order['item_id']; + $goods_num = $order['goods_num']; + $status = $order['status']; + $row = mt\ShopGoods::get($id); $desired_token_type = $row['token_type'];