全部
常见问题
产品动态
精选推荐

购物车中商品较多直接全选下单,商品没有全部下单问题

管理 管理 编辑 删除
1、路径:app\controller\api\v1\store\StoreCartController.php 方法: count();更改如下:public function count(Request $request)

{

[$numType] = $request->postMore([

['numType', true],//购物车编号

], true);

$uid = (int)$request->uid();

return app('json')->success('ok', $this->services->getUserCartCount($uid, $numType));

}

2、路径:app\services\order\StoreCartServices.php 增加如下方法:

/**

* 获取用户购物车数量 ids 统计金额

* @param int $uid

* @param string $numType

* @throws \think\db\exception\DataNotFoundException

* @throws \think\db\exception\DbException

* @throws \think\db\exception\ModelNotFoundException

*/

public function getUserCartCount(int $uid, string $numType)

{

$count = 0;

$ids = [];

$sum_price = 0;

$cartList = $this->dao->getUserCartList($uid, 'product', '*', ['productInfo', 'attrInfo']);

if ($cartList) {

/** @var StoreProductServices $productServices */

$productServices = app()->make(StoreProductServices::class);

/** @var MemberCardServices $memberCardService */

$memberCardService = app()->make(MemberCardServices::class);

$vipStatus = $memberCardService->isOpenMemberCard('vip_price');

/** @var UserServices $user */

$user = app()->make(UserServices::class);

$userInfo = $user->getUserInfo($uid);

/** @var SystemUserLevelServices $systemLevel */

$systemLevel = app()->make(SystemUserLevelServices::class);

$discount = $systemLevel->value(['id' => $userInfo['level'], 'is_del' => 0, 'is_show' => 1], 'discount') ?: null;

foreach ($cartList as &$item) {

$productInfo = $item['productInfo'];

if (isset($productInfo['attrInfo']['product_id']) && $item['product_attr_unique']) {

$item['truePrice'] = $productServices->setLevelPrice($productInfo['attrInfo']['price'] ?? 0, $uid, $userInfo, $vipStatus, true, $discount, $item['attrInfo']['vip_price'] ?? 0, $productInfo['is_vip'] ?? 0, true);

} else {

$item['truePrice'] = $productServices->setLevelPrice($item['productInfo']['price'] ?? 0, $uid, $userInfo, $vipStatus, true, $discount, $item['attrInfo']['vip_price'] ?? 0, $item['productInfo']['is_vip'] ?? 0);

}

$sum_price = bcadd((string)$sum_price, (string)bcmul((string)$item['cart_num'], (string)$item['truePrice'], 4), 2);

}

$ids = array_column($cartList, 'id');

if ($numType) {

$count = count($cartList);

} else {

$count = array_sum(array_column($cartList, 'cart_num'));

}

}

return compact('count', 'ids', 'sum_price');

}

3:路径:app\dao\order\StoreCartDao.php 增加如下方法:

/**

* 用户购物车统计数据

* @param $uid

* @param $type

* @param string $field

* @param array $with

* @return array

* @throws \think\db\exception\DataNotFoundException

* @throws \think\db\exception\DbException

* @throws \think\db\exception\ModelNotFoundException

*/

public function getUserCartList($uid, $type, string $field = '*', array $with = [])

{

return $this->getModel()->where(['uid' => $uid, 'type' => $type, 'is_pay' => 0, 'is_new' => 0, 'is_del' => 0])->when(count($with), function ($query) use ($with) {

$query->with($with);

})->order('add_time DESC')->field($field)->select()->toArray();

}

4:前端uni-app代码;

(1) 包中位置:view/uni-app 直接下载附件解压覆盖

(2)或者解压附件找到order_addcart.vue与路径 pages/order_addcart/order_addcart.vue 比较合并

5:前端需要重新打包H5放入public/下

附件:

附件

下载文件

请登录后查看

CRMEB官方 最后编辑于2022-06-21 22:32:09

快捷回复
回复({{post_count}}) {{!is_user ? '我的回复' :'全部回复'}}
回复从新到旧

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}}

作者 管理员 企业

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest==1? '取消推荐': '推荐'}}
{{item.floor}}#
{{item.user_info.title}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
{{item.like_count}}
{{item.showReply ? '取消回复' : '回复'}}
删除
回复
回复

{{itemc.user_info.nickname}}

{{itemc.user_name}}

作者 管理员 企业

回复 {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}   {{itemc.ip_address}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回复' : '回复'}}
删除
回复
回复
查看更多
回复
回复
1656
{{like_count}}
{{collect_count}}
添加回复 ({{post_count}})

相关推荐

CRMEB官方 作者
暂无简介

回答

0

发布

0

经验

0

快速安全登录

使用微信扫码登录
{{item.label}} {{item.label}} {{item.label}} 板块推荐 常见问题 产品动态 精选推荐 首页头条 首页动态 首页推荐
加精
取 消 确 定
回复
回复
问题:
问题自动获取的帖子内容,不准确时需要手动修改. [获取答案]
答案:
提交
bug 需求 取 消 确 定

微信登录/注册

切换手机号登录

{{ bind_phone ? '绑定手机' : '手机登录'}}

{{codeText}}
切换微信登录/注册
暂不绑定
CRMEB客服

CRMEB咨询热线 咨询热线

400-8888-794

微信扫码咨询

CRMEB开源商城下载 开源下载 CRMEB官方论坛 帮助文档
返回顶部 返回顶部
CRMEB客服