您的位置:首页 > 运维架构

Ecshop后台管理增加成本价和毛利润统计功能

2014-02-21 10:42 351 查看
ecshop 功能二次开发 关于后台管理增加成本价和毛利润统计功能(一)

首先在订单中的商品信息【编辑】页面中,修改成本价。也可以在添加商品时添加成本的如果不做手工修改,则使用默认的商品成本价(在商品信息里编辑的成本
价格)。

第一步:修改数据库中的商品表ecs_goods和订单商品表ecs_order_goods,添加成本价字段cost_price
把SQL语句列出来:

alter table `ecs_goods` add column `cost_price` decimal (10,2) UNSIGNED  DEFAULT '0.00' NOT NULL  after `promote_price`
alter table `ecs_order_goods` add column `cost_price` decimal (10,2)  DEFAULT '0.00' NOT NULL  after `market_price`


这里是加在了字段promote_price 和market_price后面

第二步.增加语言包 ,需要修改languages\zh_cn\admin\goods.php
再最后添加

$_LANG['lab_cost_price']            = '成本价:';
$_LANG['notice_cost_price']         = '该商品进货价格(成本价,在商品添加时设置,也可以在商品编辑里面修改 。).';


第三步.修改admin/goods.php 把成本价格插入到数据库
在两个(有两个地方需要修改)

'promote_price' => 0,


后新增一行添加

'cost_price' => 0,


再在

$shop_price = !empty($_POST['shop_price']) ? $_POST['shop_price'] : 0;


后添加

$cost_price = !empty($_POST['cost_price']) ? $_POST['cost_price'] : 0;




if ($is_insert)
{
。。。。。源代码太多省略(了这个是真实商品和虚拟商品)
}
else
{

。。。。。源代码太多省略了
}


修改成

if ($is_insert)
{
if ($code == '')
{
$sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .
"cat_id, brand_id, shop_price,cost_price, market_price, is_promote, promote_price, " .
"promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " .
"seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, " .
"is_on_sale, is_alone_sale, goods_desc, add_time, last_update, goods_type, rank_integral)" .
"VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .
"'$brand_id', '$shop_price','$cost_price', '$market_price', '$is_promote','$promote_price', ".
"'$promote_start_date', '$promote_end_date', '$goods_img', '$goods_thumb', '$original_img', ".
"'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".
" '$warn_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', '$is_on_sale', '$is_alone_sale', ".
" '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$rank_integral')";
}
else
{
$sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .
"cat_id, brand_id, shop_price,cost_price, market_price, is_promote, promote_price, " .
"promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " .
"seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, is_real, " .
"is_on_sale, is_alone_sale, goods_desc, add_time, last_update, goods_type, extension_code, rank_integral)" .
"VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .
"'$brand_id', '$shop_price','$cost_price', '$market_price', '$is_promote','$promote_price', ".
"'$promote_start_date', '$promote_end_date', '$goods_img', '$goods_thumb', '$original_img', ".
"'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".
" '$warn_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', 0, '$is_on_sale', '$is_alone_sale', ".
" '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$code', '$rank_integral')";
}
}
else
{

$sql = "SELECT goods_thumb, goods_img, original_img " .
" FROM " . $ecs->table('goods') .
" WHERE goods_id = '$_REQUEST[goods_id]'";
$row = $db->getRow($sql);
if ($proc_thumb && $goods_img && $row['goods_img'] && !goods_parse_url($row['goods_img']))
{
@unlink(ROOT_PATH . $row['goods_img']);
@unlink(ROOT_PATH . $row['original_img']);
}
if ($proc_thumb && $goods_thumb && $row['goods_thumb'] && !goods_parse_url($row['goods_thumb']))
{
@unlink(ROOT_PATH . $row['goods_thumb']);
}
$sql = "UPDATE " . $ecs->table('goods') . " SET " .
"goods_name = '$_POST[goods_name]', " .
"goods_name_style = '$goods_name_style', " .
"goods_sn = '$goods_sn', " .
"cat_id = '$catgory_id', " .
"brand_id = '$brand_id', " .
"shop_price = '$shop_price', " .
"cost_price = '$cost_price', " .
"market_price = '$market_price', " .
"is_promote = '$is_promote', " .
"promote_price = '$promote_price', " .
"promote_start_date = '$promote_start_date', " .
"promote_end_date = '$promote_end_date', ";

if ($goods_img)
{
$sql .= "goods_img = '$goods_img', original_img = '$original_img', ";
}
if ($goods_thumb)
{
$sql .= "goods_thumb = '$goods_thumb', ";
}
if ($code != '')
{
$sql .= "is_real=0, extension_code='$code', ";
}
$sql .= "keywords = '$_POST[keywords]', " .
"goods_brief = '$_POST[goods_brief]', " .
"seller_note = '$_POST[seller_note]', " .
"goods_weight = '$goods_weight'," .
"goods_number = '$goods_number', " .
"warn_number = '$warn_number', " .
"integral = '$_POST[integral]', " .
"give_integral = '$give_integral', " .
"rank_integral = '$rank_integral', " .
"is_best = '$is_best', " .
"is_new = '$is_new', " .
"is_hot = '$is_hot', " .
"is_on_sale = '$is_on_sale', " .
"is_alone_sale = '$is_alone_sale', " .
"goods_desc = '$_POST[goods_desc]', " .
"last_update = '". gmtime() ."', ".
"goods_type = '$goods_type' " .
"WHERE goods_id = '$_REQUEST[goods_id]' LIMIT 1";
}


(第三步 主要是在插入数据库时,把成本价(cost_price)的值插入到数据库)
第四步.下面应该在商品编辑页读取和显示成本价格,需要修改admin/templates/goods_info.dwt
找到代码

<tr>
<td class="label">{$lang.lab_market_price}</td>
<td><input type="text" name="market_price" value="{$goods.market_price}" size="20" />
<input type="button" value="{$lang.integral_market_price}" onclick="integral_market_price()" />
</td>
</tr>


在这段代码之后添加显示成本价格的表格

<!--新增 成本价 begin -->
<tr>
<td class="label">{$lang.lab_cost_price}</td>
<td><input type="text" name="cost_price" value="{$goods.cost_price}" size="20" />
<br />
<span class="notice-span" {if $help_open}style="display:block" {else} style="display:none" {/if} id="minNumber">{$lang.notice_cost_price}</span></td>
</td>
</tr>
<!-- 成本价 end -->


这样就把就完成了在商品添加时增加商品的成本价和在商品列表页编辑商品页显示成本价的功能

ecshop 功能二次开发 关于后台管理增加成本价和毛利润统计功能(二)

1.修改订单的语言文件languages\zh_cn\admin\order.php
最后新增:

$_LANG['cost_price'] = '成本价';


2.然后我们来修改订单显示模板文件 admin\templates\order_info.dwt

把<th colspan="8" scope="col">修改成<th colspan="9" scope="col">


在<td scope="col"><div align="center"><strong>{$lang.storage}</strong></div></td>
代码之后插入<td scope="col"><div align="center"><strong>{$lang.cost_price}</strong></div></td>


在<td><div align="right">{$goods.storage}</div></td>
代码之后插入<td><div align="right">{$goods.cost_price}</div></td>


3.下面是如何修改修改admin\order.php


$sql = "SELECT o.*, g.goods_number AS storage, o.goods_attr, IFNULL(b.brand_name, '') AS brand_name " .
"FROM " . $ecs->table('order_goods') . " AS o ".
"LEFT JOIN " . $ecs->table('goods') . " AS g ON o.goods_id = g.goods_id " .
"LEFT JOIN " . $ecs->table('brand') . " AS b ON g.brand_id = b.brand_id " .
"WHERE o.order_id = '$order[order_id]' ";


修改成

$sql = "SELECT o.*, g.goods_number AS storage,if(o.cost_price>0,o.cost_price,g.cost_price)  AS cost_price, o.goods_attr, IFNULL(b.brand_name, '') AS brand_name " .
"FROM " . $ecs->table('order_goods') . " AS o ".
"LEFT JOIN " . $ecs->table('goods') . " AS g ON o.goods_id = g.goods_id " .
"LEFT JOIN " . $ecs->table('brand') . " AS b ON g.brand_id = b.brand_id " .
"WHERE o.order_id = '$order[order_id]' ";




$goods_price = floatval($_POST['goods_price'][$key]);
之后插入$cost_price = floatval($_POST['cost_price'][$key]);




$sql = "UPDATE " . $ecs->table('order_goods') .
" SET goods_price = '$goods_price', " .
"goods_number = '$goods_number', " .
"goods_attr = '$goods_attr' " .
"WHERE rec_id = '$rec_id' LIMIT 1";


修改成

$sql = "UPDATE " . $ecs->table('order_goods') .
" SET goods_price = '$goods_price',cost_price = '$cost_price', " .
"goods_number = '$goods_number', " .
"goods_attr = '$goods_attr' " .
"WHERE rec_id = '$rec_id' LIMIT 1";




update_order($order_id, array('order_status' => OS_CONFIRMED, 'confirm_time' => gmtime()));


之后插入

$sql_cost =  "UPDATE ". $GLOBALS['ecs']->table('order_goods')." as og,".            $GLOBALS['ecs']->table('goods')." as g SET og.cost_price =
g.cost_price " .
" WHERE og.goods_id = g.goods_id".
" AND og.order_id = '$order_id' and og.cost_price=0";
$GLOBALS['db']->query($sql_cost);




update_order($order_id, array('order_status' => OS_CONFIRMED, 'confirm_time' => gmtime()));
update_order_amount($order_id);


之后插入

$sql_cost =  "UPDATE ". $GLOBALS['ecs']->table('order_goods')." as og,".            $GLOBALS['ecs']->table('goods')." as g SET og.cost_price =
g.cost_price " .
" WHERE og.goods_id = g.goods_id".
" AND og.order_id = '$order_id' and og.cost_price=0";
$GLOBALS['db']->query($sql_cost);




$goods_id = $_REQUEST['goods_id'];
$sql = "SELECT goods_id, c.cat_name, goods_sn, goods_name, b.brand_name, " .
"goods_number, market_price, shop_price, promote_price, " .
"promote_start_date, promote_end_date, goods_brief, goods_type, is_promote " .
"FROM " . $ecs->table('goods') . " AS g " .
"LEFT JOIN " . $ecs->table('brand') . " AS b ON g.brand_id = b.brand_id " .
"LEFT JOIN " . $ecs->table('category') . " AS c ON g.cat_id = c.cat_id " .
" WHERE goods_id = '$goods_id'";


修改成

$goods_id = $_REQUEST['goods_id'];
$sql = "SELECT goods_id, c.cat_name, goods_sn, goods_name, b.brand_name, " .
"goods_number, market_price, shop_price,cost_price, promote_price, " .
"promote_start_date, promote_end_date, goods_brief, goods_type, is_promote " .
"FROM " . $ecs->table('goods') . " AS g " .
"LEFT JOIN " . $ecs->table('brand') . " AS b ON g.brand_id = b.brand_id " .
"LEFT JOIN " . $ecs->table('category') . " AS c ON g.cat_id = c.cat_id " .
" WHERE goods_id = '$goods_id'";


4.修改文件includes\lib_order.php
修改order_goods函数的SQL语句,将

$sql = "SELECT rec_id, goods_id, goods_name, goods_sn, market_price, goods_number, " .
"goods_price, goods_attr, is_real, parent_id, is_gift, " .
"goods_price * goods_number AS subtotal, extension_code " .
"FROM " . $GLOBALS['ecs']->table('order_goods') .
" WHERE order_id = '$order_id'";


修改成

$sql = "SELECT o.rec_id, o.goods_id, o.goods_name, o.goods_sn, o.market_price, o.goods_number, " .
"o.goods_price,if(o.cost_price>0,o.cost_price,g.cost_price)  AS cost_price, o.goods_attr, o.is_real, o.parent_id, o.is_gift, " .
"o.goods_price * o.goods_number AS subtotal, o.extension_code " .
"FROM " . $GLOBALS['ecs']->table('order_goods') . " AS o ".
"LEFT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g ON o.goods_id = g.goods_id " .
" WHERE order_id = '$order_id'";


5.修改订单商品模板admin\templates\order.dwt

在<th scope="col">{$lang.goods_attr}</th>
之后插入<th scope="col">{$lang.cost_price}</th>


在<td><textarea name="goods_attr[]" cols="30" rows="{$goods.rows}">{$goods.goods_attr}</textarea></td>
之后插入<td><input name="cost_price[]" type="text" style="text-align:right" value="{$goods.cost_price}" size="10" /></td>


在    <tr>
<th>{$lang.goods_price}</th>
<td id="add_price"> </td>
</tr>
之后插入
<tr>
<th>{$lang.cost_price}</th>
<td id="cost_price"> </td>
</tr>


在document.getElementByIdx_x_x('add_price').innerHTML = '';
之后插入document.getElementByIdx_x_x('cost_price').innerHTML = '';
在document.getElementByIdx_x_x('add_price').innerHTML = priceHtml;
之后插入document.getElementByIdx_x_x('cost_price').innerHTML = '<input type="text" name="cost_price" value="'+result.cost_price+'" />';


ecshop 功能二次开发 关于后台管理增加成本价和毛利润统计功能(三)
毛利润显示在报表统计的销售明细里 并且增加了成本汇总

1.到admin目录下覆盖 sale_list.php 文件 (做好备份)
2.到admin\templates目录下覆盖 sale_list.html(做好备份)
完成后,到后台"清存缓存"
左边菜单栏找到“报表统计 ” -> 销售明细 查看即可.

缺陷:
如果按指定的时间查询,底下利润等就显示不出来了。 (这是由于查询的时候用ajax调用的,我没有找到调用时的sql或其它,不知道官方这里怎么写的)

下载文件:sale_list.rar
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: