source: branches/dev/html/admin/home.php @ 330

Revision 330, 6.0 KB checked in by kakinaka, 16 years ago (diff)
Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7require_once("./require.php");
8
9class 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// ǧ¾Ú²ÄÈݤÎȽÄê
22sfIsSuccess($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
60foreach ($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// ²ñ°÷¿ô
74function 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// ºòÆü¤ÎÇä¾å¹â¡¦Çä¾å·ï¿ô
82function 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')";
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)";
91        }
92        $return = $conn->getOne($sql);
93    }
94    return $return;
95}
96
97function 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')";
107    }else if (DB_TYPE == "mysql") {
108        $sql = "SELECT ".$method."(total) FROM dtb_order
109                 WHERE del_flg = 0 AND cast(substring(create_date,1,7) as date) = ?
110                 AND cast(substring(create_date,1, 10) as date) <> cast(substring(now(),1, 10) as date)";
111    }
112        $return = $conn->getOne($sql, array($month));
113    }
114    return $return;
115}
116
117function 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
126function 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
141function 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// ÉÊÀڤ쾦ÉÊÈÖ¹æ¤Î¼èÆÀ
148function 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// ¿·µ¬¼õÉÕ°ìÍ÷
156function 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
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// ¤ªÃΤ餻¼èÆÀ
200function 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        }
213        fclose($fp);
214    }
215   
216    return $arrRet;
217}
218
219
220
221?>
Note: See TracBrowser for help on using the repository browser.