Admin 会员卡-优惠券-可配置数量
parent
95afc270c3
commit
62754116a3
|
|
@ -86,8 +86,29 @@ class VipController extends AdminController
|
||||||
$form->number('sort')->min(0);
|
$form->number('sort')->min(0);
|
||||||
$form->switch('status')->default(1);
|
$form->switch('status')->default(1);
|
||||||
$form->textarea('description');
|
$form->textarea('description');
|
||||||
$form->embeds('gift', function ($form) {
|
|
||||||
$form->multipleSelect('coupon')->options(Coupon::class)->ajax('api/coupons');
|
$form->table('coupon', function ($table) {
|
||||||
|
$table->select('id', '优惠券')->options(Coupon::class)->ajax('api/coupons');
|
||||||
|
$table->number('amount', '数量')->min(1)->default(1);
|
||||||
|
})->customFormat(fn() => data_get($this->gift, 'coupon'));
|
||||||
|
|
||||||
|
$form->hidden('gift')->customFormat(fn($v) => json_encode($v));
|
||||||
|
|
||||||
|
$form->saving(function (Form $form) {
|
||||||
|
$gift = $form->model()?->gift ?: [];
|
||||||
|
if ($form->coupon) {
|
||||||
|
// [id, amount, name]
|
||||||
|
$couponList = [];
|
||||||
|
foreach($form->coupon as $item) {
|
||||||
|
if (!data_get($item, '_remove_') && $item['amount'] > 0) {
|
||||||
|
$coupon = Coupon::findOrFail($item['id']);
|
||||||
|
array_push($couponList, ['id' => $coupon->id, 'amount' => $item['amount'], 'name' => $coupon->name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$gift['coupon'] = $couponList;
|
||||||
|
}
|
||||||
|
$form->gift = $gift;
|
||||||
|
$form->deleteInput('coupon');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Exceptions\BizException;
|
||||||
use App\Models\Activity;
|
use App\Models\Activity;
|
||||||
use App\Models\Coupon;
|
use App\Models\Coupon;
|
||||||
use App\Models\ProductPart;
|
use App\Models\ProductPart;
|
||||||
|
|
|
||||||
|
|
@ -102,11 +102,16 @@ class VipService
|
||||||
$user = $userVip->user;
|
$user = $userVip->user;
|
||||||
$gift = $userVip->gift;
|
$gift = $userVip->gift;
|
||||||
// 优惠券
|
// 优惠券
|
||||||
if (isset($gift['coupon'])) {
|
if (isset($gift['coupon']) && $gift['coupon']) {
|
||||||
$coupon_service = new CouponService();
|
$coupon_service = new CouponService();
|
||||||
foreach(Coupon::whereIn('id', $gift['coupon'])->get() as $item) {
|
$couponId = array_column($gift['coupon'], 'id');
|
||||||
|
foreach(Coupon::whereIn('id', $couponId)->get() as $item) {
|
||||||
try {
|
try {
|
||||||
$coupon_service->sendCoupon($user, $item);
|
$couponItem = array_filter($gift['coupon'], fn($v) => $v['id'] == $item->id);
|
||||||
|
$amount = data_get($couponItem, 'amount', 1);
|
||||||
|
if ($amount > 0) {
|
||||||
|
$coupon_service->sendCoupon($user, $item);
|
||||||
|
}
|
||||||
} catch (BizException $e) {
|
} catch (BizException $e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -116,7 +121,7 @@ class VipService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 延长时限
|
* 延长时限
|
||||||
*
|
*
|
||||||
* @param int $num 数量
|
* @param int $num 数量
|
||||||
* @param string $unit 单位
|
* @param string $unit 单位
|
||||||
* @return Carbon
|
* @return Carbon
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<!--
|
<!--
|
||||||
模板中接收以下三个变量:
|
模板中接收以下三个变量:
|
||||||
name 字段名称
|
name 字段名称
|
||||||
value 字段值
|
value 字段值
|
||||||
|
|
@ -6,13 +6,14 @@
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@if($value)
|
@if($value)
|
||||||
<div class="list-group">
|
@foreach($value as $key => $list)
|
||||||
@if($value['coupon'])
|
<div class="list-group">
|
||||||
<div class="list-group-item">优惠券
|
@foreach($list as $item)
|
||||||
@foreach(\App\Models\Coupon::whereIn('id', $value['coupon'])->get() as $item)
|
<div class="list-group-item">
|
||||||
<span class="label bg-primary">{{ $item->name }}</span>
|
{{ $item['name'] }}
|
||||||
|
<span class="badge bg-primary">{{ $item['amount'] }}</span>
|
||||||
|
</div>
|
||||||
@endforeach
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endforeach
|
||||||
</div>
|
|
||||||
@endif
|
@endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue