diff --git a/app/Admin/Controllers/VipController.php b/app/Admin/Controllers/VipController.php index 386f2c89..24f9f32c 100644 --- a/app/Admin/Controllers/VipController.php +++ b/app/Admin/Controllers/VipController.php @@ -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(' 下载小程序码'); } @@ -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']); }); }); } diff --git a/app/Services/VipService.php b/app/Services/VipService.php index ea6c373c..ce9afbe4 100644 --- a/app/Services/VipService.php +++ b/app/Services/VipService.php @@ -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, + ); + } } /** diff --git a/resources/views/admin/vip/gift.blade.php b/resources/views/admin/vip/gift.blade.php index ea94084e..1fbef780 100644 --- a/resources/views/admin/vip/gift.blade.php +++ b/resources/views/admin/vip/gift.blade.php @@ -6,21 +6,29 @@ --> @if($value) - @foreach($value as $key => $list)