From d2069c3e7654a62ee06371bb7f8fd9e085b5c771 Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 29 Jul 2023 18:47:06 +0800 Subject: [PATCH] 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( );