欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 创投人物 > 多商户商品下单限购问题修复

多商户商品下单限购问题修复

2025/2/24 7:27:09 来源:https://blog.csdn.net/weixin_52675595/article/details/141428603  浏览:    关键词:多商户商品下单限购问题修复

问题: 当商品设置限购为 1 时,够买数量未超过限购,但是还是提示超出限购数量

修复方法:

修改代码路径:

app\common\repositories\store\order\StoreOrderCreateRepository.php
修改代码一: i s p a y s = a r r a y u n i q u e ( a r r a y c o l u m n ( is_pays = array_unique(array_column( ispays=arrayunique(arraycolumn(merchantCart[‘list’],‘is_pay’));
if ( count($is_pays) > 1 || $is_pays[0] == 1) throw new ValidateException(‘存在已购买商品请重新添加购物车’);
// 获取每个商品的ID数组
p r o d u c t i d s = a r r a y c o l u m n ( product_ids = array_column( productids=arraycolumn(merchantCart[‘list’],‘product_id’);
n u m d a t a = a r r a y c o l u m n ( num_data = array_column( numdata=arraycolumn(merchantCart[‘list’],‘cart_num’);
i d n u m = [ ] ; / / 获取每个商品 I D 出现的次数及购买数量,作为验证限购数量使用 f o r e a c h ( id_num = []; // 获取每个商品ID出现的次数及购买数量,作为验证限购数量使用 foreach ( idnum=[];//获取每个商品ID出现的次数及购买数量,作为验证限购数量使用foreach(product_ids as $key => $value) {
i d n u m [ id_num[ idnum[value] = isset( i d n u m [ id_num[ idnum[value]) ? i d n u m [ id_num[ idnum[value] + n u m d a t a [ num_data[ numdata[key] : n u m d a t a [ num_data[ numdata[key];
}
c o u n t L i s t = c o u n t ( countList = count( countList=count(merchantCart[‘list’]);
修改后的样子:在这里插入图片描述
修改代码二:

$count = i d n u m [ id_num[ idnum[cart[‘product_id’]];
if (($count) > $cart[‘product’][‘once_max_count’]) {
throw new ValidateException(‘[超出限购总数:’ . c a r t [ ′ p r o d u c t ′ ] [ ′ o n c e m a x c o u n t ′ ] . ′ ] ′ . m b s u b s t r ( cart['product']['once_max_count'] . ']' . mb_substr( cart[product][oncemaxcount].].mbsubstr(cart[‘product’][‘store_name’], 0, 10) . ‘…’);
}
$pay_count = s t o r e O r d e r R e p o s i t o r y − > g e t M a x C o u n t N u m b e r ( storeOrderRepository->getMaxCountNumber( storeOrderRepository>getMaxCountNumber(cart[‘uid’], c a r t [ ′ p r o d u c t i d ′ ] ) ; i f ( ( cart['product_id']); if (( cart[productid]);if((count + $pay_count) > $cart[‘product’][‘once_max_count’]) {
throw new ValidateException(‘[超出限购总数:’ . c a r t [ ′ p r o d u c t ′ ] [ ′ o n c e m a x c o u n t ′ ] . ′ ] ′ . m b s u b s t r ( cart['product']['once_max_count'] . ']' . mb_substr( cart[product][oncemaxcount].].mbsubstr(cart[‘product’][‘store_name’], 0, 10) . ‘…’);
}
修改后的样子:在这里插入图片描述
最后:修改完了需要重启swoole服务

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词