Ecmall订单管理生成电子表格(Excels)
  • 分类:经验分享
  • 发表:2014-05-21
  • 围观(10,181)
  • 评论(1)

需求:Ecmall后台管理中的订单管理,输出为电子表格形式。

要修改的文件:\admin\templates\order.index.html 、 \admin\app\order.app.php和\languages\sc-gbk\admin\order.lang.php文件。

打开\admin\templates\order.index.htm,在大约11行,<li><span>{$lang.manage}</span></li> 的下面加上:

<li><form method="get">
<input type="hidden" name="app" value="order" />
<input type="hidden" name="act" value="excels" />
<input name="field" type="hidden" value="{$smarty.get.field}" />
<input name="search_name" type="hidden" value="{$query.search_name|escape}" />
<input name="status" type="hidden" value="{$query.status}" />
<input name="add_time_from" type="hidden" value="{$query.add_time_from}" />
<input name="add_time_to" type="hidden" value="{$query.add_time_to}" />
<input name="order_amount_from" type="hidden" value="{$query.order_amount_from}" />
<input name="order_amount_to" type="hidden" value="{$query.order_amount_to}" />
<input name="payment_code" type="hidden" value="{$query.payment_code}" />
<input type="submit" class="formbtn1" value="{$lang.scexcels}" style="margin-left:10px;" />
</form></li>

打开\admin\app\order.app.php文件,在文件结尾,

$this->display('order.view.html');
}

后面加上:

//生成Excels
function excels()
{
$search_options = array(
'seller_name' => Lang::get('store_name'),
'buyer_name' => Lang::get('buyer_name'),
'payment_name' => Lang::get('payment_name'),
'order_sn' => Lang::get('order_sn'),
);
/* 默认搜索的字段是店铺名 */
$field = 'seller_name';
array_key_exists($_GET['field'], $search_options) && $field = $_GET['field'];
$conditions = $this->_get_query_conditions(array(array(
'field' => $field, //按用户名,店铺名,支付方式名称进行搜索
'equal' => 'LIKE',
'name' => 'search_name',
),array(
'field' => 'status',
'equal' => '=',
'type' => 'numeric',
),array(
'field' => 'add_time',
'name' => 'add_time_from',
'equal' => '>=',
'handler'=> 'gmstr2time',
),array(
'field' => 'add_time',
'name' => 'add_time_to',
'equal' => '<=',
'handler' => 'gmstr2time_end',
),array(
'field' => 'order_amount',
'name' => 'order_amount_from',
'equal' => '>=',
'type' => 'numeric',
),array(
'field' => 'order_amount',
'name' => 'order_amount_to',
'equal' => '<=',
'type' => 'numeric',
),array(
'field' => 'payment_code',
),
));
$model_order =& m('order');
$page = $this->_get_page(100000); //获取分页信息
//更新排序
if (isset($_GET['sort']) && isset($_GET['order']))
{
$sort = strtolower(trim($_GET['sort']));
$order = strtolower(trim($_GET['order']));
if (!in_array($order,array('asc','desc')))
{
$sort = 'add_time';
$order = 'desc';
}
}
else
{
$sort = 'add_time';
$order = 'desc';
}

$orders = $model_order->find(array(
'conditions' => '1=1 ' . $conditions,
'limit' => $page['limit'], //获取当前页的数据
'order' => "$sort $order",
'count' => true //允许统计
)); //找出所有商城的合作伙伴

$st_time=$_GET['add_time_from']." 00:00:00";
$end_time=$_GET['add_time_to']." 24:00:00";

header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=Order_list.xls");
echo "<table width='100%' cellpadding='5' border='1'>";
echo "<tr><th colspan='8'><font size='5'>".$_GET['add_time_from']."至".$_GET['add_time_to']."[".$_GET['payment_code']."]交易所有汇总</font></th></tr>";
echo "<tr><th width='50'>序号</th><th width='190'>店铺名称</th><th width='110'>订单号</th><th width='130'>下单时间</th><th width='100'>买家名称</th><th width='80'>订单总价</th><th width='180'>支付方式</th><th width='120'>订单状态</th></tr>";
$number=0;
$zyzfe=0;//总应支付额
$order_isok=0;
//var_dump($index);
foreach($orders as &$row)
{
$order_status="";
switch($row['status'])
{
case 11:
$order_status="待付款";
break;
case 10:
$order_status="已提交";
break;
case 20:
$order_status="待发货";
break;
case 30:
$order_status="已发货";
break;
case 40:
$order_status="已完成";
$order_isok+=1;
break;
case 0:
$order_status="已取消";
break;
default:
$order_status="退货";
break;
}
$number+=1;
echo "<tr>";
echo "<td align='center'>".$number."</td>";
echo "<td align='center'>".$row['seller_name']."</td>";
echo "<td align='center'>".$row['order_sn']."</td>";
echo "<td align='center'>".date("Y-m-d H:i:s",$row['add_time'])."</td>";
echo "<td align='center'>".$row['buyer_name']."</td>";
echo "<td align='center'>".$row['order_amount']."</td>";
echo "<td align='center'>".$row['payment_name']."[".$row['payment_code']."]</td>";
echo "<td align='center'>".$order_status."(".$row['status'].")</td>";
$zyzfe+=$row['order_amount'];
echo "</tr>";
}
echo "<tr><td colspan='4'>本列表共有订单数:".$number."单,其中已完成的订单数为:".$order_isok." 单。</td><td colspan='2' align='right'>本列表交易总额:</td><td aling='center'><strong style='color:red;'>".sprintf("%.2f",$zyzfe)."</strong></td><td> </td></tr>";
echo "<tr><td colspan='8'>注意:此列表仅做为对帐列表用;";
echo "<br />   <strong>此表仅可显示前1万条记录;</strong>";
echo "<br />   <strong>此表默认显示<font color='red'>所有状态订单</font>,如需要显示特定状态订单则需要提前选择“订单状态”。</strong>";
echo "</td></tr>";
echo "<tr><td colspan='8' align='right'>本列表生成时间:".date('Y-m-d H:i:s',time())."</td></tr>";
echo "</table>";

}

打开\languages\sc-gbk\admin\order.lang.php文件,在结尾处加上一句:

'scexcels' => '导出为Excels',

这里注意,上一句的结尾要加上一个逗号(,)。

至此,修改完了。

Top