erp_ebay_order_stats.php此模組負責 eBay 訂單的統計分析,包含時間篩選、多條件查詢、圖表資料生成等功能。
<?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);
// 動作參數初始化
$_REQUEST['act'] = empty($_REQUEST['act']) ? 'view' : 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; // 預設近 14 天
$end_date = $today;
}
// 多月份統計支援
$start_date_arr = $end_date_arr = [];
if (!empty($_POST['year_month'])) {
foreach ($_POST['year_month'] as $ym) {
if (!empty($ym)) {
$tmp_time = local_strtotime($ym . '-1');
$start_date_arr[] = $tmp_time;
$end_date_arr[] = local_strtotime($ym . '-' . 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');
}
// 綜合訂單量統計 SQL
if (!$is_multi) {
$general_xml = "<graph caption='$_LANG[general_stats]' ... >";
$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";
// ... 後續 XML 圖表資料組裝邏輯
}
}
?>
$ecs->table()、$db->query() 等框架方法。admin_priv() 確保後台操作安全。此模組展示了電商後台系統中典型的報表統計開發模式。