|
|
|
<?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;
|
|
|
|
}
|
|
|
|
} |