source: branches/beta/html/admin/home.php @ 16826

Revision 16826, 6.9 KB checked in by naka, 15 years ago (diff)

新着情報取得をEC-CUBE2.0対応に変更

Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7
8require_once("./require.php");
9require_once DATA_PATH . 'module/Services/JSON.php';
10
11class LC_Page {
12    var $arrSession;
13    function LC_Page() {
14        $this->tpl_mainpage = 'home.tpl';
15    }
16}
17
18$conn = new SC_DBConn();
19$objPage = new LC_Page();
20$objView = new SC_AdminView();
21$objSess = new SC_Session();
22
23// ǧ¾Ú²ÄÈݤÎȽÄê
24sfIsSuccess($objSess);
25
26// DB¥Ð¡¼¥¸¥ç¥ó¤Î¼èÆÀ
27$objPage->db_version = sfGetDBVersion();
28
29// PHP¥Ð¡¼¥¸¥ç¥ó¤Î¼èÆÀ
30$objPage->php_version = "PHP " . phpversion();
31
32// ¸½ºß¤Î²ñ°÷¿ô
33$objPage->customer_cnt = lfGetCustomerCnt($conn);
34
35// ºòÆü¤ÎÇä¾å¹â
36$objPage->order_yesterday_amount = lfGetOrderYesterday($conn, "SUM");
37
38// ºòÆü¤ÎÇä¾å·ï¿ô
39$objPage->order_yesterday_cnt = lfGetOrderYesterday($conn, "COUNT");
40
41// º£·î¤ÎÇä¾å¹â
42$objPage->order_month_amount = lfGetOrderMonth($conn, "SUM");
43
44// º£·î¤ÎÇä¾å·ï¿ô
45$objPage->order_month_cnt = lfGetOrderMonth($conn, "COUNT");
46
47// ¸ÜµÒ¤ÎÎ߷ץݥ¤¥ó¥È
48$objPage->customer_point = lfGetTotalCustomerPoint();
49
50//ºòÆü¤Î¥ì¥Ó¥å¡¼½ñ¤­¹þ¤ß¿ô
51$objPage->review_yesterday_cnt = lfGetReviewYesterday($conn);
52
53//¥ì¥Ó¥å¡¼½ñ¤­¹þ¤ßÈóɽ¼¨¿ô
54$objPage->review_nondisp_cnt = lfGetReviewNonDisp($conn);
55
56// ÉÊÀڤ쾦ÉÊ
57$objPage->arrSoldout = lfGetSoldOut();
58
59// ¿·µ¬¼õÉÕ°ìÍ÷
60$arrNewOrder = lfGetNewOrder();
61
62foreach ($arrNewOrder as $key => $val){
63    $arrNewOrder[$key]['create_date'] = str_replace("-", "/", substr($val['create_date'], 0,19));
64   
65}
66$objPage->arrNewOrder = $arrNewOrder;
67
68// ¤ªÃΤ餻°ìÍ÷¤Î¼èÆÀ
69$objPage->arrInfo = lfGetInfo();
70
71$objView->assignobj($objPage);
72$objView->display(MAIN_FRAME);
73//---------------------------------------------------------
74
75// ²ñ°÷¿ô
76function lfGetCustomerCnt($conn){
77   
78    $sql = "SELECT COUNT(customer_id) FROM dtb_customer WHERE del_flg = 0 AND status = 2";
79    $return = $conn->getOne($sql);
80    return $return;
81}
82
83// ºòÆü¤ÎÇä¾å¹â¡¦Çä¾å·ï¿ô
84function lfGetOrderYesterday($conn, $method){
85    if ( $method == 'SUM' or $method == 'COUNT'){
86        // postgresql ¤È mysql ¤È¤ÇSQL¤ò¤ï¤±¤ë
87        if (DB_TYPE == "pgsql") {
88            $sql = "SELECT ".$method."(total) FROM dtb_order
89                     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;
90        }else if (DB_TYPE == "mysql") {
91            $sql = "SELECT ".$method."(total) FROM dtb_order
92                     WHERE del_flg = 0 AND cast(substring(create_date,1, 10) as date) = DATE_ADD(current_date, interval -1 day) AND status <> " . ORDER_CANCEL;
93        }
94        $return = $conn->getOne($sql);
95    }
96    return $return;
97}
98
99function lfGetOrderMonth($conn, $method){
100
101    $month = date("Y/m", mktime());
102   
103    if ( $method == 'SUM' or $method == 'COUNT'){
104    // postgresql ¤È mysql ¤È¤ÇSQL¤ò¤ï¤±¤ë
105    if (DB_TYPE == "pgsql") {
106        $sql = "SELECT ".$method."(total) FROM dtb_order
107                 WHERE del_flg = 0 AND to_char(create_date,'YYYY/MM') = ?
108                 AND to_char(create_date,'YYYY/MM/DD') <> to_char(now(),'YYYY/MM/DD') AND status <> " . ORDER_CANCEL;
109    }else if (DB_TYPE == "mysql") {
110        $sql = "SELECT ".$method."(total) FROM dtb_order
111                 WHERE del_flg = 0 AND date_format(create_date, '%Y/%m') = ?
112                 AND date_format(create_date, '%Y/%m/%d') <> date_format(now(), '%Y/%m/%d') AND status <> " . ORDER_CANCEL;
113    }
114        $return = $conn->getOne($sql, array($month));
115    }
116    return $return;
117}
118
119function lfGetTotalCustomerPoint() {
120    $objQuery = new SC_Query();
121    $col = "SUM(point)";
122    $where = "del_flg = 0";
123    $from = "dtb_customer";
124    $ret = $objQuery->get($from, $col, $where);
125    return $ret;   
126}
127
128function lfGetReviewYesterday($conn){
129    // postgresql ¤È mysql ¤È¤ÇSQL¤ò¤ï¤±¤ë
130    if (DB_TYPE == "pgsql") {
131        $sql = "SELECT COUNT(*) FROM dtb_review AS A LEFT JOIN dtb_products AS B ON A.product_id = B.product_id 
132                 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')
133                 AND to_char(A.create_date,'YYYY/MM/DD') != to_char(now(),'YYYY/MM/DD')";
134    }else if (DB_TYPE == "mysql") {
135        $sql = "SELECT COUNT(*) FROM dtb_review AS A LEFT JOIN dtb_products AS B ON A.product_id = B.product_id
136                 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)
137                 AND cast(substring(A.create_date,1, 10) as date) != cast(substring(now(),1, 10) as date)";
138    }
139    $return = $conn->getOne($sql);
140    return $return;
141}
142
143function lfGetReviewNonDisp($conn){
144    $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";
145    $return = $conn->getOne($sql);
146    return $return;
147}
148
149// ÉÊÀڤ쾦ÉÊÈÖ¹æ¤Î¼èÆÀ
150function lfGetSoldOut() {
151    $objQuery = new SC_Query();
152    $where = "product_id IN (SELECT product_id FROM dtb_products_class WHERE stock_unlimited IS NULL AND stock <= 0)";
153    $arrRet = $objQuery->select("product_id, name", "dtb_products", $where);
154    return $arrRet;
155}
156
157// ¿·µ¬¼õÉÕ°ìÍ÷
158function lfGetNewOrder() {
159    $objQuery = new SC_Query();
160    $sql = "SELECT
161                ord.order_id,
162                ord.customer_id,
163                ord.order_name01 AS name01,
164                ord.order_name02 AS name02,
165                ord.total,
166                ord.create_date,
167                (SELECT
168                    det.product_name
169                FROM
170                    dtb_order_detail AS det
171                WHERE
172                    ord.order_id = det.order_id LIMIT 1
173                ) AS product_name,
174                (SELECT
175                    pay.payment_method
176                FROM
177                    dtb_payment AS pay
178                WHERE
179                    ord.payment_id = pay.payment_id
180                ) AS payment_method
181            FROM (
182                SELECT
183                    order_id,
184                    customer_id,
185                    order_name01,
186                    order_name02,
187                    total,
188                    create_date,
189                    payment_id
190                FROM
191                    dtb_order AS ord
192                WHERE
193                    del_flg = 0 AND status <> " . ORDER_CANCEL . "
194                ORDER BY
195                    create_date DESC LIMIT 10 OFFSET 0
196            ) AS ord";
197    $arrRet = $objQuery->getAll($sql);
198    return $arrRet;
199}
200
201    /**
202     * ¥ê¥ê¡¼¥¹¾ðÊó¤ò¼èÆÀ¤¹¤ë.
203     *
204     * @return unknown
205     */
206    function lfGetInfo() {
207        $query = '';
208        // TODO ¥µ¥¤¥È¾ðÊó¤ÎÁ÷¿®²ÄÈÝÀßÄê¤ò¹Ô¤¦
209        if (true) {
210            $query = '?site_url=' . SITE_URL . '&eccube_version=' . ECCUBE_VERSION;
211        }
212       
213        $url = UPDATE_HTTP2 . $query;
214        $jsonStr = @file_get_contents($url);
215       
216        $objJson = new Services_JSON;
217        $arrTmpData = is_string($jsonStr) ? $objJson->decode($jsonStr) : null;
218               
219        if (empty($arrTmpData)) {
220            sfErrorHeader(">> ¹¹¿·¾ðÊó¤Î¼èÆÀ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£");
221            return array();
222        }
223       
224        $arrTemp = array();
225        foreach ($arrTmpData as $objData) {
226            $arrTemp[] = get_object_vars($objData);           
227        }
228       
229        foreach($arrTemp as $array) {
230            foreach($array as $key => $val) {
231                $temp[$key] = mb_convert_encoding($val, CHAR_CODE, 'UTF-8');
232            }
233            $arrInfo[] = $temp;
234        }
235       
236        return $arrInfo;
237    }
238
239
240?>
Note: See TracBrowser for help on using the repository browser.