完善作废接口
This commit is contained in:
@@ -68,6 +68,7 @@ class YsdAction extends Init implements CouponContracts
|
||||
public function destroy()
|
||||
{
|
||||
return $res = (new YsdDestroy)->setCode($this->redemptionCode)
|
||||
->setOutletId($this->outletId)
|
||||
->start();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace XuanChen\Coupon\Action\ysd;
|
||||
|
||||
use App\Models\ActivityCoupon;
|
||||
use App\Models\User;
|
||||
use XuanChen\Coupon\Action\Init;
|
||||
|
||||
class YsdDestroy extends Init
|
||||
@@ -12,11 +13,31 @@ class YsdDestroy extends Init
|
||||
{
|
||||
if ($this->redemptionCode) {
|
||||
try {
|
||||
if (!$this->outletId) {
|
||||
throw new \Exception('缺少网点id');
|
||||
}
|
||||
|
||||
$info = ActivityCoupon::where('code', $this->redemptionCode)->first();
|
||||
|
||||
if (!$info) {
|
||||
throw new \Exception('未查询到卡券信息');
|
||||
}
|
||||
|
||||
$outlet = User::where('outlet_id', $this->outletId)->first();
|
||||
|
||||
if (empty($outlet)) {
|
||||
return '作废失败,未查询到此网点信息。';
|
||||
}
|
||||
|
||||
$grants = $info->activity->grants()->pluck('user_id');
|
||||
if ($grants->isEmpty()) {
|
||||
return '作废失败,此活动还没有配置可发券渠道,请联系相关人员进行配置。';
|
||||
}
|
||||
|
||||
if (!in_array($outlet->parent_id, $grants->toArray())) {
|
||||
return '作废失败,您没有权限发此类优惠券。';
|
||||
}
|
||||
|
||||
if (!$info->canDestroy()) {
|
||||
throw new \Exception('作废失败,' . $info->status_text . '不能操作');
|
||||
}
|
||||
|
||||
@@ -56,12 +56,12 @@ class Coupon
|
||||
/**
|
||||
* Notes: 卡券作废
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/7/21 13:49
|
||||
* @Date : 2020/9/2 16:54
|
||||
* @param $redemptionCode
|
||||
* @param $outletId
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function Destroy($redemptionCode)
|
||||
public static function Destroy($redemptionCode, $outletId)
|
||||
{
|
||||
try {
|
||||
$model = self::getModelByCode($redemptionCode);
|
||||
@@ -69,7 +69,9 @@ class Coupon
|
||||
return $model;
|
||||
}
|
||||
|
||||
return $model->setCode($redemptionCode)->destroy();
|
||||
return $model->setCode($redemptionCode)
|
||||
->setOutletId($outletId)
|
||||
->destroy();
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user