1、文件:app/services/order/StoreCartServices.php
方法:
checkLimit
2、復制代碼段,到后面截圖部位
/** @var StoreOrderCartInfoServices $orderCartServices */
$orderCartServices = app()->make(StoreOrderCartInfoServices::class);
/** @var StoreOrderServices $storeOrderServices */
$storeOrderServices = app()->make(StoreOrderServices::class);
//取消購買限購數量
$orderDelNum = $storeOrderServices->search(['paid' => 0, 'is_del' => 1])->column('id');
//購買數量
$orderPayNum = $orderCartServices->search(['uid' => $uid, 'product_id' => $product_id])
->when($orderDelNum, function ($query) use ($orderDelNum) {
$query->whereNotIn('oid', $orderDelNum);
})->sum('cart_num');
//退款數量
$orderRefundNum = $orderCartServices->sum(['uid' => $uid, 'product_id' => $product_ids], 'refund_num');
$orderNum = $cartNum + $orderPayNum - $orderRefundNum;
if (($num + $orderNum) > $limitInfo['limit_num']) {
throw new ValidateException('該商品限購 ' . $limitInfo['limit_num'] . ' 件,您已經購買 ' . $orderNum . ' 件');
}
3、文件:app/dao/order/StoreOrderCartInfoDao.php
4、復制代碼段,到下圖截圖部位
public function search(array $where = [])
{
return parent::search($where);
}
5、重啟swoole,重新設置限制在此購買測試