diff --git a/doc/_common.py b/doc/_common.py index e1d3586f..c65f6a64 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -1943,6 +1943,6 @@ class HashRateGoods(object): ['item_id', 0, '道具id'], ['item_num', 0, '道具数量'], ['purchased_num', 0, '已购买数量'], - ['stock_num', 0, '库存数量(-1不限购)'], + ['max_num', 0, '最大数量(-1不限购)'], ['count_down', 0, '倒计时(单位秒,只有已售罄才有效)'], ] diff --git a/webapp/controller/HashRateShopController.class.php b/webapp/controller/HashRateShopController.class.php index 9a32f0da..1b09a9cc 100644 --- a/webapp/controller/HashRateShopController.class.php +++ b/webapp/controller/HashRateShopController.class.php @@ -2,6 +2,7 @@ require_once('services/HashRateShopService.php'); require_once('mt/HashRateShop.php'); +require_once('mt/Item.php'); use mt; use phpcommon\SqlHelper; @@ -40,10 +41,6 @@ class HashRateShop extends BaseAuthedController { myself()->_rspErr(1, 'no right to purchase'); return; } - if ($goodsNum > $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) { myself()->_rspErr(1, 'goods not found, goods_id: ' . $goodsMeta['goods_id']); @@ -51,7 +48,7 @@ class HashRateShop extends BaseAuthedController { } $errCode = 0; $errMsg = ''; - if (!ShopService::buyLimitCheck($goodsMeta, $errCode, $errMsg)) { + if (!HashRateShopService::buyLimitCheck($goodsMeta, $goodsNum, $errCode, $errMsg)) { myself()->_rspErr($errCode, $errMsg); return; } diff --git a/webapp/services/HashRateShopService.php b/webapp/services/HashRateShopService.php index 94dfb32e..97fdf8bd 100644 --- a/webapp/services/HashRateShopService.php +++ b/webapp/services/HashRateShopService.php @@ -56,7 +56,7 @@ class HashRateShopService { return $goodsList; } - public static function buyLimitCheck($goodsMeta, &$errCode, &$errMsg) + public static function buyLimitCheck($goodsMeta, $goodsNum, &$errCode, &$errMsg) { $errCode = 0; $errMsg = ''; @@ -67,37 +67,47 @@ class HashRateShopService { switch ($goodsMeta['limit_type']) { case mt\HashRateShop::DAILY_BUY_LIMIT: { $buyRecord = getXVal($buyRecordHash, $goodsId); - $boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1 : 1; + $boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + $goodsNum : 1; if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $goodsMeta['limit_num']) { $errCode = 2; $errMsg = 'Daily purchase limit'; return false; } } - break; + break; case mt\HashRateShop::WEEKLY_BUY_LIMIT: { $buyRecord = getXVal($buyRecordHash, $goodsId); - $boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1; + $boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + $goodsNum : 1; if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $goodsMeta['limit_num']) { $errCode = 2; $errMsg = 'Weekly purchase limit reached'; return false; } } - break; + break; + case mt\HashRateShop::MONTH_BUY_LIMIT: { + $buyRecord = getXVal($buyRecordHash, $goodsId); + $boughtTimes = $buyRecord ? $buyRecord['this_month_buy_times'] + $goodsNum : 1; + if ($buyRecord && getXVal($buyRecord, 'this_month_buy_times', 0) >= $goodsMeta['limit_num']) { + $errCode = 2; + $errMsg = 'month purchase limit reached'; + return false; + } + } + break; case mt\HashRateShop::TOTAL_BUY_LIMIT: { $buyRecord = getXVal($buyRecordHash, $goodsId); - $boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1; + $boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + $goodsNum : 1; if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $goodsMeta['limit_num']) { $errCode = 2; $errMsg = 'Purchase limit reached'; return false; } } - break; + break; default: { } - break; + break; } } return true;