我意识到两个日期之间的信息导出脚本,我遇到了一个小难题。这是我的脚本的场景:
我的脚本完美无缺,但我想补充一点:
以下是当前代码:
$filename = $this->l('export_perfs');
$header = array('Ambassadrice:Nom/Prénom', 'Nb Filleul','CA Filleul (total)','Nvx Filleul', 'CA Nvx Filleul');
// Récupére le nombre de filleuls total et le CA total
$sql1 = Db::getInstance()->executeS("
SELECT CONCAT(amb.firstname, ' ', amb.lastname) AS NomPrénom, rs.id_sponsor, c.id_customer, SUM(o.total_products_wt + o.total_shipping) AS CA, c.date_add AS dateFilleul, o.date_add AS dateOrder
FROM `"._DB_PREFIX_."rewards_sponsorship` rs
LEFT JOIN `"._DB_PREFIX_."customer` c ON rs.id_customer = c.id_customer
LEFT JOIN `"._DB_PREFIX_."customer` amb ON rs.id_sponsor = amb.id_customer
LEFT JOIN `"._DB_PREFIX_."orders` o ON(c.id_customer = o.id_customer)
GROUP BY rs.id_customer");
$lines = array();
foreach ($sql1 as $row) {
$id_sponsor = $row['id_sponsor'];
$lines[$id_sponsor]['ambassadrice'] = $row['NomPrénom'];
$lines[$id_sponsor]['totalCa'] += $row['CA'];
$lines[$id_sponsor]['nbFilleul']++;
$dateInscriptionFilleul = $row['dateFilleul'];
$dateOrder = $row['dateOrder'];
if($dateInscriptionFilleul > $date_from .' 00:00:00' && $dateInscriptionFilleul < $date_to.' 23:59:59' && $dateOrder > $date_from.' 00:00:00' && $dateOrder < $date_to.' 23:59:59') {
$lines[$id_sponsor]['nbFilleulNew']++;
$lines[$id_sponsor]['totalCaNew'] += $row['CA'];
}
}
$results = [];
foreach ($lines as $id_sponsor => $data) {
$results[] = array(
$data['ambassadrice'],
$data['nbFilleul'],
$data['totalCa'],
isset($data['nbFilleulNew'])?$data['nbFilleulNew']:0,
isset($data['totalCaNew'])?$data['totalCaNew']:0,
);
}
return $this->generateCSV($results, $header, $filename);
break;
你知道怎么做吗?
感谢您的帮助