Files
spacestation/agent/admin/controllers/api/pinan/User.php
T
2025-07-27 12:22:34 +08:00

175 lines
5.9 KiB
PHP

<?php
defined('BASEPATH') or exit('No direct script access allowed');
require_once APPPATH . 'controllers/api/BaseController.php';
class User extends BaseController
{
public function __construct()
{
parent::__construct();
$this->load->model('agent/pingan/pingan_users_model', 'pinganUsers');
}
public function page_get()
{
$page = $this->input_param('page');
$limit = $this->input_param('limit');
$username = $this->input_param('username');
$mobile = $this->input_param('mobile');
$sort = $this->input_param('sort');
$order = $this->input_param('order');
!$page && $page = 1;
!$limit && $limit = 10;
$sort_order = 'id desc';
if ($sort && $order) {
$sort_order = $sort . ' ' . $order;
}
$where = $list = [];
$where['status>='] = 0;
$username && $where["username like '%{$username}%'"] = null;
$mobile && $where["mobile like '%{$mobile}%'"] = null;
$count = $this->pinganUsers->count($where);
if ($count) {
$res = $this->pinganUsers->select($where, $sort_order, $page, $limit);
foreach ($res as $v) {
$status = intval($v['status']);
$list[] = [
'id' => $v['id'], 'mobile' => $v['mobile'],
'username' => $v['username'], 'userCode' => $v['userCode'],
'status' => $status, 'createTime' => $v['createTime'],
'typeCn' => Pingan_users_model::TYPE_CN[$v['groupType']],
];
}
}
$date = ['list' => $list, 'count' => $count];
$this->return_response_list($date);
}
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);
}
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();
}
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();
}
public function status_put()
{
$id = $this->input_param('id');
$status = $this->input_param('status');
if (!$id) {
$this->return_json('参数错误');
}
$this->pinganUsers->update(['status' => $status], ['id' => $id]);
$this->return_response();
}
public function index_delete($id = null)
{
if (!$id) {
$this->return_json('参数错误');
}
$this->pinganUsers->update(['status' => -1], ['id' => $id]);
$this->return_response();
}
public function batch_delete()
{
$ids = $this->input_param('ids');
if (!$ids) {
$this->return_json('参数错误');
}
$str_ids = implode(',', $ids);
if ($str_ids) {
$this->pinganUsers->update(['status' => -1], ["id in($str_ids)" => null]);
}
$this->return_response();
}
}