From 95bb04db255f2e3770de2c819c0488134e864a77 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 7 Jul 2023 13:54:57 +0800 Subject: [PATCH 01/10] 1 --- webapp/services/BlockChainService.php | 73 +++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/webapp/services/BlockChainService.php b/webapp/services/BlockChainService.php index 7a7e3b83..8d712dc7 100644 --- a/webapp/services/BlockChainService.php +++ b/webapp/services/BlockChainService.php @@ -83,6 +83,79 @@ class BlockChainService { } } + /* + 注意!!!: + 调用方调用前需要校验actionType和myself()->_getAddress, + 非法的参数,或者签名服挂了,该函数直接中断请求,不会运行到调用方后续逻辑 + + trans_id:订单id + + gameItemMallBuy + setv + a + b + c + */ + + public static function gameItemMarketBuy($actionType, $price, $itemId, $itemNum) + { + if (!($actionType > Transaction::BUY_BEGIN_ACTION_TYPE && + $actionType < Transaction::BUY_END_ACTION_TYPE)) { + error_log('gameItemMarketBuy action_type error:' . $actionType); + myself()->_rspErr(500, 'server internal error 1'); + die(); + return; + } + $account = myself()->_getAddress(); + if (empty($account)) { + error_log('gameItemMarketBuy address is emtpy:' . myself()->_getAccountId()); + myself()->_rspErr(500, 'server internal error 2'); + die(); + return; + } + $params = array( + 'c' => 'GameItemMarket', + 'a' => 'buy', + 'account' => $account, + 'price' => $price, + ); + { + $url = self::getWeb3ServiceUrl(); + $response = ''; + if (!phpcommon\HttpClient::get + ($url, + $params, + $response)) { + myself()->_rspErr(500, 'server internal error 3, url:' . $url); + die(); + return; + } + error_log("gameItemMarketBuy:" . $response . "url:" . $url); + $rspObj = json_decode($response, true); + if ($rspObj['errcode'] == 0) { + $transId = $rspObj['trans_id']; + Transaction::add( + $transId, + $actionType, + '', //$tokenId, + '', //$tokenType, + 0, //$itemUniId, + $itemId, //$itemId, + $itemNum, + 1 + ); + return array( + 'trans_id' => $transId, + 'params' => $rspObj['params'] + ); + } else { + myself()->_rspErr(500, 'server internal error 4'); + die(); + return; + } + } + } + /* $price 是一个小数精确到小数点后5位 */ From 12ac97878c6eab51e5459125770dd3dd5eb1623a Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 7 Jul 2023 14:57:31 +0800 Subject: [PATCH 02/10] ... --- webapp/controller/ShopController.class.php | 37 ++++++++++++++++++- .../callback/BuyShopGoodsCbService.php | 20 +++++----- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 2c616733..fdea0e17 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -700,6 +700,41 @@ class ShopController extends BaseAuthedController } } + public function buyDiamond() + { + $num = getReqVal('num', 0); + $price = $this->normalizeWeb3Price($num); + $item_id = V_ITEM_DIAMOND; + $item_count = $num; + + $response = services\BlockChainService::gameItemMallBuy( + Transaction::BUY_GOODS_ACTION_TYPE, + $price, + $item_id, + $item_count + ); + + BcOrder::upsert($response['trans_id'], array( + 'item_id' => $item_id, + 'item_num' => $item_count, + 'order_type' => 1, + 'ext_data' => json_encode(array( + 'mode' => SHOP_BUY_MODE_NORMAL, + )), + )); + + $response['item_id'] = $item_id; + $response['item_num'] = $item_count; + + error_log("buy diamond, item_id = " . $item_id . " item_count = " . $item_count . " num = " . $num . " price = " . $price . " response = " . json_encode($response)); + + $this->_rspData( + array( + "block_chain" => $response + ) + ); + } + public function buyGoodsDS() { $idx = getReqVal('idx', 0); @@ -760,7 +795,7 @@ class ShopController extends BaseAuthedController $sql = "UPDATE t_shop_dailyselection SET count_$grid = count_$grid - $count WHERE idx = $idx"; $chk = $conn->execScript($sql); - + $itemMeta = mt\Item::get($item_id); $propertyChgService = new services\PropertyChgService(); for ($i = 0; $i < $count; $i++) { diff --git a/webapp/services/callback/BuyShopGoodsCbService.php b/webapp/services/callback/BuyShopGoodsCbService.php index c3e82177..ef61194e 100644 --- a/webapp/services/callback/BuyShopGoodsCbService.php +++ b/webapp/services/callback/BuyShopGoodsCbService.php @@ -132,12 +132,12 @@ class BuyShopGoodsCbService $itemService = new ShopAddItemService(); $item_id = $goods['goods_id']; $goods_num = $goods['goods_num']; - + $id = null; if ($goods['id']) { - $id = $goods['id']; + $id = $goods['id']; } - + error_log(json_encode($goods)); error_log('_addGoods ' . $address . ' item_id ' . $item_id . ' goods_num ' . $goods_num . ' id ' . $id); $itemService->addItem($address, $item_id, $goods_num); @@ -146,17 +146,17 @@ class BuyShopGoodsCbService } } - private function getAccountId($address){ + private function getAccountId($address) + { - $row = SqlHelper::ormSelectOne - (myself()->_getMysql($address), + $row = SqlHelper::ormSelectOne( + myself()->_getMysql($address), 't_user', array( - 'address' => $address + 'address' => $address ) - ); + ); return $row['account_id']; -} - + } } From 46a380a3e39157ef38ff9635d466d96be0f7fbab Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 7 Jul 2023 15:01:20 +0800 Subject: [PATCH 03/10] ... --- doc/Shop.py | 14 ++++++++++++++ webapp/controller/ShopController.class.php | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/Shop.py b/doc/Shop.py index 427dc86d..960962d1 100644 --- a/doc/Shop.py +++ b/doc/Shop.py @@ -117,6 +117,20 @@ class Shop(object): ['goods_chg', _common.NewGoods(), '购买后更新商品的最新信息(可能为null客户端需要做容错处理)'], ] }, + { + 'name': 'buyDiamond', + 'desc': '购买钻石', + 'group': 'Shop', + 'url': 'webapp/index.php?c=Shop&a=buyDiamond', + 'params': [ + _common.ReqHead(), + ['num', 0, '购买数量'], + ], + 'response': [ + _common.RspHead(), + ['block_chain', _common.ShopTrans(), '链上购买订单信息'], + ] + }, { 'name': 'buyGoodsDirect', 'desc': '直接购买(充值,gold)', diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index fdea0e17..71b5ce86 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -723,8 +723,8 @@ class ShopController extends BaseAuthedController )), )); - $response['item_id'] = $item_id; - $response['item_num'] = $item_count; + // $response['item_id'] = $item_id; + // $response['item_num'] = $item_count; error_log("buy diamond, item_id = " . $item_id . " item_count = " . $item_count . " num = " . $num . " price = " . $price . " response = " . json_encode($response)); From 60e6a3bfa75235623e1c46aa63042c2678263f96 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 7 Jul 2023 15:03:20 +0800 Subject: [PATCH 04/10] ... --- webapp/controller/ShopController.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 71b5ce86..fdea0e17 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -723,8 +723,8 @@ class ShopController extends BaseAuthedController )), )); - // $response['item_id'] = $item_id; - // $response['item_num'] = $item_count; + $response['item_id'] = $item_id; + $response['item_num'] = $item_count; error_log("buy diamond, item_id = " . $item_id . " item_count = " . $item_count . " num = " . $num . " price = " . $price . " response = " . json_encode($response)); From f3b757d5004d07fb44142b05469f8d22fae86e70 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 7 Jul 2023 15:13:20 +0800 Subject: [PATCH 05/10] ... --- webapp/services/callback/ShopAddItemService.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/webapp/services/callback/ShopAddItemService.php b/webapp/services/callback/ShopAddItemService.php index 5be0bc81..57d60e85 100644 --- a/webapp/services/callback/ShopAddItemService.php +++ b/webapp/services/callback/ShopAddItemService.php @@ -239,6 +239,14 @@ class ShopAddItemService )); } break; + case V_ITEM_DIAMOND: + { + $this->_updateUserInfo($conn,$accountId,array( + 'diamond' => function () use($itemNum) { + return "diamond + ${itemNum}"; + } + )); + } default: { } From 73d4cf58d04be2e49bb3994b523717b99ea08b21 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 7 Jul 2023 15:28:18 +0800 Subject: [PATCH 06/10] ... --- webapp/controller/MarketController.class.php | 30 ++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index a4529f9d..81049a47 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -1164,6 +1164,11 @@ class MarketController extends BaseAuthedController return; } + if (!$this->markOrderBuyStatus($idx)) { + $this->_rspErr(1, 'buy failed, update order status failed, idx:' . $idx); + return; + } + $this->_rspData(array( 'block_chain' => $response, )); @@ -1885,4 +1890,29 @@ class MarketController extends BaseAuthedController } return $row; } + + private function markOrderBuyStatus($idx) + { + $self = myself(); + if (!$self) { + return false; + } + + $r = SqlHelper::update( + $self->_getMarketMysql(''), + 't_market_store', + array( + 'idx' => $idx, + ), + array( + 'status' => 3, + 'buytime' => $self->_getNowTime(), + ) + ); + if (!$r) { + return false; + } + + return true; + } } From f4d1bbe2ed720117268b2e4a93b0d73083b5a987 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 7 Jul 2023 15:34:47 +0800 Subject: [PATCH 07/10] ... --- webapp/controller/MarketController.class.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index 81049a47..bc9560f9 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -24,6 +24,8 @@ require_once('services/BlockChainService.php'); require_once('phpcommon/bchelper.php'); // use phpcommon as phpcommon; + +use models\BcOrder; use phpcommon\SqlHelper; use models\BoxOrder; use models\Nft; @@ -1169,6 +1171,18 @@ class MarketController extends BaseAuthedController return; } + $item_id = $goods['item_id']; + $item_count = $goods['amount']; + + BcOrder::upsert($response['trans_id'], array( + 'item_id' => $item_id, + 'item_num' => $item_count, + 'order_type' => 1, + 'ext_data' => json_encode(array( + 'mode' => SHOP_BUY_MODE_NORMAL, + )), + )); + $this->_rspData(array( 'block_chain' => $response, )); From ebfb2a1a2bfd5685b11464667f987d1827393d8d Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 7 Jul 2023 16:04:44 +0800 Subject: [PATCH 08/10] ... --- sql/gamedb.sql | 1 + sql/gamedb2006_migrate_230707_01.sql | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 sql/gamedb2006_migrate_230707_01.sql diff --git a/sql/gamedb.sql b/sql/gamedb.sql index c1818529..9358ef2c 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -1197,6 +1197,7 @@ CREATE TABLE `t_bc_order` ( `ext_data` mediumblob COMMENT '扩展数据自定义', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + `price` varchar(60) COLLATE utf8_bin NOT NULL COMMENT '价格', PRIMARY KEY (`idx`), UNIQUE KEY `order_id` (`order_id`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; diff --git a/sql/gamedb2006_migrate_230707_01.sql b/sql/gamedb2006_migrate_230707_01.sql new file mode 100644 index 00000000..c315fe6a --- /dev/null +++ b/sql/gamedb2006_migrate_230707_01.sql @@ -0,0 +1,5 @@ +begin; + +alter table t_bc_order add column `price` varchar(60) COMMENT '价格'; + +commit; \ No newline at end of file From 55b5501021ad4ab6881a0c2275135fd62810c983 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 7 Jul 2023 16:13:06 +0800 Subject: [PATCH 09/10] ... --- doc/Market.py | 3 ++- webapp/controller/MarketController.class.php | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/doc/Market.py b/doc/Market.py index bf9eb6ab..57afeb39 100644 --- a/doc/Market.py +++ b/doc/Market.py @@ -346,7 +346,8 @@ class Market(object): ['lv_filter', 0, '等级过滤'], ['quality_filter', 0, '品阶顾虑'], ['durability_filter', 0, '能量过滤'], - ['price_filter', '', '价格过滤(用|分割)'] + ['price_filter', '', '价格过滤(用|分割)'], + ['amount_filter', '', '数量过滤(low:top)'] ], 'response': [ _common.RspHead(), diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index bc9560f9..59e15331 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -767,6 +767,8 @@ class MarketController extends BaseAuthedController $lv_filter = getReqVal('lv_filter', 0); $quality_filter = getReqVal('quality_filter', 0); $durability_filter = getReqVal('durability_filter', 0); + $amount_filter = getReqVal('amount_filter', 0); + $amount_filter_array = explode('|', $amount_filter); $price_filter = getReqVal('price_filter', ''); $price_filter_array = explode('|', $price_filter); @@ -792,6 +794,14 @@ class MarketController extends BaseAuthedController } return ''; }; + $amount_filter_fn = function ($f) { + if (count($f) == 2) { + $low = $f[0]; + $top = $f[1]; + return 'AND amount>=' . $low . ' AND amount<=' . $top . ' '; + } + return ''; + }; $lv_filter_fn = function ($f) { $f = (int) $f; return 'AND c_lv>=' . $f . ' '; @@ -853,6 +863,7 @@ class MarketController extends BaseAuthedController $quality_filter_fn($quality_filter) . $durability_filter_fn($durability_filter) . $price_filter_fn($price_filter_array) . + $amount_filter_fn($amount_filter_array) . $search_filter_fn($search_filter_array) . $order_fn($order_method, $order_asc), array( @@ -877,6 +888,7 @@ class MarketController extends BaseAuthedController $quality_filter_fn($quality_filter) . $durability_filter_fn($durability_filter) . $price_filter_fn($price_filter_array) . + $amount_filter_fn($amount_filter_array) . $search_filter_fn($search_filter_array) . $order_fn($order_method, $order_asc) . 'LIMIT ' . $start . ',' . $page_size, @@ -1173,7 +1185,7 @@ class MarketController extends BaseAuthedController $item_id = $goods['item_id']; $item_count = $goods['amount']; - + BcOrder::upsert($response['trans_id'], array( 'item_id' => $item_id, 'item_num' => $item_count, From 0426e82fe03b1b988866676702963c6a0fe1bcb2 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 7 Jul 2023 16:15:02 +0800 Subject: [PATCH 10/10] ... --- doc/Market.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Market.py b/doc/Market.py index 57afeb39..400c2d72 100644 --- a/doc/Market.py +++ b/doc/Market.py @@ -347,7 +347,7 @@ class Market(object): ['quality_filter', 0, '品阶顾虑'], ['durability_filter', 0, '能量过滤'], ['price_filter', '', '价格过滤(用|分割)'], - ['amount_filter', '', '数量过滤(low:top)'] + ['amount_filter', '', '数量过滤(低|高)'] ], 'response': [ _common.RspHead(),