From 6d7bfdd4f4d5f7a65e5574c05098a446a8e5a3a1 Mon Sep 17 00:00:00 2001 From: xuanchen <122383162@qq.com> Date: Mon, 7 Dec 2020 10:00:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9D=A5=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bootstrap/cache/events.php | 9 ++++++ packages/coupon/src/Action/Init.php | 44 ++++++++++++++++++++--------- packages/coupon/src/Coupon.php | 11 +++++++- 3 files changed, 49 insertions(+), 15 deletions(-) create mode 100644 bootstrap/cache/events.php diff --git a/bootstrap/cache/events.php b/bootstrap/cache/events.php new file mode 100644 index 0000000..3205738 --- /dev/null +++ b/bootstrap/cache/events.php @@ -0,0 +1,9 @@ + + array ( + 'App\\Events\\ConponCallback' => + array ( + 0 => 'App\\Listeners\\ConponCallbackListener', + ), + ), +); \ No newline at end of file diff --git a/packages/coupon/src/Action/Init.php b/packages/coupon/src/Action/Init.php index 5e37cdb..02286cb 100644 --- a/packages/coupon/src/Action/Init.php +++ b/packages/coupon/src/Action/Init.php @@ -35,6 +35,9 @@ class Init //订单id public $orderid; + //来源 + public $from; + //查询到的卡券规则和商品id 只有平安券才有 public $queryData; @@ -99,6 +102,15 @@ class Init } + //设置来源 + public function setFrom($from) + { + $this->from = $from; + + return $this; + + } + /** * Notes: 插入日志 * @Author: 玄尘 @@ -139,6 +151,10 @@ class Init //统一门店 相同金额 3分钟之内看作是一笔订单 public function CheckCount() { + if (!empty($this->from) && in_array($this->from, [''])) { + return true; + } + if ($this->queryData) { if (isset($this->queryData['thirdPartyGoodsId']) && $this->queryData['thirdPartyGoodsId'] == 'YSD-full0-0') { return true; @@ -147,23 +163,23 @@ class Init if ($this->orderid) { $check_count = Coupon::where('orderid', $this->orderid) - ->where('outletId', $this->outletId) - ->where('total', $this->total) - ->where('status', 2) - ->where('created_at', '>=', now()->subMinutes(3)->format('Y-m-d H:i:s')) - ->count(); + ->where('outletId', $this->outletId) + ->where('total', $this->total) + ->where('status', 2) + ->where('created_at', '>=', now()->subMinutes(3)->format('Y-m-d H:i:s')) + ->count(); } else { $check_count = Coupon::where('outletId', $this->outletId) - ->where('total', $this->total) - ->where('status', 2) - ->where('created_at', '>=', now()->subMinutes(3)->format('Y-m-d H:i:s')) - ->count(); + ->where('total', $this->total) + ->where('status', 2) + ->where('created_at', '>=', now()->subMinutes(3)->format('Y-m-d H:i:s')) + ->count(); } $count = floor($this->total / 100); if ($check_count > 0) { -// if ($this->total < 100) { + // if ($this->total < 100) { // return '核销失败,订单金额少于100只能核销一张优惠券。'; // } if ($check_count >= $count) { @@ -182,10 +198,10 @@ class Init public function HasCheck() { $info = Coupon::where('redemptionCode', $this->redemptionCode) - ->where('outletId', $this->outletId) - ->where('total', $this->total) - ->where('status', 2) - ->first(); + ->where('outletId', $this->outletId) + ->where('total', $this->total) + ->where('status', 2) + ->first(); if ($info) { return '核销失败,此优惠券已被使用'; } diff --git a/packages/coupon/src/Coupon.php b/packages/coupon/src/Coupon.php index 6e716b5..c4b80d6 100644 --- a/packages/coupon/src/Coupon.php +++ b/packages/coupon/src/Coupon.php @@ -117,9 +117,17 @@ class Coupon * @param float $total 订单金额 * @param string $outletId 网点id * @param string $orderid 订单id + * @param string $from 来源 * @return string */ - public static function Redemption(User $user, string $redemptionCode, float $total, string $outletId, string $orderid = '') + public static function Redemption( + User $user, + string $redemptionCode, + float $total, + string $outletId, + string $orderid = '', + string $from = '' + ) { try { @@ -133,6 +141,7 @@ class Coupon ->setTotal($total) ->setOutletId($outletId) ->setOrderId($orderid) + ->setFrom($from) ->start(); } catch (\Exception $e) {