From 100773ef2251b1ec3279e8e42a94bf56c579a884 Mon Sep 17 00:00:00 2001 From: azw Date: Fri, 28 Jul 2023 22:18:00 +0800 Subject: [PATCH 01/39] 1 --- .../controller/BlockChainController.class.php | 47 ++ webapp/controller/ShopController.class.php | 406 +++++++----------- webapp/mt/Shop.php | 41 +- 3 files changed, 247 insertions(+), 247 deletions(-) diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index 8f8c5534..916ddcda 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -281,6 +281,53 @@ class BlockChainController extends BaseAuthedController { } } + public function buyDiamond() + { + $num = getReqVal('num', 0); + if (!is_numeric($num)) { + $this->_rspErr(1, "num is invalid, {$num}"); + return; + } + if ($num <= 0) { + $this->_rspErr(1, "num is invalid, {$num}"); + return; + } + + $price = $this->normalizeWeb3Price($num); + $item_id = V_ITEM_DIAMOND; + $item_count = $num; + + error_log("buy diamond start " . $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, + 'price' => $num, + '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 + ) + ); + } + private static function getWeb3ServiceUrl() { if (SERVER_ENV == _TEST) { diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index a9906dde..fa43e1e8 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -49,43 +49,6 @@ use services\ShopAddItemService; class ShopController extends BaseAuthedController { - const TOKEN_TYPE_GOLD = '0'; - const TOKEN_TYPE_CEG = '1'; - const TOKEN_TYPE_CEC = '2'; - const TOKEN_TYPE_BCEG = '3'; - const TOKEN_TYPE_DIAMOND = '4'; - - - const TOKEN_TYPE_USDT = '11'; - const TOKEN_TYPE_USDC = '12'; - const TOKEN_TYPE_BUSD = '13'; - - const TOKEN_TYPE_MATIC = '101'; - const TOKEN_TYPE_BNB = '102'; - - //99 = 美元 - const TOKEN_TYPE_USD = '99'; - - //21 = 印尼 - const TOKEN_TYPE_IDR = '21'; - //22 = 菲律宾 - const TOKEN_TYPE_PHP = '22'; - //23 = 越南 - const TOKEN_TYPE_VND = '23'; - //24 = 泰国 - const TOKEN_TYPE_THB = '24'; - //25 = 马来西亚 - const TOKEN_TYPE_MYR = '25'; - //26 = 日本 - const TOKEN_TYPE_JPY = '26'; - //27 = 韩国 - const TOKEN_TYPE_KRW = '27'; - - // 限购类型 - const DAILY_BUY_LIMIT = 1; - const WEEKLY_BUY_LIMIT = 2; - const TOTAL_BUY_LIMIT = 3; - public function getGoodsList() { $shop_id = getReqVal('shop_id', 0); @@ -161,180 +124,6 @@ class ShopController extends BaseAuthedController ); } - public function startGoodsDirect() - { - $id = getReqVal('id', 0); - $token_type = getReqVal('token_type', ''); - $goods_num = getReqVal('goods_num', 1); - - if ($goods_num <= 0) { - $this->_rspErr(1, 'goods_num is invalid'); - return; - } - - $goods = mt\ShopGoods::get($id); - if (!$goods) { - $this->_rspErr(1, "id is invalid. {$id}"); - return; - } - - if ($goods['shop_id'] == 9 && $goods_num > 1) { - $this->_rspErr(1, 'goods_num is invalid'); - return; - } - - $conn = myself()->_getSelfMysql(); - - $address = myself()->_getAddress(); - if (!$address) { - $this->_rspErr(1, 'address is empty'); - return; - } - - $chk = SqlHelper::insert( - $conn, - 't_shop_buy_order', - array( - 'address' => $address, - 'createtime' => myself()->_getNowTime(), - 'id' => $id, - 'item_id' => $goods['goods_id'] ? $goods['goods_id'] : 0, - 'goods_num' => $goods_num, - 'status' => 0, // 0-客户端申请了订单 1-订单完成 2-订单失败 - ) - ); - if ($chk) { - $lastId = $this->lastInsertId($conn); - $order_id = $this->genOrderId($lastId); - SqlHelper::update( - $conn, - 't_shop_buy_order', - array( - 'idx' => $lastId, - ), - array( - 'order_id' => $order_id, - ) - ); - $this->_rspData( - array( - 'order_id' => $order_id, - ) - ); - } else { - $this->_rspErr(1, "insert error, id: {$id}, token_type: {$token_type}, goods_num: {$goods_num}"); - } - } - - public function statusGoodsDirect() - { - $order_id = getReqVal('order_id', ''); - - $conn = myself()->_getMysql(''); - - $row = SqlHelper::selectOne( - $conn, - 't_shop_buy_order', - array('status', 'id'), - array( - 'order_id' => $order_id, - ) - ); - if ($row) { - $this->_rspData( - array( - 'status' => $row['status'], - 'item_id' => $row['item_id'], - 'item_num' => $row['goods_num'], - ) - ); - } else { - $this->_rspErr(1, "order_id not found, order_id: {$order_id}"); - } - } - - public function startInappPurchase() - { - $self = myself(); - if (!$self) { - $this->_rspErr(1, "start purchase failed"); - return; - } - - $id = getReqVal('id', 0); - $goods = mt\ShopGoods::get($id); - if (!$goods) { - $this->_rspErr(2, "start purchase failed"); - return; - } - if ($goods['shop_id'] != 9) { - $this->_rspErr(3, "start purchase failed"); - return; - } - - $goods_num = getReqVal('goods_num', 1); - - $account_id = $self->_getAccountId(); - $address = $self->_getAddress(); - if (empty($address)) { - $this->_rspErr(4, "start purchase failed"); - return; - } - - $item_id = $goods['goods_id']; - $item_num = $goods['goods_num'] * $goods_num; - - $conn = $self->_getMysql(''); - - $chk = SqlHelper::insert($conn, 't_web2_order', array( - 'status' => 0, - 'createtime' => $self->_getNowTime(), - 'account_id' => $account_id, - 'address' => $address, - 'item_id' => $item_id, - 'item_num' => $item_num, - 'id' => $id, - 'goods_num' => $goods_num, - 'price' => $goods['price'], - )); - - if (!$chk) { - $this->_rspErr(5, "start purchase failed"); - return; - } - $lastId = $this->lastInsertId($conn); - $order_id = $this->genOrderId($lastId); - - $test = SqlHelper::update($conn, 't_web2_order', array('idx' => $lastId), array('order_id' => $order_id)); - if (!$test) { - $this->_rspErr(6, "start purchase failed"); - return; - } - $this->_rspData(array( - 'order_id' => $order_id, - )); - } - - 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; - } - - public function statusInappPurchase() - { - $order_id = getReqVal('order_id', ''); - $conn = myself()->_getMysql(''); - $order = SqlHelper::selectOne($conn, 't_web2_order', array('item_id', 'item_num', 'status'), array('order_id' => $order_id)); - if (!$order) { - $this->_rspErr(1, "order not found"); - return; - } - $this->_rspData($order); - } - public function buyGoods() { $address = $this->_getAddress(); @@ -624,51 +413,178 @@ class ShopController extends BaseAuthedController } } - public function buyDiamond() + public function startGoodsDirect() { - $num = getReqVal('num', 0); - if (!is_numeric($num)) { - $this->_rspErr(1, "num is invalid, {$num}"); - return; - } - if ($num <= 0) { - $this->_rspErr(1, "num is invalid, {$num}"); + $id = getReqVal('id', 0); + $token_type = getReqVal('token_type', ''); + $goods_num = getReqVal('goods_num', 1); + + if ($goods_num <= 0) { + $this->_rspErr(1, 'goods_num is invalid'); return; } - $price = $this->normalizeWeb3Price($num); - $item_id = V_ITEM_DIAMOND; - $item_count = $num; + $goods = mt\ShopGoods::get($id); + if (!$goods) { + $this->_rspErr(1, "id is invalid. {$id}"); + return; + } - error_log("buy diamond start " . $num); + if ($goods['shop_id'] == 9 && $goods_num > 1) { + $this->_rspErr(1, 'goods_num is invalid'); + return; + } - $response = services\BlockChainService::gameItemMallBuy( - Transaction::BUY_GOODS_ACTION_TYPE, - $price, - $item_id, - $item_count - ); + $conn = myself()->_getSelfMysql(); - BcOrder::upsert($response['trans_id'], array( - 'item_id' => $item_id, - 'item_num' => $item_count, - 'order_type' => 1, - 'price' => $num, - 'ext_data' => json_encode(array( - 'mode' => SHOP_BUY_MODE_NORMAL, - )), - )); + $address = myself()->_getAddress(); + if (!$address) { + $this->_rspErr(1, 'address is empty'); + return; + } - $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( + $chk = SqlHelper::insert( + $conn, + 't_shop_buy_order', array( - "block_chain" => $response + 'address' => $address, + 'createtime' => myself()->_getNowTime(), + 'id' => $id, + 'item_id' => $goods['goods_id'] ? $goods['goods_id'] : 0, + 'goods_num' => $goods_num, + 'status' => 0, // 0-客户端申请了订单 1-订单完成 2-订单失败 ) ); + if ($chk) { + $lastId = $this->lastInsertId($conn); + $order_id = $this->genOrderId($lastId); + SqlHelper::update( + $conn, + 't_shop_buy_order', + array( + 'idx' => $lastId, + ), + array( + 'order_id' => $order_id, + ) + ); + $this->_rspData( + array( + 'order_id' => $order_id, + ) + ); + } else { + $this->_rspErr(1, "insert error, id: {$id}, token_type: {$token_type}, goods_num: {$goods_num}"); + } + } + + public function statusGoodsDirect() + { + $order_id = getReqVal('order_id', ''); + + $conn = myself()->_getMysql(''); + + $row = SqlHelper::selectOne( + $conn, + 't_shop_buy_order', + array('status', 'id'), + array( + 'order_id' => $order_id, + ) + ); + if ($row) { + $this->_rspData( + array( + 'status' => $row['status'], + 'item_id' => $row['item_id'], + 'item_num' => $row['goods_num'], + ) + ); + } else { + $this->_rspErr(1, "order_id not found, order_id: {$order_id}"); + } + } + + public function startInappPurchase() + { + $self = myself(); + if (!$self) { + $this->_rspErr(1, "start purchase failed"); + return; + } + + $id = getReqVal('id', 0); + $goods = mt\ShopGoods::get($id); + if (!$goods) { + $this->_rspErr(2, "start purchase failed"); + return; + } + if ($goods['shop_id'] != 9) { + $this->_rspErr(3, "start purchase failed"); + return; + } + + $goods_num = getReqVal('goods_num', 1); + + $account_id = $self->_getAccountId(); + $address = $self->_getAddress(); + if (empty($address)) { + $this->_rspErr(4, "start purchase failed"); + return; + } + + $item_id = $goods['goods_id']; + $item_num = $goods['goods_num'] * $goods_num; + + $conn = $self->_getMysql(''); + + $chk = SqlHelper::insert($conn, 't_web2_order', array( + 'status' => 0, + 'createtime' => $self->_getNowTime(), + 'account_id' => $account_id, + 'address' => $address, + 'item_id' => $item_id, + 'item_num' => $item_num, + 'id' => $id, + 'goods_num' => $goods_num, + 'price' => $goods['price'], + )); + + if (!$chk) { + $this->_rspErr(5, "start purchase failed"); + return; + } + $lastId = $this->lastInsertId($conn); + $order_id = $this->genOrderId($lastId); + + $test = SqlHelper::update($conn, 't_web2_order', array('idx' => $lastId), array('order_id' => $order_id)); + if (!$test) { + $this->_rspErr(6, "start purchase failed"); + return; + } + $this->_rspData(array( + 'order_id' => $order_id, + )); + } + + 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; + } + + public function statusInappPurchase() + { + $order_id = getReqVal('order_id', ''); + $conn = myself()->_getMysql(''); + $order = SqlHelper::selectOne($conn, 't_web2_order', array('item_id', 'item_num', 'status'), array('order_id' => $order_id)); + if (!$order) { + $this->_rspErr(1, "order not found"); + return; + } + $this->_rspData($order); } public function boxPreview() diff --git a/webapp/mt/Shop.php b/webapp/mt/Shop.php index 93357b97..6b30eb28 100644 --- a/webapp/mt/Shop.php +++ b/webapp/mt/Shop.php @@ -6,6 +6,43 @@ use phpcommon; class Shop { + const TOKEN_TYPE_GOLD = '0'; + const TOKEN_TYPE_CEG = '1'; + const TOKEN_TYPE_CEC = '2'; + const TOKEN_TYPE_BCEG = '3'; + const TOKEN_TYPE_DIAMOND = '4'; + + + const TOKEN_TYPE_USDT = '11'; + const TOKEN_TYPE_USDC = '12'; + const TOKEN_TYPE_BUSD = '13'; + + const TOKEN_TYPE_MATIC = '101'; + const TOKEN_TYPE_BNB = '102'; + + //99 = 美元 + const TOKEN_TYPE_USD = '99'; + + //21 = 印尼 + const TOKEN_TYPE_IDR = '21'; + //22 = 菲律宾 + const TOKEN_TYPE_PHP = '22'; + //23 = 越南 + const TOKEN_TYPE_VND = '23'; + //24 = 泰国 + const TOKEN_TYPE_THB = '24'; + //25 = 马来西亚 + const TOKEN_TYPE_MYR = '25'; + //26 = 日本 + const TOKEN_TYPE_JPY = '26'; + //27 = 韩国 + const TOKEN_TYPE_KRW = '27'; + + // 限购类型 + const DAILY_BUY_LIMIT = 1; + const WEEKLY_BUY_LIMIT = 2; + const TOTAL_BUY_LIMIT = 3; + const OUTSIDE_SHOP = 100; public static function get($id) @@ -21,7 +58,7 @@ class Shop { array_push(self::$shopNameList, $meta); } } - + return self::$shopNameList; } @@ -32,7 +69,7 @@ class Shop { } return self::$metaList; } - + protected static $shopNameList; protected static $metaList; From 0b16cae60a83f15b0944f9b73106e530a7f6d339 Mon Sep 17 00:00:00 2001 From: azw Date: Fri, 28 Jul 2023 22:27:47 +0800 Subject: [PATCH 02/39] 1 --- webapp/controller/ShopController.class.php | 33 ++-------------------- 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index fa43e1e8..5eeca49f 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -413,7 +413,7 @@ class ShopController extends BaseAuthedController } } - public function startGoodsDirect() + public function outappPurchase() { $id = getReqVal('id', 0); $token_type = getReqVal('token_type', ''); @@ -478,34 +478,7 @@ class ShopController extends BaseAuthedController } } - public function statusGoodsDirect() - { - $order_id = getReqVal('order_id', ''); - - $conn = myself()->_getMysql(''); - - $row = SqlHelper::selectOne( - $conn, - 't_shop_buy_order', - array('status', 'id'), - array( - 'order_id' => $order_id, - ) - ); - if ($row) { - $this->_rspData( - array( - 'status' => $row['status'], - 'item_id' => $row['item_id'], - 'item_num' => $row['goods_num'], - ) - ); - } else { - $this->_rspErr(1, "order_id not found, order_id: {$order_id}"); - } - } - - public function startInappPurchase() + public function inappPurchase() { $self = myself(); if (!$self) { @@ -575,7 +548,7 @@ class ShopController extends BaseAuthedController return $order_id; } - public function statusInappPurchase() + public function queryInappPurchase() { $order_id = getReqVal('order_id', ''); $conn = myself()->_getMysql(''); From 4b6b23f7bb1ac05027500d9bcfe60015b3b889e6 Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 29 Jul 2023 07:43:02 +0800 Subject: [PATCH 03/39] 1 --- webapp/controller/ShopController.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 5eeca49f..bd3b5eda 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -51,11 +51,11 @@ class ShopController extends BaseAuthedController public function getGoodsList() { - $shop_id = getReqVal('shop_id', 0); - if ($shop_id == 0) { + $shopId = getReqVal('shop_id', 0); + if ($shopId == 0) { $goodsMetaList = mt\ShopGoods::all(); } else { - $goodsMetaList = mt\ShopGoods::getGoodsList($shop_id); + $goodsMetaList = mt\ShopGoods::getGoodsList($shopId); } $goodsMetaList = $goodsMetaList ? $goodsMetaList : array(); @@ -565,7 +565,7 @@ class ShopController extends BaseAuthedController $id = getReqVal('id', 0); $goods = mt\ShopGoods::get($id); $goods_id = $goods['goods_id']; - $shop_id = $goods['shop_id']; + $shopId = $goods['shop_id']; $meta = mt\Item::get($goods_id); if ($meta['type'] != mt\Item::CHEST_BOX_TYPE) { From d65f1f29ad53277388929998bba2485a0b066fa0 Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 29 Jul 2023 07:53:04 +0800 Subject: [PATCH 04/39] 1 --- webapp/controller/ShopController.class.php | 81 ++++++++++------------ 1 file changed, 38 insertions(+), 43 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index bd3b5eda..58e98191 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -126,17 +126,12 @@ class ShopController extends BaseAuthedController public function buyGoods() { - $address = $this->_getAddress(); - if (empty($address)) { - $this->_rspErr(4, 'address is empty'); - return; - } $id = getReqVal('id', 0); - $token_type = getReqVal('token_type', ''); - $goods_num = getReqVal('goods_num', 0); + $tokenType = getReqVal('token_type', ''); + $goodsNum = getReqVal('goods_num', 0); - if ($goods_num < 1) { - $this->_rspErr(1, "goods_num parameter error, goods_num: {$goods_num}"); + if ($goodsNum < 1) { + $this->_rspErr(1, "goods_num parameter error, goods_num: {$goodsNum}"); return; } @@ -147,9 +142,9 @@ class ShopController extends BaseAuthedController return; } - $goods_id = $row['goods_id']; + $goodsId = $row['goods_id']; if (!empty($address)) { - // $pending = $this->checkPendingBuyGoodsNormal($address, $goods_id, $row['shop_id'], $id); + // $pending = $this->checkPendingBuyGoodsNormal($address, $goodsId, $row['shop_id'], $id); // if ($pending) { // $this->_rspErr(1, 'pending'); // return; @@ -158,7 +153,7 @@ class ShopController extends BaseAuthedController $desired_token_type = $row['token_type']; $check_token_type = splitStr1($desired_token_type); - $token_pos = array_search($token_type, $check_token_type, true); + $token_pos = array_search($tokenType, $check_token_type, true); $isFreeBuy = false; if (!empty($row['free_type'])) { $count = $this->countFreeBuyTimes($row['free_type'], $row['id'], $row['goods_id']); @@ -167,13 +162,13 @@ class ShopController extends BaseAuthedController } } if (!$isFreeBuy) { - if (!in_array($token_type, $check_token_type)) { + if (!in_array($tokenType, $check_token_type)) { $this->_rspErr(1, "token_type parameter error, desired_token_type: {$desired_token_type}"); return; } } - if ($goods_num > $row['max_amount']) { + if ($goodsNum > $row['max_amount']) { $this->_rspErr(1, "goods_num parameter error, max_amount: {$row['max_amount']}"); return; } @@ -249,11 +244,11 @@ class ShopController extends BaseAuthedController $need_price = ceil($need_price * ($discount / 100.0)); } - $costItemId = $this->getCostItemIdByTokenType($token_type); + $costItemId = $this->getCostItemIdByTokenType($tokenType); - switch ($token_type) { + switch ($tokenType) { case ShopController::TOKEN_TYPE_GOLD: - $costItems = $this->makeCostItems($costItemId, $goods_num * $need_price); + $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); @@ -262,12 +257,12 @@ class ShopController extends BaseAuthedController $itemMeta = mt\Item::get($row['goods_id']); $propertyChgService = new services\PropertyChgService(); - for ($i = 0; $i < $goods_num; $i++) { + for ($i = 0; $i < $goodsNum; $i++) { $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0); } $awardService = new services\AwardService(); - $awardService->addItem($row['goods_id'], $goods_num); - ShopBuyRecord::add($id, $goods_num); + $awardService->addItem($row['goods_id'], $goodsNum); + ShopBuyRecord::add($id, $goodsNum); $this->_decItems($costItems); $goodsDto = array( 'goods_id' => $id, @@ -301,7 +296,7 @@ class ShopController extends BaseAuthedController if ($isFreeBuy) { $need_price = 0; } - $costItems = $this->makeCostItems($costItemId, $goods_num * $need_price); + $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); @@ -310,12 +305,12 @@ class ShopController extends BaseAuthedController $itemMeta = mt\Item::get($row['goods_id']); $propertyChgService = new services\PropertyChgService(); - for ($i = 0; $i < $goods_num; $i++) { + for ($i = 0; $i < $goodsNum; $i++) { $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0); } $awardService = new services\AwardService(); - $awardService->addItem($row['goods_id'], $goods_num); - ShopBuyRecord::add($id, $goods_num); + $awardService->addItem($row['goods_id'], $goodsNum); + ShopBuyRecord::add($id, $goodsNum); if ($isFreeBuy) { $this->addFreeBuyRecord($row); } @@ -363,9 +358,9 @@ class ShopController extends BaseAuthedController $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 1); $this->_rspOk(); } else { - $price = $this->normalizeWeb3Price($goods_num * $need_price); + $price = $this->normalizeWeb3Price($goodsNum * $need_price); $item_id = $row['goods_id']; - $item_count = $goods_num; + $item_count = $goodsNum; $response = services\BlockChainService::gameItemMallBuy( Transaction::BUY_GOODS_ACTION_TYPE, @@ -378,7 +373,7 @@ class ShopController extends BaseAuthedController 'item_id' => $item_id, 'item_num' => $item_count, 'order_type' => 1, - 'price' => $goods_num * $need_price, + 'price' => $goodsNum * $need_price, 'ext_data' => json_encode(array( 'mode' => SHOP_BUY_MODE_NORMAL, 'shop_id' => $row['shop_id'], @@ -408,7 +403,7 @@ class ShopController extends BaseAuthedController case ShopController::TOKEN_TYPE_MATIC: case ShopController::TOKEN_TYPE_BNB: default: { - $this->_rspErr(1, "token_type is unsupport, {$token_type}"); + $this->_rspErr(1, "token_type is unsupport, {$tokenType}"); } } } @@ -416,10 +411,10 @@ class ShopController extends BaseAuthedController public function outappPurchase() { $id = getReqVal('id', 0); - $token_type = getReqVal('token_type', ''); - $goods_num = getReqVal('goods_num', 1); + $tokenType = getReqVal('token_type', ''); + $goodsNum = getReqVal('goods_num', 1); - if ($goods_num <= 0) { + if ($goodsNum <= 0) { $this->_rspErr(1, 'goods_num is invalid'); return; } @@ -430,7 +425,7 @@ class ShopController extends BaseAuthedController return; } - if ($goods['shop_id'] == 9 && $goods_num > 1) { + if ($goods['shop_id'] == 9 && $goodsNum > 1) { $this->_rspErr(1, 'goods_num is invalid'); return; } @@ -451,7 +446,7 @@ class ShopController extends BaseAuthedController 'createtime' => myself()->_getNowTime(), 'id' => $id, 'item_id' => $goods['goods_id'] ? $goods['goods_id'] : 0, - 'goods_num' => $goods_num, + 'goods_num' => $goodsNum, 'status' => 0, // 0-客户端申请了订单 1-订单完成 2-订单失败 ) ); @@ -474,7 +469,7 @@ class ShopController extends BaseAuthedController ) ); } else { - $this->_rspErr(1, "insert error, id: {$id}, token_type: {$token_type}, goods_num: {$goods_num}"); + $this->_rspErr(1, "insert error, id: {$id}, token_type: {$tokenType}, goods_num: {$goodsNum}"); } } @@ -497,7 +492,7 @@ class ShopController extends BaseAuthedController return; } - $goods_num = getReqVal('goods_num', 1); + $goodsNum = getReqVal('goods_num', 1); $account_id = $self->_getAccountId(); $address = $self->_getAddress(); @@ -507,7 +502,7 @@ class ShopController extends BaseAuthedController } $item_id = $goods['goods_id']; - $item_num = $goods['goods_num'] * $goods_num; + $item_num = $goods['goods_num'] * $goodsNum; $conn = $self->_getMysql(''); @@ -519,7 +514,7 @@ class ShopController extends BaseAuthedController 'item_id' => $item_id, 'item_num' => $item_num, 'id' => $id, - 'goods_num' => $goods_num, + 'goods_num' => $goodsNum, 'price' => $goods['price'], )); @@ -564,10 +559,10 @@ class ShopController extends BaseAuthedController { $id = getReqVal('id', 0); $goods = mt\ShopGoods::get($id); - $goods_id = $goods['goods_id']; + $goodsId = $goods['goods_id']; $shopId = $goods['shop_id']; - $meta = mt\Item::get($goods_id); + $meta = mt\Item::get($goodsId); if ($meta['type'] != mt\Item::CHEST_BOX_TYPE) { $this->_rspErr(2, 'goods_id is invalid'); return; @@ -605,9 +600,9 @@ class ShopController extends BaseAuthedController ); } - private function getCostItemIdByTokenType($token_type) + private function getCostItemIdByTokenType($tokenType) { - switch ($token_type) { + switch ($tokenType) { case ShopController::TOKEN_TYPE_GOLD: return V_ITEM_GOLD; break; @@ -791,14 +786,14 @@ class ShopController extends BaseAuthedController return phpcommon\bnToStr($ret_price); } - private function countFreeBuyTimes($free_type, $id, $goods_id) + private function countFreeBuyTimes($free_type, $id, $goodsId) { return 0; switch ($free_type) { case 1: { $dayTime = myself()->_getNowDaySeconds(); $sql = 'SELECT COUNT(idx) as cnt FROM t_shop_free_record WHERE account_id = ? AND `id` = ? AND goods_id = ? AND createtime >= ?'; - $row = $conn->execQueryOne($sql, array($account, $id, $goods_id, $dayTime)); + $row = $conn->execQueryOne($sql, array($account, $id, $goodsId, $dayTime)); return $row['cnt']; } break; From 258053c297cfa48190b4a5cef212fa3d1564e7e9 Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 29 Jul 2023 08:36:56 +0800 Subject: [PATCH 05/39] 1 --- webapp/controller/ShopController.class.php | 214 +++++---------------- webapp/services/ShopService.php | 138 +++++++++++++ 2 files changed, 186 insertions(+), 166 deletions(-) create mode 100644 webapp/services/ShopService.php diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 58e98191..2316fae8 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -6,7 +6,6 @@ require_once('mt/Hero.php'); require_once('mt/Item.php'); require_once('mt/Parameter.php'); require_once('mt/Drop.php'); -require_once('mt/Dailyselection.php'); require_once('mt/ShopChest.php'); require_once('models/User.php'); @@ -23,6 +22,7 @@ require_once('models/Transaction.php'); require_once('services/AwardService.php'); require_once('services/PropertyChgService.php'); require_once('services/BlockChainService.php'); +require_once('services/ShopService.php'); require_once('phpcommon/bignumber.php'); @@ -38,85 +38,20 @@ use models\GunSkin; use models\ShopBuyRecord; use models\Chip; use mt\Shop; -use mt\Dailyselection; use mt\ShopChest; use mt\ShopGoods; use models\Transaction; use models\BcOrder; use services\LogService; use services\ShopAddItemService; +use services\ShopService; -class ShopController extends BaseAuthedController -{ +class ShopController extends BaseAuthedController { public function getGoodsList() { $shopId = getReqVal('shop_id', 0); - if ($shopId == 0) { - $goodsMetaList = mt\ShopGoods::all(); - } else { - $goodsMetaList = mt\ShopGoods::getGoodsList($shopId); - } - - $goodsMetaList = $goodsMetaList ? $goodsMetaList : array(); - $buyRecordHash = ShopBuyRecord::allToHash(); - - $goodsList = array(); - foreach ($goodsMetaList as $goodsMeta) { - $goodsDto = array( - 'goods_meta' => $this->goodsMetaToInfo($goodsMeta), - 'bought_times' => 0, - 'free_num' => 0, - ); - array_push($goodsList, $goodsDto); - switch ($goodsMeta['limit_type']) { - case mt\Item::DAILY_BUY_LIMIT: { - $buyRecord = getXVal($buyRecordHash, $goodsMeta['id']); - $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_day_buy_times'] : 0; - } - break; - case mt\Item::WEEKLY_BUY_LIMIT: { - $buyRecord = getXVal($buyRecordHash, $goodsMeta['id']); - $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0; - } - break; - case mt\Item::TOTAL_BUY_LIMIT: { - $buyRecord = getXVal($buyRecordHash, $goodsMeta['id']); - $goodsDto['bought_times'] = $buyRecord ? $buyRecord['total_buy_times'] : 0; - } - break; - default: { - } - break; - } - - $goodsId = $goodsMeta['goods_id']; - $itemMeta = mt\Item::get($goodsId); - if ($itemMeta) { - // 如果是皮肤,判断是否已经拥有,如果已经拥有,不能购买 - if ($itemMeta['type'] == mt\Item::HERO_SKIN_TYPE) { - $errCode = 0; - $errMsg = ''; - if (!$this->canBuy($itemMeta, $errCode, $errMsg)) { - $goods['bought_times'] = 1; - } else { - $goods['bought_times'] = 0; - } - } - } else { - // error !!!!!! - error_log('item not found:' . $goodsId); - } - - if (!empty($goods['free_type'])) { - $count = $this->countFreeBuyTimes($goodsMeta['free_type'], - $goodsMeta['id'], - $goodsMeta['goods_id']); - $goods['free_num'] = $goods['free_num'] - $count; - // error_log('free_num:' . $goods['free_num']); - } - } - + $goodsList = ShopService::getGoodsList($shopId); $this->_rspData( array( 'goods_list' => $goodsList, @@ -135,29 +70,22 @@ class ShopController extends BaseAuthedController return; } - $row = mt\ShopGoods::get($id); + $goodsMeta = mt\ShopGoods::get($id); - if (!$row) { + if (!$goodsMeta) { $this->_rspErr(1, 'goods not found'); return; } - $goodsId = $row['goods_id']; - if (!empty($address)) { - // $pending = $this->checkPendingBuyGoodsNormal($address, $goodsId, $row['shop_id'], $id); - // if ($pending) { - // $this->_rspErr(1, 'pending'); - // return; - // } - } + $goodsId = $goodsMeta['goods_id']; - $desired_token_type = $row['token_type']; + $desired_token_type = $goodsMeta['token_type']; $check_token_type = splitStr1($desired_token_type); $token_pos = array_search($tokenType, $check_token_type, true); $isFreeBuy = false; - if (!empty($row['free_type'])) { - $count = $this->countFreeBuyTimes($row['free_type'], $row['id'], $row['goods_id']); - if ($count < $row['free_num']) { + if (!empty($goodsMeta['free_type'])) { + $count = $this->countFreeBuyTimes($goodsMeta['free_type'], $goodsMeta['id'], $goodsMeta['goods_id']); + if ($count < $goodsMeta['free_num']) { $isFreeBuy = true; } } @@ -168,20 +96,20 @@ class ShopController extends BaseAuthedController } } - if ($goodsNum > $row['max_amount']) { - $this->_rspErr(1, "goods_num parameter error, max_amount: {$row['max_amount']}"); + if ($goodsNum > $goodsMeta['max_amount']) { + $this->_rspErr(1, "goods_num parameter error, max_amount: {$goodsMeta['max_amount']}"); return; } // 这里命名混乱了, 购买个数,一捆个数命名冲突 - $goods_count = $row['goods_num']; + $goods_count = $goodsMeta['goods_num']; $buyRecordHash = ShopBuyRecord::allToHash(); $boughtTimes = 1; - $itemMeta = mt\Item::get($row['goods_id']); + $itemMeta = mt\Item::get($goodsMeta['goods_id']); if (!$itemMeta) { - $this->_rspErr(1, 'goods not found, goods_id: ' . $row['goods_id']); + $this->_rspErr(1, 'goods not found, goods_id: ' . $goodsMeta['goods_id']); return; } @@ -194,11 +122,11 @@ class ShopController extends BaseAuthedController } } else { - switch ($row['limit_type']) { + switch ($goodsMeta['limit_type']) { case ShopController::DAILY_BUY_LIMIT: { $buyRecord = getXVal($buyRecordHash, $id); $boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1 : 1; - if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $row['limit_num']) { + if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $goodsMeta['limit_num']) { $this->_rspErr(2, 'Daily purchase limit'); return; } @@ -207,17 +135,17 @@ class ShopController extends BaseAuthedController case ShopController::WEEKLY_BUY_LIMIT: { $buyRecord = getXVal($buyRecordHash, $id); $boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1; - if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $row['limit_num']) { + if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $goodsMeta['limit_num']) { $this->_rspErr(2, 'Weekly purchase limit reached'); return; } } break; case ShopController::TOTAL_BUY_LIMIT: { - // error_log("total buy limit " . $address . " " . $id . " " . $row['limit_num']); + // error_log("total buy limit " . $address . " " . $id . " " . $goodsMeta['limit_num']); $buyRecord = getXVal($buyRecordHash, $id); $boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1; - if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $row['limit_num']) { + if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $goodsMeta['limit_num']) { $this->_rspErr(2, 'Purchase limit reached'); return; } @@ -229,14 +157,14 @@ class ShopController extends BaseAuthedController } } - $price_array = splitStr1($row['price']); - $discount_array = splitStr1($row['discount']); + $price_array = splitStr1($goodsMeta['price']); + $discount_array = splitStr1($goodsMeta['discount']); $need_price = $price_array[$token_pos]; $discount = $discount_array[$token_pos]; - $discount_begin = strtotime($row['discount_begin']); - $discount_end = strtotime($row['discount_end']); + $discount_begin = strtotime($goodsMeta['discount_begin']); + $discount_end = strtotime($goodsMeta['discount_end']); $nowTime = $this->_getNowTime(); if ($nowTime >= $discount_begin && $nowTime < $discount_end) { @@ -255,28 +183,28 @@ class ShopController extends BaseAuthedController return; } - $itemMeta = mt\Item::get($row['goods_id']); + $itemMeta = mt\Item::get($goodsMeta['goods_id']); $propertyChgService = new services\PropertyChgService(); for ($i = 0; $i < $goodsNum; $i++) { $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0); } $awardService = new services\AwardService(); - $awardService->addItem($row['goods_id'], $goodsNum); + $awardService->addItem($goodsMeta['goods_id'], $goodsNum); ShopBuyRecord::add($id, $goodsNum); $this->_decItems($costItems); $goodsDto = array( 'goods_id' => $id, - 'item_id' => $row['goods_id'], + 'item_id' => $goodsMeta['goods_id'], 'price_info' => array( - 'item_id' => $row['goods_id'], + 'item_id' => $goodsMeta['goods_id'], 'cost_list' => array(), - 'discount_begin_time' => phpcommon\datetimeToTimestamp($row['discount_begin']), - 'discount_end_time' => phpcommon\datetimeToTimestamp($row['discount_end']) + 'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']), + 'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end']) ), - 'flag_icon' => $row['tag'], - 'limit_type' => $row['limit_type'], + 'flag_icon' => $goodsMeta['tag'], + 'limit_type' => $goodsMeta['limit_type'], 'bought_times' => $boughtTimes, - 'total_buy_times' => $row['limit_num'], + 'total_buy_times' => $goodsMeta['limit_num'], ); { $priceInfo = mt\Item::getPriceInfo($itemMeta); if (!empty($priceInfo)) { @@ -303,16 +231,16 @@ class ShopController extends BaseAuthedController return; } - $itemMeta = mt\Item::get($row['goods_id']); + $itemMeta = mt\Item::get($goodsMeta['goods_id']); $propertyChgService = new services\PropertyChgService(); for ($i = 0; $i < $goodsNum; $i++) { $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0); } $awardService = new services\AwardService(); - $awardService->addItem($row['goods_id'], $goodsNum); + $awardService->addItem($goodsMeta['goods_id'], $goodsNum); ShopBuyRecord::add($id, $goodsNum); if ($isFreeBuy) { - $this->addFreeBuyRecord($row); + $this->addFreeBuyRecord($goodsMeta); } $this->_decItems($costItems); $event = [ @@ -323,17 +251,17 @@ class ShopController extends BaseAuthedController $goodsDto = array( 'goods_id' => $id, - 'item_id' => $row['goods_id'], + 'item_id' => $goodsMeta['goods_id'], 'price_info' => array( - 'item_id' => $row['goods_id'], + 'item_id' => $goodsMeta['goods_id'], 'cost_list' => array(), - 'discount_begin_time' => phpcommon\datetimeToTimestamp($row['discount_begin']), - 'discount_end_time' => phpcommon\datetimeToTimestamp($row['discount_end']) + 'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']), + 'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end']) ), - 'flag_icon' => $row['tag'], - 'limit_type' => $row['limit_type'], + 'flag_icon' => $goodsMeta['tag'], + 'limit_type' => $goodsMeta['limit_type'], 'bought_times' => $boughtTimes, - 'total_buy_times' => $row['limit_num'], + 'total_buy_times' => $goodsMeta['limit_num'], ); { $priceInfo = mt\Item::getPriceInfo($itemMeta); if (!empty($priceInfo)) { @@ -353,13 +281,13 @@ class ShopController extends BaseAuthedController case ShopController::TOKEN_TYPE_CEC: if ($isFreeBuy) { $propertyChgService = new services\PropertyChgService(); - $this->addFreeBuyRecord($row); - $itemMeta = mt\Item::get($row['goods_id']); + $this->addFreeBuyRecord($goodsMeta); + $itemMeta = mt\Item::get($goodsMeta['goods_id']); $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 1); $this->_rspOk(); } else { $price = $this->normalizeWeb3Price($goodsNum * $need_price); - $item_id = $row['goods_id']; + $item_id = $goodsMeta['goods_id']; $item_count = $goodsNum; $response = services\BlockChainService::gameItemMallBuy( @@ -376,7 +304,7 @@ class ShopController extends BaseAuthedController 'price' => $goodsNum * $need_price, 'ext_data' => json_encode(array( 'mode' => SHOP_BUY_MODE_NORMAL, - 'shop_id' => $row['shop_id'], + 'shop_id' => $goodsMeta['shop_id'], 'id' => $id, )), )); @@ -696,46 +624,6 @@ class ShopController extends BaseAuthedController } } - private function canBuy($itemMeta, &$errCode, &$errMsg) - { - $errCode = 0; - $errMsg = ''; - switch ($itemMeta['type']) { - case mt\Item::HERO_TYPE: { - $heroDb = Hero::find($itemMeta['id']); - if ($heroDb) { - $errCode = 10; - $errMsg = 'You already have the hero'; - return false; - } - } - break; - case mt\Item::HERO_SKIN_TYPE: { - $heroSkinDb = HeroSkin::find($itemMeta['id']); - if ($heroSkinDb) { - $errCode = 10; - $errMsg = 'You already have the skin'; - return false; - } - } - break; - case mt\Item::GUN_SKIN_TYPE: { - $gunSkinDb = GunSkin::find($itemMeta['id']); - if ($gunSkinDb) { - $errCode = 10; - $errMsg = 'You already have the skin'; - return false; - } - } - break; - default: { - return true; - } - break; - } - return true; - } - private function beginFirstTupop($address = null) { if (!$address) { @@ -829,10 +717,4 @@ class ShopController extends BaseAuthedController } } - private function goodsMetaToInfo($goodsMeta) { - return array( - - ); - } - } diff --git a/webapp/services/ShopService.php b/webapp/services/ShopService.php new file mode 100644 index 00000000..7aff8791 --- /dev/null +++ b/webapp/services/ShopService.php @@ -0,0 +1,138 @@ + self::goodsMetaToInfo($goodsMeta), + 'bought_times' => 0, + 'free_num' => 0, + ); + array_push($goodsList, $goodsDto); + switch ($goodsMeta['limit_type']) { + case mt\Item::DAILY_BUY_LIMIT: { + $buyRecord = getXVal($buyRecordHash, $goodsMeta['id']); + $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_day_buy_times'] : 0; + } + break; + case mt\Item::WEEKLY_BUY_LIMIT: { + $buyRecord = getXVal($buyRecordHash, $goodsMeta['id']); + $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0; + } + break; + case mt\Item::TOTAL_BUY_LIMIT: { + $buyRecord = getXVal($buyRecordHash, $goodsMeta['id']); + $goodsDto['bought_times'] = $buyRecord ? $buyRecord['total_buy_times'] : 0; + } + break; + default: { + } + break; + } + + $goodsId = $goodsMeta['goods_id']; + $itemMeta = mt\Item::get($goodsId); + if ($itemMeta) { + // 如果是皮肤,判断是否已经拥有,如果已经拥有,不能购买 + if ($itemMeta['type'] == mt\Item::HERO_SKIN_TYPE) { + $errCode = 0; + $errMsg = ''; + if (!self::canBuy($itemMeta, $errCode, $errMsg)) { + $goods['bought_times'] = 1; + } else { + $goods['bought_times'] = 0; + } + } + } else { + // error !!!!!! + error_log('item not found:' . $goodsId); + } + + if (!empty($goods['free_type'])) { + $count = self::getFreeBuyTimes($goodsMeta['free_type'], + $goodsMeta['id'], + $goodsMeta['goods_id']); + $goodsDto['free_num'] = $goodsDto['free_num'] - $count; + } + } + return $goodsList; + } + + public static function getFreeBuyTimes() { + + } + + private static function goodsMetaToInfo($goodsMeta) { + return array( + + ); + } + + private static function canBuy($itemMeta, &$errCode, &$errMsg) + { + $errCode = 0; + $errMsg = ''; + switch ($itemMeta['type']) { + case mt\Item::HERO_TYPE: { + $heroDb = Hero::find($itemMeta['id']); + if ($heroDb) { + $errCode = 10; + $errMsg = 'You already have the hero'; + return false; + } + } + break; + case mt\Item::HERO_SKIN_TYPE: { + $heroSkinDb = HeroSkin::find($itemMeta['id']); + if ($heroSkinDb) { + $errCode = 10; + $errMsg = 'You already have the skin'; + return false; + } + } + break; + case mt\Item::GUN_SKIN_TYPE: { + $gunSkinDb = GunSkin::find($itemMeta['id']); + if ($gunSkinDb) { + $errCode = 10; + $errMsg = 'You already have the skin'; + return false; + } + } + break; + default: { + return true; + } + break; + } + return true; + } + +} From 98c38f44e3bc2bd162724709f4f2e7ef5f9d1396 Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 29 Jul 2023 09:05:23 +0800 Subject: [PATCH 06/39] 1 --- webapp/controller/ShopController.class.php | 293 +++++++++++++++++++-- webapp/services/ShopService.php | 11 + 2 files changed, 288 insertions(+), 16 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 2316fae8..2bebcb29 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -336,6 +336,283 @@ class ShopController extends BaseAuthedController { } } + private function buyGoodsOld() + { + $id = getReqVal('id', 0); + $tokenType = getReqVal('token_type', ''); + $goodsNum = getReqVal('goods_num', 0); + + if ($goodsNum < 1) { + $this->_rspErr(1, "goods_num parameter error, goods_num: {$goodsNum}"); + return; + } + + $goodsMeta = mt\ShopGoods::get($id); + + if (!$goodsMeta) { + $this->_rspErr(1, 'goods not found'); + return; + } + + $goodsId = $goodsMeta['goods_id']; + + $desired_token_type = $goodsMeta['token_type']; + $check_token_type = splitStr1($desired_token_type); + $token_pos = array_search($tokenType, $check_token_type, true); + $isFreeBuy = false; + if (!empty($goodsMeta['free_type'])) { + $count = $this->countFreeBuyTimes($goodsMeta['free_type'], $goodsMeta['id'], $goodsMeta['goods_id']); + if ($count < $goodsMeta['free_num']) { + $isFreeBuy = true; + } + } + if (!$isFreeBuy) { + if (!in_array($tokenType, $check_token_type)) { + $this->_rspErr(1, "token_type parameter error, desired_token_type: {$desired_token_type}"); + return; + } + } + + if ($goodsNum > $goodsMeta['max_amount']) { + $this->_rspErr(1, "goods_num parameter error, max_amount: {$goodsMeta['max_amount']}"); + return; + } + + // 这里命名混乱了, 购买个数,一捆个数命名冲突 + $goods_count = $goodsMeta['goods_num']; + + $buyRecordHash = ShopBuyRecord::allToHash(); + $boughtTimes = 1; + + $itemMeta = mt\Item::get($goodsMeta['goods_id']); + if (!$itemMeta) { + $this->_rspErr(1, 'goods not found, goods_id: ' . $goodsMeta['goods_id']); + return; + } + + if ($itemMeta['type'] == mt\Item::HERO_SKIN_TYPE) { + $errCode = 0; + $errMsg = ''; + if (!$this->canBuy($itemMeta, $errCode, $errMsg)) { + $this->_rspErr($errCode, $errMsg); + return; + } + } else { + + switch ($goodsMeta['limit_type']) { + case ShopController::DAILY_BUY_LIMIT: { + $buyRecord = getXVal($buyRecordHash, $id); + $boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1 : 1; + if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $goodsMeta['limit_num']) { + $this->_rspErr(2, 'Daily purchase limit'); + return; + } + } + break; + case ShopController::WEEKLY_BUY_LIMIT: { + $buyRecord = getXVal($buyRecordHash, $id); + $boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1; + if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $goodsMeta['limit_num']) { + $this->_rspErr(2, 'Weekly purchase limit reached'); + return; + } + } + break; + case ShopController::TOTAL_BUY_LIMIT: { + // error_log("total buy limit " . $address . " " . $id . " " . $goodsMeta['limit_num']); + $buyRecord = getXVal($buyRecordHash, $id); + $boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1; + if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $goodsMeta['limit_num']) { + $this->_rspErr(2, 'Purchase limit reached'); + return; + } + } + break; + default: { + } + break; + } + } + + $price_array = splitStr1($goodsMeta['price']); + $discount_array = splitStr1($goodsMeta['discount']); + + $need_price = $price_array[$token_pos]; + $discount = $discount_array[$token_pos]; + + $discount_begin = strtotime($goodsMeta['discount_begin']); + $discount_end = strtotime($goodsMeta['discount_end']); + $nowTime = $this->_getNowTime(); + + if ($nowTime >= $discount_begin && $nowTime < $discount_end) { + + $need_price = ceil($need_price * ($discount / 100.0)); + } + + $costItemId = $this->getCostItemIdByTokenType($tokenType); + + switch ($tokenType) { + case ShopController::TOKEN_TYPE_GOLD: + $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); + return; + } + + $itemMeta = mt\Item::get($goodsMeta['goods_id']); + $propertyChgService = new services\PropertyChgService(); + for ($i = 0; $i < $goodsNum; $i++) { + $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0); + } + $awardService = new services\AwardService(); + $awardService->addItem($goodsMeta['goods_id'], $goodsNum); + ShopBuyRecord::add($id, $goodsNum); + $this->_decItems($costItems); + $goodsDto = array( + 'goods_id' => $id, + 'item_id' => $goodsMeta['goods_id'], + 'price_info' => array( + 'item_id' => $goodsMeta['goods_id'], + 'cost_list' => array(), + 'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']), + 'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end']) + ), + 'flag_icon' => $goodsMeta['tag'], + 'limit_type' => $goodsMeta['limit_type'], + 'bought_times' => $boughtTimes, + 'total_buy_times' => $goodsMeta['limit_num'], + ); { + $priceInfo = mt\Item::getPriceInfo($itemMeta); + if (!empty($priceInfo)) { + $goodsDto['price_info'] = $priceInfo['price_info']; + } + } + $propertyChgService->addUserChg(); + $this->_rspData( + array( + 'award' => $awardService->toDto(), + 'property_chg' => $propertyChgService->toDto(), + 'goods_chg' => $goodsDto + ) + ); + break; + case ShopController::TOKEN_TYPE_DIAMOND: + if ($isFreeBuy) { + $need_price = 0; + } + $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); + return; + } + + $itemMeta = mt\Item::get($goodsMeta['goods_id']); + $propertyChgService = new services\PropertyChgService(); + for ($i = 0; $i < $goodsNum; $i++) { + $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0); + } + $awardService = new services\AwardService(); + $awardService->addItem($goodsMeta['goods_id'], $goodsNum); + ShopBuyRecord::add($id, $goodsNum); + if ($isFreeBuy) { + $this->addFreeBuyRecord($goodsMeta); + } + $this->_decItems($costItems); + $event = [ + 'name' => LogService::SHOP_BUY_ITEM, + 'val' => $costItems[0]['item_num'] + ]; + LogService::consumeDiamond($event); + + $goodsDto = array( + 'goods_id' => $id, + 'item_id' => $goodsMeta['goods_id'], + 'price_info' => array( + 'item_id' => $goodsMeta['goods_id'], + 'cost_list' => array(), + 'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']), + 'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end']) + ), + 'flag_icon' => $goodsMeta['tag'], + 'limit_type' => $goodsMeta['limit_type'], + 'bought_times' => $boughtTimes, + 'total_buy_times' => $goodsMeta['limit_num'], + ); { + $priceInfo = mt\Item::getPriceInfo($itemMeta); + if (!empty($priceInfo)) { + $goodsDto['price_info'] = $priceInfo['price_info']; + } + } + $propertyChgService->addUserChg(); + $this->_rspData( + array( + 'award' => $awardService->toDto(), + 'property_chg' => $propertyChgService->toDto(), + 'goods_chg' => $goodsDto + ) + ); + break; + case ShopController::TOKEN_TYPE_CEG: + case ShopController::TOKEN_TYPE_CEC: + if ($isFreeBuy) { + $propertyChgService = new services\PropertyChgService(); + $this->addFreeBuyRecord($goodsMeta); + $itemMeta = mt\Item::get($goodsMeta['goods_id']); + $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 1); + $this->_rspOk(); + } else { + $price = $this->normalizeWeb3Price($goodsNum * $need_price); + $item_id = $goodsMeta['goods_id']; + $item_count = $goodsNum; + + $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, + 'price' => $goodsNum * $need_price, + 'ext_data' => json_encode(array( + 'mode' => SHOP_BUY_MODE_NORMAL, + 'shop_id' => $goodsMeta['shop_id'], + 'id' => $id, + )), + )); + + $response['item_id'] = $item_id; + $response['item_num'] = $item_count; + + error_log("buy normal, item_id = " . $item_id . " item_count = " . $item_count . " need_price = " . $need_price . " price = " . $price . " response = " . json_encode($response)); + + $this->_rspData( + array( + "block_chain" => $response + ) + ); + } + break; + + case ShopController::TOKEN_TYPE_BCEG: + break; + + case ShopController::TOKEN_TYPE_USDT: + case ShopController::TOKEN_TYPE_USDC: + case ShopController::TOKEN_TYPE_BUSD: + case ShopController::TOKEN_TYPE_MATIC: + case ShopController::TOKEN_TYPE_BNB: + default: { + $this->_rspErr(1, "token_type is unsupport, {$tokenType}"); + } + } + } + public function outappPurchase() { $id = getReqVal('id', 0); @@ -674,22 +951,6 @@ class ShopController extends BaseAuthedController { return phpcommon\bnToStr($ret_price); } - private function countFreeBuyTimes($free_type, $id, $goodsId) - { - return 0; - switch ($free_type) { - case 1: { - $dayTime = myself()->_getNowDaySeconds(); - $sql = 'SELECT COUNT(idx) as cnt FROM t_shop_free_record WHERE account_id = ? AND `id` = ? AND goods_id = ? AND createtime >= ?'; - $row = $conn->execQueryOne($sql, array($account, $id, $goodsId, $dayTime)); - return $row['cnt']; - } - break; - } - - return 0; - } - private function addFreeBuyRecord($goods) { $conn = myself()->_getMysql(''); diff --git a/webapp/services/ShopService.php b/webapp/services/ShopService.php index 7aff8791..baffc503 100644 --- a/webapp/services/ShopService.php +++ b/webapp/services/ShopService.php @@ -86,7 +86,18 @@ class ShopService { } public static function getFreeBuyTimes() { + return 0; + switch ($free_type) { + case 1: { + $dayTime = myself()->_getNowDaySeconds(); + $sql = 'SELECT COUNT(idx) as cnt FROM t_shop_free_record WHERE account_id = ? AND `id` = ? AND goods_id = ? AND createtime >= ?'; + $row = $conn->execQueryOne($sql, array($account, $id, $goodsId, $dayTime)); + return $row['cnt']; + } + break; + } + return 0; } private static function goodsMetaToInfo($goodsMeta) { From 59c18b35446f8e1779b895de08f376368e8f819e Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 29 Jul 2023 09:21:01 +0800 Subject: [PATCH 07/39] 1 --- webapp/controller/ShopController.class.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 2bebcb29..0bce764f 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -71,11 +71,19 @@ class ShopController extends BaseAuthedController { } $goodsMeta = mt\ShopGoods::get($id); - if (!$goodsMeta) { $this->_rspErr(1, 'goods not found'); return; } + if ($goodsNum > $goodsMeta['max_amount']) { + $this->_rspErr(1, "goods_num parameter error, max_amount: {$goodsMeta['max_amount']}"); + return; + } + $itemMeta = mt\Item::get($goodsMeta['goods_id']); + if (!$itemMeta) { + $this->_rspErr(1, 'goods not found, goods_id: ' . $goodsMeta['goods_id']); + return; + } $goodsId = $goodsMeta['goods_id']; @@ -96,23 +104,12 @@ class ShopController extends BaseAuthedController { } } - if ($goodsNum > $goodsMeta['max_amount']) { - $this->_rspErr(1, "goods_num parameter error, max_amount: {$goodsMeta['max_amount']}"); - return; - } - // 这里命名混乱了, 购买个数,一捆个数命名冲突 $goods_count = $goodsMeta['goods_num']; $buyRecordHash = ShopBuyRecord::allToHash(); $boughtTimes = 1; - $itemMeta = mt\Item::get($goodsMeta['goods_id']); - if (!$itemMeta) { - $this->_rspErr(1, 'goods not found, goods_id: ' . $goodsMeta['goods_id']); - return; - } - if ($itemMeta['type'] == mt\Item::HERO_SKIN_TYPE) { $errCode = 0; $errMsg = ''; From eb88b61bfa15859c768a598aade9156b8a4d652f Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 29 Jul 2023 09:28:45 +0800 Subject: [PATCH 08/39] 1 --- webapp/controller/ShopController.class.php | 279 +-------------------- 1 file changed, 1 insertion(+), 278 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 0bce764f..14058649 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -117,285 +117,8 @@ class ShopController extends BaseAuthedController { $this->_rspErr($errCode, $errMsg); return; } - } else { - - switch ($goodsMeta['limit_type']) { - case ShopController::DAILY_BUY_LIMIT: { - $buyRecord = getXVal($buyRecordHash, $id); - $boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1 : 1; - if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $goodsMeta['limit_num']) { - $this->_rspErr(2, 'Daily purchase limit'); - return; - } - } - break; - case ShopController::WEEKLY_BUY_LIMIT: { - $buyRecord = getXVal($buyRecordHash, $id); - $boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1; - if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $goodsMeta['limit_num']) { - $this->_rspErr(2, 'Weekly purchase limit reached'); - return; - } - } - break; - case ShopController::TOTAL_BUY_LIMIT: { - // error_log("total buy limit " . $address . " " . $id . " " . $goodsMeta['limit_num']); - $buyRecord = getXVal($buyRecordHash, $id); - $boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1; - if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $goodsMeta['limit_num']) { - $this->_rspErr(2, 'Purchase limit reached'); - return; - } - } - break; - default: { - } - break; - } } - - $price_array = splitStr1($goodsMeta['price']); - $discount_array = splitStr1($goodsMeta['discount']); - - $need_price = $price_array[$token_pos]; - $discount = $discount_array[$token_pos]; - - $discount_begin = strtotime($goodsMeta['discount_begin']); - $discount_end = strtotime($goodsMeta['discount_end']); - $nowTime = $this->_getNowTime(); - - if ($nowTime >= $discount_begin && $nowTime < $discount_end) { - - $need_price = ceil($need_price * ($discount / 100.0)); - } - - $costItemId = $this->getCostItemIdByTokenType($tokenType); - - switch ($tokenType) { - case ShopController::TOKEN_TYPE_GOLD: - $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); - return; - } - - $itemMeta = mt\Item::get($goodsMeta['goods_id']); - $propertyChgService = new services\PropertyChgService(); - for ($i = 0; $i < $goodsNum; $i++) { - $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0); - } - $awardService = new services\AwardService(); - $awardService->addItem($goodsMeta['goods_id'], $goodsNum); - ShopBuyRecord::add($id, $goodsNum); - $this->_decItems($costItems); - $goodsDto = array( - 'goods_id' => $id, - 'item_id' => $goodsMeta['goods_id'], - 'price_info' => array( - 'item_id' => $goodsMeta['goods_id'], - 'cost_list' => array(), - 'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']), - 'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end']) - ), - 'flag_icon' => $goodsMeta['tag'], - 'limit_type' => $goodsMeta['limit_type'], - 'bought_times' => $boughtTimes, - 'total_buy_times' => $goodsMeta['limit_num'], - ); { - $priceInfo = mt\Item::getPriceInfo($itemMeta); - if (!empty($priceInfo)) { - $goodsDto['price_info'] = $priceInfo['price_info']; - } - } - $propertyChgService->addUserChg(); - $this->_rspData( - array( - 'award' => $awardService->toDto(), - 'property_chg' => $propertyChgService->toDto(), - 'goods_chg' => $goodsDto - ) - ); - break; - case ShopController::TOKEN_TYPE_DIAMOND: - if ($isFreeBuy) { - $need_price = 0; - } - $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); - return; - } - - $itemMeta = mt\Item::get($goodsMeta['goods_id']); - $propertyChgService = new services\PropertyChgService(); - for ($i = 0; $i < $goodsNum; $i++) { - $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0); - } - $awardService = new services\AwardService(); - $awardService->addItem($goodsMeta['goods_id'], $goodsNum); - ShopBuyRecord::add($id, $goodsNum); - if ($isFreeBuy) { - $this->addFreeBuyRecord($goodsMeta); - } - $this->_decItems($costItems); - $event = [ - 'name' => LogService::SHOP_BUY_ITEM, - 'val' => $costItems[0]['item_num'] - ]; - LogService::consumeDiamond($event); - - $goodsDto = array( - 'goods_id' => $id, - 'item_id' => $goodsMeta['goods_id'], - 'price_info' => array( - 'item_id' => $goodsMeta['goods_id'], - 'cost_list' => array(), - 'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']), - 'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end']) - ), - 'flag_icon' => $goodsMeta['tag'], - 'limit_type' => $goodsMeta['limit_type'], - 'bought_times' => $boughtTimes, - 'total_buy_times' => $goodsMeta['limit_num'], - ); { - $priceInfo = mt\Item::getPriceInfo($itemMeta); - if (!empty($priceInfo)) { - $goodsDto['price_info'] = $priceInfo['price_info']; - } - } - $propertyChgService->addUserChg(); - $this->_rspData( - array( - 'award' => $awardService->toDto(), - 'property_chg' => $propertyChgService->toDto(), - 'goods_chg' => $goodsDto - ) - ); - break; - case ShopController::TOKEN_TYPE_CEG: - case ShopController::TOKEN_TYPE_CEC: - if ($isFreeBuy) { - $propertyChgService = new services\PropertyChgService(); - $this->addFreeBuyRecord($goodsMeta); - $itemMeta = mt\Item::get($goodsMeta['goods_id']); - $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 1); - $this->_rspOk(); - } else { - $price = $this->normalizeWeb3Price($goodsNum * $need_price); - $item_id = $goodsMeta['goods_id']; - $item_count = $goodsNum; - - $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, - 'price' => $goodsNum * $need_price, - 'ext_data' => json_encode(array( - 'mode' => SHOP_BUY_MODE_NORMAL, - 'shop_id' => $goodsMeta['shop_id'], - 'id' => $id, - )), - )); - - $response['item_id'] = $item_id; - $response['item_num'] = $item_count; - - error_log("buy normal, item_id = " . $item_id . " item_count = " . $item_count . " need_price = " . $need_price . " price = " . $price . " response = " . json_encode($response)); - - $this->_rspData( - array( - "block_chain" => $response - ) - ); - } - break; - - case ShopController::TOKEN_TYPE_BCEG: - break; - - case ShopController::TOKEN_TYPE_USDT: - case ShopController::TOKEN_TYPE_USDC: - case ShopController::TOKEN_TYPE_BUSD: - case ShopController::TOKEN_TYPE_MATIC: - case ShopController::TOKEN_TYPE_BNB: - default: { - $this->_rspErr(1, "token_type is unsupport, {$tokenType}"); - } - } - } - - private function buyGoodsOld() - { - $id = getReqVal('id', 0); - $tokenType = getReqVal('token_type', ''); - $goodsNum = getReqVal('goods_num', 0); - - if ($goodsNum < 1) { - $this->_rspErr(1, "goods_num parameter error, goods_num: {$goodsNum}"); - return; - } - - $goodsMeta = mt\ShopGoods::get($id); - - if (!$goodsMeta) { - $this->_rspErr(1, 'goods not found'); - return; - } - - $goodsId = $goodsMeta['goods_id']; - - $desired_token_type = $goodsMeta['token_type']; - $check_token_type = splitStr1($desired_token_type); - $token_pos = array_search($tokenType, $check_token_type, true); - $isFreeBuy = false; - if (!empty($goodsMeta['free_type'])) { - $count = $this->countFreeBuyTimes($goodsMeta['free_type'], $goodsMeta['id'], $goodsMeta['goods_id']); - if ($count < $goodsMeta['free_num']) { - $isFreeBuy = true; - } - } - if (!$isFreeBuy) { - if (!in_array($tokenType, $check_token_type)) { - $this->_rspErr(1, "token_type parameter error, desired_token_type: {$desired_token_type}"); - return; - } - } - - if ($goodsNum > $goodsMeta['max_amount']) { - $this->_rspErr(1, "goods_num parameter error, max_amount: {$goodsMeta['max_amount']}"); - return; - } - - // 这里命名混乱了, 购买个数,一捆个数命名冲突 - $goods_count = $goodsMeta['goods_num']; - - $buyRecordHash = ShopBuyRecord::allToHash(); - $boughtTimes = 1; - - $itemMeta = mt\Item::get($goodsMeta['goods_id']); - if (!$itemMeta) { - $this->_rspErr(1, 'goods not found, goods_id: ' . $goodsMeta['goods_id']); - return; - } - - if ($itemMeta['type'] == mt\Item::HERO_SKIN_TYPE) { - $errCode = 0; - $errMsg = ''; - if (!$this->canBuy($itemMeta, $errCode, $errMsg)) { - $this->_rspErr($errCode, $errMsg); - return; - } - } else { - + { switch ($goodsMeta['limit_type']) { case ShopController::DAILY_BUY_LIMIT: { $buyRecord = getXVal($buyRecordHash, $id); From 5e7088b4d7fa1912501e1991350c247c451bd635 Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 29 Jul 2023 09:29:51 +0800 Subject: [PATCH 09/39] 1 --- webapp/controller/ShopController.class.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 14058649..42cd60bf 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -84,6 +84,14 @@ class ShopController extends BaseAuthedController { $this->_rspErr(1, 'goods not found, goods_id: ' . $goodsMeta['goods_id']); return; } + if ($itemMeta['type'] == mt\Item::HERO_SKIN_TYPE) { + $errCode = 0; + $errMsg = ''; + if (!$this->canBuy($itemMeta, $errCode, $errMsg)) { + $this->_rspErr($errCode, $errMsg); + return; + } + } $goodsId = $goodsMeta['goods_id']; @@ -109,15 +117,6 @@ class ShopController extends BaseAuthedController { $buyRecordHash = ShopBuyRecord::allToHash(); $boughtTimes = 1; - - if ($itemMeta['type'] == mt\Item::HERO_SKIN_TYPE) { - $errCode = 0; - $errMsg = ''; - if (!$this->canBuy($itemMeta, $errCode, $errMsg)) { - $this->_rspErr($errCode, $errMsg); - return; - } - } { switch ($goodsMeta['limit_type']) { case ShopController::DAILY_BUY_LIMIT: { From d2069c3e7654a62ee06371bb7f8fd9e085b5c771 Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 29 Jul 2023 18:47:06 +0800 Subject: [PATCH 10/39] 1 --- webapp/controller/ShopController.class.php | 38 ---------------- webapp/models/ShopBuyRecord.php | 1 + webapp/services/ShopService.php | 50 ++++++++++++++++++++-- 3 files changed, 48 insertions(+), 41 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 42cd60bf..ddc74396 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -115,44 +115,6 @@ class ShopController extends BaseAuthedController { // 这里命名混乱了, 购买个数,一捆个数命名冲突 $goods_count = $goodsMeta['goods_num']; - $buyRecordHash = ShopBuyRecord::allToHash(); - $boughtTimes = 1; - { - switch ($goodsMeta['limit_type']) { - case ShopController::DAILY_BUY_LIMIT: { - $buyRecord = getXVal($buyRecordHash, $id); - $boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1 : 1; - if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $goodsMeta['limit_num']) { - $this->_rspErr(2, 'Daily purchase limit'); - return; - } - } - break; - case ShopController::WEEKLY_BUY_LIMIT: { - $buyRecord = getXVal($buyRecordHash, $id); - $boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1; - if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $goodsMeta['limit_num']) { - $this->_rspErr(2, 'Weekly purchase limit reached'); - return; - } - } - break; - case ShopController::TOTAL_BUY_LIMIT: { - // error_log("total buy limit " . $address . " " . $id . " " . $goodsMeta['limit_num']); - $buyRecord = getXVal($buyRecordHash, $id); - $boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1; - if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $goodsMeta['limit_num']) { - $this->_rspErr(2, 'Purchase limit reached'); - return; - } - } - break; - default: { - } - break; - } - } - $price_array = splitStr1($goodsMeta['price']); $discount_array = splitStr1($goodsMeta['discount']); diff --git a/webapp/models/ShopBuyRecord.php b/webapp/models/ShopBuyRecord.php index ce8e9598..9a64a820 100644 --- a/webapp/models/ShopBuyRecord.php +++ b/webapp/models/ShopBuyRecord.php @@ -149,4 +149,5 @@ class ShopBuyRecord extends BaseModel return $row['account_id']; } + } diff --git a/webapp/services/ShopService.php b/webapp/services/ShopService.php index baffc503..dafb4c37 100644 --- a/webapp/services/ShopService.php +++ b/webapp/services/ShopService.php @@ -18,7 +18,8 @@ use models\GunSkin; class ShopService { - public static function getGoodsList($shopId) { + public static function getGoodsList($shopId) + { if ($shopId == 0) { $goodsMetaList = mt\ShopGoods::all(); } else { @@ -85,7 +86,8 @@ class ShopService { return $goodsList; } - public static function getFreeBuyTimes() { + public static function getFreeBuyTimes() + { return 0; switch ($free_type) { case 1: { @@ -100,7 +102,49 @@ class ShopService { return 0; } - private static function goodsMetaToInfo($goodsMeta) { + public static function buyLimitCheck($goodsMeta) + { + $buyRecordHash = ShopBuyRecord::allToHash(); + $boughtTimes = 1; + { + switch ($goodsMeta['limit_type']) { + case ShopController::DAILY_BUY_LIMIT: { + $buyRecord = getXVal($buyRecordHash, $id); + $boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1 : 1; + if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $goodsMeta['limit_num']) { + $this->_rspErr(2, 'Daily purchase limit'); + return; + } + } + break; + case ShopController::WEEKLY_BUY_LIMIT: { + $buyRecord = getXVal($buyRecordHash, $id); + $boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1; + if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $goodsMeta['limit_num']) { + $this->_rspErr(2, 'Weekly purchase limit reached'); + return; + } + } + break; + case ShopController::TOTAL_BUY_LIMIT: { + // error_log("total buy limit " . $address . " " . $id . " " . $goodsMeta['limit_num']); + $buyRecord = getXVal($buyRecordHash, $id); + $boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1; + if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $goodsMeta['limit_num']) { + $this->_rspErr(2, 'Purchase limit reached'); + return; + } + } + break; + default: { + } + break; + } + } + } + + private static function goodsMetaToInfo($goodsMeta) + { return array( ); From e6a6b90fa5eeeeb09d516e3d5a2616e3c148a4c0 Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 29 Jul 2023 19:12:40 +0800 Subject: [PATCH 11/39] 1 --- webapp/controller/ShopController.class.php | 8 ++++++-- webapp/services/ShopService.php | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index ddc74396..a915164b 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -84,14 +84,18 @@ class ShopController extends BaseAuthedController { $this->_rspErr(1, 'goods not found, goods_id: ' . $goodsMeta['goods_id']); return; } + $errCode = 0; + $errMsg = ''; if ($itemMeta['type'] == mt\Item::HERO_SKIN_TYPE) { - $errCode = 0; - $errMsg = ''; if (!$this->canBuy($itemMeta, $errCode, $errMsg)) { $this->_rspErr($errCode, $errMsg); return; } } + if (!ShopService::buyLimitCheck($goodsMeta, $errCode, $errMsg)) { + $this->_rspErr($errCode, $errMsg); + return; + } $goodsId = $goodsMeta['goods_id']; diff --git a/webapp/services/ShopService.php b/webapp/services/ShopService.php index dafb4c37..5a7624e2 100644 --- a/webapp/services/ShopService.php +++ b/webapp/services/ShopService.php @@ -102,8 +102,10 @@ class ShopService { return 0; } - public static function buyLimitCheck($goodsMeta) + public static function buyLimitCheck($goodsMeta, &$errCode, &$errMsg) { + $errCode = 0; + $errMsg = ''; $buyRecordHash = ShopBuyRecord::allToHash(); $boughtTimes = 1; { From 12ea460246dc87ab311cbf99be81043fa0c45b14 Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 29 Jul 2023 19:56:52 +0800 Subject: [PATCH 12/39] 1 --- webapp/controller/ShopController.class.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index a915164b..ea922fd6 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -97,8 +97,6 @@ class ShopController extends BaseAuthedController { return; } - $goodsId = $goodsMeta['goods_id']; - $desired_token_type = $goodsMeta['token_type']; $check_token_type = splitStr1($desired_token_type); $token_pos = array_search($tokenType, $check_token_type, true); From 0d945f7a49a6c2443d8e80cec6764e130f8ae70b Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 29 Jul 2023 21:46:35 +0800 Subject: [PATCH 13/39] 1 --- webapp/controller/ShopController.class.php | 245 ++++++++------------- 1 file changed, 96 insertions(+), 149 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index ea922fd6..aa633f79 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -135,163 +135,110 @@ class ShopController extends BaseAuthedController { $costItemId = $this->getCostItemIdByTokenType($tokenType); switch ($tokenType) { - case ShopController::TOKEN_TYPE_GOLD: - $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); - return; - } + case ShopController::TOKEN_TYPE_GOLD: + $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); + return; + } - $itemMeta = mt\Item::get($goodsMeta['goods_id']); - $propertyChgService = new services\PropertyChgService(); - for ($i = 0; $i < $goodsNum; $i++) { - $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0); - } - $awardService = new services\AwardService(); - $awardService->addItem($goodsMeta['goods_id'], $goodsNum); - ShopBuyRecord::add($id, $goodsNum); - $this->_decItems($costItems); - $goodsDto = array( - 'goods_id' => $id, + $itemMeta = mt\Item::get($goodsMeta['goods_id']); + $propertyChgService = new services\PropertyChgService(); + for ($i = 0; $i < $goodsNum; $i++) { + $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0); + } + $awardService = new services\AwardService(); + $awardService->addItem($goodsMeta['goods_id'], $goodsNum); + ShopBuyRecord::add($id, $goodsNum); + $this->_decItems($costItems); + $goodsDto = array( + 'goods_id' => $id, + 'item_id' => $goodsMeta['goods_id'], + 'price_info' => array( 'item_id' => $goodsMeta['goods_id'], - 'price_info' => array( - 'item_id' => $goodsMeta['goods_id'], - 'cost_list' => array(), - 'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']), - 'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end']) - ), - 'flag_icon' => $goodsMeta['tag'], - 'limit_type' => $goodsMeta['limit_type'], - 'bought_times' => $boughtTimes, - 'total_buy_times' => $goodsMeta['limit_num'], - ); { - $priceInfo = mt\Item::getPriceInfo($itemMeta); - if (!empty($priceInfo)) { - $goodsDto['price_info'] = $priceInfo['price_info']; - } - } - $propertyChgService->addUserChg(); - $this->_rspData( - array( - 'award' => $awardService->toDto(), - 'property_chg' => $propertyChgService->toDto(), - 'goods_chg' => $goodsDto - ) - ); - break; - case ShopController::TOKEN_TYPE_DIAMOND: - if ($isFreeBuy) { - $need_price = 0; - } - $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); - return; + 'cost_list' => array(), + 'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']), + 'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end']) + ), + 'flag_icon' => $goodsMeta['tag'], + 'limit_type' => $goodsMeta['limit_type'], + 'bought_times' => $boughtTimes, + 'total_buy_times' => $goodsMeta['limit_num'], + ); { + $priceInfo = mt\Item::getPriceInfo($itemMeta); + if (!empty($priceInfo)) { + $goodsDto['price_info'] = $priceInfo['price_info']; } + } + $propertyChgService->addUserChg(); + $this->_rspData( + array( + 'award' => $awardService->toDto(), + 'property_chg' => $propertyChgService->toDto(), + 'goods_chg' => $goodsDto + ) + ); + break; + case ShopController::TOKEN_TYPE_DIAMOND: + if ($isFreeBuy) { + $need_price = 0; + } + $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); + return; + } - $itemMeta = mt\Item::get($goodsMeta['goods_id']); - $propertyChgService = new services\PropertyChgService(); - for ($i = 0; $i < $goodsNum; $i++) { - $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0); - } - $awardService = new services\AwardService(); - $awardService->addItem($goodsMeta['goods_id'], $goodsNum); - ShopBuyRecord::add($id, $goodsNum); - if ($isFreeBuy) { - $this->addFreeBuyRecord($goodsMeta); - } - $this->_decItems($costItems); - $event = [ - 'name' => LogService::SHOP_BUY_ITEM, - 'val' => $costItems[0]['item_num'] - ]; - LogService::consumeDiamond($event); + $itemMeta = mt\Item::get($goodsMeta['goods_id']); + $propertyChgService = new services\PropertyChgService(); + for ($i = 0; $i < $goodsNum; $i++) { + $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0); + } + $awardService = new services\AwardService(); + $awardService->addItem($goodsMeta['goods_id'], $goodsNum); + ShopBuyRecord::add($id, $goodsNum); + if ($isFreeBuy) { + $this->addFreeBuyRecord($goodsMeta); + } + $this->_decItems($costItems); + $event = [ + 'name' => LogService::SHOP_BUY_ITEM, + 'val' => $costItems[0]['item_num'] + ]; + LogService::consumeDiamond($event); - $goodsDto = array( - 'goods_id' => $id, + $goodsDto = array( + 'goods_id' => $id, + 'item_id' => $goodsMeta['goods_id'], + 'price_info' => array( 'item_id' => $goodsMeta['goods_id'], - 'price_info' => array( - 'item_id' => $goodsMeta['goods_id'], - 'cost_list' => array(), - 'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']), - 'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end']) - ), - 'flag_icon' => $goodsMeta['tag'], - 'limit_type' => $goodsMeta['limit_type'], - 'bought_times' => $boughtTimes, - 'total_buy_times' => $goodsMeta['limit_num'], - ); { - $priceInfo = mt\Item::getPriceInfo($itemMeta); - if (!empty($priceInfo)) { - $goodsDto['price_info'] = $priceInfo['price_info']; - } + 'cost_list' => array(), + 'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']), + 'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end']) + ), + 'flag_icon' => $goodsMeta['tag'], + 'limit_type' => $goodsMeta['limit_type'], + 'bought_times' => $boughtTimes, + 'total_buy_times' => $goodsMeta['limit_num'], + ); { + $priceInfo = mt\Item::getPriceInfo($itemMeta); + if (!empty($priceInfo)) { + $goodsDto['price_info'] = $priceInfo['price_info']; } - $propertyChgService->addUserChg(); - $this->_rspData( - array( - 'award' => $awardService->toDto(), - 'property_chg' => $propertyChgService->toDto(), - 'goods_chg' => $goodsDto - ) - ); - break; - case ShopController::TOKEN_TYPE_CEG: - case ShopController::TOKEN_TYPE_CEC: - if ($isFreeBuy) { - $propertyChgService = new services\PropertyChgService(); - $this->addFreeBuyRecord($goodsMeta); - $itemMeta = mt\Item::get($goodsMeta['goods_id']); - $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 1); - $this->_rspOk(); - } else { - $price = $this->normalizeWeb3Price($goodsNum * $need_price); - $item_id = $goodsMeta['goods_id']; - $item_count = $goodsNum; - - $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, - 'price' => $goodsNum * $need_price, - 'ext_data' => json_encode(array( - 'mode' => SHOP_BUY_MODE_NORMAL, - 'shop_id' => $goodsMeta['shop_id'], - 'id' => $id, - )), - )); - - $response['item_id'] = $item_id; - $response['item_num'] = $item_count; - - error_log("buy normal, item_id = " . $item_id . " item_count = " . $item_count . " need_price = " . $need_price . " price = " . $price . " response = " . json_encode($response)); - - $this->_rspData( - array( - "block_chain" => $response - ) - ); - } - break; - - case ShopController::TOKEN_TYPE_BCEG: - break; - - case ShopController::TOKEN_TYPE_USDT: - case ShopController::TOKEN_TYPE_USDC: - case ShopController::TOKEN_TYPE_BUSD: - case ShopController::TOKEN_TYPE_MATIC: - case ShopController::TOKEN_TYPE_BNB: + } + $propertyChgService->addUserChg(); + $this->_rspData( + array( + 'award' => $awardService->toDto(), + 'property_chg' => $propertyChgService->toDto(), + 'goods_chg' => $goodsDto + ) + ); + break; default: { - $this->_rspErr(1, "token_type is unsupport, {$tokenType}"); + $this->_rspErr(1, "token_type is unsupport, {$tokenType}"); } } } From 13852c771935e376f0338568fb90c6513db7e4ce Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 29 Jul 2023 22:25:39 +0800 Subject: [PATCH 14/39] 1 --- webapp/controller/ShopController.class.php | 118 +++------------------ webapp/services/ShopService.php | 2 +- 2 files changed, 16 insertions(+), 104 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index aa633f79..8f5025fc 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -128,118 +128,30 @@ class ShopController extends BaseAuthedController { $nowTime = $this->_getNowTime(); if ($nowTime >= $discount_begin && $nowTime < $discount_end) { - $need_price = ceil($need_price * ($discount / 100.0)); } $costItemId = $this->getCostItemIdByTokenType($tokenType); - + $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); switch ($tokenType) { case ShopController::TOKEN_TYPE_GOLD: - $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); - return; - } - - $itemMeta = mt\Item::get($goodsMeta['goods_id']); - $propertyChgService = new services\PropertyChgService(); - for ($i = 0; $i < $goodsNum; $i++) { - $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0); - } - $awardService = new services\AwardService(); - $awardService->addItem($goodsMeta['goods_id'], $goodsNum); - ShopBuyRecord::add($id, $goodsNum); - $this->_decItems($costItems); - $goodsDto = array( - 'goods_id' => $id, - 'item_id' => $goodsMeta['goods_id'], - 'price_info' => array( - 'item_id' => $goodsMeta['goods_id'], - 'cost_list' => array(), - 'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']), - 'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end']) - ), - 'flag_icon' => $goodsMeta['tag'], - 'limit_type' => $goodsMeta['limit_type'], - 'bought_times' => $boughtTimes, - 'total_buy_times' => $goodsMeta['limit_num'], - ); { - $priceInfo = mt\Item::getPriceInfo($itemMeta); - if (!empty($priceInfo)) { - $goodsDto['price_info'] = $priceInfo['price_info']; - } - } - $propertyChgService->addUserChg(); - $this->_rspData( - array( - 'award' => $awardService->toDto(), - 'property_chg' => $propertyChgService->toDto(), - 'goods_chg' => $goodsDto - ) - ); - break; + { + } + break; case ShopController::TOKEN_TYPE_DIAMOND: - if ($isFreeBuy) { - $need_price = 0; - } - $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); - return; - } - - $itemMeta = mt\Item::get($goodsMeta['goods_id']); - $propertyChgService = new services\PropertyChgService(); - for ($i = 0; $i < $goodsNum; $i++) { - $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0); - } - $awardService = new services\AwardService(); - $awardService->addItem($goodsMeta['goods_id'], $goodsNum); - ShopBuyRecord::add($id, $goodsNum); - if ($isFreeBuy) { - $this->addFreeBuyRecord($goodsMeta); - } - $this->_decItems($costItems); - $event = [ - 'name' => LogService::SHOP_BUY_ITEM, - 'val' => $costItems[0]['item_num'] - ]; - LogService::consumeDiamond($event); - - $goodsDto = array( - 'goods_id' => $id, - 'item_id' => $goodsMeta['goods_id'], - 'price_info' => array( - 'item_id' => $goodsMeta['goods_id'], - 'cost_list' => array(), - 'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']), - 'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end']) - ), - 'flag_icon' => $goodsMeta['tag'], - 'limit_type' => $goodsMeta['limit_type'], - 'bought_times' => $boughtTimes, - 'total_buy_times' => $goodsMeta['limit_num'], - ); { - $priceInfo = mt\Item::getPriceInfo($itemMeta); - if (!empty($priceInfo)) { - $goodsDto['price_info'] = $priceInfo['price_info']; - } - } - $propertyChgService->addUserChg(); - $this->_rspData( - array( - 'award' => $awardService->toDto(), - 'property_chg' => $propertyChgService->toDto(), - 'goods_chg' => $goodsDto - ) - ); - break; - default: { + { + } + break; + default: + { $this->_rspErr(1, "token_type is unsupport, {$tokenType}"); } + break; + } + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); + return; } } diff --git a/webapp/services/ShopService.php b/webapp/services/ShopService.php index 5a7624e2..4655667f 100644 --- a/webapp/services/ShopService.php +++ b/webapp/services/ShopService.php @@ -145,7 +145,7 @@ class ShopService { } } - private static function goodsMetaToInfo($goodsMeta) + public static function goodsMetaToInfo($goodsMeta) { return array( From 2307d68d6b20c3881945bf558090a1e741f405f1 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 08:41:07 +0800 Subject: [PATCH 15/39] 1 --- webapp/controller/ShopController.class.php | 24 ++++++++-------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 8f5025fc..d69b551f 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -114,9 +114,6 @@ class ShopController extends BaseAuthedController { } } - // 这里命名混乱了, 购买个数,一捆个数命名冲突 - $goods_count = $goodsMeta['goods_num']; - $price_array = splitStr1($goodsMeta['price']); $discount_array = splitStr1($goodsMeta['discount']); @@ -133,20 +130,15 @@ class ShopController extends BaseAuthedController { $costItemId = $this->getCostItemIdByTokenType($tokenType); $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); - switch ($tokenType) { - case ShopController::TOKEN_TYPE_GOLD: - { - } - break; - case ShopController::TOKEN_TYPE_DIAMOND: - { - } - break; - default: - { + if (!in_array( + $tokenType, + array( + mt\Shop::TOKEN_TYPE_GOLD, + mt\Shop::TOKEN_TYPE_DIAMOND + ) + )) { $this->_rspErr(1, "token_type is unsupport, {$tokenType}"); - } - break; + return; } $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { From 4c195789aec69cc9dc9bf762d9c95dc44c1e8428 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 09:07:23 +0800 Subject: [PATCH 16/39] 1 --- webapp/controller/ShopController.class.php | 34 +++++++++++++++------- webapp/mt/ShopGoods.php | 5 ++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index d69b551f..5b868568 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -61,7 +61,7 @@ class ShopController extends BaseAuthedController { public function buyGoods() { - $id = getReqVal('id', 0); + $goodsUuid = getReqVal('goods_uuid', 0); $tokenType = getReqVal('token_type', ''); $goodsNum = getReqVal('goods_num', 0); @@ -70,7 +70,7 @@ class ShopController extends BaseAuthedController { return; } - $goodsMeta = mt\ShopGoods::get($id); + $goodsMeta = mt\ShopGoods::getByGoodsUuid($id); if (!$goodsMeta) { $this->_rspErr(1, 'goods not found'); return; @@ -114,18 +114,18 @@ class ShopController extends BaseAuthedController { } } - $price_array = splitStr1($goodsMeta['price']); - $discount_array = splitStr1($goodsMeta['discount']); + $priceArray = splitStr1($goodsMeta['price']); + $discountArray = splitStr1($goodsMeta['discount']); - $need_price = $price_array[$token_pos]; - $discount = $discount_array[$token_pos]; + $needPrice = $priceArray[$tokenPos]; + $discount = $discountArray[$tokenPos]; - $discount_begin = strtotime($goodsMeta['discount_begin']); - $discount_end = strtotime($goodsMeta['discount_end']); + $discountBegin = strtotime($goodsMeta['discount_begin']); + $discountEnd = strtotime($goodsMeta['discount_end']); $nowTime = $this->_getNowTime(); - if ($nowTime >= $discount_begin && $nowTime < $discount_end) { - $need_price = ceil($need_price * ($discount / 100.0)); + if ($nowTime >= $discountBegin && $nowTime < $discountEnd) { + $needPrice = ceil($needPrice * ($discount / 100.0)); } $costItemId = $this->getCostItemIdByTokenType($tokenType); @@ -145,6 +145,20 @@ class ShopController extends BaseAuthedController { $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); return; } + ShopBuyRecord::add($id, $goodsNum); + $this->_decItems($costItems); + $propertyChgService = new services\PropertyChgService(); + for ($i = 0; $i < $goodsNum; $i++) { + $this->internalAddItem($propertyChgService, $itemMeta, $goodsCount, 0); + } + $propertyChgService->addUserChg(); + $this->_rspData( + array( + 'award' => $awardService->toDto(), + 'property_chg' => $propertyChgService->toDto(), + //'goods_chg' => $goodsDto + ) + ); } public function outappPurchase() diff --git a/webapp/mt/ShopGoods.php b/webapp/mt/ShopGoods.php index dd9ef143..010dca95 100644 --- a/webapp/mt/ShopGoods.php +++ b/webapp/mt/ShopGoods.php @@ -12,6 +12,11 @@ class ShopGoods return getXVal(self::getMetaList(), $id); } + public static function getByGoodsUuid($goodsUuid) + { + return getXVal(self::getMetaList(), $goodsUuid); + } + public static function getGoodsList($shopId) { self::mustBeShopGoodsHash(); From 5f31bcd84db52c97a1da51e63ad62caa24d5119a Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 09:12:49 +0800 Subject: [PATCH 17/39] 1 --- webapp/controller/ShopController.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 5b868568..a5f63723 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -70,7 +70,7 @@ class ShopController extends BaseAuthedController { return; } - $goodsMeta = mt\ShopGoods::getByGoodsUuid($id); + $goodsMeta = mt\ShopGoods::getByGoodsUuid($goodsUuid); if (!$goodsMeta) { $this->_rspErr(1, 'goods not found'); return; @@ -97,9 +97,9 @@ class ShopController extends BaseAuthedController { return; } - $desired_token_type = $goodsMeta['token_type']; - $check_token_type = splitStr1($desired_token_type); - $token_pos = array_search($tokenType, $check_token_type, true); + $desiredTokenType = $goodsMeta['token_type']; + $checkTokenType = splitStr1($desiredTokenType); + $tokenPos = array_search($tokenType, $checkTokenType, true); $isFreeBuy = false; if (!empty($goodsMeta['free_type'])) { $count = $this->countFreeBuyTimes($goodsMeta['free_type'], $goodsMeta['id'], $goodsMeta['goods_id']); @@ -108,8 +108,8 @@ class ShopController extends BaseAuthedController { } } if (!$isFreeBuy) { - if (!in_array($tokenType, $check_token_type)) { - $this->_rspErr(1, "token_type parameter error, desired_token_type: {$desired_token_type}"); + if (!in_array($tokenType, $checkTokenType)) { + $this->_rspErr(1, "token_type parameter error, desired_token_type: {$desiredTokenType}"); return; } } From 580a2d35d1e72a602ada16070c990f186a829bf8 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 09:23:33 +0800 Subject: [PATCH 18/39] 1 --- webapp/controller/ShopController.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index a5f63723..7da0ee8e 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -129,7 +129,7 @@ class ShopController extends BaseAuthedController { } $costItemId = $this->getCostItemIdByTokenType($tokenType); - $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); + $costItems = $this->makeCostItems($costItemId, $goodsNum * $needPrice); if (!in_array( $tokenType, array( From 701002030709831bd38257bfcda03a669d526379 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 10:48:08 +0800 Subject: [PATCH 19/39] 1 --- webapp/controller/ShopController.class.php | 123 ++++++++++----------- 1 file changed, 59 insertions(+), 64 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 7da0ee8e..276d8d3c 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -79,7 +79,7 @@ class ShopController extends BaseAuthedController { $this->_rspErr(1, "goods_num parameter error, max_amount: {$goodsMeta['max_amount']}"); return; } - $itemMeta = mt\Item::get($goodsMeta['goods_id']); + $itemMeta = mt\Item::get($goodsMeta['item_id']); if (!$itemMeta) { $this->_rspErr(1, 'goods not found, goods_id: ' . $goodsMeta['goods_id']); return; @@ -102,12 +102,24 @@ class ShopController extends BaseAuthedController { $tokenPos = array_search($tokenType, $checkTokenType, true); $isFreeBuy = false; if (!empty($goodsMeta['free_type'])) { - $count = $this->countFreeBuyTimes($goodsMeta['free_type'], $goodsMeta['id'], $goodsMeta['goods_id']); + $count = $this->countFreeBuyTimes($goodsMeta['free_type'], $goodsMeta['id'], $goodsMeta['item_id']); if ($count < $goodsMeta['free_num']) { $isFreeBuy = true; } } - if (!$isFreeBuy) { + $propertyChgService = new services\PropertyChgService(); + $awardService = new services\AwardService(); + if ($isFreeBuy) { + $awardService->addItem($itemMeta['id'], $goodsNum); + $this->_rspData( + array( + 'award' => $awardService->toDto(), + 'property_chg' => $propertyChgService->toDto(), + //'goods_chg' => $goodsDto + ) + ); + return; + } else { if (!in_array($tokenType, $checkTokenType)) { $this->_rspErr(1, "token_type parameter error, desired_token_type: {$desiredTokenType}"); return; @@ -147,9 +159,8 @@ class ShopController extends BaseAuthedController { } ShopBuyRecord::add($id, $goodsNum); $this->_decItems($costItems); - $propertyChgService = new services\PropertyChgService(); for ($i = 0; $i < $goodsNum; $i++) { - $this->internalAddItem($propertyChgService, $itemMeta, $goodsCount, 0); + $this->internalAddItem($propertyChgService, $itemMeta, $goodsMeta['goods_num'], 0); } $propertyChgService->addUserChg(); $this->_rspData( @@ -387,65 +398,51 @@ class ShopController extends BaseAuthedController { return $costItems; } - private function internalAddItem($propertyChgService, $itemMeta, $count, $sysAdd, $grade = null) + private function internalAddItem($propertyChgService, $itemMeta, $count, $grade = null) { switch ($itemMeta['type']) { - case mt\Item::HERO_TYPE: { - if (empty($grade)) { - $grade = 0; - } - switch ($grade) { - case 1: { - Hero::addHero1($itemMeta); - } - break; - case 2: { - Hero::addHero2($itemMeta); - } - break; - case 3: { - Hero::addHero3($itemMeta); - } - break; - default: { - Hero::addHero($itemMeta); - } - break; - } - $propertyChgService->addHeroChg(); - $propertyChgService->addUserChg(); - } - break; - case mt\Item::HERO_SKIN_TYPE: { - HeroSkin::addSkin($itemMeta); - $propertyChgService->addHeroSkinChg(); - } - break; - case mt\Item::GUN_TYPE: { - Gun::addGun($itemMeta); - $propertyChgService->addGunChg(); - } - break; - case mt\Item::GUN_SKIN_TYPE: { - GunSkin::addSkin($itemMeta); - $propertyChgService->addGunSkinChg(); - } - break; - case mt\Item::CHIP_TYPE: { - Chip::addChip($itemMeta); - $propertyChgService->addChip(); - } - break; - default: { - if ($this->_isVirtualItem($itemMeta['id'])) { - $this->_addVirtualItem($itemMeta['id'], $count, null, $propertyChgService); - $propertyChgService->addUserChg(); - } else { - Bag::addItem($itemMeta['id'], $count); - $propertyChgService->addBagChg(); - } - } - break; + case mt\Item::HERO_TYPE: + { + if (empty($grade)) { + $grade = 0; + } + switch ($grade) { + case 1: + { + Hero::addHero1($itemMeta); + } + break; + case 2: + { + Hero::addHero2($itemMeta); + } + break; + case 3: + { + Hero::addHero3($itemMeta); + } + break; + default: + { + Hero::addHero($itemMeta); + } + break; + } + $propertyChgService->addHeroChg(); + $propertyChgService->addUserChg(); + } + break; + default: + { + myself()->_addItems( + array( + 'item_id' => $itemMeta['id'], + 'item_num' => $count + ), + $awardService, + $propertyChgService); + } + break; } } @@ -494,8 +491,6 @@ class ShopController extends BaseAuthedController { $bn1 = phpcommon\bnInit($price * pow(10, 8)); $bn2 = phpcommon\bnInit('1000000000000000000'); $ret_price = phpcommon\bnDiv(phpcommon\bnMul($bn1, $bn2), pow(10, 8)); - - // error_log('normalizeWeb3Price: ' . $ret_price . ' ' . $price * pow(10, 8)); return phpcommon\bnToStr($ret_price); } From cb40c60c20ac5693d444beee02919480baeae1da Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 10:54:18 +0800 Subject: [PATCH 20/39] 1 --- webapp/controller/ShopController.class.php | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 276d8d3c..8a7cfd2f 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -141,7 +141,10 @@ class ShopController extends BaseAuthedController { } $costItemId = $this->getCostItemIdByTokenType($tokenType); - $costItems = $this->makeCostItems($costItemId, $goodsNum * $needPrice); + $costItems = array( + 'item_id' => $costItemId, + 'item_num' => $goodsNum * $needPrice + ); if (!in_array( $tokenType, array( @@ -160,7 +163,11 @@ class ShopController extends BaseAuthedController { ShopBuyRecord::add($id, $goodsNum); $this->_decItems($costItems); for ($i = 0; $i < $goodsNum; $i++) { - $this->internalAddItem($propertyChgService, $itemMeta, $goodsMeta['goods_num'], 0); + $this->internalAddItem($awardService, + $propertyChgService, + $itemMeta, + $goodsMeta['goods_num'], + 0); } $propertyChgService->addUserChg(); $this->_rspData( @@ -387,18 +394,11 @@ class ShopController extends BaseAuthedController { } } - private function makeCostItems($item_id, $num) - { - $costItems = array( - array( - 'item_id' => $item_id, - 'item_num' => $num - ) - ); - return $costItems; - } - - private function internalAddItem($propertyChgService, $itemMeta, $count, $grade = null) + private function internalAddItem($awardService, + $propertyChgService, + $itemMeta, + $count, + $grade = null) { switch ($itemMeta['type']) { case mt\Item::HERO_TYPE: From cdedb2059aaebcbc06af9c1010ee3db0852c9496 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 10:58:04 +0800 Subject: [PATCH 21/39] 1 --- webapp/controller/ShopController.class.php | 30 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 8a7cfd2f..87304b57 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -52,7 +52,7 @@ class ShopController extends BaseAuthedController { { $shopId = getReqVal('shop_id', 0); $goodsList = ShopService::getGoodsList($shopId); - $this->_rspData( + myself()->_rspData( array( 'goods_list' => $goodsList, ) @@ -66,34 +66,34 @@ class ShopController extends BaseAuthedController { $goodsNum = getReqVal('goods_num', 0); if ($goodsNum < 1) { - $this->_rspErr(1, "goods_num parameter error, goods_num: {$goodsNum}"); + myself()->_rspErr(1, "goods_num parameter error, goods_num: {$goodsNum}"); return; } $goodsMeta = mt\ShopGoods::getByGoodsUuid($goodsUuid); if (!$goodsMeta) { - $this->_rspErr(1, 'goods not found'); + myself()->_rspErr(1, 'goods not found'); return; } if ($goodsNum > $goodsMeta['max_amount']) { - $this->_rspErr(1, "goods_num parameter error, max_amount: {$goodsMeta['max_amount']}"); + myself()->_rspErr(1, "goods_num parameter error, max_amount: {$goodsMeta['max_amount']}"); return; } $itemMeta = mt\Item::get($goodsMeta['item_id']); if (!$itemMeta) { - $this->_rspErr(1, 'goods not found, goods_id: ' . $goodsMeta['goods_id']); + myself()->_rspErr(1, 'goods not found, goods_id: ' . $goodsMeta['goods_id']); return; } $errCode = 0; $errMsg = ''; if ($itemMeta['type'] == mt\Item::HERO_SKIN_TYPE) { if (!$this->canBuy($itemMeta, $errCode, $errMsg)) { - $this->_rspErr($errCode, $errMsg); + myself()->_rspErr($errCode, $errMsg); return; } } if (!ShopService::buyLimitCheck($goodsMeta, $errCode, $errMsg)) { - $this->_rspErr($errCode, $errMsg); + myself()->_rspErr($errCode, $errMsg); return; } @@ -111,7 +111,7 @@ class ShopController extends BaseAuthedController { $awardService = new services\AwardService(); if ($isFreeBuy) { $awardService->addItem($itemMeta['id'], $goodsNum); - $this->_rspData( + myself()->_rspData( array( 'award' => $awardService->toDto(), 'property_chg' => $propertyChgService->toDto(), @@ -121,7 +121,7 @@ class ShopController extends BaseAuthedController { return; } else { if (!in_array($tokenType, $checkTokenType)) { - $this->_rspErr(1, "token_type parameter error, desired_token_type: {$desiredTokenType}"); + myself()->_rspErr(1, "token_type parameter error, desired_token_type: {$desiredTokenType}"); return; } } @@ -134,13 +134,13 @@ class ShopController extends BaseAuthedController { $discountBegin = strtotime($goodsMeta['discount_begin']); $discountEnd = strtotime($goodsMeta['discount_end']); - $nowTime = $this->_getNowTime(); + $nowTime = myself()->_getNowTime(); if ($nowTime >= $discountBegin && $nowTime < $discountEnd) { $needPrice = ceil($needPrice * ($discount / 100.0)); } - $costItemId = $this->getCostItemIdByTokenType($tokenType); + $costItemId = myself()->getCostItemIdByTokenType($tokenType); $costItems = array( 'item_id' => $costItemId, 'item_num' => $goodsNum * $needPrice @@ -152,16 +152,16 @@ class ShopController extends BaseAuthedController { mt\Shop::TOKEN_TYPE_DIAMOND ) )) { - $this->_rspErr(1, "token_type is unsupport, {$tokenType}"); + myself()->_rspErr(1, "token_type is unsupport, {$tokenType}"); return; } $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); + if (!myself()->_hasEnoughItems($costItems, $lackItem)) { + myself()->_rspErr(2, myself()->_getLackItemErrMsg($lackItem)); return; } ShopBuyRecord::add($id, $goodsNum); - $this->_decItems($costItems); + myself()->_decItems($costItems); for ($i = 0; $i < $goodsNum; $i++) { $this->internalAddItem($awardService, $propertyChgService, From 64e190056ba1101a3ea9a03436f22f933f072594 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 12:33:27 +0800 Subject: [PATCH 22/39] 1 --- webapp/controller/ShopController.class.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 87304b57..ee5415ab 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -160,7 +160,7 @@ class ShopController extends BaseAuthedController { myself()->_rspErr(2, myself()->_getLackItemErrMsg($lackItem)); return; } - ShopBuyRecord::add($id, $goodsNum); + ShopBuyRecord::add($itemMeta['id'], $goodsNum); myself()->_decItems($costItems); for ($i = 0; $i < $goodsNum; $i++) { $this->internalAddItem($awardService, @@ -174,7 +174,6 @@ class ShopController extends BaseAuthedController { array( 'award' => $awardService->toDto(), 'property_chg' => $propertyChgService->toDto(), - //'goods_chg' => $goodsDto ) ); } From 8ec2131b82a640867eef4c4e978840c769abc7c6 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 12:42:44 +0800 Subject: [PATCH 23/39] 1 --- webapp/controller/ShopController.class.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index ee5415ab..95e4ca07 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -166,8 +166,8 @@ class ShopController extends BaseAuthedController { $this->internalAddItem($awardService, $propertyChgService, $itemMeta, - $goodsMeta['goods_num'], - 0); + $goodsMeta['goods_num'] + ); } $propertyChgService->addUserChg(); $this->_rspData( @@ -365,7 +365,6 @@ class ShopController extends BaseAuthedController { array( 'items' => array_keys($record), 'free_num' => $free_num, - 'pending' => 0, ) ); } @@ -396,8 +395,8 @@ class ShopController extends BaseAuthedController { private function internalAddItem($awardService, $propertyChgService, $itemMeta, - $count, - $grade = null) + $count + ) { switch ($itemMeta['type']) { case mt\Item::HERO_TYPE: From 2b029f1b771c66cd1122bca906012e7aa667f48d Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 13:17:05 +0800 Subject: [PATCH 24/39] 1 --- sql/gamedb.sql | 58 ++++++++++++++++++++++ webapp/controller/ShopController.class.php | 22 ++------ webapp/models/InAppOrder.php | 10 ++++ webapp/models/OutAppOrder.php | 10 ++++ webapp/mt/Shop.php | 1 + 5 files changed, 83 insertions(+), 18 deletions(-) create mode 100644 webapp/models/InAppOrder.php create mode 100644 webapp/models/OutAppOrder.php diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 6dbdf24f..d1dfafc6 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -1278,6 +1278,64 @@ CREATE TABLE `t_user_honor` ( ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `t_inapp_order` +-- + +DROP TABLE IF EXISTS `t_inapp_order`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_inapp_order` ( + `idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `order_id` varchar(60) NOT NULL DEFAULT '' COMMENT '订单id', + `sp_order_id` varchar(64) DEFAULT NULL COMMENT 'app store order_id', + `platform` int(11) NOT NULL DEFAULT '0' COMMENT '0: ios 1: android', + `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '申请账号id', + `address` varchar(60) DEFAULT NULL COMMENT '申请时账号绑定的钱包', + `item_id` int(11) NOT NULL DEFAULT '0' COMMENT '物品id', + `item_num` bigint(20) NOT NULL DEFAULT '0' COMMENT '物品数量', + `price` bigint(20) NOT NULL DEFAULT '0' COMMENT '价格', + `status` int(11) NOT NULL DEFAULT '0' COMMENT 'status', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `order_id` (`order_id`), + UNIQUE KEY `platform_sp_order_id` (`platform_sp_order_id`), + KEY `account_id` (`account_id`), + KEY `address` (`address`), + KEY `sp_order_id` (`sp_order_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_outapp_order` +-- + +DROP TABLE IF EXISTS `t_outapp_order`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_outapp_order` ( + `idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `order_id` varchar(60) NOT NULL DEFAULT '' COMMENT '订单id', + `sp_order_id` varchar(64) DEFAULT NULL COMMENT 'app store order_id', + `platform` int(11) NOT NULL DEFAULT '0' COMMENT '0: ios 1: android', + `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '申请账号id', + `address` varchar(60) DEFAULT NULL COMMENT '申请时账号绑定的钱包', + `item_id` int(11) NOT NULL DEFAULT '0' COMMENT '物品id', + `item_num` bigint(20) NOT NULL DEFAULT '0' COMMENT '物品数量', + `price` bigint(20) NOT NULL DEFAULT '0' COMMENT '价格', + `status` int(11) NOT NULL DEFAULT '0' COMMENT 'status', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `order_id` (`order_id`), + UNIQUE KEY `platform_sp_order_id` (`platform_sp_order_id`), + KEY `account_id` (`account_id`), + KEY `address` (`address`), + KEY `sp_order_id` (`sp_order_id`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + DROP TABLE IF EXISTS `t_web2_order`; CREATE TABLE `t_web2_order` ( `idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id', diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 95e4ca07..7bf53c23 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -245,32 +245,18 @@ class ShopController extends BaseAuthedController { public function inappPurchase() { - $self = myself(); - if (!$self) { - $this->_rspErr(1, "start purchase failed"); - return; - } - - $id = getReqVal('id', 0); - $goods = mt\ShopGoods::get($id); + $goodsUuid = getReqVal('goods_uuid', 0); + $goodsNum = getReqVal('goods_num', 0); + $goods = mt\ShopGoods::getByGoodsUuid($goodsUuid); if (!$goods) { $this->_rspErr(2, "start purchase failed"); return; } - if ($goods['shop_id'] != 9) { + if ($goods['shop_id'] != mt\Shop::INAPP_SHOP) { $this->_rspErr(3, "start purchase failed"); return; } - $goodsNum = getReqVal('goods_num', 1); - - $account_id = $self->_getAccountId(); - $address = $self->_getAddress(); - if (empty($address)) { - $this->_rspErr(4, "start purchase failed"); - return; - } - $item_id = $goods['goods_id']; $item_num = $goods['goods_num'] * $goodsNum; diff --git a/webapp/models/InAppOrder.php b/webapp/models/InAppOrder.php new file mode 100644 index 00000000..7cccd922 --- /dev/null +++ b/webapp/models/InAppOrder.php @@ -0,0 +1,10 @@ + Date: Sun, 30 Jul 2023 13:22:35 +0800 Subject: [PATCH 25/39] 1 --- webapp/controller/ShopController.class.php | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 7bf53c23..a788cf5d 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -291,14 +291,6 @@ class ShopController extends BaseAuthedController { )); } - 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; - } - public function queryInappPurchase() { $order_id = getReqVal('order_id', ''); @@ -464,20 +456,6 @@ class ShopController extends BaseAuthedController { } } - private function lastInsertId($conn) - { - $row = $conn->execQueryOne('SELECT LAST_INSERT_ID() as lastId;', array()); - return $row['lastId']; - } - - private function normalizeWeb3Price($price) - { - $bn1 = phpcommon\bnInit($price * pow(10, 8)); - $bn2 = phpcommon\bnInit('1000000000000000000'); - $ret_price = phpcommon\bnDiv(phpcommon\bnMul($bn1, $bn2), pow(10, 8)); - return phpcommon\bnToStr($ret_price); - } - private function addFreeBuyRecord($goods) { $conn = myself()->_getMysql(''); From 9e2d8768a8924dac56739685aa71334b1efac2fe Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 13:32:15 +0800 Subject: [PATCH 26/39] 1 --- doc/Shop.py | 14 ------ webapp/controller/ShopController.class.php | 50 ++++++++-------------- webapp/models/InAppOrder.php | 11 +++++ 3 files changed, 29 insertions(+), 46 deletions(-) diff --git a/doc/Shop.py b/doc/Shop.py index 63d667ba..62041fd8 100644 --- a/doc/Shop.py +++ b/doc/Shop.py @@ -85,20 +85,6 @@ class Shop(object): ['status', 0, '订单状态 0:未支付 1:已支付 2:支付失败'], ] }, - { - 'name': 'getPayMethods', - 'desc': '获取支付方式', - 'group': 'Shop', - 'url': 'webapp/index.php?c=Shop&a=getPayMethods', - 'params': [ - _common.ReqHead(), - ['token_type', 0, "选用币种"], - ], - 'response': [ - _common.RspHead(), - ['!pay_methods', [_common.PayMethod()], '支付方式列表'], - ] - }, { 'name': 'boxPreview', 'desc': '宝箱道具预览', diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index a788cf5d..0aa5ee39 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -2,48 +2,30 @@ require_once('mt/Shop.php'); require_once('mt/ShopGoods.php'); -require_once('mt/Hero.php'); require_once('mt/Item.php'); require_once('mt/Parameter.php'); -require_once('mt/Drop.php'); require_once('mt/ShopChest.php'); -require_once('models/User.php'); require_once('models/Hero.php'); -require_once('models/Bag.php'); -require_once('models/HeroSkin.php'); -require_once('models/Gun.php'); -require_once('models/GunSkin.php'); require_once('models/ShopBuyRecord.php'); -require_once('models/Chip.php'); -require_once('models/BcOrder.php'); -require_once('models/Transaction.php'); +require_once('models/InAppOrder.php'); +require_once('models/OutAppOrder.php'); require_once('services/AwardService.php'); require_once('services/PropertyChgService.php'); -require_once('services/BlockChainService.php'); require_once('services/ShopService.php'); - -require_once('phpcommon/bignumber.php'); - require_once('services/LogService.php'); -require_once('services/callback/ShopAddItemService.php'); -use models\User; -use models\Bag; -use models\Hero; -use models\HeroSkin; -use models\Gun; -use models\GunSkin; -use models\ShopBuyRecord; -use models\Chip; use mt\Shop; use mt\ShopChest; use mt\ShopGoods; -use models\Transaction; -use models\BcOrder; + +use models\Hero; +use models\ShopBuyRecord; +use models\InAppOrder; +use models\OutAppOrder; + use services\LogService; -use services\ShopAddItemService; use services\ShopService; class ShopController extends BaseAuthedController { @@ -293,14 +275,18 @@ class ShopController extends BaseAuthedController { public function queryInappPurchase() { - $order_id = getReqVal('order_id', ''); - $conn = myself()->_getMysql(''); - $order = SqlHelper::selectOne($conn, 't_web2_order', array('item_id', 'item_num', 'status'), array('order_id' => $order_id)); - if (!$order) { - $this->_rspErr(1, "order not found"); + $orderId = getReqVal('order_id', ''); + $orderDb = InAppOrder::find($orderId); + if ($orderDb) { + myself()->_rspErr(1, 'order not found'); return; } - $this->_rspData($order); + $this->_rspData(array( + 'order_id' => $orderDb['order_id'], + 'item_id' => $orderDb['item_id'], + 'item_num' => $orderDb['item_num'], + 'status' => $orderDb['status'], + )); } public function boxPreview() diff --git a/webapp/models/InAppOrder.php b/webapp/models/InAppOrder.php index 7cccd922..2bc16bbc 100644 --- a/webapp/models/InAppOrder.php +++ b/webapp/models/InAppOrder.php @@ -7,4 +7,15 @@ use phpcommon\SqlHelper; class InAppOrder extends BaseModel { + public static function find($orderId) { + $row = SqlHelper::ormSelectOne( + myself()->_get(), + 't_inapp_order', + array( + 'order_id' => $orderId, + ) + ); + return $row; + } + } From 89c9c8799f3d2af07bbf0f5316106cca72d311d7 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 13:34:06 +0800 Subject: [PATCH 27/39] 1 --- webapp/controller/ShopController.class.php | 27 ---------------------- 1 file changed, 27 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 0aa5ee39..834ba6dd 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -442,31 +442,4 @@ class ShopController extends BaseAuthedController { } } - private function addFreeBuyRecord($goods) - { - $conn = myself()->_getMysql(''); - $account = myself()->_getAccountId(); - - switch ($goods['free_type']) { - case 1: { - $dayTime = myself()->_getNowTime(); - SqlHelper::insert( - $conn, - 't_shop_free_record', - array( - 'account_id' => $account, - 'shop_id' => $goods['shop_id'], - 'id' => $goods['id'], - 'goods_id' => $goods['goods_id'], - 'goods_num' => $goods['goods_num'], - 'free_type' => $goods['free_type'], - 'free_num' => $goods['free_num'], - 'createtime' => $dayTime, - ) - ); - } - break; - } - } - } From c5293c8884ea34c77e0ba6637a36f0735d0db917 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 13:54:27 +0800 Subject: [PATCH 28/39] 1 --- .../controller/CallbackController.class.php | 4 +- webapp/controller/ShopController.class.php | 34 --- ...opBuyGoodsDirect.php => InAppPurchase.php} | 4 +- webapp/services/callback/IutAppPurchase.php | 226 ++++++++++++++++++ webapp/services/callback/OutAppPurchase.php | 226 ++++++++++++++++++ 5 files changed, 456 insertions(+), 38 deletions(-) rename webapp/services/callback/{ShopBuyGoodsDirect.php => InAppPurchase.php} (99%) create mode 100644 webapp/services/callback/IutAppPurchase.php create mode 100644 webapp/services/callback/OutAppPurchase.php diff --git a/webapp/controller/CallbackController.class.php b/webapp/controller/CallbackController.class.php index 6266d6c5..be917c15 100644 --- a/webapp/controller/CallbackController.class.php +++ b/webapp/controller/CallbackController.class.php @@ -15,8 +15,8 @@ class CallbackController extends BaseController { 'MarketBuyOrderOk' => 'MarketBuyOrderOk', 'MarketCancelOrderOk' => 'MarketCancelOrderOk', 'MarketPriceUpdateOrderOk' => 'MarketPriceUpdateOrderOk', - 'ShopBuyGoodsDirect' => 'ShopBuyGoodsDirect', - //'ShopInappPurchaseDiamonds' => 'ShopInappPurchaseDiamonds', + 'inappPurchase' => 'InAppPurchase', + 'outappPurchase' => 'OutAppPurchase', ); public function dispatch() diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 834ba6dd..9fccbffc 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -408,38 +408,4 @@ class ShopController extends BaseAuthedController { } } - private function beginFirstTupop($address = null) - { - if (!$address) { - $address = myself()->_getAddress(); - } - $conn = myself()->_getMysql(''); - - $exist = SqlHelper::selectOne( - $conn, - 't_first_topup', - array('address'), - array('address' => $address) - ); - if ($exist) { - return; - } - - // 开始首充奖励活动进程 - $chk = SqlHelper::insert( - $conn, - 't_first_topup', - array( - 'address' => $address, - 'createtime' => myself()->_getNowTime(), - 'status1' => 0, - 'status2' => 0, - 'status3' => 0, - ) - ); - if (!$chk) { - return; - } - } - } diff --git a/webapp/services/callback/ShopBuyGoodsDirect.php b/webapp/services/callback/InAppPurchase.php similarity index 99% rename from webapp/services/callback/ShopBuyGoodsDirect.php rename to webapp/services/callback/InAppPurchase.php index 673ded55..a4a5cbf3 100644 --- a/webapp/services/callback/ShopBuyGoodsDirect.php +++ b/webapp/services/callback/InAppPurchase.php @@ -16,8 +16,8 @@ use models\ShopBuyRecord; use services\LogService; -class ShopBuyGoodsDirect -{ +class InAppPurchase { + public function process() { error_log("buyGoodsDirect --- " . json_encode($_REQUEST)); diff --git a/webapp/services/callback/IutAppPurchase.php b/webapp/services/callback/IutAppPurchase.php new file mode 100644 index 00000000..b042917f --- /dev/null +++ b/webapp/services/callback/IutAppPurchase.php @@ -0,0 +1,226 @@ + $account_id, + 'id' => $id, + 'order_id' => $order_id, + 'status' => $status, + 'txhash' => $txhash, + ); + + $hash_data = http_build_query($data); + + $signature = hash_hmac('sha256', $hash_data, BUY_SERVER_PKEY); + + if ($signature != $sign) { + $this->_rspErr(1, "signature error, signature: {$signature}, sign: {$sign}"); + return; + } + + error_log("buyGoodsDirect-------" . $order_id . "---" . $status); + + $conn = myself()->_getMysql(''); + + $order = SqlHelper::selectOne($conn, 't_shop_buy_order', array('address', 'id', 'item_id', 'goods_num', 'status'), array('order_id' => $order_id)); + if (!$order) { + $this->_rspErr(2, "order not found: {$order_id}"); + return; + } + + $id = $order['id']; + $goods_num = $order['goods_num']; + $o_status = $order['status']; + $address = $order['address']; + + if ($o_status != 0) { + $this->_rspErr(1, "order status error, status: {$o_status}"); + return; + } + + $buyStatus = 0; // 1: 成功, 2: 失败 + switch ($status) { + case "9": + $buyStatus = 1; + // 充值成功,开始首充奖励 + $this->beginFirstTupop($address); + break; + case "99": + case "98": + $buyStatus = 2; + break; + default: + error_log("buyGoodsDirect--- " . $order_id . " --- " . $status); + $this->_rspErr(1, "status error, status: {$status}"); + break; + } + + SqlHelper::update($conn, 't_shop_buy_order', array('order_id' => $order_id), array('status' => $buyStatus)); + + if ($buyStatus == 2) { + $this->_rspErr(2, "buyStatus error, buyStatus: {$buyStatus}"); + return; + } + + // 以下是看商品表中是否配置了充值额外奖励 + $goods = ShopGoods::get($id); + error_log("buyGoodsDirect---" . json_encode($goods)); + $goods_num = $order['goods_num']; + $bundle_size = $goods['bonus_num'] ? $goods['bonus_num'] : 0; + $item_num = $goods_num * $bundle_size; + $item_id = $goods['bonus']; + $meta = Item::get($item_id); + error_log("buyGoodsDirect---" . $item_id . "---" . $item_num . "---" . $bundle_size . "---" . $meta['name']); + if ($meta && $item_num > 0) { + // $address = $order['address']; + $account_id = $this->getAccountId($address); + + if ($item_id == V_ITEM_DIAMOND) { + $event = [ + 'name' => LogService::RECHARGE_CEBG_BONUS, + 'val' => $item_num + ]; + LogService::productDiamondCallback(['account_id' => $account_id], $event); + } + + error_log("buyGoodsDirect---" . $address . "---" . $item_id . "---" . $item_num); + + $this->_addGoods($address, array( + 'goods_id' => $item_id, + 'goods_num' => $item_num, + 'id' => $id, + )); + } + + $this->_rspOk(); + } + + private function getAccountId($address) + { + $row = SqlHelper::ormSelectOne( + myself()->_getMysql($address), + 't_user', + array( + 'address' => $address + ) + ); + return $row['account_id']; + } + + private function _addGoods($address, $goods) + { + $itemService = new ShopAddItemService(); + $item_id = $goods['goods_id']; + $goods_num = $goods['goods_num']; + + $id = null; + if ($goods['id']) { + $id = $goods['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); + } + } + + private function beginFirstTupop($address) + { + $conn = myself()->_getMysql(''); + + $exist = SqlHelper::selectOne( + $conn, + 't_first_topup', + array('address'), + array('address' => $address) + ); + if ($exist) { + return; + } + + // 开始首充奖励活动进程 + $chk = SqlHelper::insert( + $conn, + 't_first_topup', + array( + 'address' => $address, + 'createtime' => myself()->_getNowTime(), + 'status1' => 0, + 'status2' => 0, + 'status3' => 0, + ) + ); + if (!$chk) { + return; + } + } + + private function _rspOk() + { + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => "callback success", + )); + } + + private function _rspErr($errcode, $errmsg) + { + if (SERVER_ENV != _ONLINE) { + error_log(json_encode(array( + 'errcode' => $errcode, + 'errmsg' => $errmsg, + ))); + } + echo json_encode(array( + 'errcode' => $errcode, + 'errmsg' => $errmsg, + )); + } +} diff --git a/webapp/services/callback/OutAppPurchase.php b/webapp/services/callback/OutAppPurchase.php new file mode 100644 index 00000000..b042917f --- /dev/null +++ b/webapp/services/callback/OutAppPurchase.php @@ -0,0 +1,226 @@ + $account_id, + 'id' => $id, + 'order_id' => $order_id, + 'status' => $status, + 'txhash' => $txhash, + ); + + $hash_data = http_build_query($data); + + $signature = hash_hmac('sha256', $hash_data, BUY_SERVER_PKEY); + + if ($signature != $sign) { + $this->_rspErr(1, "signature error, signature: {$signature}, sign: {$sign}"); + return; + } + + error_log("buyGoodsDirect-------" . $order_id . "---" . $status); + + $conn = myself()->_getMysql(''); + + $order = SqlHelper::selectOne($conn, 't_shop_buy_order', array('address', 'id', 'item_id', 'goods_num', 'status'), array('order_id' => $order_id)); + if (!$order) { + $this->_rspErr(2, "order not found: {$order_id}"); + return; + } + + $id = $order['id']; + $goods_num = $order['goods_num']; + $o_status = $order['status']; + $address = $order['address']; + + if ($o_status != 0) { + $this->_rspErr(1, "order status error, status: {$o_status}"); + return; + } + + $buyStatus = 0; // 1: 成功, 2: 失败 + switch ($status) { + case "9": + $buyStatus = 1; + // 充值成功,开始首充奖励 + $this->beginFirstTupop($address); + break; + case "99": + case "98": + $buyStatus = 2; + break; + default: + error_log("buyGoodsDirect--- " . $order_id . " --- " . $status); + $this->_rspErr(1, "status error, status: {$status}"); + break; + } + + SqlHelper::update($conn, 't_shop_buy_order', array('order_id' => $order_id), array('status' => $buyStatus)); + + if ($buyStatus == 2) { + $this->_rspErr(2, "buyStatus error, buyStatus: {$buyStatus}"); + return; + } + + // 以下是看商品表中是否配置了充值额外奖励 + $goods = ShopGoods::get($id); + error_log("buyGoodsDirect---" . json_encode($goods)); + $goods_num = $order['goods_num']; + $bundle_size = $goods['bonus_num'] ? $goods['bonus_num'] : 0; + $item_num = $goods_num * $bundle_size; + $item_id = $goods['bonus']; + $meta = Item::get($item_id); + error_log("buyGoodsDirect---" . $item_id . "---" . $item_num . "---" . $bundle_size . "---" . $meta['name']); + if ($meta && $item_num > 0) { + // $address = $order['address']; + $account_id = $this->getAccountId($address); + + if ($item_id == V_ITEM_DIAMOND) { + $event = [ + 'name' => LogService::RECHARGE_CEBG_BONUS, + 'val' => $item_num + ]; + LogService::productDiamondCallback(['account_id' => $account_id], $event); + } + + error_log("buyGoodsDirect---" . $address . "---" . $item_id . "---" . $item_num); + + $this->_addGoods($address, array( + 'goods_id' => $item_id, + 'goods_num' => $item_num, + 'id' => $id, + )); + } + + $this->_rspOk(); + } + + private function getAccountId($address) + { + $row = SqlHelper::ormSelectOne( + myself()->_getMysql($address), + 't_user', + array( + 'address' => $address + ) + ); + return $row['account_id']; + } + + private function _addGoods($address, $goods) + { + $itemService = new ShopAddItemService(); + $item_id = $goods['goods_id']; + $goods_num = $goods['goods_num']; + + $id = null; + if ($goods['id']) { + $id = $goods['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); + } + } + + private function beginFirstTupop($address) + { + $conn = myself()->_getMysql(''); + + $exist = SqlHelper::selectOne( + $conn, + 't_first_topup', + array('address'), + array('address' => $address) + ); + if ($exist) { + return; + } + + // 开始首充奖励活动进程 + $chk = SqlHelper::insert( + $conn, + 't_first_topup', + array( + 'address' => $address, + 'createtime' => myself()->_getNowTime(), + 'status1' => 0, + 'status2' => 0, + 'status3' => 0, + ) + ); + if (!$chk) { + return; + } + } + + private function _rspOk() + { + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => "callback success", + )); + } + + private function _rspErr($errcode, $errmsg) + { + if (SERVER_ENV != _ONLINE) { + error_log(json_encode(array( + 'errcode' => $errcode, + 'errmsg' => $errmsg, + ))); + } + echo json_encode(array( + 'errcode' => $errcode, + 'errmsg' => $errmsg, + )); + } +} From 9017463ff0ef0a2b0ba2d2d62aa8e2c035564ebb Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 14:03:47 +0800 Subject: [PATCH 29/39] 1 --- webapp/services/callback/OutAppPurchase.php | 23 +-------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/webapp/services/callback/OutAppPurchase.php b/webapp/services/callback/OutAppPurchase.php index b042917f..a43aba32 100644 --- a/webapp/services/callback/OutAppPurchase.php +++ b/webapp/services/callback/OutAppPurchase.php @@ -20,7 +20,7 @@ class OutAppPurchase { public function process() { - error_log("buyGoodsDirect --- " . json_encode($_REQUEST)); + error_log("OutAppPurchase --- " . json_encode($_REQUEST)); // let repdata = { // account_id: string @@ -202,25 +202,4 @@ class OutAppPurchase { } } - private function _rspOk() - { - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => "callback success", - )); - } - - private function _rspErr($errcode, $errmsg) - { - if (SERVER_ENV != _ONLINE) { - error_log(json_encode(array( - 'errcode' => $errcode, - 'errmsg' => $errmsg, - ))); - } - echo json_encode(array( - 'errcode' => $errcode, - 'errmsg' => $errmsg, - )); - } } From 7b356dbcd5fb122d93507c10927b09cc9f49b7ca Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 14:13:23 +0800 Subject: [PATCH 30/39] 1 --- .../controller/CallbackController.class.php | 32 +++------------ webapp/services/CallBack.php | 39 +++++++++++++++++++ 2 files changed, 45 insertions(+), 26 deletions(-) create mode 100644 webapp/services/CallBack.php diff --git a/webapp/controller/CallbackController.class.php b/webapp/controller/CallbackController.class.php index be917c15..25769447 100644 --- a/webapp/controller/CallbackController.class.php +++ b/webapp/controller/CallbackController.class.php @@ -5,37 +5,17 @@ 需要对web3service回调的做签名校验!!! */ -class CallbackController extends BaseController { +require_once('services/CallBack.php'); - private $handlers = array( - 'mintNftHero' => 'MintNftHero' , - 'gameItemMallBuyOk' => 'GameItemMallBuyOk', - 'gameItemMarketBuyOk' => 'GameItemMarketBuyOk', - 'MarketSellOrderOk' => 'MarketSellOrderOk', - 'MarketBuyOrderOk' => 'MarketBuyOrderOk', - 'MarketCancelOrderOk' => 'MarketCancelOrderOk', - 'MarketPriceUpdateOrderOk' => 'MarketPriceUpdateOrderOk', - 'inappPurchase' => 'InAppPurchase', - 'outappPurchase' => 'OutAppPurchase', - ); +use services\CallBackService; + +class CallbackController extends BaseController { public function dispatch() { - error_log("CallbackController Begin"); + $cbService = new CallBackService(); $action = getReqVal('action', ''); - if (key_exists($action, $this->handlers)) { - error_log("Callback:dispatch____". json_encode($_REQUEST)); - $this->internalDispatch($this->handlers[$action]); - } else { - $this->_rspErr(500, 'not found'); - } - } - - private function internalDispatch($className) - { - require_once ('services/callback/' . $className . '.php'); - $obj = eval("return new services\\" . $className . "();"); - $obj->process(); + $cbService->dispatch($action); } } diff --git a/webapp/services/CallBack.php b/webapp/services/CallBack.php new file mode 100644 index 00000000..f0d2bd98 --- /dev/null +++ b/webapp/services/CallBack.php @@ -0,0 +1,39 @@ + 'MintNftHero' , + 'gameItemMallBuyOk' => 'GameItemMallBuyOk', + 'gameItemMarketBuyOk' => 'GameItemMarketBuyOk', + 'MarketSellOrderOk' => 'MarketSellOrderOk', + 'MarketBuyOrderOk' => 'MarketBuyOrderOk', + 'MarketCancelOrderOk' => 'MarketCancelOrderOk', + 'MarketPriceUpdateOrderOk' => 'MarketPriceUpdateOrderOk', + 'inappPurchase' => 'InAppPurchase', + 'outappPurchase' => 'OutAppPurchase', + ); + + public function dispatch($action) + { + error_log("CallbackController Begin"); + if (key_exists($action, $this->handlers)) { + error_log("Callback:dispatch____". json_encode($_REQUEST)); + $this->internalDispatch($this->handlers[$action]); + } else { + myself()->_rspErr(500, 'not found'); + die(); + } + } + + private function internalDispatch($className) + { + require_once ('services/callback/' . $className . '.php'); + $obj = eval("return new services\\" . $className . "();"); + $obj->process(); + die(); + } + +} From 79922b27817fc4bd81d41ab7560b099c24547ce9 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 14:16:44 +0800 Subject: [PATCH 31/39] 1 --- webapp/controller/ShopController.class.php | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 9fccbffc..d69fcdf1 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -15,6 +15,7 @@ require_once('services/AwardService.php'); require_once('services/PropertyChgService.php'); require_once('services/ShopService.php'); require_once('services/LogService.php'); +require_once('services/CallBack.php'); use mt\Shop; use mt\ShopChest; @@ -27,9 +28,21 @@ use models\OutAppOrder; use services\LogService; use services\ShopService; +use services\CallBackService; class ShopController extends BaseAuthedController { + public function _handlePre() + { + $a = getReqVal('a', ''); + if ( + $a != 'buyGoodsDirect' && + $a != 'inappPurchaseDiamonds' + ) { + parent::_handlePre(); + } + } + public function getGoodsList() { $shopId = getReqVal('shop_id', 0); @@ -408,4 +421,19 @@ class ShopController extends BaseAuthedController { } } + public function buyGoodsDirect() { + error_log('buyGoodsDirect:' . json_encode($_REQUEST)); + $cbService = new CallBackService(); + $action = 'inappPurchase'; + $cbService->dispatch($action); + } + + public function inappPurchaseDiamonds() + { + error_log('inappPurchaseDiamonds:' . json_encode($_REQUEST)); + $cbService = new CallBackService(); + $action = 'outappPurchase'; + $cbService->dispatch($action); + } + } From 3de0044afec2771640f8c3012ac784c0ad512e45 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 14:18:59 +0800 Subject: [PATCH 32/39] 1 --- webapp/services/callback/OutAppPurchase.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/webapp/services/callback/OutAppPurchase.php b/webapp/services/callback/OutAppPurchase.php index a43aba32..63e5b045 100644 --- a/webapp/services/callback/OutAppPurchase.php +++ b/webapp/services/callback/OutAppPurchase.php @@ -141,18 +141,6 @@ class OutAppPurchase { $this->_rspOk(); } - private function getAccountId($address) - { - $row = SqlHelper::ormSelectOne( - myself()->_getMysql($address), - 't_user', - array( - 'address' => $address - ) - ); - return $row['account_id']; - } - private function _addGoods($address, $goods) { $itemService = new ShopAddItemService(); From 153c9262fe512fe3494f18f2178d954329539a71 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 15:36:11 +0800 Subject: [PATCH 33/39] 1 --- webapp/models/InAppOrder.php | 4 + webapp/models/OutAppOrder.php | 30 ++ webapp/services/callback/InAppPurchase.php | 331 +++++++++----------- webapp/services/callback/OutAppPurchase.php | 72 +++-- 4 files changed, 228 insertions(+), 209 deletions(-) diff --git a/webapp/models/InAppOrder.php b/webapp/models/InAppOrder.php index 2bc16bbc..6ed6b0ba 100644 --- a/webapp/models/InAppOrder.php +++ b/webapp/models/InAppOrder.php @@ -7,6 +7,10 @@ use phpcommon\SqlHelper; class InAppOrder extends BaseModel { + const PENDING_STATE = 0; + const FINISHED_STATE = 1; + const FAILED_STATE = 2; + public static function find($orderId) { $row = SqlHelper::ormSelectOne( myself()->_get(), diff --git a/webapp/models/OutAppOrder.php b/webapp/models/OutAppOrder.php index 063c2e21..8e02117b 100644 --- a/webapp/models/OutAppOrder.php +++ b/webapp/models/OutAppOrder.php @@ -7,4 +7,34 @@ use phpcommon\SqlHelper; class OutAppOrder extends BaseModel { + const PENDING_STATE = 0; + const FINISHED_STATE = 1; + const FAILED_STATE = 2; + + public static function find($orderId) + { + $row = SqlHelper::ormSelectOne( + myself()->_get(), + 't_outapp_order', + array( + 'order_id' => $orderId, + ) + ); + return $row; + } + + public static function markFinished($orderId) + { + SqlHelper::update( + myself()->_get(), + 't_outapp_order', + array( + 'order_id' => $orderId, + ), + array( + 'state' => self::FINISHED_STATE, + ) + ); + } + } diff --git a/webapp/services/callback/InAppPurchase.php b/webapp/services/callback/InAppPurchase.php index a4a5cbf3..5362b1e9 100644 --- a/webapp/services/callback/InAppPurchase.php +++ b/webapp/services/callback/InAppPurchase.php @@ -20,42 +20,50 @@ class InAppPurchase { public function process() { - error_log("buyGoodsDirect --- " . json_encode($_REQUEST)); + error_log('ShopInappPurchaseDiamonds:' . json_encode($_REQUEST, JSON_PRETTY_PRINT)); + error_log('----- inappPurchaseDiamonds -----'); + $body = json_decode(file_get_contents('php://input'), true); + error_log('body:' . json_encode($body)); + $channel = $body['channel']; + $records = $body['records']; + $sign = $body['sign']; - // let repdata = { - // account_id: string - // order_id: string - // status: string - // id: string - // txhash: string - // } - // 我返回给你这些数据和一个sign字段, - // sign使用上面 repdata 按key 顺序排后, 组成key1=val1&key2=val2后, 使用hmac_sha256 hash, key是 - // PENDING = 0, // 初始状态 - // TRANSFERING = 1, //只有国库模式才会有该状态 - // TRANSFERED = 2, //只有国库模式才会有该状态 - // SUCCESS = 9, // 成功的最终状态 - // TRANSFER_FAIL = 98, // 转账错误 - // FAIL = 99, // 也是错误 - // + // { + // channel: 'google', + // sign: '123456677' // 签名字段 + // records: [{ + // productId: '2999', // 从google play console获取的product id + // gameOrderId: '1231321312', // 开始支付时, 从游戏相关服务那获得的订单id + // orderId: 'GPA.3355-1172-9416-16839', // 从google develope API 获取的订单id + // status: 9, // 订单状态, 上报的订单状态一般只有2种情况, 9: 支付成功, 96: 用户退款 + // }] + // } + // let reportData: any = { + // channel: 'google', + // records, + // } + // const hashSort = '' + // const signStr = 'channel=google&' + records.map(record =>Object.keys(record).sort().map(key => `${key}=${record[key]}`).join('&')).join('&') - $account_id = getReqVal('account_id', ''); - $order_id = getReqVal('order_id', ''); - $status = getReqVal('status', ''); - $id = getReqVal('id', ''); - $txhash = getReqVal('txhash', ''); + // const sign = hmacsha256(signStr, hashSort) - $sign = getReqVal('sign', ''); + // 定义一个空数组,用来存放每个记录的键值对字符串 + $record_strings = array(); - $data = array( - 'account_id' => $account_id, - 'id' => $id, - 'order_id' => $order_id, - 'status' => $status, - 'txhash' => $txhash, - ); + // 遍历 records 数组,对每个记录进行排序和拼接 + foreach ($records as $record) { + // 对记录的键进行升序排序 + ksort($record); + // 把记录的键值对用等号连接,然后用 & 连接成一个字符串 + $record_string = http_build_query($record); + // 把字符串加入到 record_strings 数组中 + $record_strings[] = $record_string; + } - $hash_data = http_build_query($data); + // 把 record_strings 数组用 & 连接成一个字符串 + $records_string = implode("&", $record_strings); + + $hash_data = 'channel=' . $channel . '&' . $records_string; $signature = hash_hmac('sha256', $hash_data, BUY_SERVER_PKEY); @@ -64,163 +72,136 @@ class InAppPurchase { return; } - error_log("buyGoodsDirect-------" . $order_id . "---" . $status); - $conn = myself()->_getMysql(''); + // 有三种情况: + // 1. 从商城购买钻石,有订单号 + // 2. 站外充值钻石,没有订单号 + // 3. appstore 退款,没有订单号 - $order = SqlHelper::selectOne($conn, 't_shop_buy_order', array('address', 'id', 'item_id', 'goods_num', 'status'), array('order_id' => $order_id)); - if (!$order) { - $this->_rspErr(2, "order not found: {$order_id}"); - return; - } + for ($i = 0; $i < count($records); $i++) { + $record = $records[$i]; - $id = $order['id']; - $goods_num = $order['goods_num']; - $o_status = $order['status']; - $address = $order['address']; + $product_id = $record['productId']; + $order_id = $record['gameOrderId']; + $out_order_id = $record['orderId']; + $status = $record['status']; - if ($o_status != 0) { - $this->_rspErr(1, "order status error, status: {$o_status}"); - return; - } + switch ($status) { + case 9: { + $status = 1; + if (empty($order_id)) { + if (empty($product_id)) { + $this->_rspErr(2, "product_id is empty"); + return; + } - $buyStatus = 0; // 1: 成功, 2: 失败 - switch ($status) { - case "9": - $buyStatus = 1; - // 充值成功,开始首充奖励 - $this->beginFirstTupop($address); - break; - case "99": - case "98": - $buyStatus = 2; - break; - default: - error_log("buyGoodsDirect--- " . $order_id . " --- " . $status); - $this->_rspErr(1, "status error, status: {$status}"); - break; - } + // $goods = mt\ShopGoods::getByProductId($product_id); - SqlHelper::update($conn, 't_shop_buy_order', array('order_id' => $order_id), array('status' => $buyStatus)); + return; + } - if ($buyStatus == 2) { - $this->_rspErr(2, "buyStatus error, buyStatus: {$buyStatus}"); - return; - } + $order = SqlHelper::selectOne($conn, 't_web2_order', array('address', 'id', 'item_id', 'goods_num', 'status'), array('order_id' => $order_id, 'status' => 0)); + error_log('process order ' . json_encode($order)); + if (!$order) { + $this->_rspErr(3, "order not found, order_id: {$order_id}"); + return; + } - // 以下是看商品表中是否配置了充值额外奖励 - $goods = ShopGoods::get($id); - error_log("buyGoodsDirect---" . json_encode($goods)); - $goods_num = $order['goods_num']; - $bundle_size = $goods['bonus_num'] ? $goods['bonus_num'] : 0; - $item_num = $goods_num * $bundle_size; - $item_id = $goods['bonus']; - $meta = Item::get($item_id); - error_log("buyGoodsDirect---" . $item_id . "---" . $item_num . "---" . $bundle_size . "---" . $meta['name']); - if ($meta && $item_num > 0) { - // $address = $order['address']; - $account_id = $this->getAccountId($address); + SqlHelper::update($conn, 't_web2_order', array('order_id' => $order_id), array('status' => $status, 'channel' => $channel, 'out_order_id' => $out_order_id)); - if ($item_id == V_ITEM_DIAMOND) { - $event = [ - 'name' => LogService::RECHARGE_CEBG_BONUS, - 'val' => $item_num - ]; - LogService::productDiamondCallback(['account_id' => $account_id], $event); + $id = $order['id']; + $goods = ShopGoods::get($id); + // 这里命名混乱了, 购买个数,一捆个数命名冲突 + $goods_num = $order['goods_num']; + $bundle_size = $goods['goods_num']; + $item_num = $goods_num * $bundle_size; + $item_id = $goods['goods_id']; + $address = $order['address']; + if (empty($address)) { + $this->_rspErr(4, "address is empty"); + return; + } + $account_id = $this->getAccountId($address); + if (empty($account_id)) { + $this->_rspErr(5, "account_id is empty"); + return; + } + + if ($item_id == V_ITEM_DIAMOND) { + $event = [ + 'name' => LogService::RECHARGE_DIAMOND, + 'val' => $item_num + ]; + LogService::productDiamond(['account_id' => $account_id], $event); + } + + $this->_addGoods($address, array( + 'goods_id' => $item_id, + 'goods_num' => $item_num, + 'id' => $id, + )); + } + break; + case 96: + $status = 3; + if (empty($order_id)) { + if (empty($product_id)) { + $this->_rspErr(2, "product_id is empty"); + return; + } + // $goods = mt\ShopGoods::getByProductId($product_id); + + return; + } + // 退款 + $order = SqlHelper::selectOne($conn, 't_web2_order', array('address', 'id', 'item_id', 'goods_num', 'status'), array('order_id' => $order_id, 'status' => 1)); + if (!$order) { + $this->_rspErr(3, "order not found, order_id: {$order_id}"); + return; + } + SqlHelper::update($conn, 't_web2_order', array('order_id' => $order_id), array('status' => $status)); + + $id = $order['id']; + $goods = ShopGoods::get($id); + // 这里命名混乱了, 购买个数,一捆个数命名冲突 + $goods_num = $order['goods_num']; + $bundle_size = $goods['goods_num']; + $item_num = $goods_num * $bundle_size; + $item_id = $goods['goods_id']; + $address = $order['address']; + if (empty($address)) { + $this->_rspErr(4, "address is empty"); + return; + } + $account_id = $this->getAccountId($address); + if (empty($account_id)) { + $this->_rspErr(5, "account_id is empty"); + return; + } + + if ($item_id == V_ITEM_DIAMOND) { + $event = [ + 'name' => LogService::RECHARGE_DIAMOND, + 'val' => -$item_num + ]; + LogService::productDiamond(['account_id' => $account_id], $event); + } + + $this->_decGoods($address, array( + 'goods_id' => $item_id, + 'goods_num' => $item_num, + 'id' => $id, + )); + break; + default: + $status = 0; + $this->_rspErr(1, "status is not 9 or 96"); + return; + break; } - - error_log("buyGoodsDirect---" . $address . "---" . $item_id . "---" . $item_num); - - $this->_addGoods($address, array( - 'goods_id' => $item_id, - 'goods_num' => $item_num, - 'id' => $id, - )); } $this->_rspOk(); } - private function getAccountId($address) - { - $row = SqlHelper::ormSelectOne( - myself()->_getMysql($address), - 't_user', - array( - 'address' => $address - ) - ); - return $row['account_id']; - } - - private function _addGoods($address, $goods) - { - $itemService = new ShopAddItemService(); - $item_id = $goods['goods_id']; - $goods_num = $goods['goods_num']; - - $id = null; - if ($goods['id']) { - $id = $goods['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); - } - } - - private function beginFirstTupop($address) - { - $conn = myself()->_getMysql(''); - - $exist = SqlHelper::selectOne( - $conn, - 't_first_topup', - array('address'), - array('address' => $address) - ); - if ($exist) { - return; - } - - // 开始首充奖励活动进程 - $chk = SqlHelper::insert( - $conn, - 't_first_topup', - array( - 'address' => $address, - 'createtime' => myself()->_getNowTime(), - 'status1' => 0, - 'status2' => 0, - 'status3' => 0, - ) - ); - if (!$chk) { - return; - } - } - - private function _rspOk() - { - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => "callback success", - )); - } - - private function _rspErr($errcode, $errmsg) - { - if (SERVER_ENV != _ONLINE) { - error_log(json_encode(array( - 'errcode' => $errcode, - 'errmsg' => $errmsg, - ))); - } - echo json_encode(array( - 'errcode' => $errcode, - 'errmsg' => $errmsg, - )); - } } diff --git a/webapp/services/callback/OutAppPurchase.php b/webapp/services/callback/OutAppPurchase.php index 63e5b045..4b7366fc 100644 --- a/webapp/services/callback/OutAppPurchase.php +++ b/webapp/services/callback/OutAppPurchase.php @@ -4,7 +4,10 @@ namespace services; require_once("mt/ShopGoods.php"); require_once("mt/Item.php"); + require_once("models/ShopBuyRecord.php"); +require_once("models/OutAppOrder.php"); + require_once("services/LogService.php"); require_once("ShopAddItemService.php"); @@ -12,7 +15,9 @@ use phpcommon\SqlHelper; use mt\ShopGoods; use mt\Item; + use models\ShopBuyRecord; +use models\OutAppOrder; use services\LogService; @@ -29,61 +34,54 @@ class OutAppPurchase { // id: string // txhash: string // } - // 我返回给你这些数据和一个sign字段, - // sign使用上面 repdata 按key 顺序排后, 组成key1=val1&key2=val2后, 使用hmac_sha256 hash, key是 + // 我返回给你这些数据和一个sign字段, + // sign使用上面 repdata 按key 顺序排后, 组成key1=val1&key2=val2后, 使用hmac_sha256 hash, key是 // PENDING = 0, // 初始状态 // TRANSFERING = 1, //只有国库模式才会有该状态 // TRANSFERED = 2, //只有国库模式才会有该状态 // SUCCESS = 9, // 成功的最终状态 // TRANSFER_FAIL = 98, // 转账错误 // FAIL = 99, // 也是错误 - // - - $account_id = getReqVal('account_id', ''); - $order_id = getReqVal('order_id', ''); + // + if (!$this->verifySign()) { + error_log("verifySign error --- " . json_encode($_REQUEST)); + myself()->_rspErr(1, 'verifySign error'); + return; + } + $accountId = getReqVal('account_id', ''); $status = getReqVal('status', ''); $id = getReqVal('id', ''); $txhash = getReqVal('txhash', ''); - $sign = getReqVal('sign', ''); - $data = array( - 'account_id' => $account_id, - 'id' => $id, - 'order_id' => $order_id, - 'status' => $status, - 'txhash' => $txhash, - ); - - $hash_data = http_build_query($data); - - $signature = hash_hmac('sha256', $hash_data, BUY_SERVER_PKEY); - - if ($signature != $sign) { - $this->_rspErr(1, "signature error, signature: {$signature}, sign: {$sign}"); + $orderId = getReqVal('order_id', ''); + $orderDb = OutAppOrder::find($orderId); + if (!$orderDb) { + myself()->_rspErr(2, 'not found order'); + return; + } + if ($orderDb['status'] != OutAppOrder::FINISHED_STATE) { + myself()->_rspErr(0, 'order is finished'); + return; + } + OutAppOrder::markFinished($orderDb['order_id']); + $orderDb = OutAppOrder::find($orderId); + if (!$orderDb) { + myself()->_rspErr(2, 'not found order'); + return; + } + if ($orderDb['status'] == OutAppOrder::FINISHED_STATE) { + myself()->_rspErr(0, 'order is finished'); return; } - - error_log("buyGoodsDirect-------" . $order_id . "---" . $status); $conn = myself()->_getMysql(''); - $order = SqlHelper::selectOne($conn, 't_shop_buy_order', array('address', 'id', 'item_id', 'goods_num', 'status'), array('order_id' => $order_id)); - if (!$order) { - $this->_rspErr(2, "order not found: {$order_id}"); - return; - } - $id = $order['id']; $goods_num = $order['goods_num']; $o_status = $order['status']; $address = $order['address']; - if ($o_status != 0) { - $this->_rspErr(1, "order status error, status: {$o_status}"); - return; - } - $buyStatus = 0; // 1: 成功, 2: 失败 switch ($status) { case "9": @@ -190,4 +188,10 @@ class OutAppPurchase { } } + + private function verifySign() + { + + } + } From bb84a010ef0204cc945a8777eede5c7af1840313 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 15:57:25 +0800 Subject: [PATCH 34/39] 1 --- webapp/models/OutAppOrder.php | 14 +++++++ webapp/services/callback/OutAppPurchase.php | 43 +++++---------------- 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/webapp/models/OutAppOrder.php b/webapp/models/OutAppOrder.php index 8e02117b..6f632737 100644 --- a/webapp/models/OutAppOrder.php +++ b/webapp/models/OutAppOrder.php @@ -37,4 +37,18 @@ class OutAppOrder extends BaseModel { ); } + public static function markFailed($orderId) + { + SqlHelper::update( + myself()->_get(), + 't_outapp_order', + array( + 'order_id' => $orderId, + ), + array( + 'state' => self::FAILED_STATE, + ) + ); + } + } diff --git a/webapp/services/callback/OutAppPurchase.php b/webapp/services/callback/OutAppPurchase.php index 4b7366fc..18708b2d 100644 --- a/webapp/services/callback/OutAppPurchase.php +++ b/webapp/services/callback/OutAppPurchase.php @@ -21,12 +21,7 @@ use models\OutAppOrder; use services\LogService; -class OutAppPurchase { - - public function process() - { - error_log("OutAppPurchase --- " . json_encode($_REQUEST)); - +/* // let repdata = { // account_id: string // order_id: string @@ -43,6 +38,14 @@ class OutAppPurchase { // TRANSFER_FAIL = 98, // 转账错误 // FAIL = 99, // 也是错误 // +*/ + +class OutAppPurchase { + + public function process() + { + error_log("OutAppPurchase --- " . json_encode($_REQUEST)); + if (!$this->verifySign()) { error_log("verifySign error --- " . json_encode($_REQUEST)); myself()->_rspErr(1, 'verifySign error'); @@ -74,14 +77,6 @@ class OutAppPurchase { myself()->_rspErr(0, 'order is finished'); return; } - - $conn = myself()->_getMysql(''); - - $id = $order['id']; - $goods_num = $order['goods_num']; - $o_status = $order['status']; - $address = $order['address']; - $buyStatus = 0; // 1: 成功, 2: 失败 switch ($status) { case "9": @@ -99,8 +94,6 @@ class OutAppPurchase { break; } - SqlHelper::update($conn, 't_shop_buy_order', array('order_id' => $order_id), array('status' => $buyStatus)); - if ($buyStatus == 2) { $this->_rspErr(2, "buyStatus error, buyStatus: {$buyStatus}"); return; @@ -139,24 +132,6 @@ class OutAppPurchase { $this->_rspOk(); } - private function _addGoods($address, $goods) - { - $itemService = new ShopAddItemService(); - $item_id = $goods['goods_id']; - $goods_num = $goods['goods_num']; - - $id = null; - if ($goods['id']) { - $id = $goods['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); - } - } - private function beginFirstTupop($address) { $conn = myself()->_getMysql(''); From 021116eb81b6fb90911b463484d2b4c96f3ea30c Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 16:05:40 +0800 Subject: [PATCH 35/39] 1 --- webapp/services/callback/OutAppPurchase.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/webapp/services/callback/OutAppPurchase.php b/webapp/services/callback/OutAppPurchase.php index 18708b2d..315cca4b 100644 --- a/webapp/services/callback/OutAppPurchase.php +++ b/webapp/services/callback/OutAppPurchase.php @@ -56,8 +56,8 @@ class OutAppPurchase { $id = getReqVal('id', ''); $txhash = getReqVal('txhash', ''); $sign = getReqVal('sign', ''); - $orderId = getReqVal('order_id', ''); + $orderDb = OutAppOrder::find($orderId); if (!$orderDb) { myself()->_rspErr(2, 'not found order'); @@ -101,23 +101,22 @@ class OutAppPurchase { // 以下是看商品表中是否配置了充值额外奖励 $goods = ShopGoods::get($id); - error_log("buyGoodsDirect---" . json_encode($goods)); $goods_num = $order['goods_num']; $bundle_size = $goods['bonus_num'] ? $goods['bonus_num'] : 0; $item_num = $goods_num * $bundle_size; $item_id = $goods['bonus']; $meta = Item::get($item_id); - error_log("buyGoodsDirect---" . $item_id . "---" . $item_num . "---" . $bundle_size . "---" . $meta['name']); if ($meta && $item_num > 0) { - // $address = $order['address']; - $account_id = $this->getAccountId($address); - if ($item_id == V_ITEM_DIAMOND) { $event = [ 'name' => LogService::RECHARGE_CEBG_BONUS, 'val' => $item_num ]; - LogService::productDiamondCallback(['account_id' => $account_id], $event); + LogService::productDiamondCallback( + array( + 'account_id' => $orderDb['account_id'] + ), + $event); } error_log("buyGoodsDirect---" . $address . "---" . $item_id . "---" . $item_num); From 58723947abd5ab5a151d9984d44ac55778d3283f Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 16:19:57 +0800 Subject: [PATCH 36/39] 1 --- webapp/services/callback/OutAppPurchase.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webapp/services/callback/OutAppPurchase.php b/webapp/services/callback/OutAppPurchase.php index 315cca4b..073eebfb 100644 --- a/webapp/services/callback/OutAppPurchase.php +++ b/webapp/services/callback/OutAppPurchase.php @@ -100,11 +100,11 @@ class OutAppPurchase { } // 以下是看商品表中是否配置了充值额外奖励 - $goods = ShopGoods::get($id); + $goodsMeta = ShopGoods::get($id); $goods_num = $order['goods_num']; - $bundle_size = $goods['bonus_num'] ? $goods['bonus_num'] : 0; + $bundle_size = $goodsMeta['bonus_num'] ? $goodsMeta['bonus_num'] : 0; $item_num = $goods_num * $bundle_size; - $item_id = $goods['bonus']; + $item_id = $goodsMeta['bonus']; $meta = Item::get($item_id); if ($meta && $item_num > 0) { if ($item_id == V_ITEM_DIAMOND) { From 0cf89e271d9fd172ccc7f37a1d68f32c2a2b7132 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 16:21:16 +0800 Subject: [PATCH 37/39] 1 --- webapp/services/callback/OutAppPurchase.php | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/webapp/services/callback/OutAppPurchase.php b/webapp/services/callback/OutAppPurchase.php index 073eebfb..84c8f360 100644 --- a/webapp/services/callback/OutAppPurchase.php +++ b/webapp/services/callback/OutAppPurchase.php @@ -101,16 +101,16 @@ class OutAppPurchase { // 以下是看商品表中是否配置了充值额外奖励 $goodsMeta = ShopGoods::get($id); - $goods_num = $order['goods_num']; - $bundle_size = $goodsMeta['bonus_num'] ? $goodsMeta['bonus_num'] : 0; - $item_num = $goods_num * $bundle_size; - $item_id = $goodsMeta['bonus']; - $meta = Item::get($item_id); - if ($meta && $item_num > 0) { - if ($item_id == V_ITEM_DIAMOND) { + $goodsNum = $order['goods_num']; + $bundleSize = $goodsMeta['bonus_num'] ? $goodsMeta['bonus_num'] : 0; + $itemNum = $goodsNum * $bundleSize; + $itemId = $goodsMeta['bonus']; + $meta = Item::get($itemId); + if ($meta && $itemNum > 0) { + if ($itemId == V_ITEM_DIAMOND) { $event = [ 'name' => LogService::RECHARGE_CEBG_BONUS, - 'val' => $item_num + 'val' => $itemNum ]; LogService::productDiamondCallback( array( @@ -119,11 +119,11 @@ class OutAppPurchase { $event); } - error_log("buyGoodsDirect---" . $address . "---" . $item_id . "---" . $item_num); + error_log("buyGoodsDirect---" . $address . "---" . $itemId . "---" . $itemNum); $this->_addGoods($address, array( - 'goods_id' => $item_id, - 'goods_num' => $item_num, + 'goods_id' => $itemId, + 'goods_num' => $itemNum, 'id' => $id, )); } From 6634dade817b396996b386f33a7df56f84602527 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 16:23:50 +0800 Subject: [PATCH 38/39] 1 --- webapp/services/callback/OutAppPurchase.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/webapp/services/callback/OutAppPurchase.php b/webapp/services/callback/OutAppPurchase.php index 84c8f360..90792531 100644 --- a/webapp/services/callback/OutAppPurchase.php +++ b/webapp/services/callback/OutAppPurchase.php @@ -13,9 +13,6 @@ require_once("ShopAddItemService.php"); use phpcommon\SqlHelper; -use mt\ShopGoods; -use mt\Item; - use models\ShopBuyRecord; use models\OutAppOrder; @@ -100,12 +97,12 @@ class OutAppPurchase { } // 以下是看商品表中是否配置了充值额外奖励 - $goodsMeta = ShopGoods::get($id); + $goodsMeta = mt\ShopGoods::get($id); $goodsNum = $order['goods_num']; $bundleSize = $goodsMeta['bonus_num'] ? $goodsMeta['bonus_num'] : 0; $itemNum = $goodsNum * $bundleSize; $itemId = $goodsMeta['bonus']; - $meta = Item::get($itemId); + $meta = mt\Item::get($itemId); if ($meta && $itemNum > 0) { if ($itemId == V_ITEM_DIAMOND) { $event = [ From 3430f13809dee38b1db6a333e4cb9e2a483000c5 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 30 Jul 2023 17:28:42 +0800 Subject: [PATCH 39/39] 1 --- webapp/services/callback/OutAppPurchase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/services/callback/OutAppPurchase.php b/webapp/services/callback/OutAppPurchase.php index 90792531..ea6f0c94 100644 --- a/webapp/services/callback/OutAppPurchase.php +++ b/webapp/services/callback/OutAppPurchase.php @@ -97,8 +97,8 @@ class OutAppPurchase { } // 以下是看商品表中是否配置了充值额外奖励 - $goodsMeta = mt\ShopGoods::get($id); - $goodsNum = $order['goods_num']; + $goodsMeta = mt\ShopGoods::get($orderDb['goods_id']); + $goodsNum = $orderDb['goods_num']; $bundleSize = $goodsMeta['bonus_num'] ? $goodsMeta['bonus_num'] : 0; $itemNum = $goodsNum * $bundleSize; $itemId = $goodsMeta['bonus'];