all(), [ 'username' => 'required', 'password' => 'required' ],[ 'username.required' => '账户必填', 'password.required' => '密码必填' ]); if ($validator->fails()) { return self::returnValue($validator->getMessageBag(), 1102); } $username = $request->input('username'); $password = $request->input('password'); $user = Users::query() ->select(['name', 'password', 'id','is_system_admin']) ->where('name', $username) ->where('enable', 1) ->first(); if (empty($user)) { return self::returnValue('账户不存在', 3001); } if (Hash::check($password, $user->password)) { $redisKey = env('LOGIN_REDIS_KEY') . '-'. $user->id; $randomKey = RedisModel::get($redisKey); if(!$randomKey){ $randomKey = Users::random(20); RedisModel::set($redisKey, $randomKey); RedisModel::expire($redisKey, 86400*30); } $data = array( 'admin_id' => $user->id, 'username' => $user->name, 'is_system_admin' => $user->is_system_admin, 'random' => $randomKey, 'ttl' => time() ); return self::returnValue($data, 0); } else { return self::returnValue('密码错误', 3001); } } /* * 获取企业内用户列表 * */ public static function userList(Request $request) { $groupAdminId = $request->input('sys_group_id'); $type = $request->input('type', 0); $operatorId = $request->input('operator_id'); if(!$groupAdminId) return self::returnValue([]); $userList = Users::query()->selectRaw("id as admin_id, name") ->where(function($query) use($groupAdminId, $type, $operatorId){ if($groupAdminId != 1) { $query->where('group_admin_id', $groupAdminId); } if(1 == $type) { if($operatorId) { $query->where('enable', 1)->orWhere('id', $operatorId); } else { $query->where('enable', 1); } } })->get(); return self::returnValue($userList); } }