//控制器(Controller)
class Order_BaggingController extends Zend_Controller_Action {
//导出汇总表
public function exportBaggedAction() {
$shipping_method = $this->_request->getParam('shipping_method', '');
$bag_numbers = $this->_request->getParam('bag_number', '');
$warehouse_id = $this->_request->getParam('warehouse_id', '');
if ($shipping_method == '')
die(Zend_I18n::getInstance()->translate('1100203'));
if ($warehouse_id == '')
die(Zend_I18n::getInstance()->translate('1000711'));
$condition = array(
'shipping_method' => $shipping_method,
'status' => 2,
'opackage_code' => explode(',', $bag_numbers),
'warehouse_id' => $warehouse_id
);
$opObj = new Order_Model_OrderPackage();
$list = $opObj->getByCond($condition, array('opackage_code', 'opackage_create_time', 'opackage_weight', 'opackage_qty', 'opackage_count', 'lock_number', 'opackage_area', 'opackage_note'));
if (!$list)
die(Zend_I18n::getInstance()->translate('12000015'));
$total = array('orders' => 0, 'weight' => 0);
$shipDate = 0;
foreach ($list as $key => $value) {
if ($shipDate == 0) {
$shipDate = strtotime($value['opackage_create_time']);
} else {
$tmpTime = strtotime($value['opackage_create_time']);
if ($tmpTime < $shipDate) {
$shipDate = $tmpTime;
}
}
$list[$key]['bagCount'] = $value['opackage_count'];
$total['orders'] += $value['opackage_qty'];
$total['weight'] += $value['opackage_weight'];
}
$this->view->data = $list;
$this->view->total = $total;
$this->view->shipping_method = $shipping_method;
$this->view->nowDate = date('Y-m-d', $shipDate);
if (strtolower($shipping_method) == 'dgsgamr') {
$tpl = 'export-bagged-dg-dgsgamr';
} else if (strtolower($shipping_method) == 'sls' || strtolower($shipping_method) == 'mlma') {
$tpl = 'export-bagged-dg-sls';
} else {
$tpl = 'export-bagged';
}
$content = $this->view->render($this->tplDirectory . $tpl . '.tpl');
$content = mb_convert_encoding($content, 'gbk', 'utf-8');
$title = mb_convert_encoding($shipping_method . Zend_I18n::getInstance()->translate('12000014') . date('Ymd', $shipDate), 'gbk', 'utf-8');
header("Pragma: public");
header("Expires: 0");
header("Accept-Ranges: bytes");
header("Content-Disposition: attachment; filename=" . $title . ".xls");
header("Content-Type:APPLICATION/OCTET-STREAM;charset=gb2312");
echo $content;
}
}
Html
<!DOCTYPE html>
<html>
<head>
<title>装袋汇总表</title>
<meta charset="gb2312">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
table tr td{
text-align: center
}
</style>
</head>
<body>
<table border="1" width="100%" bordercolor="#C0C0C0">
<tr><th colspan="5"><b><{$shipping_method}> 装袋汇总表</b></th></tr>
<tr><td colspan="5"></td></tr>
<tr>
<th style="color:red;">日期</th>
<td><{$nowDate}></td>
<th style="color:red;">联系人</th>
<td>曾小元</td>
</tr>
<tr>
<th style="color:red;">客户</th>
<td>PZWG</td>
<th style="color:red;">联系电话</th>
<td>18926792027</td>
</tr>
<tr>
<th>序号</th>
<th>箱/袋数</th>
<th>包裹数</th>
<th>重量(KG)</th>
<th>备注</th>
</tr>
<{foreach item=item key=key from=$data}>
<tr>
<td><{$key + 1}></td>
<{if $shipping_method == SLS }>
<td><{$item.lock_number}></td>
<{else}>
<td><{$shipping_method}><{$item.opackage_code}></td>
<{/if}>
<td><{$item.opackage_qty}></td>
<td><{$item.opackage_weight}></td>
<td><{$item.opackage_note}></td>
</tr>
<{/foreach}>
<tr>
<th>总计</th>
<td></td>
<td><{$total.orders}></td>
<td><{$total.weight}></td>
</tr>
</table>
</body>
</html>
�