From d2fc2fd37d4d0a274fd76e272c07bfe32694154e Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 7 Aug 2023 12:18:12 +0800 Subject: [PATCH] 1 --- .../controller/BlockChainController.class.php | 63 ++++++++++++++ webapp/controller/MallController.class.php | 87 ------------------- 2 files changed, 63 insertions(+), 87 deletions(-) diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index 0c1b3187..6b77a220 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -351,6 +351,69 @@ class BlockChainController extends BaseAuthedController { ); } + public function buyMallProduct() + { + $address = $this->_getAddress(); + if (!$address) { + $this->_rspErr(1, 'address not found'); + return; + } + + $idx = getReqVal('idx', ''); + $s_price = getReqVal('s_price', ''); + if (empty($s_price)) { + $this->_rspErr(1, 's_price not found'); + return; + } + if (!is_numeric($s_price)) { + $this->_rspErr(1, 's_price not number'); + return; + } + + $goods = $this->getGoodsByIdx($idx); + if (!$goods) { + $this->_rspErr(1, 'goods not found, idx:' . $idx); + return; + } + + if ($s_price != $goods['s_price']) { + $this->_rspErr(1, 'price not match, idx:' . $idx); + return; + } + + $response = services\BlockChainService::gameItemMarketBuy( + Transaction::BUY_GOODS_FROM_MARKET_ACTION_TYPE, + $goods['owner_address'], + $goods['s_price'], + $goods['item_id'], + $goods['amount'] + ); + + if (!$this->markOrderBuyStatus($idx)) { + $this->_rspErr(1, 'buy failed, update order status failed, idx:' . $idx); + 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' => BcOrder::SPEC_ORDER_TYPE, + 'price' => $this->Web3PriceLowFormat($goods['s_price']), + 'ext_data' => json_encode(array( + 'mode' => BcOrder::MARKET_BUY_MODE_NORMAL, + 'idx' => $idx, + 'order_id' => $goods['order_id'], + )), + )); + + $this->_rspData(array( + 'block_chain' => $response, + )); + } + private static function getWeb3ServiceUrl() { if (SERVER_ENV == _TEST) { diff --git a/webapp/controller/MallController.class.php b/webapp/controller/MallController.class.php index 96d7be4f..0e400580 100644 --- a/webapp/controller/MallController.class.php +++ b/webapp/controller/MallController.class.php @@ -130,30 +130,6 @@ class MallController extends BaseAuthedController { $this->_rspOk(); } - private function genOrderId($id) - { - $order_id_base = date('YmdHis') . "10000000"; - $divIdx = phpcommon\bnToStr(gmp_mod($id, 9999999)); - $order_id = phpcommon\bnAdd_s($order_id_base, $divIdx); - return $order_id; - } - private function lastInsertId($conn) - { - $row = $conn->execQueryOne('SELECT LAST_INSERT_ID() as lastId;', array()); - return $row['lastId']; - } - - private function makeCostItems($item_id, $num) - { - $costItems = array( - array( - 'item_id' => $item_id, - 'item_num' => $num - ) - ); - return $costItems; - } - public function productOffline() { $idx = getReqVal('idx', ''); @@ -268,67 +244,4 @@ class MallController extends BaseAuthedController { $this->_rspOk(); } - public function buyProduct() - { - $address = $this->_getAddress(); - if (!$address) { - $this->_rspErr(1, 'address not found'); - return; - } - - $idx = getReqVal('idx', ''); - $s_price = getReqVal('s_price', ''); - if (empty($s_price)) { - $this->_rspErr(1, 's_price not found'); - return; - } - if (!is_numeric($s_price)) { - $this->_rspErr(1, 's_price not number'); - return; - } - - $goods = $this->getGoodsByIdx($idx); - if (!$goods) { - $this->_rspErr(1, 'goods not found, idx:' . $idx); - return; - } - - if ($s_price != $goods['s_price']) { - $this->_rspErr(1, 'price not match, idx:' . $idx); - return; - } - - $response = services\BlockChainService::gameItemMarketBuy( - Transaction::BUY_GOODS_FROM_MARKET_ACTION_TYPE, - $goods['owner_address'], - $goods['s_price'], - $goods['item_id'], - $goods['amount'] - ); - - if (!$this->markOrderBuyStatus($idx)) { - $this->_rspErr(1, 'buy failed, update order status failed, idx:' . $idx); - 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' => BcOrder::SPEC_ORDER_TYPE, - 'price' => $this->Web3PriceLowFormat($goods['s_price']), - 'ext_data' => json_encode(array( - 'mode' => BcOrder::MARKET_BUY_MODE_NORMAL, - 'idx' => $idx, - 'order_id' => $goods['order_id'], - )), - )); - - $this->_rspData(array( - 'block_chain' => $response, - )); - } - }