AdminPartCController.php 3.8 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 AdminPartCController extends AdminBaseController
{
    private $identity_arr = ['员工','领导','总领导'];

    //列表页
    public function index(){
        //查询领导
        $staff_B = $this->getLeader();
        //员工
        //领导
        $l_ids = '';
        //总领导
        $ls_ids = '';
        foreach($staff_B as $s_value){
            $l_ids .= $s_value['u_l_id'].',';
            if(!empty($s_value['u_ls_id'])){
                $ls_ids .= $s_value['u_ls_id'].',';
            }
        }
        $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')
            ->order('id desc')
            ->paginate(10,false,['query'=>request()->param()]);
        $s_user = $list->toArray();
        foreach($s_user['data'] as &$value){
            $value['identity_c'] = $this->identity_arr[$value['identity']];
            $uid = $value['id'];
            $value['company_name'] = '';
            $value['company_name_head'] = '';
            foreach($staff_B as $c_value){
                if($value['identity'] == 1){
                    //领导
                    if($uid == $c_value['u_l_id']){
                        $value['company_name'] = $c_value['company_name'];
                        //是否有子企业
                        if($c_value['is_children'] == 1){
                            $value['company_name_head'] = $c_value['company_name_head'];
                        }
                    }
                }else{
                    //总领导
                    if($uid == $c_value['u_ls_id']){
                        $value['company_name'] = $c_value['company_name'];
                        //是否有子企业
                        if($c_value['is_children'] == 1){
                            $value['company_name_head'] = $c_value['company_name_head'];
                        }
                    }
                }

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

    //查询领导id
    public function getLeader(){
        $staff = Db::name('company')
            ->field('id,company_name,u_l_id,u_ls_id,is_children,company_name_head')
            ->select()
            ->toArray();
        return $staff;
    }
}