完善作废接口
This commit is contained in:
@@ -129,8 +129,10 @@ class UserController extends Controller
|
|||||||
|
|
||||||
$validator = \Validator::make($res, [
|
$validator = \Validator::make($res, [
|
||||||
'redemptionCode' => 'required',
|
'redemptionCode' => 'required',
|
||||||
|
'outletId' => 'required',
|
||||||
], [
|
], [
|
||||||
'redemptionCode.required' => '缺少卡券兑换码',
|
'redemptionCode.required' => '缺少卡券兑换码',
|
||||||
|
'outletId.required' => '缺少网点id',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
@@ -138,8 +140,8 @@ class UserController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$redemptionCode = $res['redemptionCode'];
|
$redemptionCode = $res['redemptionCode'];
|
||||||
|
$outletId = $res['outletId'];
|
||||||
$res = Coupon::Destroy($redemptionCode);
|
$res = Coupon::Destroy($redemptionCode, $outletId);
|
||||||
|
|
||||||
if ($res !== true) {
|
if ($res !== true) {
|
||||||
return $this->error($res, $log);
|
return $this->error($res, $log);
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ class YsdAction extends Init implements CouponContracts
|
|||||||
public function destroy()
|
public function destroy()
|
||||||
{
|
{
|
||||||
return $res = (new YsdDestroy)->setCode($this->redemptionCode)
|
return $res = (new YsdDestroy)->setCode($this->redemptionCode)
|
||||||
|
->setOutletId($this->outletId)
|
||||||
->start();
|
->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace XuanChen\Coupon\Action\ysd;
|
namespace XuanChen\Coupon\Action\ysd;
|
||||||
|
|
||||||
use App\Models\ActivityCoupon;
|
use App\Models\ActivityCoupon;
|
||||||
|
use App\Models\User;
|
||||||
use XuanChen\Coupon\Action\Init;
|
use XuanChen\Coupon\Action\Init;
|
||||||
|
|
||||||
class YsdDestroy extends Init
|
class YsdDestroy extends Init
|
||||||
@@ -12,11 +13,31 @@ class YsdDestroy extends Init
|
|||||||
{
|
{
|
||||||
if ($this->redemptionCode) {
|
if ($this->redemptionCode) {
|
||||||
try {
|
try {
|
||||||
|
if (!$this->outletId) {
|
||||||
|
throw new \Exception('缺少网点id');
|
||||||
|
}
|
||||||
|
|
||||||
$info = ActivityCoupon::where('code', $this->redemptionCode)->first();
|
$info = ActivityCoupon::where('code', $this->redemptionCode)->first();
|
||||||
|
|
||||||
if (!$info) {
|
if (!$info) {
|
||||||
throw new \Exception('未查询到卡券信息');
|
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()) {
|
if (!$info->canDestroy()) {
|
||||||
throw new \Exception('作废失败,' . $info->status_text . '不能操作');
|
throw new \Exception('作废失败,' . $info->status_text . '不能操作');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,12 +56,12 @@ class Coupon
|
|||||||
/**
|
/**
|
||||||
* Notes: 卡券作废
|
* Notes: 卡券作废
|
||||||
* @Author: 玄尘
|
* @Author: 玄尘
|
||||||
* @Date : 2020/7/21 13:49
|
* @Date : 2020/9/2 16:54
|
||||||
* @param $redemptionCode
|
* @param $redemptionCode
|
||||||
|
* @param $outletId
|
||||||
* @return string
|
* @return string
|
||||||
* @throws \Exception
|
|
||||||
*/
|
*/
|
||||||
public static function Destroy($redemptionCode)
|
public static function Destroy($redemptionCode, $outletId)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$model = self::getModelByCode($redemptionCode);
|
$model = self::getModelByCode($redemptionCode);
|
||||||
@@ -69,7 +69,9 @@ class Coupon
|
|||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $model->setCode($redemptionCode)->destroy();
|
return $model->setCode($redemptionCode)
|
||||||
|
->setOutletId($outletId)
|
||||||
|
->destroy();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user