From b119b634153c4016769aa7fd8c61070cb56881b1 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 1 Nov 2022 21:06:19 +0800 Subject: [PATCH 1/6] 1 --- doc/BlockChain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/BlockChain.py b/doc/BlockChain.py index 2bc82646..4e875a39 100644 --- a/doc/BlockChain.py +++ b/doc/BlockChain.py @@ -39,7 +39,7 @@ class BlockChain(object): 'group': 'BlockChain', 'url': 'webapp/index.php?c=BlockChain&a=active1155Nft', 'params': [ - ['trans_id', '', '事务id'], + ['uniid', '', '芯片唯一id'], ], 'response': [ _common.RspHead(), From 935b5c3fd7162bda4afade23071b3a5c9969edb6 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 1 Nov 2022 22:03:07 +0800 Subject: [PATCH 2/6] 1 --- sql/gamedb.sql | 3 +- .../controller/BlockChainController.class.php | 32 ++++++++ webapp/controller/ShopController.class.php | 76 ++++++++++++++++--- 3 files changed, 101 insertions(+), 10 deletions(-) diff --git a/sql/gamedb.sql b/sql/gamedb.sql index aa2821a7..5618abe9 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -791,6 +791,7 @@ CREATE TABLE `t_transaction` ( `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', `trans_id` varchar(255) NOT NULL DEFAULT '' COMMENT '事务id', `action` int(11) NOT NULL DEFAULT '0' COMMENT 'action', + `item_uniid` int(11) NOT NULL DEFAULT '0' COMMENT '道具uniid', `item_id` int(11) NOT NULL DEFAULT '0' COMMENT '道具id', `status` int(11) NOT NULL DEFAULT '0' COMMENT 'status', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', @@ -840,4 +841,4 @@ CREATE TABLE `t_shop_goods` ( `buy_gift` varchar(255) DEFAULT NULL, `normal_gift` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index de8d73a8..d517683f 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -47,7 +47,39 @@ class BlockChainController extends BaseAuthedController { public function active721Nft() { + $type = getReqVal('type', 0); + $uniid = getReqVal('uniid', 0); + switch ($type) { + case 1: + { + $heroDb = Hero::find($uuid); + if (!$heroDb) { + myself()->_rspErr(1, 'hero not found'); + return; + } + if ($heroDb['token_id']) { + myself()->_rspErr(1, 'already activated'); + return; + } + } + break; + case 2: + { + $gunDb = Gun::find($uuid); + if (!$gunDb) { + myself()->_rspErr(1, 'gun not found'); + return; + } + } + break; + default: + { + myself()->_rspErr(1, 'type param error'); + return; + } + break; + } } public function active1155Nft() diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 9dfd61c6..dd686a25 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -38,6 +38,11 @@ class ShopController extends BaseAuthedController { const TOKEN_TYPE_MATIC = '101'; const TOKEN_TYPE_BNB = '102'; + // 限购类型 + const DAILY_BUY_LIMIT = 1; + const WEEKLY_BUY_LIMIT = 2; + const TOTAL_BUY_LIMIT = 3; + public function getGoodsList() { $row = SqlHelper::ormSelect( @@ -89,6 +94,59 @@ class ShopController extends BaseAuthedController { return; } + $buyRecordHash = ShopBuyRecord::allToHash(); + $boughtTimes = 1; + switch ($row['limit_type']) { + case ShopController::DAILY_BUY_LIMIT: + { + + $buyRecord = getXVal($buyRecordHash, $id); + echo "===========".json_encode($buyRecord)."-------".$row['limit_num']."..".getXVal($buyRecord, 'this_day_buy_times', 0); + $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']); @@ -111,21 +169,21 @@ class ShopController extends BaseAuthedController { $this->internalAddItem($propertyChgService, $itemMeta); $awardService = new services\AwardService(); $awardService->addItem($row['goods_id'], $goods_num); - ShopBuyRecord::add($row['goods_id'], $itemNum); + ShopBuyRecord::add($id, $goods_num); $this->_decItems($costItems); $goodsDto = array( - 'goods_id' => $itemMeta['id'], - 'item_id' => $itemMeta['id'], + 'goods_id' => $id, + 'item_id' => $row['goods_id'], 'price_info' => array( - 'item_id' => $itemMeta['id'], + 'item_id' => $row['goods_id'], 'cost_list' => array(), - 'discount_begin_time' => phpcommon\datetimeToTimestamp($itemMeta['discount_begin']), - 'discount_end_time' => phpcommon\datetimeToTimestamp($itemMeta['discount_end']) + 'discount_begin_time' => phpcommon\datetimeToTimestamp($row['discount_begin']), + 'discount_end_time' => phpcommon\datetimeToTimestamp($row['discount_end']) ), - 'flag_icon' => $goodsMeta['tag'], - 'limit_type' => $itemMeta['limit_type'], + 'flag_icon' => $row['tag'], + 'limit_type' => $row['limit_type'], 'bought_times' => $boughtTimes, - 'total_buy_times' => $itemMeta['limit_num'], + 'total_buy_times' => $row['limit_num'], ); { $priceInfo = mt\Item::getPriceInfo($itemMeta); From 6b323add40b40241a7005fb2e17a395a1f6f4ee3 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 2 Nov 2022 09:24:09 +0800 Subject: [PATCH 3/6] 1 --- third_party/j7 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/j7 b/third_party/j7 index 7533a5e7..f98d9e8d 160000 --- a/third_party/j7 +++ b/third_party/j7 @@ -1 +1 @@ -Subproject commit 7533a5e7ed287378d33cb1bc3244487d33de7951 +Subproject commit f98d9e8dfb0575f3c42795163bfbaa5c807a5935 From c58d1684c703e4678ac82ee5ecc24e3030eb2722 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 2 Nov 2022 09:39:10 +0800 Subject: [PATCH 4/6] 1 --- third_party/phpcommon | 2 +- webapp/controller/BlockChainController.class.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/third_party/phpcommon b/third_party/phpcommon index 848e05c0..571b6c46 160000 --- a/third_party/phpcommon +++ b/third_party/phpcommon @@ -1 +1 @@ -Subproject commit 848e05c01f44622e52996bb04dfb6b344acce1b8 +Subproject commit 571b6c46137597d3bede13989e284130a070bea0 diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index d517683f..08909470 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -10,6 +10,7 @@ require_once('models/Hero.php'); require_once('models/Gun.php'); require_once('models/Nft.php'); require_once('models/Transaction.php'); +require_once('models/BuyRecord.php'); require_once('services/AwardService.php'); require_once('services/PropertyChgService.php'); @@ -22,6 +23,7 @@ use models\Hero; use models\Gun; use models\Nft; use models\Transaction; +use models\BuyRecord; class BlockChainController extends BaseAuthedController { @@ -61,7 +63,9 @@ class BlockChainController extends BaseAuthedController { myself()->_rspErr(1, 'already activated'); return; } + if (!$heroDb['active_token_id']) { + } } break; case 2: From e3e8e95072033a5d291e901e8b9a5a9191514267 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 2 Nov 2022 10:19:08 +0800 Subject: [PATCH 5/6] 1 --- .../controller/BlockChainController.class.php | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index 08909470..e044abf5 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -63,9 +63,24 @@ class BlockChainController extends BaseAuthedController { myself()->_rspErr(1, 'already activated'); return; } - if (!$heroDb['active_token_id']) { - + $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: @@ -136,4 +151,16 @@ class BlockChainController extends BaseAuthedController { } + private function internalActivate721Nft($tokenId, $tokenType, $itemUniId, $itemId) + { + $params = array( + 'account_id' => myself()->_getAccountId(), + 'session_id' => myself()->_getSessionId(), + 'token_id' => $tokenId, + 'token_type' => $tokenType, + 'item_uniid' => $itemUniId, + 'item_id' => $itemId + ); + } + } From 5a7739def19a33af9f5b0565d05d2592a49e4ca3 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 2 Nov 2022 10:43:27 +0800 Subject: [PATCH 6/6] 1 --- .../controller/BlockChainController.class.php | 31 +++++++++++++++++++ webapp/models/Transaction.php | 18 ++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index e044abf5..dc2c1e83 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -161,6 +161,37 @@ class BlockChainController extends BaseAuthedController { 'item_uniid' => $itemUniId, 'item_id' => $itemId ); + { + $url = self::getWeb3ServiceUrl(); + $response = ''; + if (!phpcommon\HttpClient::get + ($url, + $params, + $response)) { + phpcommon\sendError(500, 'server internal error'); + die(); + return; + } + $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 + ); + myself()->_rspData(array( + 'trans_id' => $transId, + 'params' => $rspObj['params'] + )); + } else { + phpcommon\sendError(500, 'server internal error'); + return; + } + } } } diff --git a/webapp/models/Transaction.php b/webapp/models/Transaction.php index 08d1efad..9e30a94a 100644 --- a/webapp/models/Transaction.php +++ b/webapp/models/Transaction.php @@ -5,7 +5,7 @@ namespace models; use mt; use phpcommon\SqlHelper; -class Transaction extends BaseModel { +class Transactionxo extends BaseModel { const MINT_721_ACTION_TYPE = 1; const MINT_1155_ACTION_TYPE = 2; @@ -43,6 +43,22 @@ class Transaction extends BaseModel { return $row; } + public static function add($transId, $action, $tokenId, $tokenType, $itemUniId, $itemId) + { + SqlHelper::insert( + 't_transaction', + array( + 'account_id' => myself()->_getAccountId(), + 'trans_id' => $transId, + 'action' => $action, + 'token_id' => $tokenId, + 'token_type' => $tokenType, + 'item_uniid' => $itemUniId, + 'item_id' => $itemId, + ) + ); + } + public static function getActionDesc($transDb) { switch ($transDb['action']) {