| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * Copyright(c) 2000-2006 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->system = "PHP" . phpversion(). "/" . sfGetDBVersion(); |
|---|
| 26 | |
|---|
| 27 | // ¸½ºß¤Î²ñ°÷¿ô |
|---|
| 28 | $objPage->customer_cnt = lfGetCustomerCnt($conn); |
|---|
| 29 | |
|---|
| 30 | // ºòÆü¤ÎÇä¾å¹â |
|---|
| 31 | $objPage->order_yesterday_amount = lfGetOrderYesterday($conn, "SUM"); |
|---|
| 32 | |
|---|
| 33 | // ºòÆü¤ÎÇä¾å·ï¿ô |
|---|
| 34 | $objPage->order_yesterday_cnt = lfGetOrderYesterday($conn, "COUNT"); |
|---|
| 35 | |
|---|
| 36 | // º£·î¤ÎÇä¾å¹â |
|---|
| 37 | $objPage->order_month_amount = lfGetOrderMonth($conn, "SUM"); |
|---|
| 38 | |
|---|
| 39 | // º£·î¤ÎÇä¾å·ï¿ô |
|---|
| 40 | $objPage->order_month_cnt = lfGetOrderMonth($conn, "COUNT"); |
|---|
| 41 | |
|---|
| 42 | // ¸ÜµÒ¤ÎÎ߷ץݥ¤¥ó¥È |
|---|
| 43 | $objPage->customer_point = lfGetTotalCustomerPoint(); |
|---|
| 44 | |
|---|
| 45 | //ºòÆü¤Î¥ì¥Ó¥å¡¼½ñ¤¹þ¤ß¿ô |
|---|
| 46 | $objPage->review_yesterday_cnt = lfGetReviewYesterday($conn); |
|---|
| 47 | |
|---|
| 48 | //¥ì¥Ó¥å¡¼½ñ¤¹þ¤ßÈóɽ¼¨¿ô |
|---|
| 49 | $objPage->review_nondisp_cnt = lfGetReviewNonDisp($conn); |
|---|
| 50 | |
|---|
| 51 | // ÉÊÀڤ쾦ÉÊ |
|---|
| 52 | $objPage->arrSoldout = lfGetSoldOut(); |
|---|
| 53 | |
|---|
| 54 | // ¿·µ¬¼õÉÕ°ìÍ÷ |
|---|
| 55 | $arrNewOrder = lfGetNewOrder(); |
|---|
| 56 | |
|---|
| 57 | foreach ($arrNewOrder as $key => $val){ |
|---|
| 58 | $arrNewOrder[$key]['create_date'] = str_replace("-", "/", substr($val['create_date'], 0,19)); |
|---|
| 59 | |
|---|
| 60 | } |
|---|
| 61 | $objPage->arrNewOrder = $arrNewOrder; |
|---|
| 62 | |
|---|
| 63 | // ¤ªÃΤ餻°ìÍ÷¤Î¼èÆÀ |
|---|
| 64 | $objPage->arrInfo = lfGetInfo(); |
|---|
| 65 | |
|---|
| 66 | $objView->assignobj($objPage); |
|---|
| 67 | $objView->display(MAIN_FRAME); |
|---|
| 68 | //--------------------------------------------------------- |
|---|
| 69 | |
|---|
| 70 | // ²ñ°÷¿ô |
|---|
| 71 | function lfGetCustomerCnt($conn){ |
|---|
| 72 | |
|---|
| 73 | $sql = "SELECT COUNT(customer_id) FROM dtb_customer WHERE del_flg = 0 AND status = 2"; |
|---|
| 74 | $return = $conn->getOne($sql); |
|---|
| 75 | return $return; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | // ºòÆü¤ÎÇä¾å¹â¡¦Çä¾å·ï¿ô |
|---|
| 79 | function lfGetOrderYesterday($conn, $method){ |
|---|
| 80 | if ( $method == 'SUM' or $method == 'COUNT'){ |
|---|
| 81 | // postgresql ¤È mysql ¤È¤ÇSQL¤ò¤ï¤±¤ë |
|---|
| 82 | if (DB_TYPE == "pgsql") { |
|---|
| 83 | $sql = "SELECT ".$method."(total) FROM dtb_order |
|---|
| 84 | WHERE del_flg = 0 AND to_char(create_date,'YYYY/MM/DD') = to_char(now() - interval '1 days','YYYY/MM/DD')"; |
|---|
| 85 | }else if (DB_TYPE == "mysql") { |
|---|
| 86 | $sql = "SELECT ".$method."(total) FROM dtb_order |
|---|
| 87 | WHERE del_flg = 0 AND cast(substring(create_date,1, 10) as date) = DATE_ADD(current_date, interval -1 day)"; |
|---|
| 88 | } |
|---|
| 89 | $return = $conn->getOne($sql); |
|---|
| 90 | } |
|---|
| 91 | return $return; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | function lfGetOrderMonth($conn, $method){ |
|---|
| 95 | |
|---|
| 96 | $month = date("Y/m", mktime()); |
|---|
| 97 | |
|---|
| 98 | if ( $method == 'SUM' or $method == 'COUNT'){ |
|---|
| 99 | // postgresql ¤È mysql ¤È¤ÇSQL¤ò¤ï¤±¤ë |
|---|
| 100 | if (DB_TYPE == "pgsql") { |
|---|
| 101 | $sql = "SELECT ".$method."(total) FROM dtb_order |
|---|
| 102 | WHERE del_flg = 0 AND to_char(create_date,'YYYY/MM') = ? |
|---|
| 103 | AND to_char(create_date,'YYYY/MM/DD') <> to_char(now(),'YYYY/MM/DD')"; |
|---|
| 104 | }else if (DB_TYPE == "mysql") { |
|---|
| 105 | $sql = "SELECT ".$method."(total) FROM dtb_order |
|---|
| 106 | WHERE del_flg = 0 AND cast(substring(create_date,1,7) as date) = ? |
|---|
| 107 | AND cast(substring(create_date,1, 10) as date) <> cast(substring(now(),1, 10) as date)"; |
|---|
| 108 | } |
|---|
| 109 | $return = $conn->getOne($sql, array($month)); |
|---|
| 110 | } |
|---|
| 111 | return $return; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | function lfGetTotalCustomerPoint() { |
|---|
| 115 | $objQuery = new SC_Query(); |
|---|
| 116 | $col = "SUM(point)"; |
|---|
| 117 | $where = "del_flg = 0"; |
|---|
| 118 | $from = "dtb_customer"; |
|---|
| 119 | $ret = $objQuery->get($from, $col, $where); |
|---|
| 120 | return $ret; |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | function lfGetReviewYesterday($conn){ |
|---|
| 124 | // postgresql ¤È mysql ¤È¤ÇSQL¤ò¤ï¤±¤ë |
|---|
| 125 | if (DB_TYPE == "pgsql") { |
|---|
| 126 | $sql = "SELECT COUNT(*) FROM dtb_review |
|---|
| 127 | WHERE del_flg=0 AND to_char(create_date, 'YYYY/MM/DD') = to_char(now() - interval '1 days','YYYY/MM/DD') |
|---|
| 128 | AND to_char(create_date,'YYYY/MM/DD') != to_char(now(),'YYYY/MM/DD')"; |
|---|
| 129 | }else if (DB_TYPE == "mysql") { |
|---|
| 130 | $sql = "SELECT COUNT(*) FROM dtb_review |
|---|
| 131 | WHERE del_flg = 0 AND cast(substring(create_date,1, 10) as date) = DATE_ADD(current_date, interval -1 day) |
|---|
| 132 | AND cast(substring(create_date,1, 10) as date) != cast(substring(now(),1, 10) as date)"; |
|---|
| 133 | } |
|---|
| 134 | $return = $conn->getOne($sql); |
|---|
| 135 | return $return; |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | function lfGetReviewNonDisp($conn){ |
|---|
| 139 | $sql = "SELECT COUNT(*) FROM dtb_review WHERE del_flg=0 AND status=2"; |
|---|
| 140 | $return = $conn->getOne($sql); |
|---|
| 141 | return $return; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | // ÉÊÀڤ쾦ÉÊÈÖ¹æ¤Î¼èÆÀ |
|---|
| 145 | function lfGetSoldOut() { |
|---|
| 146 | $objQuery = new SC_Query(); |
|---|
| 147 | $where = "product_id IN (SELECT product_id FROM dtb_products_class WHERE stock_unlimited IS NULL AND stock <= 0)"; |
|---|
| 148 | $arrRet = $objQuery->select("product_id, name", "dtb_products", $where); |
|---|
| 149 | return $arrRet; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | // ¿·µ¬¼õÉÕ°ìÍ÷ |
|---|
| 153 | function lfGetNewOrder() { |
|---|
| 154 | $objQuery = new SC_Query(); |
|---|
| 155 | $col = "ord.order_id, customer_id, ord.order_name01 AS name01, ord.order_name02 AS name02, ord.total, "; |
|---|
| 156 | $col.= "(SELECT det.product_name FROM dtb_order_detail AS det WHERE ord.order_id = det.order_id LIMIT 1) AS product_name, "; |
|---|
| 157 | $col.= "(SELECT pay.payment_method FROM dtb_payment AS pay WHERE ord.payment_id = pay.payment_id) AS payment_method, "; |
|---|
| 158 | $col.= "create_date AS create_date"; |
|---|
| 159 | $from = "dtb_order AS ord"; |
|---|
| 160 | $where = "del_flg = 0"; |
|---|
| 161 | $objQuery->setoption("ORDER BY create_date DESC LIMIT 10 OFFSET 0"); |
|---|
| 162 | $arrRet = $objQuery->select($col, $from, $where); |
|---|
| 163 | return $arrRet; |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | // ¤ªÃΤ餻¼èÆÀ |
|---|
| 167 | function lfGetInfo() { |
|---|
| 168 | // ¹¹¿·¾ðÊó¤òºÇ¿·¤Ë¤¹¤ë |
|---|
| 169 | $objQuery = new SC_Query(); |
|---|
| 170 | $path = UPDATE_HTTP . "info.txt"; |
|---|
| 171 | $fp = @fopen($path, "rb"); |
|---|
| 172 | |
|---|
| 173 | $arrRet = array(); |
|---|
| 174 | if(!$fp) { |
|---|
| 175 | sfErrorHeader(">> " . $path . "¤Î¼èÆÀ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£"); |
|---|
| 176 | } else { |
|---|
| 177 | while (!feof($fp)) { |
|---|
| 178 | $arrRet[] = $arrCSV = fgetcsv($fp, UPDATE_CSV_LINE_MAX); |
|---|
| 179 | } |
|---|
| 180 | fclose($fp); |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | return $arrRet; |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | ?> |
|---|