143 lines
4.4 KiB
PHP
143 lines
4.4 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
require_once APPPATH . 'controllers/api/BaseController.php';
|
|
|
|
/**
|
|
* Notes:角色管理
|
|
* Created on: 2022/9/05 17:15
|
|
* Created by: dengbw
|
|
*/
|
|
class Role extends BaseController
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('market/Market_sys_role_model', 'mdSysRole');
|
|
}
|
|
|
|
/**
|
|
* Notes角色管理
|
|
* Created on: 2022/9/8 14:48
|
|
* Created by: dengbw
|
|
*/
|
|
public function index_get()
|
|
{
|
|
$page = intval($this->input_param('page'));
|
|
$limit = intval($this->input_param('limit'));
|
|
$roleName = $this->input_param('roleName');
|
|
$roleCode = $this->input_param('roleCode');
|
|
$comments = $this->input_param('comments');
|
|
$sort = $this->input_param('sort');
|
|
$order = $this->input_param('order');
|
|
$date = $where = [];
|
|
if (!$page) {
|
|
$where['status'] = 0;
|
|
} else {
|
|
$where['status>='] = 0;
|
|
}
|
|
$sort_order = 'roleId desc';
|
|
if ($sort && $order) {
|
|
$sort_order = $sort . ' ' . $order;
|
|
}
|
|
$roleName && $where['roleName'] = $roleName;
|
|
$roleCode && $where['roleCode'] = $roleCode;
|
|
$comments && $where['comments'] = $comments;
|
|
$res = $this->mdSysRole->select($where, $sort_order, $page, $limit);
|
|
foreach ($res as $v) {
|
|
$date[] = $v;
|
|
}
|
|
$this->return_response_list($date);
|
|
}
|
|
|
|
/**
|
|
* Notes:修改角色
|
|
* Created on: 2022/9/8 17:58
|
|
* Created by: dengbw
|
|
*/
|
|
public function index_put()
|
|
{
|
|
$roleId = $this->input_param('roleId');
|
|
$roleName = $this->input_param('roleName');
|
|
$roleCode = $this->input_param('roleCode');
|
|
$comments = $this->input_param('comments');
|
|
if (!$roleId) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
if (!$roleName) {
|
|
$this->return_json('请输入角色名称');
|
|
}
|
|
if (!$roleCode) {
|
|
$this->return_json('请输入角色标识');
|
|
}
|
|
$upDate = ['roleName' => $roleName, 'roleCode' => $roleCode, 'comments' => $comments];
|
|
$this->mdSysRole->update($upDate, ['roleId' => $roleId]);
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* Notes:添加角色
|
|
* Created on: 2022/9/9 11:47
|
|
* Created by: dengbw
|
|
*/
|
|
public function index_post()
|
|
{
|
|
$roleName = $this->input_param('roleName');
|
|
$roleCode = $this->input_param('roleCode');
|
|
$comments = $this->input_param('comments');
|
|
if (!$roleName) {
|
|
$this->return_json('请输入角色名称');
|
|
}
|
|
if (!$roleCode) {
|
|
$this->return_json('请输入角色标识');
|
|
}
|
|
$addDate = ['roleName' => $roleName, 'roleCode' => $roleCode, 'comments' => $comments, 'createTime' => date('Y-m-d H:i:s')];
|
|
$id = $this->mdSysRole->add($addDate);
|
|
if (!$id) {
|
|
$this->return_json('添加角色失败');
|
|
}
|
|
if ($roleCode == 'brand') {//角色品牌
|
|
$this->load->model('market/Market_sylive_organization_model', 'mdSyliveOrganization');
|
|
$re_org = $this->mdSyliveOrganization->get(['organizationName' => $roleName, 'parentId' => 0, 'status' => 0]);
|
|
if (!$re_org) {//创建品牌
|
|
$addDate = ['parentId' => 0, 'organizationName' => $roleName, 'organizationType' => 1, 'createTime' => date('Y-m-d H:i:s')];
|
|
$this->mdSyliveOrganization->add($addDate);
|
|
}
|
|
}
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* Notes:删除用户
|
|
* Created on: 2022/9/9 16:10
|
|
* Created by: dengbw
|
|
* @param null $roleId
|
|
*/
|
|
public function index_delete($roleId = null)
|
|
{
|
|
if (!$roleId) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$this->mdSysRole->update(['status' => -1], ['roleId' => $roleId]);
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* Notes:批量删除用户
|
|
* Created on: 2022/9/9 17:11
|
|
* Created by: dengbw
|
|
*/
|
|
public function batch_delete()
|
|
{
|
|
$roleIds = $this->inputs;
|
|
if (!$roleIds) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$str_roleIds = implode(',', $roleIds);
|
|
if ($str_roleIds) {
|
|
$this->mdSysRole->update(['status' => -1], ["roleId in($str_roleIds)" => null]);
|
|
}
|
|
$this->return_response();
|
|
}
|
|
|
|
} |