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(); // $check = DictType::where('type', 'activities')->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') ->withTrashed() ->find(); // if (isset($check) && $check['status'] == 1) { // $find['price'] = $find['cost']; // } if ($find) { $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() { return ['total_price' => $this->total_price]; } }