1 | <?php |
---|
2 | /* |
---|
3 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. |
---|
4 | * |
---|
5 | * http://www.lockon.co.jp/ |
---|
6 | */ |
---|
7 | |
---|
8 | // {{{ requires |
---|
9 | require_once(CLASS_PATH . "pages/LC_Page.php"); |
---|
10 | |
---|
11 | /** |
---|
12 | * 管理画面ホーム のページクラス. |
---|
13 | * |
---|
14 | * @package Page |
---|
15 | * @author LOCKON CO.,LTD. |
---|
16 | * @version $Id$ |
---|
17 | */ |
---|
18 | class LC_Page_Admin_Home extends LC_Page { |
---|
19 | |
---|
20 | // }}} |
---|
21 | // {{{ functions |
---|
22 | |
---|
23 | /** |
---|
24 | * Page を初期化する. |
---|
25 | * |
---|
26 | * @return void |
---|
27 | */ |
---|
28 | function init() { |
---|
29 | parent::init(); |
---|
30 | $this->tpl_mainpage = 'home.tpl'; |
---|
31 | } |
---|
32 | |
---|
33 | /** |
---|
34 | * Page のプロセス. |
---|
35 | * |
---|
36 | * @return void |
---|
37 | */ |
---|
38 | function process() { |
---|
39 | $conn = new SC_DBConn(); |
---|
40 | $objView = new SC_AdminView(); |
---|
41 | $objSess = new SC_Session(); |
---|
42 | |
---|
43 | // 認証可否の判定 |
---|
44 | SC_Utils_Ex::sfIsSuccess($objSess); |
---|
45 | |
---|
46 | // DBバージョンの取得 |
---|
47 | $objDb = new SC_Helper_DB_Ex(); |
---|
48 | $this->db_version = $objDb->sfGetDBVersion(); |
---|
49 | |
---|
50 | // PHPバージョンの取得 |
---|
51 | $this->php_version = "PHP " . phpversion(); |
---|
52 | |
---|
53 | // 現在の会員数 |
---|
54 | $this->customer_cnt = $this->lfGetCustomerCnt($conn); |
---|
55 | |
---|
56 | // 昨日の売上高 |
---|
57 | $this->order_yesterday_amount = $this->lfGetOrderYesterday($conn, "SUM"); |
---|
58 | |
---|
59 | // 昨日の売上件数 |
---|
60 | $this->order_yesterday_cnt = $this->lfGetOrderYesterday($conn, "COUNT"); |
---|
61 | |
---|
62 | // 今月の売上高 |
---|
63 | $this->order_month_amount = $this->lfGetOrderMonth($conn, "SUM"); |
---|
64 | |
---|
65 | // 今月の売上件数 |
---|
66 | $this->order_month_cnt = $this->lfGetOrderMonth($conn, "COUNT"); |
---|
67 | |
---|
68 | // 顧客の累計ポイント |
---|
69 | $this->customer_point = $this->lfGetTotalCustomerPoint(); |
---|
70 | |
---|
71 | //昨日のレビュー書き込み数 |
---|
72 | $this->review_yesterday_cnt = $this->lfGetReviewYesterday($conn); |
---|
73 | |
---|
74 | //レビュー書き込み非表示数 |
---|
75 | $this->review_nondisp_cnt = $this->lfGetReviewNonDisp($conn); |
---|
76 | |
---|
77 | // 品切れ商品 |
---|
78 | $this->arrSoldout = $this->lfGetSoldOut(); |
---|
79 | |
---|
80 | // 新規受付一覧 |
---|
81 | $arrNewOrder = $this->lfGetNewOrder(); |
---|
82 | |
---|
83 | foreach ($arrNewOrder as $key => $val){ |
---|
84 | $arrNewOrder[$key]['create_date'] = str_replace("-", "/", substr($val['create_date'], 0,19)); |
---|
85 | |
---|
86 | } |
---|
87 | $this->arrNewOrder = $arrNewOrder; |
---|
88 | |
---|
89 | // お知らせ一覧の取得 |
---|
90 | $this->arrInfo = $this->lfGetInfo(); |
---|
91 | |
---|
92 | $objView->assignobj($this); |
---|
93 | $objView->display(MAIN_FRAME); |
---|
94 | } |
---|
95 | |
---|
96 | /** |
---|
97 | * デストラクタ. |
---|
98 | * |
---|
99 | * @return void |
---|
100 | */ |
---|
101 | function destroy() { |
---|
102 | parent::destroy(); |
---|
103 | } |
---|
104 | |
---|
105 | // 会員数 |
---|
106 | function lfGetCustomerCnt($conn){ |
---|
107 | |
---|
108 | $sql = "SELECT COUNT(customer_id) FROM dtb_customer WHERE del_flg = 0 AND status = 2"; |
---|
109 | $return = $conn->getOne($sql); |
---|
110 | return $return; |
---|
111 | } |
---|
112 | |
---|
113 | // 昨日の売上高・売上件数 |
---|
114 | function lfGetOrderYesterday($conn, $method){ |
---|
115 | if ( $method == 'SUM' or $method == 'COUNT'){ |
---|
116 | // postgresql と mysql とでSQLをわける |
---|
117 | if (DB_TYPE == "pgsql") { |
---|
118 | $sql = "SELECT ".$method."(total) FROM dtb_order |
---|
119 | WHERE del_flg = 0 AND to_char(create_date,'YYYY/MM/DD') = to_char(now() - interval '1 days','YYYY/MM/DD') AND status <> " . ORDER_CANCEL; |
---|
120 | }else if (DB_TYPE == "mysql") { |
---|
121 | $sql = "SELECT ".$method."(total) FROM dtb_order |
---|
122 | WHERE del_flg = 0 AND cast(substring(create_date,1, 10) as date) = DATE_ADD(current_date, interval -1 day) AND status <> " . ORDER_CANCEL; |
---|
123 | } |
---|
124 | $return = $conn->getOne($sql); |
---|
125 | } |
---|
126 | return $return; |
---|
127 | } |
---|
128 | |
---|
129 | function lfGetOrderMonth($conn, $method){ |
---|
130 | |
---|
131 | $month = date("Y/m", mktime()); |
---|
132 | |
---|
133 | if ( $method == 'SUM' or $method == 'COUNT'){ |
---|
134 | // postgresql と mysql とでSQLをわける |
---|
135 | if (DB_TYPE == "pgsql") { |
---|
136 | $sql = "SELECT ".$method."(total) FROM dtb_order |
---|
137 | WHERE del_flg = 0 AND to_char(create_date,'YYYY/MM') = ? |
---|
138 | AND to_char(create_date,'YYYY/MM/DD') <> to_char(now(),'YYYY/MM/DD') AND status <> " . ORDER_CANCEL; |
---|
139 | }else if (DB_TYPE == "mysql") { |
---|
140 | $sql = "SELECT ".$method."(total) FROM dtb_order |
---|
141 | WHERE del_flg = 0 AND date_format(create_date, '%Y/%m') = ? |
---|
142 | AND date_format(create_date, '%Y/%m/%d') <> date_format(now(), '%Y/%m/%d') AND status <> " . ORDER_CANCEL; |
---|
143 | } |
---|
144 | $return = $conn->getOne($sql, array($month)); |
---|
145 | } |
---|
146 | return $return; |
---|
147 | } |
---|
148 | |
---|
149 | function lfGetTotalCustomerPoint() { |
---|
150 | $objQuery = new SC_Query(); |
---|
151 | $col = "SUM(point)"; |
---|
152 | $where = "del_flg = 0"; |
---|
153 | $from = "dtb_customer"; |
---|
154 | $ret = $objQuery->get($from, $col, $where); |
---|
155 | return $ret; |
---|
156 | } |
---|
157 | |
---|
158 | function lfGetReviewYesterday($conn){ |
---|
159 | // postgresql と mysql とでSQLをわける |
---|
160 | if (DB_TYPE == "pgsql") { |
---|
161 | $sql = "SELECT COUNT(*) FROM dtb_review AS A LEFT JOIN dtb_products AS B ON A.product_id = B.product_id |
---|
162 | WHERE A.del_flg=0 AND B.del_flg = 0 AND to_char(A.create_date, 'YYYY/MM/DD') = to_char(now() - interval '1 days','YYYY/MM/DD') |
---|
163 | AND to_char(A.create_date,'YYYY/MM/DD') != to_char(now(),'YYYY/MM/DD')"; |
---|
164 | }else if (DB_TYPE == "mysql") { |
---|
165 | $sql = "SELECT COUNT(*) FROM dtb_review AS A LEFT JOIN dtb_products AS B ON A.product_id = B.product_id |
---|
166 | WHERE A.del_flg = 0 AND B.del_flg = 0 AND cast(substring(A.create_date,1, 10) as date) = DATE_ADD(current_date, interval -1 day) |
---|
167 | AND cast(substring(A.create_date,1, 10) as date) != cast(substring(now(),1, 10) as date)"; |
---|
168 | } |
---|
169 | $return = $conn->getOne($sql); |
---|
170 | return $return; |
---|
171 | } |
---|
172 | |
---|
173 | function lfGetReviewNonDisp($conn){ |
---|
174 | $sql = "SELECT COUNT(*) FROM dtb_review AS A LEFT JOIN dtb_products AS B ON A.product_id = B.product_id WHERE A.del_flg=0 AND A.status=2 AND B.del_flg=0"; |
---|
175 | $return = $conn->getOne($sql); |
---|
176 | return $return; |
---|
177 | } |
---|
178 | |
---|
179 | // 品切れ商品番号の取得 |
---|
180 | function lfGetSoldOut() { |
---|
181 | $objQuery = new SC_Query(); |
---|
182 | $where = "product_id IN (SELECT product_id FROM dtb_products_class WHERE stock_unlimited IS NULL AND stock <= 0)"; |
---|
183 | $arrRet = $objQuery->select("product_id, name", "dtb_products", $where); |
---|
184 | return $arrRet; |
---|
185 | } |
---|
186 | |
---|
187 | // 新規受付一覧 |
---|
188 | function lfGetNewOrder() { |
---|
189 | $objQuery = new SC_Query(); |
---|
190 | $sql = "SELECT |
---|
191 | ord.order_id, |
---|
192 | ord.customer_id, |
---|
193 | ord.order_name01 AS name01, |
---|
194 | ord.order_name02 AS name02, |
---|
195 | ord.total, |
---|
196 | ord.create_date, |
---|
197 | (SELECT |
---|
198 | det.product_name |
---|
199 | FROM |
---|
200 | dtb_order_detail AS det |
---|
201 | WHERE |
---|
202 | ord.order_id = det.order_id LIMIT 1 |
---|
203 | ) AS product_name, |
---|
204 | (SELECT |
---|
205 | pay.payment_method |
---|
206 | FROM |
---|
207 | dtb_payment AS pay |
---|
208 | WHERE |
---|
209 | ord.payment_id = pay.payment_id |
---|
210 | ) AS payment_method |
---|
211 | FROM ( |
---|
212 | SELECT |
---|
213 | order_id, |
---|
214 | customer_id, |
---|
215 | order_name01, |
---|
216 | order_name02, |
---|
217 | total, |
---|
218 | create_date, |
---|
219 | payment_id |
---|
220 | FROM |
---|
221 | dtb_order AS ord |
---|
222 | WHERE |
---|
223 | del_flg = 0 AND status <> " . ORDER_CANCEL . " |
---|
224 | ORDER BY |
---|
225 | create_date DESC LIMIT 10 OFFSET 0 |
---|
226 | ) AS ord"; |
---|
227 | $arrRet = $objQuery->getAll($sql); |
---|
228 | return $arrRet; |
---|
229 | } |
---|
230 | |
---|
231 | // お知らせ取得 |
---|
232 | function lfGetInfo() { |
---|
233 | // 更新情報を最新にする |
---|
234 | $objQuery = new SC_Query(); |
---|
235 | $path = UPDATE_HTTP . "info.txt"; |
---|
236 | $fp = @fopen($path, "rb"); |
---|
237 | |
---|
238 | $arrRet = array(); |
---|
239 | if(!$fp) { |
---|
240 | SC_Utils_Ex::sfErrorHeader(">> " . $path . "の取得に失敗しました。"); |
---|
241 | } else { |
---|
242 | while (!feof($fp)) { |
---|
243 | $arrRet[] = $arrCSV = fgetcsv($fp, UPDATE_CSV_LINE_MAX); |
---|
244 | } |
---|
245 | fclose($fp); |
---|
246 | } |
---|
247 | |
---|
248 | // CHAR_CODE が EUC-JP 以外の場合は CHAR_CODE へ変換 |
---|
249 | if (CHAR_CODE == "EUC-JP") { |
---|
250 | return $arrRet; |
---|
251 | } else { |
---|
252 | $newArrRet = array(); |
---|
253 | foreach ($arrRet as $inKey => $inArr) { |
---|
254 | |
---|
255 | $inVal = array(); |
---|
256 | foreach($inArr as $key => $val) { |
---|
257 | |
---|
258 | $inVal[$key] = mb_convert_encoding($val, CHAR_CODE, "EUC-JP"); |
---|
259 | } |
---|
260 | $newArrRet[$inKey] = $inVal; |
---|
261 | } |
---|
262 | |
---|
263 | return $newArrRet; |
---|
264 | } |
---|
265 | } |
---|
266 | } |
---|
267 | ?> |
---|