|
|
|
@ -76,9 +76,15 @@ class ShopCartService implements ShopCartServiceInterface |
|
|
|
return $storeArr; |
|
|
|
} |
|
|
|
|
|
|
|
public function check($goodsId) |
|
|
|
public function check($userId,$goodsId) |
|
|
|
{ |
|
|
|
return mt_rand(0,6); |
|
|
|
$ShoppingCart = ShoppingCart::query()->where([ |
|
|
|
['user_id','=',$userId], |
|
|
|
['goods_id','=',$goodsId], |
|
|
|
]) |
|
|
|
->select('num') |
|
|
|
->get(); |
|
|
|
return $ShoppingCart->num; |
|
|
|
} |
|
|
|
|
|
|
|
public function undo($userId,$marketId) |
|
|
|
@ -130,13 +136,47 @@ class ShopCartService implements ShopCartServiceInterface |
|
|
|
|
|
|
|
public function countGoods($userId,$marketId) |
|
|
|
{ |
|
|
|
return mt_rand(1,100); |
|
|
|
$ShoppingCart = ShoppingCart::query()->where([ |
|
|
|
['user_id','=',$userId], |
|
|
|
['market_id','=',$marketId], |
|
|
|
])->get(); |
|
|
|
$num = 0; |
|
|
|
foreach ($ShoppingCart as $cart){ |
|
|
|
if($cart->activity_type == 2){ |
|
|
|
$goods = GoodsActivity::query()->find($cart->goods_id); |
|
|
|
$goodsCheck = $this->goodsActivityService->check($goods,$cart->num,$cart->user_id); |
|
|
|
}else{ |
|
|
|
$goods = Goods::query()->find($cart->goods_id); |
|
|
|
$goodsCheck = $this->goodsService->check($goods,$cart->num); |
|
|
|
} |
|
|
|
if($goodsCheck){ |
|
|
|
$num+= $cart->num; |
|
|
|
} |
|
|
|
} |
|
|
|
return $num; |
|
|
|
} |
|
|
|
|
|
|
|
public function getTotal($userId,$marketId) |
|
|
|
{ |
|
|
|
$randomFloat = rand(100,999)/100; |
|
|
|
return $randomFloat; |
|
|
|
$ShoppingCart = ShoppingCart::query()->where([ |
|
|
|
['user_id','=',$userId], |
|
|
|
['market_id','=',$marketId], |
|
|
|
])->get(); |
|
|
|
$total = 0; |
|
|
|
foreach ($ShoppingCart as $cart){ |
|
|
|
if($cart->activity_type == 2){ |
|
|
|
$goods = GoodsActivity::query()->find($cart->goods_id); |
|
|
|
$goodsCheck = $this->goodsActivityService->check($goods,$cart->num,$cart->user_id); |
|
|
|
}else{ |
|
|
|
$goods = Goods::query()->find($cart->goods_id); |
|
|
|
$goodsCheck = $this->goodsService->check($goods,$cart->num); |
|
|
|
} |
|
|
|
if($goodsCheck){ |
|
|
|
$subTotal = bcmul($goods->price,$cart->num); |
|
|
|
$total = bcadd($subTotal,$total,2); |
|
|
|
} |
|
|
|
} |
|
|
|
return $total; |
|
|
|
} |
|
|
|
|
|
|
|
public function getGoodsByShopcartId($shopcartIds) |
|
|
|
@ -191,14 +231,13 @@ class ShopCartService implements ShopCartServiceInterface |
|
|
|
public function allForUser($userId, $marketId) |
|
|
|
{ |
|
|
|
|
|
|
|
bcscale(6); |
|
|
|
//bcscale(6);
|
|
|
|
// 查询当前用户的市场下的购物车数据
|
|
|
|
$carts = ShoppingCart::query() |
|
|
|
->with(['store', 'goods']) |
|
|
|
->where(['user_id' => $userId]) |
|
|
|
->where(['market_id' => $marketId]) |
|
|
|
->get(); |
|
|
|
|
|
|
|
$cartList = []; |
|
|
|
$totalAmount = 0; |
|
|
|
foreach ($carts as $key => &$cart) { |
|
|
|
@ -231,8 +270,10 @@ class ShopCartService implements ShopCartServiceInterface |
|
|
|
|
|
|
|
// 商品是否失效
|
|
|
|
if ($cart->activity_type == 2) { |
|
|
|
$goods = GoodsActivity::query()->find($cart->goods_id); |
|
|
|
$res = $this->goodsActivityService->check($cart->goods, $cart->num, $cart->user_id); |
|
|
|
} else { |
|
|
|
$goods = Goods::query()->find($cart->goods_id); |
|
|
|
$res = $this->goodsService->check($cart->goods, $cart->num); |
|
|
|
} |
|
|
|
|
|
|
|
|