/*
* CSP 订单添加增值服务并完成质检提交后系统自动发邮件到收件人邮箱
* $start_date 前一天时间
* $end_dates 当天时间
* $warehouse (string) 仓库
*/
public static function QcCSPEmail($start_date, $end_date, $warehouse = "11") {
//根据时间限制获取对应数据
$condition = array(
"start_date" => date("Y-m-d H:i:s", strtotime($start_date)),
"end_date" => date("Y-m-d H:i:s", strtotime($end_date)),
"warehouse_id" => $warehouse,
);
$dataList = Special_Service_SpecialProjectOrderLog::getByCond($condition, "*", array("spol_create_date"));
$text = '<style>.tab-report{border-top:1px solid #cccccc;border-left:1px solid #cccccc;} .tab-report td, .tab-report th{border-bottom:1px solid #cccccc;border-right:1px solid #cccccc; text-align:center;} .tab-report .yellow{background-color:yellow} .tab-report .blue{background-color:#82A3F8} .tab-report .orange{background-color:#E6F3F9} .tab-report .event-tr{background-color:#E6F3F9}</style>';
$text .= '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tab-report">';
$text .= '<tr class="o0range">';
$text .= '<th>ASN单号</th>';
$text .= '<th>采购单号</th>';
$text .= '<th>QC单号</th>';
$text .= '<th>CSP</th>';
$text .= '<th>增值服务项</th>';
$text .= '<th>原因</th>';
$text .= '<th>操作员</th>';
$text .= '<th>日期</th>';
$text .= '</tr>';
//组合数组以时间为键名
$date = array();
foreach ($dataList as $value) {
if ($value['spol_msg_type'] == 1) {
$spoRefCode = Special_Service_SpecialProjectOrder::getBySpoCode($value['spo_code']);
$qcoCode = Product_Service_QualityControlOrder::getQcoCode($spoRefCode['spo_ref_code']);
$receivingCode = Product_Service_Receiving::getByReceivingCode($qcoCode['qco_ref_code']);
if ($receivingCode['plat_form'] == "CSP") {
$da = date('Y-m-d', strtotime($value['spol_create_date']));
$date[$da][] = $value;
}
}
}
//对数组按照键名逆向排序
krsort($date);
/*
* 整合邮件内容(附件)
* 遍历每天
*/
foreach ($date as $key => $value) {
$content .= "\n" . $key . "\n";
$content .= "ASN单号,采购单号,QC单号,CSP,增值服务项,原因,操作员,日期\n";
//遍历一天中的单号
foreach ($value as $va) {
$spoRefCode = Special_Service_SpecialProjectOrder::getBySpoCode($va['spo_code']);
$qcoCode = Product_Service_QualityControlOrder::getQcoCode($spoRefCode['spo_ref_code']);
$receivingCode = Product_Service_Receiving::getByReceivingCode($qcoCode['qco_ref_code']);
$spoCode = Special_Service_SpecialProjectItem::getBySpoCodeAll($va['spo_code']);
$Is_show = $receivingCode['plat_form'] == "CSP" ? '是' : '否';
$spolNote = explode(';', $va['spol_note']);
$userId = User_Service_User::getByUserId($va['user_id']);
//遍历一个单号中的增值服务项
foreach ($spoCode as $k => $v) {
$pocValueCn = Special_Service_SpecialProjectOptions::getById($v['poc_id']);
//正文内容
$tet = date('Y-m-d', strtotime($va['spol_create_date']));
$te = date('Y-m-d', strtotime("-1 day", strtotime($end_date)));
if ($tet == $te) {
$text .= '<tr>'
. '<td>' . $qcoCode['qco_ref_code'] . '</td>'
. '<td>' . $receivingCode['ref_id'] . '</td>'
. '<td>' . $spoRefCode['spo_ref_code'] . '</td>'
. '<td>' . $Is_show . '</td>'
. '<td>' . $pocValueCn['spop_value_cn'] . '</td>'
. '<td>' . $spolNote[$k] . '</td>'
. '<td>' . $userId['name'] . '</td>'
. '<td>' . $va['spol_create_date'] . '</td>'
. '</tr>';
}
//附件内容
$content .= $qcoCode['qco_ref_code'] . ','
. "\t" . $receivingCode['ref_id'] . ','
. $spoRefCode['spo_ref_code'] . ','
. $Is_show . ','
. $pocValueCn['spop_value_cn'] . ','
. $spolNote[$k] . ','
. $userId['name'] . ','
. $va['spol_create_date'] . "\n";
}
}
}
$text .= '</table>';
//获取收件人邮箱
$configAttribute = Common_Service_Config::getByAttribute('CSP_EXCEPTION_LIST_EMAIL');
if (!empty($configAttribute)) {
$mailUser = explode(';', $configAttribute['config_value']);
} else {
die('请添加邮箱地址!');
}
//发送邮件对应处理
$content = iconv("UTF-8", "GBK", $content);
$mail_subject = "CSP 订单报表";
$mail = Cff::setupMail();
$aee = $mail->setBodyHtml($text);
$mail->addTo($mailUser, $mail_subject);
$mail->setSubject($mail_subject);
$at = $mail->createAttachment($content);
$at->type = 'application/vnd.ms-excel';
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_8BIT;
$at->filename = iconv("UTF-8", "GB2312", $mail_subject . date('Y-m-d') . '.csv');
$mail->send();
}
提交订单系统自动发送邮件到收件人邮箱优化(邮件正文内容为当天数据,附件内容为当月数据)
最新推荐文章于 2021-05-24 18:39:35 发布