diff --git a/packages/coupon/src/Action/Init.php b/packages/coupon/src/Action/Init.php index 6c00412..b3c3de0 100644 --- a/packages/coupon/src/Action/Init.php +++ b/packages/coupon/src/Action/Init.php @@ -147,4 +147,37 @@ class Init return true; } + /** + * Notes: 校验是否已经核销过。3秒内视为同一订单 + * @Author: 玄尘 + * @Date : 2020/8/8 13:43 + */ + public function HasCheck() + { + $code = $this->redemptionCode; + $total = $this->total; + $outletId = $this->outletId; + + $info = Coupon::where('redemptionCode', $this->redemptionCode) + ->where('outletId', $this->outletId) + ->where('total', $this->total) + ->where('status', 2) + ->first(); + if ($info) { + if ($info->created_at->gt(now()->subSecond(3))) { + return [ + 'name' => $info->couponName, + 'total' => $info->total, + 'price' => $info->price, + ]; + + } + + return '核销失败,此优惠券已被使用'; + } + + return false; + + } + } diff --git a/packages/coupon/src/Action/pingan/Verification.php b/packages/coupon/src/Action/pingan/Verification.php index 2b0c961..d9eecca 100644 --- a/packages/coupon/src/Action/pingan/Verification.php +++ b/packages/coupon/src/Action/pingan/Verification.php @@ -16,6 +16,12 @@ class Verification extends PingAnInit public function start() { + //检查是否已经核销过 + $res = $this->HasCheck(); + if ($res !== false) { + return $res; + } + //检查可核销次数 $ret = $this->CheckCount(); if ($ret !== true) { diff --git a/packages/coupon/src/Action/ysd/YsdVerification.php b/packages/coupon/src/Action/ysd/YsdVerification.php index 0bbc9fa..e2f41e0 100644 --- a/packages/coupon/src/Action/ysd/YsdVerification.php +++ b/packages/coupon/src/Action/ysd/YsdVerification.php @@ -20,11 +20,20 @@ class YsdVerification extends Init */ public function start() { + //检查是否已经核销过 + $res = $this->HasCheck(); + if ($res !== false) { + return $res; + } - //查询卡券信息 + //查询卡券信息 返回model string 说明报错 $this->query_coupon = (new YsdQuery)->setOutletId($this->outletId) ->setCode($this->redemptionCode) ->start(); + if (is_string($this->query_coupon)) { + return $this->query_coupon; + } + //检查可核销次数 if ($this->query_coupon->activity && $this->query_coupon->activity->need_check) { $ret = $this->CheckCount(); @@ -33,10 +42,6 @@ class YsdVerification extends Init } } - if (is_string($this->query_coupon)) { - return $this->query_coupon; - } - //校验卡券 $ticket = $this->checkCoupon(); if (!is_array($ticket)) {