Ver código fonte

Weenier utc项目部署 06231

wesmiler 3 anos atrás
pai
commit
3ecd8811c0

+ 37 - 0
app/Http/Controllers/Admin/LayoutController.php

@@ -0,0 +1,37 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Http\Controllers\Admin;
+
+use App\Services\Common\LayoutService;
+
+/**
+ * 布局管理-控制器
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class LayoutController
+ * @package App\Http\Controllers
+ */
+class LayoutController extends Backend
+{
+    /**
+     * 构造函数
+     * @author laravel开发员
+     * @since 2020/11/11
+     * LayoutController constructor.
+     */
+    public function __construct()
+    {
+        parent::__construct();
+        $this->service = new LayoutService();
+    }
+
+}

+ 0 - 92
app/Http/Controllers/IndexController.php

@@ -1,92 +0,0 @@
-<?php
-// +----------------------------------------------------------------------
-// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
-// +----------------------------------------------------------------------
-// | 版权所有 2017~2021 LARAVEL研发中心
-// +----------------------------------------------------------------------
-// | 官方网站: http://www.laravel.cn
-// +----------------------------------------------------------------------
-// | Author: laravel开发员 <laravel.qq.com>
-// +----------------------------------------------------------------------
-
-namespace App\Http\Controllers;
-
-use App\Models\UserModel;
-use App\Models\AdminRomModel;
-use App\Services\AdminService;
-use App\Services\MenuService;
-use App\Services\UserService;
-
-/**
- * 系统主页控制器
- * @author laravel开发员
- * @since 2020/11/10
- * Class IndexController
- * @package App\Http\Controllers
- */
-class IndexController extends Backend
-{
-
-    /**
-     * 构造函数
-     * @author laravel开发员
-     * @since 2020/11/10
-     * IndexController constructor.
-     */
-    public function __construct()
-    {
-        parent::__construct();
-    }
-
-    /**
-     * 后台主页
-     * @author laravel开发员
-     * @since 2020/11/10
-     */
-    public function getMenuList()
-    {
-        $menuService = new MenuService();
-        $menuList = $menuService->getPermissionList($this->userId);
-        return $menuList;
-    }
-
-    /**
-     * 获取个人信息
-     * @return array
-     * @since 2020/11/10
-     * @author laravel开发员
-     */
-    public function getUserInfo()
-    {
-        $userService = new UserService();
-        $result = $userService->getUserInfo($this->userId);
-        return $result;
-    }
-
-    /**
-     * 更新个人资料
-     * @return mixed
-     * @since 2020/11/11
-     * @author laravel开发员
-     */
-    public function updateUserInfo()
-    {
-        $userService = new UserService();
-        $result = $userService->updateUserInfo($this->userId);
-        return $result;
-    }
-
-    /**
-     * 更新密码
-     * @return mixed
-     * @since 2020/11/11
-     * @author laravel开发员
-     */
-    public function updatePwd()
-    {
-        $userService = new UserService();
-        $result = $userService->updatePwd($this->userId);
-        return $result;
-    }
-
-}

+ 254 - 0
app/Services/Common/UserService.php

@@ -0,0 +1,254 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Services\Common;
+
+use App\Models\UserModel;
+use App\Services\BaseService;
+
+/**
+ * 用户管理-服务类
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class UserService
+ * @package App\Services\Common
+ */
+class UserService extends BaseService
+{
+    /**
+     * 构造函数
+     * @author laravel开发员
+     * @since 2020/11/11
+     * UserService constructor.
+     */
+    public function __construct()
+    {
+        $this->model = new UserModel();
+    }
+
+    /**
+     * 获取用户列表
+     * @return array
+     * @since 2020/11/11
+     * @author laravel开发员
+     */
+    public function getList()
+    {
+        $param = request()->all();
+
+        // 查询条件
+        $map = [];
+
+        // 用户账号
+        $username = getter($param, "username");
+        if ($username) {
+            $map[] = ["username", 'like', "%{$username}%"];
+        }
+        // 用户姓名
+        $realname = getter($param, "realname");
+        if ($realname) {
+            $map[] = ['realname', 'like', "%{$realname}%"];
+        }
+        // 用户性别
+        $gender = getter($param, "gender");
+        if ($gender) {
+            $map[] = ['gender', '=', $gender];
+        }
+        return parent::getList($map); // TODO: Change the autogenerated stub
+    }
+
+    /**
+     * 添加或编辑用户
+     * @return array
+     * @since 2020/11/11
+     * @author laravel开发员
+     */
+    public function edit()
+    {
+        // 请求参数
+        $data = request()->all();
+        // 用户名
+        $username = trim($data['username']);
+        // 密码
+        $password = trim($data['password']);
+
+        // 添加时设置密码
+        if (empty($data['id'])) {
+            $data['password'] = get_password($password . $username);
+            // 用户名重复性验证
+            $count = $this->model
+                ->where("username", '=', $username)
+                ->where("mark", "=", 1)
+                ->count();
+            if ($count > 0) {
+                return message("系统中已存在相同的用户名", false);
+            }
+        } else {
+            // 用户名重复性验证
+            $count = $this->model
+                ->where("username", '=', $username)
+                ->where("id", "<>", $data['id'])
+                ->where("mark", "=", 1)
+                ->count();
+            if ($count > 0) {
+                return message("系统中已存在相同的用户名", false);
+            }
+        }
+
+
+        // 头像处理
+        $avatar = isset($data['avatar']) ? trim($data['avatar']) : '';
+        if (strpos($avatar, "temp")) {
+            $data['avatar'] = save_image($avatar, 'user');
+        } else {
+            $data['avatar'] = str_replace(IMG_URL, "", $data['avatar']);
+        }
+        $error = "";
+        $result = $this->model->edit($data, $error);
+        if (!$result) {
+            return message($error, false);
+        }
+        // 删除已存在的用户角色关系数据
+        $userRoleService = new UserRoleService();
+        $userRoleService->deleteUserRole($result);
+        // 插入用户角色关系数据
+        $userRoleService->insertUserRole($result, $data['role_ids']);
+        return message();
+    }
+
+    /**
+     * 获取用户信息
+     * @param $userId 用户ID
+     * @return array
+     * @author laravel开发员
+     * @since 2020/11/10
+     */
+    public function getUserInfo($userId)
+    {
+        $userInfo = $this->model->getInfo($userId);
+        $userInfo['roles'] = [];
+        $userInfo['authorities'] = [];
+        // 权限节点列表
+        $menuService = new MenuService();
+        $permissionList = $menuService->getPermissionsList($userId);
+        $userInfo['permissionList'] = $permissionList;
+        return message("操作成功", true, $userInfo);
+    }
+
+    /**
+     * 更新个人资料
+     * @author laravel开发员
+     * @since 2020/11/11
+     */
+    public function updateUserInfo($userId)
+    {
+        // 参数
+        $param = request()->all();
+        // 个人信息
+        $data = [
+            'id' => $userId,
+            'realname' => $param['realname'],
+            'nickname' => $param['nickname'],
+            'gender' => $param['gender'],
+            'mobile' => $param['mobile'],
+            'email' => $param['email'],
+            'intro' => $param['intro'],
+        ];
+        // 头像处理
+        $avatar = isset($param['avatar']) ? $param['avatar'] : "";
+        if (strpos($avatar, "data:image") !== false) {
+            $expData = explode(';', $avatar);
+            $fileInfo = explode('/', $expData[0]);
+            $fileExt = $fileInfo[1] == 'jpeg' ? 'jpg' : $fileInfo[1];
+            // 文件存储路径
+            $filePath = create_image_path("user", $fileExt);
+
+            // 获取图片流
+            $item = explode(',', $avatar);
+            file_put_contents(ATTACHMENT_PATH . $filePath, base64_decode($item[1]));
+
+            $data['avatar'] = $filePath;
+        } else {
+            $data['avatar'] = str_replace(IMG_URL, "", $param['avatar']);
+        }
+        $result = $this->model->edit($data);
+        if (!$result) {
+            return message("更新资料信息失败", false);
+        }
+        return message("更新资料信息成功");
+    }
+
+    /**
+     * 更新密码
+     * @param $userId 用户ID
+     * @return array
+     * @author laravel开发员
+     * @since 2020/11/14
+     */
+    public function updatePwd($userId)
+    {
+        // 获取参数
+        $param = request()->all();
+        // 原始密码
+        $oldPassword = trim(getter($param, "oldPassword"));
+        if (!$oldPassword) {
+            return message("旧密码不能为空", false);
+        }
+        // 新密码
+        $newPassword = trim(getter($param, "newPassword"));
+        if (!$newPassword) {
+            return message("新密码不能为空", false);
+        }
+        $userInfo = $this->model->getInfo($userId);
+        if (!$userInfo) {
+            return message("用户信息不存在", false);
+        }
+        if ($userInfo['password'] != get_password($oldPassword . $userInfo['username'])) {
+            return message("旧密码输入不正确", false);
+        }
+        // 设置新密码
+        $userInfo['password'] = get_password($newPassword . $userInfo['username']);
+        $result = $this->model->edit($userInfo);
+        if (!$result) {
+            return message("修改失败", false);
+        }
+        return message("修改成功");
+    }
+
+    /**
+     * 重置密码
+     * @return array
+     * @since 2020/11/14
+     * @author laravel开发员
+     */
+    public function resetPwd()
+    {
+        // 获取参数
+        $param = request()->all();
+        // 用户ID
+        $userId = getter($param, "id");
+        if (!$userId) {
+            return message("用户ID不能为空", false);
+        }
+        $userInfo = $this->model->getInfo($userId);
+        if (!$userInfo) {
+            return message("用户信息不存在", false);
+        }
+        // 设置新密码
+        $userInfo['password'] = get_password("123456" . $userInfo['username']);
+        $result = $this->model->edit($userInfo);
+        if (!$result) {
+            return message("重置密码失败", false);
+        }
+        return message("重置密码成功");
+    }
+
+}

+ 0 - 91
app/Services/UserRoleService.php

@@ -1,91 +0,0 @@
-<?php
-// +----------------------------------------------------------------------
-// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
-// +----------------------------------------------------------------------
-// | 版权所有 2017~2021 LARAVEL研发中心
-// +----------------------------------------------------------------------
-// | 官方网站: http://www.laravel.cn
-// +----------------------------------------------------------------------
-// | Author: laravel开发员 <laravel.qq.com>
-// +----------------------------------------------------------------------
-
-namespace App\Services;
-
-use App\Models\UserRoleModel;
-
-/**
- * 用户角色关系-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * Class UserRoleService
- * @package App\Services
- */
-class UserRoleService extends BaseService
-{
-    /**
-     * 构造函数
-     * @author laravel开发员
-     * @since 2020/11/11
-     * UserRoleService constructor.
-     */
-    public function __construct()
-    {
-        $this->model = new UserRoleModel();
-    }
-
-    /**
-     * 根据用户ID获取角色列表
-     * @param $userId 用户ID
-     * @return mixed
-     * @author laravel开发员
-     * @since 2020/11/11
-     */
-    public function getUserRoleList($userId)
-    {
-        $userRoleModel = new UserRoleModel();
-        $roleList = $userRoleModel::from("role as r")
-            ->select('r.*')
-            ->join('user_role as ur', 'ur.role_id', '=', 'r.id')
-            ->distinct(true)
-            ->where('ur.user_id', '=', $userId)
-            ->where('r.status', '=', 1)
-            ->where('r.mark', '=', 1)
-            ->orderBy('r.sort')
-            ->get()->toArray();
-        return $roleList;
-    }
-
-    /**
-     * 删除用户角色关系数据
-     * @param $userId 用户ID
-     * @since 2020/11/11
-     * @author laravel开发员
-     */
-    public function deleteUserRole($userId)
-    {
-        $this->model->where("user_id", '=', $userId)->delete();
-    }
-
-    /**
-     * 批量插入用户角色关系数据
-     * @param $userId 用户ID
-     * @param $roleIds 角色ID集合
-     * @author laravel开发员
-     * @since 2020/11/11
-     */
-    public function insertUserRole($userId, $roleIds)
-    {
-        if (!empty($roleIds)) {
-            $list = [];
-            foreach ($roleIds as $val) {
-                $data = [
-                    'user_id' => $userId,
-                    'role_id' => $val,
-                ];
-                $list[] = $data;
-            }
-            $this->model->insert($list);
-        }
-    }
-
-}