一、主程序/admin/erp_ebay_order_stats.php
代碼如下
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
require_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/admin/erp_ebay_statistic.php');
$smarty->assign('lang', $_LANG);
/* act操作項的初始化 */
if (empty($_REQUEST['act']))
{
$_REQUEST['act'] = 'view';
}
else
{
$_REQUEST['act'] = trim($_REQUEST['act']);
}
if ($_REQUEST['act'] == 'view')
{
admin_priv('order_stats'); //檢查權限
$is_multi = empty($_POST['is_multi']) ? false : true;
/* 時間參數 */
if (isset($_POST['start_date']) && !empty($_POST['end_date']))
{
$start_date = local_strtotime($_POST['start_date']);
$end_date = local_strtotime($_POST['end_date']);
}
else
{
$today = local_strtotime(local_date('Y-m-d'));
$start_date = $today - 86400 * 14;
$end_date = $today;
}
$start_date_arr = array();
$end_date_arr = array();
if(!empty($_POST['year_month']))
{
$tmp = $_POST['year_month'];
for ($i = 0; $i < count($tmp); $i++)
{
if (!empty($tmp[$i]))
{
$tmp_time = local_strtotime($tmp[$i] . '-1');
//echo $tmp_time;
$start_date_arr[] = $tmp_time;
$end_date_arr[] = local_strtotime($tmp[$i] . '-' . date('t', $tmp_time));
//echo local_strtotime($tmp[$i] . '-' . date('t', $tmp_time));
}
}
}
else
{
$tmp_time = local_strtotime(local_date('Y-m-d'));
$start_date_arr[] = local_strtotime(local_date('Y-m') . '-1');
$end_date_arr[] = local_strtotime(local_date('Y-m') . '-31');;
}
/* ------------------------------------- */
/* -- 綜合訂單量
/* ------------------------------------- */
$max = 0;
if(!$is_multi)
{
$general_xml = "<graph caption='$_LANG[general_stats]' shownames='1' showvalues='1' decimalPrecision='0' yaxisminvalue='0' yaxismaxvalue='%d' animation='1' outCnvBaseFontSize='12' baseFontSize='12' xaxisname='$_LANG[date]' yaxisname='$_LANG[order_count]' >";
$sql = "SELECT FLOOR((created_time - $start_date) / (24 * 3600)) AS sn, created_time, COUNT(*) AS order_count".
" FROM " .$ecs->table('erp_ebay_order').
" WHERE ebay_status = 'Complete' AND created_time >= '$start_date' AND created_time <= " .($end_date + 86400).
" GROUP BY sn";
$res = $db->query($sql);
$key = 0;
while ($val = $db->fetchRow($res))
{
$val['order_date'] = gmdate('m-d',$val['created_time'] + $timezone * 3600 + 86400);
$general_xml .= "<set name='$val[order_date]' value='$val[order_count]' color='" .chart_color($key). "' />";
if ($val['order_count'] > $max)
{
$max = $val['order_count'];
}
$key++;
}
$general_xml .= '</graph>';
$general_xml = sprintf($general_xml, $max);
}
else
{
$general_xml = "<graph caption='$_LANG[general_stats]' lineThickness='1' showValues='0' formatNumberScale='0' anchorRadius='2' divLineAlpha='20' divLineColor='CC3300' divLineIsDashed='1' showAlternateHGridColor='1' alternateHGridAlpha='5' alternateHGridColor='CC3300' shadowAlpha='40' labelStep='2' numvdivlines='5' chartRightMargin='35' bgColor='FFFFFF,CC3300' bgAngle='270' bgAlpha='10,10' outCnvBaseFontSize='12' baseFontSize='12' >";
foreach($start_date_arr AS $k => $val)
{
$seriesName = local_date('Y-m', $start_date_arr[$k]);
$general_xml .= "<dataset seriesName='$seriesName' color='" . chart_color($k) . "' anchorBorderColor='" . chart_color($k) . "' anchorBgColor='" . chart_color($k) . "'>";
$sql = "SELECT FLOOR((created_time - $start_date_arr[$k]) / (24 * 3600)) AS sn, created_time, COUNT(*) AS order_count".
" FROM " .$ecs->table('erp_ebay_order').
" WHERE ebay_status = 'Complete' AND created_time >= '$start_date_arr[$k]' AND created_time <= " .($end_date_arr[$k] + 86400).
" GROUP BY sn";
$res = $db->query($sql);
$lastDay = 0;
while ($val = $db->fetchRow($res))
{
$day = gmdate('d', $val['created_time'] + $timezone * 3600);
if ($lastDay == 0)
{
$time_span = (($day-1) - $lastDay);
$lastDay++;
for (; $lastDay < $day; $lastDay++)
{
$general_xml .= "<set value='0' />";
}
}
$general_xml .= "<set value='$val[order_count]' />";
$lastDay = $day;
}
$general_xml .= "</dataset>";
}
$general_xml .= "<categories>";
for ($i = 1; $i<=31; $i++)
{
$general_xml .= "<category label='$i' />";
}
$general_xml .= "</categories>";
$general_xml .= "</graph>";
echo $general_xml;
}
/* ------------------------------------- */
/* -- 銷售額
/* ------------------------------------- */
$max = 0;
if(!$is_multi)
{
$amount_xml = "<graph caption='$_LANG[amount_stats]' shownames='1' showvalues='1' decimalPrecision='0' yaxisminvalue='0' yaxismaxvalue='%d' animation='1' outCnvBaseFontSize='12' baseFontSize='12' xaxisname='$_LANG[date]' yaxisname='$_LANG[order_count]' >";
$sql = "SELECT FLOOR((created_time - $start_date) / (24 * 3600)) AS sn, created_time, SUM(subtotal) AS order_amount".
" FROM " .$ecs->table('erp_ebay_order').
" WHERE ebay_status = 'Complete' AND created_time >= '$start_date' AND created_time <= " .($end_date + 86400) . " AND ebay_status = 'Complete'" .
" GROUP BY sn";
$res = $db->query($sql);
$key = 0;
while ($val = $db->fetchRow($res))
{
$val['order_date'] = gmdate('m-d',$val['created_time'] + $timezone * 3600 + 86400);
$amount_xml .= "<set name='$val[order_date]' value='$val[order_amount]' color='" .chart_color($key). "' />";
if ($val['order_amount'] > $max)
{
$max = $val['order_amount'];
}
$key++;
}
$amount_xml .= '</graph>';
$amount_xml = sprintf($amount_xml, $max);
}
else
{
$amount_xml = "<graph caption='$_LANG[amount_stats]' lineThickness='1' showValues='0' formatNumberScale='0' anchorRadius='2' divLineAlpha='20' divLineColor='CC3300' divLineIsDashed='1' showAlternateHGridColor='1' alternateHGridAlpha='5' alternateHGridColor='CC3300' shadowAlpha='40' labelStep='2' numvdivlines='5' chartRightMargin='35' bgColor='FFFFFF,CC3300' bgAngle='270' bgAlpha='10,10' outCnvBaseFontSize='12' baseFontSize='12' >";
foreach($start_date_arr AS $k => $val)
{
$seriesName = local_date('Y-m', $start_date_arr[$k]);
$amount_xml .= "<dataset seriesName='$seriesName' color='" . chart_color($k) . "' anchorBorderColor='" . chart_color($k) . "' anchorBgColor='" . chart_color($k) . "'>";
$sql = "SELECT FLOOR((created_time - $start_date_arr[$k]) / (24 * 3600)) AS sn, created_time, SUM(subtotal) AS order_amount".
" FROM " .$ecs->table('erp_ebay_order').
" WHERE ebay_status = 'Complete' AND created_time >= '$start_date_arr[$k]' AND created_time <= " .($end_date_arr[$k] + 86400) . " AND ebay_status = 'Complete'" .
" GROUP BY sn";
$res = $db->query($sql);
$lastDay = 0;
while ($val = $db->fetchRow($res))
{
$day = gmdate('d',$val['created_time'] + $timezone * 3600);
if ($lastDay == 0)
{
$time_span = (($day-1) - $lastDay);
$lastDay++;
for (; $lastDay < $day; $lastDay++)
{
$amount_xml .= "<set value='0' />";
}
}
$amount_xml .= "<set value='$val[order_amount]' />";
$lastDay = $day;
}
$amount_xml .= "</dataset>";
}
$amount_xml .= "<categories>";
for ($i = 1;$i<=31;$i++)
{
$amount_xml .= "<category label='$i' />";
}
$amount_xml .= "</categories>";
$amount_xml .= "</graph>";
}
/* ------------------------------------- */
/* -- 狀態
/* ------------------------------------- */
$status_xml = '';
if(!$is_multi)
{
$status_xml .= "<graph caption='".$_LANG['status_stats']."' shownames='1' showvalues='1' decimalPrecision='2' outCnvBaseFontSize='13' baseFontSize='13' pieYScale='45' pieBorderAlpha='40' pieFillAlpha='70' pieSliceDepth='15' pieRadius='100' bgAngle='460'>";
$sql = "SELECT COUNT(*) AS order_count, ebay_status FROM " . $ecs->table('erp_ebay_order') .
" WHERE created_time >= '$start_date' AND created_time < " .($end_date + 86400).
" GROUP BY ebay_status ORDER BY order_count DESC LIMIT 20";
$res = $db->query($sql);
$key = 0;
while ($val = $db->fetchRow($res))
{
$ebay_status = empty($val['ebay_status']) ? 'no data' : $val['ebay_status'];
$status_xml .= "<set name='$ebay_status' value='$val[order_count]' color='" .chart_color($key). "' />";
$key++;
}
$status_xml .= '</graph>';
}
else
{
$where = '';
foreach($start_date_arr AS $k => $val)
{
if ($where != '')
{
$where .= ' or ';
}
$where .= "(created_time >= '$start_date_arr[$k]' AND created_time <= " .($end_date_arr[$k] + 86400).")";
}
$sql = "SELECT created_time, ebay_status FROM " . $ecs->table('erp_ebay_order') .
" WHERE $where";
$res = $db->query($sql);
$area_arr = array();
while ($val = $db->fetchRow($res))
{
$date = local_date('Y-m', $val['created_time']);
$area_arr[$val['ebay_status']] = null;
if (isset($category[$date][$val['ebay_status']]))
{
$category[$date][$val['ebay_status']]++;
}
else
{
$category[$date][$val['ebay_status']] = 1;
}
}
$status_xml = "<chart palette='2' caption='$_LANG[status_stats]' shownames='1' showvalues='0' numberPrefix='' useRoundEdges='1' legendBorderAlpha='0' outCnvBaseFontSize='13' baseFontSize='13'>";
$status_xml .= "<categories>";
foreach ($area_arr AS $k => $v)
{
$status_xml .= "<category label='$k'/>";
}
$status_xml .= "</categories>";
$key = 0;
foreach($start_date_arr AS $val)
{
$key++;
$date = local_date('Y-m', $val);
$status_xml .= "<dataset seriesName='$date' color='" .chart_color($key). "' showValues='0'>";
foreach ($area_arr AS $k => $v)
{
if (isset($category[$date][$k]))
{
$status_xml .= "<set value='" .$category[$date][$k]. "'/>";
}
else
{
$status_xml .= "<set value='0'/>";
}
}
$status_xml .= "</dataset>";
}
$status_xml .= "</chart>";
}
/* 模板賦值 */
$smarty->assign('ur_here', $_LANG['01_erp_order_stats']);
$smarty->assign('general_data', $general_xml);
$smarty->assign('amount_data', $amount_xml);
$smarty->assign('status_data', $status_xml);
$smarty->assign('is_multi', $is_multi);
/* 顯示日期 */
$smarty->assign('start_date', local_date('Y-m-d', $start_date));
$smarty->assign('end_date', local_date('Y-m-d', $end_date));
for ($i = 0; $i < 5; $i++)
{
if (isset($start_date_arr[$i]))
{
$start_date_arr[$i] = local_date('Y-m', $start_date_arr[$i]);
}
else
{
$start_date_arr[$i] = null;
}
}
$smarty->assign('start_date_arr', $start_date_arr);
if (!$is_multi)
{
$filename = gmdate($_CFG['date_format'], $start_date + $timezone * 3600 + 86400) . '_' .
gmdate($_CFG['date_format'], $end_date + $timezone * 3600 + 86400);
$smarty->assign('action_link', array('text' => $_LANG['down_order_stats'],
'href'=>'erp_ebay_order_stats.php?act=download&filename=' . $filename .
'&start_date=' . $start_date . '&end_date=' . $end_date));
}
/* 顯示頁面 */
assign_query_info();
$smarty->display('erp_ebay_order_stats.htm');
}
/* 報表下載 */
elseif ($act = 'download')
{
admin_priv('download_order_stats'); //檢查權限
$filename = !empty($_REQUEST['filename']) ? trim($_REQUEST['filename']) : '';
header("Content-type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment; filename=$filename.xls");
$start_date = empty($_GET['start_date']) ? strtotime('-20 day') : intval($_GET['start_date']);
$end_date = empty($_GET['end_date']) ? time() : intval($_GET['end_date']);
//綜合訂單量統計
$sql = "SELECT FLOOR((created_time - $start_date) / (24 * 3600)) AS sn, created_time, COUNT(*) AS order_count, SUM(subtotal) AS order_amount".
" FROM " . $GLOBALS['ecs']->table('erp_ebay_order') .
" WHERE created_time >= '$start_date' AND created_time <= " .($end_date + 86400) . " AND ebay_status = 'Complete'".
" GROUP BY sn";
$res = $GLOBALS['db']->query($sql);
$data .= $_LANG['date'] . "t";
$data .= $_LANG['order_count'] . "t";
$data .= $_LANG['order_amount'] . "tn";
while ($val = $GLOBALS['db']->fetchRow($res))
{
$val['created_date'] = gmdate($_CFG['date_format'], $val['created_time'] + $timezone * 3600 + 86400);
$data .= $val['created_date'] . "t";
$data .= $val['order_count'] . "t";
$data .= price_format($val['order_amount']) . "tn";
$total_count += $val['order_count'];
$total_amount += $val['order_amount'];
}
$data .= $_LANG['total'] . "t";
$data .= $total_count . "t";
$data .= price_format($total_amount) . "tn";
//狀態統計
$sql = "SELECT COUNT(*) AS order_count, SUM(subtotal) AS order_amount, ebay_status FROM " . $GLOBALS['ecs']->table('erp_ebay_order') .
" WHERE created_time >= '$start_date' AND created_time <= " .($end_date + 86400).
" GROUP BY ebay_status ORDER BY order_count DESC LIMIT 20";
$res = $GLOBALS['db']->query($sql);
$data .= "tn";
$data .= $_LANG['order_status'] . "t";
$data .= $_LANG['order_count'] . "t";
$data .= $_LANG['order_amount'] . "tn";
while ($val = $GLOBALS['db']->fetchRow($res))
{
$data .= $val['ebay_status'] . "t";
$data .= $val['order_count'] . "t";
$data .= price_format($val['order_amount']) . "tn";
}
if (EC_CHARSET != 'UTF-8')
{
echo ecs_iconv(EC_CHARSET, 'UTF-8', $data) . "t";
}
else
{
echo $data. "t";
}
}
?>
二、語言文件/languages/zh_cn/admin/erp_ebay_statistic.php
代碼如下 <?php三、模板文件/admin/templates/erp_ebay_order_stats.htm
代碼如下{include file="pageheader.htm"}
<script type="text/javascript" src="../js/calendar.php?lang={$cfg_lang}"></script>
<link href="../js/calendar/calendar.css" rel="stylesheet" type="text/css" />
<div class="form-div">
<form action="" method="post" id="selectForm" name="selectForm">
{$lang.date_interval}
<input name="start_date" value="{$start_date}" style="width:80px;" onclick="return showCalendar(this, '%Y-%m-%d', false, false, this);" />
--
<input name="end_date" value="{$end_date}" style="width:80px;" onclick="return showCalendar(this, '%Y-%m-%d', false, false, this);" />
<input type="submit" name="submit" value="{$lang.query}" class="button" />
</form>
<form action="" method="post" id="selectForm" name="selectForm">
{$lang.year_month}
<!--{foreach from=$start_date_arr item=start_date key=k}-->
{if $k > 0}
+
{/if}
<input name="year_month[]" value="{$start_date}" style="width:60px;" onclick="return showCalendar(this, '%Y-%m', false, false, this);" />
<!--{/foreach}--><input type="hidden" name="is_multi" value="1" />
<input type="submit" name="submit" value="{$lang.query}" class="button" />
</form>
</div>
<div class="tab-div">
<!-- tab bar -->
<div id="tabbar-div">
<p>
<span class="tab-front" id="general-tab">{$lang.tab_general}</span>
<span class="tab-back" id="amount-tab">{$lang.tab_amount}</span>
<span class="tab-back" id="status-tab">{$lang.tab_status}</span>
</p>
</div>
<!-- tab body -->
<div id="tabbody-div">
<!-- 綜合訂單量 -->
<table width="90%" id="general-table">
<tr><td align="center">
<!--{if $is_multi eq "0"}-->
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
width="565" height="420" id="FCColumn2" align="middle">
<PARAM NAME="FlashVars" value="&dataXML={$general_data}">
<PARAM NAME=movie VALUE="images/charts/line.swf?chartWidth=800&chartHeight=400">
<param NAME="quality" VALUE="high">
<param NAME="bgcolor" VALUE="#FFFFFF">
<param NAME="wmode" VALUE="opaque">
<embed src="images/charts/line.swf?chartWidth=800&chartHeight=400" FlashVars="&dataXML={$general_data}" quality="high" bgcolor="#FFFFFF" width="800" height="400" name="FCColumn2" wmode="opaque" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
</object>
<!--{else}-->
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
width="565" height="420" id="FCColumn2" align="middle">
<PARAM NAME="FlashVars" value="&dataXML={$general_data}">
<PARAM NAME=movie VALUE="images/charts/MSline.swf?chartWidth=800&chartHeight=400">
<param NAME="quality" VALUE="high">
<param NAME="bgcolor" VALUE="#FFFFFF">
<param NAME="wmode" VALUE="opaque" />
<embed src="images/charts/MSline.swf?chartWidth=800&chartHeight=400" FlashVars="&dataXML={$general_data}" quality="high" bgcolor="#FFFFFF" width="800" height="400" name="FCColumn2" wmode="opaque" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
</object>
<!--{/if}-->
</td></tr>
</table>
<!-- 銷售額 -->
<table width="90%" id="amount-table" style="display:none">
<tr><td align="center">
<!--{if $is_multi eq "0"}-->
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
width="565" height="420" id="FCColumn2" align="middle">
<PARAM NAME="FlashVars" value="&dataXML={$amount_data}">
<PARAM NAME=movie VALUE="images/charts/line.swf?chartWidth=800&chartHeight=400">
<param NAME="quality" VALUE="high">
<param NAME="bgcolor" VALUE="#FFFFFF">
<param NAME="wmode" VALUE="opaque">
<embed src="images/charts/line.swf?chartWidth=800&chartHeight=400" FlashVars="&dataXML={$amount_data}" quality="high" bgcolor="#FFFFFF" width="800" height="400" name="FCColumn2" wmode="opaque" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
</object>
<!--{else}-->
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
width="565" height="420" id="FCColumn2" align="middle">
<PARAM NAME="FlashVars" value="&dataXML={$amount_data}">
<PARAM NAME=movie VALUE="images/charts/MSline.swf?chartWidth=800&chartHeight=400">
<param NAME="quality" VALUE="high">
<param NAME="bgcolor" VALUE="#FFFFFF">
<param NAME="wmode" VALUE="opaque" />
<embed src="images/charts/MSline.swf?chartWidth=800&chartHeight=400" FlashVars="&dataXML={$amount_data}" quality="high" bgcolor="#FFFFFF" width="800" height="400" name="FCColumn2" wmode="opaque" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
</object>
<!--{/if}-->
</td></tr>
</table>
<!-- 狀態 -->
<table width="90%" id="status-table" style="display:none">
<tr><td align="center">
<!--{if $is_multi eq "0"}-->
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="465" HEIGHT="320" id="General" ALIGN="middle">
<PARAM NAME="FlashVars" value="&dataXML={$status_data-tab}">
<PARAM NAME=movie VALUE="images/charts/pie3d.swf?chartWidth=800&chartHeight=400">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#FFFFFF>
<param NAME="wmode" VALUE="opaque" />
<EMBED src="images/charts/pie3d.swf?chartWidth=800&chartHeight=400" FlashVars="&dataXML={$status_data}" quality=high bgcolor=#FFFFFF WIDTH="800" HEIGHT="400" NAME="General" ALIGN="middle" wmode="opaque" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>
</OBJECT>
<!--{else}-->
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="465" HEIGHT="320" id="General" ALIGN="middle">
<PARAM NAME="FlashVars" value="&dataXML={$status_data}">
<PARAM NAME=movie VALUE="images/charts/ScrollColumn2D.swf?chartWidth=800&chartHeight=400">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#FFFFFF>
<param NAME="wmode" VALUE="opaque" />
<EMBED src="images/charts/ScrollColumn2D.swf?chartWidth=800&chartHeight=400" FlashVars="&dataXML={$status_data}" quality=high bgcolor=#FFFFFF WIDTH="800" HEIGHT="400" NAME="General" wmode="opaque" ALIGN="middle" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>
</OBJECT>
<!--{/if}-->
</td></tr>
</table>
</div>
</div>
{insert_scripts files="tab.js"}
<script type="Text/Javascript" language="JavaScript">
<!--
onload = function()
{
// 開始檢查訂單
startCheckOrder();
}
//-->
</script>
{include file="pagefooter.htm"}