From 6be99a2655795e05628daddbdfb67038b5d9a98f Mon Sep 17 00:00:00 2001 From: xuanchen <122383162@qq.com> Date: Fri, 11 Sep 2020 08:13:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AE=9E=E7=89=A9=E5=85=91?= =?UTF-8?q?=E6=8D=A2=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/coupon/src/Action/Init.php | 385 +++++++++--------- .../coupon/src/Action/pingan/Verification.php | 19 +- 2 files changed, 205 insertions(+), 199 deletions(-) diff --git a/packages/coupon/src/Action/Init.php b/packages/coupon/src/Action/Init.php index d3650b2..5e37cdb 100644 --- a/packages/coupon/src/Action/Init.php +++ b/packages/coupon/src/Action/Init.php @@ -1,188 +1,197 @@ -user = $user; - - return $this; - } - - //设置渠道 - public function setOrderId($orderid) - { - $this->orderid = $orderid; - - return $this; - } - - //设置核销码 - public function setCode($redemptionCode) - { - $this->redemptionCode = $redemptionCode; - - return $this; - - } - - //设置订单总额 - public function setTotal($total) - { - $this->total = $total; - - return $this; - - } - - //设置网点id - public function setOutletId($outletId) - { - $this->outletId = $outletId; - - return $this; - - } - - //设置活动id - public function setActivityId($activityId) - { - $this->activityId = $activityId; - - return $this; - - } - - //设置手机号 - public function setMobile($mobile) - { - $this->mobile = $mobile; - - return $this; - - } - - /** - * Notes: 插入日志 - * @Author: 玄尘 - * @Date : 2020/6/30 10:29 - * @param $url - * @param $method - * @param $params - * @param string $type - * @return mixed - */ - public function createLog($url, $method, $params, $type = 'pingan') - { - $data = [ - 'path' => $url, - 'method' => $method, - 'type' => $type, - 'in_source' => $params, - ]; - - $info = LogModel::create($data); - - return $info; - } - - /** - * Notes: 更新日志 - * @Author: 玄尘 - * @Date : 2020/6/30 10:29 - * @param $log - * @param $params - */ - public static function updateLog($log, $params) - { - $log->out_source = $params; - $log->save(); - } - - //统一门店 相同金额 3分钟之内看作是一笔订单 - public function CheckCount() - { - 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(); - } 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(); - } - - $count = floor($this->total / 100); - - if ($check_count > 0) { - if ($this->total < 100) { - return '核销失败,订单金额少于100只能核销一张优惠券。'; - } - if ($check_count >= $count) { - return "核销失败,此订单您只能使用 {$count} 张优惠券"; - } - } - - return true; - } - - /** - * Notes: 校验是否已经核销过 - * @Author: 玄尘 - * @Date : 2020/8/8 13:43 - */ - public function HasCheck() - { - $info = Coupon::where('redemptionCode', $this->redemptionCode) - ->where('outletId', $this->outletId) - ->where('total', $this->total) - ->where('status', 2) - ->first(); - if ($info) { - return '核销失败,此优惠券已被使用'; - } - - return false; - - } - -} +user = $user; + + return $this; + } + + //设置渠道 + public function setOrderId($orderid) + { + $this->orderid = $orderid; + + return $this; + } + + //设置核销码 + public function setCode($redemptionCode) + { + $this->redemptionCode = $redemptionCode; + + return $this; + + } + + //设置订单总额 + public function setTotal($total) + { + $this->total = $total; + + return $this; + + } + + //设置网点id + public function setOutletId($outletId) + { + $this->outletId = $outletId; + + return $this; + + } + + //设置活动id + public function setActivityId($activityId) + { + $this->activityId = $activityId; + + return $this; + + } + + //设置手机号 + public function setMobile($mobile) + { + $this->mobile = $mobile; + + return $this; + + } + + /** + * Notes: 插入日志 + * @Author: 玄尘 + * @Date : 2020/6/30 10:29 + * @param $url + * @param $method + * @param $params + * @param string $type + * @return mixed + */ + public function createLog($url, $method, $params, $type = 'pingan') + { + $data = [ + 'path' => $url, + 'method' => $method, + 'type' => $type, + 'in_source' => $params, + ]; + + $info = LogModel::create($data); + + return $info; + } + + /** + * Notes: 更新日志 + * @Author: 玄尘 + * @Date : 2020/6/30 10:29 + * @param $log + * @param $params + */ + public static function updateLog($log, $params) + { + $log->out_source = $params; + $log->save(); + } + + //统一门店 相同金额 3分钟之内看作是一笔订单 + public function CheckCount() + { + if ($this->queryData) { + if (isset($this->queryData['thirdPartyGoodsId']) && $this->queryData['thirdPartyGoodsId'] == 'YSD-full0-0') { + return true; + } + } + + 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(); + } 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(); + } + + $count = floor($this->total / 100); + + if ($check_count > 0) { +// if ($this->total < 100) { + // return '核销失败,订单金额少于100只能核销一张优惠券。'; + // } + if ($check_count >= $count) { + return "核销失败,此订单您只能使用 {$count} 张优惠券"; + } + } + + return true; + } + + /** + * Notes: 校验是否已经核销过 + * @Author: 玄尘 + * @Date : 2020/8/8 13:43 + */ + public function HasCheck() + { + $info = Coupon::where('redemptionCode', $this->redemptionCode) + ->where('outletId', $this->outletId) + ->where('total', $this->total) + ->where('status', 2) + ->first(); + if ($info) { + return '核销失败,此优惠券已被使用'; + } + + return false; + + } + +} diff --git a/packages/coupon/src/Action/pingan/Verification.php b/packages/coupon/src/Action/pingan/Verification.php index fdba147..bdcafbb 100644 --- a/packages/coupon/src/Action/pingan/Verification.php +++ b/packages/coupon/src/Action/pingan/Verification.php @@ -11,9 +11,6 @@ class Verification extends PingAnInit public $ticket; - //查询到的卡券规则和商品id - public $queryData; - public function start() { //检查是否已经核销过 @@ -22,16 +19,10 @@ class Verification extends PingAnInit return $res; } - //检查可核销次数 - $ret = $this->CheckCount(); - if ($ret !== true) { - return $ret; - } - //查询卡券信息 $this->query_coupon = (new Query)->setOutletId($this->outletId) - ->setCode($this->redemptionCode) - ->start(); + ->setCode($this->redemptionCode) + ->start(); if (is_string($this->query_coupon)) { return $this->query_coupon; } @@ -42,6 +33,12 @@ class Verification extends PingAnInit return $ticket; } + //检查可核销次数 + $ret = $this->CheckCount(); + if ($ret !== true) { + return $ret; + } + //增加核销记录 $coupon = $this->AddCoupon(); if (is_string($coupon)) {