近期ecshop网站做活动,统计商品订单量的时候没有按商品名搜索的选项,只能手动查询。这样效率很低下,而且容易出错。
涉及到2个文件,分别是/admin/order.php,/admin/templates/order_list.htm,下面详说。
第一步,增加表单项在/admin/templates/order_list.htm第11行下面增加
1
商品名<input name="goods_name" type="text" id="goods_name" size="15">
这样,代码上下文基本为
1
{$lang.order_sn}<input name="order_sn" type="text" id="order_sn" size="15">
2
{$lang.consignee|escape}<input name="consignee" type="text" id="consignee"size="15">
3
商品名<input name="goods_name" type="text" id="goods_name" size="15">
4
{$lang.all_status}
5
<select name="status" id="status">
在/admin/order_list.htm第105行下面增加
1
listTable.filter['goods_name'] = Utils.trim(document.forms['searchForm'].elements['goods_name'].value);
这样,代码上下文基本为
1
/**
2
* 搜索订单
3
*/
4
function searchOrder()
5
{
6
listTable.filter['order_sn'] = Utils.trim(document.forms['searchForm'].elements['order_sn'].value);
7
listTable.filter['consignee'] = Utils.trim(document.forms['searchForm'].elements['consignee'].value);
8
listTable.filter['goods_name'] = Utils.trim(document.forms['searchForm'].elements['goods_name'].value);
9
listTable.filter['composite_status'] = document.forms['searchForm'].elements['status'].value;
10
listTable.filter['page'] = 1;
11
listTable.loadList();
12
}
3.1)php文件接收参数并准备拼接sql
在/admin/order.php第4874行找到“$where = ‘WHERE 1 ‘;”,在下面增加
1
$join_goods =" ";
2
if ($filter['goods_name'])
3
{
4
$join_goods = " LEFT JOIN " .$GLOBALS['ecs']->table('order_goods'). " AS og ON o.order_id=og.order_id LEFT JOIN " .$GLOBALS['ecs']->table('goods'). " AS g ON g.goods_id = og.goods_id ";
5
$where .= " AND g.goods_name LIKE '%" . mysql_like_quote($filter['goods_name']) . "%'";
6
}
3.2)拼接sql
分别更改/admin/order.php第5025,5029,5041行sql语句为下面三句代码
1,
1
$sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('order_info') . " AS o ,".
2
$GLOBALS['ecs']->table('users') . " AS u ". $join_goods. $where;
2.