From 2e93e6e384329c0e141fc8a1b3f2cb16d8619f10 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 17 Jan 2022 14:46:32 +0800 Subject: [PATCH] 1 --- doc/_common.py | 1 + sql/marketdb.sql | 49 +++++++++------- webapp/bootstrap/config_loader.php | 12 ++++ webapp/controller/BaseController.class.php | 13 +++++ webapp/controller/MarketController.class.php | 59 +++++++++++++++++--- webapp/models/Goods.php | 38 +++++++++++++ webapp/mt/Market.php | 1 - 7 files changed, 144 insertions(+), 29 deletions(-) create mode 100644 webapp/models/Goods.php diff --git a/doc/_common.py b/doc/_common.py index 09dbc641..eb31e028 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -455,6 +455,7 @@ class Nft(object): ['type', 0, '类型 0:英雄 1:枪支 2:芯片'], ['token_id', '', '代币id?'], ['status', 0, '状态'], + ['inventory', 0, '库存(剩余数量)'], ['owner_address', '', '所有者地址'], ['owner_id', '', '所有者'], ['image_avatar', '', '图片'], diff --git a/sql/marketdb.sql b/sql/marketdb.sql index 766167ca..c48ff25a 100644 --- a/sql/marketdb.sql +++ b/sql/marketdb.sql @@ -19,23 +19,6 @@ CREATE TABLE `version` ( ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `t_boxes` --- - -DROP TABLE IF EXISTS `t_boxes`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `t_boxes` ( - `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', - `box_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'box_id', - `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', - `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', - PRIMARY KEY (`idx`), - UNIQUE KEY `box_id` (`box_id`) -) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `t_goods` -- @@ -45,12 +28,38 @@ DROP TABLE IF EXISTS `t_goods`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `t_goods` ( `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', - `goods_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'goods_id', - `goods_num` int(11) NOT NULL DEFAULT '0' COMMENT 'goods数量', + `goods_id` int(11) NOT NULL DEFAULT '0' COMMENT 'goods id', + `goods_idx` int(11) NOT NULL DEFAULT '0' COMMENT 'goods idx', + `item_id` int(11) NOT NULL DEFAULT '0' COMMENT '道具id', + `state` int(11) NOT NULL DEFAULT '0' COMMENT 'state 0:待支付 1:支付成功', + `buy_count` int(11) NOT NULL DEFAULT '0' COMMENT 'buy count', + `last_buyer` varchar(60) NOT NULL DEFAULT '' COMMENT '最后购买者', + `last_buy_time` int(11) NOT NULL DEFAULT '0' COMMENT '最后一次购买时间', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), - UNIQUE KEY `box_id` (`box_id`) + UNIQUE KEY `goods_id_goods_idx` (`goods_id`, `goods_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_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', + `buyer` varchar(60) NOT NULL DEFAULT '' COMMENT 'buyer', + `goods_id` int(11) NOT NULL DEFAULT '0' COMMENT 'goods id', + `goods_idx` int(11) NOT NULL DEFAULT '0' COMMENT 'goods idx', + `item_id` int(11) NOT NULL DEFAULT '0' COMMENT '道具id', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + KEY `goods_id_goods_idx` (`goods_id`, `goods_idx`), + KEY `buyer` (`buyer`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/webapp/bootstrap/config_loader.php b/webapp/bootstrap/config_loader.php index 3121316c..54a7556c 100644 --- a/webapp/bootstrap/config_loader.php +++ b/webapp/bootstrap/config_loader.php @@ -1,5 +1,6 @@ $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'marketdb2006' + )); + return $conn; + } + public function _getRedis($data) { $redis_conf = getRedisConfig(crc32($data)); diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index 7aa7ef5b..d5eeb807 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -5,7 +5,10 @@ require_once('mt/Item.php'); require_once('mt/WhiteList.php'); require_once('mt/Currency.php'); +require_once('models/Goods.php'); + use phpcommon\SqlHelper; +use models\Goods; class MarketController extends BaseController { @@ -49,16 +52,56 @@ class MarketController extends BaseController { $page = getReqVal('page', 1); $type = getReqVal('type', 0); $sort = getReqVal('sort', ''); + + $rows = array(); + $pageInfo = array( + 'total' => 0, + 'count' => 0, + 'per_page' => 10, + 'current_page' => $page, + 'total_pages' => 0 + ); + mt\Market::traverseMeta(function ($meta) use(&$rows, &$pageInfo) { + $remainBuyableNum = Goods::getRemainBuyableNum($meta); + if ($remainBuyableNum > 0) { + ++$pageInfo['total']; + if ($pageInfo['total'] >= $pageInfo['per_page'] * $pageInfo['current_page'] && + count($rows) < $pageInfo['per_page']) { + array_push($rows, $this->wrapNft($meta, $remainBuyableNum)); + } + } + }); + + $pageInfo['count'] = count($rows); + $pageInfo['total_pages'] = ceil($pageInfo['total'] / $pageInfo['per_page']); $this->_rspData(array( - 'rows' => array(), - 'page' => array( - 'total' => 0, - 'count' => 0, - 'per_page' => 10, - 'current_page' => 1, - 'total_pages' => 0 - ) + 'rows' => $rows, + 'page' => $pageInfo )); } + private function wrapNft($meta, $inventory) + { + $nft = array(); + $nft['goods_id'] = 0; + $nft['nft_id'] = ''; + $nft['type'] = 0; + $nft['token_id'] = ''; + $nft['status'] = 0; + $nft['inventory'] = 0; + $nft['owner_address'] = ''; + $nft['owner_id'] = ''; + $nft['image_avatar'] = ''; + $nft['image_full'] = ''; + $nft['price'] = array( + 'type' => 0, + 'name' => '', + 'value' => 0, + 'decimals' => 0 + ); + $nft['created_at'] = 0; + $nft['last_modified_at'] = 0; + return $nft; + } + } diff --git a/webapp/models/Goods.php b/webapp/models/Goods.php new file mode 100644 index 00000000..e4f8d7ef --- /dev/null +++ b/webapp/models/Goods.php @@ -0,0 +1,38 @@ +_getMarketMysql()->execQuery + ('SELECT goods_id, count(goods_idx) AS num FROM t_goods WHERE state=1 GROUP BY goods_id;', + array( + + )); + self::$buyedNumHash = array(); + foreach ($rows as $row) { + self::$buyedNumHash[$row['goods_id']] = $row['num']; + } + } + + private static $buyedNumHash; + +} diff --git a/webapp/mt/Market.php b/webapp/mt/Market.php index 0b251d3e..804000c1 100644 --- a/webapp/mt/Market.php +++ b/webapp/mt/Market.php @@ -10,7 +10,6 @@ use phpcommon; class Market { const SYS_TYPE = 0; - const AUCTION_TYPE = 1; public static function get($id) {