| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | require_once("./require.php"); |
|---|
| 4 | |
|---|
| 5 | class LC_Page { |
|---|
| 6 | var $arrSession; |
|---|
| 7 | function LC_Page() { |
|---|
| 8 | $this->tpl_mainpage = 'home.tpl'; |
|---|
| 9 | } |
|---|
| 10 | } |
|---|
| 11 | |
|---|
| 12 | $conn = new SC_DBConn(); |
|---|
| 13 | $objPage = new LC_Page(); |
|---|
| 14 | $objView = new SC_AdminView(); |
|---|
| 15 | $objSess = new SC_Session(); |
|---|
| 16 | |
|---|
| 17 | // ǧ¾Ú²ÄÈݤÎȽÄê |
|---|
| 18 | sfIsSuccess($objSess); |
|---|
| 19 | |
|---|
| 20 | // ¸½ºß¤Î²ñ°÷¿ô |
|---|
| 21 | $objPage->customer_cnt = lfGetCustomerCnt($conn); |
|---|
| 22 | |
|---|
| 23 | // ºòÆü¤ÎÇä¾å¹â |
|---|
| 24 | $objPage->order_yesterday_amount = lfGetOrderYesterday($conn, "SUM"); |
|---|
| 25 | |
|---|
| 26 | // ºòÆü¤ÎÇä¾å·ï¿ô |
|---|
| 27 | $objPage->order_yesterday_cnt = lfGetOrderYesterday($conn, "COUNT"); |
|---|
| 28 | |
|---|
| 29 | // º£·î¤ÎÇä¾å¹â |
|---|
| 30 | $objPage->order_month_amount = lfGetOrderMonth($conn, "SUM"); |
|---|
| 31 | |
|---|
| 32 | // º£·î¤ÎÇä¾å·ï¿ô |
|---|
| 33 | $objPage->order_month_cnt = lfGetOrderMonth($conn, "COUNT"); |
|---|
| 34 | |
|---|
| 35 | // ¸ÜµÒ¤ÎÎ߷ץݥ¤¥ó¥È |
|---|
| 36 | $objPage->customer_point = lfGetTotalCustomerPoint(); |
|---|
| 37 | |
|---|
| 38 | //ºòÆü¤Î¥ì¥Ó¥å¡¼½ñ¤¹þ¤ß¿ô |
|---|
| 39 | $objPage->review_yesterday_cnt = lfGetReviewYesterday($conn); |
|---|
| 40 | |
|---|
| 41 | //¥ì¥Ó¥å¡¼½ñ¤¹þ¤ßÈóɽ¼¨¿ô |
|---|
| 42 | $objPage->review_nondisp_cnt = lfGetReviewNonDisp($conn); |
|---|
| 43 | |
|---|
| 44 | // ÉÊÀڤ쾦ÉÊ |
|---|
| 45 | $objPage->arrSoldout = lfGetSoldOut(); |
|---|
| 46 | |
|---|
| 47 | // ¿·µ¬¼õÉÕ°ìÍ÷ |
|---|
| 48 | $objPage->arrNewOrder = lfGetNewOrder(); |
|---|
| 49 | |
|---|
| 50 | // ¤ªÃΤ餻°ìÍ÷¤Î¼èÆÀ |
|---|
| 51 | $objPage->arrInfo = lfGetInfo(); |
|---|
| 52 | |
|---|
| 53 | $objView->assignobj($objPage); |
|---|
| 54 | $objView->display(MAIN_FRAME); |
|---|
| 55 | //--------------------------------------------------------- |
|---|
| 56 | |
|---|
| 57 | // ²ñ°÷¿ô |
|---|
| 58 | function lfGetCustomerCnt($conn){ |
|---|
| 59 | |
|---|
| 60 | $sql = "SELECT COUNT(customer_id) FROM dtb_customer WHERE delete = 0 AND status = 2"; |
|---|
| 61 | $return = $conn->getOne($sql); |
|---|
| 62 | return $return; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | // ºòÆü¤ÎÇä¾å¹â¡¦Çä¾å·ï¿ô |
|---|
| 66 | function lfGetOrderYesterday($conn, $method){ |
|---|
| 67 | if ( $method == 'SUM' or $method == 'COUNT'){ |
|---|
| 68 | $sql = "SELECT ".$method."(total) FROM dtb_order |
|---|
| 69 | WHERE delete = 0 AND to_char(create_date,'YYYY/MM/DD') = to_char(now() - interval '1 days','YYYY/MM/DD')"; |
|---|
| 70 | $return = $conn->getOne($sql); |
|---|
| 71 | } |
|---|
| 72 | return $return; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | function lfGetOrderMonth($conn, $method){ |
|---|
| 76 | |
|---|
| 77 | $month = date("Y/m", mktime()); |
|---|
| 78 | |
|---|
| 79 | if ( $method == 'SUM' or $method == 'COUNT'){ |
|---|
| 80 | $sql = "SELECT ".$method."(total) FROM dtb_order |
|---|
| 81 | WHERE delete = 0 AND to_char(create_date,'YYYY/MM') = ? |
|---|
| 82 | AND to_char(create_date,'YYYY/MM/DD') <> to_char(now(),'YYYY/MM/DD')"; |
|---|
| 83 | $return = $conn->getOne($sql, array($month)); |
|---|
| 84 | } |
|---|
| 85 | return $return; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | function lfGetTotalCustomerPoint() { |
|---|
| 89 | $objQuery = new SC_Query(); |
|---|
| 90 | $col = "SUM(point)"; |
|---|
| 91 | $where = "delete = 0"; |
|---|
| 92 | $from = "dtb_customer"; |
|---|
| 93 | $ret = $objQuery->get($from, $col, $where); |
|---|
| 94 | return $ret; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | function lfGetReviewYesterday($conn){ |
|---|
| 98 | $sql = "SELECT COUNT (*) FROM dtb_review |
|---|
| 99 | WHERE delete=0 AND to_char(create_date, 'YYYY/MM/DD') = to_char(now() - interval '1 days','YYYY/MM/DD') |
|---|
| 100 | AND to_char(create_date,'YYYY/MM/DD') != to_char(now(),'YYYY/MM/DD')"; |
|---|
| 101 | $return = $conn->getOne($sql); |
|---|
| 102 | return $return; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | function lfGetReviewNonDisp($conn){ |
|---|
| 106 | $sql = "SELECT COUNT (*) FROM dtb_review WHERE delete=0 AND status=2"; |
|---|
| 107 | $return = $conn->getOne($sql); |
|---|
| 108 | return $return; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | // ÉÊÀڤ쾦ÉÊÈÖ¹æ¤Î¼èÆÀ |
|---|
| 112 | function lfGetSoldOut() { |
|---|
| 113 | $objQuery = new SC_Query(); |
|---|
| 114 | $where = "product_id IN (SELECT product_id FROM dtb_products_class WHERE stock_unlimited IS NULL AND stock <= 0)"; |
|---|
| 115 | $arrRet = $objQuery->select("product_id, name", "dtb_products", $where); |
|---|
| 116 | return $arrRet; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | // ¿·µ¬¼õÉÕ°ìÍ÷ |
|---|
| 120 | function lfGetNewOrder() { |
|---|
| 121 | $objQuery = new SC_Query(); |
|---|
| 122 | $col = "ord.order_id, customer_id, (ord.order_name01 || ' ' || ord.order_name02) AS name, ord.total, "; |
|---|
| 123 | $col.= "(SELECT det.product_name FROM dtb_order_detail AS det WHERE ord.order_id = det.order_id LIMIT 1) AS product_name, "; |
|---|
| 124 | $col.= "(SELECT pay.payment_method FROM dtb_payment AS pay WHERE ord.payment_id = pay.payment_id) AS payment_method, "; |
|---|
| 125 | $col.= "to_char(create_date, 'YYYY/MM/DD HH24:MI') AS create_date"; |
|---|
| 126 | $from = "dtb_order AS ord"; |
|---|
| 127 | $where = "delete = 0"; |
|---|
| 128 | $objQuery->setoption("ORDER BY create_date DESC LIMIT 10 OFFSET 0"); |
|---|
| 129 | $arrRet = $objQuery->select($col, $from, $where); |
|---|
| 130 | return $arrRet; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | // ¤ªÃΤ餻¼èÆÀ |
|---|
| 134 | function lfGetInfo() { |
|---|
| 135 | // ¹¹¿·¾ðÊó¤òºÇ¿·¤Ë¤¹¤ë |
|---|
| 136 | $objQuery = new SC_Query(); |
|---|
| 137 | $path = UPDATE_HTTP . "info.txt"; |
|---|
| 138 | $fp = @fopen($path, "rb"); |
|---|
| 139 | |
|---|
| 140 | $arrRet = array(); |
|---|
| 141 | if(!$fp) { |
|---|
| 142 | sfErrorHeader(">> " . $path . "¤Î¼èÆÀ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£"); |
|---|
| 143 | } else { |
|---|
| 144 | while (!feof($fp)) { |
|---|
| 145 | $arrRet[] = $arrCSV = fgetcsv($fp, UPDATE_CSV_LINE_MAX); |
|---|
| 146 | } |
|---|
| 147 | fclose($fp); |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | return $arrRet; |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | ?> |
|---|