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

    //列表页
    public function index(){
        $common = new AdminCommonController();
        //查询甲方员工
        $staff_A = $common->getPartA();
        //员工
        $s_ids = '';
        //领导
        $l_ids = '';
        //总领导
        $ls_ids = '';
        foreach($staff_A 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_a'] = $this->identity_arr[$value['identity']];
            $uid = $value['id'];
            $value['company_name_head'] = '';
            $value['company_name'] = '';
            $value['is_children'] = 0;
            foreach($staff_A 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'];
                        //是否有子企业
                        if($c_value['is_children'] == 1){
                            $value['company_name_head'] = $c_value['company_name_head'];
                        }
                        $value['is_children'] = $c_value['is_children'];

                        //查找甲方员工所在的项目组
                        $arr = $common->getProjectA($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'];
                        //是否有子企业
                        if($c_value['is_children'] == 1){
                            $value['company_name_head'] = $c_value['company_name_head'];
                        }
                        $value['is_children'] = $c_value['is_children'];
                    }
                }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'];
                        }
                        $value['is_children'] = $c_value['is_children'];
                    }
                }

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

    //根据uid查询用户正常考勤日期
    public function getNormalWork($uid){
        //聚合相同日期
        $res = Db::name('work')
            ->where(['uid'=>$uid])
            ->field('id,uid,create_time')
            ->group("DATE_FORMAT(FROM_UNIXTIME(create_time),'%Y-%m-%d')")
            ->select()
            ->toArray();
        $normal = 0;
        $not_normal = 0;
        $arr = [];
        foreach($res as $value){
            $count = $this->getWorkCount($value['uid'],$value['create_time']);
            if($count == 2){
                //正常
                $arr['normal'] = ++$normal;
            }else{
                //缺卡
                $arr['not_normal'] = ++$not_normal;
            }
        }
        return $arr;
    }

    //根据uid获取是否含有上班,下班
    public function getWorkCount($uid,$create_time){
        $time = date('Y-m-d',$create_time);
        $time1 = date('Y-m-d',$create_time+86400);
        //查询所有记录
        $count = Db::name('work')
            ->where(['uid'=>$uid])
            ->whereTime('create_time',[$time,$time1])
            ->count();
        return $count;
    }
}