From 3428495fc87a35a0d7013a4a586b4723d3c47671 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Fri, 3 Dec 2021 15:52:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E5=9F=BA?= =?UTF-8?q?=E6=9C=AC=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Controllers/UserController.php | 117 ++++++++++++++++++ app/Admin/Controllers/VipController.php | 93 ++++++++++++++ app/Admin/Repositories/User.php | 52 ++++++++ app/Admin/Repositories/Vip.php | 16 +++ app/Admin/routes.php | 3 + app/Models/User.php | 2 + app/Models/UserVip.php | 11 ++ app/Models/Vip.php | 23 ++++ .../2021_12_03_135905_create_vips_table.php | 33 +++++ ...21_12_03_135913_create_user_vips_table.php | 34 +++++ database/seeders/AdminPermissionSeeder.php | 4 + dcat_admin_ide_helper.php | 28 ++++- resources/lang/zh_CN/user.php | 22 ++++ resources/lang/zh_CN/vip.php | 16 +++ 14 files changed, 450 insertions(+), 4 deletions(-) create mode 100644 app/Admin/Controllers/UserController.php create mode 100644 app/Admin/Controllers/VipController.php create mode 100644 app/Admin/Repositories/User.php create mode 100644 app/Admin/Repositories/Vip.php create mode 100644 app/Models/UserVip.php create mode 100644 app/Models/Vip.php create mode 100644 database/migrations/2021_12_03_135905_create_vips_table.php create mode 100644 database/migrations/2021_12_03_135913_create_user_vips_table.php create mode 100644 resources/lang/zh_CN/user.php create mode 100644 resources/lang/zh_CN/vip.php diff --git a/app/Admin/Controllers/UserController.php b/app/Admin/Controllers/UserController.php new file mode 100644 index 00000000..b0d4b460 --- /dev/null +++ b/app/Admin/Controllers/UserController.php @@ -0,0 +1,117 @@ +column('id')->sortable(); + $grid->column('username'); + // $grid->column('password'); + $grid->column('phone'); + $grid->column('email'); + $grid->column('last_login_ip'); + $grid->column('last_login_at')->sortable(); + $grid->column('register_ip'); + // $grid->column('remember_token'); + $grid->column('status')->using([1=>'正常', -1=>'禁用']) + ->dot([ + 1 => 'primary', + -1 => 'danger', + ]); + $grid->column('created_at'); + + /** 操作 **/ + //新增 + if (Admin::user()->can('dcat.admin.users.create')) { + $grid->disableCreateButton(false); + $grid->enableDialogCreate(); + } + //删除以及自定义操作 + $grid->actions(function (Grid\Displayers\Actions $actions) { + $actions->disableView(Admin::user()->cannot('dcat.admin.users.show')); + }); + + $grid->filter(function (Grid\Filter $filter) { + $filter->panel(); + $filter->like('username')->width(3); + $filter->like('phone')->width(3); + $filter->like('email')->width(3); + // $filter->equal('id'); + }); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + return function (Row $row) use ($id) { + $row->column(4, function ($column) use ($id) { + $column->row(Show::make($id, new User(), function (Show $show) { + $show->field('id'); + $show->field('username'); + $show->field('phone'); + $show->field('email'); + $show->field('last_login_ip'); + $show->field('last_login_at'); + $show->field('register_ip'); + $show->field('created_at'); + $show->field('updated_at'); + $show->panel() + ->tools(function ($tools) { + $tools->disableEdit(); + // $tools->disableList(); + $tools->disableDelete(); + // 显示快捷编辑按钮 + // $tools->showQuickEdit(); + }); + })); + }); + $row->column(5, function () { + }); + }; + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + return Form::make(new User(), function (Form $form) { + $form->display('id'); + $form->text('username'); + $form->mobile('phone')->rules('unique:users,phone'); + $form->email('email')->rules('unique:users,email'); + $form->password('password'); + // 设置错误信息 + $form->password('password_confirm')->same('password', '两次密码输入不一致'); + $form->ignore(['password_confirm']); + + $form->display('created_at'); + $form->display('updated_at'); + }); + } +} diff --git a/app/Admin/Controllers/VipController.php b/app/Admin/Controllers/VipController.php new file mode 100644 index 00000000..9bb99954 --- /dev/null +++ b/app/Admin/Controllers/VipController.php @@ -0,0 +1,93 @@ +column('id')->sortable(); + $grid->column('vip_name'); + $grid->column('vip_growth_value')->sortable(); + + $grid->model()->orderBy('vip_growth_value', 'asc'); + + /** 操作 **/ + //新增 + if (Admin::user()->can('dcat.admin.vips.create')) { + $grid->disableCreateButton(false); + $grid->enableDialogCreate(); + } + //修改 + $grid->showQuickEditButton(Admin::user()->can('dcat.admin.vips.edit')); + //删除以及自定义操作 + $grid->actions(function (Grid\Displayers\Actions $actions) { + $actions->disableDelete(Admin::user()->cannot('dcat.admin.vips.destroy')); + }); + + $grid->filter(function (Grid\Filter $filter) { + $filter->panel(false); + $filter->like('vip_name'); + }); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + return Show::make($id, new Vip(), function (Show $show) { + $show->field('id'); + $show->field('vip_name'); + $show->field('vip_growth_value'); + $show->field('created_at'); + $show->field('updated_at'); + }); + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + return Form::make(new Vip(), function (Form $form) { + $form->display('id'); + $form->text('vip_name')->required(); + $form->number('vip_growth_value')->default(0); + + $form->display('created_at'); + $form->display('updated_at'); + }); + } + + public function destroy($id) + { + $vip = VipModel::findOrFail($id); + if ($vip->hasUser()) { + throw new BizException(__('vip.options.deny_message')); + } + return parent::destroy($id); + } +} diff --git a/app/Admin/Repositories/User.php b/app/Admin/Repositories/User.php new file mode 100644 index 00000000..1bf3f5e7 --- /dev/null +++ b/app/Admin/Repositories/User.php @@ -0,0 +1,52 @@ +model(); + + $updates = $form->updates(); + + [$relations, $relationKeyMap] = $this->getRelationInputs($model, $updates); + + if ($relations) { + $updates = Arr::except($updates, array_keys($relationKeyMap)); + } + + // foreach ($updates as $column => $value) { + // $model->setAttribute($column, $value); + // } + + $result = $model::create($updates); + + $this->updateRelation($form, $model, $relations, $relationKeyMap); + }); + + return $this->model()->getKey(); + } +} diff --git a/app/Admin/Repositories/Vip.php b/app/Admin/Repositories/Vip.php new file mode 100644 index 00000000..d4a3fc9a --- /dev/null +++ b/app/Admin/Repositories/Vip.php @@ -0,0 +1,16 @@ +names('product_sku_verifies'); + $router->resource('users', 'UserController'); + + $router->resource('vips', 'VipController'); /** api接口 **/ $router->get('api/product-categories', 'ProductCategoryController@categories')->name('api.product_categories'); diff --git a/app/Models/User.php b/app/Models/User.php index c4c35b67..988077e0 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Constants\Device; +use Dcat\Admin\Traits\HasDateTimeFormatter; use Illuminate\Auth\Authenticatable; use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; @@ -19,6 +20,7 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac use Authorizable; use HasFactory; use HasApiTokens; + use HasDateTimeFormatter; public const STATUS_FROZEN = -1; // 冻结 public const STATUS_INACTIVATED = 0; // 未激活 diff --git a/app/Models/UserVip.php b/app/Models/UserVip.php new file mode 100644 index 00000000..9dd5bccd --- /dev/null +++ b/app/Models/UserVip.php @@ -0,0 +1,11 @@ +belongsToMany(User::class, 'user_vips', 'vip_id', 'user_id'); + } + + public function hasUser() + { + return $this->users()->exists(); + } +} diff --git a/database/migrations/2021_12_03_135905_create_vips_table.php b/database/migrations/2021_12_03_135905_create_vips_table.php new file mode 100644 index 00000000..0bbc0057 --- /dev/null +++ b/database/migrations/2021_12_03_135905_create_vips_table.php @@ -0,0 +1,33 @@ +id(); + $table->string('vip_name')->comment('等级名称'); + $table->unsignedBigInteger('vip_growth_value')->default(0)->comment('等级成长值'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('vips'); + } +} diff --git a/database/migrations/2021_12_03_135913_create_user_vips_table.php b/database/migrations/2021_12_03_135913_create_user_vips_table.php new file mode 100644 index 00000000..c5c421e2 --- /dev/null +++ b/database/migrations/2021_12_03_135913_create_user_vips_table.php @@ -0,0 +1,34 @@ +id(); + $table->unsignedBigInteger('user_id')->unique()->comment('用户ID'); + $table->unsignedBigInteger('vip_id')->comment('会员等级ID'); + $table->unsignedBigInteger('grow_value')->comment('当前会员成长值'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('user_vips'); + } +} diff --git a/database/seeders/AdminPermissionSeeder.php b/database/seeders/AdminPermissionSeeder.php index 7c7ca261..f13e0fa1 100644 --- a/database/seeders/AdminPermissionSeeder.php +++ b/database/seeders/AdminPermissionSeeder.php @@ -130,6 +130,10 @@ class AdminPermissionSeeder extends Seeder ], ], ], + 'vips'=>[ + 'name' =>'会员等级', + 'curd'=>['index', 'create', 'store', 'edit', 'update', 'destroy'], + ], ]; try { DB::begintransaction(); diff --git a/dcat_admin_ide_helper.php b/dcat_admin_ide_helper.php index 67c771bb..993be3aa 100644 --- a/dcat_admin_ide_helper.php +++ b/dcat_admin_ide_helper.php @@ -68,6 +68,7 @@ namespace Dcat\Admin { * @property Grid\Column|Collection specs * @property Grid\Column|Collection part_id * @property Grid\Column|Collection sku_id + * @property Grid\Column|Collection spu_id * @property Grid\Column|Collection status * @property Grid\Column|Collection buynote_id * @property Grid\Column|Collection cost_price @@ -77,7 +78,6 @@ namespace Dcat\Admin { * @property Grid\Column|Collection release_at * @property Grid\Column|Collection sales * @property Grid\Column|Collection sell_price - * @property Grid\Column|Collection spu_id * @property Grid\Column|Collection stock * @property Grid\Column|Collection verify_state * @property Grid\Column|Collection vip_price @@ -85,6 +85,7 @@ namespace Dcat\Admin { * @property Grid\Column|Collection feature_id * @property Grid\Column|Collection items * @property Grid\Column|Collection product_spu_id + * @property Grid\Column|Collection view_date * @property Grid\Column|Collection code * @property Grid\Column|Collection expires_at * @property Grid\Column|Collection is_use @@ -93,6 +94,8 @@ namespace Dcat\Admin { * @property Grid\Column|Collection gender * @property Grid\Column|Collection inviter_id * @property Grid\Column|Collection nickname + * @property Grid\Column|Collection grow_value + * @property Grid\Column|Collection vip_id * @property Grid\Column|Collection email * @property Grid\Column|Collection email_verified_at * @property Grid\Column|Collection last_login_at @@ -100,6 +103,8 @@ namespace Dcat\Admin { * @property Grid\Column|Collection phone_verified_at * @property Grid\Column|Collection register_ip * @property Grid\Column|Collection status_remark + * @property Grid\Column|Collection vip_growth_value + * @property Grid\Column|Collection vip_name * * @method Grid\Column|Collection id(string $label = null) * @method Grid\Column|Collection created_at(string $label = null) @@ -158,6 +163,7 @@ namespace Dcat\Admin { * @method Grid\Column|Collection specs(string $label = null) * @method Grid\Column|Collection part_id(string $label = null) * @method Grid\Column|Collection sku_id(string $label = null) + * @method Grid\Column|Collection spu_id(string $label = null) * @method Grid\Column|Collection status(string $label = null) * @method Grid\Column|Collection buynote_id(string $label = null) * @method Grid\Column|Collection cost_price(string $label = null) @@ -167,7 +173,6 @@ namespace Dcat\Admin { * @method Grid\Column|Collection release_at(string $label = null) * @method Grid\Column|Collection sales(string $label = null) * @method Grid\Column|Collection sell_price(string $label = null) - * @method Grid\Column|Collection spu_id(string $label = null) * @method Grid\Column|Collection stock(string $label = null) * @method Grid\Column|Collection verify_state(string $label = null) * @method Grid\Column|Collection vip_price(string $label = null) @@ -175,6 +180,7 @@ namespace Dcat\Admin { * @method Grid\Column|Collection feature_id(string $label = null) * @method Grid\Column|Collection items(string $label = null) * @method Grid\Column|Collection product_spu_id(string $label = null) + * @method Grid\Column|Collection view_date(string $label = null) * @method Grid\Column|Collection code(string $label = null) * @method Grid\Column|Collection expires_at(string $label = null) * @method Grid\Column|Collection is_use(string $label = null) @@ -183,6 +189,8 @@ namespace Dcat\Admin { * @method Grid\Column|Collection gender(string $label = null) * @method Grid\Column|Collection inviter_id(string $label = null) * @method Grid\Column|Collection nickname(string $label = null) + * @method Grid\Column|Collection grow_value(string $label = null) + * @method Grid\Column|Collection vip_id(string $label = null) * @method Grid\Column|Collection email(string $label = null) * @method Grid\Column|Collection email_verified_at(string $label = null) * @method Grid\Column|Collection last_login_at(string $label = null) @@ -190,6 +198,8 @@ namespace Dcat\Admin { * @method Grid\Column|Collection phone_verified_at(string $label = null) * @method Grid\Column|Collection register_ip(string $label = null) * @method Grid\Column|Collection status_remark(string $label = null) + * @method Grid\Column|Collection vip_growth_value(string $label = null) + * @method Grid\Column|Collection vip_name(string $label = null) */ class Grid {} @@ -253,6 +263,7 @@ namespace Dcat\Admin { * @property Show\Field|Collection specs * @property Show\Field|Collection part_id * @property Show\Field|Collection sku_id + * @property Show\Field|Collection spu_id * @property Show\Field|Collection status * @property Show\Field|Collection buynote_id * @property Show\Field|Collection cost_price @@ -262,7 +273,6 @@ namespace Dcat\Admin { * @property Show\Field|Collection release_at * @property Show\Field|Collection sales * @property Show\Field|Collection sell_price - * @property Show\Field|Collection spu_id * @property Show\Field|Collection stock * @property Show\Field|Collection verify_state * @property Show\Field|Collection vip_price @@ -270,6 +280,7 @@ namespace Dcat\Admin { * @property Show\Field|Collection feature_id * @property Show\Field|Collection items * @property Show\Field|Collection product_spu_id + * @property Show\Field|Collection view_date * @property Show\Field|Collection code * @property Show\Field|Collection expires_at * @property Show\Field|Collection is_use @@ -278,6 +289,8 @@ namespace Dcat\Admin { * @property Show\Field|Collection gender * @property Show\Field|Collection inviter_id * @property Show\Field|Collection nickname + * @property Show\Field|Collection grow_value + * @property Show\Field|Collection vip_id * @property Show\Field|Collection email * @property Show\Field|Collection email_verified_at * @property Show\Field|Collection last_login_at @@ -285,6 +298,8 @@ namespace Dcat\Admin { * @property Show\Field|Collection phone_verified_at * @property Show\Field|Collection register_ip * @property Show\Field|Collection status_remark + * @property Show\Field|Collection vip_growth_value + * @property Show\Field|Collection vip_name * * @method Show\Field|Collection id(string $label = null) * @method Show\Field|Collection created_at(string $label = null) @@ -343,6 +358,7 @@ namespace Dcat\Admin { * @method Show\Field|Collection specs(string $label = null) * @method Show\Field|Collection part_id(string $label = null) * @method Show\Field|Collection sku_id(string $label = null) + * @method Show\Field|Collection spu_id(string $label = null) * @method Show\Field|Collection status(string $label = null) * @method Show\Field|Collection buynote_id(string $label = null) * @method Show\Field|Collection cost_price(string $label = null) @@ -352,7 +368,6 @@ namespace Dcat\Admin { * @method Show\Field|Collection release_at(string $label = null) * @method Show\Field|Collection sales(string $label = null) * @method Show\Field|Collection sell_price(string $label = null) - * @method Show\Field|Collection spu_id(string $label = null) * @method Show\Field|Collection stock(string $label = null) * @method Show\Field|Collection verify_state(string $label = null) * @method Show\Field|Collection vip_price(string $label = null) @@ -360,6 +375,7 @@ namespace Dcat\Admin { * @method Show\Field|Collection feature_id(string $label = null) * @method Show\Field|Collection items(string $label = null) * @method Show\Field|Collection product_spu_id(string $label = null) + * @method Show\Field|Collection view_date(string $label = null) * @method Show\Field|Collection code(string $label = null) * @method Show\Field|Collection expires_at(string $label = null) * @method Show\Field|Collection is_use(string $label = null) @@ -368,6 +384,8 @@ namespace Dcat\Admin { * @method Show\Field|Collection gender(string $label = null) * @method Show\Field|Collection inviter_id(string $label = null) * @method Show\Field|Collection nickname(string $label = null) + * @method Show\Field|Collection grow_value(string $label = null) + * @method Show\Field|Collection vip_id(string $label = null) * @method Show\Field|Collection email(string $label = null) * @method Show\Field|Collection email_verified_at(string $label = null) * @method Show\Field|Collection last_login_at(string $label = null) @@ -375,6 +393,8 @@ namespace Dcat\Admin { * @method Show\Field|Collection phone_verified_at(string $label = null) * @method Show\Field|Collection register_ip(string $label = null) * @method Show\Field|Collection status_remark(string $label = null) + * @method Show\Field|Collection vip_growth_value(string $label = null) + * @method Show\Field|Collection vip_name(string $label = null) */ class Show {} diff --git a/resources/lang/zh_CN/user.php b/resources/lang/zh_CN/user.php new file mode 100644 index 00000000..4f22a12a --- /dev/null +++ b/resources/lang/zh_CN/user.php @@ -0,0 +1,22 @@ + [ + 'User' => '会员管理', + 'users' => '会员管理', + ], + 'fields' => [ + 'username' => '用户名', + 'password' => '密码', + 'password_confirm'=>'重复密码', + 'phone' => '手机号', + 'email' => '邮箱', + 'status'=>'状态', + 'last_login_ip' => '最近登录IP', + 'last_login_at' => '最近登录时间', + 'register_ip' => '注册IP', + 'created_at' => '注册时间', + ], + 'options' => [ + ], +]; diff --git a/resources/lang/zh_CN/vip.php b/resources/lang/zh_CN/vip.php new file mode 100644 index 00000000..b43d20f9 --- /dev/null +++ b/resources/lang/zh_CN/vip.php @@ -0,0 +1,16 @@ + [ + 'Vip' => '会员等级', + 'vips' => '会员等级', + ], + 'fields' => [ + 'vip_name' => '等级名称', + 'vip_growth_value' => '等级成长值', + ], + 'options' => [ + 'deny' => '删除失败', + 'deny_message'=>'当前会员等级下会员人数大于0', + ], +];