9 changed files with 352 additions and 8 deletions
-
36app/Admin/Actions/Grid/v3/StoreUserPassword.php
-
143app/Admin/Controllers/v3/StoreUserController.php
-
73app/Admin/Forms/v3/StoreUserPasswordForm.php
-
16app/Admin/Repositories/v3/StoreUser.php
-
1app/Admin/routes.php
-
46app/Models/v3/StoreUser.php
-
6config/label.php
-
16dcat_admin_ide_helper.php
-
23resources/lang/zh-CN/store-user.php
@ -0,0 +1,36 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Actions\Grid\v3; |
|||
|
|||
use Dcat\Admin\Grid\RowAction; |
|||
use Dcat\Admin\Widgets\Modal; |
|||
use App\Admin\Forms\v3\StoreUserPasswordForm; |
|||
|
|||
class StoreUserPassword extends RowAction |
|||
{ |
|||
/** |
|||
* @return string |
|||
*/ |
|||
protected $title = '修改密码'; |
|||
|
|||
public function render() |
|||
{ |
|||
$id = $this->getKey(); |
|||
|
|||
$modal = Modal::make() |
|||
->xl() |
|||
->title($this->title) |
|||
->body(StoreUserPasswordForm::make()->setKey($id)) |
|||
->button($this->title); |
|||
|
|||
return $modal; |
|||
} |
|||
|
|||
public function parameters() |
|||
{ |
|||
|
|||
return [ |
|||
|
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,143 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Controllers\v3; |
|||
|
|||
use App\Admin\Repositories\v3\StoreUser; |
|||
use Dcat\Admin\Form; |
|||
use Dcat\Admin\Grid; |
|||
use Dcat\Admin\Show; |
|||
use Dcat\Admin\Controllers\AdminController; |
|||
use App\Models\v3\Store as StoreModel; |
|||
use App\Models\v3\StoreUser as StoreUserModel; |
|||
use App\Admin\Controllers\v3\StoreController; |
|||
use App\Admin\Actions\Grid\v3\StoreUserPassword; |
|||
|
|||
class StoreUserController extends AdminController |
|||
{ |
|||
|
|||
/** |
|||
* Make a grid builder. |
|||
* |
|||
* @return Grid |
|||
*/ |
|||
protected function grid() |
|||
{ |
|||
return Grid::make(new StoreUser(), function (Grid $grid) { |
|||
// 店铺
|
|||
$storeList = StoreModel::getStoreArray(); |
|||
// 账号类型
|
|||
$categoryList = StoreUserModel::$_USER_CATEGORY; |
|||
// 注册类型
|
|||
$typeList = StoreUserModel::$_REGISTER_TYPE; |
|||
|
|||
$grid->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(); |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,73 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Forms\v3; |
|||
|
|||
use App\Models\v3\GoodsBanners; |
|||
use Dcat\Admin\Widgets\Form; |
|||
use Symfony\Component\HttpFoundation\Response; |
|||
use App\Models\v3\StoreUser as StoreUserModel; |
|||
use App\Admin\Controllers\v3\StoreController; |
|||
|
|||
class StoreUserPasswordForm extends Form |
|||
{ |
|||
|
|||
/** |
|||
* Handle the form request. |
|||
* |
|||
* @param array $input |
|||
* |
|||
* @return Response |
|||
*/ |
|||
public function handle(array $input) |
|||
{ |
|||
// 获取外部传递参数
|
|||
$id = $input['id']; |
|||
$password= $input['password']; |
|||
|
|||
if($id > 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 []; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Repositories\v3; |
|||
|
|||
use App\Models\v3\StoreUser as Model; |
|||
use Dcat\Admin\Repositories\EloquentRepository; |
|||
|
|||
class StoreUser extends EloquentRepository |
|||
{ |
|||
/** |
|||
* Model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $eloquentClass = Model::class; |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
<?php |
|||
|
|||
namespace App\Models\v3; |
|||
|
|||
use Dcat\Admin\Traits\HasDateTimeFormatter; |
|||
use Illuminate\Database\Eloquent\SoftDeletes; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
|
|||
class StoreUser extends Model |
|||
{ |
|||
use HasDateTimeFormatter; |
|||
use SoftDeletes; |
|||
|
|||
protected $table = 'lanzu_store_users'; |
|||
protected $dateFormat = 'U'; |
|||
protected $appends = [ |
|||
'user_category_text', |
|||
'register_type_text', |
|||
'status_text', |
|||
'last_visit_time_text', |
|||
]; |
|||
public static $_USER_CATEGORY = ['管理员', '店长', '店员', '默认']; |
|||
public static $_REGISTER_TYPE = ['网站注册','QQ','微信','app','商户注册默认账号','后台添加商户账号']; |
|||
public static $_STATUS = ['禁用','审核中', '正常']; |
|||
|
|||
public function getUserCategoryTextAttribute($value) |
|||
{ |
|||
$value = $value ? $value : $this->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) : ''; |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
<?php |
|||
return [ |
|||
'labels' => [ |
|||
'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' => [ |
|||
], |
|||
]; |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue