問題: 當(dāng)商品設(shè)置限購為 1 時(shí),夠買數(shù)量未超過限購,但是還是提示超出限購數(shù)量
修復(fù)方法:
修改代碼路徑:
app\common\repositories\store\order\StoreOrderCreateRepository.php
修改代碼一:
$is_pays = array_unique(array_column($merchantCart['list'],'is_pay'));
if ( count($is_pays) > 1 || $is_pays[0] == 1) throw new ValidateException('存在已購買商品請重新添加購物車');
// 獲取每個(gè)商品的ID數(shù)組
$product_ids = array_column($merchantCart['list'],'product_id');
$num_data = array_column($merchantCart['list'],'cart_num');
$id_num = [];
// 獲取每個(gè)商品ID出現(xiàn)的次數(shù)及購買數(shù)量,作為驗(yàn)證限購數(shù)量使用
foreach ($product_ids as $key => $value) {
$id_num[$value] = isset($id_num[$value]) ? $id_num[$value] + $num_data[$key] : $num_data[$key];
}
$countList = count($merchantCart['list']);
修改后的樣子:
修改代碼二:
$count = $id_num[$cart['product_id']];
if (($count) > $cart['product']['once_max_count']) {
throw new ValidateException('[超出限購總數(shù):' . $cart['product']['once_max_count'] . ']' . mb_substr($cart['product']['store_name'], 0, 10) . '...');
}
$pay_count = $storeOrderRepository->getMaxCountNumber($cart['uid'], $cart['product_id']);
if (($count + $pay_count) > $cart['product']['once_max_count']) {
throw new ValidateException('[超出限購總數(shù):' . $cart['product']['once_max_count'] . ']' . mb_substr($cart['product']['store_name'], 0, 10) . '...');
}
修改后的樣子:
最后:修改完了需要重啟swoole服務(wù)