Ecshop模板网
首页 > ecshop扩展插件 > ecshop自定义销量插件
模板详情
ecshop模板堂
 
ecshop自定义销量插件
 
 

ecshop自定义销量插件

 
¥500元 
总价 :
 
独家最新研发的ECSHOP商品详细页面显示累计销量,可以后台对每个商品增加自定义销售数,同时支持后台开关显示和可选虚拟真实 方式切换显示。虚拟显示方式是采用自定义数量+真实实际的销量数量=累计销量显示在每个商品的详细页面上,同时会自动根据购买实际真实销量自动累计向 上增加,从而达到完美最好的效果。真实显示方式是直接显示实际真实的销量数量,不累计加上自定义的虚拟数量。

本补丁以假乱真,对网站销售有一定帮助,计算公式:前台显示销量 = 后台自定义销量 = 实际销量,以下讲解以官方默认模板(default)为例。

ecshop自定义销量插件




开发指南

一、将安装文件覆盖到网站根目录(覆盖前注意备份),输入”站点路径/db_patch.php”,如”http://ecshop.phpally.com/db_patch.php”一键完成数据库补丁的安装,安装完成后,请立即删除db_patch.php。

数据库补丁


<?php

 
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
 
$sql = "
ALTER TABLE `{$prefix}goods` ADD `sales_volume_base` INT( 10 ) UNSIGNED NOTNULLDEFAULT '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.sel ectAll(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" colspan="10">{$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'] = '件';



 用户评论(共 0 条评论)
  • 暂时还没有任何用户评论
用户名: 匿名用户 E-mail:
当前心情:
评论内容:
验证码: captcha
返回顶部 返回首页
 
QQ在线咨询
售前电话热线
#
售前QQ客服