修改:优惠券赠送支持任意类型

This commit is contained in:
wuhui_zzw 2024-02-06 14:20:04 +08:00
parent 465d2d38c0
commit 803aa1d6d5
3 changed files with 24 additions and 3 deletions

View File

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

View File

@ -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 = [];

View File

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