Admin 会员卡-优惠券-可配置数量
parent
95afc270c3
commit
62754116a3
|
|
@ -86,8 +86,29 @@ class VipController extends AdminController
|
|||
$form->number('sort')->min(0);
|
||||
$form->switch('status')->default(1);
|
||||
$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;
|
||||
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\Activity;
|
||||
use App\Models\Coupon;
|
||||
use App\Models\ProductPart;
|
||||
|
|
|
|||
|
|
@ -102,11 +102,16 @@ class VipService
|
|||
$user = $userVip->user;
|
||||
$gift = $userVip->gift;
|
||||
// 优惠券
|
||||
if (isset($gift['coupon'])) {
|
||||
if (isset($gift['coupon']) && $gift['coupon']) {
|
||||
$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 {
|
||||
$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) {
|
||||
}
|
||||
}
|
||||
|
|
@ -116,7 +121,7 @@ class VipService
|
|||
|
||||
/**
|
||||
* 延长时限
|
||||
*
|
||||
*
|
||||
* @param int $num 数量
|
||||
* @param string $unit 单位
|
||||
* @return Carbon
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<!--
|
||||
<!--
|
||||
模板中接收以下三个变量:
|
||||
name 字段名称
|
||||
value 字段值
|
||||
|
|
@ -6,13 +6,14 @@
|
|||
-->
|
||||
|
||||
@if($value)
|
||||
<div class="list-group">
|
||||
@if($value['coupon'])
|
||||
<div class="list-group-item">优惠券
|
||||
@foreach(\App\Models\Coupon::whereIn('id', $value['coupon'])->get() as $item)
|
||||
<span class="label bg-primary">{{ $item->name }}</span>
|
||||
@foreach($value as $key => $list)
|
||||
<div class="list-group">
|
||||
@foreach($list as $item)
|
||||
<div class="list-group-item">
|
||||
{{ $item['name'] }}
|
||||
<span class="badge bg-primary">{{ $item['amount'] }}</span>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@endforeach
|
||||
@endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue