diff --git a/app/common/dao/store/coupon/StoreCouponDao.php b/app/common/dao/store/coupon/StoreCouponDao.php index c822626..5fa8d09 100644 --- a/app/common/dao/store/coupon/StoreCouponDao.php +++ b/app/common/dao/store/coupon/StoreCouponDao.php @@ -176,11 +176,14 @@ class StoreCouponDao extends BaseDao * @author xaboy * @day 2020/6/19 */ - public function validCoupon($id, $uid) + public function validCoupon($id, $uid, $phone = '') { - return $this->validCouponQuery()->when($uid, function (BaseQuery $query, $uid) { - $query->with(['issue' => function (BaseQuery $query) use ($uid) { + return $this->validCouponQuery()->when($uid, function (BaseQuery $query) use($uid, $phone) { + $query->with(['issue' => function (BaseQuery $query) use ($uid, $phone) { $query->where('uid', $uid); + if($phone){ + $query->whereOr('phone', $phone); + } }]); })->where('coupon_id', $id)->find(); } diff --git a/app/common/repositories/store/coupon/StoreCouponIssueUserRepository.php b/app/common/repositories/store/coupon/StoreCouponIssueUserRepository.php index 271a9b2..e6138a6 100644 --- a/app/common/repositories/store/coupon/StoreCouponIssueUserRepository.php +++ b/app/common/repositories/store/coupon/StoreCouponIssueUserRepository.php @@ -16,6 +16,7 @@ namespace app\common\repositories\store\coupon; use app\common\dao\store\coupon\StoreCouponIssueUserDao; use app\common\repositories\BaseRepository; +use app\common\repositories\user\UserRepository; /** * Class StoreCouponIssueUserRepository @@ -37,8 +38,10 @@ class StoreCouponIssueUserRepository extends BaseRepository public function issue($couponId, $uid) { + $user = app(UserRepository::class)->get($uid); return $this->dao->create([ 'coupon_id' => $couponId, + 'phone' => $user['phone'] ?? '', 'uid' => $uid, ]); } diff --git a/app/common/repositories/store/coupon/StoreCouponRepository.php b/app/common/repositories/store/coupon/StoreCouponRepository.php index 3dd7c4d..eb37261 100644 --- a/app/common/repositories/store/coupon/StoreCouponRepository.php +++ b/app/common/repositories/store/coupon/StoreCouponRepository.php @@ -281,7 +281,11 @@ class StoreCouponRepository extends BaseRepository 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) throw new ValidateException('优惠券失效'); diff --git a/app/controller/api/store/product/StoreCoupon.php b/app/controller/api/store/product/StoreCoupon.php index 94c1b61..6480406 100644 --- a/app/controller/api/store/product/StoreCoupon.php +++ b/app/controller/api/store/product/StoreCoupon.php @@ -22,6 +22,7 @@ use think\App; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; +use think\facade\Log; /** * Class StoreCoupon