2016-01-29 26 views
0

我正在嘗試使自己的功能,我不明白爲什麼它需要太多的時間來加載。我在cakephp3上的腳本太長,無法加載

如果有人可以幫忙嗎?

我想注意到其他功能如列表,編輯或添加客戶運行良好。

這是我的代碼:

<?php 
namespace App\Controller; 

use App\Controller\AppController; 
use Cake\Collection\Collection; 

/** 
* Customer Controller 
* 
* @property \App\Model\Table\CustomerTable $Customer 
*/ 
class CustomerController extends AppController 
{ 

    /** 
    * Index method 
    * 
    * @return void 
    */ 



    /** 
    *Login method 
    * 
    *@param string|null $login Customer login 
    *@param string|null $pasword Customer password 
    *@return true Redirects to \connection index 
    */ 
    public function login() 
    { 
     //$this->layout = 'default2'; 

     // Si vous accédez à la session plusieurs fois, 
     // vous voudrez probablement une variable locale. 
     $session = $this->request->session(); 
     if ($this->request->is('post')) { 

      $query = $this->Customer->find('all', [ 
       /*'CustLogin' => $this->request->data['login'], 
       'CustPassword' => $this->request->data['password'],*/ 
       'conditions' => [ 
        'Customer.CustLogin ' => $this->request->data['login'], 
        'Customer.CustPassword ' => $this->request->data['password'] 
       ] 
      ]); 
      $row = $query->first(); 
     //debug($row); 
      if(count($row) == 1){ 
       $customer = $row->toArray(); 
       $this->set('customer', $customer); 
       $session->write('customer_session', $customer); 
       //$this->redirect(array('action' => 'index')); 
       $this->setAction('dashboard'); 
      }else{ 
       $this->Flash->error('Votre username ou mot de passe est incorrect.'); 
      } 


     } 


    } 

    /** 
    *logout method to disconnect customer 
    * 
    */ 

    public function logout() 
    { 
     $this->request->session()->destroy(); 
     $this->redirect('/customer/login'); 
    } 

    public function dashboard() 
    { 
     $session = $this->request->session(); 
     if(isset($session) && !empty($session)){ 

      $customer = $session->read('customer_session'); 
      if(isset($customer) && !empty($customer)) 
      { 
       $this->set('customer', $customer); 
       //$this->set('_serialize', ['customer']); 

       //************on doit recuperer son credit 
       $this->loadModel('Credits'); 
       $query = $this->Credits->find('all', [ 
        'conditions' => [ 
         'Credits.AccID ' => $customer['CustIdCredit'] 
        ] 
       ]); 
       $row = $query->first(); 
       $this->set('credit', $row->toArray()); 

       //******************on recherche les sms inbound du jour 
       $yesterday = strtotime('yesterday midnight'); 
       $today = strtotime('today midnight'); //on recupère le jour 
       $tomorrow = strtotime('tomorrow midnight'); 
       $aujourdhui = str_replace(' ', '@', date('Y.m.d H:i:s', $today)); //. ' - Today for example purposes<br />'; 
       $demain = str_replace(' ', '@', date('Y.m.d H:i:s', $tomorrow)); 
       $hier = str_replace(' ', '@', date('Y.m.d H:i:s', $yesterday)); 
       //echo '/**********aujourdhui start $aujourdhui on and end on $demain ****/'; 
       //var_dump($aujourdhui);//******** date d aujourd'hui 
       //var_dump($demain);//********* date de demain 
       //echo '/**********this week start on $ceweekd and end on $ceweeke ****/'; 
       $this_week_start = strtotime("this week midnight"); 
       $next_week_start = strtotime("next week midnight"); 
       $ceweekd = str_replace(' ', '@', date('Y.m.d H:i:s', $this_week_start)); 
       $ceweeke = str_replace(' ', '@', date('Y.m.d H:i:s', $next_week_start));//******this week end on next week start 
       //var_dump($ceweekd); 
       //var_dump($ceweeke); 
       //echo '/**********last week start on $ceweekld and end on $ceweekle ****/'; 
       $last_week_start = strtotime("last week midnight"); 
       //$last_week_end = strtotime("last week, +6 days"); 
       $ceweekld = str_replace(' ', '@', date('Y.m.d H:i:s', $last_week_start)); 
       $ceweekle = str_replace(' ', '@', date('Y.m.d H:i:s', $this_week_start)); 
       //var_dump($ceweekld); 
       //var_dump($ceweekle); 
       //echo '/**********this month start on $cemonthd and end on $cemonthe ****/'; 
       $this_month_start = strtotime("first day of this month midnight"); 
       $next_month_start = strtotime("first day of next month midnight"); 
       $cemonthd = str_replace(' ', '@', date('Y.m.d H:i:s', $this_month_start)); 
       $cemonthe = str_replace(' ', '@', date('Y.m.d H:i:s', $next_month_start));//******this month end on next month start 
       //var_dump($cemonthd); 
       //var_dump($cemonthe); 
       //echo '/**********last month start on $cemonthld and end on $cemonthle ****/'; 
       $last_month_start = strtotime("first day of last month midnight"); 
       //$last_week_end = strtotime("last week, +6 days"); 
       $cemonthld = str_replace(' ', '@', date('Y.m.d H:i:s', $last_month_start)); 
       $cemonthle = str_replace(' ', '@', date('Y.m.d H:i:s', $this_month_start)); 
       //var_dump($cemonthld); 
       //var_dump($cemonthle); 



       //*****************on selectionne toutes les conncetions utilisateur 
       $this->loadModel('Connection'); 
       $query = $this->Connection->find('all', [ 
        'conditions' => [ 
         'Connection.CustId ' => $customer['CustId'] 
        ] 
       ]); 
       $row = $query->all(); 
       //$this->set('connection', $row->toArray()); //var_dump(count($row->toArray())); 

       //***********on boucle dessus pour avoir les inbound par msgAccountID and msgBody 
       $this->loadModel('Outbox'); 
       $credit_today = 0;$credit_week = 0;$credit_lweek = 0;$credit_month = 0; $credit_lmonth = 0; 
       if(count($row->toArray()) == 1) 
       { 
       $array1 = $row->toArray(); 
        $connection = $array1[0]->toArray(); 

         $query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]); 
         $query->where(['Outbox.MsgReceivedTime >=' => $aujourdhui,'Outbox.MsgReceivedTime <' => $demain]); 
         $count_jour = $query->count('*'); 
         $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
         $credit_jour = (int)$sum[0]->sum; 

         $query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]); 
         $query->where(['Outbox.MsgReceivedTime >=' => $ceweekd,'Outbox.MsgReceivedTime <' => $ceweeke]);       
         $count_week = $query->count('*'); 
         $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
         $credit_week = (int)$sum[0]->sum; 

         $query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]); 
         $query->where(['Outbox.MsgReceivedTime >=' => $ceweekld,'Outbox.MsgReceivedTime <' => $ceweekle]); 
         $count_lweek = $query->count('*'); 
         $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
         $credit_lweek = (int)$sum[0]->sum; 

         $query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]); 
         $query->where(['Outbox.MsgReceivedTime >=' => $cemonthd,'Outbox.MsgReceivedTime <' => $cemonthe]); 
         $count_month = $query->count('*'); 
         $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
         $credit_month = (int)$sum[0]->sum; 

         $query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]); 
         $query->where(['Outbox.MsgReceivedTime >=' => $cemonthld,'Outbox.MsgReceivedTime <' => $cemonthle]); 
         $count_lmonth = $query->count('*'); 
         $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
         $credit_lmonth = (int)$sum[0]->sum; 




        $this->set('inbound_jour', $count_jour);      
        $this->set('cr_inboud_jour', $credit_jour);     
        $this->set('inbound_week', $count_week);      
        $this->set('credit_inbound_week', $credit_week);      
        $this->set('inbound_lweek', $count_lweek);     
        $this->set('credit_inbound_lweek', $credit_lweek);     
        $this->set('inbound_month', $count_month);     
        $this->set('credit_inbound_month', $credit_month);     
        $this->set('inbound_lmonth', $count_lmonth);      
        $this->set('credit_inbound_lmonth', $credit_lmonth); 

       }else{ //************** le client a plusieurs connections 

       $count_jour = 0;$credit_jour = 0;$count_week = 0;$credit_week = 0;$count_lweek = 0;$credit_lweek = 0; 
       $count_month = 0;$credit_month = 0; $count_lmonth = 0;$credit_lmonth = 0; 
        foreach($row->toArray() as $value) 
        { 

         $connection = $value->toArray(); 

         $query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]); 
         $query->where(['Outbox.MsgReceivedTime >=' => $aujourdhui,'Outbox.MsgReceivedTime <' => $demain]); 
         $count_jour += $query->count('*'); 
         $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
         $credit_jour += (int)$sum[0]->sum; 

         $query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]); 
         $query->where(['Outbox.MsgReceivedTime >=' => $ceweekd,'Outbox.MsgReceivedTime <' => $ceweeke]);       
         $count_week += $query->count('*'); 
         $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
         $credit_week += (int)$sum[0]->sum; 

         $query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]); 
         $query->where(['Outbox.MsgReceivedTime >=' => $ceweekld,'Outbox.MsgReceivedTime <' => $ceweekle]); 
         $count_lweek += $query->count('*'); 
         $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
         $credit_lweek += (int)$sum[0]->sum; 

         $query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]); 
         $query->where(['Outbox.MsgReceivedTime >=' => $cemonthd,'Outbox.MsgReceivedTime <' => $cemonthe]); 
         $count_month += $query->count('*'); 
         $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
         $credit_month += (int)$sum[0]->sum; 

         $query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => $connection['ConAccountid'], 'Outbox.MsgBodyType ' => 0]); 
         $query->where(['Outbox.MsgReceivedTime >=' => $cemonthld,'Outbox.MsgReceivedTime <' => $cemonthle]); 
         $count_lmonth += $query->count('*'); 
         $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
         $credit_lmonth += (int)$sum[0]->sum;  


        } 

        $this->set('inbound_jour', $count_jour);      
        $this->set('cr_inboud_jour', $credit_jour);     
        $this->set('inbound_week', $count_week);      
        $this->set('credit_inbound_week', $credit_week);      
        $this->set('inbound_lweek', $count_lweek);     
        $this->set('credit_inbound_lweek', $credit_lweek);     
        $this->set('inbound_month', $count_month);     
        $this->set('credit_inbound_month', $credit_month);     
        $this->set('inbound_lmonth', $count_lmonth);      
        $this->set('credit_inbound_lmonth', $credit_lmonth); 
       } 


       //**************************** 
       //***********on boucle dessus pour avoir les outbound par msgAccountID and msgBody 
       $this->loadModel('Inbox'); 
       if(count($row->toArray()) == 1) 
       { 

        $array1 = $row->toArray(); 
        $connection = $array1[0]->toArray(); 

        $query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]); 
        $query->where(['Inbox.MsgReceivedTime >=' => $aujourdhui,'Inbox.MsgReceivedTime <' => $demain]); 
        $count_jour = $query->count('*'); 
        $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
        $credit_jour = (int)$sum[0]->sum; 

        $query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]); 
        $query->where(['Inbox.MsgReceivedTime >=' => $ceweekd,'Inbox.MsgReceivedTime <' => $ceweeke]);      
        $count_week = $query->count('*'); 
        $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
        $credit_week = (int)$sum[0]->sum; 

        $query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]); 
        $query->where(['Inbox.MsgReceivedTime >=' => $ceweekld,'Inbox.MsgReceivedTime <' => $ceweekle]); 
        $count_lweek = $query->count('*'); 
        $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
        $credit_lweek = (int)$sum[0]->sum; 

        $query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]); 
        $query->where(['Inbox.MsgReceivedTime >=' => $cemonthd,'Inbox.MsgReceivedTime <' => $cemonthe]); 
        $count_month = $query->count('*'); 
        $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
        $credit_month = (int)$sum[0]->sum; 

        $query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]); 
        $query->where(['Inbox.MsgReceivedTime >=' => $cemonthld,'Inbox.MsgReceivedTime <' => $cemonthle]); 
        $count_lmonth = $query->count('*'); 
        $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
        $credit_lmonth = (int)$sum[0]->sum; 




        $this->set('outbound_jour', $count_jour);     
        $this->set('cr_outboud_jour', $credit_jour);      
        $this->set('outbound_week', $count_week);     
        $this->set('credit_outbound_week', $credit_week);     
        $this->set('outbound_lweek', $count_lweek);     
        $this->set('credit_outbound_lweek', $credit_lweek);     
        $this->set('outbound_month', $count_month);     
        $this->set('credit_outbound_month', $credit_month);     
        $this->set('outbound_lmonth', $count_lmonth);     
        $this->set('credit_outbound_lmonth', $credit_lmonth); 


       }else{ 
       //var_dump($row->toArray()); 
       $count_jour = 0;$count_week = 0;$count_weekl = 0;$count_month = 0;$count_lmonth = 0; 
       $credit_jour = 0;$credit_week = 0;$credit_weekl = 0;$credit_month = 0;$credit_lmonth = 0; 
        foreach($row->toArray() as $value) 
        { 

         $connection = $value->toArray(); 
         $query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]); 
        $query->where(['Inbox.MsgReceivedTime >=' => $aujourdhui,'Inbox.MsgReceivedTime <' => $demain]); 
        $count_jour += $query->count('*'); 
        $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
        $credit_jour += (int)$sum[0]->sum; 

        $query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]); 
        $query->where(['Inbox.MsgReceivedTime >=' => $ceweekd,'Inbox.MsgReceivedTime <' => $ceweeke]);      
        $count_week += $query->count('*'); 
        $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
        $credit_week += (int)$sum[0]->sum; 

        $query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]); 
        $query->where(['Inbox.MsgReceivedTime >=' => $ceweekld,'Inbox.MsgReceivedTime <' => $ceweekle]); 
        $count_lweek += $query->count('*'); 
        $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
        $credit_lweek += (int)$sum[0]->sum; 

        $query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]); 
        $query->where(['Inbox.MsgReceivedTime >=' => $cemonthd,'Inbox.MsgReceivedTime <' => $cemonthe]); 
        $count_month += $query->count('*'); 
        $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
        $credit_month += (int)$sum[0]->sum; 

        $query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => $connection['ConAccountid'], 'Inbox.MsgBodyType ' => 0]); 
        $query->where(['Inbox.MsgReceivedTime >=' => $cemonthld,'Inbox.MsgReceivedTime <' => $cemonthle]); 
        $count_lmonth += $query->count('*'); 
        $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
        $credit_lmonth += (int)$sum[0]->sum;  


        } 

        $this->set('outbound_jour', $count_jour);     
        $this->set('cr_outboud_jour', $credit_jour);      
        $this->set('outbound_week', $count_week);     
        $this->set('credit_outbound_week', $credit_week);     
        $this->set('outbound_lweek', $count_lweek);     
        $this->set('credit_outbound_lweek', $credit_lweek);     
        $this->set('outbound_month', $count_month);     
        $this->set('credit_outbound_month', $credit_month);     
        $this->set('outbound_lmonth', $count_lmonth);     
        $this->set('credit_outbound_lmonth', $credit_lmonth); 
       } 

      }else{ 
       $this->Flash->error(__('Votre session a expiré, veuillez vous reconnecter!')); 
       $this->setAction('login'); 
      } 
     }else{ 
      $this->Flash->error(__('Votre session a expiré, veuillez vous reconnecter!')); 
      $this->setAction('login'); 
     } 
    } 

    public function oprSmsTraffic(){ 
     $this->loadModel('Inbox'); 
     $this->loadModel('Outbox'); 
     $yesterday = strtotime('yesterday midnight'); 
     $today = strtotime('today midnight'); //on recupère le jour 
     $tomorrow = strtotime('tomorrow midnight'); 
     $aujourdhui = str_replace(' ', '@', date('Y.m.d H:i:s', $today)); //. ' - Today for example purposes<br />'; 
     $demain = str_replace(' ', '@', date('Y.m.d H:i:s', $tomorrow)); 
     $hier = str_replace(' ', '@', date('Y.m.d H:i:s', $yesterday)); 

     $this_week_start = strtotime("this week midnight"); 
     $next_week_start = strtotime("next week midnight"); 
     $ceweekd = str_replace(' ', '@', date('Y.m.d H:i:s', $this_week_start)); 
     $ceweeke = str_replace(' ', '@', date('Y.m.d H:i:s', $next_week_start));//******this week end on next week start 

     $last_week_start = strtotime("last week midnight"); 

     $ceweekld = str_replace(' ', '@', date('Y.m.d H:i:s', $last_week_start)); 
     $ceweekle = str_replace(' ', '@', date('Y.m.d H:i:s', $this_week_start)); 

     $this_month_start = strtotime("first day of this month midnight"); 
     $next_month_start = strtotime("first day of next month midnight"); 
     $cemonthd = str_replace(' ', '@', date('Y.m.d H:i:s', $this_month_start)); 
     $cemonthe = str_replace(' ', '@', date('Y.m.d H:i:s', $next_month_start));//******this month end on next month start 

     $last_month_start = strtotime("first day of last month midnight"); 

     $cemonthld = str_replace(' ', '@', date('Y.m.d H:i:s', $last_month_start)); 
     $cemonthle = str_replace(' ', '@', date('Y.m.d H:i:s', $this_month_start));//*********last month end on this month start 

     $this->set('customer', $this->paginate($this->Customer)); 
     $this->set('_serialize', ['customer']); 


     if ($this->request->is('post')) { 

     $data = $this->request->data; 


      if((int)$data['idCheckPHandler_Flt_4'] == 0){ 
       $this->set('operator', 0); 
      }else{ 

       $this->loadModel('Connection'); 
       $query = $this->Connection->find('all', [ 
        'conditions' => [ 
         'Connection.CustId ' => (int)$data['operator'], 
        ] 
       ]); 
       foreach($query as $value){ 
        $operator = $value; 
       } 
       $operator = $operator->toArray(); 
       $this->set('operator', $operator); 

       $query = $this->Inbox->find('first')->where(['Inbox.MsgAccountID ' => $operator['ConAccountid'], 'Inbox.MsgBodyType ' => 0]); 
       $query->where(['Inbox.MsgReceivedTime >=' => $cemonthld,'Inbox.MsgReceivedTime <' => $cemonthle]); 
       $count_lmonth += $query->count('*'); 
       debug($count_lmonth); 

      } 
     }else{ 
      $this->set('operator', 0); $count_month = 0;$credit_month = 0; 
      //*******on recherche pour MTN 
      $query = $this->Inbox->find(
       'all', ['fields' => ['MsgTo', 'MsgBodyType', 'MsgAccountID', 'MsgPartCount', 'MsgReceivedTime'],] 
      )->where(['Inbox.MsgAccountID ' => 22, 'Inbox.MsgBodyType ' => 0]); 
      $query->where(['Inbox.MsgReceivedTime >=' => $cemonthd,'Inbox.MsgReceivedTime <' => $cemonthe]); 
      $count_month = $query->count('*'); 
      $this->set('count_Imonth',(int)$count_month); 
      $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
      $credit_month = (int)$sum[0]->sum; 
      $this->set('credit_Imonth',(int)$credit_month); 

      $count_month = 0; 
      for($i = 0; $i < 10; $i++){ 
       $query = $this->Inbox->find(
        'all', ['fields' => ['MsgTo', 'MsgBodyType', 'MsgAccountID', 'MsgPartCount', 'MsgReceivedTime'],] 
       )->where(['Inbox.MsgAccountID ' => 22, 'Inbox.MsgBodyType ' => 0]); 
       $query->where(['Inbox.MsgReceivedTime >=' => $cemonthd,'Inbox.MsgReceivedTime <' => $cemonthe]); 
       $query->where(['Inbox.MsgTo = 800'.$i]); 
       $count_month = $query->count('*'); 
       $this->set('count_Imonth_800'.$i,(int)$count_month); 
      } 
      $count_month = 0; 
      //for($i = 0; $i < 10; $i++){ 
       $query = $this->Inbox->find(
        'all', ['fields' => ['MsgTo', 'MsgBodyType', 'MsgAccountID', 'MsgPartCount', 'MsgReceivedTime'],] 
       )->where(['Inbox.MsgAccountID ' => 22, 'Inbox.MsgBodyType ' => 0]); 
       $query->where(['Inbox.MsgReceivedTime >=' => $cemonthd,'Inbox.MsgReceivedTime <' => $cemonthe]); 
       $query->where(['Inbox.MsgTo NOT BETWEEN 8000 AND 8009']); 
       $count_month = $query->count('*'); 
       $this->set('count_Imonth_autres',(int)$count_month); 
      //} 

      $query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => 22, 'Outbox.MsgBodyType ' => 0]); 
      $query->where(['Outbox.MsgReceivedTime >=' => $cemonthd,'Outbox.MsgReceivedTime <' => $cemonthe]); 
      $count_month = $query->count('*'); 
      $this->set('count_Omonth',(int)$count_month); 
      $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
      $credit_month = (int)$sum[0]->sum; 
      $this->set('credit_Omonth',(int)$credit_month); 

      $count_month = 0; 
      for($i = 0; $i < 10; $i++){ 
       $query = $this->Outbox->find(
        'all', ['fields' => ['MsgTo', 'MsgBodyType', 'MsgAccountID', 'MsgPartCount', 'MsgReceivedTime'],] 
       )->where(['Outbox.MsgAccountID ' => 22, 'Outbox.MsgBodyType ' => 0]); 
       $query->where(['Outbox.MsgReceivedTime >=' => $cemonthd,'Outbox.MsgReceivedTime <' => $cemonthe]); 
       $query->where(['Outbox.MsgTo = 800'.$i]); 
       $count_month = $query->count('*'); 
       $this->set('count_Omonth_800'.$i,(int)$count_month); 
      } 
      $count_month = 0; 
      //for($i = 0; $i < 10; $i++){ 
       $query = $this->Outbox->find(
        'all', ['fields' => ['MsgTo', 'MsgBodyType', 'MsgAccountID', 'MsgPartCount', 'MsgReceivedTime'],] 
       )->where(['Outbox.MsgAccountID ' => 22, 'Outbox.MsgBodyType ' => 0]); 
       $query->where(['Outbox.MsgReceivedTime >=' => $cemonthd,'Outbox.MsgReceivedTime <' => $cemonthe]); 
       $query->where(['Outbox.MsgTo NOT BETWEEN 8000 AND 8009']); 
       $count_month = $query->count('*'); 
       $this->set('count_Omonth_autres',(int)$count_month); 
      //} 
      $count_month = 0; 
      //*******on recherche pour ORANGE 
      $query = $this->Inbox->find()->where(['Inbox.MsgAccountID ' => 5, 'Inbox.MsgBodyType ' => 0]); 
      $query->where(['Inbox.MsgReceivedTime >=' => $cemonthd,'Inbox.MsgReceivedTime <' => $cemonthe]); 
      $count_month = $query->count('*'); 
      $this->set('count_Imonth1',(int)$count_month); 
      $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
      $credit_month = (int)$sum[0]->sum; 
      $this->set('credit_Imonth1',(int)$credit_month); 

      $count_month = 0; 
      for($i = 0; $i < 10; $i++){ 
       $query = $this->Inbox->find(
        'all', ['fields' => ['MsgTo', 'MsgBodyType', 'MsgAccountID', 'MsgPartCount', 'MsgReceivedTime'],] 
       )->where(['Inbox.MsgAccountID ' => 5, 'Inbox.MsgBodyType ' => 0]); 
       $query->where(['Inbox.MsgReceivedTime >=' => $cemonthd,'Inbox.MsgReceivedTime <' => $cemonthe]); 
       $query->where(['Inbox.MsgTo = 800'.$i]); 
       $count_month = $query->count('*'); 
       $this->set('count_Imonth1_800'.$i,(int)$count_month); 
      } 

      $count_month = 0; 
      //for($i = 0; $i < 10; $i++){ 
       $query = $this->Inbox->find(
        'all', ['fields' => ['MsgTo', 'MsgBodyType', 'MsgAccountID', 'MsgPartCount', 'MsgReceivedTime'],] 
       )->where(['Inbox.MsgAccountID ' => 5, 'Inbox.MsgBodyType ' => 0]); 
       $query->where(['Inbox.MsgReceivedTime >=' => $cemonthd,'Inbox.MsgReceivedTime <' => $cemonthe]); 
       $query->where(['Inbox.MsgTo NOT BETWEEN 8000 AND 8009']); 
       $count_month = $query->count('*'); 
       $this->set('count_Imonth1_autres',(int)$count_month); 
      //} 
      $count_month = 0; 
      $query = $this->Outbox->find()->where(['Outbox.MsgAccountID ' => 5, 'Outbox.MsgBodyType ' => 0]); 
      $query->where(['Outbox.MsgReceivedTime >=' => $cemonthd,'Outbox.MsgReceivedTime <' => $cemonthe]); 
      $count_month = $query->count('*'); 
      $this->set('count_Omonth1',(int)$count_month); 
      $sum = $query->select(['sum' => $query->func()->sum('MsgPartCount')])->toArray(); 
      $credit_month = (int)$sum[0]->sum; 
      $this->set('credit_Omonth1',(int)$credit_month); 
      $count_month = 0; 
      for($i = 0; $i < 10; $i++){ 
       $query = $this->Outbox->find(
        'all', ['fields' => ['MsgTo', 'MsgBodyType', 'MsgAccountID', 'MsgPartCount', 'MsgReceivedTime'],] 
       )->where(['Outbox.MsgAccountID ' => 5, 'Outbox.MsgBodyType ' => 0]); 
       $query->where(['Outbox.MsgReceivedTime >=' => $cemonthd,'Outbox.MsgReceivedTime <' => $cemonthe]); 
       $query->where(['Outbox.MsgTo = 800'.$i]); 
       $count_month = $query->count('*'); 
       $this->set('count_Omonth1_800'.$i,(int)$count_month); 
      } 
      $count_month = 0; 
      //for($i = 0; $i < 10; $i++){ 
       $query = $this->Outbox->find(
        'all', ['fields' => ['MsgTo', 'MsgBodyType', 'MsgAccountID', 'MsgPartCount', 'MsgReceivedTime'],] 
       )->where(['Outbox.MsgAccountID ' => 5, 'Outbox.MsgBodyType ' => 0]); 
       $query->where(['Outbox.MsgReceivedTime >=' => $cemonthd,'Outbox.MsgReceivedTime <' => $cemonthe]); 
       $query->where(['Outbox.MsgTo NOT BETWEEN 8000 AND 8009']); 
       $count_month = $query->count('*'); 
       $this->set('count_Omonth1_autres',(int)$count_month); 
      //} 

     } 
    } 

} 

我的截圖: enter image description here

+1

給我,我不知道任何形式的'cakephp',它看起來像你在'dashboard'方法中執行數百個查詢 – RamRaider

回答

0

正如@RamRaider已經說了,這是最有可能是由於你試圖執行查詢的絕對數量。您可以通過查看CakePHP Debug Tool的SQL選項卡來驗證這一點。

您會看到相當多的查詢。您還可以查看哪些查詢需要很長時間才能執行。

其它可能的解決方案是:

最後一個Aggregated data需要另一個腳本實際執行所有的計算,並選擇你現在正在做的頁面請求。

This post提供了有關數據倉庫的更多信息。