| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of EC-CUBE |
|---|
| 4 | * |
|---|
| 5 | * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved. |
|---|
| 6 | * |
|---|
| 7 | * http://www.lockon.co.jp/ |
|---|
| 8 | * |
|---|
| 9 | * This program is free software; you can redistribute it and/or |
|---|
| 10 | * modify it under the terms of the GNU General Public License |
|---|
| 11 | * as published by the Free Software Foundation; either version 2 |
|---|
| 12 | * of the License, or (at your option) any later version. |
|---|
| 13 | * |
|---|
| 14 | * This program is distributed in the hope that it will be useful, |
|---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | * GNU General Public License for more details. |
|---|
| 18 | * |
|---|
| 19 | * You should have received a copy of the GNU General Public License |
|---|
| 20 | * along with this program; if not, write to the Free Software |
|---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | // {{{ requires |
|---|
| 25 | require_once(CLASS_PATH . "pages/LC_Page.php"); |
|---|
| 26 | require_once(CLASS_EX_PATH . "batch_extends/SC_Batch_Daily_Ex.php"); |
|---|
| 27 | require_once(CLASS_PATH . "graph/SC_GraphPie.php"); |
|---|
| 28 | require_once(CLASS_PATH . "graph/SC_GraphLine.php"); |
|---|
| 29 | require_once(CLASS_PATH . "graph/SC_GraphBar.php"); |
|---|
| 30 | |
|---|
| 31 | /** |
|---|
| 32 | * 売上集計 のページクラス. |
|---|
| 33 | * |
|---|
| 34 | * @package Page |
|---|
| 35 | * @author LOCKON CO.,LTD. |
|---|
| 36 | * @version $Id$ |
|---|
| 37 | */ |
|---|
| 38 | class LC_Page_Admin_Total extends LC_Page { |
|---|
| 39 | |
|---|
| 40 | // }}} |
|---|
| 41 | // {{{ functions |
|---|
| 42 | |
|---|
| 43 | /** |
|---|
| 44 | * Page を初期化する. |
|---|
| 45 | * |
|---|
| 46 | * @return void |
|---|
| 47 | */ |
|---|
| 48 | function init() { |
|---|
| 49 | parent::init(); |
|---|
| 50 | // GDライブラリのインストール判定 |
|---|
| 51 | $this->install_GD = function_exists("gd_info") ? true : false; |
|---|
| 52 | $this->tpl_mainpage = 'total/index.tpl'; |
|---|
| 53 | $this->tpl_subnavi = 'total/subnavi.tpl'; |
|---|
| 54 | $this->tpl_graphsubtitle = 'total/subtitle.tpl'; |
|---|
| 55 | $this->tpl_titleimage = URL_DIR.'img/title/title_sale.jpg'; |
|---|
| 56 | $this->tpl_mainno = 'total'; |
|---|
| 57 | |
|---|
| 58 | $masterData = new SC_DB_MasterData_Ex(); |
|---|
| 59 | $this->arrWDAY = $masterData->getMasterData("mtb_wday"); |
|---|
| 60 | $this->arrSex = $masterData->getMasterData("mtb_sex"); |
|---|
| 61 | $this->arrJob = $masterData->getMasterData("mtb_job"); |
|---|
| 62 | // ページタイトル |
|---|
| 63 | $this->arrTitle[''] = "期間別集計"; |
|---|
| 64 | $this->arrTitle['term'] = "期間別集計"; |
|---|
| 65 | $this->arrTitle['products'] = "商品別集計"; |
|---|
| 66 | $this->arrTitle['age'] = "年代別集計"; |
|---|
| 67 | $this->arrTitle['job'] = "職業別集計"; |
|---|
| 68 | $this->arrTitle['member'] = "会員別集計"; |
|---|
| 69 | |
|---|
| 70 | // キャッシュ回避のために日付を渡す |
|---|
| 71 | $this->cashtime = time(); |
|---|
| 72 | $this->objBatch = new SC_Batch_Daily_Ex(); |
|---|
| 73 | |
|---|
| 74 | // TODO エレガントじゃない... |
|---|
| 75 | if (!isset($_POST['search_startyear'])) $_POST['search_startyear'] = ""; |
|---|
| 76 | if (!isset($_POST['search_startmonth'])) $_POST['search_startmonth'] = ""; |
|---|
| 77 | if (!isset($_POST['search_startday'])) $_POST['search_startday'] = ""; |
|---|
| 78 | if (!isset($_POST['search_endyear'])) $_POST['search_endyear'] = ""; |
|---|
| 79 | if (!isset($_POST['search_endmonth'])) $_POST['search_endmonth'] = ""; |
|---|
| 80 | if (!isset($_POST['search_endday'])) $_POST['search_endday'] = ""; |
|---|
| 81 | |
|---|
| 82 | if (!isset($_POST['search_startyear_m'])) $_POST['search_startyear_m'] = ""; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | /** |
|---|
| 86 | * Page のプロセス. |
|---|
| 87 | * |
|---|
| 88 | * @return void |
|---|
| 89 | */ |
|---|
| 90 | function process() { |
|---|
| 91 | $objView = new SC_AdminView(); |
|---|
| 92 | $objSess = new SC_Session(); |
|---|
| 93 | |
|---|
| 94 | // 認証可否の判定 |
|---|
| 95 | SC_Utils_Ex::sfIsSuccess($objSess); |
|---|
| 96 | |
|---|
| 97 | // 入力期間をセッションに記録する |
|---|
| 98 | $this->lfSaveDateSession(); |
|---|
| 99 | |
|---|
| 100 | if(isset($_GET['draw_image']) && $_GET['draw_image'] != ""){ |
|---|
| 101 | define('DRAW_IMAGE' , true); |
|---|
| 102 | }else{ |
|---|
| 103 | define('DRAW_IMAGE' , false); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | // パラメータ管理クラス |
|---|
| 107 | $this->objFormParam = new SC_FormParam(); |
|---|
| 108 | // パラメータ情報の初期化 |
|---|
| 109 | $this->lfInitParam(); |
|---|
| 110 | $this->objFormParam->setParam($_POST); |
|---|
| 111 | $this->objFormParam->setParam($_GET); |
|---|
| 112 | |
|---|
| 113 | // 検索ワードの引き継ぎ |
|---|
| 114 | foreach ($_POST as $key => $val) { |
|---|
| 115 | if (ereg("^search_", $key)) { |
|---|
| 116 | $this->arrHidden[$key] = $val; |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | $mode = $this->objFormParam->getValue('mode'); |
|---|
| 121 | switch($mode) { |
|---|
| 122 | case 'csv': |
|---|
| 123 | case 'search': |
|---|
| 124 | // 入力値の変換 |
|---|
| 125 | $this->objFormParam->convParam(); |
|---|
| 126 | $this->arrErr = $this->lfCheckError(); |
|---|
| 127 | $arrRet = $this->objFormParam->getHashArray(); |
|---|
| 128 | // 入力エラーなし |
|---|
| 129 | if (empty($this->arrErr)) { |
|---|
| 130 | foreach ($arrRet as $key => $val) { |
|---|
| 131 | if($val == "") { |
|---|
| 132 | continue; |
|---|
| 133 | } |
|---|
| 134 | switch ($key) { |
|---|
| 135 | case 'search_startyear': |
|---|
| 136 | $sdate = $this->objFormParam->getValue('search_startyear') . "/" . $this->objFormParam->getValue('search_startmonth') . "/" . $this->objFormParam->getValue('search_startday'); |
|---|
| 137 | break; |
|---|
| 138 | case 'search_endyear': |
|---|
| 139 | $edate = $this->objFormParam->getValue('search_endyear') . "/" . $this->objFormParam->getValue('search_endmonth') . "/" . $this->objFormParam->getValue('search_endday'); |
|---|
| 140 | break; |
|---|
| 141 | case 'search_startyear_m': |
|---|
| 142 | list($sdate, $edate) = SC_Utils_Ex::sfTermMonth($this->objFormParam->getValue('search_startyear_m'), $this->objFormParam->getValue('search_startmonth_m'), CLOSE_DAY); |
|---|
| 143 | break; |
|---|
| 144 | default: |
|---|
| 145 | break; |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| 148 | if($this->objFormParam->getValue('type') != "") { |
|---|
| 149 | $type = $this->objFormParam->getValue('type'); |
|---|
| 150 | } else { |
|---|
| 151 | $type = ""; |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | $page = $this->objFormParam->getValue('page'); |
|---|
| 155 | |
|---|
| 156 | switch($page) { |
|---|
| 157 | // 商品別集計 |
|---|
| 158 | case 'products': |
|---|
| 159 | if($type == "") { |
|---|
| 160 | $type = 'all'; |
|---|
| 161 | } |
|---|
| 162 | $this->tpl_page_type = "total/page_products.tpl"; |
|---|
| 163 | // 未集計データの集計を行う |
|---|
| 164 | if(!DAILY_BATCH_MODE) { |
|---|
| 165 | $this->objBatch->lfRealTimeDailyTotal($sdate, $edate); |
|---|
| 166 | } |
|---|
| 167 | // 検索結果の取得 |
|---|
| 168 | $this->lfGetOrderProducts($type, $sdate, $edate, $this, $this->install_GD, $mode); |
|---|
| 169 | break; |
|---|
| 170 | // 職業別集計 |
|---|
| 171 | case 'job': |
|---|
| 172 | if($type == "") { |
|---|
| 173 | $type = 'all'; |
|---|
| 174 | } |
|---|
| 175 | $this->tpl_page_type = "total/page_job.tpl"; |
|---|
| 176 | // 未集計データの集計を行う |
|---|
| 177 | if(!DAILY_BATCH_MODE) { |
|---|
| 178 | $this->objBatch->lfRealTimeDailyTotal($sdate, $edate); |
|---|
| 179 | } |
|---|
| 180 | // 検索結果の取得 |
|---|
| 181 | $this->lfGetOrderJob($type, $sdate, $edate, $this, $this->install_GD); |
|---|
| 182 | break; |
|---|
| 183 | // 会員別集計 |
|---|
| 184 | case 'member': |
|---|
| 185 | if($type == "") { |
|---|
| 186 | $type = 'all'; |
|---|
| 187 | } |
|---|
| 188 | $this->tpl_page_type = "total/page_member.tpl"; |
|---|
| 189 | // 未集計データの集計を行う |
|---|
| 190 | if(!DAILY_BATCH_MODE) { |
|---|
| 191 | $this->objBatch->lfRealTimeDailyTotal($sdate, $edate); |
|---|
| 192 | } |
|---|
| 193 | // 検索結果の取得 |
|---|
| 194 | $this->lfGetOrderMember($type, $sdate, $edate, $this, $this->install_GD); |
|---|
| 195 | break; |
|---|
| 196 | // 年代別集計 |
|---|
| 197 | case 'age': |
|---|
| 198 | if($type == "") { |
|---|
| 199 | $type = 'all'; |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | $this->tpl_page_type = "total/page_age.tpl"; |
|---|
| 203 | // 未集計データの集計を行う |
|---|
| 204 | if(!DAILY_BATCH_MODE) { |
|---|
| 205 | $this->objBatch->lfRealTimeDailyTotal($sdate, $edate); |
|---|
| 206 | } |
|---|
| 207 | // 検索結果の取得 |
|---|
| 208 | $this->lfGetOrderAge($type, $sdate, $edate, $this, $this->install_GD); |
|---|
| 209 | break; |
|---|
| 210 | // 期間別集計 |
|---|
| 211 | default: |
|---|
| 212 | if (!isset($type)) $type = ""; |
|---|
| 213 | if($type == "") { |
|---|
| 214 | $type = 'day'; |
|---|
| 215 | } |
|---|
| 216 | $this->tpl_page_type = "total/page_term.tpl"; |
|---|
| 217 | // 未集計データの集計を行う |
|---|
| 218 | if(!DAILY_BATCH_MODE) { |
|---|
| 219 | $this->objBatch->lfRealTimeDailyTotal($sdate, $edate); |
|---|
| 220 | } |
|---|
| 221 | // 検索結果の取得 |
|---|
| 222 | $this->lfGetOrderTerm($type, $sdate, $edate, $this, $this->install_GD); |
|---|
| 223 | |
|---|
| 224 | break; |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | if($mode == 'csv') { |
|---|
| 228 | // CSV出力タイトル行の取得 |
|---|
| 229 | list($arrTitleCol, $arrDataCol) = $this->lfGetCSVColum($page, $this->keyname); |
|---|
| 230 | $head = SC_Utils_Ex::sfGetCSVList($arrTitleCol); |
|---|
| 231 | $data = $this->lfGetDataColCSV($this->arrResults, $arrDataCol); |
|---|
| 232 | // CSVを送信する。 |
|---|
| 233 | SC_Utils_Ex::sfCSVDownload($head.$data, $page."_".$type); |
|---|
| 234 | exit; |
|---|
| 235 | } |
|---|
| 236 | } |
|---|
| 237 | break; |
|---|
| 238 | default: |
|---|
| 239 | if(count($_GET) == 0) { |
|---|
| 240 | // バッチモードの場合のみ実行する(当日の集計を行うため) |
|---|
| 241 | if(DAILY_BATCH_MODE) { |
|---|
| 242 | // 3日前までの集計 |
|---|
| 243 | $this->objBatch->lfStartDailyTotal(3,0); |
|---|
| 244 | } |
|---|
| 245 | } |
|---|
| 246 | break; |
|---|
| 247 | } |
|---|
| 248 | |
|---|
| 249 | // 登録・更新日検索用 |
|---|
| 250 | $objDate = new SC_Date(); |
|---|
| 251 | $objDate->setStartYear(RELEASE_YEAR); |
|---|
| 252 | $objDate->setEndYear(DATE("Y")); |
|---|
| 253 | $this->arrYear = $objDate->getYear(); |
|---|
| 254 | $this->arrMonth = $objDate->getMonth(); |
|---|
| 255 | $this->arrDay = $objDate->getDay(); |
|---|
| 256 | // 入力値の取得 |
|---|
| 257 | $this->arrForm = $this->objFormParam->getFormParamList(); |
|---|
| 258 | |
|---|
| 259 | $this->tpl_subtitle = $this->arrTitle[$this->objFormParam->getValue('page')]; |
|---|
| 260 | $objView->assignobj($this); |
|---|
| 261 | $objView->display(MAIN_FRAME); |
|---|
| 262 | } |
|---|
| 263 | |
|---|
| 264 | /** |
|---|
| 265 | * デストラクタ. |
|---|
| 266 | * |
|---|
| 267 | * @return void |
|---|
| 268 | */ |
|---|
| 269 | function destroy() { |
|---|
| 270 | parent::destroy(); |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | /* セッションに入力期間を記録する */ |
|---|
| 274 | function lfSaveDateSession() { |
|---|
| 275 | if (!isset($_POST['form'])) $_POST['form'] = ""; |
|---|
| 276 | |
|---|
| 277 | if($_POST['form'] == 1) { |
|---|
| 278 | $_SESSION['total']['startyear_m'] = $_POST['search_startyear_m']; |
|---|
| 279 | $_SESSION['total']['startmonth_m'] = $_POST['search_startmonth_m']; |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | if($_POST['form'] == 2) { |
|---|
| 283 | $_SESSION['total']['startyear'] = $_POST['search_startyear']; |
|---|
| 284 | $_SESSION['total']['startmonth'] = $_POST['search_startmonth']; |
|---|
| 285 | $_SESSION['total']['startday'] = $_POST['search_startday']; |
|---|
| 286 | $_SESSION['total']['endyear'] = $_POST['search_endyear']; |
|---|
| 287 | $_SESSION['total']['endmonth'] = $_POST['search_endmonth']; |
|---|
| 288 | $_SESSION['total']['endday'] = $_POST['search_endday']; |
|---|
| 289 | } |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | /* デフォルト値の取得 */ |
|---|
| 293 | function lfGetDateDefault() { |
|---|
| 294 | $year = date("Y"); |
|---|
| 295 | $month = date("m"); |
|---|
| 296 | $day = date("d"); |
|---|
| 297 | |
|---|
| 298 | $list = isset($_SESSION['total']) ? $_SESSION['total'] : ""; |
|---|
| 299 | |
|---|
| 300 | // セッション情報に開始月度が保存されていない。 |
|---|
| 301 | if(empty($_SESSION['total']['startyear_m'])) { |
|---|
| 302 | $list['startyear_m'] = $year; |
|---|
| 303 | $list['startmonth_m'] = $month; |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | // セッション情報に開始日付、終了日付が保存されていない。 |
|---|
| 307 | if(empty($_SESSION['total']['startyear']) && empty($_SESSION['total']['endyear'])) { |
|---|
| 308 | $list['startyear'] = $year; |
|---|
| 309 | $list['startmonth'] = $month; |
|---|
| 310 | $list['startday'] = $day; |
|---|
| 311 | $list['endyear'] = $year; |
|---|
| 312 | $list['endmonth'] = $month; |
|---|
| 313 | $list['endday'] = $day; |
|---|
| 314 | } |
|---|
| 315 | |
|---|
| 316 | return $list; |
|---|
| 317 | } |
|---|
| 318 | |
|---|
| 319 | /* パラメータ情報の初期化 */ |
|---|
| 320 | function lfInitParam() { |
|---|
| 321 | // デフォルト値の取得 |
|---|
| 322 | $arrList = $this->lfGetDateDefault(); |
|---|
| 323 | |
|---|
| 324 | // 月度集計 |
|---|
| 325 | $this->objFormParam->addParam("月度", "search_startyear_m", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startyear_m']); |
|---|
| 326 | $this->objFormParam->addParam("月度", "search_startmonth_m", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startmonth_m']); |
|---|
| 327 | // 期間集計 |
|---|
| 328 | $this->objFormParam->addParam("開始日", "search_startyear", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startyear']); |
|---|
| 329 | $this->objFormParam->addParam("開始日", "search_startmonth", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startmonth']); |
|---|
| 330 | $this->objFormParam->addParam("開始日", "search_startday", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startday']); |
|---|
| 331 | $this->objFormParam->addParam("終了日", "search_endyear", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['endyear']); |
|---|
| 332 | $this->objFormParam->addParam("終了日", "search_endmonth", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['endmonth']); |
|---|
| 333 | $this->objFormParam->addParam("終了日", "search_endday", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['endday']); |
|---|
| 334 | |
|---|
| 335 | // hiddenデータの取得用 |
|---|
| 336 | $this->objFormParam->addParam("", "page"); |
|---|
| 337 | $this->objFormParam->addParam("", "type"); |
|---|
| 338 | $this->objFormParam->addParam("", "mode"); |
|---|
| 339 | |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | /* 入力内容のチェック */ |
|---|
| 343 | function lfCheckError() { |
|---|
| 344 | // 入力データを渡す。 |
|---|
| 345 | $arrRet = $this->objFormParam->getHashArray(); |
|---|
| 346 | $objErr = new SC_CheckError($arrRet); |
|---|
| 347 | $objErr->arrErr = $this->objFormParam->checkError(); |
|---|
| 348 | |
|---|
| 349 | // 特殊項目チェック |
|---|
| 350 | if($_POST['form'] == 1) { |
|---|
| 351 | $objErr->doFunc(array("月度", "search_startyear_m"), array("ONE_EXIST_CHECK")); |
|---|
| 352 | } |
|---|
| 353 | |
|---|
| 354 | if($_POST['form'] == 2) { |
|---|
| 355 | $objErr->doFunc(array("期間", "search_startyear", "search_endyear"), array("ONE_EXIST_CHECK")); |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | $objErr->doFunc(array("月度", "search_startyear_m", "search_startmonth_m"), array("ALL_EXIST_CHECK")); |
|---|
| 359 | $objErr->doFunc(array("開始日", "search_startyear", "search_startmonth", "search_startday"), array("CHECK_DATE")); |
|---|
| 360 | $objErr->doFunc(array("終了日", "search_endyear", "search_endmonth", "search_endday"), array("CHECK_DATE")); |
|---|
| 361 | $objErr->doFunc(array("開始日", "終了日", "search_startyear", "search_startmonth", "search_startday", "search_endyear", "search_endmonth", "search_endday"), array("CHECK_SET_TERM")); |
|---|
| 362 | return $objErr->arrErr; |
|---|
| 363 | } |
|---|
| 364 | |
|---|
| 365 | /* 折れ線グラフの作成 */ |
|---|
| 366 | function lfGetGraphLine($arrResults, $keyname, $type, $xtitle, $ytitle, $sdate, $edate) { |
|---|
| 367 | |
|---|
| 368 | $ret_path = ""; |
|---|
| 369 | |
|---|
| 370 | // 結果が0行以上ある場合のみグラフを生成する。 |
|---|
| 371 | if(count($arrResults) > 0) { |
|---|
| 372 | |
|---|
| 373 | // グラフの生成 |
|---|
| 374 | $arrList = SC_Utils_Ex::sfArrKeyValue($arrResults, $keyname, "total"); |
|---|
| 375 | |
|---|
| 376 | // 一時ファイル名の取得 |
|---|
| 377 | $pngname = $this->lfGetGraphPng($type); |
|---|
| 378 | |
|---|
| 379 | $path = GRAPH_DIR . $pngname; |
|---|
| 380 | |
|---|
| 381 | // ラベル表示インターバルを求める |
|---|
| 382 | $interval = intval(count($arrList) / 20); |
|---|
| 383 | if($interval < 1) { |
|---|
| 384 | $interval = 1; |
|---|
| 385 | } |
|---|
| 386 | $objGraphLine = new SC_GraphLine(); |
|---|
| 387 | |
|---|
| 388 | // 値のセット |
|---|
| 389 | $objGraphLine->setData($arrList); |
|---|
| 390 | $objGraphLine->setXLabel(array_keys($arrList)); |
|---|
| 391 | |
|---|
| 392 | // ラベル回転(日本語不可) |
|---|
| 393 | if($keyname == "key_day"){ |
|---|
| 394 | $objGraphLine->setXLabelAngle(45); |
|---|
| 395 | } |
|---|
| 396 | |
|---|
| 397 | // タイトルセット |
|---|
| 398 | $objGraphLine->setXTitle($xtitle); |
|---|
| 399 | $objGraphLine->setYTitle($ytitle); |
|---|
| 400 | |
|---|
| 401 | // メインタイトル作成 |
|---|
| 402 | list($sy, $sm, $sd) = split("[/ ]" , $sdate); |
|---|
| 403 | list($ey, $em, $ed) = split("[/ ]" , $edate); |
|---|
| 404 | $start_date = $sy . "年" . $sm . "月" . $sd . "日"; |
|---|
| 405 | $end_date = $ey . "年" . $em . "月" . $ed . "日"; |
|---|
| 406 | $objGraphLine->drawTitle("集計期間:" . $start_date . " - " . $end_date); |
|---|
| 407 | |
|---|
| 408 | // グラフ描画 |
|---|
| 409 | $objGraphLine->drawGraph(); |
|---|
| 410 | |
|---|
| 411 | // グラフの出力 |
|---|
| 412 | if(DRAW_IMAGE){ |
|---|
| 413 | $objGraphLine->outputGraph(); |
|---|
| 414 | exit(); |
|---|
| 415 | } |
|---|
| 416 | |
|---|
| 417 | // ファイルパスを返す |
|---|
| 418 | $ret_path = GRAPH_URL . $pngname; |
|---|
| 419 | } |
|---|
| 420 | return $ret_path; |
|---|
| 421 | } |
|---|
| 422 | |
|---|
| 423 | // 円グラフの作成 |
|---|
| 424 | function lfGetGraphPie($arrResults, $keyname, $type, $title = "", $sdate = "", $edate = "") { |
|---|
| 425 | |
|---|
| 426 | $ret_path = ""; |
|---|
| 427 | // 結果が0行以上ある場合のみグラフを生成する。 |
|---|
| 428 | if(count($arrResults) > 0) { |
|---|
| 429 | // グラフの生成 |
|---|
| 430 | $arrList = SC_Utils_Ex::sfArrKeyValue($arrResults, $keyname, |
|---|
| 431 | "total", GRAPH_PIE_MAX, |
|---|
| 432 | GRAPH_LABEL_MAX); |
|---|
| 433 | |
|---|
| 434 | // 一時ファイル名の取得 |
|---|
| 435 | $pngname = $this->lfGetGraphPng($type); |
|---|
| 436 | $path = GRAPH_DIR . $pngname; |
|---|
| 437 | |
|---|
| 438 | $objGraphPie = new SC_GraphPie(); |
|---|
| 439 | |
|---|
| 440 | /* デバッグ表示用 by naka |
|---|
| 441 | foreach($arrList as $key => $val) { |
|---|
| 442 | $objGraphPie->debugPrint("key:$key val:$val"); |
|---|
| 443 | } |
|---|
| 444 | */ |
|---|
| 445 | |
|---|
| 446 | // データをセットする |
|---|
| 447 | $objGraphPie->setData($arrList); |
|---|
| 448 | // 凡例をセットする |
|---|
| 449 | $objGraphPie->setLegend(array_keys($arrList)); |
|---|
| 450 | |
|---|
| 451 | // メインタイトル作成 |
|---|
| 452 | list($sy, $sm, $sd) = split("[/ ]" , $sdate); |
|---|
| 453 | list($ey, $em, $ed) = split("[/ ]" , $edate); |
|---|
| 454 | $start_date = $sy . "年" . $sm . "月" . $sd . "日"; |
|---|
| 455 | $end_date = $ey . "年" . $em . "月" . $ed . "日"; |
|---|
| 456 | $objGraphPie->drawTitle("集計期間:" . $start_date . " - " . $end_date); |
|---|
| 457 | |
|---|
| 458 | // 円グラフ描画 |
|---|
| 459 | $objGraphPie->drawGraph(); |
|---|
| 460 | |
|---|
| 461 | // グラフの出力 |
|---|
| 462 | if(DRAW_IMAGE){ |
|---|
| 463 | $objGraphPie->outputGraph(); |
|---|
| 464 | exit(); |
|---|
| 465 | } |
|---|
| 466 | |
|---|
| 467 | // ファイルパスを返す |
|---|
| 468 | $ret_path = GRAPH_URL . $pngname; |
|---|
| 469 | } |
|---|
| 470 | return $ret_path; |
|---|
| 471 | } |
|---|
| 472 | |
|---|
| 473 | // 棒グラフの作成 |
|---|
| 474 | function lfGetGraphBar($arrResults, $keyname, $type, $xtitle, $ytitle, $sdate, $edate) { |
|---|
| 475 | $ret_path = ""; |
|---|
| 476 | |
|---|
| 477 | // 結果が0行以上ある場合のみグラフを生成する。 |
|---|
| 478 | if(count($arrResults) > 0) { |
|---|
| 479 | // グラフの生成 |
|---|
| 480 | $arrList = SC_Utils_Ex::sfArrKeyValue($arrResults, $keyname, "total", GRAPH_PIE_MAX, GRAPH_LABEL_MAX); |
|---|
| 481 | |
|---|
| 482 | // 一時ファイル名の取得 |
|---|
| 483 | $pngname = $this->lfGetGraphPng($type); |
|---|
| 484 | $path = GRAPH_DIR . $pngname; |
|---|
| 485 | |
|---|
| 486 | $objGraphBar = new SC_GraphBar(); |
|---|
| 487 | |
|---|
| 488 | foreach(array_keys($arrList) as $val) { |
|---|
| 489 | $arrKey[] = ereg_replace("~", "-", $val); |
|---|
| 490 | } |
|---|
| 491 | |
|---|
| 492 | // グラフ描画 |
|---|
| 493 | $objGraphBar->setXLabel($arrKey); |
|---|
| 494 | $objGraphBar->setXTitle($xtitle); |
|---|
| 495 | $objGraphBar->setYTitle($ytitle); |
|---|
| 496 | $objGraphBar->setData($arrList); |
|---|
| 497 | |
|---|
| 498 | // メインタイトル作成 |
|---|
| 499 | $arrKey = array_keys($arrList); |
|---|
| 500 | list($sy, $sm, $sd) = split("[/ ]" , $sdate); |
|---|
| 501 | list($ey, $em, $ed) = split("[/ ]" , $edate); |
|---|
| 502 | $start_date = $sy . "年" . $sm . "月" . $sd . "日"; |
|---|
| 503 | $end_date = $ey . "年" . $em . "月" . $ed . "日"; |
|---|
| 504 | $objGraphBar->drawTitle("集計期間:" . $start_date . " - " . $end_date); |
|---|
| 505 | |
|---|
| 506 | $objGraphBar->drawGraph(); |
|---|
| 507 | |
|---|
| 508 | if(DRAW_IMAGE){ |
|---|
| 509 | $objGraphBar->outputGraph(); |
|---|
| 510 | exit(); |
|---|
| 511 | } |
|---|
| 512 | |
|---|
| 513 | // ファイルパスを返す |
|---|
| 514 | $ret_path = GRAPH_URL . $pngname; |
|---|
| 515 | } |
|---|
| 516 | return $ret_path; |
|---|
| 517 | } |
|---|
| 518 | |
|---|
| 519 | // グラフ用のPNGファイル名 |
|---|
| 520 | function lfGetGraphPng($keyname) { |
|---|
| 521 | |
|---|
| 522 | if($_POST['search_startyear_m'] != "") { |
|---|
| 523 | $pngname = sprintf("%s_%02d%02d.png", $keyname, substr($_POST['search_startyear_m'],2), $_POST['search_startmonth_m']); |
|---|
| 524 | } else { |
|---|
| 525 | $pngname = sprintf("%s_%02d%02d%02d_%02d%02d%02d.png", $keyname, substr($_POST['search_startyear'], 2), $_POST['search_startmonth'], $_POST['search_startday'], substr($_POST['search_endyear'],2), $_POST['search_endmonth'], $_POST['search_endday']); |
|---|
| 526 | } |
|---|
| 527 | return $pngname; |
|---|
| 528 | } |
|---|
| 529 | |
|---|
| 530 | // 会員、非会員集計のWHERE分の作成 |
|---|
| 531 | function lfGetWhereMember($col_date, $sdate, $edate, $type, $col_member = "customer_id") { |
|---|
| 532 | $where = ""; |
|---|
| 533 | // 取得日付の指定 |
|---|
| 534 | if($sdate != "") { |
|---|
| 535 | if ($where != "") { |
|---|
| 536 | $where.= " AND "; |
|---|
| 537 | } |
|---|
| 538 | $where.= " $col_date >= '". $sdate ."'"; |
|---|
| 539 | } |
|---|
| 540 | |
|---|
| 541 | if($edate != "") { |
|---|
| 542 | if ($where != "") { |
|---|
| 543 | $where.= " AND "; |
|---|
| 544 | } |
|---|
| 545 | $edate = date("Y/m/d",strtotime("1 day" ,strtotime($edate))); |
|---|
| 546 | $where.= " $col_date < date('" . $edate ."')"; |
|---|
| 547 | } |
|---|
| 548 | |
|---|
| 549 | // 会員、非会員の判定 |
|---|
| 550 | switch($type) { |
|---|
| 551 | // 全体 |
|---|
| 552 | case 'all': |
|---|
| 553 | break; |
|---|
| 554 | case 'member': |
|---|
| 555 | if ($where != "") { |
|---|
| 556 | $where.= " AND "; |
|---|
| 557 | } |
|---|
| 558 | $where.= " $col_member <> 0"; |
|---|
| 559 | break; |
|---|
| 560 | case 'nonmember': |
|---|
| 561 | if ($where != "") { |
|---|
| 562 | $where.= " AND "; |
|---|
| 563 | } |
|---|
| 564 | $where.= " $col_member = 0"; |
|---|
| 565 | break; |
|---|
| 566 | default: |
|---|
| 567 | break; |
|---|
| 568 | } |
|---|
| 569 | |
|---|
| 570 | return array($where, array()); |
|---|
| 571 | } |
|---|
| 572 | |
|---|
| 573 | /** 会員別集計 **/ |
|---|
| 574 | function lfGetOrderMember($type, $sdate, $edate, &$objPage, $graph = true) { |
|---|
| 575 | list($where, $arrval) = $this->lfGetWhereMember('create_date', $sdate, $edate, $type); |
|---|
| 576 | |
|---|
| 577 | // 会員集計の取得 |
|---|
| 578 | $col = "COUNT(*) AS order_count, SUM(total) AS total, trunc(AVG(total),0) AS total_average, order_sex"; |
|---|
| 579 | $from = "dtb_order"; |
|---|
| 580 | $objQuery = new SC_Query(); |
|---|
| 581 | $objQuery->setGroupBy("order_sex"); |
|---|
| 582 | |
|---|
| 583 | $tmp_where = $where . " AND customer_id <> 0 AND del_flg = 0 AND status <> " . ORDER_CANCEL; |
|---|
| 584 | $arrRet = $objQuery->select($col, $from, $tmp_where, $arrval); |
|---|
| 585 | |
|---|
| 586 | // 会員購入であることを記録する。 |
|---|
| 587 | $max = count($arrRet); |
|---|
| 588 | for($i = 0; $i < $max; $i++) { |
|---|
| 589 | $arrRet[$i]['member_name'] = '会員'.$this->arrSex[$arrRet[$i]['order_sex']]; |
|---|
| 590 | } |
|---|
| 591 | $objPage->arrResults = $arrRet; |
|---|
| 592 | |
|---|
| 593 | // 非会員集計の取得 |
|---|
| 594 | $tmp_where = $where . " AND customer_id = 0 AND del_flg = 0 AND status <> " . ORDER_CANCEL; |
|---|
| 595 | $arrRet = $objQuery->select($col, $from, $tmp_where, $arrval); |
|---|
| 596 | // 非会員購入であることを記録する。 |
|---|
| 597 | $max = count($arrRet); |
|---|
| 598 | for($i = 0; $i < $max; $i++) { |
|---|
| 599 | $arrRet[$i]['member_name'] = '非会員'.$this->arrSex[$arrRet[$i]['order_sex']]; |
|---|
| 600 | } |
|---|
| 601 | |
|---|
| 602 | $objPage->arrResults = array_merge($objPage->arrResults, $arrRet); |
|---|
| 603 | |
|---|
| 604 | // 円グラフの生成 |
|---|
| 605 | if($graph) { |
|---|
| 606 | $image_key = "member"; |
|---|
| 607 | $objPage->tpl_image = $this->lfGetGraphPie($objPage->arrResults, "member_name", $image_key, "(売上比率)", $sdate, $edate); |
|---|
| 608 | } |
|---|
| 609 | } |
|---|
| 610 | |
|---|
| 611 | /** 商品別集計 **/ |
|---|
| 612 | function lfGetOrderProducts($type, $sdate, $edate, &$objPage, $graph = true, $mode = "") { |
|---|
| 613 | list($where, $arrval) = $this->lfGetWhereMember('create_date', $sdate, $edate, $type); |
|---|
| 614 | |
|---|
| 615 | $where .= " and del_flg=0 and status <> " . ORDER_CANCEL; |
|---|
| 616 | |
|---|
| 617 | $sql = "SELECT T1.product_id, T1.product_code, T1.product_name, T1.products_count, T1.order_count, T1.price, T1.total "; |
|---|
| 618 | $sql.= "FROM ( "; |
|---|
| 619 | $sql.= "SELECT product_id, product_name, product_code, price, "; |
|---|
| 620 | $sql.= "COUNT(*) AS order_count, "; |
|---|
| 621 | $sql.= "SUM(quantity) AS products_count, "; |
|---|
| 622 | $sql.= "(price * sum(quantity)) AS total "; |
|---|
| 623 | $sql.= "FROM dtb_order_detail AS T2 WHERE EXISTS (SELECT 1 FROM dtb_order AS T3 WHERE T2.order_id = T3.order_id AND $where ) "; |
|---|
| 624 | $sql.= "GROUP BY product_id, product_name, product_code, price "; |
|---|
| 625 | $sql.= ") AS T1 "; |
|---|
| 626 | $sql.= "ORDER BY T1.total DESC "; |
|---|
| 627 | |
|---|
| 628 | if($mode != "csv") { |
|---|
| 629 | $sql.= "LIMIT " . PRODUCTS_TOTAL_MAX; |
|---|
| 630 | } |
|---|
| 631 | |
|---|
| 632 | $objQuery = new SC_Query(); |
|---|
| 633 | $objPage->arrResults = $objQuery->getAll($sql, $arrval); |
|---|
| 634 | |
|---|
| 635 | // 円グラフの生成 |
|---|
| 636 | if($graph) { |
|---|
| 637 | $image_key = "products_" . $type; |
|---|
| 638 | $objPage->tpl_image = $this->lfGetGraphPie($objPage->arrResults, "product_name", $image_key, "(売上比率)", $sdate, $edate); |
|---|
| 639 | } |
|---|
| 640 | } |
|---|
| 641 | |
|---|
| 642 | /** 職業別集計 **/ |
|---|
| 643 | function lfGetOrderJob($type, $sdate, $edate, &$objPage, $graph = true) { |
|---|
| 644 | list($where, $arrval) = $this->lfGetWhereMember('T2.create_date', $sdate, $edate, $type); |
|---|
| 645 | |
|---|
| 646 | $sql = "SELECT job, count(*) AS order_count, SUM(total) AS total, trunc(AVG(total),0) AS total_average "; |
|---|
| 647 | $sql.= "FROM dtb_customer AS T1 LEFT JOIN dtb_order AS T2 USING ( customer_id ) WHERE $where AND T2.del_flg = 0 and T2.status <> " . ORDER_CANCEL; |
|---|
| 648 | $sql.= " GROUP BY job ORDER BY total DESC"; |
|---|
| 649 | |
|---|
| 650 | $objQuery = new SC_Query(); |
|---|
| 651 | $objPage->arrResults = $objQuery->getAll($sql, $arrval); |
|---|
| 652 | |
|---|
| 653 | $max = count($objPage->arrResults); |
|---|
| 654 | for($i = 0; $i < $max; $i++) { |
|---|
| 655 | $job_key = $objPage->arrResults[$i]['job']; |
|---|
| 656 | if($job_key != "") { |
|---|
| 657 | $objPage->arrResults[$i]['job_name'] = $this->arrJob[$job_key]; |
|---|
| 658 | } else { |
|---|
| 659 | $objPage->arrResults[$i]['job_name'] = "未回答"; |
|---|
| 660 | } |
|---|
| 661 | } |
|---|
| 662 | |
|---|
| 663 | // 円グラフの生成 |
|---|
| 664 | if($graph) { |
|---|
| 665 | $image_key = "job_" . $type; |
|---|
| 666 | $objPage->tpl_image = $this->lfGetGraphPie($objPage->arrResults, "job_name", $image_key, "(売上比率)", $sdate, $edate); |
|---|
| 667 | } |
|---|
| 668 | } |
|---|
| 669 | |
|---|
| 670 | /** 年代別集計 **/ |
|---|
| 671 | function lfGetOrderAge($type, $sdate, $edate, &$objPage, $graph = true) { |
|---|
| 672 | |
|---|
| 673 | list($where, $arrval) = $this->lfGetWhereMember('order_date', $sdate, $edate, $type, "member"); |
|---|
| 674 | |
|---|
| 675 | $sql = "SELECT SUM(order_count) AS order_count, SUM(total) AS total, start_age, end_age "; |
|---|
| 676 | $sql.= "FROM dtb_bat_order_daily_age WHERE $where "; |
|---|
| 677 | $sql.= "GROUP BY start_age, end_age ORDER BY start_age, end_age"; |
|---|
| 678 | |
|---|
| 679 | $objQuery = new SC_Query(); |
|---|
| 680 | $objPage->arrResults = $objQuery->getAll($sql, $arrval); |
|---|
| 681 | |
|---|
| 682 | $max = count($objPage->arrResults); |
|---|
| 683 | for($i = 0; $i < $max; $i++) { |
|---|
| 684 | if($objPage->arrResults[$i]['order_count'] > 0) { |
|---|
| 685 | $objPage->arrResults[$i]['total_average'] = intval($objPage->arrResults[$i]['total'] / $objPage->arrResults[$i]['order_count']); |
|---|
| 686 | } |
|---|
| 687 | $start_age = $objPage->arrResults[$i]['start_age']; |
|---|
| 688 | $end_age = $objPage->arrResults[$i]['end_age']; |
|---|
| 689 | if($start_age != "" || $end_age != "") { |
|---|
| 690 | if($end_age != 999) { |
|---|
| 691 | $objPage->arrResults[$i]['age_name'] = $start_age . "~" . $end_age . "歳"; |
|---|
| 692 | } else { |
|---|
| 693 | $objPage->arrResults[$i]['age_name'] = $start_age . "歳~"; |
|---|
| 694 | } |
|---|
| 695 | } else { |
|---|
| 696 | $objPage->arrResults[$i]['age_name'] = "未回答"; |
|---|
| 697 | } |
|---|
| 698 | } |
|---|
| 699 | |
|---|
| 700 | // 棒グラフの生成 |
|---|
| 701 | if($graph) { |
|---|
| 702 | $image_key = "age_" . $type; |
|---|
| 703 | $xtitle = "(年齢)"; |
|---|
| 704 | $ytitle = "(売上合計)"; |
|---|
| 705 | $objPage->tpl_image = $this->lfGetGraphBar($objPage->arrResults, "age_name", $image_key, $xtitle, $ytitle, $sdate, $edate); |
|---|
| 706 | } |
|---|
| 707 | } |
|---|
| 708 | |
|---|
| 709 | /** 期間別集計 **/ |
|---|
| 710 | function lfGetOrderTerm($type, $sdate, $edate, &$objPage, $graph = true) { |
|---|
| 711 | |
|---|
| 712 | $tmp_col = "sum(total_order) as total_order, sum(men) as men, sum(women) as women,"; |
|---|
| 713 | $tmp_col.= "sum(men_member) as men_member, sum(men_nonmember) as men_nonmember,"; |
|---|
| 714 | $tmp_col.= "sum(women_member) as women_member, sum(women_nonmember) as women_nonmember,"; |
|---|
| 715 | $tmp_col.= "sum(total) as total, (avg(total_average)) as total_average"; |
|---|
| 716 | $objQuery = new SC_Query(); |
|---|
| 717 | |
|---|
| 718 | switch($type) { |
|---|
| 719 | // 月別 |
|---|
| 720 | case 'month': |
|---|
| 721 | $col = $tmp_col . ",key_month"; |
|---|
| 722 | $objQuery->setGroupBy("key_month"); |
|---|
| 723 | $objQuery->setOrder("key_month"); |
|---|
| 724 | $objPage->keyname = "key_month"; |
|---|
| 725 | $objPage->tpl_tail = "月"; |
|---|
| 726 | $from = "dtb_bat_order_daily"; |
|---|
| 727 | $xtitle = "(月別)"; |
|---|
| 728 | $ytitle = "(売上合計)"; |
|---|
| 729 | break; |
|---|
| 730 | // 年別 |
|---|
| 731 | case 'year': |
|---|
| 732 | $col = $tmp_col . ",key_year"; |
|---|
| 733 | $objQuery->setGroupBy("key_year"); |
|---|
| 734 | $objQuery->setOrder("key_year"); |
|---|
| 735 | $objPage->keyname = "key_year"; |
|---|
| 736 | $objPage->tpl_tail = "年"; |
|---|
| 737 | $from = "dtb_bat_order_daily"; |
|---|
| 738 | $xtitle = "(年別)"; |
|---|
| 739 | $ytitle = "(売上合計)"; |
|---|
| 740 | break; |
|---|
| 741 | // 曜日別 |
|---|
| 742 | case 'wday': |
|---|
| 743 | $col = $tmp_col . ",key_wday, wday"; |
|---|
| 744 | $objQuery->setGroupBy("key_wday, wday"); |
|---|
| 745 | $objQuery->setOrder("wday"); |
|---|
| 746 | $objPage->keyname = "key_wday"; |
|---|
| 747 | $objPage->tpl_tail = "曜日"; |
|---|
| 748 | $from = "dtb_bat_order_daily"; |
|---|
| 749 | $xtitle = "(曜日別)"; |
|---|
| 750 | $ytitle = "(売上合計)"; |
|---|
| 751 | break; |
|---|
| 752 | // 時間別 |
|---|
| 753 | case 'hour': |
|---|
| 754 | $col = $tmp_col . ",hour"; |
|---|
| 755 | $objQuery->setGroupBy("hour"); |
|---|
| 756 | $objQuery->setOrder("hour"); |
|---|
| 757 | $objPage->keyname = "hour"; |
|---|
| 758 | $objPage->tpl_tail = "時"; |
|---|
| 759 | $from = "dtb_bat_order_daily_hour"; |
|---|
| 760 | $xtitle = "(時間別)"; |
|---|
| 761 | $ytitle = "(売上合計)"; |
|---|
| 762 | break; |
|---|
| 763 | default: |
|---|
| 764 | $col = "*"; |
|---|
| 765 | $objQuery->setOrder("key_day"); |
|---|
| 766 | $objPage->keyname = "key_day"; |
|---|
| 767 | $from = "dtb_bat_order_daily"; |
|---|
| 768 | $xtitle = "(日別)"; |
|---|
| 769 | $ytitle = "(売上合計)"; |
|---|
| 770 | break; |
|---|
| 771 | } |
|---|
| 772 | |
|---|
| 773 | if (!isset($where)) $where = ""; |
|---|
| 774 | |
|---|
| 775 | // 取得日付の指定 |
|---|
| 776 | if($sdate != "") { |
|---|
| 777 | if ($where != "") { |
|---|
| 778 | $where.= " AND "; |
|---|
| 779 | } |
|---|
| 780 | $where.= " order_date >= '". $sdate ."'"; |
|---|
| 781 | } |
|---|
| 782 | |
|---|
| 783 | if($edate != "") { |
|---|
| 784 | if ($where != "") { |
|---|
| 785 | $where.= " AND "; |
|---|
| 786 | } |
|---|
| 787 | $edate_next = date("Y/m/d",strtotime("1 day" ,strtotime($edate))); |
|---|
| 788 | $where.= " order_date < date('" . $edate_next ."')"; |
|---|
| 789 | } |
|---|
| 790 | |
|---|
| 791 | if (!isset($arrval)) $arrval = array(); |
|---|
| 792 | |
|---|
| 793 | // 検索結果の取得 |
|---|
| 794 | $objPage->arrResults = $objQuery->select($col, $from, $where, $arrval); |
|---|
| 795 | |
|---|
| 796 | // 折れ線グラフの生成 |
|---|
| 797 | if($graph) { |
|---|
| 798 | $image_key = "term_" . $type; |
|---|
| 799 | $objPage->tpl_image = $this->lfGetGraphLine($objPage->arrResults, $objPage->keyname, $image_key, $xtitle, $ytitle, $sdate, $edate); |
|---|
| 800 | } |
|---|
| 801 | |
|---|
| 802 | // 検索結果が0でない場合 |
|---|
| 803 | if(count($objPage->arrResults) > 0) { |
|---|
| 804 | // 最終集計行取得する |
|---|
| 805 | $col = $tmp_col; |
|---|
| 806 | $objQuery = new SC_Query(); |
|---|
| 807 | $arrRet = $objQuery->select($col, $from, $where, $arrval); |
|---|
| 808 | $arrRet[0][$objPage->keyname] = "合計"; |
|---|
| 809 | $objPage->arrResults[] = $arrRet[0]; |
|---|
| 810 | } |
|---|
| 811 | |
|---|
| 812 | // 平均値の計算 |
|---|
| 813 | $max = count($objPage->arrResults); |
|---|
| 814 | for($i = 0; $i < $max; $i++) { |
|---|
| 815 | if($objPage->arrResults[$i]['total_order'] > 0) { |
|---|
| 816 | $objPage->arrResults[$i]['total_average'] = intval($objPage->arrResults[$i]['total'] / $objPage->arrResults[$i]['total_order']); |
|---|
| 817 | } |
|---|
| 818 | } |
|---|
| 819 | } |
|---|
| 820 | |
|---|
| 821 | // 必要なカラムのみ抽出する(CSVデータで取得する) |
|---|
| 822 | function lfGetDataColCSV($arrData, $arrDataCol) { |
|---|
| 823 | $max = count($arrData); |
|---|
| 824 | $csv_data = ""; |
|---|
| 825 | for($i = 0; $i < $max; $i++) { |
|---|
| 826 | foreach($arrDataCol as $val) { |
|---|
| 827 | $arrRet[$i][$val] = $arrData[$i][$val]; |
|---|
| 828 | } |
|---|
| 829 | $csv_data.= SC_Utils_Ex::sfGetCSVList($arrRet[$i]); |
|---|
| 830 | } |
|---|
| 831 | return $csv_data; |
|---|
| 832 | } |
|---|
| 833 | |
|---|
| 834 | function lfGetCSVColum($page, $key = "") { |
|---|
| 835 | switch($page) { |
|---|
| 836 | // 商品別集計 |
|---|
| 837 | case 'products': |
|---|
| 838 | $arrTitleCol = array( |
|---|
| 839 | '商品コード', |
|---|
| 840 | '商品名', |
|---|
| 841 | '購入件数', |
|---|
| 842 | '点数', |
|---|
| 843 | '単価', |
|---|
| 844 | '金額' |
|---|
| 845 | ); |
|---|
| 846 | $arrDataCol = array( |
|---|
| 847 | 'product_code', |
|---|
| 848 | 'product_name', |
|---|
| 849 | 'order_count', |
|---|
| 850 | 'products_count', |
|---|
| 851 | 'price', |
|---|
| 852 | 'total', |
|---|
| 853 | ); |
|---|
| 854 | break; |
|---|
| 855 | // 職業別集計 |
|---|
| 856 | case 'job': |
|---|
| 857 | $arrTitleCol = array( |
|---|
| 858 | '職業', |
|---|
| 859 | '購入件数', |
|---|
| 860 | '購入合計', |
|---|
| 861 | '購入平均', |
|---|
| 862 | ); |
|---|
| 863 | $arrDataCol = array( |
|---|
| 864 | 'job_name', |
|---|
| 865 | 'order_count', |
|---|
| 866 | 'total', |
|---|
| 867 | 'total_average', |
|---|
| 868 | ); |
|---|
| 869 | break; |
|---|
| 870 | // 会員別集計 |
|---|
| 871 | case 'member': |
|---|
| 872 | $arrTitleCol = array( |
|---|
| 873 | '会員', |
|---|
| 874 | '購入件数', |
|---|
| 875 | '購入合計', |
|---|
| 876 | '購入平均', |
|---|
| 877 | ); |
|---|
| 878 | $arrDataCol = array( |
|---|
| 879 | 'member_name', |
|---|
| 880 | 'order_count', |
|---|
| 881 | 'total', |
|---|
| 882 | 'total_average', |
|---|
| 883 | ); |
|---|
| 884 | break; |
|---|
| 885 | // 年代別集計 |
|---|
| 886 | case 'age': |
|---|
| 887 | $arrTitleCol = array( |
|---|
| 888 | '年齢', |
|---|
| 889 | '購入件数', |
|---|
| 890 | '購入合計', |
|---|
| 891 | '購入平均', |
|---|
| 892 | ); |
|---|
| 893 | $arrDataCol = array( |
|---|
| 894 | 'age_name', |
|---|
| 895 | 'order_count', |
|---|
| 896 | 'total', |
|---|
| 897 | 'total_average', |
|---|
| 898 | ); |
|---|
| 899 | break; |
|---|
| 900 | // 期間別集計 |
|---|
| 901 | default: |
|---|
| 902 | $arrTitleCol = array( |
|---|
| 903 | '期間', |
|---|
| 904 | '購入件数', |
|---|
| 905 | '男性', |
|---|
| 906 | '女性', |
|---|
| 907 | '男性(会員)', |
|---|
| 908 | '男性(非会員)', |
|---|
| 909 | '女性(会員)', |
|---|
| 910 | '女性(非会員)', |
|---|
| 911 | '購入合計', |
|---|
| 912 | '購入平均', |
|---|
| 913 | ); |
|---|
| 914 | $arrDataCol = array( |
|---|
| 915 | $key, |
|---|
| 916 | 'total_order', |
|---|
| 917 | 'men', |
|---|
| 918 | 'women', |
|---|
| 919 | 'men_member', |
|---|
| 920 | 'men_nonmember', |
|---|
| 921 | 'women_member', |
|---|
| 922 | 'women_nonmember', |
|---|
| 923 | 'total', |
|---|
| 924 | 'total_average' |
|---|
| 925 | ); |
|---|
| 926 | break; |
|---|
| 927 | } |
|---|
| 928 | |
|---|
| 929 | return array($arrTitleCol, $arrDataCol); |
|---|
| 930 | } |
|---|
| 931 | } |
|---|
| 932 | ?> |
|---|