AdminPartBController.php 3.7 KB
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------

namespace app\portal\controller;

use cmf\controller\AdminBaseController;
use think\Db;
use think\db\Query;
use app\portal\model\InspectModel;

class AdminPartBController extends AdminBaseController
{
    private $identity_arr = ['员工','领导','总领导'];

    //列表页
    public function index(){
        $common = new AdminCommonController();
        //查询乙方员工
        $staff_B = $common->getPartB();
        //员工
        $s_ids = '';
        //领导
        $l_ids = '';
        //总领导
        $ls_ids = '';
        foreach($staff_B as $s_value){
            $s_ids .= $s_value['u_s_id'].',' ;
            $l_ids .= $s_value['u_l_id'].',';
            if(!empty($s_value['u_ls_id'])){
                $ls_ids .= $s_value['u_ls_id'].',';
            }
        }
        $ids = $s_ids.$l_ids.$ls_ids;
        $ids = explode(',',trim($ids,','));
        //根据id获取员工
        $list = Db::name('user')
            ->whereIn('id',$ids)
            ->where('user_status',1)
            ->where(function (Query $query) {
                $data = $this->request->param();
                if (!empty($data['user_login'])) {
                    $user_login = $data['user_login'];
                    $query->where('user_login', 'like', "%$user_login%");
                }
                if (!empty($data['mobile'])) {
                    $mobile = $data['mobile'];
                    $query->where('mobile', 'like', "%$mobile%");
                }
            })
            ->field('id,user_login,avatar,identity,mobile,position')
            ->order('id desc')
            ->paginate(10,false,['query'=>request()->param()]);
        $s_user = $list->toArray();

        foreach($s_user['data'] as &$value){
            $value['identity_b'] = $this->identity_arr[$value['identity']];
            $uid = $value['id'];
            $value['company_name'] = '';
            foreach($staff_B as $c_value){
                if($value['identity'] == 0){
                    //员工
                    $u_s_ids = explode(',',trim($c_value['u_s_id'],','));
                    if(in_array($uid,$u_s_ids)){
                        $value['company_name'] = $c_value['company_name'];

                        $arr = $common->getProjectB($c_value['id'],$uid);
                        $value['project_name'] = isset($arr['project_name'])&&!empty($arr['project_name'])?$arr['project_name']:'';
                    }
                }else if($value['identity'] == 1){
                    //领导
                    if($uid == $c_value['u_l_id']){
                        $value['company_name'] = $c_value['company_name'];
                    }
                }else{
                    //总领导
                    if($uid == $c_value['u_ls_id']){
                        $value['company_name'] = $c_value['company_name'];
                    }
                }

            }
        }
        $page = $list->render();
        $host = new InspectModel();
        $this->assign('host',$host::host);
        $this->assign('list',$s_user['data']);
        $this->assign('page',$page);
        // 渲染模板输出
        return $this->fetch();
    }
}