完善作废接口

This commit is contained in:
2020-09-02 17:08:28 +08:00
parent 29d3c3fb3d
commit 71aba4e876
4 changed files with 33 additions and 7 deletions

View File

@@ -129,8 +129,10 @@ class UserController extends Controller
$validator = \Validator::make($res, [
'redemptionCode' => 'required',
'outletId' => 'required',
], [
'redemptionCode.required' => '缺少卡券兑换码',
'outletId.required' => '缺少网点id',
]);
if ($validator->fails()) {
@@ -138,8 +140,8 @@ class UserController extends Controller
}
$redemptionCode = $res['redemptionCode'];
$res = Coupon::Destroy($redemptionCode);
$outletId = $res['outletId'];
$res = Coupon::Destroy($redemptionCode, $outletId);
if ($res !== true) {
return $this->error($res, $log);

View File

@@ -68,6 +68,7 @@ class YsdAction extends Init implements CouponContracts
public function destroy()
{
return $res = (new YsdDestroy)->setCode($this->redemptionCode)
->setOutletId($this->outletId)
->start();
}

View File

@@ -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 . '不能操作');
}

View File

@@ -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();
}