From bf6a11ea2334e8c5db40097443d6151b180dfac9 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 30 Jun 2023 13:59:18 +0800 Subject: [PATCH 01/11] ... --- webapp/controller/ShopController.class.php | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 9e91ad32..3a67b171 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -483,6 +483,9 @@ class ShopController extends BaseAuthedController private function getCostItemIdByTokenType($token_type) { switch ($token_type) { + case ShopController::TOKEN_TYPE_GOLD: + return V_ITEM_GOLD; + break; case ShopController::TOKEN_TYPE_CEG: return V_ITEM_GOLD; break; @@ -783,15 +786,35 @@ class ShopController extends BaseAuthedController return; } + $maxCount = mt\Parameter::getByName('daily_selection_refresh_time')['param_value']; $count = $this->countTodayRefreshTimes($address); - if ($count >= 6) { + if ($count >= $maxCount) { $this->_rspErr(2, 'The maximum number of refreshes has been reached'); return; } + $count = $this->countTodayRefreshTimes($address); + $costs = mt\Parameter::getByName('daily_selection_refresh_cost'); + $arrCosts = explode('|', $costs['param_value']); + $cost = $arrCosts[$count]; + $costItemId = $this->getCostItemIdByTokenType(ShopController::TOKEN_TYPE_GOLD); + $costItems = $this->makeCostItems($costItemId, $cost); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); + return; + } + $chk = $this->refreshDailySelectionWithMode($address, 1); if ($chk) { - $this->_rspOk(); + $this->_decItems($costItems); + $this->_rspData( + array( + 'cost' => $cost, + ) + ); + } else { + $this->_rspErr(3, 'refresh failed'); } } From 0f66a219a51933e1ec2596ac933a67b655748046 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 30 Jun 2023 14:01:14 +0800 Subject: [PATCH 02/11] ... --- doc/Shop.py | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/Shop.py b/doc/Shop.py index d7eecb08..b1294271 100644 --- a/doc/Shop.py +++ b/doc/Shop.py @@ -201,6 +201,7 @@ class Shop(object): ], 'response': [ _common.RspHead(), + ['cost', 0, '每日精选的当前刷新价格'], ] }, { From 33f49a7063b73388de283dc6bff883111b7aa2a4 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 30 Jun 2023 14:15:13 +0800 Subject: [PATCH 03/11] ... --- webapp/controller/ShopController.class.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 3a67b171..06af5d20 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -432,11 +432,18 @@ class ShopController extends BaseAuthedController $conn = myself()->_getMysql(''); + $address = myself()->_getAddress(); + + if (empty($address)) { + $this->_rspErr(1, "address is empty"); + return; + } + $chk = SqlHelper::insert( $conn, 't_shop_buy_order', array( - 'address' => myself()->_getAddress(), + 'address' => $address, 'createtime' => myself()->_getNowTime(), 'item_id' => $id, 'goods_num' => $goods_num, From 76b1596381c8c8f0ed034f28ec87bdec4173f363 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 30 Jun 2023 14:19:09 +0800 Subject: [PATCH 04/11] ... --- webapp/controller/ShopController.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 06af5d20..d866812d 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -434,11 +434,11 @@ class ShopController extends BaseAuthedController $address = myself()->_getAddress(); + if (empty($address)) { - $this->_rspErr(1, "address is empty"); - return; + $address = myself()->_getAccountId(); } - + $chk = SqlHelper::insert( $conn, 't_shop_buy_order', From 52629fab4b16467d739856621e01741ed4c9f4e5 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 30 Jun 2023 14:28:55 +0800 Subject: [PATCH 05/11] ... --- doc/Shop.py | 2 ++ doc/_common.py | 1 + 2 files changed, 3 insertions(+) diff --git a/doc/Shop.py b/doc/Shop.py index b1294271..1eb0768b 100644 --- a/doc/Shop.py +++ b/doc/Shop.py @@ -247,6 +247,8 @@ class Shop(object): 'response': [ _common.RspHead(), ['!items', [0], '宝箱物品列表'], + ['free_num', 0, '免费次数'], + ['pending', 0, '购买中...'], ] }, { diff --git a/doc/_common.py b/doc/_common.py index f686f202..078f72da 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -402,6 +402,7 @@ class NewGoods(object): ['bought_times', 0, '已购买次数'], ['free_type', 0, '免费类型 0:不免费 1:日刷新'], ['free_num', 0, '免费次数'], + ['pending', 0, '购买中...'], ] class ShopName(object): From d48fb43e4b79ad85f1e8093870bfedfa64e6c495 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 30 Jun 2023 15:21:35 +0800 Subject: [PATCH 06/11] ... --- sql/marketdb.sql | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/sql/marketdb.sql b/sql/marketdb.sql index db310399..81702dc7 100644 --- a/sql/marketdb.sql +++ b/sql/marketdb.sql @@ -575,3 +575,45 @@ CREATE TABLE `t_log` ( /*!40101 SET character_set_client = @saved_cs_client */; -- Dump completed on 2015-08-19 18:51:22 +DROP TABLE IF EXISTS `t_market_store`; +CREATE TABLE `t_market_store` ( + `idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `o_link` varchar(64) NOT NULL COMMENT '关联的链上上架单号', + `status` int(11) NOT NULL COMMENT '订单状态 0:出售中 1:已下架 2:已售出', + `owner_address` varchar(60) NOT NULL COMMENT '当前拥有者', + `token_id` varchar(80) NOT NULL COMMENT 'token_id', + `nft_token` varchar(64) DEFAULT NULL COMMENT 'nftToken', + `token_type` int(11) NOT NULL COMMENT 'nft类型 1:英雄 2:枪支 3:芯片', + `item_id` int(11) DEFAULT NULL COMMENT '特殊字段,用于标记中心化道具,用于交易金币', + `amount` int(11) NOT NULL DEFAULT '1' COMMENT '堆叠数量', + `createtime` int(11) NOT NULL COMMENT '创建时间(上架时间)', + `modifytime` int(11) NOT NULL COMMENT '修改时间(更新价格等)', + `s_currency` varchar(255) NOT NULL COMMENT '出售时选择的币种地址', + `s_price` varchar(64) NOT NULL COMMENT '出售价格', + `c_name` varchar(32) NOT NULL COMMENT '缓存-名称', + `c_job` int(11) NOT NULL COMMENT '缓存-职业', + `c_type` int(11) NOT NULL COMMENT '缓存-碎片类型', + `c_lv` int(11) NOT NULL COMMENT '缓存-级别', + `c_quality` int(11) NOT NULL COMMENT '缓存-品阶', + `c_durability` float NOT NULL COMMENT '缓存-能量', + `c_id` int(11) NOT NULL COMMENT '缓存-id', + PRIMARY KEY (`idx`,`o_link`) USING BTREE, + UNIQUE KEY `o_link` (`o_link`) USING HASH COMMENT '链上合约上架订单号', + UNIQUE KEY `idx` (`idx`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=350 DEFAULT CHARSET=utf8; + +DROP TABLE IF EXISTS `t_market_transaction_record`; +CREATE TABLE `t_market_transaction_record` ( + `idx` bigint(20) NOT NULL AUTO_INCREMENT, + `createtime` int(11) NOT NULL COMMENT '交易成功时间', + `orderid` bigint(20) NOT NULL COMMENT 'market 订单id', + `o_link` varchar(64) NOT NULL COMMENT '合约订单id', + `seller` varchar(64) NOT NULL COMMENT '卖家', + `buyer` varchar(64) NOT NULL COMMENT '买家', + `tokenid` int(64) NOT NULL COMMENT 'tokenid', + `item_id` int(11) DEFAULT NULL COMMENT '如果有,说明是中心化道具交易', + `amount` int(11) NOT NULL COMMENT '堆叠数量', + `name` varchar(64) NOT NULL COMMENT '商品名称', + `type` int(11) NOT NULL COMMENT '商品类型', + PRIMARY KEY (`idx`) +) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8; From 5b7cb8e1fba87722323c8ec4ef13f8e4e060fb9d Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 30 Jun 2023 15:38:09 +0800 Subject: [PATCH 07/11] ... --- webapp/controller/MarketController.class.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index 4f017c75..fb907065 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -780,7 +780,7 @@ class MarketController extends BaseController { return ''; }; - $conn = myself()->_getMysql(''); + $conn = myself()->_getMarketMysql(''); $counts = $conn->execQuery( 'SELECT count(*) as count FROM t_market_store '. @@ -952,7 +952,7 @@ class MarketController extends BaseController { $signature = getReqVal('signature', ''); $net_id = getReqVal('net_id', ''); - $conn = myself()->_getMysql(''); + $conn = myself()->_getMarketMysql(''); $conn->execScript('DELETE FROM t_market_store WHERE '.'token_id=\''.$nft_token.'\''); $this->_rspOk(); @@ -1142,7 +1142,7 @@ class MarketController extends BaseController { ) ); - $conn = myself()->_getMysql(''); + $conn = myself()->_getMarketMysql(''); // 1. check order status $chk = SqlHelper::selectOne($conn, 't_market_store', array('status','idx', 'c_name', 'token_type'), array('o_link' => $orderId)); @@ -1196,7 +1196,7 @@ class MarketController extends BaseController { ) ); - $conn = myself()->_getMysql(''); + $conn = myself()->_getMarketMysql(''); // 1. check order status $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); @@ -1241,7 +1241,7 @@ class MarketController extends BaseController { ) ); - $conn = myself()->_getMysql(''); + $conn = myself()->_getMarketMysql(''); // 1. check order status $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); @@ -1308,7 +1308,7 @@ class MarketController extends BaseController { } private function attach_market_selling(&$row) { - $conn = myself()->_getMysql(''); + $conn = myself()->_getMarketMysql(''); $rows = $conn->execQuery( 'SELECT * FROM t_market_store '. @@ -1333,7 +1333,7 @@ class MarketController extends BaseController { private function listMySelledNfts($account, $type) { - $conn = myself()->_getMysql(''); + $conn = myself()->_getMarketMysql(''); $rows = $conn->execQuery( 'SELECT * FROM t_market_store '. From d33fea4988ee431ffb075faa99006914b0c9b3b1 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 30 Jun 2023 16:49:54 +0800 Subject: [PATCH 08/11] ... --- doc/_common.py | 1 + webapp/controller/ShopController.class.php | 45 +++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/doc/_common.py b/doc/_common.py index 078f72da..09c8d995 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -444,6 +444,7 @@ class DailySelectionGoods(object): ['weight', 0, '权重'], ['discount', 0, '折扣'], ['price', 0, '价格'], + ['pending', 0, '购买中...'], ] class Mission(object): diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index d866812d..64d34864 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -847,12 +847,13 @@ class ShopController extends BaseAuthedController for ($i = 1; $i <= 6; $i++) { $goodsList[$i] = mt\Dailyselection::get($selection['grid_' . $i]); $goodsList[$i]['count'] = $selection['count_' . $i]; + $goodsList[$i]['pending'] = $this->checkPendingBuyGoodsDS($address, $goodsList[$i]['goods_id'], $selection['idx'], $i); } $count = $this->countTodayRefreshTimes($address); $costs = mt\Parameter::getByName('daily_selection_refresh_cost'); $arrCosts = explode('|', $costs['param_value']); - $cost = $arrCosts[$count]; + $cost = $count < count($arrCosts) ? $arrCosts[$count] : null; $this->_rspData( array( @@ -882,7 +883,11 @@ class ShopController extends BaseAuthedController $row = mt\ShopGoods::get($id); $goods_id = $row['goods_id']; - + $pending = $this->checkPendingBuyGoodsNormal($address, $goods_id, $row['shop_id'], $id); + if ($pending) { + $this->_rspErr(1, 'pending'); + return; + } $desired_token_type = $row['token_type']; $check_token_type = splitStr1($desired_token_type); $token_pos = array_search($token_type, $check_token_type, true); @@ -1130,6 +1135,12 @@ class ShopController extends BaseAuthedController $goods = mt\Dailyselection::get($sel_id); + $pending = $this->checkPendingBuyGoodsDS($address, $goods['goods_id'], $idx, $grid); + if ($pending) { + $this->_rspErr(2, 'pending'); + return; + } + $price = $this->normalizeWeb3Price($goods['price'] * $count); $item_id = $goods['goods_id']; $item_count = $goods['goods_num'] * $count; @@ -1557,6 +1568,36 @@ class ShopController extends BaseAuthedController return 0; } + private function checkPendingBuyGoodsDS($address, $goodsId, $idx, $grid) + { + $self = myself(); + if (!$self) return; + + $conn = $self->_getMysql(''); + + $rows = SqlHelper::select( + $conn, + 't_bc_order', + array('ext_data'), + array( + 'address' => $address, + 'item_id' => $goodsId, + 'status' => 0, + ) + ); + foreach ($rows as $row) { + $extData = json_decode($row['ext_data'], true); + if ($extData['mode'] == SHOP_BUY_MODE_DAILY_SELECTION) { + if ($extData['idx'] == $idx) { + if ($extData['grid'] == $grid) { + return 1; + } + } + } + } + return 0; + } + private function outsideBuy($shopId, $itemId, $itemNum, $costItemId) { $propertyChgService = new services\PropertyChgService(); From a236553bddf301f8d1c87f51fe5a53fc9d56ae7c Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 30 Jun 2023 17:19:25 +0800 Subject: [PATCH 09/11] ... --- webapp/controller/MarketController.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index fb907065..4c7069ee 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -1067,7 +1067,7 @@ class MarketController extends BaseController { ) ); - $conn = myself()->_getMysql(''); + $conn = myself()->_getMarketMysql(''); // 1. check order status $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); From 27fc5bf0e48ef7a6d3bc69fa328e8932a52a2517 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 30 Jun 2023 17:39:38 +0800 Subject: [PATCH 10/11] ... --- webapp/controller/MarketController.class.php | 2 ++ webapp/controller/ShopController.class.php | 1 + 2 files changed, 3 insertions(+) diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index 4c7069ee..682db2a5 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -1333,6 +1333,8 @@ class MarketController extends BaseController { private function listMySelledNfts($account, $type) { + error_log('listMySelledNfts ' . $account . ' ' . $type); + $conn = myself()->_getMarketMysql(''); $rows = $conn->execQuery( diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 64d34864..9fd6e02e 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -1557,6 +1557,7 @@ class ShopController extends BaseAuthedController ); foreach ($rows as $row) { $extData = json_decode($row['ext_data'], true); + error_log("checkPendingBuyGoodsNormal: " . json_encode($extData)); if ($extData['mode'] == SHOP_BUY_MODE_NORMAL) { if ($extData['shop_id'] == $shop_id) { if ($extData['id'] == $id) { From 89f1d8dfd917c18275e39e3dc2186a7de2d73b76 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 30 Jun 2023 17:49:50 +0800 Subject: [PATCH 11/11] ... --- webapp/controller/ShopController.class.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 9fd6e02e..f1054d84 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -1350,6 +1350,13 @@ class ShopController extends BaseAuthedController } $chestType = $meta['sub_type']; $itemStore = mt\ShopChest::getRandomItemListByChestType($chestType); + error_log("getChestItems start1 " . json_encode( + array( + 'goods_id' => $goods_id, + 'chestType' => $chestType, + 'items' => $itemStore, + ) + )); $record = array(); foreach ($itemStore as $key => $value) { foreach ($value as $k => $v) {