You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							160 lines
						
					
					
						
							5.9 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							160 lines
						
					
					
						
							5.9 KiB
						
					
					
				
								<?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('username');
							 | 
						|
								                $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')->as(function($storeId){
							 | 
						|
								                $item = StoreModel::getStoreInfo($storeId,'name');
							 | 
						|
								                return empty($item)?'':$item['name'];
							 | 
						|
								            });
							 | 
						|
								            $show->field('username');
							 | 
						|
								            $show->field('user_category')->as(function($userCategory){
							 | 
						|
								                $item = StoreUserModel::$_USER_CATEGORY;
							 | 
						|
								                return isset($item[$userCategory])?$item[$userCategory]:'';
							 | 
						|
								            });
							 | 
						|
								            $show->field('register_type')->as(function($registerType){
							 | 
						|
								                $item = StoreUserModel::$_REGISTER_TYPE;
							 | 
						|
								                return isset($item[$registerType])?$item[$registerType]:'';
							 | 
						|
								            });
							 | 
						|
								            $show->field('status')->as(function($status){
							 | 
						|
								                $item = StoreUserModel::$_STATUS;
							 | 
						|
								                return isset($item[$status])?$item[$status]:'';
							 | 
						|
								            });
							 | 
						|
								            $show->field('join_ip');
							 | 
						|
								            $show->field('last_visit_time_text');
							 | 
						|
								            $show->field('last_ip');
							 | 
						|
								            $show->field('created_at')->as(function($createdAt){
							 | 
						|
								                return date('Y-m-d H:i:s', $createdAt);
							 | 
						|
								            });
							 | 
						|
								            $show->field('updated_at')->as(function($updatedAt){
							 | 
						|
								                return date('Y-m-d H:i:s', $updatedAt);
							 | 
						|
								            });
							 | 
						|
								        });
							 | 
						|
								    }
							 | 
						|
								
							 | 
						|
								    /**
							 | 
						|
								     * 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();
							 | 
						|
								        });
							 | 
						|
								    }
							 | 
						|
								}
							 |