作者 lyh

gx

... ... @@ -169,5 +169,5 @@ class BaseController extends Controller
}
... ...
<?php
namespace App\Http\Logic\Bside\User;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\User\ProjectGroup;
use App\Models\User\User as UserModel;
use Illuminate\Support\Facades\DB;
class GroupLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new ProjectGroup();
$this->param = $this->requestAll;
}
/**
* @name :添加用户组
* @return void
* @author :liyuhang
* @method
*/
public function group_add(){
$this->param['project_id'] = $this->user['project_id'];
$this->param['admin_id'] = $this->user['id'];
$this->param['create_id'] = $this->user['id'];
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->add($this->param);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @name :(添加成员)group_add_user
* @author :lyh
* @method :post
* @time :2023/5/17 15:58
*/
public function group_add_user(){
$info = $this->model->read(['id'=>$this->param['id']]);
//组装数据
$str = ltrim($info['user_list'],',').$this->param['user_list'];
$arr = array_unique(explode(',',$str));
sort($arr);
$str = ','.implode(',',$arr).',';
DB::beginTransaction();
try {
$this->model->edit(['user_list'=>$str],['id'=>$this->param['id']]);
//更新父类
$this->update_parent($this->param,$info);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('添加成员失败');
}
return $this->success();
}
/**
* @name :编辑
* @return void
* @author :liyuhang
* @method
*/
public function group_edit(){
$rs = $this->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @name :(获取成员列表)user_list
* @author :lyh
* @method :post
* @time :2023/5/17 14:51
*/
public function user_list($data = [],$order = 'id'){
unset($this->param['id']);
$userModel = new UserModel();
$data = array_merge($data,$this->param);
$lists = $userModel->list($data,$order,['id','name','mobile','created_at']);
return $this->success($lists);
}
/**
* @name :详情
* @return void
* @author :liyuhang
* @method
*/
public function group_info($param = []){
if(empty($param)){
$param = $this->param;
}
$info = $this->model->read($this->param);
return $this->success($info);
}
/**
* @name :删除
* @return void
* @author :liyuhang
* @method
*/
public function group_del(){
//查看当前是否拥有父类
$info = $this->model->read(['pid'=>$this->param['id']]);
if($info !== false){
$this->fail('当前删除组织拥有下级组织,不允许删除');
}
$rs = $this->del($this->param);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @name :(更新父类成员)update_parent
* @author :lyh
* @method :post
* @time :2023/5/17 9:22
*/
public function update_parent($param,$info){
//查询当前组是否拥有父类
if($info['pid'] != 0){
$parent_info = $this->model->read(['id'=>$info['pid']]);
//把添加成员合并到上级
$str = trim(trim($param['user_list'],',').$parent_info['user_list'],',');
$arr = array_unique(explode(',', $str));
sort($arr);
$mergedString = ','.implode(',', $arr).',';
$rs = $this->model->edit(['user_list'=>$mergedString],['id'=>$parent_info['id']]);
if($rs === false){
$this->fail('更新父级失败');
}
//查看当前父级是否还拥有父级
if($parent_info['pid'] != 0){
return $this->update_parent($param,$parent_info);
}
}
return $this->success();
}
/**
* @name :(更新子类,同时清空子集成员)edit_son
* @author :lyh
* @method :post
* @time :2023/5/17 13:52
*/
public function update_son($param,$id){
//当前数据详情
$info = $this->model->read(['id'=>$id]);
//子集详情
$son_list = $this->model->list(['pid'=>$info['id']],'id');
if(!empty($son_list)){
//循环查询
foreach ($son_list as $k => $v){
$son_data = explode(',',trim($v['user_list'],','));
$son_str = '';
foreach ($son_data as $v1){
if(strpos($param['user_list'],','.$v1.',') > -1){
$son_str .= $v1.',';
}
}
$this->model->edit(['user_list'=>','.$son_str],['id'=>$v['id']]);
}
}
return true;
}
}
... ... @@ -18,10 +18,48 @@ class RoleLogic extends BaseLogic
}
/**
* @name :添加角色
* @return void
* @author :liyuhang
* @method
* @remark :获取菜单
* @name :role_get_menu
* @author :lyh
* @method :post
* @time :2023/6/17 16:40
*/
public function role_get_menu(){
//根据当前登录用户角色返回用户菜单列表
$info = $this->model->read(['id'=>$this->user['role_id']]);
$info['role_menu'] = trim($info['role_menu'],',');
$menuModel = new ProjectMenuModel();
$lists = $menuModel->where(['status'=>0])->whereIn('id',explode(',',$info['role_menu']))->get();
$lists = $lists->toArray();
$menu = array();
foreach ($lists as $k => $v){
$v = (array)$v;
if ($v['pid'] == 0) {
$v['sub'] = _get_child($v['id'], $lists);
$menu[] = $v;
}
}
return $this->success($menu);
}
/**
* @remark :获取详情
* @name :role_info
* @author :lyh
* @method :post
* @time :2023/6/17 16:39
*/
public function role_info(){
$info = $this->info($this->param);
return $this->success($info);
}
/**
* @remark :添加角色
* @name :role_add
* @author :lyh
* @method :post
* @time :2023/6/17 16:38
*/
public function role_add(){
$condition = [
... ... @@ -48,10 +86,11 @@ class RoleLogic extends BaseLogic
}
/**
* @name :编辑角色
* @return void
* @author :liyuhang
* @method
* @remark :编辑角色
* @name :role_edit
* @author :lyh
* @method :post
* @time :2023/6/17 16:38
*/
public function role_edit(){
//TODO::查询当前名称是否重复
... ... @@ -69,10 +108,11 @@ class RoleLogic extends BaseLogic
}
/**
* @name :修改状态/排序
* @return void
* @author :liyuhang
* @method
* @remark :编辑角色状态
* @name :role_status
* @author :lyh
* @method :post
* @time :2023/6/17 16:38
*/
public function role_status(){
$this->edit($this->param,['id'=>$this->param['id']]);
... ... @@ -80,9 +120,11 @@ class RoleLogic extends BaseLogic
}
/**
* @name :删除角色
* @return void
* @author :liyuhang
* @remark :删除角色
* @name :role_del
* @author :lyh
* @method :post
* @time :2023/6/17 16:38
*/
public function role_del(){
//查询当前角色下是否有用户
... ... @@ -100,38 +142,4 @@ class RoleLogic extends BaseLogic
return $this->success();
}
/**
* @name :获取角色详情
* @return void
* @author :liyuhang
* @method
*/
public function role_info(){
$info = $this->info($this->param);
return $this->success($info);
}
/**
* @name :获取菜单列表
* @return array
* @author :liyuhang
* @method
*/
public function role_get_menu(){
//根据当前登录用户角色返回用户菜单列表
$info = $this->model->read(['id'=>$this->user['role_id']]);
$info['role_menu'] = trim($info['role_menu'],',');
$menuModel = new ProjectMenuModel();
$lists = $menuModel->where(['status'=>0])->whereIn('id',explode(',',$info['role_menu']))->get();
$lists = $lists->toArray();
$menu = array();
foreach ($lists as $k => $v){
$v = (array)$v;
if ($v['pid'] == 0) {
$v['sub'] = _get_child($v['id'], $lists);
$menu[] = $v;
}
}
return $this->success($menu);
}
}
... ...
... ... @@ -19,19 +19,25 @@ class UserLogic extends BaseLogic
$this->model = new User();
$this->param = $this->requestAll;
}
/**
* @name :用户详情
* @return void
* @author :liyuhang
* @method
* @remark :获取用户详情
* @name :User_info
* @author :lyh
* @method :post
* @time :2023/6/17 16:42
*/
public function user_info(){
$info = $this->model->read($this->param);
return $this->success($info);
}
/**
* @name :添加会员
* @author :liyuhang
* @remark :添加用户
* @name :user_add
* @author :lyh
* @method :post
* @time :2023/6/17 16:42
*/
public function user_add(){
//验证当前用户是否存在
... ... @@ -56,8 +62,11 @@ class UserLogic extends BaseLogic
}
/**
* @name :编辑用户
* @author :liyuhang
* @remark :编辑用户
* @name :user_edit
* @author :lyh
* @method :post
* @time :2023/6/17 16:42
*/
public function user_edit(){
$condition = [
... ... @@ -82,8 +91,11 @@ class UserLogic extends BaseLogic
}
/**
* @name :编辑状态/排序
* @author :liyuhang
* @remark :编辑状态与排序
* @name :user_status
* @author :lyh
* @method :post
* @time :2023/6/17 16:41
*/
public function user_status(){
$this->param['operator_id'] = $this->user['id'];
... ... @@ -95,8 +107,11 @@ class UserLogic extends BaseLogic
}
/**
* @name :删除用户(逻辑删除)
* @author :liyuhang
* @remark :删除用户
* @name :user_del
* @author :lyh
* @method :post
* @time :2023/6/17 16:41
*/
public function user_del(){
$this->param['id'] = ['in',$this->param['id']];
... ... @@ -107,10 +122,11 @@ class UserLogic extends BaseLogic
/**
* @param $param
* @name :编辑管理员
* @return bool
* @author :liyuhang
* @method
* @remark :编辑用户
* @name :edits
* @author :lyh
* @method :post
* @time :2023/6/17 16:41
*/
public function edits($param){
//查看密码是否修改
... ...
... ... @@ -27,10 +27,12 @@ class UserLoginLogic
}
/***
* @name :登录
* @author :liyuhang
* @method
/**
* @remark :登录接口
* @name :login
* @author :lyh
* @method :post
* @time :2023/6/17 16:43
*/
public function login(){
//验证账号密码是否正确
... ...