Source for file SC_Batch_Daily.php
Documentation is available at SC_Batch_Daily.php
* This file is part of EC-CUBE
* Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
* http://www.lockon.co.jp/
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
require_once(CLASS_PATH .
"batch/SC_Batch.php");
* @author LOCKON CO.,LTD.
* @param array $argv コマンドライン用引数.
* @param mixed $argv コマンドライン引数
$start =
1; // 集計期間は、$start~$termの間となる。通常前日分から。
if (SC_Utils_Ex::sfIsInt($argv[1]) &&
$argv[1] <=
365) {
if (SC_Utils_Ex::sfIsInt($argv[2]) &&
$argv[2] <=
365) {
$path =
GRAPH_DIR .
"*.png";
$where =
"order_id IN (SELECT order_id FROM dtb_order WHERE del_flg = 1)";
$objQuery->delete("dtb_order_detail", $where);
$ret =
$objQuery->max("dtb_bat_order_daily", "create_date");
list
($batch_last) =
split("\.", $ret);
// 最後のバッチ実行からLOAD_BATCH_PASS秒経過していないと実行しない。
if($pass <
LOAD_BATCH_PASS) {
GC_Utils_Ex::gfPrintLog("LAST BATCH " .
$arrRet[0]['create_date'] .
" > " .
$batch_pass .
" -> EXIT BATCH $batch_date");
for ($i =
$start; $i <
$term; $i++
) {
$tmp_time =
$now_time -
($i *
24 *
3600);
$batch_date =
date("Y/m/d", $tmp_time);
// リアルタイムで集計を実施する。集計が終了しているレコードは実施しない。
$sdate:YYYY-MM-DD hh:mm:ss形式の日付
$edate:YYYY-MM-DD hh:mm:ss形式の日付
$loop =
intval($pass /
86400);
for($i =
0; $i <=
$loop; $i++
) {
$tmp_time =
strtotime($sdate) +
($i *
86400);
$batch_date =
date("Y/m/d H:i:s", $tmp_time);
$arrRet =
$objQuery->select("order_date, create_date", "dtb_bat_order_daily", "order_date = ?", array($batch_date));
// すでにバッチ処理が終了しているかチェックする。
list
($create_date) =
split("\.", $arrRet[0]['create_date']);
list
($order_date) =
split("\.", $arrRet[0]['order_date']);
// オーダー開始日より一日以上後に集計されている場合は集計しなおさない
if($order_time +
86400 <
$create_time ||
$tmp_time >
time()) {
GC_Utils_Ex::gfPrintLog("EXIT BATCH $batch_date $tmp_time" .
" " .
time());
$from =
" FROM dtb_order AS T1 LEFT JOIN dtb_customer AS T2 USING ( customer_id ) ";
$where =
" WHERE T1.del_flg = 0 AND T1.status <> " .
ORDER_CANCEL .
" AND T1.create_date BETWEEN '$start' AND '$end' ";
$sql.= "COUNT(*) AS total_order, ";
$sql.= "SUM((SELECT COUNT(*) WHERE customer_id = 0)) AS nonmember, ";
$sql.= "SUM((SELECT COUNT(*) WHERE customer_id <> 0 GROUP BY customer_id)) AS member, ";
$sql.= "SUM((SELECT COUNT(*) WHERE order_sex = 1)) AS men, ";
$sql.= "SUM((SELECT COUNT(*) WHERE order_sex = 2)) AS women, ";
$sql.= "SUM((SELECT COUNT(*) WHERE order_sex = 1 AND customer_id <> 0)) AS men_member, ";
$sql.= "SUM((SELECT COUNT(*) WHERE order_sex = 1 AND customer_id = 0)) AS men_nonmember, ";
$sql.= "SUM((SELECT COUNT(*) WHERE order_sex = 2 AND customer_id <> 0)) AS women_member, ";
$sql.= "SUM((SELECT COUNT(*) WHERE order_sex = 2 AND customer_id = 0)) AS women_nonmember, ";
$sql.= "SUM(total) AS total, ";
$sql.= "int8(AVG(total)) AS total_average ";
$sql.= $where; // 受注作成日で検索する
$sql.=
"COUNT(*) AS total_order, ";
$sql.=
"(SELECT sum(cnt) FROM (SELECT COUNT(*) AS cnt $from $where AND T1.customer_id = 0) AS nonmember ) AS nonmember, ";
$sql.=
"(SELECT sum(cnt) FROM (SELECT COUNT(*) AS cnt $from $where AND T1.customer_id <> 0) AS member ) AS member, ";
$sql.=
"(SELECT sum(cnt) FROM (SELECT COUNT(*) AS cnt $from $where AND T1.order_sex = 1) AS men ) AS men, ";
$sql.=
"(SELECT sum(cnt) FROM (SELECT COUNT(*) AS cnt $from $where AND T1.order_sex = 2) AS women ) AS women, ";
$sql.=
"(SELECT sum(cnt) FROM (SELECT COUNT(*) AS cnt $from $where AND T1.order_sex = 1 AND T2.customer_id <> 0) AS men_member ) AS men_member, ";
$sql.=
"(SELECT sum(cnt) FROM (SELECT COUNT(*) AS cnt $from $where AND T1.order_sex = 1 AND T1.customer_id = 0) AS men_nonmember ) AS men_nonmember, ";
$sql.=
"(SELECT sum(cnt) FROM (SELECT COUNT(*) AS cnt $from $where AND T1.order_sex = 2 AND T2.customer_id <> 0) AS women_member ) AS women_member, ";
$sql.=
"(SELECT sum(cnt) FROM (SELECT COUNT(*) AS cnt $from $where AND T1.order_sex = 2 AND T1.customer_id = 0) AS women_nonmember ) AS women_nonmember, ";
$sql.=
"SUM(total) AS total, ";
$sql.=
"(AVG(total)) AS total_average ";
$sql.=
$where; // 受注作成日で検索する
$arrWDAY =
$masterData->getMasterData("mtb_wday");
$date =
date("Y-m-d", $time);
$start =
$date .
" 00:00:00";
$end =
$date .
" 23:59:59";
$arrRet =
$objQuery->getall($sql);
foreach($sqlval as $key =>
$val) {
$sqlval['create_date'] =
'now()';
$sqlval['order_date'] =
$start;
$sqlval['year'] =
date("Y", $time);
$sqlval['month'] =
date("m", $time);
$sqlval['day'] =
date("d", $time);
$sqlval['wday'] =
date("w", $time);
$sqlval['key_day'] =
sprintf("%02d/%02d/%02d", substr($sqlval['year'],2), $sqlval['month'], $sqlval['day']);
$sqlval['key_month'] =
sprintf("%02d/%02d", substr($sqlval['year'],2), $sqlval['month']);
$sqlval['key_year'] =
sprintf("%d", $sqlval['year']);
$sqlval['key_wday'] =
sprintf("%s", $arrWDAY[$sqlval['wday']]);
$objQuery->delete("dtb_bat_order_daily", "order_date = ?", array($start));
$objQuery->insert("dtb_bat_order_daily", $sqlval);
$date =
date("Y-m-d", $time);
$start =
$date .
" 00:00:00";
$objQuery->delete("dtb_bat_order_daily_hour", "order_date = ?", array($start));
for($i =
0; $i <
24; $i++
) {
$sdate =
sprintf("%s %02d:00:00", $date, $i);
$edate =
sprintf("%s %02d:59:59", $date, $i);
$arrRet =
$objQuery->getall($sql);
foreach($sqlval as $key =>
$val) {
$sqlval['create_date'] =
"now()";
$sqlval['order_date'] =
$start;
$objQuery->insert("dtb_bat_order_daily_hour", $sqlval);
$age_loop =
intval(BAT_ORDER_AGE /
10);
$sql =
"SELECT COUNT(*) AS order_count, SUM(total) AS total, (AVG(total)) AS total_average ";
$sql.=
"FROM dtb_order ";
$date =
date("Y-m-d", $time);
$start =
$date .
" 00:00:00";
$end =
$date .
" 23:59:59";
$objQuery->delete("dtb_bat_order_daily_age", "order_date = ?", array($start));
$base_where =
"WHERE (create_date BETWEEN ? AND ?) AND customer_id <> 0 AND del_flg = 0 AND status <> " .
ORDER_CANCEL;
for($i =
0; $i <=
$age_loop; $i++
) {
$where =
$base_where .
" AND order_birth >= cast('$start_date' as date)";
$where =
$where .
" AND order_birth < cast('$end_date' as date)";
$where =
$base_where .
" AND order_birth < cast('$end_date' as date)";
$where =
$base_where .
" AND order_birth IS NULL ";
$base_where =
"WHERE (create_date BETWEEN ? AND ?) AND customer_id = 0 AND del_flg = 0 AND status <> " .
ORDER_CANCEL;
$where =
$base_where .
" AND (to_number(to_char(age(current_timestamp, order_birth), 'YYY'), 999) BETWEEN ? AND ?) ";
for($i =
0; $i <=
$age_loop; $i++
) {
$where =
$base_where .
" AND order_birth >= cast('$start_date' as date)";
$where =
$where .
" AND order_birth < cast('$end_date' as date)";
$where =
$base_where .
" AND order_birth < cast('$end_date' as date)";
$where =
$base_where .
" AND order_birth IS NULL AND del_flg = 0";
$arrRet =
$objQuery->getall($sql, array($start, $end));
foreach($sqlval as $key =>
$val) {
$sqlval['create_date'] =
"now()";
$sqlval['order_date'] =
$start;
$sqlval['start_age'] =
"$start_age";
$sqlval['end_age'] =
"$end_age";
$sqlval['member'] =
"$member";
$objQuery->insert("dtb_bat_order_daily_age", $sqlval);
// 文字列にSingleQuotationを付与する
if (DB_TYPE ==
"mysql") {
$ret =
"'" .
$value .
"'";
Documentation generated on Tue, 28 Apr 2009 18:13:05 +0900 by phpDocumentor 1.4.2