vip-coupon
parent
6b4c363a68
commit
41a6f3f5d0
|
|
@ -3,7 +3,7 @@
|
|||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\Vip;
|
||||
use App\Models\{Vip, Coupon};
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
|
|
@ -32,12 +32,9 @@ class VipController extends AdminController
|
|||
|
||||
$grid->disableViewButton(false);
|
||||
//新增
|
||||
if (Admin::user()->can('dcat.admin.vips.create')) {
|
||||
$grid->disableCreateButton(false);
|
||||
$grid->enableDialogCreate();
|
||||
}
|
||||
$grid->showCreateButton(Admin::user()->can('dcat.admin.vips.create'));
|
||||
//修改
|
||||
$grid->showQuickEditButton(Admin::user()->can('dcat.admin.vips.edit'));
|
||||
$grid->showEditButton(Admin::user()->can('dcat.admin.vips.edit'));
|
||||
//删除以及自定义操作
|
||||
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
||||
$actions->disableDelete(Admin::user()->cannot('dcat.admin.vips.destroy'));
|
||||
|
|
@ -93,6 +90,9 @@ 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::pluck('name', 'id'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\{User, Vip, UserVip, PayLog};
|
||||
use App\Models\{User, Vip, UserVip, PayLog, Coupon};
|
||||
use App\Exceptions\BizException;
|
||||
use App\Enums\{PayWay, SocialiteType, WxpayTradeType};
|
||||
use App\Services\Payment\WxpayService;
|
||||
|
|
@ -70,6 +70,11 @@ class VipService
|
|||
throw new BizException('未知的支付方式');
|
||||
}
|
||||
|
||||
/**
|
||||
* 购买成功
|
||||
* @param UserVip $userVip 购买记录
|
||||
* @param array $params {'pay_at':'购买时间'}
|
||||
*/
|
||||
public function success(UserVip $userVip, array $params = null)
|
||||
{
|
||||
$userVip->update([
|
||||
|
|
@ -81,10 +86,35 @@ class VipService
|
|||
$userVip->user->update([
|
||||
'vip_expired' => $vip_expired
|
||||
]);
|
||||
$this->gift($userVip);
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间转换
|
||||
* 发放赠品
|
||||
* @param UserVip $userVip 购买记录
|
||||
*/
|
||||
public function gift(UserVip $userVip)
|
||||
{
|
||||
if ($userVip->status != 1) {
|
||||
throw new BizException('请先购买');
|
||||
}
|
||||
$user = $userVip->user;
|
||||
$gift = $userVip->gift;
|
||||
// 优惠券
|
||||
if (isset($gift['coupon'])) {
|
||||
$coupon_service = new CouponService();
|
||||
foreach(Coupon::whereIn('id', $gift['coupon'])->get() as $item) {
|
||||
try {
|
||||
$coupon_service->sendCoupon($user, $item);
|
||||
} catch (BizException $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 延长时限
|
||||
*
|
||||
* @param int $num 数量
|
||||
* @param string $unit 单位
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ return [
|
|||
'price' => '价格',
|
||||
'status' => '状态',
|
||||
'description' => '描述',
|
||||
'coupon' => '优惠券',
|
||||
],
|
||||
'options' => [
|
||||
'deny' => '删除失败',
|
||||
|
|
|
|||
Loading…
Reference in New Issue