This commit is contained in:
aozhiwei 2024-10-10 16:12:22 +08:00
parent c936760e31
commit 0a4b16c84e
3 changed files with 21 additions and 14 deletions

View File

@ -1943,6 +1943,6 @@ class HashRateGoods(object):
['item_id', 0, '道具id'], ['item_id', 0, '道具id'],
['item_num', 0, '道具数量'], ['item_num', 0, '道具数量'],
['purchased_num', 0, '已购买数量'], ['purchased_num', 0, '已购买数量'],
['stock_num', 0, '库存数量(-1不限购)'], ['max_num', 0, '最大数量(-1不限购)'],
['count_down', 0, '倒计时(单位秒,只有已售罄才有效)'], ['count_down', 0, '倒计时(单位秒,只有已售罄才有效)'],
] ]

View File

@ -2,6 +2,7 @@
require_once('services/HashRateShopService.php'); require_once('services/HashRateShopService.php');
require_once('mt/HashRateShop.php'); require_once('mt/HashRateShop.php');
require_once('mt/Item.php');
use mt; use mt;
use phpcommon\SqlHelper; use phpcommon\SqlHelper;
@ -40,10 +41,6 @@ class HashRateShop extends BaseAuthedController {
myself()->_rspErr(1, 'no right to purchase'); myself()->_rspErr(1, 'no right to purchase');
return; 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']); $itemMeta = mt\Item::get($goodsMeta['item_id']);
if (!$itemMeta) { if (!$itemMeta) {
myself()->_rspErr(1, 'goods not found, goods_id: ' . $goodsMeta['goods_id']); myself()->_rspErr(1, 'goods not found, goods_id: ' . $goodsMeta['goods_id']);
@ -51,7 +48,7 @@ class HashRateShop extends BaseAuthedController {
} }
$errCode = 0; $errCode = 0;
$errMsg = ''; $errMsg = '';
if (!ShopService::buyLimitCheck($goodsMeta, $errCode, $errMsg)) { if (!HashRateShopService::buyLimitCheck($goodsMeta, $goodsNum, $errCode, $errMsg)) {
myself()->_rspErr($errCode, $errMsg); myself()->_rspErr($errCode, $errMsg);
return; return;
} }

View File

@ -56,7 +56,7 @@ class HashRateShopService {
return $goodsList; return $goodsList;
} }
public static function buyLimitCheck($goodsMeta, &$errCode, &$errMsg) public static function buyLimitCheck($goodsMeta, $goodsNum, &$errCode, &$errMsg)
{ {
$errCode = 0; $errCode = 0;
$errMsg = ''; $errMsg = '';
@ -67,37 +67,47 @@ class HashRateShopService {
switch ($goodsMeta['limit_type']) { switch ($goodsMeta['limit_type']) {
case mt\HashRateShop::DAILY_BUY_LIMIT: { case mt\HashRateShop::DAILY_BUY_LIMIT: {
$buyRecord = getXVal($buyRecordHash, $goodsId); $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']) { if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $goodsMeta['limit_num']) {
$errCode = 2; $errCode = 2;
$errMsg = 'Daily purchase limit'; $errMsg = 'Daily purchase limit';
return false; return false;
} }
} }
break; break;
case mt\HashRateShop::WEEKLY_BUY_LIMIT: { case mt\HashRateShop::WEEKLY_BUY_LIMIT: {
$buyRecord = getXVal($buyRecordHash, $goodsId); $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']) { if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $goodsMeta['limit_num']) {
$errCode = 2; $errCode = 2;
$errMsg = 'Weekly purchase limit reached'; $errMsg = 'Weekly purchase limit reached';
return false; 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: { case mt\HashRateShop::TOTAL_BUY_LIMIT: {
$buyRecord = getXVal($buyRecordHash, $goodsId); $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']) { if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $goodsMeta['limit_num']) {
$errCode = 2; $errCode = 2;
$errMsg = 'Purchase limit reached'; $errMsg = 'Purchase limit reached';
return false; return false;
} }
} }
break; break;
default: { default: {
} }
break; break;
} }
} }
return true; return true;