AdminStats.php
8.88 KB
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<? include $_SERVER["DOCUMENT_ROOT"] . "/common/classes/AdminBase.php" ;?>
<?
/*
* Admin process
* add by dev.lee
* */
if(!class_exists("AdminStats")){
class AdminStats extends AdminBase {
function __construct($req)
{
parent::__construct($req);
}
/**
* 일별 통계실 필요한 월 일 데이터
* @param unknown $year
* @param unknown $month
*/
function getMonthDayListData($year, $month)
{
$sql = "
SELECT *
FROM tbl_stats_date SD
WHERE SD.year = '{$year}' AND SD.month = '{$month}'
ORDER BY SD.date ASC
";
$result = $this->getArray($sql);
return $result;
}
/**
* 마이포인트 통계
*/
function getListOfPointStatsForUser()
{
$year = $this->req["year"] == "" ? date("Y", time()) : $this->req["year"];
$month = $this->req["month"] == "" ? date("n", time()) : $this->req["month"];
$sql = "
SELECT
SD.date
, IFNULL(SUM(CASE WHEN PT.pay_type = '{$this->PAY_TYPE_ADMIN}' AND PT.trans_type = 'I' THEN PT.amt ELSE 0 END), 0) AS input_point
, IFNULL(SUM(CASE WHEN PT.pay_type = '{$this->PAY_TYPE_USE}' AND PT.trans_type = 'O' THEN PT.amt ELSE 0 END), 0) AS output_point
FROM tbl_stats_date SD
LEFT JOIN tbl_point_trans PT ON(SD.date = PT.reg_date AND PT.pay_type != '{$this->PAY_TYPE_RETRIEVE}')
WHERE SD.year = '{$year}' AND SD.month = '{$month}'
GROUP BY SD.date
ORDER BY SD.date ASC
";
$result = $this->getArray($sql);
return $result;
}
/**
* 통계 정보 조회
* @return unknown[][]|mixed[][]
*/
function getGroupPointStatsData()
{
$year = $this->req["year"] == "" ? date("Y", time()) : $this->req["year"];
$pointArr = Array();
$where = " WHERE G.status = 'Y' ";
$subWhere = " WHERE PT.pay_type != '{$this->PAY_TYPE_RETRIEVE}' AND PT.group_fk > 0 AND YEAR(PT.reg_date) = '{$year}' ";
if($this->admUser["admin_type"] == "2")
{
$where .= " AND G.no = '{$this->admUser["target_fk"]}' ";
$subWhere .= " AND PT.group_fk = '{$this->admUser["target_fk"]}'";
}
$sql = "
SELECT
P.month, P.input_point, P.output_point, G.name AS group_name, G.no AS group_fk
, IFNULL((SELECT A.admin_name FROM tbl_admin A WHERE A.target_fk = G.no AND A.admin_type = '2' AND A.is_apply = 1 LIMIT 1), '-') AS manager_name
FROM tbl_user_group G
LEFT JOIN (
SELECT
PT.group_fk
, MONTH(PT.reg_date) AS `month`
, IFNULL(SUM(CASE WHEN PT.pay_type = '{$this->PAY_TYPE_ADMIN}' AND PT.trans_type = 'I' THEN PT.amt ELSE 0 END), 0) AS input_point
, IFNULL(SUM(CASE WHEN PT.pay_type = '{$this->PAY_TYPE_USE}' AND PT.trans_type = 'O' THEN PT.amt ELSE 0 END), 0) AS output_point
FROM tbl_point_trans PT
{$subWhere}
GROUP BY PT.group_fk, `month`
ORDER BY PT.group_fk ASC, `month` ASC
) P ON(P.group_fk = G.no)
{$where}
";
$result = $this->getArray($sql);
$monthIndex = 0;
$tmp_group_fk = "0";
$groupData = Array();
for($i=0; $i<sizeof($result); $i++)
{
if($result[$i]["group_fk"] != $tmp_group_fk)
{
if($i > 0)
$pointArr[] = $groupData;
$monthIndex = 1;
$tmp_group_fk = $result[$i]["group_fk"];
$groupData = Array(
"group_fk" => $result[$i]["group_fk"],
"group_name" => $result[$i]["group_name"],
"manager_name" => $result[$i]["manager_name"],
"list" => Array()
);
}
$groupData["list"][$result[$i]["month"]] = Array("input_point" => $result[$i]["input_point"], "output_point" => $result[$i]["output_point"]);
}
$pointArr[] = $groupData;
return $pointArr;
}
/**
* 상점별 통계
* @return unknown[][]|mixed[][]
*/
function getShopPointStatsData()
{
$year = $this->req["year"] == "" ? date("Y", time()) : $this->req["year"];
$pointArr = Array();
$where = " WHERE S.status = 'Y' ";
$subWhere = " WHERE PT.trans_type = 'O' AND PT.pay_type = '{$this->PAY_TYPE_USE}' AND PT.shop_fk > 0 AND YEAR(PT.reg_date) = '{$year}' ";
if($this->admUser["admin_type"] == "3")
{
$where .= " AND S.no = '{$this->admUser["target_fk"]}' ";
$subWhere .= " AND PT.shop_fk = '{$this->admUser["target_fk"]}'";
}
$sql = "
SELECT
P.month, P.output_point, S.name AS shop_name, S.no AS shop_fk
, IFNULL((SELECT A.admin_name FROM tbl_admin A WHERE A.target_fk = S.no AND A.admin_type = '3' AND A.is_apply = 1 LIMIT 1), '-') AS manager_name
FROM tbl_shop S
LEFT JOIN (
SELECT
PT.shop_fk
, MONTH(PT.reg_date) AS `month`
, IFNULL(SUM(PT.amt), 0) AS output_point
FROM tbl_point_trans PT
{$subWhere}
GROUP BY PT.shop_fk, `month`
ORDER BY PT.shop_fk ASC, `month` ASC
) P ON(P.shop_fk = S.no)
{$where}
";
$result = $this->getArray($sql);
$monthIndex = 0;
$tmp_shop_fk = "0";
$shopData = Array();
for($i=0; $i<sizeof($result); $i++)
{
if($result[$i]["shop_fk"] != $tmp_shop_fk)
{
if($i > 0)
$pointArr[] = $shopData;
$monthIndex = 1;
$tmp_shop_fk = $result[$i]["shop_fk"];
$shopData = Array(
"shop_fk" => $result[$i]["shop_fk"],
"shop_name" => $result[$i]["shop_name"],
"manager_name" => $result[$i]["manager_name"],
"list" => Array()
);
}
$shopData["list"][$result[$i]["month"]] = $result[$i]["output_point"];
}
$pointArr[] = $shopData;
return $pointArr;
}
/**
* 그룹별 상점 통계
* @return unknown[][]|mixed[][]
*/
function getShopPointStatsDataForGroup()
{
$no = $this->req["no"];
$year = $this->req["year"] == "" ? date("Y", time()) : $this->req["year"];
$month = $this->req["month"] == "" ? date("n", time()) : $this->req["month"];
$pointArr = Array();
$sql = "
SELECT G.no AS group_fk, G.name AS group_name, SD.date, IFNULL(SUM(PT.amt), 0) AS output_point
FROM
(
SELECT *
FROM tbl_user_group G
WHERE G.no IN(
SELECT T.group_fk
FROM tbl_point_trans T
WHERE T.shop_fk = '{$no}' AND T.trans_type = 'O' AND T.pay_type = 'use' AND YEAR(T.reg_date) = '{$year}' AND MONTH(T.reg_date) = '{$month}'
GROUP BY T.group_fk
)
) G
JOIN tbl_stats_date SD ON (SD.year = '{$year}' AND SD.month = '{$month}')
LEFT JOIN tbl_point_trans PT ON(PT.shop_fk = '{$no}' AND PT.trans_type = 'O' AND PT.pay_type = 'use' AND SD.date = PT.reg_date AND G.no = PT.group_fk)
GROUP BY G.no, SD.date
ORDER BY G.no ASC, SD.date ASC
";
$result = $this->getArray($sql);
$monthIndex = 0;
$tmp_group_fk = "0";
$groupData = Array();
for($i=0; $i<sizeof($result); $i++)
{
if($result[$i]["group_fk"] != $tmp_group_fk)
{
if($i > 0)
$pointArr[] = $groupData;
$monthIndex = 1;
$tmp_group_fk = $result[$i]["group_fk"];
$groupData = Array(
"group_fk" => $result[$i]["group_fk"],
"group_name" => $result[$i]["group_name"],
"total_point" => 0,
"list" => Array()
);
}
$groupData["list"][$result[$i]["date"]] = $result[$i]["output_point"];
$groupData["total_point"] += $result[$i]["output_point"];
}
$pointArr[] = $groupData;
return $pointArr;
}
/**
* 상점 통계 회원별
* @return mixed[][]
*/
function getShopPointStatsDataForUser()
{
$no = $this->req["no"];
$year = $this->req["year"] == "" ? date("Y", time()) : $this->req["year"];
$month = $this->req["month"] == "" ? date("n", time()) : $this->req["month"];
$pointArr = Array();
$sql = "
SELECT
U.no AS user_fk, U.name AS user_name, SD.date, IFNULL(SUM(PT.amt), 0) AS output_point
FROM
(
SELECT *
FROM tbl_user U
WHERE U.no IN(
SELECT T.user_fk
FROM tbl_point_trans T
WHERE T.shop_fk = '{$no}' AND T.trans_type = 'O' AND T.pay_type = 'use' AND YEAR(T.reg_date) = '{$year}' AND MONTH(T.reg_date) = '{$month}'
GROUP BY T.user_fk
)
) U
JOIN tbl_stats_date SD ON (SD.year = '{$year}' AND SD.month = '{$month}')
LEFT JOIN tbl_point_trans PT ON(PT.shop_fk = '{$no}' AND PT.trans_type = 'O' AND PT.pay_type = 'use' AND SD.date = PT.reg_date AND U.no = PT.user_fk)
GROUP BY U.no, SD.date
ORDER BY U.no ASC, SD.date ASC
";
$result = $this->getArray($sql);
$tmp_user_fk = "0";
$groupData = Array();
for($i=0; $i<sizeof($result); $i++)
{
if($result[$i]["user_fk"] != $tmp_user_fk)
{
if($i > 0)
$pointArr[] = $groupData;
$monthIndex = 1;
$tmp_user_fk = $result[$i]["user_fk"];
$groupData = Array(
"user_fk" => $result[$i]["user_fk"],
"user_name" => $result[$i]["user_name"],
"total_point" => 0,
"list" => Array()
);
}
$groupData["list"][$result[$i]["date"]] = $result[$i]["output_point"];
$groupData["total_point"] += $result[$i]["output_point"];
}
$pointArr[] = $groupData;
return $pointArr;
}
} // class end
}
?>