...
|
...
|
@@ -11,6 +11,7 @@ |
|
|
|
|
|
namespace app\portal\controller;
|
|
|
|
|
|
use app\portal\model\UserModel;
|
|
|
use cmf\controller\AdminBaseController;
|
|
|
use app\portal\model\CompanyModel;
|
|
|
use think\Db;
|
...
|
...
|
@@ -22,30 +23,26 @@ class AdminCompanyController extends AdminBaseController |
|
|
//列表页
|
|
|
public function index(){
|
|
|
$list = Db::name('company')
|
|
|
->alias('c')
|
|
|
->join('user u','c.u_l_id = u.id','LEFT')
|
|
|
->where('c.pid',0)
|
|
|
->where('pid',0)
|
|
|
->where(function (Query $query) {
|
|
|
$data = $this->request->param();
|
|
|
if (!empty($data['company_name'])) {
|
|
|
$company_name = $data['company_name'];
|
|
|
$query->where('c.company_name', 'like', "%$company_name%");
|
|
|
}
|
|
|
if (!empty($data['user_login'])) {
|
|
|
$user_login = $data['user_login'];
|
|
|
$query->where('u.user_login', 'like', "%$user_login%");
|
|
|
}
|
|
|
if (!empty($data['mobile'])) {
|
|
|
$mobile = $data['mobile'];
|
|
|
$query->where('u.mobile', 'like', "%$mobile%");
|
|
|
$query->where('company_name', 'like', "%$company_name%");
|
|
|
}
|
|
|
})
|
|
|
->field('c.id,c.company_name,u.user_login,u.mobile')
|
|
|
->order('c.id desc')
|
|
|
->field('id,company_name,u_l_id')
|
|
|
->order('id desc')
|
|
|
->paginate(10,false,['query'=>request()->param()]);
|
|
|
$res = $list->toArray();
|
|
|
// 获取分页显示
|
|
|
$page = $list->render();
|
|
|
foreach($res['data'] as &$value){
|
|
|
$ids = explode(',',trim($value['u_l_id'],','));
|
|
|
$user = $this->getLeader($ids);
|
|
|
$value['user_login'] = $user['user_login'];
|
|
|
// $value['mobile'] = $user['mobile'];
|
|
|
}
|
|
|
$this->assign('list', $res['data']);
|
|
|
$this->assign('page', $page);
|
|
|
|
...
|
...
|
@@ -57,6 +54,19 @@ class AdminCompanyController extends AdminBaseController |
|
|
return $this->fetch();
|
|
|
}
|
|
|
|
|
|
//获取领导用户名
|
|
|
public function getLeader($ids){
|
|
|
$res = Db::name('user')
|
|
|
->whereIn('id',$ids)
|
|
|
->where('user_status',1)
|
|
|
->field('id,user_login,mobile')
|
|
|
->select()
|
|
|
->toArray();
|
|
|
$arr['user_login'] = implode(',',array_values(array_column($res,'user_login')));
|
|
|
// $arr['mobile'] = implode(',',array_values(array_column($res,'mobile')));
|
|
|
return $arr;
|
|
|
}
|
|
|
|
|
|
//新增页面
|
|
|
public function add(){
|
|
|
//查询领导
|
...
|
...
|
@@ -108,7 +118,7 @@ class AdminCompanyController extends AdminBaseController |
|
|
//乙方数据
|
|
|
$part_B['company_name'] = $data['company_name'];
|
|
|
//负责人uid
|
|
|
$part_B['u_l_id'] = $data['u_l_id'];
|
|
|
$part_B['u_l_id'] = ','.implode(',',$data['u_l_id']).',';
|
|
|
//员工uid,以逗号隔开
|
|
|
$part_B['u_s_id'] = ','.implode(',',$data['u_s_id']).',';
|
|
|
//营业执照
|
...
|
...
|
@@ -133,7 +143,7 @@ class AdminCompanyController extends AdminBaseController |
|
|
}
|
|
|
$part_A['is_children'] = $data['is_children'.$value];
|
|
|
//负责人uid
|
|
|
$part_A['u_l_id'] = $data['u_l_id'.$value];
|
|
|
$part_A['u_l_id'] = ','.implode(',',$data['u_l_id'.$value]).',';
|
|
|
//员工uid,以逗号隔开
|
|
|
$part_A['u_s_id'] = ','.implode(',',$data['u_s_id'.$value]).',';
|
|
|
//营业执照
|
...
|
...
|
@@ -144,6 +154,17 @@ class AdminCompanyController extends AdminBaseController |
|
|
$companyModel->create($part_A);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//创建乙方登录普通管理员账号
|
|
|
$userModel = new UserModel();
|
|
|
$arr['user_login'] = $res->company_name;
|
|
|
$arr['user_pass'] = cmf_password('123456');
|
|
|
$arr['company_id'] = $res->id;
|
|
|
$res1 = $userModel->create($arr);
|
|
|
//role_user表
|
|
|
$role['role_id'] = 2;
|
|
|
$role['user_id'] = $res1->id;
|
|
|
Db::name('RoleUser')->insert($role);
|
|
|
$this->success("添加成功!", url("AdminCompany/index"));
|
|
|
}
|
|
|
|
...
|
...
|
@@ -154,6 +175,7 @@ class AdminCompanyController extends AdminBaseController |
|
|
$res = Db::name('company')
|
|
|
->where('id',$id)
|
|
|
->find();
|
|
|
$res['u_l_id'] = explode(',',trim($res['u_l_id'],','));
|
|
|
$res['u_s_id'] = explode(',',trim($res['u_s_id'],','));
|
|
|
//获取甲方数据
|
|
|
$res1 = Db::name('company')
|
...
|
...
|
@@ -161,9 +183,9 @@ class AdminCompanyController extends AdminBaseController |
|
|
->select()
|
|
|
->toArray();
|
|
|
foreach($res1 as &$value){
|
|
|
$value['u_l_id'] = explode(',',trim($value['u_l_id'],','));
|
|
|
$value['u_s_id'] = explode(',',trim($value['u_s_id'],','));
|
|
|
}
|
|
|
|
|
|
//数组数量
|
|
|
$index = count($res1);
|
|
|
$this->assign('index',$index);
|
...
|
...
|
@@ -221,7 +243,7 @@ class AdminCompanyController extends AdminBaseController |
|
|
//乙方数据
|
|
|
$part_B['company_name'] = $data['company_name'];
|
|
|
//负责人uid
|
|
|
$part_B['u_l_id'] = $data['u_l_id'];
|
|
|
$part_B['u_l_id'] = ','.implode(',',$data['u_l_id']).',';
|
|
|
//员工uid,以逗号隔开
|
|
|
$part_B['u_s_id'] = ','.implode(',',$data['u_s_id']).',';
|
|
|
//营业执照
|
...
|
...
|
@@ -230,7 +252,6 @@ class AdminCompanyController extends AdminBaseController |
|
|
//公司logo
|
|
|
$part_B['logo'] = $data['logo'];
|
|
|
$companyModel->where('id',$data['id'])->update($part_B);
|
|
|
|
|
|
//甲方数据
|
|
|
if(isset($data['flag'])){
|
|
|
foreach($data['flag'] as $value){
|
...
|
...
|
@@ -246,7 +267,7 @@ class AdminCompanyController extends AdminBaseController |
|
|
}
|
|
|
$part_A['is_children'] = $data['is_children'.$value];
|
|
|
//负责人uid
|
|
|
$part_A['u_l_id'] = $data['u_l_id'.$value];
|
|
|
$part_A['u_l_id'] = ','.implode(',',$data['u_l_id'.$value]).',';
|
|
|
//员工uid,以逗号隔开
|
|
|
$part_A['u_s_id'] = ','.implode(',',$data['u_s_id'.$value]).',';
|
|
|
//营业执照
|
...
|
...
|
|