增加实物兑换校验

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

@@ -1,188 +1,197 @@
<?php <?php
namespace XuanChen\Coupon\Action; namespace XuanChen\Coupon\Action;
use App\Models\Coupon; use App\Models\Coupon;
use App\Models\Log as LogModel; use App\Models\Log as LogModel;
class Init class Init
{ {
//渠道 //渠道
public $user; public $user;
//卡券编号 //卡券编号
public $redemptionCode; public $redemptionCode;
//订单金额 //订单金额
public $total; public $total;
//网点编号 //网点编号
public $outletId; public $outletId;
//活动id //活动id
public $activityId; public $activityId;
//手机号 //手机号
public $mobile; public $mobile;
//核销的卡券 创建的核销记录 //核销的卡券 创建的核销记录
public $coupon; public $coupon;
//查询返回卡券信息 //查询返回卡券信息
public $query_coupon; public $query_coupon;
//订单id //订单id
public $orderid; public $orderid;
//设置渠道 //查询到的卡券规则和商品id 只有平安券才有
public function setUser($user) public $queryData;
{
$this->user = $user; //设置渠道
public function setUser($user)
return $this; {
} $this->user = $user;
//设置渠道 return $this;
public function setOrderId($orderid) }
{
$this->orderid = $orderid; //设置渠道
public function setOrderId($orderid)
return $this; {
} $this->orderid = $orderid;
//设置核销码 return $this;
public function setCode($redemptionCode) }
{
$this->redemptionCode = $redemptionCode; //设置核销码
public function setCode($redemptionCode)
return $this; {
$this->redemptionCode = $redemptionCode;
}
return $this;
//设置订单总额
public function setTotal($total) }
{
$this->total = $total; //设置订单总额
public function setTotal($total)
return $this; {
$this->total = $total;
}
return $this;
//设置网点id
public function setOutletId($outletId) }
{
$this->outletId = $outletId; //设置网点id
public function setOutletId($outletId)
return $this; {
$this->outletId = $outletId;
}
return $this;
//设置活动id
public function setActivityId($activityId) }
{
$this->activityId = $activityId; //设置活动id
public function setActivityId($activityId)
return $this; {
$this->activityId = $activityId;
}
return $this;
//设置手机号
public function setMobile($mobile) }
{
$this->mobile = $mobile; //设置手机号
public function setMobile($mobile)
return $this; {
$this->mobile = $mobile;
}
return $this;
/**
* Notes: 插入日志 }
* @Author: 玄尘
* @Date : 2020/6/30 10:29 /**
* @param $url * Notes: 插入日志
* @param $method * @Author: 玄尘
* @param $params * @Date : 2020/6/30 10:29
* @param string $type * @param $url
* @return mixed * @param $method
*/ * @param $params
public function createLog($url, $method, $params, $type = 'pingan') * @param string $type
{ * @return mixed
$data = [ */
'path' => $url, public function createLog($url, $method, $params, $type = 'pingan')
'method' => $method, {
'type' => $type, $data = [
'in_source' => $params, 'path' => $url,
]; 'method' => $method,
'type' => $type,
$info = LogModel::create($data); 'in_source' => $params,
];
return $info;
} $info = LogModel::create($data);
/** return $info;
* Notes: 更新日志 }
* @Author: 玄尘
* @Date : 2020/6/30 10:29 /**
* @param $log * Notes: 更新日志
* @param $params * @Author: 玄尘
*/ * @Date : 2020/6/30 10:29
public static function updateLog($log, $params) * @param $log
{ * @param $params
$log->out_source = $params; */
$log->save(); public static function updateLog($log, $params)
} {
$log->out_source = $params;
//统一门店 相同金额 3分钟之内看作是一笔订单 $log->save();
public function CheckCount() }
{
if ($this->orderid) { //统一门店 相同金额 3分钟之内看作是一笔订单
$check_count = Coupon::where('orderid', $this->orderid) public function CheckCount()
->where('outletId', $this->outletId) {
->where('total', $this->total) if ($this->queryData) {
->where('status', 2) if (isset($this->queryData['thirdPartyGoodsId']) && $this->queryData['thirdPartyGoodsId'] == 'YSD-full0-0') {
->where('created_at', '>=', now()->subMinutes(3)->format('Y-m-d H:i:s')) return true;
->count(); }
} else { }
$check_count = Coupon::where('outletId', $this->outletId)
->where('total', $this->total) if ($this->orderid) {
->where('status', 2) $check_count = Coupon::where('orderid', $this->orderid)
->where('created_at', '>=', now()->subMinutes(3)->format('Y-m-d H:i:s')) ->where('outletId', $this->outletId)
->count(); ->where('total', $this->total)
} ->where('status', 2)
->where('created_at', '>=', now()->subMinutes(3)->format('Y-m-d H:i:s'))
$count = floor($this->total / 100); ->count();
} else {
if ($check_count > 0) { $check_count = Coupon::where('outletId', $this->outletId)
if ($this->total < 100) { ->where('total', $this->total)
return '核销失败订单金额少于100只能核销一张优惠券。'; ->where('status', 2)
} ->where('created_at', '>=', now()->subMinutes(3)->format('Y-m-d H:i:s'))
if ($check_count >= $count) { ->count();
return "核销失败,此订单您只能使用 {$count} 张优惠券"; }
}
} $count = floor($this->total / 100);
return true; if ($check_count > 0) {
} // if ($this->total < 100) {
// return '核销失败订单金额少于100只能核销一张优惠券。';
/** // }
* Notes: 校验是否已经核销过 if ($check_count >= $count) {
* @Author: 玄尘 return "核销失败,此订单您只能使用 {$count} 张优惠券";
* @Date : 2020/8/8 13:43 }
*/ }
public function HasCheck()
{ return true;
$info = Coupon::where('redemptionCode', $this->redemptionCode) }
->where('outletId', $this->outletId)
->where('total', $this->total) /**
->where('status', 2) * Notes: 校验是否已经核销过
->first(); * @Author: 玄尘
if ($info) { * @Date : 2020/8/8 13:43
return '核销失败,此优惠券已被使用'; */
} public function HasCheck()
{
return false; $info = Coupon::where('redemptionCode', $this->redemptionCode)
->where('outletId', $this->outletId)
} ->where('total', $this->total)
->where('status', 2)
} ->first();
if ($info) {
return '核销失败,此优惠券已被使用';
}
return false;
}
}

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)) {