6
0
Fork 0

admin UserVipController

release
panliang 2022-05-20 13:33:49 +08:00
parent 68404f3c9b
commit 51278dc9c5
8 changed files with 66 additions and 27 deletions

View File

@ -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();
});
});
}

View File

@ -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);
}
}

View File

@ -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'),
];
}
}

View File

@ -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 => '已付款',

View File

@ -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();

View File

@ -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
]);

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddExipiredToUserVips extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('user_vips', function (Blueprint $table) {
$table->timestamp('expired')->nullable()->comment('购买后的会员有效期');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('user_vips', function (Blueprint $table) {
$table->dropColumn(['expired']);
});
}
}

View File

@ -14,7 +14,9 @@ return [
],
'vip' => [
'name' => '会员卡'
]
],
'expired' => '会员有效期',
'price' => '价格',
],
'options' => [
],