request->userId; if (!$userId) return []; $where = [ 'uid' => $userId, 'is_pay' => 0 ]; $list = Cart::where($this->searchWhere)->where($where) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) { return $item; }) ->toArray(); $off_activity = Config::where('name', 'off_activity')->value('value'); $this->off_activity=$off_activity; $user = User::where('id', $userId)->find(); foreach ($list as $key => &$item) { $find = StoreBranchProduct::where(['product_id' => $item['product_id'], 'store_id' => $item['store_id']]) ->field('product_id,image,price,cost,store_name,unit,delete_time,vip_price') ->withTrashed() ->find(); if ($find) { if($off_activity==1){ $this->activity_price = bcadd(bcmul($find['cost'],$item['cart_num'], 2), $this->activity_price, 2); }else{ if ($user && $user['user_ship'] == 1) { //更新 会员为1的时候原价减去会员价 $deduction_price_count = bcmul(bcsub($find['price'], $find['vip_price'], 2), $item['cart_num'], 2); $this->activity_price = bcadd($this->activity_price, $deduction_price_count, 2); } elseif ($user && $user['user_ship'] == 4) { //更新 为4商户的时候减去商户价格 $deduction_price_count = bcmul(bcsub($find['price'], $find['cost'], 2), $item['cart_num'], 2); $this->activity_price = bcadd($this->activity_price, $deduction_price_count, 2); } else { $this->activity_price = 0; } } $item['goods_total_price'] = bcmul($item['cart_num'], $find['price'], 2); $this->total_price = bcadd($this->total_price, $item['goods_total_price'], 2); $item['imgs'] = $find['image']; $item['sell'] = $find['price']; $item['goods_name'] = $find['store_name']; $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); } } return $list; } /** * @notes 购物车数量 * @return int * @date 2024/04/27 11:26 */ public function count(): int { $userId = $this->request->userId; if (!$userId) return 0; $where = [ 'uid' => $userId, 'is_pay' => 0 ]; return Cart::where($this->searchWhere)->where($where)->count(); } public function extend() { $data= [ 'off_activity' => $this->off_activity, 'total_price' => $this->total_price, 'msg' => '', 'pay_price' => bcsub($this->total_price, $this->activity_price, 2) ]; if($this->off_activity==1){ $data['pay_price']=$this->activity_price; if($this->total_price<500){ $data['msg']='还差'.bcsub(500,$this->total_price,2).'元可获得10%品牌礼品券'; $data['pay_price']= $this->activity_price; } } return $data; } }