where([ ['user_id','=',$userId], ['market_id','=',$marketId], ])->pluck('store_id')->toArray(); $stores = Store::query()->with(['ShoppingCart' => function($query) use ($userId,$marketId){ $query->where([ ['user_id','=',$userId], ['market_id','=',$marketId], ]); }])->whereIn('id',$storeIds) ->get() ->toArray(); $storeArr = []; foreach ($stores as $key => &$store){ $sotreType = $this->storeService->check($store['id']); if(!$sotreType){ continue; } $subtotal = 0; foreach ($store['shopping_cart'] as $k => &$shopcart){ if($shopcart['activity_type'] == 1){ $goodsType = $this->goodsService->check($shopcart['goods_id']); }else{ $goodsType = $this->goodsActivityService->check($shopcart['goods_id'],$shopcart['num'],$shopcart['user_id']); } if($goodsType !== true){ unset($store['shopping_cart'][$k]); continue; } if($shopcart['activity_type'] == 1){ $builder = Goods::query(); }else{ $builder = GoodsActivity::query(); } $shopcart['goods'] = $builder->where('id',$shopcart['goods_id'])->first()->toArray(); $subtotal+= $shopcart['num'] * $shopcart['goods']['price']; } $store['subtotal'] = $subtotal; $storeArr[] = $store; } return $storeArr; } public function check($goodsId) { return mt_rand(0,6); } public function undo($userId,$marketId) { $storeIds = Db::table('lanzu_shopping_cart')->where([ ['user_id','=',$userId], ['market_id','=',$marketId], ])->pluck('store_id')->toArray(); $stores = Store::query()->with(['ShoppingCart' => function($query) use ($userId,$marketId){ $query->where([ ['user_id','=',$userId], ['market_id','=',$marketId], ]); }])->whereIn('id',$storeIds) ->get() ->toArray(); $storeArr = []; foreach ($stores as $key => &$store){ $addStore = false; $sotreType = $this->storeService->check($store['id']); if(!$sotreType){ $addStore = true; } foreach ($store['shopping_cart'] as $k => &$shopcart){ if($shopcart['activity_type'] == 1){ $goodsType = $this->goodsService->check($shopcart['goods_id']); }else{ $goodsType = $this->goodsActivityService->check($shopcart['goods_id'],$shopcart['num'],$shopcart['user_id']); } if($goodsType === true){ unset($store['shopping_cart'][$k]); continue; } $addStore = true; if($shopcart['activity_type'] == 1){ $builder = Goods::query(); }else{ $builder = GoodsActivity::query(); } $shopcart['goods'] = $builder->where('id',$shopcart['goods_id'])->first()->toArray(); $shopcart['goods']['invalid_cause'] = $goodsType; } if($addStore){ $storeArr[] = $store; } } return $storeArr; } public function countGoods($userId,$marketId) { return mt_rand(1,100); } public function getTotal($userId,$marketId) { $randomFloat = rand(100,999)/100; return $randomFloat; } public function getGoodsByShopcartId($shopcartIds) { $shopcartIds = explode(',',$shopcartIds); $storeIds = Db::table('lanzu_shopping_cart') ->whereIn('id',$shopcartIds) ->pluck('store_id') ->toArray(); $stores = Store::query()->with(['ShoppingCart' => function($query) use ($shopcartIds){ $query->whereIn('id',$shopcartIds); }])->whereIn('id',$storeIds) ->get() ->toArray(); $storeArr = []; foreach ($stores as $key => &$store){ $sotreType = $this->storeService->check($store['id']); if(!$sotreType){ continue; } $subtotal = 0; foreach ($store['shopping_cart'] as $k => &$shopcart){ if($shopcart['activity_type'] == 1){ $goodsType = $this->goodsService->check($shopcart['goods_id']); }else{ $goodsType = $this->goodsActivityService->check($shopcart['goods_id'],$shopcart['num'],$shopcart['user_id']); } if($goodsType !== true){ unset($store['shopping_cart'][$k]); continue; } if($shopcart['activity_type'] == 1){ $builder = Goods::query(); }else{ $builder = GoodsActivity::query(); } $shopcart['goods'] = $builder->where('id',$shopcart['goods_id'])->first()->toArray(); $subtotal+= $shopcart['num'] * $shopcart['goods']['price']; } $store['subtotal'] = $subtotal; $storeArr[] = $store; } return $storeArr; } }