chengkun
2025-05-26 8f3df543230cd4403368b39b9bbe5726d11a0284
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
 
class statis_city_controller extends siteadmin_controller{
 
    //图表类型 bar 柱形图,line折线图,pie饼形图
    private $chartType = 'pie';
 
    //消费最多行业统计
    public function index_action(){
 
        $CompanyorderM    =    $this->MODEL('companyorder');
        $CompanyM        =    $this->MODEL('company');
        $StatisM        =    $this->MODEL('statis');
 
        $this->yunset('user', '地区');
 
        if(isset($_GET['radio_time'])){
 
            $this->yunset('radio_time', $_GET['radio_time']);
        }
        //查询报表数据
        $time_begin    =    isset($_GET['time_begin']) ? $_GET['time_begin'] : date('Y-m-d 00:00:00', strtotime('-30 day'));
        
        $time_end    =    isset($_GET['time_end']) ? $_GET['time_end'] :date('Y-m-d H:i:s');
        
        $this->yunset('defaultTimeBegin', $time_begin);
        $this->yunset('defaultTimeEnd', $time_end);
 
        $isAllTime    =    isset($_GET['isAllTime']) ? $_GET['isAllTime'] : 0; 
 
        //查询30条内的信息,展示到页面第一屏
        if($isAllTime != 1){
 
            $timeBegin    =    strtotime($time_begin);
        }else{
            $timeBegin    =    strtotime(date('Y-m-d 00:00:00', strtotime('-30 year')));
        }    
        $timeEnd    =    strtotime("now");
 
        list($in, $out, $net_income)    =    $StatisM->getStatisTotal($timeBegin, $timeEnd );
 
        $data [] = array('time' => '近30', 'in' => $in, 'out' => $out, 'net_income' => $net_income);
        $this->yunset('data', $data);
 
        //如果不是查询全部数据,组织查询的开始、结束时间
        if($isAllTime != 1){
 
            $timeBegin    =    strtotime($time_begin);
            $timeEnd    =    strtotime($time_end);
            $dateBegin    =    date('Y-m-d', $timeBegin);
            $dateEnd    =    date('Y-m-d', $timeEnd);
                
            $title    =    "消费最多地区统计 - {$dateBegin}~{$dateEnd}";
        }else{
            $title    =    "消费最多地区统计 - 全部数据";
        }
        $names    =    array();//扇形每块的名称(收入渠道)
        $values    =    array();//扇形每块的值
        $topNum    =    10;//统计消费最多10个地区
 
        $orwhere['order_state']    =    2;
 
        if($isAllTime != 1){
 
            $orwhere['order_time'][]    =    array('>=', $timeBegin);
            $orwhere['order_time'][]    =    array('<=', $timeEnd,'AND');
        }
        $limit                =    $topNum * 10;
        $orwhere['groupby']    =    'uid';
        $orwhere['orderby']    =    array('num,asc');
        $orwhere['limit']    =    $limit;
        $field    =    'sum(order_price) as `num`, `uid`';
        
        $row    =    $CompanyorderM->getList($orwhere,array('field'=>$field));
 
        $uidArr        =    array();
        $uidValue    =    array();
 
        foreach($row as $r){
 
            $uidArr []                =    $r['uid'];
            $uidValue[$r['uid']]    =    $r['num'];
        }
        $uidStr                =    implode(',', $uidArr);
        $comwhere['uid']    =    array('in',pylode(',',$uidArr));
        $comwhere['cityid']    =    array('>',0);
        
        $data    =    $CompanyM->getChCompanyList($comwhere,array('field'=>'`uid`,`cityid`,`provinceid`'));
 
        $total    =    0;
 
        foreach($data as $r){
 
            if(array_key_exists($r['cityid'], $values) ){
 
                $values [$r['cityid']]['value']    +=    $uidValue[$r['uid']];
            }else{
                $values [$r['cityid']]['value']    =    $uidValue[$r['uid']];                
                $values [$r['cityid']]['pid']    =    $r['provinceid'];                
                $values [$r['cityid']]['cid']    =    $r['cityid'];            
            }
        }
        usort($values,'my_sort');
 
        $city    =    $this->MODEL('cache')->GetCache(array('city'));
 
        $arr    =    array();
        $i        =    0;
        foreach($values as $r){
 
            $names []        =    $city['city_name'][$r['pid']] . '-' . $city['city_name'][$r['cid']];
            $rr['value']    =    $r['value'];
            $rr['name']        =    $city['city_name'][$r['pid']] . '-' . $city['city_name'][$r['cid']];
            $arr []            =    $rr;
            $total            +=    $r['value'];
            $i ++;
            if($i == $topNum){
                break;
            }
        }
        $values    =    $arr;
 
        $this->yunset('total', $total);
        
        $this->yunset( array('title' => $title,'names' => $names, 'values' => $values ) );
        
        if(isset($_GET['c']) && $_GET['c']!=$_GET['m']){
            $url="index.php?m={$_GET['m']}&c={$_GET['c']}";
        }else{
            $url="index.php?m={$_GET['m']}";
        }
        $this->yunset('gourl',$url);
 
        $this->siteadmin_tpl(array('statis_user'));
    }
}
?>