修复优惠券注销重复领取的bug

main
home.fengxinyhyl 8 months ago
parent 048ca68ac7
commit 524bd10efb
  1. 9
      app/common/dao/store/coupon/StoreCouponDao.php
  2. 3
      app/common/repositories/store/coupon/StoreCouponIssueUserRepository.php
  3. 6
      app/common/repositories/store/coupon/StoreCouponRepository.php
  4. 1
      app/controller/api/store/product/StoreCoupon.php

@ -176,11 +176,14 @@ class StoreCouponDao extends BaseDao
* @author xaboy * @author xaboy
* @day 2020/6/19 * @day 2020/6/19
*/ */
public function validCoupon($id, $uid) public function validCoupon($id, $uid, $phone = '')
{ {
return $this->validCouponQuery()->when($uid, function (BaseQuery $query, $uid) { return $this->validCouponQuery()->when($uid, function (BaseQuery $query) use($uid, $phone) {
$query->with(['issue' => function (BaseQuery $query) use ($uid) { $query->with(['issue' => function (BaseQuery $query) use ($uid, $phone) {
$query->where('uid', $uid); $query->where('uid', $uid);
if($phone){
$query->whereOr('phone', $phone);
}
}]); }]);
})->where('coupon_id', $id)->find(); })->where('coupon_id', $id)->find();
} }

@ -16,6 +16,7 @@ namespace app\common\repositories\store\coupon;
use app\common\dao\store\coupon\StoreCouponIssueUserDao; use app\common\dao\store\coupon\StoreCouponIssueUserDao;
use app\common\repositories\BaseRepository; use app\common\repositories\BaseRepository;
use app\common\repositories\user\UserRepository;
/** /**
* Class StoreCouponIssueUserRepository * Class StoreCouponIssueUserRepository
@ -37,8 +38,10 @@ class StoreCouponIssueUserRepository extends BaseRepository
public function issue($couponId, $uid) public function issue($couponId, $uid)
{ {
$user = app(UserRepository::class)->get($uid);
return $this->dao->create([ return $this->dao->create([
'coupon_id' => $couponId, 'coupon_id' => $couponId,
'phone' => $user['phone'] ?? '',
'uid' => $uid, 'uid' => $uid,
]); ]);
} }

@ -281,7 +281,11 @@ class StoreCouponRepository extends BaseRepository
public function receiveCoupon($id, $uid) public function receiveCoupon($id, $uid)
{ {
$coupon = $this->dao->validCoupon($id, $uid); $user = app(UserRepository::class)->get($uid);
if(empty($user['phone'])){
throw new ValidateException('请先绑定手机号');
}
$coupon = $this->dao->validCoupon($id, $uid, $user['phone']);
if (!$coupon) if (!$coupon)
throw new ValidateException('优惠券失效'); throw new ValidateException('优惠券失效');

@ -22,6 +22,7 @@ use think\App;
use think\db\exception\DataNotFoundException; use think\db\exception\DataNotFoundException;
use think\db\exception\DbException; use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException; use think\db\exception\ModelNotFoundException;
use think\facade\Log;
/** /**
* Class StoreCoupon * Class StoreCoupon

Loading…
Cancel
Save