|
|
|
@ -138,4 +138,47 @@ class ShopCartService implements ShopCartServiceInterface |
|
|
|
$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; |
|
|
|
} |
|
|
|
} |