Browse Source

删除购物车

master
Lemon 5 years ago
parent
commit
6ed929dc77
  1. 2
      app/Controller/v3/ShopCartController.php
  2. 3
      app/Controller/v3/ShopCartUpdateController.php
  3. 64
      app/Service/v3/Implementations/ShopCartService.php
  4. 5
      app/Service/v3/Implementations/ShopCartUpdateService.php
  5. 2
      app/Service/v3/Interfaces/ShopCartServiceInterface.php
  6. 2
      app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php
  7. 1
      config/routes.php

2
app/Controller/v3/ShopCartController.php

@ -20,7 +20,7 @@ class ShopCartController extends BaseController
//获取购物车商品信息
$res['store_lists'] = $this->shopCartService->do($userId,$marketId);
//获取购物车失效商品信息
$res['store_lists_invalid'] = $this->shopCartService->undo();
$res['store_lists_invalid'] = $this->shopCartService->undo($userId,$marketId);
//计算购物车价格
$res['total'] = $this->shopCartService->getTotal($userId,$marketId);
return $this->success($res);

3
app/Controller/v3/ShopCartUpdateController.php

@ -25,7 +25,8 @@ class ShopCartUpdateController extends BaseController
public function delete()
{
$res = $this->shopCarServiceUpdate->undo($this->request->all());
$shopcartIds = $this->request->input('shopcart_ids','');
$res = $this->shopCarServiceUpdate->undo($shopcartIds);
return $this->success($res);
}
}

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

@ -84,32 +84,52 @@ class ShopCartService implements ShopCartServiceInterface
return mt_rand(0,6);
}
public function undo()
public function undo($userId,$marketId)
{
$storeIds = Db::table('lanzu_shopping_cart')->where('user_id',198)->pluck('store_id')->toArray();
$res = Store::query()->with(['ShoppingCart' => function($query) {
$query->with('goods');
$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();
foreach ($res as &$k){
$k->subtotal = '99.90';
foreach ($k->ShoppingCart as &$v){
switch (mt_rand(1,3)) {
case 1:
$str = '已下架';
break;
case 2:
$str = '已抢光';
break;
case 3:
$str = '已打烊';
break;
}
$v['goods']['invalid_cause'] = $str;
->get()
->toArray();
$storeArr = [];
foreach ($stores as $key => &$store){
$sotreType = $this->storeService->check($store['id']);
if(!$sotreType){
unset($stores[$key]);
continue;
}
$subtotal = 0;
foreach ($store['shopping_cart'] as &$shopcart){
if($shopcart['activity_type'] == 1){
$builder = Goods::query();
}else{
$builder = GoodsActivity::query();
}
return $res;
$shopcart['goods'] = $builder->where('id',$shopcart['goods_id'])->first()->toArray();
foreach ($shopcart['goods'] as $goods){
if($shopcart['activity_type'] == 1){
$goodsType = $this->goodsService->check($goods['id']);
}else{
$goodsType = $this->goodsActivityService->check($goods['id'],$shopcart['num'],$shopcart['user_id']);
}
if($goodsType !== true){
unset($shopcart['goods'][$key]);
continue;
}
$subtotal+= $shopcart['num'] * $shopcart['goods']['price'];
}
}
$store['subtotal'] = $subtotal;
$storeArr[] = $store;
}
return $storeArr;
}
public function countGoods()

5
app/Service/v3/Implementations/ShopCartUpdateService.php

@ -42,8 +42,9 @@ class ShopCartUpdateService implements ShopCartUpdateServiceInterface
// TODO: Implement check() method.
}
public function undo($params)
public function undo($shopcartIds)
{
return true;
$shopcartIdsArr = explode(',',$shopcartIds);
return ShoppingCart::destroy($shopcartIdsArr);
}
}

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

@ -8,7 +8,7 @@ interface ShopCartServiceInterface
public function check($goodsId);
public function undo();
public function undo($userId,$marketId);
public function countGoods();

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

@ -8,5 +8,5 @@ interface ShopCartUpdateServiceInterface
public function check();
public function undo($params);
public function undo($shopcartIds);
}

1
config/routes.php

@ -134,6 +134,7 @@ Router::addGroup('/v3/', function () {
Router::post('orderOnline/del', 'App\Controller\v3\OrderOnlineController@del');
Router::post('orderOnline/applyRefund', 'App\Controller\v3\OrderOnlineController@applyRefund');
Router::post('orderOnline/complete', 'App\Controller\v3\OrderOnlineController@complete');
Router::post('shopCart/delete', 'App\Controller\v3\ShopCartUpdateController@delete');
},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]);
// 微信支付回调

Loading…
Cancel
Save