Ignore:
Timestamp:
Mar 24, 2015 2:15:02 PM (10 years ago)
Author:
namnd
Message:
 
Location:
pro-violet-viettel/sourcecode/application/modules/admin/models
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pro-violet-viettel/sourcecode/application/modules/admin/models/paidlog_model.php

    r777 r818  
    1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
     1<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    22
    33class Paidlog_model extends MY_Model
     
    3737                        if ($data['paid_type'] ==0){
    3838                                $sql.=" WHERE paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
    39                                 //write_file('./log/sql.log', date("m/d/Y H:i:s")." ".$sql."\n", FOPEN_WRITE_CREATE);
    4039                        }else{
    4140                                $sql.=" AND paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
     
    4544
    4645        $order = "";
    47         if ($data['sorting_order'] != "sorting") {
    48             if ($data['sorting_field'] != "money") {
    49                 $sort = "DESC";
    50                 if ($data['sorting_order'] == "sorting_asc")
    51                     $sort = "ASC";
    52                 $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
    53             }
    54         }
    55         $sql=$sql . " " . $order . " LIMIT " . $data['start'] . ", " . $data['perpage'] . " ";
     46                if ($data['sorting_order']){
     47                        if ($data['sorting_order'] != "sorting") {
     48                                if ($data['sorting_field'] != "money") {
     49                                        $sort = "DESC";
     50                                        if ($data['sorting_order'] == "sorting_asc")
     51                                                $sort = "ASC";
     52                                        $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
     53                                }
     54                        }
     55                }
     56                if ($data['start']){
     57                        $sql=$sql . " " . $order . " LIMIT " . $data['start'] . ", " . $data['perpage'] . " ";
     58                }
    5659        //return $this->db->query($sql)->result_array();
    5760                $re = $this->db->query($sql)->result_array();
  • pro-violet-viettel/sourcecode/application/modules/admin/models/reportmodel.php

    r765 r818  
    4545               
    4646                // Tinh thue bao theo tinh theo nam
    47                 $sql = "SELECT *,count(us_id) as total FROM tbluser WHERE tbluser.created_time >= '" . $input ['year'] . "-01-01' AND tbluser.created_time <= '" . ($input ['year'] + 1) . "-01-01' GROUP BY tbluser.province";
    48                 $query = $this->db->query ( $sql );
     47                $sql = "SELECT *,count(us_id) as total FROM tbluser WHERE tbluser.created_time >= '" . $input ['year'] . "-01-01 00:00:00' AND tbluser.created_time <= '" . ($input ['year'] + 1) . "-01-01 23:59:59' GROUP BY tbluser.province";
     48                $query = $this->db->query ( $sql );
     49                write_file('./log/test.log', date('d-m-Y H:i:s').": ".$sql."\n", FOPEN_WRITE_CREATE);
    4950                $tbns = $query->result_array ();
    5051               
    5152                // tinh thue bao theo thang
    52                 $sql = "SELECT *,count(us_id) as total FROM tbluser WHERE $from AND  $to GROUP BY tbluser.province";
     53                //$sql = "SELECT *,count(us_id) as total FROM tbluser WHERE $from AND  $to GROUP BY tbluser.province";
     54                $sql = "SELECT *,count(us_id) as total FROM tbluser WHERE created_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . '01 00:00:00' . "' AND created_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . " 23:59:59' GROUP BY tbluser.province";
    5355                $query = $this->db->query ( $sql );
    5456                $tbts = $query->result_array ();
     
    5658                // tinh thue bao theo ngay
    5759                $sql = "SELECT *,count(us_id) as total FROM tbluser WHERE tbluser.created_time >='" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . " 00:00:00' AND tbluser.created_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . " 23:59:59'  GROUP BY tbluser.province";
    58                
    5960                $query = $this->db->query ( $sql );
    6061                $tbng = $query->result_array ();
    61                
    6262                $dem = 1;
     63               
     64                $totalTbng = 0;
     65                $totalTbth = 0;
     66                $totalTbn = 0;
     67                $totalDtng = 0;
     68                $totalDtth = 0;
     69                $totalDtn = 0;
    6370               
    6471                foreach ( $provinces as $index2 => $province ) {
     
    104111                                }
    105112                        }
     113                       
     114                        $totalTbng = $totalTbng + $provinces [$index2] ['tbng'];
     115                        $totalTbth = $totalTbth + $provinces [$index2] ['tbt'];
     116                        $totalTbn = $totalTbn + $provinces [$index2] ['tbn'];
     117                       
     118                        $totalDtng = $totalDtng + $provinces [$index2] ['dtng'];
     119                        $totalDtth = $totalDtth + $provinces [$index2] ['dtt'];
     120                        $totalDtn = $totalDtn + $provinces [$index2] ['dtn'];
     121                       
    106122                        $dem ++;
    107123                }
    108                
    109                 return $provinces;
     124
     125                $data['provinces'] = $provinces;
     126               
     127                $data['totalTbng'] = $totalTbng;
     128                $data['totalTbth'] = $totalTbth;
     129                $data['totalTbn'] = $totalTbn;
     130               
     131                $data['totalDtng'] = $totalDtng;
     132                $data['totalDtth'] = $totalDtth;
     133                $data['totalDtn'] = $totalDtn;
     134               
     135                //return $provinces;
     136                return $data;
    110137        }
    111138       
     
    118145                $provinces = lang ( '_PROVINCES_' );
    119146                // tinh thue bao theo thang
    120                 $sql = "SELECT * FROM tbluser LEFT JOIN tblservicepackage ON tbluser.p_id=tblservicepackage.p_id  WHERE tbluser.created_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . $input ['date'] . "' AND tbluser.created_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . "' AND tblservicepackage.p_period > 0 ";
     147                //$sql = "SELECT * FROM tbluser LEFT JOIN tblservicepackage ON tbluser.p_id=tblservicepackage.p_id LEFT JOIN tblregisterpackagelog ON tbluser.cellphone = tblregisterpackagelog.username WHERE tbluser.updated_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . $input ['date'] . "' AND tbluser.updated_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . "' AND tblregisterpackagelog.created_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . $input ['date'] . "' AND tblregisterpackagelog.created_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . "' AND tblservicepackage.p_period > 0 ";
     148                $sql = "SELECT * FROM tbluser LEFT JOIN tblregisterpackagelog ON tbluser.cellphone = tblregisterpackagelog.username WHERE tbluser.updated_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . $input ['date'] . "' AND tbluser.updated_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . "' AND tblregisterpackagelog.created_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . $input ['date'] . "' AND tblregisterpackagelog.created_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . "'";
    121149                $query = $this->db->query ( $sql );
    122150                $users = $query->result_array ();
     
    128156                        $packages [$index] ['users'] = array ();
    129157                        foreach ( $users as $user ) {
    130                                 if ($user ['p_id'] == $package ['p_id']) {
     158                                if ($user ['p_code'] == $package ['p_code']) {
    131159                                        $packages [$index] ['users'] [] = $user;
    132160                                }
    133161                        }
    134162                }
    135                
    136163                foreach ( $provinces as $index => $province ) {
    137164                        $provinces [$index] = array (
     
    139166                        );
    140167                }
     168               
    141169                $dem = 1;
     170               
    142171                foreach ( $provinces as $index => $province ) {
    143172                        $provinces [$index] ['stt'] = $dem;
     
    154183                                                $provinces [$index] ['total'] = $totaluser;
    155184                                                $provinces [$index] ['packages'] [$package ['p_name']] ['total'] = $total;
     185                                                $provinces [$index] ['packages'] [$package ['p_name']] ['users'] [] = $user;
    156186                                               
    157                                                 $provinces [$index] ['packages'] [$package ['p_name']] ['users'] [] = $user;
    158187                                        }
    159188                                }
     
    161190                        $dem ++;
    162191                }
     192               
     193                $totalByVIP = array();
     194               
     195                foreach ($packages as $index => $package){
     196                        $totalByVIP[$package ['p_name']] = 0;
     197                        foreach ( $provinces as $index=>$province){
     198                                foreach ($province['packages'] as $index2 => $p){
     199                                        if ($index2 == $package['p_name'])
     200                                                $totalByVIP[$package ['p_name']] = $totalByVIP[$package ['p_name']] + $p['total'];
     201                                }
     202                        }
     203                }
     204               
     205                $totalVip = 0;
     206               
     207                foreach ($totalByVIP as $vipName=>$total){
     208                        $totalVip = $totalVip + $total;
     209                }
     210               
     211                $totalByVIP['total'] = $totalVip;
     212               
    163213                foreach ( $provinces as $index => $province ) {
    164214                        foreach ( $packages as $index2 => $package ) {
     
    172222                $data ['packages'] = $packages;
    173223                $data ['provinces'] = $provinces;
     224                $data['totalVip'] = $totalByVIP;
    174225                return $data;
    175226        }
  • pro-violet-viettel/sourcecode/application/modules/admin/models/user_model.php

    r769 r818  
    6969                                                        $sql.=" WHERE province = '".$data['province_code']."' AND created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
    7070                                                }else{
    71                                                         $sql.=" AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
     71                                                        $sql.=" WHERE (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
    7272                                                }
    7373                                        }else{
     
    101101                        }
    102102                }
     103                write_file('./log/test.log', date("d-m-Y: H:i:s"). ": ".$sql." ".$order." LIMIT ".$data['start'].", ".$data['perpage'] , FOPEN_WRITE_CREATE);
    103104                return $this->db->query($sql." ".$order." LIMIT ".$data['start'].", ".$data['perpage']." ")->result_array();
    104105        }
Note: See TracChangeset for help on using the changeset viewer.