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