public static function &get_instance()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #2
0
 public function handle_request_internal()
 {
     $req = APF::get_instance()->get_request();
     $res = APF::get_instance()->get_response();
     $params = $req->get_parameters();
     $pro = $params['pro'] ? $params['pro'] : 'all';
     $user_id = $req->get_user_id();
     $departments = Bll_DdCommonBiz::get_instance()->get_departments_for_user_group();
     $groups = Bll_UserGroupCustomBiz::get_instance()->get_all_groups();
     $input_arr = array('type_key' => 'page', 'type_value' => 'onlinenew');
     $return = " ";
     if (isset($params['group_id']) && !empty($params['group_id'])) {
         $input_arr['groups'] = explode("|", $params['group_id']);
         array_pop($input_arr['groups']);
         $return = Bll_ReportGroupSelectedBiz::get_instance()->insert_selected_group($input_arr);
     }
     if ($return == null || $return == " ") {
         $page_bind_groups = "";
     } else {
         $page_bind_groups = Bll_ReportGroupSelectedBiz::get_instance()->get_group_ids_arr($input_arr);
     }
     foreach ($departments as $value) {
         if (intval($value->value) < 17 || intval($value->value) > 26) {
             $department[$value->value] = $value->name;
         }
     }
     $page_bind_groups_with_name = array();
     foreach ($groups as $value) {
         $group[$value->department][] = array('name' => $value->group_name, 'id' => $value->id);
         if (!empty($page_bind_groups) || strlen($page_bind_groups[0]) > 0) {
             foreach ($page_bind_groups as $p) {
                 if ($p == $value->id) {
                     $temp = array();
                     $temp['id'] = $p;
                     $temp['name'] = $value->group_name;
                     array_push($page_bind_groups_with_name, $temp);
                 }
             }
         }
     }
     $tab_info = array('all' => array('name' => 'ALL', 'click' => false), 'mobile' => array('name' => 'Mobile', 'click' => false), 'pc' => array('name' => 'Pc', 'click' => false));
     $tab_info[$pro]['click'] = true;
     $req->set_attribute('tab_info', $tab_info);
     $req->set_attribute('department', $department);
     if ($group != null) {
         $req->set_attribute('group', $group);
     }
     $req->set_attribute('user_id', $user_id);
     if (!empty($page_bind_groups) || strlen($page_bind_groups[0]) > 0) {
         $req->set_attribute('page_bind_groups', $page_bind_groups);
     }
     if (!empty($page_bind_groups_with_name) || strlen($page_bind_groups_with_name) > 0) {
         $req->set_attribute('page_bind_groups_with_name', $page_bind_groups_with_name);
     }
     $req->set_attribute('department_id', $department_id);
     $product = $params['pro'] ? $params['pro'] : 0;
     $tab_info = APF::get_instance()->get_config('department');
     /*$tab_info = array(
                     0 => array('name' => 'Overview', 'click' => false),
                     1 => array('name' => 'Anjuke', 'click' => false),
                     2 => array('name' => 'Aifang', 'click' => false),
                     3 => array('name' => 'Haozu', 'click' => false),
                     4 => array('name' => 'Jinpu', 'click' => false),
                     5 => array('name' => 'Mobile', 'click' => false),
                     6 => array('name' => 'Inc', 'click' => false)
     
             );*/
     $tab_info[$product]['click'] = true;
     $month_query = $params['form_month'] ? $params['form_month'] : date("Y-m", strtotime('now'));
     $depart_value_id = array('0' => '99', '10' => '51', '11' => '52', '12' => '53', '13' => '54', '20' => '52', '5' => '100', '15' => '56', '24' => '75');
     $pro_id = $depart_value_id[$product];
     $begin = date('Y-m-01', strtotime('now'));
     $end = date('Y-m-t', strtotime('now'));
     $detail_url = Ticket_CustomQueryController::build_uri() . "?act=query&page_current=1&created_at[v][1][b]=" . $begin . "&created_at[v][1][e]=" . $end . "&environment[v][]=19&department[v][]=" . $pro_id . "&sort_by=resolution&sort_order=desc&sort_c=&sort_o=desc";
     $departments = Bll_DdCommonBiz::get_instance()->get_departments_new();
     $department = array();
     foreach ($departments as $depart) {
         $department[$depart->value] = $depart->name;
     }
     //overview
     if ($product == 0) {
         $rows = 30 * count($department);
         $counts_all = Bll_ReportDayOnlineBiz::get_instance()->get_counts_by_date_all($rows, $product);
         //每个部门
         $counts_all = array_reverse($counts_all);
         $count_day_sec = array();
         $counts_all_temp = array();
         /*$count ="";
                     $day="";
                     foreach($counts_all as $row){
                         if (  in_array( $row->department,array('14','15','16','18','19') ) ){
                             $count = $count + $row->count;
                             $day =$row->day;
                         }else{
                             $counts_all_temp[] =$row;
                         }
                     }
                     $count_day_sec[$day]['移动']=$count."";
         
         
                     foreach ($counts_all_temp as $row) {
                         $count_day_sec[$row->day][$department[$row->department]] = $row->count;
                     }*/
         foreach ($counts_all as $row) {
             $count_day_sec[$row->day][$department[$row->department]] = $row->count;
         }
         foreach ($count_day_sec as $day => $ticketcnt) {
             $count = $ticketcnt['Mobile-broker'] + $ticketcnt['Mobile-jinpu'] + $ticketcnt['Mobile-xinfang'] + $ticketcnt['Mobile-haozu'] + $ticketcnt['Mobile-anjuke'];
             $count_day_sec[$day]['移动'] = $count;
             unset($count_day_sec[$day]['Mobile-broker']);
             unset($count_day_sec[$day]['Mobile-jinpu']);
             unset($count_day_sec[$day]['Mobile-xinfang']);
             unset($count_day_sec[$day]['Mobile-haozu']);
             unset($count_day_sec[$day]['Mobile-anjuke']);
         }
         $count_day_all = array();
         foreach ($count_day_sec as $key => $row) {
             $count_day_all[] = array_merge(array('date' => $key), $row);
         }
         //$count_day_all[] = array_merge($count_day_all,$temparray);
         //month_all
         //$rows_month = 12 * count($department);
         //array_pop($department);
         //array_pop($department);
         //month_all
         $rows_month = 12 * count($department);
         $last_twelve_month = array();
         for ($month = date('Y-m-d', strtotime('now')), $times = 12; $times > 0; $month = date('Y-m-d', strtotime('last month', strtotime($month))), --$times) {
             $last_twelve_month[] = date('Y-m', strtotime($month));
         }
         $last_twelve_month = array_reverse($last_twelve_month);
         foreach ($last_twelve_month as $month) {
             foreach ($department as $key => $value) {
                 $departc[] = Bll_ReportMonthOnlineBiz::get_instance()->get_counts_by_month($month, 'all', $key);
             }
             $counts_month = $departc;
         }
         foreach ($counts_month as $value) {
             $temp[] = $value[0];
         }
         $counts_month = $temp;
         /*$count_month_temp = array();
           $count= 0;
           $month="";
           foreach($counts_month as $row){
               if (  in_array( $row->department,array('14','15','16','18','19') ) ){
                   $count = $count + $row->count;
                   $month =$row->month;
               }else{
                   $count_month_temp[] =$row;
               }
           }*/
         //$counts_month = Bll_ReportMonthOnlineBiz::get_instance()->get_counts_by_type('all', $rows_month, $product, 1);
         $count_month_sec = array();
         foreach ($counts_month as $row) {
             $count_month_sec[$row->month][$department[$row->department]] = $row->count;
         }
         array_shift($count_month_sec);
         foreach ($count_month_sec as $month => $ticketcnt) {
             $count = $ticketcnt['Mobile-broker'] + $ticketcnt['Mobile-jinpu'] + $ticketcnt['Mobile-xinfang'] + $ticketcnt['Mobile-haozu'] + $ticketcnt['Mobile-anjuke'];
             $count_month_sec[$month]['移动'] = $count;
             unset($count_month_sec[$month]['Mobile-broker']);
             unset($count_month_sec[$month]['Mobile-jinpu']);
             unset($count_month_sec[$month]['Mobile-xinfang']);
             unset($count_month_sec[$month]['Mobile-haozu']);
             unset($count_month_sec[$month]['Mobile-anjuke']);
         }
         //$count_month_sec[$month]['移动']=$count."";
         $count_month_all = array();
         foreach ($count_month_sec as $key => $row) {
             $count = $row['用户端'] + $row['开发商'] + $row['CRM'] + $row['客户端'] + $row['移动'] + $row['Inc.'];
             $count_month_all[] = array_merge(array('date' => $key, 'count' => $count), $row);
         }
         /*$depart_staff = array(
           '1' => 'Inc',
           '2' => 'Anjuke',
           '3' => 'Aifang',
           '4' => 'Haozu',
           '5' => 'Jinpu',
           '6' => 'Mobile'
           );*/
         $m_begin = date('Y-m', strtotime('-7 month'));
         $m_end = date('Y-m', strtotime('now'));
         $tech_persons = Bll_ReportPersonCountBiz::get_instance()->get_counts_by_month($m_begin, $m_end);
         $tech_count = array();
         foreach ($tech_persons as $row) {
             $tech_count[$row->month][$row->department] = $row->person_count;
         }
         $count_month_table = $count_month_all;
         rsort($count_month_table);
         array_pop($count_month_table);
         $req->set_attribute('product', $product);
         $req->set_attribute('month_query', $month_query);
         $req->set_attribute('count_day_all', $count_day_all);
         $req->set_attribute('count_month_all', $count_month_all);
         $req->set_attribute('tab_info', $tab_info);
         $req->set_attribute('detail_url', '');
         $req->set_attribute('tech_count', $tech_count);
         $req->set_attribute('count_month_table', $count_month_table);
         return 'Newreport_OnlineNew';
     }
     if ($product == 5) {
         $owner = Bll_ReportDayOnlineOwnerBiz::get_instance()->get_owner();
         $rows = 30 * count($owner);
         $allowner = array();
         foreach ($owner as $own) {
             $allowner[] = $own->owner;
         }
         $counts_all = Bll_ReportDayOnlineOwnerBiz::get_instance()->get_30day($rows);
         //$counts_all = array_reverse($data);
         $count_day_sec = array();
         foreach ($counts_all as $row) {
             $count_day_sec[$row->day][$row->owner] = $row->count;
         }
         $count_day_all = array();
         foreach ($count_day_sec as $key => $row) {
             $count_day_all[] = array_merge(array('date' => $key), $row);
         }
         $count_day_all = array_reverse($count_day_all);
         $req->set_attribute('product', $product);
         $req->set_attribute('month_query', $month_query);
         $req->set_attribute('count_day_all', $count_day_all);
         $req->set_attribute('tab_info', $tab_info);
         $req->set_attribute('allowner', $allowner);
         return 'Newreport_OnlineNew';
     }
     if ($product == 15) {
         $rows = 30 * 5;
         $counts_all = Bll_ReportDayOnlineBiz::get_instance()->get_counts_mobile_by_date($rows, array(14, 15, 16, 18, 19));
         $counts_all = array_reverse($counts_all);
         $count_day_sec = array();
         $count_day_all = array();
         $count_day_all_temp = array();
         foreach ($counts_all as $row) {
             $count_day_sec[$row->day][$department[$row->department]] = $row->count;
         }
         foreach ($count_day_sec as $day => $ticketcnt) {
             $count_day_all[] = array('date' => $day, 'count' => array_sum($ticketcnt));
             //$count_day_all_temp[$day] =  array_sum($ticketcnt);
         }
         /* foreach($count_day_all_temp as $row){
                $count_day_all[] = array('date' => $row->day,
                                         'count' => $row->count);
            }*/
         //month_all
         $rows_month = 12 * count($department);
         $last_twelve_month = array();
         for ($month = date('Y-m-d', strtotime('now')), $times = 12; $times > 0; $month = date('Y-m-d', strtotime('last month', strtotime($month))), --$times) {
             $last_twelve_month[] = date('Y-m', strtotime($month));
         }
         $last_twelve_month = array_reverse($last_twelve_month);
         foreach ($last_twelve_month as $month) {
             foreach ($department as $key => $value) {
                 $departc[] = Bll_ReportMonthOnlineBiz::get_instance()->get_counts_by_month($month, 'all', $key);
             }
             $counts_month = $departc;
         }
         foreach ($counts_month as $value) {
             $temp[] = $value[0];
         }
         $counts_month = $temp;
         //$counts_month = Bll_ReportMonthOnlineBiz::get_instance()->get_counts_by_type('all', $rows_month, $product, 1);
         $count_month_sec = array();
         foreach ($counts_month as $row) {
             $count_month_sec[$row->month][$department[$row->department]] = $row->count;
         }
         array_shift($count_month_sec);
         foreach ($count_month_sec as $month => $ticketcnt) {
             $count = $ticketcnt['Mobile-broker'] + $ticketcnt['Mobile-jinpu'] + $ticketcnt['Mobile-xinfang'] + $ticketcnt['Mobile-haozu'] + $ticketcnt['Mobile-anjuke'];
             $count_month_sec[$month]['移动'] = $count;
             unset($count_month_sec[$month]['Mobile-broker']);
             unset($count_month_sec[$month]['Mobile-jinpu']);
             unset($count_month_sec[$month]['Mobile-xinfang']);
             unset($count_month_sec[$month]['Mobile-haozu']);
             unset($count_month_sec[$month]['Mobile-anjuke']);
         }
         /*foreach($counts_month as $row){
                         if (  in_array( $row->department,array('14','15','16','18','19') ) ){
                             $count = $count + $row->count;
                             $month =$row->month;
                         }else{
                             $count_month_temp[] =$row;
                         }
                     }
                     foreach ($count_month_temp as $row) {
                         $count_month_sec[$row->month][$department[$row->department]] = $row->count;
                     }
         
                     $m_begin = date('Y-m', strtotime('-7 month'));
                     $m_end = date('Y-m', strtotime('now'));
         
                     /*$rows_month = 12;
                     $counts_month = Bll_ReportMonthOnlineBiz::get_instance()->get_counts_by_type('all', $rows_month, array(14,15,16,18,19));
                     $count_month_all = array();
                     $counts_month_sec=array();
                     foreach($counts_month as $temp){
                         $counts_month_sec[$temp['month']][$temp['department']] =$temp;
                     }
         */
         $count_month_all = array();
         $count_month_all_temp = array();
         foreach ($count_month_sec as $key => $value) {
             $count_month_all_temp[$key] = array_slice($value, -1, 1);
         }
         foreach ($count_month_all_temp as $key => $value) {
             $count_month_all[] = array('date' => $key, 'count' => $value['移动']);
         }
         //$count_month_all = array_reverse($count_month_all);
         $count_month_table = $count_month_all;
         rsort($count_month_table);
         //array_pop($count_month_table);
         //group by resolution
         $counts_resos = Bll_ReportMonthOnlineBiz::get_instance()->get_counts_by_month_mobile($month_query, 'resolution', array(14, 15, 16, 18, 19));
         $counts_reso = array();
         foreach ($counts_resos as $row) {
             $counts_reso[$row->type_value] = $row->count;
         }
         $resolutions = Bll_DdCommonBiz::get_instance()->get_resolutions();
         $resolution = array();
         foreach ($resolutions as $resolu) {
             $resolution[$resolu->value] = $resolu->name;
         }
         $count_month_reso = array();
         foreach ($resolution as $r_value => $r_name) {
             $count_reso = isset($counts_reso[$r_value]) ? $counts_reso[$r_value] : 0;
             $count_month_reso[] = array('date' => $r_name, 'count' => $count_reso);
         }
         $req->set_attribute('product', $product);
         $req->set_attribute('month_query', $month_query);
         $req->set_attribute('count_day_all', $count_day_all);
         $req->set_attribute('count_month_all', $count_month_all);
         $req->set_attribute('tab_info', $tab_info);
         $req->set_attribute('detail_url', '');
         $req->set_attribute('tech_count', $tech_count);
         $req->set_attribute('count_month_table', $count_month_table);
         $req->set_attribute('count_month_reso', $count_month_reso);
         return 'Newreport_OnlineNew';
     }
     if ($page_bind_groups != "") {
         //day_all
         $department_id = intval(Bll_DdCommonBiz::get_instance()->get_department_id_by_value($product));
         $count_day_all = array();
         $days = $this->get_30Days();
         $interval = $this->get_the_day();
         $begin = $interval[0];
         $end = $interval[1];
         $tickets_all = Bll_TicketBiz::get_instance()->get_count_online_by_month($begin, $end, 'all', $department_id);
         for ($i = 29; $i >= 0; $i--) {
             $c = 0;
             foreach ($page_bind_groups as $group_id) {
                 $group_user_names = $this->get_group_member_name($group_id);
                 if (!empty($group_user_names)) {
                     foreach ($tickets_all as $value) {
                         if (in_array($value->owner, $group_user_names) && substr($value->created_at, 0, 10) == $days[$i]) {
                             $c++;
                         }
                     }
                 }
             }
             $count_day_all[] = array('date' => $days[$i], 'count' => $c);
         }
         //month_all
         $count_month_all = array();
         $count_month_comp = array();
         $count_month_reso = array();
         $counts_comp = array();
         $counts_reso = array();
         $flag = 0;
         $months = $this->get_12Months();
         for ($i = 11; $i >= 0; $i--) {
             $total = 0;
             $month_interval = $this->get_the_month($months[$i]);
             $begin = $month_interval[0];
             $end = $month_interval[1];
             $tickets_all = Bll_TicketBiz::get_instance()->get_count_online_by_month($begin, $end, 'all', $department_id);
             if ($month_query == $months[$i]) {
                 $flag = 1;
                 foreach ($page_bind_groups as $group_id) {
                     $group_user_names = $this->get_group_member_name($group_id);
                     if (!empty($group_user_names)) {
                         foreach ($tickets_all as $value) {
                             if (in_array($value->owner, $group_user_names)) {
                                 $total++;
                                 $counts_comp[$value->component] = isset($counts_comp[$value->component]) ? ++$counts_comp[$value->component] : 1;
                                 $counts_reso[$value->resolution] = isset($counts_reso[$value->resolution]) ? ++$counts_reso[$value->resolution] : 1;
                             }
                         }
                     }
                 }
             } else {
                 foreach ($page_bind_groups as $group_id) {
                     $group_user_names = $this->get_group_member_name($group_id);
                     if (!empty($group_user_names)) {
                         foreach ($tickets_all as $value) {
                             if (in_array($value->owner, $group_user_names)) {
                                 $total++;
                             }
                         }
                     }
                 }
             }
             $count_month_all[] = array('date' => $months[$i], 'count' => $total);
         }
         if ($flag == 0) {
             $month_interval = $this->get_the_month($months[$i]);
             $begin = $month_interval[0];
             $end = $month_interval[1];
             $tickets_all = Bll_TicketBiz::get_instance()->get_count_online_by_month($begin, $end, 'all', $department_id);
             foreach ($page_bind_groups as $group_id) {
                 $group_user_names = $this->get_group_member_name($group_id);
                 if (!empty($group_user_names)) {
                     foreach ($tickets_all as $value) {
                         if (in_array($value->owner, $group_user_names)) {
                             $counts_comp[$value->component] = isset($counts_comp[$value->component]) ? ++$counts_comp[$value->component] : 1;
                             $counts_reso[$value->resolution] = isset($counts_reso[$value->resolution]) ? ++$counts_reso[$value->resolution] : 1;
                         }
                     }
                 }
             }
         }
         $components = Bll_DdComponentBiz::get_instance()->get_components($pro_id);
         foreach ($components as $component) {
             $count_row = isset($counts_comp[$component->int]) ? $counts_comp[$component->int] : 0;
             $count_month_comp[] = array('date' => $component->name, 'count' => $count_row);
         }
         $resolutions = Bll_DdCommonBiz::get_instance()->get_resolutions();
         $resolution = array();
         foreach ($resolutions as $resolu) {
             $resolution[$resolu->id] = $resolu->name;
         }
         foreach ($resolution as $r_value => $r_name) {
             $count_reso = isset($counts_reso[$r_value]) ? $counts_reso[$r_value] : 0;
             $count_month_reso[] = array('date' => $r_name, 'count' => $count_reso);
         }
     } else {
         $rows = 30;
         $counts_all = Bll_ReportDayOnlineBiz::get_instance()->get_counts_by_date_all($rows, $product);
         $counts_all = array_reverse($counts_all);
         $count_day_all = array();
         foreach ($counts_all as $row) {
             $count_day_all[] = array('date' => $row->day, 'count' => $row->count);
         }
         //month_all
         $rows_month = 12;
         $counts_month = Bll_ReportMonthOnlineBiz::get_instance()->get_counts_by_type('all', $rows_month, $product);
         $count_month_all = array();
         foreach ($counts_month as $row) {
             $count_month_all[] = array('date' => $row->month, 'count' => $row->count);
         }
         $count_month_all = array_reverse($count_month_all);
         //group by component
         $counts_comps = Bll_ReportMonthOnlineBiz::get_instance()->get_counts_by_month($month_query, 'component', $product);
         $counts_comp = array();
         foreach ($counts_comps as $row) {
             $counts_comp[$row->type_value] = $row->count;
         }
         $components = Bll_DdComponentBiz::get_instance()->get_components($pro_id);
         $count_month_comp = array();
         foreach ($components as $component) {
             $count_row = isset($counts_comp[$component->value]) ? $counts_comp[$component->value] : 0;
             $count_month_comp[] = array('date' => $component->name, 'count' => $count_row);
         }
         //group by resolution
         $counts_resos = Bll_ReportMonthOnlineBiz::get_instance()->get_counts_by_month($month_query, 'resolution', $product);
         $counts_reso = array();
         foreach ($counts_resos as $row) {
             $counts_reso[$row->type_value] = $row->count;
         }
         $resolutions = Bll_DdCommonBiz::get_instance()->get_resolutions();
         $resolution = array();
         foreach ($resolutions as $resolu) {
             $resolution[$resolu->value] = $resolu->name;
         }
         $count_month_reso = array();
         foreach ($resolution as $r_value => $r_name) {
             $count_reso = isset($counts_reso[$r_value]) ? $counts_reso[$r_value] : 0;
             $count_month_reso[] = array('date' => $r_name, 'count' => $count_reso);
         }
     }
     $req->set_attribute('product', $product);
     $req->set_attribute('month_query', $month_query);
     $req->set_attribute('count_day_all', $count_day_all);
     $req->set_attribute('count_month_all', $count_month_all);
     $req->set_attribute('count_month_comp', $count_month_comp);
     $req->set_attribute('count_month_reso', $count_month_reso);
     $req->set_attribute('tab_info', $tab_info);
     $req->set_attribute('detail_url', $detail_url);
     return 'Newreport_OnlineNew';
 }
<?php

apf_require_class('Bll_TicketBiz');
apf_require_class('Bll_ReportDayOnlineOwnerBiz');
apf_require_class('Bll_DdCommonBiz');
apf_require_class('Bll_UserBiz');
$owner = Bll_DdComponentBiz::get_instance()->get_all_blong('blongto');
$oneday = 86400 * 0;
$whichday = strtotime('now') - $oneday;
$begin = date('Y-m-d 00:00:00', $whichday);
$end = date('Y-m-d 23:59:59', $whichday);
$day = date('Y-m-d', $whichday);
foreach ($owner as $key => $value) {
    $count = Bll_TicketBiz::get_instance()->get_count_by_function($begin, $end, $value);
    $owner[$key] = $count;
}
$user = array_keys($owner);
$userName = Bll_UserBiz::get_instance()->get_chinesenames_by_ids($user);
$input_arr = array();
foreach ($userName as $userid => $username) {
    $input_arr['day'] = $day;
    $input_arr['owner'] = $username;
    $input_arr['count'] = $owner[$userid] ? $owner[$userid] : 0;
    Bll_ReportDayOnlineOwnerBiz::get_instance()->insert_count_data($input_arr);
}