Ignore:
Timestamp:
2007/09/04 22:52:02 (17 years ago)
Author:
nanasess
Message:

リファクタリング

  • Page をクラス化
  • 日次バッチをクラス化

:FIXME: グラフ出力を要修正

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/feature-module-update/html/admin/total/index.php

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