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/下
附件:
{{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}}