增加实物兑换校验

This commit is contained in:
2020-09-11 08:13:02 +08:00
parent 744e53a407
commit 6be99a2655
2 changed files with 205 additions and 199 deletions

View File

@@ -35,6 +35,9 @@ class Init
//订单id //订单id
public $orderid; public $orderid;
//查询到的卡券规则和商品id 只有平安券才有
public $queryData;
//设置渠道 //设置渠道
public function setUser($user) public function setUser($user)
{ {
@@ -136,27 +139,33 @@ class Init
//统一门店 相同金额 3分钟之内看作是一笔订单 //统一门店 相同金额 3分钟之内看作是一笔订单
public function CheckCount() public function CheckCount()
{ {
if ($this->queryData) {
if (isset($this->queryData['thirdPartyGoodsId']) && $this->queryData['thirdPartyGoodsId'] == 'YSD-full0-0') {
return true;
}
}
if ($this->orderid) { if ($this->orderid) {
$check_count = Coupon::where('orderid', $this->orderid) $check_count = Coupon::where('orderid', $this->orderid)
->where('outletId', $this->outletId) ->where('outletId', $this->outletId)
->where('total', $this->total) ->where('total', $this->total)
->where('status', 2) ->where('status', 2)
->where('created_at', '>=', now()->subMinutes(3)->format('Y-m-d H:i:s')) ->where('created_at', '>=', now()->subMinutes(3)->format('Y-m-d H:i:s'))
->count(); ->count();
} else { } else {
$check_count = Coupon::where('outletId', $this->outletId) $check_count = Coupon::where('outletId', $this->outletId)
->where('total', $this->total) ->where('total', $this->total)
->where('status', 2) ->where('status', 2)
->where('created_at', '>=', now()->subMinutes(3)->format('Y-m-d H:i:s')) ->where('created_at', '>=', now()->subMinutes(3)->format('Y-m-d H:i:s'))
->count(); ->count();
} }
$count = floor($this->total / 100); $count = floor($this->total / 100);
if ($check_count > 0) { if ($check_count > 0) {
if ($this->total < 100) { // if ($this->total < 100) {
return '核销失败订单金额少于100只能核销一张优惠券。'; // return '核销失败订单金额少于100只能核销一张优惠券。';
} // }
if ($check_count >= $count) { if ($check_count >= $count) {
return "核销失败,此订单您只能使用 {$count} 张优惠券"; return "核销失败,此订单您只能使用 {$count} 张优惠券";
} }
@@ -173,10 +182,10 @@ class Init
public function HasCheck() public function HasCheck()
{ {
$info = Coupon::where('redemptionCode', $this->redemptionCode) $info = Coupon::where('redemptionCode', $this->redemptionCode)
->where('outletId', $this->outletId) ->where('outletId', $this->outletId)
->where('total', $this->total) ->where('total', $this->total)
->where('status', 2) ->where('status', 2)
->first(); ->first();
if ($info) { if ($info) {
return '核销失败,此优惠券已被使用'; return '核销失败,此优惠券已被使用';
} }

View File

@@ -11,9 +11,6 @@ class Verification extends PingAnInit
public $ticket; public $ticket;
//查询到的卡券规则和商品id
public $queryData;
public function start() public function start()
{ {
//检查是否已经核销过 //检查是否已经核销过
@@ -22,16 +19,10 @@ class Verification extends PingAnInit
return $res; return $res;
} }
//检查可核销次数
$ret = $this->CheckCount();
if ($ret !== true) {
return $ret;
}
//查询卡券信息 //查询卡券信息
$this->query_coupon = (new Query)->setOutletId($this->outletId) $this->query_coupon = (new Query)->setOutletId($this->outletId)
->setCode($this->redemptionCode) ->setCode($this->redemptionCode)
->start(); ->start();
if (is_string($this->query_coupon)) { if (is_string($this->query_coupon)) {
return $this->query_coupon; return $this->query_coupon;
} }
@@ -42,6 +33,12 @@ class Verification extends PingAnInit
return $ticket; return $ticket;
} }
//检查可核销次数
$ret = $this->CheckCount();
if ($ret !== true) {
return $ret;
}
//增加核销记录 //增加核销记录
$coupon = $this->AddCoupon(); $coupon = $this->AddCoupon();
if (is_string($coupon)) { if (is_string($coupon)) {