load->model('market/Market_sys_admin_model', 'mdSysAdmin'); $this->load->model('market/Market_sys_role_model', 'mdSysRole'); } /** * Notes:用户管理列表 * Created on: 2022/9/8 14:48 * Created by: dengbw */ public function page_get() { $page = $this->input_param('page'); $limit = $this->input_param('limit'); $username = $this->input_param('username'); $nickname = $this->input_param('nickname'); $sex = $this->input_param('sex'); $sort = $this->input_param('sort'); $order = $this->input_param('order'); !$page && $page = 1; !$limit && $limit = 10; $sort_order = 'userId desc'; if ($sort && $order) { if ($sort == 'sexName') { $sort_order = 'sex ' . $order; } else { $sort_order = $sort . ' ' . $order; } } $where = $list = []; $where['status>='] = 0; $username && $where['username'] = $username; $nickname && $where['nickname'] = $nickname; $sex && $where['sex'] = $sex; $count = $this->mdSysAdmin->count($where); if ($count) { $res = $this->mdSysAdmin->select($where, $sort_order, $page, $limit); foreach ($res as $v) { $sexName = $v['sex'] == 2 ? '女' : '男'; $status = intval($v['status']); $roles = []; if ($v['roleId']) { $re_ro = $this->mdSysRole->get(['roleId' => $v['roleId']]); if ($re_ro) { $re_ro['userId'] = $v['userId']; $re_ro['deleted'] = 0; $roles[] = $re_ro; } } $list[] = [ 'userId' => $v['userId'], 'username' => $v['username'], 'nickname' => $v['nickname'], 'phone' => $v['phone'] , 'status' => $status, 'sex' => $v['sex'], 'sexName' => $sexName, 'birthday' => $v['birthday'] , 'introduction' => $v['introduction'], 'email' => $v['email'], 'createTime' => $v['createTime'], 'roles' => $roles, ]; } } $date = ['list' => $list, 'count' => $count]; $this->return_response_list($date); } /** * Notes:用户详情 * Created on: 2022/9/21 16:15 * Created by: dengbw * @param null $userId */ public function index_get($userId = null) { if (!$userId) { $this->return_json('参数错误'); } $re = $this->mdSysAdmin->get(['userId' => $userId]); if (!$re) { $this->return_json('用户不存在'); } $re['sexName'] = $re['sex'] == 2 ? '女' : '男'; $re['status'] = intval($re['status']); $roles = []; if ($re['roleId']) { $re_ro = $this->mdSysRole->get(['roleId' => $re['roleId']]); $re_ro && $roles[] = $re_ro; } $re['roles'] = $roles; $this->return_response($re); } /** * Notes:修改用户 * Created on: 2022/9/8 14:48 * Created by: dengbw */ public function index_put() { $userId = $this->input_param('userId'); $nickname = $this->input_param('nickname'); $phone = $this->input_param('phone'); $sex = $this->input_param('sex'); $birthday = $this->input_param('birthday'); $introduction = $this->input_param('introduction'); $email = $this->input_param('email'); $roleIds = $this->input_param('roleIds'); if (!$userId) { $this->return_json('参数错误'); } if (!$nickname) { $this->return_json('请输入用户名'); } if (!$sex) { $this->return_json('请选择性别'); } if (!$roleIds) { $this->return_json('请选择角色'); } $roleId = intval($roleIds[0]); $upDate = ['nickname' => $nickname, 'phone' => $phone, 'sex' => $sex, 'birthday' => $birthday, 'introduction' => $introduction, 'email' => $email, 'roleId' => $roleId]; $this->mdSysAdmin->update($upDate, ['userId' => $userId]); $this->return_response(); } /** * Notes:添加用户 * Created on: 2022/9/8 16:46 * Created by: dengbw */ public function index_post() { $username = $this->input_param('username'); $nickname = $this->input_param('nickname'); $phone = $this->input_param('phone'); $sex = $this->input_param('sex'); $birthday = $this->input_param('birthday'); $introduction = $this->input_param('introduction'); $email = $this->input_param('email'); $roleIds = $this->input_param('roleIds'); $password = $this->input_param('password'); if (!$username) { $this->return_json('请输入用户帐户'); } if (!$nickname) { $this->return_json('请输入用户名'); } if (!$sex) { $this->return_json('请选择性别'); } if (!$password) { $this->return_json('请输入登录密码'); } if (!$roleIds) { $this->return_json('请选择角色'); } $re = $this->mdSysAdmin->get(['username' => $username]); if ($re) { $this->return_json('用户帐号已存在'); } $roleId = intval($roleIds[0]); $password = password_hash($password, PASSWORD_BCRYPT); $addDate = ['username' => $username, 'nickname' => $nickname, 'phone' => $phone, 'sex' => $sex, 'birthday' => $birthday , 'password' => $password, 'introduction' => $introduction, 'email' => $email, 'roleId' => $roleId, 'createTime' => date('Y-m-d H:i:s')]; $id = $this->mdSysAdmin->add($addDate); if (!$id) { $this->return_json('添加用户失败'); } $this->return_response(); } /** * Notes:修改状态 * Created on: 2022/9/8 16:10 * Created by: dengbw */ public function status_put() { $userId = $this->input_param('userId'); $status = $this->input_param('status'); if (!$userId) { $this->return_json('参数错误'); } $this->mdSysAdmin->update(['status' => $status], ['userId' => $userId]); $this->return_response(); } /** * Notes:修改密码 * Created on: 2022/9/8 16:11 * Created by: dengbw */ public function password_put() { $userId = $this->input_param('userId'); $password = $this->input_param('password'); if (!$userId) { $this->return_json('参数错误'); } if (!$password) { $this->return_json('请输入重置密码'); } $password = password_hash($password, PASSWORD_BCRYPT); $this->mdSysAdmin->update(['password' => $password], ['userId' => $userId]); $this->return_response(); } /** * Notes:删除用户 * Created on: 2022/9/8 16:10 * Created by: dengbw * @param null $userId */ public function index_delete($userId = null) { if (!$userId) { $this->return_json('参数错误'); } $this->mdSysAdmin->update(['status' => -1], ['userId' => $userId]); $this->return_response(); } /** * Notes:批量删除用户 * Created on: 2022/9/8 17:11 * Created by: dengbw */ public function batch_delete() { $ids = $this->input_param('ids'); if (!$ids) { $this->return_json('参数错误'); } $str_ids = implode(',', $ids); if ($str_ids) { $this->mdSysAdmin->update(['status' => -1], ["userId in($str_ids)" => null]); } $this->return_response(); } /** * Notes:栓验字段 * Created on: 2022/9/8 15:52 * Created by: dengbw */ public function existence_get() { $field = $this->input_param('field'); $value = $this->input_param('value'); $id = $this->input_param('id'); if (!$id) { $where = [$field => $value, 'status<>' => -1]; $re = $this->mdSysAdmin->get($where); if ($re) { $this->return_json('已存在', 0); } } $this->return_json('不存在', 1); } }