作者 jinglong
1 个管道 的构建 通过 耗费 46 秒

修改总领导多个人

... ... @@ -1185,8 +1185,9 @@ class CommonController extends RestBaseController
//根据企业id查询甲方总领导项目组名称
public function getAsProjectGroup(){
$uid = ','.$this->userId.',';
$company = Db::name('company')
->where(['u_ls_id'=>$this->userId,'pid'=>['<>',0]])
->where(['u_ls_id'=>['like','%'.$uid.'%'],'pid'=>['<>',0]])
->field('id')
->select()
->toArray();
... ...
... ... @@ -196,6 +196,7 @@ class AdminProjectController extends AdminBaseController
$arr = [
['id' => 0,'name'=>'员工'],
['id' => 1,'name'=>'领导'],
['id' => 2,'name'=>'总领导'],
];
$this->assign('list',$arr);
$this->assign('company_id',$company_id);
... ... @@ -245,33 +246,32 @@ class AdminProjectController extends AdminBaseController
$u_l_id = ','.$u_l_id;
//如果有总领导
$u_ls_id = 0;
$u_ls_id = '';
$companyModel = new CompanyModel();
if($data['is_children'] == 1){
$res = $common->getIsMobile($data['mobile2']);
$userModel = new UserModel();
//合并甲方总领导
if(!empty($data['mobile2'])){
$res2 = $common->array_merge_more($keys, $data['user_login2'], $data['mobile2'], $data['position2']);
foreach ($res2 as $value2){
$res = $common->getIsMobile($value2['mobile']);
if(!$res){
//创建总领导
if(!empty($data['mobile2'])){
$leader['user_login'] = $data['user_login2'];
$leader['mobile'] = $data['mobile2'];
$leader['position'] = $data['position2'];
$leader['user_pass'] = cmf_password(123456);
$leader['user_type'] = 2;
$leader['identity'] = 2;
$leader['create_time'] = time();
$arr2 = $userModel->create($leader);
$u_ls_id = $arr2->id;
}
$value2['user_pass'] = cmf_password(123456);
$value2['user_type'] = 2;
$value2['identity'] = 2;
$value2['create_time'] = time();
$arr2 = $userModel->create($value2);
$u_ls_id .= $arr2->id.',';
}else{
if(!empty($data['mobile2'])){
$leader['user_login'] = $data['user_login2'];
$leader['position'] = $data['position2'];
$userModel->where('mobile',$data['mobile2'])->update($leader);
$u_ls_id = $res['id'];
$u_ls_id .= $res['id'].',';
}
}
}
}
if(!empty($u_ls_id)){
$u_ls_id = ','.$u_ls_id;
}
//创建甲方公司
$admin_id = cmf_get_current_admin_id();
... ... @@ -366,17 +366,9 @@ class AdminProjectController extends AdminBaseController
$part_a = $common->getCompanyById($post['a_cid'],'*');
$post['part_a'] = $part_a;
//根据总领导id获取总领导信息
$leader['user_login'] = '';
$leader['mobile'] = '';
$leader['position'] = '';
if($part_a['is_children'] == 1){
$user_leader = $common->getUserInfo($part_a['u_ls_id']);
$leader['user_login'] = $user_leader['user_login'];
$leader['mobile'] = $user_leader['mobile'];
$leader['position'] = $user_leader['position'];
}
$post['u_ls_id_a'] = $leader;
//获取甲方企业总领导
$u_ls_ids = explode(',',trim($part_a['u_ls_id'],','));
$post['u_ls_id_a'] = $common->getUserName($u_ls_ids);
//获取甲方企业负责人
$u_l_ids = explode(',',trim($part_a['u_l_id'],','));
... ... @@ -436,6 +428,16 @@ class AdminProjectController extends AdminBaseController
//甲方企业id,甲方员工id
$project = $common->getProject(['id'=>$data['id']],'id,a_cid');
//领导
if(!empty($data['u_l_id'])){
$company_a['u_l_id'] = ','.implode($data['u_l_id'],',').',';//领导
}
//员工
if(!empty($data['u_s_id'])){
$company_a['u_s_id'] = ','.implode($data['u_s_id'],',').',';//员工
}
$companyModel = new CompanyModel();
//更新甲方企业公司名称,logo,营业执照
$company_a['company_name'] = $data['company_name'];
... ... @@ -446,37 +448,13 @@ class AdminProjectController extends AdminBaseController
$company_a['company_name_head'] = $data['company_name_head'];//甲方总公司名称
$company_a['head_logo'] = $data['head_logo'];//总公司logo
//$company_a['address'] = $data['address'];//地区
//查询该总领导是否存在
$res = $common->getIsMobile($data['mobile2']);
$userModel = new UserModel();
if(!$res){
//创建总领导
if(!empty($data['mobile2'])){
$leader['user_login'] = $data['user_login2'];
$leader['mobile'] = $data['mobile2'];
$leader['position'] = $data['position2'];
$leader['user_pass'] = cmf_password(123456);
$leader['user_type'] = 2;
$leader['identity'] = 2;
$leader['create_time'] = time();
$arr2 = $userModel->create($leader);
$u_ls_id = $arr2->id;
$companyModel->where('id',$project['a_cid'])->update(['u_ls_id'=>$u_ls_id]);
}
}else{
if(!empty($data['mobile2'])){
$leader['user_login'] = $data['user_login2'];
$leader['position'] = $data['position2'];
$userModel->where('mobile',$data['mobile2'])->update($leader);
$companyModel->where('id',$project['a_cid'])->update(['u_ls_id'=>$res['id']]);
}
if(!empty($data['u_ls_id'])){
$company_a['u_ls_id'] = ','.implode($data['u_ls_id'],',').',';//总领导
}
}else{
$company_a['company_name_head'] = '';//甲方总公司名称
//$company_a['address'] = '';//地区
$company_a['u_ls_id'] = 0;//总领导
$company_a['u_ls_id'] = '';//总领导
}
$companyModel->where('id',$project['a_cid'])->update($company_a);
... ... @@ -551,10 +529,7 @@ class AdminProjectController extends AdminBaseController
public function addUserPost(){
$data = $this->request->param();
$adminCommon = new AdminCommonController();
$res = $adminCommon->getIsMobile($data['mobile']);
if($res){
$this->error('手机号不能重复');
}
//创建普通用户
$userModel = new UserModel();
$arr['user_login'] = $data['user_login'];
... ... @@ -564,7 +539,27 @@ class AdminProjectController extends AdminBaseController
$arr['user_pass'] = cmf_password(123456);
$arr['user_type'] = 2;
$arr['create_time'] = time();
if($data['identity'] == 2){
//总领导
$res = $adminCommon->getIsMobile($data['mobile']);
if($res){
//存在则不用添加
$res_user = 2;
$uid = $res['id'];
}else{
//不存在则新增用户
$res_user = $userModel->create($arr);
$uid = $res_user->id;
}
}else{
$res = $adminCommon->getIsMobile($data['mobile']);
if($res){
$this->error('手机号不能重复');
}
$res_user = $userModel->create($arr);
$uid = $res_user->id;
}
if($res_user){
$common = new AdminCommonController();
... ... @@ -573,7 +568,6 @@ class AdminProjectController extends AdminBaseController
//更新所属公司的员工或领导
$companyModel = new CompanyModel();
$uid = $res_user->id;
if($data['identity'] == 0){
//更新项目甲方员工
$projectModel = new ProjectModel();
... ... @@ -584,11 +578,16 @@ class AdminProjectController extends AdminBaseController
$res = $this->getStaffLeader($project['a_cid'],'id,u_s_id');
$u_s_id = $res['u_s_id'].$uid.',';
$res1 = $companyModel->where('id',$project['a_cid'])->update(['u_s_id'=>$u_s_id]);
}else{
}else if($data['identity'] == 1){
//更新甲方公司的领导
$res = $this->getStaffLeader($project['a_cid'],'id,u_l_id');
$u_l_id = $res['u_l_id'].$uid.',';
$res1 = $companyModel->where('id',$project['a_cid'])->update(['u_l_id'=>$u_l_id]);
}else{
//更新甲方公司的总领导
$res = $this->getStaffLeader($project['a_cid'],'id,u_ls_id');
$u_ls_id = $res['u_ls_id'].$uid.',';
$res1 = $companyModel->where('id',$project['a_cid'])->update(['u_ls_id'=>$u_ls_id]);
}
if($res1){
$this->success("添加成功");
... ... @@ -603,12 +602,26 @@ class AdminProjectController extends AdminBaseController
public function delUserPost(){
$data = $this->request->param();
$userModel = new UserModel();
$res_user = $userModel->where(['id'=>$data['uid']])->delete();
if($res_user){
$common = new AdminCommonController();
//甲方企业id,甲方员工id
$project = $common->getProject(['id'=>$data['project_id']],'id,a_cid,a_sid');
if($data['identity'] == 2){
//总领导,查询该账号是否存在其他项目中
$u_ls_id = ','.$data['uid'].',';
$res = $this->getLeadersCount(['id'=>['<>',$project['a_cid']],'u_ls_id'=>['like','%'.$u_ls_id.'%']]);
if($res == 0){
//不存在则删除
$res_user = $userModel->where(['id'=>$data['uid']])->delete();
}else{
//存在不用删除
$res_user = 1;
}
}else{
$res_user = $userModel->where(['id'=>$data['uid']])->delete();
}
if($res_user){
$companyModel = new CompanyModel();
$uid = ','.$data['uid'];
if($data['identity'] == 0){
... ... @@ -621,11 +634,16 @@ class AdminProjectController extends AdminBaseController
$res = $this->getStaffLeader($project['a_cid'],'id,u_s_id');
$u_s_id = str_replace($uid,'',$res['u_s_id']);
$res1 = $companyModel->where('id',$project['a_cid'])->update(['u_s_id'=>$u_s_id]);
}else{
}else if($data['identity'] == 1){
//更新甲方公司的领导
$res = $this->getStaffLeader($project['a_cid'],'id,u_l_id');
$u_l_id = str_replace($uid,'',$res['u_l_id']);
$res1 = $companyModel->where('id',$project['a_cid'])->update(['u_l_id'=>$u_l_id]);
}else{
//更新甲方公司的总领导
$res = $this->getStaffLeader($project['a_cid'],'id,u_ls_id');
$u_ls_id = str_replace($uid,'',$res['u_ls_id']);
$res1 = $companyModel->where('id',$project['a_cid'])->update(['u_ls_id'=>$u_ls_id]);
}
if($res1){
//更新推送甲方表
... ... @@ -647,6 +665,14 @@ class AdminProjectController extends AdminBaseController
$this->error("删除用户失败");
}
//查询甲方其他公司是否存在总领导
public function getLeadersCount($where){
$res = Db::name('company')
->where($where)
->count();
return $res;
}
//查询甲方公司领导或者员工
public function getStaffLeader($id,$field){
$res = Db::name('company')
... ...
... ... @@ -9,10 +9,10 @@
height:150px;
overflow-y: scroll;
}
.users_leader_s{
.users_leaders{
border:1px solid #f0f0f0;
padding:5px 10px;
height:80px;
height:100px;
overflow-y: scroll;
}
.users_staff{
... ... @@ -134,24 +134,34 @@
<!--<input class="form-control" type="text" name="address" placeholder="请输入企业地区"/>-->
<!--</td>-->
<!--</tr>-->
<!--<tr class="address company_address">-->
<!--<th>企业总领导</th>-->
<!--<td>-->
<!--<input class="form-control" type="text" name="user_login2" placeholder="请输入企业总领导"/>-->
<!--</td>-->
<!--</tr>-->
<tr class="address company_address">
<th>企业总领导</th>
<td>
<input class="form-control" type="text" name="user_login2" placeholder="请输入企业总领导"/>
</td>
</tr>
<tr class="address company_address">
<th>手机号(唯一)</th>
<td>
<input class="form-control" type="tel" name="mobile2" placeholder="请输入总领导手机号" value=""/>
</td>
</tr>
<tr class="address company_address">
<th>职位</th>
<td>
<input class="form-control" type="text" name="position2" placeholder="请输入总领导职位"/>
<div class="users_leaders user_leaders_a">
</div>
</td>
</tr>
<!--<tr class="address company_address">-->
<!--<th>手机号(唯一)</th>-->
<!--<td>-->
<!--<input class="form-control" type="tel" name="mobile2" placeholder="请输入总领导手机号" value=""/>-->
<!--</td>-->
<!--</tr>-->
<!--<tr class="address company_address">-->
<!--<th>职位</th>-->
<!--<td>-->
<!--<input class="form-control" type="text" name="position2" placeholder="请输入总领导职位"/>-->
<!--</td>-->
<!--</tr>-->
<!--是否有子企业end-->
<tr>
... ... @@ -350,6 +360,11 @@
$(this).parent('.users').remove();
});
//移除总领导
$(document).on('click','.u_ls_del',function () {
$(this).parent('.users').remove();
});
//移除员工
$(document).on('click','.u_s_del',function () {
$(this).parent('.users').remove();
... ... @@ -380,7 +395,7 @@
html += '<input type="hidden" name="position[]" value="'+data.position+'">';
html += '</div>';
$('.user_staff_a').append(html);
}else{
}else if(data.identity == 1){
//领导
html += '<div class="users">';
html += '<div class="user_name">'+data.user_login+'('+data.mobile+')</div>';
... ... @@ -394,6 +409,20 @@
html += '<input type="hidden" name="position1[]" value="'+data.position+'">';
html += '</div>';
$('.user_leader_a').append(html);
}else{
//总领导
html += '<div class="users">';
html += '<div class="user_name">'+data.user_login+'('+data.mobile+')</div>';
//删除图标
html += '<div class="u_ls_del" style="cursor: pointer;">';
html += '<img src="/static/images/del.png" alt="" style="width:16px;height:16px;">';
html += '</div>';
//隐藏数据,姓名,身份,手机号,职位
html += '<input type="hidden" name="user_login2[]" value="'+data.user_login+'">';
html += '<input type="hidden" name="mobile2[]" value="'+data.mobile+'">';
html += '<input type="hidden" name="position2[]" value="'+data.position+'">';
html += '</div>';
$('.user_leaders_a').append(html);
}
layer.close(index); //如果设定了yes回调,需进行手工关闭
... ...
... ... @@ -9,10 +9,10 @@
height:150px;
overflow-y: scroll;
}
.users_leader_s{
.users_leaders{
border:1px solid #f0f0f0;
padding:5px 10px;
height:80px;
height:100px;
overflow-y: scroll;
}
.users_staff{
... ... @@ -153,21 +153,28 @@
<tr class="address company_address">
<th>企业总领导</th>
<td>
<input class="form-control" type="text" name="user_login2" placeholder="请输入企业总领导" value="{$post.u_ls_id_a.user_login}"/>
</td>
</tr>
<tr class="address company_address">
<th>手机号(唯一)</th>
<td>
<input class="form-control" type="tel" name="mobile2" placeholder="请输入总领导手机号" value="{$post.u_ls_id_a.mobile}"/>
</td>
</tr>
<tr class="address company_address">
<th>职位</th>
<td>
<input class="form-control" type="text" name="position2" placeholder="请输入总领导职位" value="{$post.u_ls_id_a.position}"/>
<div class="users_leaders user_leaders_a">
<volist name="post.u_ls_id_a" id="vo">
<div class="users">
<div class="user_name">{$vo.user_login}({$vo.mobile})</div>
<?php
if($login_uid != 1){
?>
<div class="u_ls_del" style="cursor: pointer;">
<img src="/static/images/del.png" alt="" style="width:16px;height:16px;">
<input type="hidden" class="u_ls_ids" value="{$vo.id}">
</div>
<?php
}
?>
<input type="hidden" name="u_ls_id[]" value="{$vo.id}"/>
<input type="hidden" name="user_login2[]" value="{$vo.user_login}"/>
</div>
</volist>
</div>
</td>
</tr>
<!--是否有子企业end-->
<tr>
... ... @@ -474,6 +481,21 @@
});
//删除总领导
$('.u_ls_del').click(function () {
var project_id = $('#id').val();
var uid = $(this).children('.u_ls_ids').val();
layer.open({
content: '确认删除企业总领导?',
btn: ['确认', '取消'],
shadeClose: false,
yes: function(){
del(project_id,2,uid);
}
});
});
//删除员工
$('.u_s_del').click(function () {
var project_id = $('#id').val();
... ...