admin UserVipController
parent
68404f3c9b
commit
51278dc9c5
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App\Admin\Controllers;
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
use App\Models\UserVip;
|
use App\Models\{UserVip, Vip};
|
||||||
use Dcat\Admin\Form;
|
use Dcat\Admin\Form;
|
||||||
use Dcat\Admin\Grid;
|
use Dcat\Admin\Grid;
|
||||||
use Dcat\Admin\Show;
|
use Dcat\Admin\Show;
|
||||||
|
|
@ -17,22 +17,24 @@ class UserVipController extends AdminController
|
||||||
*/
|
*/
|
||||||
protected function grid()
|
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('user.phone');
|
||||||
$grid->column('vip.name');
|
$grid->column('name');
|
||||||
$grid->column('times')->display(function ($v) {
|
$grid->column('times')->display(function ($v) {
|
||||||
return data_get($v, 'text');
|
return data_get($v, 'text');
|
||||||
});
|
});
|
||||||
|
$grid->column('price');
|
||||||
$grid->column('success_time');
|
$grid->column('success_time');
|
||||||
$grid->column('created_at');
|
$grid->column('expired');
|
||||||
|
|
||||||
$grid->disableViewButton(false);
|
$grid->disableViewButton(false);
|
||||||
|
|
||||||
$grid->filter(function (Grid\Filter $filter) {
|
$grid->filter(function (Grid\Filter $filter) {
|
||||||
$filter->panel(false);
|
$filter->panel(false);
|
||||||
|
$filter->like('user.phone')->width(3);
|
||||||
$filter->like('name')->width(3);
|
$filter->like('name')->width(3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -47,16 +49,24 @@ class UserVipController extends AdminController
|
||||||
*/
|
*/
|
||||||
protected function detail($id)
|
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('id');
|
||||||
$show->field('user_id');
|
$show->field('user.phone', '用户');
|
||||||
$show->field('vip_id');
|
$show->field('vip.name', '会员卡');
|
||||||
$show->field('times')->as(function ($v) {
|
$show->field('times')->as(function ($v) {
|
||||||
return data_get($v, 'text');
|
return data_get($v, 'text');
|
||||||
});;
|
});
|
||||||
$show->field('success_time');
|
$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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class UserVipResource extends JsonResource
|
||||||
'price' => (int)$this->price,
|
'price' => (int)$this->price,
|
||||||
'gift' => $this->gift,
|
'gift' => $this->gift,
|
||||||
'status' => $this->status,
|
'status' => $this->status,
|
||||||
'success_time' => $this->success_time,
|
'success_time' => $this->success_time->format('Y-m-d'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,15 @@ class UserVip extends Model
|
||||||
const STATUS_SUCCESS = 1;
|
const STATUS_SUCCESS = 1;
|
||||||
const STATUS_PROCESSING = 2;
|
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 = [
|
protected $casts = [
|
||||||
'times' => 'json',
|
'times' => 'json',
|
||||||
'gift' => 'json'
|
'gift' => 'json',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected $dates = ['success_time', 'expired'];
|
||||||
|
|
||||||
public static $statusMap = [
|
public static $statusMap = [
|
||||||
self::STATUS_UNPAID => '待付款',
|
self::STATUS_UNPAID => '待付款',
|
||||||
self::STATUS_SUCCESS => '已付款',
|
self::STATUS_SUCCESS => '已付款',
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ class AppServiceProvider extends ServiceProvider
|
||||||
'wallet_to_bank_log' => \App\Models\WalletToBankLog::class,
|
'wallet_to_bank_log' => \App\Models\WalletToBankLog::class,
|
||||||
'balance_log' => \App\Models\BalanceLog::class,
|
'balance_log' => \App\Models\BalanceLog::class,
|
||||||
'admin_users' => \App\Models\Admin\Administrator::class,
|
'admin_users' => \App\Models\Admin\Administrator::class,
|
||||||
|
'user_vip' => \App\Models\UserVip::class,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
JsonResource::withoutWrapping();
|
JsonResource::withoutWrapping();
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,7 @@ class VipService
|
||||||
$userVip->update([
|
$userVip->update([
|
||||||
'status' => 2
|
'status' => 2
|
||||||
]);
|
]);
|
||||||
$pay_log = PayLog::create([
|
$pay_log = $userVip->pay()->create([
|
||||||
'payable_type' => UserVip::class,
|
|
||||||
'payable_id' => $userVip->id,
|
|
||||||
'pay_sn' => serial_number(),
|
'pay_sn' => serial_number(),
|
||||||
'pay_way' => $pay_way
|
'pay_way' => $pay_way
|
||||||
]);
|
]);
|
||||||
|
|
@ -83,6 +81,9 @@ class VipService
|
||||||
]);
|
]);
|
||||||
$user = $userVip->user;
|
$user = $userVip->user;
|
||||||
$vip_expired = $this->convertTimes(data_get($userVip->times, 'num'), data_get($userVip->times, 'unit'), $user->vip_expired);
|
$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([
|
$userVip->user->update([
|
||||||
'vip_expired' => $vip_expired
|
'vip_expired' => $vip_expired
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -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']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,9 @@ return [
|
||||||
],
|
],
|
||||||
'vip' => [
|
'vip' => [
|
||||||
'name' => '会员卡'
|
'name' => '会员卡'
|
||||||
]
|
],
|
||||||
|
'expired' => '会员有效期',
|
||||||
|
'price' => '价格',
|
||||||
],
|
],
|
||||||
'options' => [
|
'options' => [
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue