chengkun
2025-04-27 a0402d122fee696e2b7684ef7edfc504ade12640
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
 
class statis_controller extends adminCommon{
 
    //图表类型 bar 柱形图,line折线图,pie饼形图
    private $chartType = 'line';
 
    //收支总计页面
    public function index_action(){
 
        $StatisM                                =            $this->MODEL('statis');
 
        $CompanyorderM                            =            $this->MODEL('companyorder');
 
        $PackM                                    =            $this->MODEL('pack');
 
        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($time_end);
 
        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                                 =             "收支统计 - 全部数据";    
        }
 
        //收支总计 查询:in毛收入,out支出/提现,net_income净收入
        
        $names                                     =             array();//横坐标名称(时间日期)
        
        $values                                 =             array();//纵坐标的值
        
        $dataGroupNames                         =             array();//柱行代表数据的名称
            
        //毛收入
        $comwhere['order_state']                =            2;
 
        if($isAllTime != 1){
 
            $comwhere['order_time'][]             =           array('>=', $timeBegin);
            
            $comwhere['order_time'][]             =           array('<=', $timeEnd,'AND');
 
        }
 
        $comwhere['groupby']                    =            'date';
 
        $comwhere['orderby']                    =            array('date,asc');
 
        $comfield                                 =            "sum(order_price) as `num`, from_unixtime(order_time,'%Y-%m-%d') as `date`";
        
        $row                                    =            $CompanyorderM->getList($comwhere,array('field'=>$comfield));
        
        $totalIn                                 =             0;//收入总计
        if(count($row) < 1){
 
            $in                                 =             array('names' => array(), 'values' => array());
        
        }else{
 
            $inNames                             =             array();
 
            $inValues                             =             array();
            foreach($row as $r){
 
                $inNames []                     =             $r['date'];
 
                $inValues []                     =             $r['num'];
 
                $totalIn                         +=             $r['num'];
            }
 
            $in                                  =             array('names' => $inNames, 'values' => $inValues);
        
        }
 
        //支出/提现
        $memwhere['order_state']        =            1;
    
        if($isAllTime != 1){
 
            $memwhere['time'][]         =           array('>=', $timeBegin);
            
            $memwhere['time'][]         =           array('<=', $timeEnd,'AND');
 
        }
 
        $memwhere['groupby']            =            'date';
 
        $memwhere['orderby']            =            'date';
 
 
        $memfield                        =             "sum(order_price) as num, from_unixtime(`time`,'%Y-%m-%d') as `date`";
        
        $mrow                            =            $PackM->getList($memwhere,array('field'=>$memfield));
    
        $totalOut                         =             0;
 
        if(count($mrow) < 1){
            $out                         =             array('names' => array(), 'values' => array());
        }
        else{
 
            $outNames                     =             array();
 
            $outValues                     =            array();
 
            foreach($mrow as $r){
 
                $outNames []             =            $r['date'];
 
                $outValues []             =            $r['num'];
 
                $totalOut                 +=            $r['num'];
 
            }
 
            $out                         =           array('names' => $outNames, 'values' => $outValues);
        
        }
        
        //净收入 综合names、values
        $names                             =          array_merge($in['names'], $out['names']);
        
        $names                             =          array_unique($names);
        
        usort($names,'t_sort');
 
        $inValues                         =           array();
 
        $outValues                         =           array();
        
        $inK                             =           0;
 
        $outK                             =           0;
 
        foreach($names as $n){
            if(in_array($n, $in['names'])){
 
                $inValues []             =         $in['values'][$inK];
 
                $inK ++;
 
            }else{
 
                $inValues []             =         0;
            
            }
 
            if(in_array($n, $out['names'])){
 
                $outValues []             =         $out['values'][$outK];
 
                $outK ++;
            
            }else{
                $outValues []             =         0;
            }
 
            $netIncomeValues []         =         end($inValues) - end($outValues);
        }
 
        $in['values']                     =         $inValues;
 
        $out['values']                     =         $outValues;
        
        $dataGroupNames []                 =         '毛收入';
        
        $dataGroupNames []                 =         '支出/提现';
        
        $dataGroupNames []                 =         '净收入';
 
        $values[]                         =         array('name' => '毛收入','type' => $this->chartType,'data' => $in['values']);
        
        $values[]                         =         array('name' => '支出/提现','type' => $this->chartType,'data' => $out['values']);
 
        $values[]                         =       array('name' => '净收入','type' => $this->chartType,'data' => $netIncomeValues);
 
        $data                             =         array('title' => $title,'names' => $names, 'values' => $values, 'dataGroupNames' => $dataGroupNames);
        
        $this->yunset($data);
 
        $this->yunset(array('totalIn'=> $totalIn, 'totalOut' => $totalOut, 'totalNetIncome' => $totalIn - $totalOut));
 
        $this->yuntpl(array('admin/statis'));
        
    }
 
}
?>