diff --git a/app/Admin/Actions/Grid/v3/StoreUserPassword.php b/app/Admin/Actions/Grid/v3/StoreUserPassword.php new file mode 100644 index 0000000..fda32de --- /dev/null +++ b/app/Admin/Actions/Grid/v3/StoreUserPassword.php @@ -0,0 +1,36 @@ +getKey(); + + $modal = Modal::make() + ->xl() + ->title($this->title) + ->body(StoreUserPasswordForm::make()->setKey($id)) + ->button($this->title); + + return $modal; + } + + public function parameters() + { + + return [ + + ]; + } +} diff --git a/app/Admin/Controllers/v3/StoreUserController.php b/app/Admin/Controllers/v3/StoreUserController.php new file mode 100644 index 0000000..25e7b4e --- /dev/null +++ b/app/Admin/Controllers/v3/StoreUserController.php @@ -0,0 +1,143 @@ +column('id')->sortable(); + $grid->column('store_id')->display(function($storeId) use($storeList){ + return isset($storeList[$storeId])?$storeList[$storeId]:''; + }); + $grid->column('username'); + $grid->column('user_category')->using($categoryList)->label(config('label.account_label')); + + $grid->column('register_type')->display(function($registerType) use($typeList){ + return isset($typeList[$registerType])?$typeList[$registerType]:''; + }); + $grid->column('status'); + $grid->column('join_ip'); + + $grid->column('last_ip'); + $grid->column('last_visit_time_text'); + $grid->model()->orderBy('id', 'desc'); + // 每页10条 + $grid->paginate(10); + + $grid->actions([new StoreUserPassword()]); + + $grid->filter(function (Grid\Filter $filter) use($categoryList,$storeList){ + unset($categoryList[0]); + $filter->equal('id'); + $filter->equal('user_category')->select($categoryList); + $filter->equal('store_id')->select($storeList); + }); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + return Show::make($id, new StoreUser(), function (Show $show) { + $show->field('id'); + $show->field('store_id'); + $show->field('username'); + $show->field('user_category'); + $show->field('register_type'); + $show->field('status'); + $show->field('join_ip'); + $show->field('last_visit_time'); + $show->field('last_ip'); + $show->field('created_at'); + $show->field('updated_at'); + }); + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + return Form::make(new StoreUser(), function (Form $form) { + // 店铺 + $storeList = StoreModel::getStoreArray(); + // 账号类型 + $categoryList = StoreUserModel::$_USER_CATEGORY; + unset($categoryList[0]); + + $form->hidden('id'); + $form->hidden('salt')->default(''); + $form->hidden('join_ip')->default(''); + $form->select('store_id')->options($storeList)->required(); + $form->select('user_category')->options($categoryList)->required(); + if($form->isCreating()){ + $form->text('username')->minLength(6,'必须大于等于6位字符')->required(); + }else if($form->isEditing()){ + $form->text('username')->disable(); + } + + $form->password('password')->minLength(6,'必须大于等于6位数')->required(); + $form->password('password_confirm','再次输入密码')->same('password'); + $form->hidden('register_type')->default(5); + $form->hidden('status')->default(2); + $form->text('remark')->default(''); + + $form->saving(function(Form $form){ + $ip = isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:''; + + $userName = $form->input('username'); + $password = $form->input('password'); + + if($form->isCreating() && !empty($password)){ + $storeCon = new StoreController(); + $form->salt = $storeCon->random(8); + $form->password = $storeCon->stringHash($password,$form->salt); + } + + if($form->isCreating() && !empty($userName) && !empty(StoreUserModel::where('username', $userName)->first())){ + return $form->error('账号已存在'); + } + $form->join_ip = $ip; + $form->deleteInput('password_confirm'); + }); + $form->disableResetButton(); + $form->disableViewCheck(); + $form->disableEditingCheck(); + $form->disableCreatingCheck(); + $form->disableDeleteButton(); + }); + } +} diff --git a/app/Admin/Forms/v3/StoreUserPasswordForm.php b/app/Admin/Forms/v3/StoreUserPasswordForm.php new file mode 100644 index 0000000..41fd5db --- /dev/null +++ b/app/Admin/Forms/v3/StoreUserPasswordForm.php @@ -0,0 +1,73 @@ + 0 && !empty($password)){ + $model = StoreUserModel::select('id','password','salt')->find($id); + $storeCon = new StoreController(); + $salt = $storeCon->random(8); + $passwordOld = $storeCon->stringHash($password,$model->salt); + + if($model && $model->password != $passwordOld){ + $model->salt = $salt; + $model->password = $storeCon->stringHash($password,$salt);; + if($model->save()){ + return $this->success('修改成功!'); + }else{ + return $this->error('修改失败!'); + } + }else{ + return $this->error('密码相同,无需修改!'); + } + } + + return $this->error('请求参数为空!'); + } + + /** + * Build a form here. + */ + public function form() + { + $id = $this->getKey(); + $storeUser = StoreUserModel::select('username')->find($id); + $userName = empty($storeUser->username)?'':$storeUser->username; + $this->hidden('id')->value($id); + $this->display('username','账号')->value($userName); + $this->password('password')->minLength(6,'必须大于等于6位数')->required(); + $this->password('password_confirm','再次输入密码')->same('password'); + } + + /** + * The data of the form. + * + * @return array + */ + public function default() + { + return []; + } + +} diff --git a/app/Admin/Repositories/v3/StoreUser.php b/app/Admin/Repositories/v3/StoreUser.php new file mode 100644 index 0000000..4cddf8c --- /dev/null +++ b/app/Admin/Repositories/v3/StoreUser.php @@ -0,0 +1,16 @@ +resource('/store', 'v3\StoreController'); + $router->resource('/store_user', 'v3\StoreUserController'); // 商品 $router->resource('/goods', 'v3\GoodsController'); $router->resource('/goods_activity', 'v3\GoodsActivityController'); diff --git a/app/Models/v3/StoreUser.php b/app/Models/v3/StoreUser.php new file mode 100644 index 0000000..c9899bc --- /dev/null +++ b/app/Models/v3/StoreUser.php @@ -0,0 +1,46 @@ +user_category; + return isset(self::$_USER_CATEGORY[$value]) ? self::$_USER_CATEGORY[$value] : ''; + } + public function getRegisterTypeTextAttribute($value) + { + $value = $value ? $value : $this->register_type; + return isset(self::$_REGISTER_TYPE[$value]) ? self::$_REGISTER_TYPE[$value] : ''; + } + public function getStatusTextAttribute($value) + { + $value = $value ? $value : $this->status; + return isset(self::$_STATUS[$value]) ? self::$_STATUS[$value] : ''; + } + public function getLastVisitTimeTextAttribute($value) + { + $value = $value ? $value : $this->last_visit_time; + return $value ? date('Y-m-d H:i',$value) : ''; + } +} diff --git a/config/label.php b/config/label.php index 6b9290c..2a67a48 100644 --- a/config/label.php +++ b/config/label.php @@ -8,5 +8,11 @@ return [ 2 => 'warning', 3 => 'danger', -1=> 'danger' + ], + 'account_label'=>[ + 'default' => '#d3ffd3', + 0 => '#f00', + 1 => '#ff6600', + 2 => '#1c9f78' ] ]; diff --git a/dcat_admin_ide_helper.php b/dcat_admin_ide_helper.php index 50bc1f7..ee2e53e 100644 --- a/dcat_admin_ide_helper.php +++ b/dcat_admin_ide_helper.php @@ -92,12 +92,14 @@ namespace Dcat\Admin { * @property Grid\Column|Collection price * @property Grid\Column|Collection category_id * @property Grid\Column|Collection goods_category_id + * @property Grid\Column|Collection content * @property Grid\Column|Collection on_sale * @property Grid\Column|Collection order_num * @property Grid\Column|Collection state * @property Grid\Column|Collection pay_time * @property Grid\Column|Collection time * @property Grid\Column|Collection head_url + * @property Grid\Column|Collection dm_state * @property Grid\Column|Collection parent_id * @property Grid\Column|Collection order * @property Grid\Column|Collection icon @@ -129,7 +131,6 @@ namespace Dcat\Admin { * @property Grid\Column|Collection token * @property Grid\Column|Collection admin_id * @property Grid\Column|Collection url - * @property Grid\Column|Collection content * @property Grid\Column|Collection useragent * @property Grid\Column|Collection pid * @property Grid\Column|Collection shortname @@ -484,7 +485,6 @@ namespace Dcat\Admin { * @property Grid\Column|Collection yhq_money2 * @property Grid\Column|Collection coupon_id2 * @property Grid\Column|Collection dn_state - * @property Grid\Column|Collection dm_state * @property Grid\Column|Collection yy_state * @property Grid\Column|Collection deposit * @property Grid\Column|Collection ship_id @@ -1320,12 +1320,14 @@ namespace Dcat\Admin { * @method Grid\Column|Collection price(string $label = null) * @method Grid\Column|Collection category_id(string $label = null) * @method Grid\Column|Collection goods_category_id(string $label = null) + * @method Grid\Column|Collection content(string $label = null) * @method Grid\Column|Collection on_sale(string $label = null) * @method Grid\Column|Collection order_num(string $label = null) * @method Grid\Column|Collection state(string $label = null) * @method Grid\Column|Collection pay_time(string $label = null) * @method Grid\Column|Collection time(string $label = null) * @method Grid\Column|Collection head_url(string $label = null) + * @method Grid\Column|Collection dm_state(string $label = null) * @method Grid\Column|Collection parent_id(string $label = null) * @method Grid\Column|Collection order(string $label = null) * @method Grid\Column|Collection icon(string $label = null) @@ -1357,7 +1359,6 @@ namespace Dcat\Admin { * @method Grid\Column|Collection token(string $label = null) * @method Grid\Column|Collection admin_id(string $label = null) * @method Grid\Column|Collection url(string $label = null) - * @method Grid\Column|Collection content(string $label = null) * @method Grid\Column|Collection useragent(string $label = null) * @method Grid\Column|Collection pid(string $label = null) * @method Grid\Column|Collection shortname(string $label = null) @@ -1712,7 +1713,6 @@ namespace Dcat\Admin { * @method Grid\Column|Collection yhq_money2(string $label = null) * @method Grid\Column|Collection coupon_id2(string $label = null) * @method Grid\Column|Collection dn_state(string $label = null) - * @method Grid\Column|Collection dm_state(string $label = null) * @method Grid\Column|Collection yy_state(string $label = null) * @method Grid\Column|Collection deposit(string $label = null) * @method Grid\Column|Collection ship_id(string $label = null) @@ -2553,12 +2553,14 @@ namespace Dcat\Admin { * @property Show\Field|Collection price * @property Show\Field|Collection category_id * @property Show\Field|Collection goods_category_id + * @property Show\Field|Collection content * @property Show\Field|Collection on_sale * @property Show\Field|Collection order_num * @property Show\Field|Collection state * @property Show\Field|Collection pay_time * @property Show\Field|Collection time * @property Show\Field|Collection head_url + * @property Show\Field|Collection dm_state * @property Show\Field|Collection parent_id * @property Show\Field|Collection order * @property Show\Field|Collection icon @@ -2590,7 +2592,6 @@ namespace Dcat\Admin { * @property Show\Field|Collection token * @property Show\Field|Collection admin_id * @property Show\Field|Collection url - * @property Show\Field|Collection content * @property Show\Field|Collection useragent * @property Show\Field|Collection pid * @property Show\Field|Collection shortname @@ -2945,7 +2946,6 @@ namespace Dcat\Admin { * @property Show\Field|Collection yhq_money2 * @property Show\Field|Collection coupon_id2 * @property Show\Field|Collection dn_state - * @property Show\Field|Collection dm_state * @property Show\Field|Collection yy_state * @property Show\Field|Collection deposit * @property Show\Field|Collection ship_id @@ -3781,12 +3781,14 @@ namespace Dcat\Admin { * @method Show\Field|Collection price(string $label = null) * @method Show\Field|Collection category_id(string $label = null) * @method Show\Field|Collection goods_category_id(string $label = null) + * @method Show\Field|Collection content(string $label = null) * @method Show\Field|Collection on_sale(string $label = null) * @method Show\Field|Collection order_num(string $label = null) * @method Show\Field|Collection state(string $label = null) * @method Show\Field|Collection pay_time(string $label = null) * @method Show\Field|Collection time(string $label = null) * @method Show\Field|Collection head_url(string $label = null) + * @method Show\Field|Collection dm_state(string $label = null) * @method Show\Field|Collection parent_id(string $label = null) * @method Show\Field|Collection order(string $label = null) * @method Show\Field|Collection icon(string $label = null) @@ -3818,7 +3820,6 @@ namespace Dcat\Admin { * @method Show\Field|Collection token(string $label = null) * @method Show\Field|Collection admin_id(string $label = null) * @method Show\Field|Collection url(string $label = null) - * @method Show\Field|Collection content(string $label = null) * @method Show\Field|Collection useragent(string $label = null) * @method Show\Field|Collection pid(string $label = null) * @method Show\Field|Collection shortname(string $label = null) @@ -4173,7 +4174,6 @@ namespace Dcat\Admin { * @method Show\Field|Collection yhq_money2(string $label = null) * @method Show\Field|Collection coupon_id2(string $label = null) * @method Show\Field|Collection dn_state(string $label = null) - * @method Show\Field|Collection dm_state(string $label = null) * @method Show\Field|Collection yy_state(string $label = null) * @method Show\Field|Collection deposit(string $label = null) * @method Show\Field|Collection ship_id(string $label = null) diff --git a/resources/lang/zh-CN/store-user.php b/resources/lang/zh-CN/store-user.php new file mode 100644 index 0000000..b2f596c --- /dev/null +++ b/resources/lang/zh-CN/store-user.php @@ -0,0 +1,23 @@ + [ + 'StoreUser' => '店铺账号', + 'storeUser' => '店铺账号', + 'store_user' => '店铺账号', + ], + 'fields' => [ + 'store_id' => '商家', + 'username' => '账号', + 'password' => '密码', + 'user_category' => '账号类型', + 'register_type' => '注册类型', + 'status' => '状态', + 'join_ip' => '注册IP', + 'last_visit_time' => '最后访问时间', + 'last_visit_time_text' => '最后访问时间', + 'last_ip' => '最后访问IP', + 'remark' => '备注' + ], + 'options' => [ + ], +];