6
0
Fork 0

购买会员卡赠送积分

base
Jing Li 2023-11-13 10:53:37 +08:00
parent cd63ae1636
commit 5916ebcb72
3 changed files with 47 additions and 18 deletions

View File

@ -62,7 +62,6 @@ class VipController extends AdminController
$grid->column('status')->switch();
$grid->tools(function (Grid\Tools $tools) {
// x
if (Admin::user()->can('dcat.admin.vip.mp_qrcode')) {
$tools->append('<a class="btn btn-primary btn-outline" href="'.route('dcat.admin.vip.mp_qrcode').'" target="_blank"><i class="feather grid-action-icon icon-download"></i>&nbsp;下载小程序码</a>');
}
@ -125,6 +124,9 @@ class VipController extends AdminController
$form->switch('status')->default(1);
$form->textarea('description');
$form->currency('points', '赠送积分')
->symbol('¥')
->customFormat(fn () => data_get($this->gift, 'points'));
$form->table('coupon', function ($table) {
$table->select('id', '优惠券')->options(Coupon::class)->ajax('api/coupons');
$table->number('amount', '数量')->min(1)->default(1);
@ -138,6 +140,14 @@ class VipController extends AdminController
$form->saving(function (Form $form) {
$gift = $form->model()?->gift ?: [];
$points = str_replace(',', '', $form->input('points'));
if ($points > 0) {
$gift['points'] = $points;
} else {
unset($gift['points']);
}
if ($form->coupon) {
// [id, amount, name]
$couponList = [];
@ -149,8 +159,9 @@ class VipController extends AdminController
}
$gift['coupon'] = $couponList;
}
$form->gift = $gift;
$form->deleteInput('coupon');
$form->deleteInput(['points', 'coupon']);
});
});
}

View File

@ -2,9 +2,10 @@
namespace App\Services;
use App\Models\{User, Vip, UserVip, PayLog, Coupon};
use App\Exceptions\BizException;
use App\Enums\PointLogAction;
use App\Enums\{PayWay, SocialiteType, WxpayTradeType};
use App\Exceptions\BizException;
use App\Models\{User, Vip, UserVip, PayLog, Coupon};
use App\Services\Payment\WxpayService;
use Carbon\Carbon;
@ -128,6 +129,15 @@ class VipService
}
}
if (isset($gift['points']) && bccomp($gift['points'], 0, 2) === 1) {
(new PointService())->change(
$user,
bcmul($gift['points'], 100),
PointLogAction::Recharge,
"购买会员卡【{$userVip->name}】赠送积分",
$userVip,
);
}
}
/**

View File

@ -6,9 +6,10 @@
-->
@if($value)
@foreach($value as $key => $list)
<div class="list-group">
@foreach($list as $item)
@foreach($value as $k => $v)
@if ($k === 'coupon')
@foreach($v as $item)
@if(is_array($item))
<div class="list-group-item">
{{ $item['name'] }}
@ -21,6 +22,13 @@
</div>
@endif
@endforeach
@elseif ($k === 'points')
<div class="list-group-item">
积分
<span class="badge bg-primary">{{ $v }}</span>
</div>
@endif
@endforeach
</div>
@endif