post(); $pageSize = request()->post('pageSize', 12); $params['user_id'] = $this->userId; $datas = CartService::make()->getDataList($params, $pageSize); return message(1010, true, $datas); } /** * 添加购物车 */ public function add() { $params = request()->all(); $id = isset($params['id']) ? intval($params['id']) : 0; $skuId = isset($params['sku_id']) ? intval($params['sku_id']) : 0; $num = isset($params['num']) && $params['num']? intval($params['num']) : 1; if (empty($id)) { return message(1036, false); } try { if ($result = CartService::make()->add($this->userId, $id, $skuId, $num)) { return message(CartService::make()->getError(), true, $result); } else { return message(CartService::make()->getError(), false); } } catch (\Exception $exception) { $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()]; return showJson(1046, false, $error); } } /** * 更新购物车 */ public function update() { $params = request()->all(); $id = isset($params['id']) ? intval($params['id']) : 0; if (empty($id)) { return message(1036, false); } try { if ($result = CartService::make()->update($this->userId, $id)) { return message(CartService::make()->getError(), true, $result); } else { return message(CartService::make()->getError(), false); } } catch (\Exception $exception) { $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()]; return showJson(1046, false, $error); } } /** * 删除购物车 */ public function delete() { $params = request()->all(); $ids = isset($params['ids']) && $params['ids']? $params['ids'] : []; try { if ($result = CartService::make()->deleteCart($this->userId, $ids)) { return message(CartService::make()->getError(), true, $result); } else { return message(CartService::make()->getError(), false); } } catch (\Exception $exception) { $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()]; return showJson(1046, false, $error); } } /** * 购物车数量 */ public function count() { try { if ($result = CartService::make()->getCount($this->userId)) { return message(1010, true, [ 'count'=>$result, 'social_open'=> ConfigService::make()->getConfigByCode('social_open', 0), ]); } else { return message(1009, false); } } catch (\Exception $exception) { $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()]; return showJson(1046, false, $error); } } }