'待审核','1'=>'审核中','2'=>'审核通过','3'=>'已拒绝','4'=>'已撤回']; /** * [getSortByExamine 排序] * @author zhi * @param * @return */ public function getSortByExamine($whereArr) { $count = OaExamineModel::where($whereArr) ->group('create_user_id') ->field('create_user_id,count(*) as count') ->order('count desc') ->select(); return $count; } /** * [getStatistics 审批统计] * * @param $param * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getStatistics($param) { $userModel = new \app\admin\model\User(); $adminModel = new \app\admin\model\Admin(); $perUserIds = []; //权限范围内userIds $whereData = $adminModel->getWhere($param, '', $perUserIds); //统计条件 $userIds = $whereData['userIds']; //时间 $time_array = getTimeArray(); $category_list = db('oa_examine_category') ->where(['status' => 1,'is_deleted' => ['neq',1]]) ->field('category_id,title') ->select(); $fields = ['create_user_id']; foreach ($category_list as $key=>$val) { // 拼接表头标题 $category_list[$key]['title'] = strstr($val['title'],'审批') ? str_replace('审批','次数',$val['title']) : $val['title'].'次数'; $fields['SUM(CASE WHEN category_id = ' . $val['category_id'] . ' THEN 1 ELSE 0 END)'] = 'count_' . $val['category_id']; } $sql = OaExamineModel::field($fields) ->where([ 'create_time' => ['BETWEEN', $time_array['between']], 'create_user_id' => ['IN', $userIds], 'check_status' => ['neq', 4] ]) ->group('create_user_id') ->fetchSql() ->select(); $list = queryCache($sql); // $list = array_column($list, null, 'create_user_id'); foreach ($list as $key => $val) { $val['realname'] = $userModel->getUserById($val['create_user_id'])['realname']; $val['id'] = $val['create_user_id']; $list[$key] = $val; } $data = [ 'category_list' => $category_list, 'userList' => $list ]; return $data ? : []; } }