From 803aa1d6d5bcaa43fd52ae50f427f086470687a6 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Tue, 6 Feb 2024 14:20:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E8=B5=A0=E9=80=81=E6=94=AF=E6=8C=81=E4=BB=BB=E6=84=8F?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/coupon/StoreCouponDao.php | 14 +++++++++++++- .../store/coupon/StoreCouponRepository.php | 4 +++- app/listener/giveCoupon/CardOpeningEvent.php | 9 ++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/common/dao/store/coupon/StoreCouponDao.php b/app/common/dao/store/coupon/StoreCouponDao.php index 2b03467..d78973d 100644 --- a/app/common/dao/store/coupon/StoreCouponDao.php +++ b/app/common/dao/store/coupon/StoreCouponDao.php @@ -85,7 +85,9 @@ class StoreCouponDao extends BaseDao { $query = StoreCoupon::getDB() ->where('status', 1) - ->where('send_type', $send_type) + ->when(isset($where['send_type']) && $where['send_type'] !== '', function ($query) use ($send_type) { + $query->where('send_type', $send_type); + }) ->where('is_del', 0) ->order('sort DESC,coupon_id DESC') ->when(!is_null($type), function ($query) use ($type) { @@ -188,6 +190,16 @@ class StoreCouponDao extends BaseDao })->where('coupon_id', $id)->find(); } + + public function validSvipCouponTwo($id, $uid) + { + return $this->validCouponQuery(null,'')->when($uid, function (BaseQuery $query, $uid) { + $query->with(['svipIssue' => function (BaseQuery $query) use ($uid) { + $query->where('uid', $uid); + }]); + })->where('coupon_id', $id)->find(); + } + /** * @param $merId * @param null $uid diff --git a/app/common/repositories/store/coupon/StoreCouponRepository.php b/app/common/repositories/store/coupon/StoreCouponRepository.php index 6a97480..cfbf9cb 100644 --- a/app/common/repositories/store/coupon/StoreCouponRepository.php +++ b/app/common/repositories/store/coupon/StoreCouponRepository.php @@ -300,7 +300,9 @@ class StoreCouponRepository extends BaseRepository // 购买会员卡赠送优惠券 支持重复赠送 public function buyMembershipCardGive($id, $order){ $uid = $order['uid']; - $coupon = $this->dao->validSvipCoupon($id,$uid); + $coupon = $this->dao->validSvipCouponTwo($id,$uid); + + if (!$coupon) throw new ValidateException('优惠券失效'); // 获取酒道馆id 和关联的品牌ID $bindShop = []; diff --git a/app/listener/giveCoupon/CardOpeningEvent.php b/app/listener/giveCoupon/CardOpeningEvent.php index b6b66b1..982c5f9 100644 --- a/app/listener/giveCoupon/CardOpeningEvent.php +++ b/app/listener/giveCoupon/CardOpeningEvent.php @@ -19,7 +19,14 @@ class CardOpeningEvent $StoreCouponRepository = app()->make(StoreCouponRepository::class); foreach ($coupon as $val){ - $StoreCouponRepository->buyMembershipCardGive($val, $order); + try { + $StoreCouponRepository->buyMembershipCardGive($val, $order); + } catch (\Exception $e) { + Log::info('会员卡开通成功 - 错误: '.var_export([ + 'msg' => $e->getMessage(), + 'coupon_id' => $val + ],1)); + } } }