From 70a34f60b0c8b337c7a79969a476608ae95deb77 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Tue, 25 Aug 2020 21:48:22 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=8D=95=E4=B8=AA=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=8F=AA=E8=83=BD=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA=E7=89=B9?= =?UTF-8?q?=E4=BB=B7=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/ShopCarService.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/Service/ShopCarService.php b/app/Service/ShopCarService.php index a739846..dab1ef9 100644 --- a/app/Service/ShopCarService.php +++ b/app/Service/ShopCarService.php @@ -27,6 +27,20 @@ class ShopCarService implements ShopCarServiceInterface ]; return $error; } + //一个订单只能添加一个特价商品 + if($params['money'] == 0.01){ + $goods_exists = ShopCar::where([ + ['money','=',0.01], + ['user_id','=',$params['user_id']] + ]) + ->exists(); + if($goods_exists){ + $error = [ + 'error' => '一个订单只能添加一个特价商品' + ]; + return $error; + } + } //获取主表商品表信息 $goods = Goods::where([ ['id','=',$params['good_id']], From fa61e20d7565e4b03c7108edc70ec0b1002bbeff Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Tue, 25 Aug 2020 22:00:18 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=B8=80=E4=B8=AA=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=8F=AA=E8=83=BD=E8=B4=AD=E4=B9=B0=E4=B8=80=E4=B8=AA=E7=89=B9?= =?UTF-8?q?=E4=BB=B7=E5=95=86=E5=93=81=20=E4=BD=86=E6=98=AF=E5=90=8C?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E8=B4=AD=E4=B9=B0=E5=A4=9A=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/ShopCarService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Service/ShopCarService.php b/app/Service/ShopCarService.php index dab1ef9..b017955 100644 --- a/app/Service/ShopCarService.php +++ b/app/Service/ShopCarService.php @@ -32,6 +32,7 @@ class ShopCarService implements ShopCarServiceInterface $goods_exists = ShopCar::where([ ['money','=',0.01], ['user_id','=',$params['user_id']] + ['good_id','=',$params['good_id']] ]) ->exists(); if($goods_exists){ From 58676c0b1fb2c5ad22d971c5276b036a621530f7 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 00:42:34 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=8F=AF=E7=94=A8?= =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponController.php | 62 ++------------------------ app/Service/CouponService.php | 60 ++++++++++++++++++++++++- app/Service/CouponServiceInterface.php | 2 +- app/Service/ShopCarService.php | 2 +- 4 files changed, 64 insertions(+), 62 deletions(-) diff --git a/app/Controller/CouponController.php b/app/Controller/CouponController.php index dc8ae7c..af85368 100644 --- a/app/Controller/CouponController.php +++ b/app/Controller/CouponController.php @@ -199,65 +199,9 @@ class CouponController extends BaseController $type = $this->request->input('type', 1); # 店铺类型id $storetypeId = $this->request->input('storetype_id', 0); - $storetypeIds = explode(',', str_replace(',', ',', $storetypeId)); - - $available = []; - $notAvailable = []; - - if ($this->empty($orderAmount) || $this->empty($userId)) { - return $this->success([ - 'available' => $available, - 'not_available' => array_values($notAvailable) - ]); - } - - // 获取用户优惠券 - $currentTime = time(); - - $data = Db::table('ims_system_coupon_user_receive as receive') - ->select([ - 'receive.id as receive_id', - 'receive.user_id', - 'receive.number_remain', - 'coupon.id', - 'coupon.title', - 'coupon.full_amount', - 'coupon.discounts', - 'coupon.usable_start_time', - 'coupon.usable_end_time', - 'coupon.discount_type' - ]) - ->join('ims_system_coupon_user as coupon', 'coupon.id', '=', 'receive.system_coupon_user_id') - ->where(['receive.user_id' => $userId]) - ->whereIn('receive.status', [0,1]) - ->where('receive.number_remain', '>', 0) - ->whereIn('coupon.type', [1,$type]) - ->where('coupon.full_amount', '<=', $orderAmount) - ->where('coupon.usable_start_time', '<=', $currentTime) - ->where('coupon.usable_end_time', '>=', $currentTime) - ->where('coupon.usable_number', '<=', Db::raw('receive.number_remain')) - ->where('coupon.market_id', 'in', [0, $marketId]) - ->whereIn('coupon.storetype_id', $storetypeIds) - ->orderByRaw('coupon.discounts DESC, coupon.full_amount DESC') - ->get(); - - // 分离用户今天用过的优惠券种类 - $container = ApplicationContext::getContainer(); - $redis = $container->get(Redis::class); - $couponIds = $redis->sMembers('coupon_'.date('Ymd').'_used_'.$userId); - - foreach ($data as $key => &$item) { - if (in_array($item->id, $couponIds)) { - $notAvailable[$item->id] = $item; - } else { - $available[] = $item; - } - } - - return $this->success([ - 'available' => $available, - 'not_available' => array_values($notAvailable) - ]); + + $res = $this->couponService->getUserAvailableCoupons($orderAmount,$userId,$marketId,$storetypeId); + return $this->success($res); } diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index e0469f1..57acfa4 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -154,9 +154,67 @@ class CouponService implements CouponServiceInterface * 获取用户当前订单可用的优惠券列表 * 按分类(1订单 等优惠)分组返回 */ - public function getUserAvailableCoupons() + public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$storetypeId) { + $storetypeIds = explode(',', str_replace(',', ',', $storetypeId)); + $available = []; + $notAvailable = []; + + if ($this->empty($orderAmount) || $this->empty($userId)) { + return $this->success([ + 'available' => $available, + 'not_available' => array_values($notAvailable) + ]); + } + + // 获取用户优惠券 + $currentTime = time(); + + $data = Db::table('ims_system_coupon_user_receive as receive') + ->select([ + 'receive.id as receive_id', + 'receive.user_id', + 'receive.number_remain', + 'coupon.id', + 'coupon.title', + 'coupon.full_amount', + 'coupon.discounts', + 'coupon.usable_start_time', + 'coupon.usable_end_time', + 'coupon.discount_type' + ]) + ->join('ims_system_coupon_user as coupon', 'coupon.id', '=', 'receive.system_coupon_user_id') + ->where(['receive.user_id' => $userId]) + ->whereIn('receive.status', [0,1]) + ->where('receive.number_remain', '>', 0) + ->whereIn('coupon.type', [1,$type]) + ->where('coupon.full_amount', '<=', $orderAmount) + ->where('coupon.usable_start_time', '<=', $currentTime) + ->where('coupon.usable_end_time', '>=', $currentTime) + ->where('coupon.usable_number', '<=', Db::raw('receive.number_remain')) + ->where('coupon.market_id', 'in', [0, $marketId]) + ->whereIn('coupon.storetype_id', $storetypeIds) + ->orderByRaw('coupon.discounts DESC, coupon.full_amount DESC') + ->get(); + + // 分离用户今天用过的优惠券种类 + $container = ApplicationContext::getContainer(); + $redis = $container->get(Redis::class); + $couponIds = $redis->sMembers('coupon_'.date('Ymd').'_used_'.$userId); + + foreach ($data as $key => &$item) { + if (in_array($item->id, $couponIds)) { + $notAvailable[$item->id] = $item; + } else { + $available[] = $item; + } + } + + return [ + 'available' => $available, + 'not_available' => array_values($notAvailable) + ]; } /** diff --git a/app/Service/CouponServiceInterface.php b/app/Service/CouponServiceInterface.php index 5220320..bf82ab4 100644 --- a/app/Service/CouponServiceInterface.php +++ b/app/Service/CouponServiceInterface.php @@ -13,7 +13,7 @@ interface CouponServiceInterface public function getUserReceiveCouponList(); - public function getUserAvailableCoupons(); + public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$storetypeId); /** * 当前订单可用优惠券列表 diff --git a/app/Service/ShopCarService.php b/app/Service/ShopCarService.php index b017955..6f0536d 100644 --- a/app/Service/ShopCarService.php +++ b/app/Service/ShopCarService.php @@ -31,7 +31,7 @@ class ShopCarService implements ShopCarServiceInterface if($params['money'] == 0.01){ $goods_exists = ShopCar::where([ ['money','=',0.01], - ['user_id','=',$params['user_id']] + ['user_id','=',$params['user_id']], ['good_id','=',$params['good_id']] ]) ->exists(); From 6aa253e70556109915a35fed5bb133ed3a126334 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 26 Aug 2020 00:48:06 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=8F=AF=E7=94=A8=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponController.php | 2 +- app/Service/CouponService.php | 2 +- app/Service/CouponServiceInterface.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Controller/CouponController.php b/app/Controller/CouponController.php index af85368..e7fd6c4 100644 --- a/app/Controller/CouponController.php +++ b/app/Controller/CouponController.php @@ -200,7 +200,7 @@ class CouponController extends BaseController # 店铺类型id $storetypeId = $this->request->input('storetype_id', 0); - $res = $this->couponService->getUserAvailableCoupons($orderAmount,$userId,$marketId,$storetypeId); + $res = $this->couponService->getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId); return $this->success($res); } diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index 57acfa4..313f18d 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -154,7 +154,7 @@ class CouponService implements CouponServiceInterface * 获取用户当前订单可用的优惠券列表 * 按分类(1订单 等优惠)分组返回 */ - public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$storetypeId) + public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId) { $storetypeIds = explode(',', str_replace(',', ',', $storetypeId)); diff --git a/app/Service/CouponServiceInterface.php b/app/Service/CouponServiceInterface.php index bf82ab4..f272c42 100644 --- a/app/Service/CouponServiceInterface.php +++ b/app/Service/CouponServiceInterface.php @@ -13,7 +13,7 @@ interface CouponServiceInterface public function getUserReceiveCouponList(); - public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$storetypeId); + public function getUserAvailableCoupons($orderAmount,$userId,$marketId,$type,$storetypeId); /** * 当前订单可用优惠券列表