From 4f75f51d5006bdf949aed1e4692c4874ec039e9d Mon Sep 17 00:00:00 2001 From: wangxinglong <2371974647@qq.com> Date: Thu, 16 Dec 2021 14:03:35 +0800 Subject: [PATCH] setter --- app/controller/api/Consumer.php | 2 +- app/controller/api/Coupon.php | 10 ++++++---- app/traits/CouponMainTrait.php | 13 +++++++------ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/controller/api/Consumer.php b/app/controller/api/Consumer.php index 8a79ee6..3df38e7 100644 --- a/app/controller/api/Consumer.php +++ b/app/controller/api/Consumer.php @@ -76,7 +76,7 @@ class Consumer extends Base if (($params['businessCircleId']) > 0 ) { $whereMap[] = ['business_circle_id', '=', $params['businessCircleId']]; } - + if ($params['dis'] > 0) { $pointList = getEarthSquareRangePoint($params['lat'],$params['lng'], $params['dis']); $latRange[] = ['lat', 'BETWEEN', [$pointList['lat_min'], $pointList['lat_max']]]; diff --git a/app/controller/api/Coupon.php b/app/controller/api/Coupon.php index 1bd068f..1ffbf01 100644 --- a/app/controller/api/Coupon.php +++ b/app/controller/api/Coupon.php @@ -188,12 +188,14 @@ class Coupon extends Base return $q->with("business")->lock(true); }); - //检查优惠券状态 - $checkCouponMainReceiveStatus = CouponRepository::getInstance()->checkCouponMainReceiveStatus($couponMain); - if( $checkCouponMainReceiveStatus !== true ){ - return $checkCouponMainReceiveStatus; + try { + //检查优惠券状态 + CouponRepository::getInstance()->checkCouponMainReceiveStatus($couponMain); + }catch (RepositoryException $e){ + return $this->json(4001,$e->getMessage()); } + try { //检查是否可以领取 0可领取 1已领取 AccountRepository::getInstance()->getCouponReceiveStatusText($account,$couponMain);//领取状态 diff --git a/app/traits/CouponMainTrait.php b/app/traits/CouponMainTrait.php index 1495b78..be089f3 100644 --- a/app/traits/CouponMainTrait.php +++ b/app/traits/CouponMainTrait.php @@ -2,6 +2,7 @@ namespace app\traits; +use app\exception\RepositoryException; use app\model\CouponMain; use app\model\UsingRule; use app\model\Coupon; @@ -15,25 +16,25 @@ trait CouponMainTrait */ public function checkCouponMainReceiveStatus(CouponMain $couponMain){ if (empty($couponMain)) { - return $this->json(4001, "优惠券不存在"); + throw new RepositoryException("优惠券不存在"); } if ($couponMain->status != CouponMain::status_on) { - return $this->json(4002, "优惠券已停用"); + throw new RepositoryException("优惠券已停用"); } if ($couponMain->on_shelf != CouponMain::on_shelf_on) { - return $this->json(4003, "优惠券已下架"); + throw new RepositoryException("优惠券已下架"); } $time = time(); if (strtotime($couponMain->start_time) > $time) { - return $this->json(4004, "优惠券还未发行"); + throw new RepositoryException("优惠券还未到开始使用时间"); } if (strtotime($couponMain->end_time) < $time) { - return $this->json(4004, "优惠券已结束使用"); + throw new RepositoryException("优惠券已结束使用"); } if ($couponMain->using_count <= 0) { - return $this->json(4004, "优惠券已经被领完了"); + throw new RepositoryException("优惠券已经被领完了"); } return true; }