From 522c121d8d1f27220be6ecc1743b93bd075fa114 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 14 Jul 2023 11:42:55 +0800 Subject: [PATCH 01/22] 1 --- webapp/controller/CallbackController.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/webapp/controller/CallbackController.class.php b/webapp/controller/CallbackController.class.php index bd5e9178..ee96ac24 100644 --- a/webapp/controller/CallbackController.class.php +++ b/webapp/controller/CallbackController.class.php @@ -4,6 +4,7 @@ class CallbackController extends BaseController { private $handlers = array( 'gameItemMallBuyOk' => 'GameItemMallBuyOk', + 'gameItemMarketBuyOk' => 'GameItemMarketBuyOk', 'MarketSellOrderOk' => 'MarketSellOrderOk', 'MarketBuyOrderOk' => 'MarketBuyOrderOk', 'MarketCancelOrderOk' => 'MarketCancelOrderOk', From 76cb211997c35f609e61341f7c290185f9927e6f Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 14 Jul 2023 11:53:53 +0800 Subject: [PATCH 02/22] ... --- .../services/callback/GameItemMarketBuyOk.php | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 webapp/services/callback/GameItemMarketBuyOk.php diff --git a/webapp/services/callback/GameItemMarketBuyOk.php b/webapp/services/callback/GameItemMarketBuyOk.php new file mode 100644 index 00000000..8faa6881 --- /dev/null +++ b/webapp/services/callback/GameItemMarketBuyOk.php @@ -0,0 +1,83 @@ +_getMysql($address), + 't_bc_order', + array( + 'order_id' => $orderId + ) + ); + //1:已发货 2:订单不存在 + if (!$orderDb){ + echo json_encode(array( + 'errcode' => 2, + 'errmsg' => "Order does not exist", + )); + die ; + } + if ($orderDb['status'] == 1){ + echo json_encode(array( + 'errcode' => 1, + 'errmsg' => "Order shipped", + )); + die; + } +// 修改订单状态 + $this->_updateOrderState($address,$orderId); + +// 小胡 回调的处理 + if ($this->_isVirtualItem($orderDb['item_id'])){ + $passCbService = new BuyPassCbService(); + $passCbService->process($orderDb); + } else { +// 老宋 处理... + $shopGoodsCbService = new BuyShopGoodsCbService(); + $shopGoodsCbService->process($orderDb); + + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => "callback success", + )); + } + + private function _isVirtualItem($itemId){ + return in_array($itemId, array( + V_ITEM_EXP, + V_ITEM_PASS, + V_ITEM_RESET_CARD, + ) + ); + } + + private function _updateOrderState($address,$transId){ + SqlHelper::update + (myself()->_getMysql($address), + 't_bc_order', + array( + 'order_id' => $transId + ), + array( + 'status' => 1, + 'modifytime' => myself()->_getNowTime(), + ) + ); + } + +} From 38848eb8eee0b060484f4afaea75915ffcb1cdff Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 14 Jul 2023 12:18:05 +0800 Subject: [PATCH 03/22] ... --- webapp/bootstrap/constant.php | 1 + webapp/controller/MarketController.class.php | 4 ++-- webapp/controller/ShopController.class.php | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/webapp/bootstrap/constant.php b/webapp/bootstrap/constant.php index 98074b3d..3a9d6b17 100644 --- a/webapp/bootstrap/constant.php +++ b/webapp/bootstrap/constant.php @@ -63,6 +63,7 @@ define('TN_WEEKLY_END', 10005); define('SHOP_BUY_MODE_NORMAL', 0); define('SHOP_BUY_MODE_DAILY_SELECTION', 1); +define('MARKET_BUY_MODE_NORMAL', 2); const kHAT_Begin = 0; const kHAT_Hp = 1; diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index 1a674e1c..2bccebe9 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -681,7 +681,6 @@ class MarketController extends BaseAuthedController public function buy() { - $account = strtolower(getReqVal('account', '')); $idx = getReqVal('idx', ''); $goods = $this->getGoodsByIdx($idx); @@ -712,7 +711,8 @@ class MarketController extends BaseAuthedController 'order_type' => 1, 'price' => $goods['s_price'], 'ext_data' => json_encode(array( - 'mode' => SHOP_BUY_MODE_NORMAL, + 'mode' => MARKET_BUY_MODE_NORMAL, + 'idx' => $idx, )), )); diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index e274fe31..295ae851 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -699,16 +699,16 @@ class ShopController extends BaseAuthedController { $address = $this->_getAccountId(); - $maxCount = mt\Parameter::getByName('daily_selection_refresh_time')['param_value']; + $costs = mt\Parameter::getByName('daily_selection_refresh_cost'); + $arrCosts = explode('|', $costs['param_value']); + $maxCount = count($arrCosts); + $count = $this->countTodayRefreshTimes($address); 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); From 46e514801c623ffb6229c00c199c24046317d29f Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 14 Jul 2023 12:20:12 +0800 Subject: [PATCH 04/22] ... --- webapp/controller/MarketController.class.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index 2bccebe9..b18c4c24 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -681,6 +681,12 @@ class MarketController extends BaseAuthedController public function buy() { + $address = $this->_getAddress(); + if (!$address) { + $this->_rspErr(1, 'address not found'); + return; + } + $idx = getReqVal('idx', ''); $goods = $this->getGoodsByIdx($idx); From 73667b06717a098a93fbe5fc0dfe1cdd7fd56751 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 14 Jul 2023 13:14:23 +0800 Subject: [PATCH 05/22] ... --- webapp/services/callback/GameItemMarketBuyOk.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/services/callback/GameItemMarketBuyOk.php b/webapp/services/callback/GameItemMarketBuyOk.php index 8faa6881..f1810d1a 100644 --- a/webapp/services/callback/GameItemMarketBuyOk.php +++ b/webapp/services/callback/GameItemMarketBuyOk.php @@ -8,7 +8,7 @@ require_once ('services/callback/BuyShopGoodsCbService.php'); use phpcommon\SqlHelper; -class GameItemMallBuyOk { +class GameItemMarketBuyOk { public function process() { From 5368924a12335fdf095553411cd8c2c3e27ea534 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 14 Jul 2023 13:49:08 +0800 Subject: [PATCH 06/22] 1 --- .../callback/common/SignatureService.php | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/webapp/services/callback/common/SignatureService.php b/webapp/services/callback/common/SignatureService.php index 155599d5..6529a162 100644 --- a/webapp/services/callback/common/SignatureService.php +++ b/webapp/services/callback/common/SignatureService.php @@ -4,8 +4,33 @@ namespace services; class SignatureService { - public static function web3ServiceCheck() { + const ERRCODE_SIGN = 2001; + public static function web3ServiceCheck() + { + $cbUuid = getReqVal('_cb_uuid', ''); + $row = SqlHelper::ormSelectOne( + myself()->_getMarketMysql(), + 't_callback', + array( + 'cb_uuid' => $cbUuid + ) + ); + if (!$row) { + myself()-_rspErr(self::ERRCODE); + die(); + } + } + + public static function normalMd5Sign($params, $secretKey, $excludeKeys){ + ksort($params); + $paramsStr = ''; + foreach($params as $key => $val){ + if (!in_array($key, $excludeKeys)) { + $paramsStr = $paramsStr . $key . '=' . $val . $connStr; + } + } + return md5($paramsStr . $$secretKey); } } From 300d4fcc3ca40e5058743a58a11122848a876c27 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 14 Jul 2023 13:54:20 +0800 Subject: [PATCH 07/22] 1 --- webapp/services/callback/common/SignatureService.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/webapp/services/callback/common/SignatureService.php b/webapp/services/callback/common/SignatureService.php index 6529a162..4aea21e0 100644 --- a/webapp/services/callback/common/SignatureService.php +++ b/webapp/services/callback/common/SignatureService.php @@ -20,6 +20,11 @@ class SignatureService { myself()-_rspErr(self::ERRCODE); die(); } + $sign = self::normalMd5Sign($_REQUEST, $row['secret_key'], array('_sign')); + if ($sign != $row['signature']) { + myself()-_rspErr(self::ERRCODE); + die(); + } } public static function normalMd5Sign($params, $secretKey, $excludeKeys){ From 4435fb06310cd5c5c48cda2a8793dced73c18bb5 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 14 Jul 2023 13:56:53 +0800 Subject: [PATCH 08/22] ... --- webapp/controller/MarketController.class.php | 5 +- .../callback/BuyShopGoodsCbService.php | 2 + .../services/callback/GameItemMarketBuyOk.php | 216 ++++++++++++------ 3 files changed, 155 insertions(+), 68 deletions(-) diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index b18c4c24..ccf79f4d 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -686,7 +686,7 @@ class MarketController extends BaseAuthedController $this->_rspErr(1, 'address not found'); return; } - + $idx = getReqVal('idx', ''); $goods = $this->getGoodsByIdx($idx); @@ -719,6 +719,7 @@ class MarketController extends BaseAuthedController 'ext_data' => json_encode(array( 'mode' => MARKET_BUY_MODE_NORMAL, 'idx' => $idx, + 'order_id' => $goods['order_id'], )), )); @@ -1379,7 +1380,7 @@ class MarketController extends BaseAuthedController $row = SqlHelper::selectOne( myself()->_getSelfMysql(), 't_market_store', - array('item_id', 'amount', 's_price', 'owner_address'), + array('order_id', 'item_id', 'amount', 's_price', 'owner_address'), array( 'idx' => $idx, 'status' => 0, diff --git a/webapp/services/callback/BuyShopGoodsCbService.php b/webapp/services/callback/BuyShopGoodsCbService.php index 12c4965f..2431e741 100644 --- a/webapp/services/callback/BuyShopGoodsCbService.php +++ b/webapp/services/callback/BuyShopGoodsCbService.php @@ -59,6 +59,8 @@ class BuyShopGoodsCbService )), )); break; + case MARKET_BUY_MODE_NORMAL: + break; } } break; diff --git a/webapp/services/callback/GameItemMarketBuyOk.php b/webapp/services/callback/GameItemMarketBuyOk.php index f1810d1a..9d2af813 100644 --- a/webapp/services/callback/GameItemMarketBuyOk.php +++ b/webapp/services/callback/GameItemMarketBuyOk.php @@ -3,81 +3,165 @@ namespace services; require_once('phpcommon/bchelper.php'); -require_once ('services/callback/BuyPassCbService.php'); -require_once ('services/callback/BuyShopGoodsCbService.php'); +require_once('services/callback/BuyPassCbService.php'); +require_once('services/callback/BuyShopGoodsCbService.php'); +require_once('ShopAddItemService.php'); use phpcommon\SqlHelper; +use models\ShopBuyRecord; -class GameItemMarketBuyOk { +class GameItemMarketBuyOk +{ - public function process() - { - $address = getReqVal('address', ''); - $orderId = getReqVal('order_id', ''); - - error_log("GameItemMallBuyOk-------------------"); - $orderDb = SqlHelper::ormSelectOne( - myself()->_getMysql($address), - 't_bc_order', - array( - 'order_id' => $orderId - ) - ); - //1:已发货 2:订单不存在 - if (!$orderDb){ - echo json_encode(array( - 'errcode' => 2, - 'errmsg' => "Order does not exist", - )); - die ; + public function process() + { + $itemService = new ShopAddItemService(); + $address = getReqVal('address', ''); + $orderId = getReqVal('order_id', ''); + + error_log("GameItemMallBuyOk-------------------"); + $orderDb = SqlHelper::ormSelectOne( + myself()->_getMysql($address), + 't_bc_order', + array( + 'order_id' => $orderId + ) + ); + //1:已发货 2:订单不存在 + if (!$orderDb) { + echo json_encode(array( + 'errcode' => 2, + 'errmsg' => "Order does not exist", + )); + die; + } + if ($orderDb['status'] == 1) { + echo json_encode(array( + 'errcode' => 1, + 'errmsg' => "Order shipped", + )); + die; + } + // 修改订单状态 + $this->_updateOrderState($address, $orderId); + + $ext_data = json_decode($orderDb['ext_data'], true); + + switch ($ext_data['mode']) { + case MARKET_BUY_MODE_NORMAL: { + $order = $orderDb; + $itemService->addGameLog($order['address'], "shopBuyNormal", "begin", array( + 'param1' => $order['order_id'], + 'param2' => json_encode(array( + 'item_id' => $order['item_id'], + 'item_num' => $order['item_num'], + )), + )); + $this->buyFromMarket($order, $ext_data['idx']); + $itemService->addGameLog($order['address'], "shopBuyNormal", "end", array( + 'param1' => $order['order_id'], + 'param2' => json_encode(array( + 'item_id' => $order['item_id'], + 'item_num' => $order['item_num'], + )), + )); } - if ($orderDb['status'] == 1){ - echo json_encode(array( - 'errcode' => 1, - 'errmsg' => "Order shipped", - )); - die; - } -// 修改订单状态 - $this->_updateOrderState($address,$orderId); - -// 小胡 回调的处理 - if ($this->_isVirtualItem($orderDb['item_id'])){ - $passCbService = new BuyPassCbService(); - $passCbService->process($orderDb); - } else { -// 老宋 处理... - $shopGoodsCbService = new BuyShopGoodsCbService(); - $shopGoodsCbService->process($orderDb); - - } - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => "callback success", - )); + break; } - private function _isVirtualItem($itemId){ - return in_array($itemId, array( - V_ITEM_EXP, - V_ITEM_PASS, - V_ITEM_RESET_CARD, - ) - ); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => "callback success", + )); + } + + private function _isVirtualItem($itemId) + { + return in_array( + $itemId, + array( + V_ITEM_EXP, + V_ITEM_PASS, + V_ITEM_RESET_CARD, + ) + ); + } + + private function _updateOrderState($address, $transId) + { + SqlHelper::update( + myself()->_getMysql($address), + 't_bc_order', + array( + 'order_id' => $transId + ), + array( + 'status' => 1, + 'modifytime' => myself()->_getNowTime(), + ) + ); + } + + private function buyFromMarket($order, $idx) + { + $address = $order['address']; + $goods = $this->getMarketGoods($address, $idx); + $this->markMarketGoodsSold($address, $idx); + + $this->_addGoods($address, $goods); + } + + private function getMarketGoods($address, $idx) + { + $row = SqlHelper::selectOne( + myself()->_getMysql($address), + 't_market_store', + array('order_id', 'item_id', 'amount', 's_price', 'owner_address'), + array( + 'idx' => $idx + ) + ); + if (!$row) { + return null; + } + if (!$row['item_id']) { + return null; + } + return $row; + } + + private function markMarketGoodsSold($address, $idx) + { + SqlHelper::update( + myself()->_getMysql($address), + 't_market_store', + array( + 'idx' => $idx + ), + array( + 'status' => 2, + 'modifytime' => myself()->_getNowTime(), + ) + ); + } + + private function _addGoods($address, $goods) + { + $itemService = new ShopAddItemService(); + $item_id = $goods['item_id']; + $goods_num = $goods['amount']; + + $id = null; + if ($goods['id']) { + $id = $goods['id']; } - private function _updateOrderState($address,$transId){ - SqlHelper::update - (myself()->_getMysql($address), - 't_bc_order', - array( - 'order_id' => $transId - ), - array( - 'status' => 1, - 'modifytime' => myself()->_getNowTime(), - ) - ); + error_log(json_encode($goods)); + error_log('_addGoods ' . $address . ' item_id ' . $item_id . ' goods_num ' . $amount . ' id ' . $id); + $itemService->addItem($address, $item_id, $goods_num); + if ($id) { + ShopBuyRecord::addWithAddress($address, $id, $goods_num); } + } } From ef426965b3526289374ddb6f6ea5fd86df6bb683 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 14 Jul 2023 14:00:57 +0800 Subject: [PATCH 09/22] ... --- webapp/services/callback/GameItemMarketBuyOk.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/services/callback/GameItemMarketBuyOk.php b/webapp/services/callback/GameItemMarketBuyOk.php index 9d2af813..ed5424bd 100644 --- a/webapp/services/callback/GameItemMarketBuyOk.php +++ b/webapp/services/callback/GameItemMarketBuyOk.php @@ -152,12 +152,12 @@ class GameItemMarketBuyOk $goods_num = $goods['amount']; $id = null; - if ($goods['id']) { + if (!empty($goods['id'])) { $id = $goods['id']; } error_log(json_encode($goods)); - error_log('_addGoods ' . $address . ' item_id ' . $item_id . ' goods_num ' . $amount . ' id ' . $id); + error_log('_addGoods ' . $address . ' item_id ' . $item_id . ' goods_num ' . $goods_num . ' id ' . $id); $itemService->addItem($address, $item_id, $goods_num); if ($id) { ShopBuyRecord::addWithAddress($address, $id, $goods_num); From 9526252f38e2db043109faf3f5fc188b6b3f25e8 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 14 Jul 2023 14:10:08 +0800 Subject: [PATCH 10/22] ... --- webapp/controller/MarketController.class.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index ccf79f4d..aebacedd 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -249,7 +249,6 @@ class MarketController extends BaseAuthedController $job_filters = getReqVal('job_filters', ''); $job_filter_array = explode('|', $job_filters); $search_filters = getReqVal('search_filters', ''); - error_log('search_filters:' . $search_filters); if ($search_filters != '') { $search_filter_array = explode('|', $search_filters); } else { @@ -446,7 +445,6 @@ class MarketController extends BaseAuthedController } $search_filters = getReqVal('search_filters', ''); - error_log('search_filters:' . $search_filters); if ($search_filters != '') { $search_filter_array = explode('|', $search_filters); } else { From aa70d11a5b0e51c1291bab8cb43276fbd2359ec0 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 14 Jul 2023 14:43:53 +0800 Subject: [PATCH 11/22] ... --- webapp/controller/MarketController.class.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index aebacedd..83c6ca94 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -307,14 +307,12 @@ class MarketController extends BaseAuthedController }; $search_filter_fn = function ($f) { $str = ''; - error_log('search_filter ' . json_encode($f)); $arr_options = array(); foreach ($f as $v) { if (!empty($v)) { array_push($arr_options, 'c_name=\'' . $v . '\' OR token_id=\'' . $v . '\' '); } } - error_log('$$search_filter ' . json_encode($arr_options)); if (count($arr_options) > 0) { $str = implode('OR ', $arr_options); $str = 'AND (' . $str . ') '; From 5dee2fc3f0d7dfcdfb054a2dbfaf3f955d98ec98 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 14 Jul 2023 14:46:36 +0800 Subject: [PATCH 12/22] ... --- webapp/services/FormulaService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/webapp/services/FormulaService.php b/webapp/services/FormulaService.php index f3af5026..08555d6f 100644 --- a/webapp/services/FormulaService.php +++ b/webapp/services/FormulaService.php @@ -7,6 +7,7 @@ require_once('mt/Item.php'); require_once('mt/FormulaPvp.php'); require_once('mt/HeroQuality.php'); require_once('mt/GunQuality.php'); +require_once('mt/Parameter.php'); require_once('models/RealtimeData.php'); use models\Chip; From a7a0a9b5ffc648894813a1b5260e8b117908fecf Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 14 Jul 2023 14:48:41 +0800 Subject: [PATCH 13/22] ... --- webapp/services/callback/MarketCallbackBase.php | 1 + 1 file changed, 1 insertion(+) diff --git a/webapp/services/callback/MarketCallbackBase.php b/webapp/services/callback/MarketCallbackBase.php index b11702ee..423d9035 100644 --- a/webapp/services/callback/MarketCallbackBase.php +++ b/webapp/services/callback/MarketCallbackBase.php @@ -2,6 +2,7 @@ namespace services; +require_once('phpcommon/bignumber.php'); use phpcommon\SqlHelper; use phpcommon; From dd5d78003ff3f012a3c586562cca4b209b5c863b Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 14 Jul 2023 15:21:12 +0800 Subject: [PATCH 14/22] ... --- webapp/controller/MarketController.class.php | 8 +++++++- webapp/controller/ShopController.class.php | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index 83c6ca94..82ac33cf 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -711,7 +711,7 @@ class MarketController extends BaseAuthedController 'item_id' => $item_id, 'item_num' => $item_count, 'order_type' => 1, - 'price' => $goods['s_price'], + 'price' => $this->Web3PriceLowFormat($goods['s_price']), 'ext_data' => json_encode(array( 'mode' => MARKET_BUY_MODE_NORMAL, 'idx' => $idx, @@ -723,6 +723,12 @@ class MarketController extends BaseAuthedController 'block_chain' => $response, )); } + private function Web3PriceLowFormat($price) { + $bn2 = phpcommon\bnInit('1000000000000000000'); + $ret_price = phpcommon\bnDiv($price, $bn2); + return phpcommon\bnToStr($ret_price); + } + private function sellMyNft() { diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 295ae851..7fc430d8 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -702,7 +702,7 @@ class ShopController extends BaseAuthedController $costs = mt\Parameter::getByName('daily_selection_refresh_cost'); $arrCosts = explode('|', $costs['param_value']); $maxCount = count($arrCosts); - + $count = $this->countTodayRefreshTimes($address); if ($count >= $maxCount) { $this->_rspErr(2, 'The maximum number of refreshes has been reached'); @@ -1993,6 +1993,12 @@ class ShopController extends BaseAuthedController return phpcommon\bnToStr($ret_price); } + private function Web3PriceLowFormat($price) { + $bn2 = phpcommon\bnInit('1000000000000000000'); + $ret_price = phpcommon\bnDiv($price, $bn2); + return phpcommon\bnToStr($ret_price); + } + private function countFreeBuyTimes($free_type, $id, $goods_id) { $conn = myself()->_getMysql(''); From 408adc225d7a4943e334fd59a53215cb9ecf598e Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 14 Jul 2023 15:22:53 +0800 Subject: [PATCH 15/22] ... --- 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 82ac33cf..5cd94f09 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -718,7 +718,7 @@ class MarketController extends BaseAuthedController 'order_id' => $goods['order_id'], )), )); - + $this->_rspData(array( 'block_chain' => $response, )); From 04c01a4659f714e27a9627dced62c112eba3e948 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 14 Jul 2023 15:41:27 +0800 Subject: [PATCH 16/22] 1 --- webapp/controller/CallbackController.class.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/webapp/controller/CallbackController.class.php b/webapp/controller/CallbackController.class.php index ee96ac24..04268a96 100644 --- a/webapp/controller/CallbackController.class.php +++ b/webapp/controller/CallbackController.class.php @@ -1,5 +1,10 @@ Date: Fri, 14 Jul 2023 15:43:16 +0800 Subject: [PATCH 17/22] 1 --- webapp/services/callback/GameItemMallBuyOk.php | 2 ++ webapp/services/callback/common/SignatureService.php | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/webapp/services/callback/GameItemMallBuyOk.php b/webapp/services/callback/GameItemMallBuyOk.php index 8faa6881..e4c34910 100644 --- a/webapp/services/callback/GameItemMallBuyOk.php +++ b/webapp/services/callback/GameItemMallBuyOk.php @@ -5,6 +5,7 @@ namespace services; require_once('phpcommon/bchelper.php'); require_once ('services/callback/BuyPassCbService.php'); require_once ('services/callback/BuyShopGoodsCbService.php'); +require_once ('services/callback/common/SignatureService.php'); use phpcommon\SqlHelper; @@ -12,6 +13,7 @@ class GameItemMallBuyOk { public function process() { + SignatureService::web3ServiceCheck(); $address = getReqVal('address', ''); $orderId = getReqVal('order_id', ''); diff --git a/webapp/services/callback/common/SignatureService.php b/webapp/services/callback/common/SignatureService.php index 4aea21e0..9c31bb3d 100644 --- a/webapp/services/callback/common/SignatureService.php +++ b/webapp/services/callback/common/SignatureService.php @@ -17,12 +17,12 @@ class SignatureService { ) ); if (!$row) { - myself()-_rspErr(self::ERRCODE); + myself()-_rspErr(self::ERRCODE_SIGN); die(); } $sign = self::normalMd5Sign($_REQUEST, $row['secret_key'], array('_sign')); if ($sign != $row['signature']) { - myself()-_rspErr(self::ERRCODE); + myself()-_rspErr(self::ERRCODE_SIGN); die(); } } From dc7946c7ff5e69323018d607de0ccb113c214f12 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 14 Jul 2023 15:43:33 +0800 Subject: [PATCH 18/22] ... --- webapp/controller/ShopController.class.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 7fc430d8..1f922568 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -1129,7 +1129,7 @@ class ShopController extends BaseAuthedController $token_type = $goods['token_type']; $costItemId = $this->getCostItemIdByTokenType($token_type); - $costItems = $this->makeCostItems($costItemId, $goods['goods_num'] * $count * $goods['price']); + $costItems = $this->makeCostItems($costItemId, $count * $goods['price']); $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); @@ -1138,7 +1138,7 @@ class ShopController extends BaseAuthedController $item_id = $goods['goods_id']; - $item_num = $goods['goods_num'] * $count; + $item_num = $goods['goods_num']; $sql = "UPDATE t_shop_dailyselection SET count_$grid = count_$grid - $count WHERE idx = $idx"; $chk = $conn->execScript($sql); @@ -1149,7 +1149,7 @@ class ShopController extends BaseAuthedController $this->internalAddItem($propertyChgService, $itemMeta, $item_num, 0); } $awardService = new services\AwardService(); - $awardService->addItem($goods['goods_id'], $count); + $awardService->addItem($goods['goods_id'], $count * $item_num); $this->_decItems($costItems); $event = [ @@ -1993,12 +1993,6 @@ class ShopController extends BaseAuthedController return phpcommon\bnToStr($ret_price); } - private function Web3PriceLowFormat($price) { - $bn2 = phpcommon\bnInit('1000000000000000000'); - $ret_price = phpcommon\bnDiv($price, $bn2); - return phpcommon\bnToStr($ret_price); - } - private function countFreeBuyTimes($free_type, $id, $goods_id) { $conn = myself()->_getMysql(''); From 04b228b061b62d843b52590a612239209a4ff7f6 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 14 Jul 2023 15:47:19 +0800 Subject: [PATCH 19/22] 1 --- webapp/services/callback/common/SignatureService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webapp/services/callback/common/SignatureService.php b/webapp/services/callback/common/SignatureService.php index 9c31bb3d..e4f4e0bc 100644 --- a/webapp/services/callback/common/SignatureService.php +++ b/webapp/services/callback/common/SignatureService.php @@ -4,7 +4,7 @@ namespace services; class SignatureService { - const ERRCODE_SIGN = 2001; + const ERRCODE_SIGN_ERROR = 2001; public static function web3ServiceCheck() { @@ -17,12 +17,12 @@ class SignatureService { ) ); if (!$row) { - myself()-_rspErr(self::ERRCODE_SIGN); + myself()-_rspErr(self::ERRCODE_SIGN_ERROR, 'not found cb info'); die(); } $sign = self::normalMd5Sign($_REQUEST, $row['secret_key'], array('_sign')); if ($sign != $row['signature']) { - myself()-_rspErr(self::ERRCODE_SIGN); + myself()-_rspErr(self::ERRCODE_SIGN_ERROR, 'sign error'); die(); } } From 17c8cd647821f3543b2c7b62c1f3efed5e8ba01d Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 14 Jul 2023 15:53:03 +0800 Subject: [PATCH 20/22] ... --- webapp/controller/MarketController.class.php | 266 +------------------ 1 file changed, 1 insertion(+), 265 deletions(-) diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index 5cd94f09..a0bc677a 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -43,19 +43,6 @@ use models\Transaction; class MarketController extends BaseAuthedController { - - public function _handlePre() - { - if ( - getReqVal('a', '') != 'eventSellOrder' && - getReqVal('a', '') != 'eventBuyOrder' && - getReqVal('a', '') != 'eventCancelOrder' && - getReqVal('a', '') != 'eventPriceUpdateOrder' - ) { - parent::_handlePre(); - } - } - private function getNftListByAccountAndType($account, $type, $order_method, $order_asc, $job, $search, $lv, $quality, $durability) { $sortByLevel = function ($a, $b) use ($order_asc) { @@ -718,7 +705,7 @@ class MarketController extends BaseAuthedController 'order_id' => $goods['order_id'], )), )); - + $this->_rspData(array( 'block_chain' => $response, )); @@ -863,257 +850,6 @@ class MarketController extends BaseAuthedController )); } - private function addTransactionRecord($record) - { - $conn = myself()->_getMarketMysql(''); - - $r = SqlHelper::insert( - $conn, - 't_market_transaction_record', - $record - ); - if (!$r) { - $this->_rspErr(2, 'unknown error, orderId=' . $record['order_id']); - } - } - - public function eventSellOrder() - { - $tokenId = getReqVal('tokenId', ''); - $owner = strtolower(getReqVal('owner', '')); - $nftToken = getReqVal('nftToken', ''); - $amount = getReqVal('amount', 0); - $orderId = getReqVal('orderId', ''); - $currency = getReqVal('currency', ''); - $price = getReqVal('price', ''); - - error_log( - "eventSellOrder:" . json_encode( - array( - 'tokenId' => $tokenId, - 'owner' => $owner, - 'nftToken' => $nftToken, - 'amount' => $amount, - 'orderId' => $orderId, - 'currency' => $currency, - 'price' => $price, - ), - JSON_PRETTY_PRINT - ) - ); - - $conn = myself()->_getSelfMysql(); - - // 1. check order status - $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); - if (!empty($chk)) { - $this->_rspErr(1, 'repeat sell order, orderId=' . $orderId); - return; - } - - // 2. insert sell order to t_market_store - $nftDb = Nft::findNftByOwner($owner, $tokenId); - if (empty($nftDb)) { - $nftDb = Nft::getNft($tokenId); - } - $nftDetail = Nft::toDto($nftDb); - $detail = $this->getNftGameData($nftDb); - $r = SqlHelper::insert( - $conn, - 't_market_store', - array( - 'token_id' => $tokenId, - 'o_link' => $orderId, - 'nft_token' => $nftToken, - 'status' => 0, - 'owner_address' => $owner, - 'token_type' => $nftDetail['type'], - 'amount' => $amount, - 'createtime' => myself()->_getNowTime(), - 'modifytime' => myself()->_getNowTime(), - 's_currency' => $currency, - 's_price' => $price, - 'c_name' => $nftDetail['info']['name'], - 'c_job' => isset($nftDetail['info']['job']) ? $nftDetail['info']['job'] - : (isset($detail['chip_type']) ? $detail['chip_type'] - : (isset($detail['type']) ? $detail['type'] - : 0)), - 'c_lv' => @$detail['gun_lv'] | @$detail['hero_lv'] | @$detail['chip_grade'], - 'c_quality' => isset($nftDetail['info']['quality']) ? $nftDetail['info']['quality'] : 0, - 'c_durability' => isset($nftDetail['info']['durability']) ? $nftDetail['info']['durability'] : (isset($detail['hero_tili']) ? $detail['hero_tili'] : 0), - 'c_type' => isset($detail['type']) ? $detail['type'] : 0, - 'c_id' => $nftDetail['item_id'], - ) - ); - if (!$r) { - $this->_rspErr(2, 'unknown error, orderId=' . $orderId); - } - - $this->_rspOk(); - } - - public function eventBuyOrder() - { - $tokenId = getReqVal('tokenId', ''); - $orderId = getReqVal('orderId', ''); - $nftToken = getReqVal('nftToken', ''); - $amount = getReqVal('amount', 0); - $seller = strtolower(getReqVal('seller', '')); - $buyer = strtolower(getReqVal('buyer', '')); - $erc20 = getReqVal('erc20', ''); - $price = getReqVal('price', ''); - - error_log( - "eventBuyOrder:" . json_encode( - array( - 'tokenId' => $tokenId, - 'orderId' => $orderId, - 'nftToken' => $nftToken, - 'amount' => $amount, - 'seller' => $seller, - 'buyer' => $buyer, - 'erc20' => $erc20, - 'price' => $price, - ), - JSON_PRETTY_PRINT - ) - ); - - // nft order id 统一改为 o_link 字段 - $o_link = $orderId; - - $conn = myself()->_getSelfMysql(); - - // 1. check order status - $chk = SqlHelper::selectOne($conn, 't_market_store', array('status', 'idx', 'c_name', 'token_type'), array('o_link' => $o_link)); - if (empty($chk)) { - $this->_rspErr(1, 'not found order, orderId=' . $o_link); - return; - } - if ($chk['status'] == '0') { - $r = SqlHelper::update( - $conn, - 't_market_store', - array( - 'o_link' => $o_link, - ), - array( - 'status' => 2, - ) - ); - if ($r) { - // 增加交易记录 - $record = array( - 'createtime' => myself()->_getNowTime(), - 'order_id' => $chk['idx'], - 'o_link' => $o_link, - 'seller' => $seller, - 'buyer' => $buyer, - 'tokenid' => $tokenId, - 'amount' => $amount, - 'name' => $chk['c_name'], - 'type' => $chk['token_type'], - ); - $this->addTransactionRecord($record); - $this->_rspOk(); - return; - } - } - $this->_rspErr(1, 'order status error, order=' . $orderId); - } - - public function eventCancelOrder() - { - $orderId = getReqVal('orderId', ''); - $nftToken = getReqVal('nftToken', ''); - $tokenId = getReqVal('tokenId', ''); - error_log( - "eventCancelOrder:" . json_encode( - array( - 'orderId' => $orderId, - 'nftToken' => $nftToken, - 'tokenId' => $tokenId, - ), - JSON_PRETTY_PRINT - ) - ); - - $conn = myself()->_getSelfMysql(); - - // 1. check order status - $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); - if (empty($chk)) { - $this->_rspErr(1, 'not found order, orderId=' . $orderId); - return; - } - if ($chk['status'] == '0') { - $r = SqlHelper::update( - $conn, - 't_market_store', - array( - 'o_link' => $orderId, - ), - array( - 'status' => 1, - ) - ); - if ($r) { - $this->_rspOk(); - return; - } - } - $this->_rspErr(1, 'order status error, order=' . $orderId); - } - - public function eventPriceUpdateOrder() - { - $orderId = getReqVal('orderId', '');; - $nftToken = getReqVal('nftToken', ''); - $tokenId = getReqVal('tokenId', ''); - $priceOld = getReqVal('priceOld', ''); - $price = getReqVal('price', ''); - error_log( - "eventPriceUpdateOrder:" . json_encode( - array( - 'orderId' => $orderId, - 'nftToken' => $nftToken, - 'tokenId' => $tokenId, - 'priceOld' => $priceOld, - 'price' => $price, - ), - JSON_PRETTY_PRINT - ) - ); - - $conn = myself()->_getSelfMysql(); - - // 1. check order status - $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); - if (empty($chk)) { - $this->_rspErr(1, 'not found order, orderId=' . $orderId); - return; - } - - if ($chk['status'] == '0') { - $r = SqlHelper::update( - $conn, - 't_market_store', - array( - 'o_link' => $orderId, - ), - array( - 's_price' => $price, - ) - ); - if ($r) { - $this->_rspOk(); - return; - } - } - - $this->_rspErr(1, 'price update failed, orderId=' . $orderId); - } - private function getNftGameData($nftRowInfo) { $t = $nftRowInfo['token_type']; From 2e8273916ee295583a138abdc8558d929b904e01 Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 14 Jul 2023 15:58:28 +0800 Subject: [PATCH 21/22] ... --- sql/gamedb.sql | 2 +- sql/gamedb2006_migrate_230713_01.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 88b52b51..29081abc 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -1346,7 +1346,7 @@ CREATE TABLE `t_market_transaction_record` ( `buyer` varchar(60) NOT NULL COMMENT '买家', `token_id` varchar(60) NOT NULL COMMENT 'tokenid', `item_id` int(11) DEFAULT NULL COMMENT '如果有,说明是中心化道具交易', - `amount` int(11) NOT NULL COMMENT '堆叠数量', + `amount` bigint(11) NOT NULL COMMENT '堆叠数量', `name` varchar(64) NOT NULL COMMENT '商品名称', `type` int(11) NOT NULL COMMENT '商品类型', PRIMARY KEY (`idx`), diff --git a/sql/gamedb2006_migrate_230713_01.sql b/sql/gamedb2006_migrate_230713_01.sql index 6bed84d0..47eb2225 100644 --- a/sql/gamedb2006_migrate_230713_01.sql +++ b/sql/gamedb2006_migrate_230713_01.sql @@ -49,7 +49,7 @@ CREATE TABLE `t_market_transaction_record` ( `buyer` varchar(60) NOT NULL COMMENT '买家', `token_id` varchar(60) NOT NULL COMMENT 'tokenid', `item_id` int(11) DEFAULT NULL COMMENT '如果有,说明是中心化道具交易', - `amount` int(11) NOT NULL COMMENT '堆叠数量', + `amount` bigint(20) NOT NULL COMMENT '堆叠数量', `name` varchar(64) NOT NULL COMMENT '商品名称', `type` int(11) NOT NULL COMMENT '商品类型', PRIMARY KEY (`idx`), From 0163373957ae01de60db959927dfdfe4987b14da Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 14 Jul 2023 15:59:48 +0800 Subject: [PATCH 22/22] ... --- sql/gamedb.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 29081abc..c76c7ce4 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -1346,7 +1346,7 @@ CREATE TABLE `t_market_transaction_record` ( `buyer` varchar(60) NOT NULL COMMENT '买家', `token_id` varchar(60) NOT NULL COMMENT 'tokenid', `item_id` int(11) DEFAULT NULL COMMENT '如果有,说明是中心化道具交易', - `amount` bigint(11) NOT NULL COMMENT '堆叠数量', + `amount` bigint(20) NOT NULL COMMENT '堆叠数量', `name` varchar(64) NOT NULL COMMENT '商品名称', `type` int(11) NOT NULL COMMENT '商品类型', PRIMARY KEY (`idx`),