request->userId; if (!$userId) return []; $list = Cart::where($this->searchWhere)->where('uid', $userId) ->limit($this->limitOffset, $this->limitLength) ->order(['cart_id' => 'desc']) ->select()->each(function ($item) { return $item; }) ->toArray(); $total_price = 0; foreach ($list as $key => &$item) { $sell = Goods::where('id', $item['goods_id'])->value('sell'); $item['goods_total_price'] = bcmul($item['cart_num'], $sell, 2); $total_price += $item['goods_total_price']; } $this->total_price=$total_price; return $list; } /** * @notes 购物车数量 * @return int * @date 2024/04/27 11:26 */ public function count(): int { return Cart::where($this->searchWhere)->count(); } public function extend() { return ['total_price'=>$this->total_price]; } }