您现在的位置是:首页 > cms教程 > Ecshop商城教程Ecshop商城教程
ecshop增加自定义虚拟销量的实现方法
谢协2025-02-06Ecshop商城教程已有人查阅
导读本补丁以假乱真,对网站销售有一定帮助,计算公式:前台显示销量 = 后台自定义销量 = 实际销量,以下讲解以官方默认模板(default)为例
本补丁以假乱真,对网站销售有一定帮助,计算公式:前台显示销量 = 后台自定义销量 = 实际销量,以下讲解以官方默认模板(default)为例
后台商品列表
前台效果
开发指南
一、将安装文件覆盖到网站根目录(覆盖前注意备份),输入”站点路径/db_patch.php”,如”http://ecshop.phpally.com/db_patch.php”一键完成数据库补丁的安装,安装完成后,请立即删除db_patch.php。
后台商品列表
前台效果
开发指南
一、将安装文件覆盖到网站根目录(覆盖前注意备份),输入”站点路径/db_patch.php”,如”http://ecshop.phpally.com/db_patch.php”一键完成数据库补丁的安装,安装完成后,请立即删除db_patch.php。
<?php
/**
* ECSHOP 自定义销量 数据库补丁
* ----------------------------------------------------------------------------
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
$sql = "
ALTER TABLE `{$prefix}goods` ADD `sales_volume_base` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '销量基数'
";
$db->query($sql);
echo '数据库补丁程序执行成功,请立即删除此补丁文件(db_patch.php)。';
二、编辑/admin/goods.php,添加修改销量基数(sales_volume_base)
*------------------------------------------------------ */
//-- 修改商品销量基数
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'edit_sales_volume_base')
{
check_authz_json('goods_manage');
$goods_id = intval($_POST['id']);
$sales_volume_base = json_str_iconv(trim($_POST['val']));
if ($exc->edit("sales_volume_base = '$sales_volume_base', last_update=" .gmtime(), $goods_id))
{
clear_cache_files();
make_json_result(stripslashes($sales_volume_base));
}
}
三、编辑/admin/includes/lib_goods.php,添加查询销量基数(sales_volume_base)
sql = "SELECT goods_id, goods_name, goods_type, goods_sn, shop_price, is_on_sale, is_best, is_new, is_hot, sort_order, goods_number, integral, sales_volume_base, " .
" (promote_price > 0 AND promote_start_date <= '$today' AND promote_end_date >= '$today') AS is_promote ".
" FROM " . $GLOBALS['ecs']->table('goods') . " AS g WHERE is_delete='$is_delete' $where" .
" ORDER BY $filter[sort_by] $filter[sort_order] ".
" LIMIT " . $filter['start'] . ",$filter[page_size]";
四、编辑/admin/templates/goods_list.htm,添加显示销量基数(sales_volume_base)
<table cellpadding="3" cellspacing="1">
<tr>
<th>
<input onclick='listTable.selectAll(this, "checkboxes")' type="checkbox" />
<a href="javascript:listTable.sort('goods_id'); ">{$lang.record_id}</a>{$sort_goods_id}
</th>
<th><a href="javascript:listTable.sort('goods_name'); ">{$lang.goods_name}</a>{$sort_goods_name}</th>
<th><a href="javascript:listTable.sort('goods_sn'); ">{$lang.goods_sn}</a>{$sort_goods_sn}</th>
<th><a href="javascript:listTable.sort('shop_price'); ">{$lang.shop_price}</a>{$sort_shop_price}</th>
<th><a href="javascript:listTable.sort('is_on_sale'); ">{$lang.is_on_sale}</a>{$sort_is_on_sale}</th>
<th><a href="javascript:listTable.sort('is_best'); ">{$lang.is_best}</a>{$sort_is_best}</th>
<th><a href="javascript:listTable.sort('is_new'); ">{$lang.is_new}</a>{$sort_is_new}</th>
<th><a href="javascript:listTable.sort('is_hot'); ">{$lang.is_hot}</a>{$sort_is_hot}</th>
<th><a href="javascript:listTable.sort('sort_order'); ">{$lang.sort_order}</a>{$sort_sort_order}</th>
{if $use_storage}
<th><a href="javascript:listTable.sort('goods_number'); ">{$lang.goods_number}</a>{$sort_goods_number}</th>
{/if}
<th><a href="javascript:listTable.sort('sales_volume_base'); ">{$lang.sales_volume_base}</a>{$sort_sales_volume_base}</th>
<th>{$lang.handler}</th>
<tr>
{foreach from=$goods_list item=goods}
<tr>
<td><input type="checkbox" name="checkboxes[]" value="{$goods.goods_id}" />{$goods.goods_id}</td>
<td class="first-cell" style="{if $goods.is_promote}color:red;{/if}"><span onclick="listTable.edit(this, 'edit_goods_name', {$goods.goods_id})">{$goods.goods_name|escape:html}</span></td>
<td><span onclick="listTable.edit(this, 'edit_goods_sn', {$goods.goods_id})">{$goods.goods_sn}</span></td>
<td align="right"><span onclick="listTable.edit(this, 'edit_goods_price', {$goods.goods_id})">{$goods.shop_price}
</span></td>
<td align="center"><img src="images/{if $goods.is_on_sale}yes{else}no{/if}.gif" onclick="listTable.toggle(this, 'toggle_on_sale', {$goods.goods_id})" /></td>
<td align="center"><img src="images/{if $goods.is_best}yes{else}no{/if}.gif" onclick="listTable.toggle(this, 'toggle_best', {$goods.goods_id})" /></td>
<td align="center"><img src="images/{if $goods.is_new}yes{else}no{/if}.gif" onclick="listTable.toggle(this, 'toggle_new', {$goods.goods_id})" /></td>
<td align="center"><img src="images/{if $goods.is_hot}yes{else}no{/if}.gif" onclick="listTable.toggle(this, 'toggle_hot', {$goods.goods_id})" /></td>
<td align="center"><span onclick="listTable.edit(this, 'edit_sort_order', {$goods.goods_id})">{$goods.sort_order}</span></td>
{if $use_storage}
<td align="right"><span onclick="listTable.edit(this, 'edit_goods_number', {$goods.goods_id})">{$goods.goods_number}</span></td>
{/if}
<td align="center"><span onclick="listTable.edit(this, 'edit_sales_volume_base', {$goods.goods_id})">{$goods.sales_volume_base}</span></td>
<td align="center">
<a href="../goods.php?id={$goods.goods_id}" target="_blank" title="{$lang.view}"><img src="images/icon_view.gif" width="16" height="16" border="0" /></a>
<a href="goods.php?act=edit&goods_id={$goods.goods_id}{if $code neq 'real_goods'}&extension_code={$code}{/if}" title="{$lang.edit}"><img src="images/icon_edit.gif" width="16" height="16" border="0" /></a>
<a href="goods.php?act=copy&goods_id={$goods.goods_id}{if $code neq 'real_goods'}&extension_code={$code}{/if}" title="{$lang.copy}"><img src="images/icon_copy.gif" width="16" height="16" border="0" /></a>
<a href="javascript:;" onclick="listTable.remove({$goods.goods_id}, '{$lang.trash_goods_confirm}')" title="{$lang.trash}"><img src="images/icon_trash.gif" width="16" height="16" border="0" /></a>
{if $specifications[$goods.goods_type] neq ''}<a href="goods.php?act=product_list&goods_id={$goods.goods_id}" title="{$lang.item_list}"><img src="images/icon_docs.gif" width="16" height="16" border="0" /></a>{else}<img src="images/empty.gif" width="16" height="16" border="0" />{/if}
{if $add_handler}
|
{foreach from=$add_handler item=handler}
<a href="{$handler.url}&goods_id={$goods.goods_id}" title="{$handler.title}"><img src="images/{$handler.img}" width="16" height="16" border="0" /></a>
{/foreach}
{/if}
</td>
</tr>
{foreachelse}
<tr><td class="no-records">{$lang.no_records}</td></tr>
{/foreach}
</table>
五、编辑/languages/zh_cn/admin/goods.php,添加语言项
$_LANG['sales_volume_base'] = '销量基数';
六、编辑/includes/lib_goods.php,修改get_goods_info函数,计算累计销量(sales_volume_total)
/**
* 获得商品的详细信息
*
* @access public
* @param integer $goods_id
* @return void
*/
function get_goods_info($goods_id)
{
$time = gmtime();
$sql = 'SELECT g.*, c.measure_unit, b.brand_id, b.brand_name AS goods_brand, m.type_money AS bonus_money, ' .
'IFNULL(AVG(r.comment_rank), 0) AS comment_rank, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS rank_price " .
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS c ON g.cat_id = c.cat_id ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON g.brand_id = b.brand_id ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('comment') . ' AS r '.
'ON r.id_value = g.goods_id AND comment_type = 0 AND r.parent_id = 0 AND r.status = 1 ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('bonus_type') . ' AS m ' .
"ON g.bonus_type_id = m.type_id AND m.send_start_date <= '$time' AND m.send_end_date >= '$time'" .
" LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
"WHERE g.goods_id = '$goods_id' AND g.is_delete = 0 " .
"GROUP BY g.goods_id";
$row = $GLOBALS['db']->getRow($sql);
/* 查询该商品的实际销量 */
$sql = 'SELECT IFNULL(SUM(g.goods_number), 0) ' .
'FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS o, ' .
$GLOBALS['ecs']->table('order_goods') . ' AS g ' .
"WHERE o.order_id = g.order_id " .
"AND o.order_status = '" . OS_CONFIRMED . "' " .
"AND o.shipping_status " . db_create_in(array(SS_SHIPPED, SS_RECEIVED)) .
" AND o.pay_status " . db_create_in(array(PS_PAYED, PS_PAYING)) .
" AND g.goods_id = '$goods_id'" ;
$sales_count = $GLOBALS['db']->getOne($sql);
/* 累计销量 = 自定义销量基数 + 实际销量 */
$row['sales_volume_total'] = $row['sales_volume_base'] + $sales_count;
if ($row !== false)
{
/* 用户评论级别取整 */
$row['comment_rank'] = ceil($row['comment_rank']) == 0 ? 5 : ceil($row['comment_rank']);
/* 获得商品的销售价格 */
$row['market_price'] = price_format($row['market_price']);
$row['shop_price_formated'] = price_format($row['shop_price']);
/* 修正促销价格 */
if ($row['promote_price'] > 0)
{
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
}
else
{
$promote_price = 0;
}
/* 处理商品水印图片 */
$watermark_img = '';
if ($promote_price != 0)
{
$watermark_img = "watermark_promote";
}
elseif ($row['is_new'] != 0)
{
$watermark_img = "watermark_new";
}
elseif ($row['is_best'] != 0)
{
$watermark_img = "watermark_best";
}
elseif ($row['is_hot'] != 0)
{
$watermark_img = 'watermark_hot';
}
if ($watermark_img != '')
{
$row['watermark_img'] = $watermark_img;
}
$row['promote_price_org'] = $promote_price;
$row['promote_price'] = price_format($promote_price);
/* 修正重量显示 */
$row['goods_weight'] = (intval($row['goods_weight']) > 0) ?
$row['goods_weight'] . $GLOBALS['_LANG']['kilogram'] :
($row['goods_weight'] * 1000) . $GLOBALS['_LANG']['gram'];
/* 修正上架时间显示 */
$row['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']);
/* 促销时间倒计时 */
$time = gmtime();
if ($time >= $row['promote_start_date'] && $time <= $row['promote_end_date'])
{
$row['gmt_end_time'] = $row['promote_end_date'];
}
else
{
$row['gmt_end_time'] = 0;
}
/* 是否显示商品库存数量 */
$row['goods_number'] = ($GLOBALS['_CFG']['use_storage'] == 1) ? $row['goods_number'] : '';
/* 修正积分:转换为可使用多少积分(原来是可以使用多少钱的积分) */
$row['integral'] = $GLOBALS['_CFG']['integral_scale'] ? round($row['integral'] * 100 / $GLOBALS['_CFG']['integral_scale']) : 0;
/* 修正优惠券 */
$row['bonus_money'] = ($row['bonus_money'] == 0) ? 0 : price_format($row['bonus_money'], false);
/* 修正商品图片 */
$row['goods_img'] = get_image_path($goods_id, $row['goods_img']);
$row['goods_thumb'] = get_image_path($goods_id, $row['goods_thumb'], true);
return $row;
}
else
{
return false;
}
}
七、以默认模板为例,编辑/themes/default/goods.dwt,添加显示累计销量
<li class="clearfix">
<dd>
<strong>{$lang.sales_volume_total}<font color="#FE596A" size="2">{$goods.sales_volume_total}{$lang.pcs}</font></strong>
</dd>
<dd>
</dd>
</li>
八、编辑/languages/zh_cn/common.php,添加语言项
$_LANG['sales_volume_total'] = '累计销量:';
$_LANG['pcs'] = '件';
本文标签:
很赞哦! ()
下一篇:ecshop订单状态对应值介绍
相关教程
图文教程
ecshop兼容CSS样式在FF、IE7、IE6中的不同表现
随着IE7对!important的支持,现在IE7和FF都支持!important,可以用!important来区分FF、IE7和IE6的高度。
ECSHOP漏洞\admin\edit_languages.php GETSHELL Based On Inject
对于很多CMS网站来说,它们都需要保存很多的网站META信息,最常用的较佳实践是以变量声明的形式保存在.php文件中,在需要的时候直接include进来
ecshop的info: Can't Connect MySQL Server(localhost:3306)报错解决
很多人新人在搬家过程,打开ecshop网站会出现以下ECSHOP info: Can't Connect MySQL Server(localhost:3306)
ecshop商品限制购买和批发起订数量的实行方法
做过商城,或者说经营过商城的都会知道,有很多商品利润很小,而且还要包运费什么的,所以根本就是做 的生意,如果利润小,数量多的话 这样就不会出现赔本的损失。
相关源码
-
(PC+WAP)院校学院职业学校机构协会网站开源源码下载本模板基于PbootCMS系统开发,为高等院校、职业学校等教育机构设计,特别适合展示学校概况、院系设置、招生信息等内容。采用双端适配技术,确保在PC和移动设备上都能获得良好的浏览体验。查看源码 -
自适应建材瓷砖卫浴大理石类pbootcms网站模板源码下载为建材瓷砖、卫浴瓷砖企业打造的高端响应式门户模板,基于PbootCMS内核深度开发。采用前沿HTML5自适应架构,无缝兼容手机端触控交互与PC端展示场景。查看源码 -
(自适应)中英文双语外贸扬声器音响喇叭话筒网站模板免费下载为音响设备外贸企业设计的中英文双语网站模板,基于PbootCMS内核开发。适配扬声器系统、音频设备等产品的国际化展示需求查看源码 -
(PC+WAP)地暖热水器烘干机节能设备网站模板下载为地暖热水器及节能设备企业设计的PbootCMS网站模板,集成产品展示、节能方案介绍、技术参数说明等专业模块。采用PC与移动端同步响应架构查看源码 -
(自适应响应式)陶瓷研磨盘抛光机械设备pbootcms网站模板本模板基于PbootCMS系统开发,为研磨抛光设备制造企业设计,特别适合陶瓷研磨盘、抛光设备等表面处理设备展示。采用响应式布局技术,确保各类设备的参数和工艺在不同终端上都能清晰呈现。查看源码 -
(自适应)帝国cms7.5模板新闻资讯门户带会员中心基于帝国CMS7.5内核开发的HTML5响应式模板,为新闻机构、媒体门户及资讯聚合平台设计。通过模块化布局实现图文混排查看源码
| 分享笔记 (共有 篇笔记) |
