From 51278dc9c5521863cbca92567596e34fc05c4d48 Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Fri, 20 May 2022 13:33:49 +0800 Subject: [PATCH] admin UserVipController --- app/Admin/Controllers/UserVipController.php | 32 ++++++++++++------- app/Admin/Controllers/VipController.php | 9 ------ .../Api/Http/Resources/UserVipResource.php | 2 +- app/Models/UserVip.php | 6 ++-- app/Providers/AppServiceProvider.php | 1 + app/Services/VipService.php | 7 ++-- ...05_20_131910_add_exipired_to_user_vips.php | 32 +++++++++++++++++++ resources/lang/zh_CN/user-vip.php | 4 ++- 8 files changed, 66 insertions(+), 27 deletions(-) create mode 100644 database/migrations/2022_05_20_131910_add_exipired_to_user_vips.php diff --git a/app/Admin/Controllers/UserVipController.php b/app/Admin/Controllers/UserVipController.php index 4364adab..a53c8aae 100644 --- a/app/Admin/Controllers/UserVipController.php +++ b/app/Admin/Controllers/UserVipController.php @@ -2,7 +2,7 @@ namespace App\Admin\Controllers; -use App\Models\UserVip; +use App\Models\{UserVip, Vip}; use Dcat\Admin\Form; use Dcat\Admin\Grid; use Dcat\Admin\Show; @@ -17,22 +17,24 @@ class UserVipController extends AdminController */ protected function grid() { - return Grid::make(UserVip::with(['user', 'vip']), function (Grid $grid) { + return Grid::make(UserVip::with(['user']), function (Grid $grid) { - $grid->model()->where('status', UserVip::STATUS_SUCCESS); + $grid->model()->where('status', UserVip::STATUS_SUCCESS)->latest('created_at'); $grid->column('user.phone'); - $grid->column('vip.name'); + $grid->column('name'); $grid->column('times')->display(function ($v) { return data_get($v, 'text'); }); + $grid->column('price'); $grid->column('success_time'); - $grid->column('created_at'); + $grid->column('expired'); $grid->disableViewButton(false); $grid->filter(function (Grid\Filter $filter) { $filter->panel(false); + $filter->like('user.phone')->width(3); $filter->like('name')->width(3); }); }); @@ -47,16 +49,24 @@ class UserVipController extends AdminController */ protected function detail($id) { - return Show::make($id, UserVip::with(['user', 'vip']), function (Show $show) { + return Show::make($id, UserVip::with(['user', 'vip', 'pay']), function (Show $show) { $show->field('id'); - $show->field('user_id'); - $show->field('vip_id'); + $show->field('user.phone', '用户'); + $show->field('vip.name', '会员卡'); $show->field('times')->as(function ($v) { return data_get($v, 'text'); - });; + }); $show->field('success_time'); - $show->field('created_at'); - $show->field('updated_at'); + + $show->field('pay.pay_sn', '订单号'); + $show->field('pay.pay_way', '支付方式')->as(function ($value) { + return $this->pay->pay_way->text(); + }); + + $show->panel()->tools(function ($tools) { + $tools->disableEdit(); + $tools->disableDelete(); + }); }); } diff --git a/app/Admin/Controllers/VipController.php b/app/Admin/Controllers/VipController.php index a453754d..d119461a 100644 --- a/app/Admin/Controllers/VipController.php +++ b/app/Admin/Controllers/VipController.php @@ -96,13 +96,4 @@ class VipController extends AdminController }); }); } - - public function destroy($id) - { - $vip = Vip::findOrFail($id); - if ($vip->hasUser()) { - throw new BizException(__('vip.options.deny_message')); - } - return parent::destroy($id); - } } diff --git a/app/Endpoint/Api/Http/Resources/UserVipResource.php b/app/Endpoint/Api/Http/Resources/UserVipResource.php index 68a0c426..c3ee1ebf 100644 --- a/app/Endpoint/Api/Http/Resources/UserVipResource.php +++ b/app/Endpoint/Api/Http/Resources/UserVipResource.php @@ -16,7 +16,7 @@ class UserVipResource extends JsonResource 'price' => (int)$this->price, 'gift' => $this->gift, 'status' => $this->status, - 'success_time' => $this->success_time, + 'success_time' => $this->success_time->format('Y-m-d'), ]; } } diff --git a/app/Models/UserVip.php b/app/Models/UserVip.php index 0962c719..c7230721 100644 --- a/app/Models/UserVip.php +++ b/app/Models/UserVip.php @@ -14,13 +14,15 @@ class UserVip extends Model const STATUS_SUCCESS = 1; const STATUS_PROCESSING = 2; - protected $fillable = ['user_id', 'vip_id', 'name', 'price', 'times', 'gift', 'status', 'success_time']; + protected $fillable = ['user_id', 'vip_id', 'name', 'price', 'times', 'gift', 'status', 'expired', 'success_time']; protected $casts = [ 'times' => 'json', - 'gift' => 'json' + 'gift' => 'json', ]; + protected $dates = ['success_time', 'expired']; + public static $statusMap = [ self::STATUS_UNPAID => '待付款', self::STATUS_SUCCESS => '已付款', diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 4071b62d..63cc7904 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -55,6 +55,7 @@ class AppServiceProvider extends ServiceProvider 'wallet_to_bank_log' => \App\Models\WalletToBankLog::class, 'balance_log' => \App\Models\BalanceLog::class, 'admin_users' => \App\Models\Admin\Administrator::class, + 'user_vip' => \App\Models\UserVip::class, ]); JsonResource::withoutWrapping(); diff --git a/app/Services/VipService.php b/app/Services/VipService.php index 0bd68d09..14cacb38 100644 --- a/app/Services/VipService.php +++ b/app/Services/VipService.php @@ -37,9 +37,7 @@ class VipService $userVip->update([ 'status' => 2 ]); - $pay_log = PayLog::create([ - 'payable_type' => UserVip::class, - 'payable_id' => $userVip->id, + $pay_log = $userVip->pay()->create([ 'pay_sn' => serial_number(), 'pay_way' => $pay_way ]); @@ -83,6 +81,9 @@ class VipService ]); $user = $userVip->user; $vip_expired = $this->convertTimes(data_get($userVip->times, 'num'), data_get($userVip->times, 'unit'), $user->vip_expired); + $userVip->update([ + 'expired' => $vip_expired + ]); $userVip->user->update([ 'vip_expired' => $vip_expired ]); diff --git a/database/migrations/2022_05_20_131910_add_exipired_to_user_vips.php b/database/migrations/2022_05_20_131910_add_exipired_to_user_vips.php new file mode 100644 index 00000000..6cbf763f --- /dev/null +++ b/database/migrations/2022_05_20_131910_add_exipired_to_user_vips.php @@ -0,0 +1,32 @@ +timestamp('expired')->nullable()->comment('购买后的会员有效期'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('user_vips', function (Blueprint $table) { + $table->dropColumn(['expired']); + }); + } +} diff --git a/resources/lang/zh_CN/user-vip.php b/resources/lang/zh_CN/user-vip.php index f8d95616..935b72b0 100644 --- a/resources/lang/zh_CN/user-vip.php +++ b/resources/lang/zh_CN/user-vip.php @@ -14,7 +14,9 @@ return [ ], 'vip' => [ 'name' => '会员卡' - ] + ], + 'expired' => '会员有效期', + 'price' => '价格', ], 'options' => [ ],