find($goodsId); $goodsCheck = $this->goodsActivityService->check($goods,$num,$userId); }else{ $builder = Goods::query(); $goodsType = Goods::class; $goods = $builder->find($goodsId); $goodsCheck = $this->goodsService->check($goods,$num); } if(empty($goods)){ throw new ErrorCodeException(ErrorCode::GOODS_NOT_EXISTS); } if($goodsCheck !== true) { throw new ErrorCodeException($goodsCheck); } return ShoppingCart::query()->updateOrCreate( [ 'user_id' => $userId, 'goods_id' => $goodsId, 'activity_type' => $activityType ], [ 'market_id' => $goods->market_id, 'store_id' => $goods->store_id, 'num' => $num, 'goods_type' => $goodsType ] ); } public function check() { // TODO: Implement check() method. } public function undo($shopcartIds) { $shopcartIdsArr = explode(',',$shopcartIds); return ShoppingCart::destroy($shopcartIdsArr); } /** * 清空购物车 * @param $userId * @param $marketId */ public function doClear($userId, $marketId) { return ShoppingCart::query()->where([ ['user_id','=',$userId], ['market_id','=',$marketId], ]) ->delete(); } }