...
|
...
|
@@ -343,12 +343,136 @@ class UserController extends AdminBaseController |
|
|
$this->error("最高管理员不能删除!");
|
|
|
}
|
|
|
|
|
|
if (Db::name('user')->delete($id) !== false) {
|
|
|
Db::name("RoleUser")->where("user_id", $id)->delete();
|
|
|
$this->success("删除成功!");
|
|
|
} else {
|
|
|
$this->error("删除失败!");
|
|
|
//删除乙方公司关联的用户uid
|
|
|
$res = $this->getUid($id);
|
|
|
$company_id = $res['company_id'];
|
|
|
$b_uid = $this->getCompanyB($company_id);
|
|
|
$a_uid = $this->getCompanyA($company_id);
|
|
|
$uid = $b_uid.','.$a_uid;
|
|
|
$uids = explode(',',$uid);
|
|
|
Db::name('user')->whereIn('id',$uids)->delete();
|
|
|
|
|
|
//删除乙方公司
|
|
|
Db::name("company")->where("id", $company_id)->delete();
|
|
|
|
|
|
//删除甲方公司
|
|
|
Db::name("company")->where("pid", $company_id)->delete();
|
|
|
|
|
|
//删除甲方公司对应的项目
|
|
|
$project_ids = $this->getProjectId($company_id);
|
|
|
Db::name("project")->whereIn("id", $project_ids)->delete();
|
|
|
|
|
|
//根据项目ids删除日检
|
|
|
Db::name("inspect")->whereIn("project_id", $project_ids)->delete();
|
|
|
|
|
|
//根据项目ids删除月检
|
|
|
Db::name("check")->whereIn("project_id", $project_ids)->delete();
|
|
|
|
|
|
//根据项目ids删除年检
|
|
|
Db::name("pro_check")->whereIn("project_id", $project_ids)->delete();
|
|
|
|
|
|
//根据项目ids删除报修
|
|
|
Db::name("repair")->whereIn("project_id", $project_ids)->delete();
|
|
|
|
|
|
//根据项目ids删除改造
|
|
|
Db::name("reform")->whereIn("project_id", $project_ids)->delete();
|
|
|
|
|
|
//根据项目ids删除培训
|
|
|
Db::name("train")->whereIn("project_id", $project_ids)->delete();
|
|
|
|
|
|
//根据项目ids删除演习
|
|
|
Db::name("exercise")->whereIn("project_id", $project_ids)->delete();
|
|
|
|
|
|
|
|
|
//删除user用户数据
|
|
|
Db::name('user')->where('id',$id)->delete();
|
|
|
//删除用户角色表
|
|
|
Db::name("RoleUser")->where("user_id", $id)->delete();
|
|
|
|
|
|
$this->success('删除成功!');
|
|
|
|
|
|
|
|
|
// if (Db::name('user')->delete($id) !== false) {
|
|
|
// Db::name("RoleUser")->where("user_id", $id)->delete();
|
|
|
//
|
|
|
//
|
|
|
// $this->success("删除成功!");
|
|
|
// } else {
|
|
|
// $this->error("删除失败!");
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
//根据乙方公司查找项目id
|
|
|
public function getProjectId($b_cid){
|
|
|
$res = Db::name('project')
|
|
|
->where('b_cid',$b_cid)
|
|
|
->field('id')
|
|
|
->select()
|
|
|
->toArray();
|
|
|
$id = array_column($res,'id');
|
|
|
return $id;
|
|
|
}
|
|
|
|
|
|
//根据乙方公司id,查找乙方公司所属的所有用户以及对应甲方公司所有的用户
|
|
|
public function getUid($id){
|
|
|
$res = Db::name('user')
|
|
|
->where(['id'=>$id,'user_type'=>1])
|
|
|
->field('id,company_id')
|
|
|
->find();
|
|
|
return $res;
|
|
|
}
|
|
|
|
|
|
//获取乙方公司人员
|
|
|
public function getCompanyB($company_id){
|
|
|
$res = Db::name('company')
|
|
|
->where('id',$company_id)
|
|
|
->field('u_l_id,u_s_id')
|
|
|
->find();
|
|
|
//领导uid
|
|
|
$u_l_id = '';
|
|
|
if($res['u_l_id']){
|
|
|
$u_l_id = trim($res['u_l_id'],',');
|
|
|
}
|
|
|
//员工uid
|
|
|
$u_s_id = '';
|
|
|
if($res['u_l_id']){
|
|
|
$u_s_id = trim($res['u_s_id'],',');
|
|
|
}
|
|
|
$uid = $u_l_id.','.$u_s_id;
|
|
|
return $uid;
|
|
|
}
|
|
|
|
|
|
//获取甲方公司人员
|
|
|
public function getCompanyA($company_id){
|
|
|
$res = Db::name('company')
|
|
|
->where('pid',$company_id)
|
|
|
->field('u_l_id,u_ls_id,u_s_id')
|
|
|
->select()
|
|
|
->toArray();
|
|
|
$uid = '';
|
|
|
foreach($res as $value){
|
|
|
//领导
|
|
|
if($value['u_l_id']){
|
|
|
$u_l_id = trim($value['u_l_id'],',');
|
|
|
}else{
|
|
|
$u_l_id = '';
|
|
|
}
|
|
|
//总领导
|
|
|
if($value['u_ls_id']){
|
|
|
$u_ls_id = trim($value['u_ls_id'],',');
|
|
|
}else{
|
|
|
$u_ls_id = '';
|
|
|
}
|
|
|
//员工
|
|
|
if($value['u_l_id']){
|
|
|
$u_s_id = trim($value['u_s_id'],',');
|
|
|
}else{
|
|
|
$u_s_id = '';
|
|
|
}
|
|
|
$uid .= ','.$u_l_id.','.$u_ls_id.','.$u_s_id;
|
|
|
}
|
|
|
$uid = trim($uid,',');
|
|
|
return $uid;
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
|