diff --git a/app/Controller/v3/ShopCartController.php b/app/Controller/v3/ShopCartController.php index 9f396e2..4eca551 100644 --- a/app/Controller/v3/ShopCartController.php +++ b/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); diff --git a/app/Controller/v3/ShopCartUpdateController.php b/app/Controller/v3/ShopCartUpdateController.php index 83b526b..c6dc577 100644 --- a/app/Controller/v3/ShopCartUpdateController.php +++ b/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); } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/ShopCartService.php b/app/Service/v3/Implementations/ShopCartService.php index 005c59d..2bc754c 100644 --- a/app/Service/v3/Implementations/ShopCartService.php +++ b/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; + ->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(); + } + $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']; } - $v['goods']['invalid_cause'] = $str; } - + $store['subtotal'] = $subtotal; + $storeArr[] = $store; } - return $res; + return $storeArr; } public function countGoods() diff --git a/app/Service/v3/Implementations/ShopCartUpdateService.php b/app/Service/v3/Implementations/ShopCartUpdateService.php index 7ce4e95..38e1a36 100644 --- a/app/Service/v3/Implementations/ShopCartUpdateService.php +++ b/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); } } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/ShopCartServiceInterface.php b/app/Service/v3/Interfaces/ShopCartServiceInterface.php index 311be25..0038524 100644 --- a/app/Service/v3/Interfaces/ShopCartServiceInterface.php +++ b/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(); diff --git a/app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php b/app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php index dcd4893..1fd40cb 100644 --- a/app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php +++ b/app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php @@ -8,5 +8,5 @@ interface ShopCartUpdateServiceInterface public function check(); - public function undo($params); + public function undo($shopcartIds); } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 11a8405..c8f1eaa 100644 --- a/config/routes.php +++ b/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]]); // 微信支付回调