id)->orderByDesc("id")->paginate($params['page_size']); return [ "total" => $p->total(), "page_total" => $p->lastPage(), "list" => array_map(function (Cart $model) { return [ "id" => $model->id, "sn" => $model->sn, "name" => $model->goods->name, "en_name" => $model->goods->en_name, "thumb" => $model->thumb, "count" => $model->count, "custom" => $model->custom, ]; }, $p->items()), ]; } public function add(User $user, $params): Cart { $gid = $params['id']; $goods = Goods::findOrFail($gid); $cart = new Cart(); $cart->user_id = $user->id; $cart->goods_id = $goods->id; $cart->count = $params['count']; $cart->extra = [ "goods_name" => $goods->name, "goods_en_name" => $goods->en_name, "thumb" => $goods->thumb, "sn" => $goods->sn, "custom" => $params['custom'], ]; $cart->save(); return $cart; } public function update(User $user, $params) { $cart = Cart::where("id", $params['id'])->where("user_id", $user->id)->firstOrFail(); if ($params['count']) { $cart->count = $params['count']; $cart->save(); } else { $cart->delete(); } return $cart; } public function ask(User $user, $params) { $params['source'] = Order::SOURCE_CART; return app(OrderService::class)->askByCart($user, $params); } }