From bae8c2dd358973a54d09a26569db49c04f42bf0c Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 27 Jan 2022 14:43:08 +0800 Subject: [PATCH] 1 --- sql/marketdb.sql | 17 ++++++++ third_party/phpcommon | 2 +- webapp/controller/MarketController.class.php | 26 +++++++++++-- webapp/models/BuyRecord.php | 41 ++++++++++++++++++++ 4 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 webapp/models/BuyRecord.php diff --git a/sql/marketdb.sql b/sql/marketdb.sql index fb0e9bd5..2f0d9877 100644 --- a/sql/marketdb.sql +++ b/sql/marketdb.sql @@ -80,6 +80,23 @@ CREATE TABLE `t_nft` ( ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `t_buy_record` +-- + +DROP TABLE IF EXISTS `t_buy_record`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_buy_record` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `blobdata` mediumblob COMMENT 'blobdata', + `buyer_address` mediumblob COMMENT 'buyer_address', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `t_log` -- diff --git a/third_party/phpcommon b/third_party/phpcommon index 80d7222a..e42a7b73 160000 --- a/third_party/phpcommon +++ b/third_party/phpcommon @@ -1 +1 @@ -Subproject commit 80d7222a4a31e295fffbf09fc1880940b4eb630b +Subproject commit e42a7b732c806c4cc8060a101f9a13ae579039e3 diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index 94a7369b..7785df25 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -9,10 +9,14 @@ require_once('mt/Hero.php'); require_once('models/BoxOrder.php'); require_once('models/Nft.php'); +require_once('models/BuyRecord.php'); + +require_once('phpcommon/bchelper.php'); use phpcommon\SqlHelper; use models\BoxOrder; use models\Nft; +use models\BuyRecord; class MarketController extends BaseController { @@ -120,6 +124,7 @@ class MarketController extends BaseController { $nonce = getReqVal('nonce', ''); $signature = getReqVal('signature', ''); $gameId = 2006; + $funcId = 1; if (empty($type) || empty($buyerAddress) || @@ -137,14 +142,29 @@ class MarketController extends BaseController { return; } + if (!phpcommon\isValidBcGameId($gameId)) { + myself()->_rspErr(500, 'server internal error'); + return; + } + + if (!phpcommon\isValidBcTime(myself()->_getNowTime())) { + myself()->_rspErr(500, 'server internal error'); + return; + } + + if (!phpcommon\isValidBcFunc($funcId)) { + myself()->_rspErr(500, 'server internal error'); + return; + } + /*if (!$this->isTestMode() && BoxOrder::isBuyed($buyerAddress, $currBatchMeta['batch_id'])) { myself()->_rspErr(1, 'account can only choose 1 hero to purchase'); return; }*/ + $orderId = BuyRecord::genOrderId($gameId, $funcId, myself()->_getNowTime(), $buyerAddress); + $tokenId = $orderId; if ($this->isTestMode()) { - $orderId = myself()->_getNowTime(); - $tokenId = $orderId; $itemId = $type; SqlHelper::insert (myself()->_getMarketMysql(), @@ -181,8 +201,6 @@ class MarketController extends BaseController { ) ); } else { - $orderId = myself()->_getNowTime(); - $tokenId = $orderId; $itemId = $type; SqlHelper::insert (myself()->_getMarketMysql(), diff --git a/webapp/models/BuyRecord.php b/webapp/models/BuyRecord.php new file mode 100644 index 00000000..9655718c --- /dev/null +++ b/webapp/models/BuyRecord.php @@ -0,0 +1,41 @@ +_getMarketMysql(), + 't_buy_record', + array( + 'blobdata' => json_encode($_REQUEST), + 'buyer_address' => $buyerAddress, + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ) + ); + $lastIdx = SqlHelper::getLastInsertId(myself()->_getMarketMysql()); + if (empty($lastIdx)) { + die(json_encode(array( + 'errcode' => 500, + 'errmsg' => 'server internal error' + ))); + } + $orderId = phpcommon\genOrderId($gameId, $funcId, $time, $lastIdx); + if (!phpcommon\isValidOrderId($orderId)) { + die(json_encode(array( + 'errcode' => 500, + 'errmsg' => 'server internal error' + ))); + } + return $orderId; + } + +}