作者 何书鹏
1 个管道 的构建 通过 耗费 2 秒

购物车选中

... ... @@ -217,19 +217,21 @@ class Cart extends Api
*/
public function select($cart_ids)
{
$list = $this->model
->where('user_id',$this->user['id'])
$where = [
'user_id' => $this->user['id'],
'isbuynow' => '0'
];
// 传过来的选中
$this->model
->where($where)
->where('id','in',$cart_ids)
->select();
$total_num = 0;
$total_price = 0;
foreach ($list as $key => $cart) {
// 商品总数
$total_num += $cart['goods_num'];
// 商品总价
$total_price += bcmul($cart['goods_price'], $cart['goods_num'], 2);
}
$this->success(__('成功'),compact('total_num','total_price'));
->update(['isselected'=>'1']);
// 未传过来的取消选中
$this->model
->where($where)
->where('id','notin',$cart_ids)
->update(['isselected'=>'0']);
$this->success(__('成功'));
}
/**
... ...
... ... @@ -194,12 +194,16 @@ class Cart extends Model
if ($goods['ismake'] == '0' && $cart['goods_num'] > $cart['goods_sku']['stock_num']) {
$this->setError('很抱歉,商品 [' . $goods['goods_name'] . '] 库存不足');
}
// 商品总数
$total_num += $cart['goods_num'];
// 商品总价
$total_price += $cart['goods_total_price'] = bcmul($cart['goods_price'], $cart['goods_num'], 2);
// 商品总重量
$total_goods_weight += bcmul($cart['goods_sku']['goods_weight'], $cart['goods_num'], 2);
$cart['goods_total_price'] = bcmul($cart['goods_price'], $cart['goods_num'], 2);
// 只计算选中商品
if($cart['isselected'] == '1'){
// 商品总数
$total_num += $cart['goods_num'];
// 商品总价
$total_price += $cart['goods_total_price'];
// 商品总重量
$total_goods_weight += bcmul($cart['goods_sku']['goods_weight'], $cart['goods_num'], 2);
}
// 显示商品信息
$cart->goods->visible(['goods_name','goods_image','category_ids','spec_type']);
// 显示用户尺寸信息
... ... @@ -218,7 +222,8 @@ class Cart extends Model
'goods_num',
'make_type',
'goods',
'user_size'
'user_size',
'isselected'
])->append([
'goods_total_price',
'goods_sku'
... ... @@ -236,7 +241,7 @@ class Cart extends Model
krsort($express);
$express_price = 0;
foreach($express as $k => $v){
if($total_goods_weight >= $k){
if($total_goods_weight > $k){
$express_price = $v;
break;
}
... ... @@ -305,7 +310,9 @@ class Cart extends Model
public function orderCouponList($user,$cart_list){
$new_cart_list = [];
foreach ($cart_list as $key => $value) {
$new_cart_list[$value['goods_id']][] = $value;
if($value['isselected'] == '1'){
$new_cart_list[$value['goods_id']][] = $value;
}
}
$coupon_id_arr = [];
$tree = Tree::instance()->init(collection(Category::order('weigh desc,id desc')->select())->toArray(), 'pid');
... ...