Browse Source

确认订单

master
Lemon 5 years ago
parent
commit
53ec42c151
  1. 11
      app/Controller/v3/OrderOnlineController.php
  2. 43
      app/Service/v3/Implementations/ShopCartService.php
  3. 2
      app/Service/v3/Interfaces/ShopCartServiceInterface.php

11
app/Controller/v3/OrderOnlineController.php

@ -72,6 +72,7 @@ class OrderOnlineController extends BaseController
{
$userId = $this->request->input('user_id');
$marketId = $this->request->input('market_id');
$shopcartIds = $this->request->input('shopcart_ids');
//判断用户有没有绑定手机
// $telExists = $this->userBindTelService->check($params['user_id']);
// if(!$telExists){
@ -82,7 +83,7 @@ class OrderOnlineController extends BaseController
//返回预约送达时间 数组
$res['appointment_time'] = $this->appointmentTimeService->do();
//
$res['store_list'] = $this->shopCartService->do($userId,$marketId);
$res['store_list'] = $this->shopCartService->getGoodsByShopcartId($shopcartIds);
//获取用户优惠券
$res['coupon']['available'] = $this->couponRecService->allForOrderOlAvailable('181.02',$userId,'',1,'');
$res['coupon']['not_available'] = $this->couponRecService->allForOrderOlAvailable('181.02',$userId,'',1,'');
@ -93,6 +94,14 @@ class OrderOnlineController extends BaseController
'select' => 1,
'price' => 3.50
];
$total = 0;
foreach ($res['store_list'] as $store)
{
$total+= $store['subtotal'];
}
$total+= $res['value_added_service']['price'];
$total+= $res['distribution_price'];
$res['total'] = $total;
return $this->success($res);
}

43
app/Service/v3/Implementations/ShopCartService.php

@ -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;
}
}

2
app/Service/v3/Interfaces/ShopCartServiceInterface.php

@ -13,4 +13,6 @@ interface ShopCartServiceInterface
public function countGoods($userId,$marketId);
public function getTotal($userId,$marketId);
public function getGoodsByShopcartId($shopcartIds);
}
Loading…
Cancel
Save