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,重新设置限制在此购买测试
{{item.user_info.nickname ? item.user_info.nickname : item.user_name}}
作者 管理员 企业
{{itemf.name}}
{{itemc.user_info.nickname}}
{{itemc.user_name}}
回复 {{itemc.comment_user_info.nickname}}
{{itemf.name}}