为ecshop用户提供商品批备注功能

更新时间:2014-12-30 点击量:802

 ecshop开发需求:

1. 每个登录的用户在购物过程中的商品列表页、商品详细页、购物车都可以对商品进行批注;
2. 要求1中的批注会显示在订单中每个商品项中;
3. 用户每次登陆之后清除上次的批注。
 
修改方法:
【1】增加两个表:
-- ----------------------------
-- Table structure for `order_comment`
-- ----------------------------
DROP TABLE IF EXISTS `order_comment`;
CREATE TABLE `order_comment` (
  `order_id` mediumint(8) NOT NULL,
  `goods_id` mediumint(8) NOT NULL,
  `goods_comment` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`order_id`,`goods_id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;
 
 
-- ----------------------------
-- Table structure for `goods_comment`
-- ----------------------------
DROP TABLE IF EXISTS `goods_comment`;
CREATE TABLE `goods_comment` (
  `goods_id` mediumint(8) NOT NULL,
  `user_id` mediumint(8) NOT NULL,
  `goods_comment` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`goods_id`,`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;
 
 
【2】themes\default\library\goods_list.lbi文件中:
<a href="javascript:;" id="compareLink" onClick="Compare.add({$goods.goods_id},'{$goods.goods_name|escape:"html"}','{$goods.type}')" class="f6">{$lang.compare}</a>
后边增加:
           <!--{if $smarty.session.user_id}-->
           {$lang.my_goods_comment}:<textarea onclick="addGoodsComment(this, {$goods.goods_id})" style="width:90%;">{$goods.goods_comment}</textarea>
           <br />
           <!--{/if}-->
 
 
【3】themes\default\user_transaction.dwt文件中:
<th width="23%" align="center" bgcolor="#ffffff">{$lang.goods_name}</th>
            <th width="29%" align="center" bgcolor="#ffffff">{$lang.goods_attr}</th>
后面增加:
<!--{if $smarty.session.user_id}-->
              <th bgcolor="#ffffff">{$lang.my_goods_comment}</th>
              <!--{/if}-->
 
 
在:
<td align="left" bgcolor="#ffffff">{$goods.goods_attr|nl2br}</td>
后边增加:
<!--{if $smarty.session.user_id}-->
              <td align="right" bgcolor="#ffffff">
              {$goods.goods_comment}
               </td>
              <!--{/if}-->
 
 
【4】themes\default\goods.dwt文件中:
<li class="padd">
      <a href="javascript:addToCart({$goods.goods_id})"><img src="images/bnt_cat.gif" /></a>
      <a href="javascript:collect({$goods.goods_id})"><img src="images/bnt_colles.gif" /></a>
      <!-- {if $affiliate.on} -->
      <a href="user.php?act=affiliate&goodsid={$goods.goods_id}"><img src='images/bnt_recommend.gif'></a>
      <!-- {/if} -->
      </li>
后边增加:
<li>
      <!--{if $smarty.session.user_id}-->
      {$lang.my_goods_comment}:<textarea onclick="addGoodsComment(this, {$goods.goods_id})" style="width:90%;">{$goods.goods_comment}</textarea>
      <!--{/if}-->
      </li>
 
 
【5】themes\default\flow.dwt文件中:
<th bgcolor="#ffffff">{$lang.goods_name}</th>
      <!-- {if $show_goods_attribute eq 1} 显示商品属性 -->
              <th bgcolor="#ffffff">{$lang.goods_attr}</th>
              <!-- {/if} -->
后边增加:
<!--{if $smarty.session.user_id}-->
              <th bgcolor="#ffffff">{$lang.my_goods_comment}</th>
              <!--{/if}-->
 
 
在:
<!-- {if $show_goods_attribute eq 1} 显示商品属性 -->
              <td bgcolor="#ffffff">{$goods.goods_attr|nl2br}</td>
<!--{/if}-->
后边增加:
<!--{if $smarty.session.user_id}-->
              <td align="right" bgcolor="#ffffff">
              <textarea onclick="addGoodsComment(this, {$goods.goods_id})" style="width:90%;">{$goods.goods_comment}</textarea>
               </td>
              <!-- {/if} -->
 
 
在:
<th bgcolor="#ffffff">{$lang.goods_name}</th>
              <th bgcolor="#ffffff">{$lang.goods_attr}</th>
后边增加:
<!--{if $smarty.session.user_id}-->
              <th bgcolor="#ffffff">{$lang.my_goods_comment}</th>
              <!--{/if}-->
 
 
在:
<!-- {if $goods.is_shipping} -->(<span style="color:#FF0000">{$lang.free_goods}</span>)<!-- {/if} -->
              </td>
              <td bgcolor="#ffffff">{$goods.goods_attr|nl2br}</td>
后边增加:
<!--{if $smarty.session.user_id}-->
              <td align="right" bgcolor="#ffffff">
              <textarea onclick="addGoodsComment(this, {$goods.goods_id})" style="width:90%;">{$goods.goods_comment}</textarea>
               </td>
              <!--{/if}-->
 
 
【6】languages\zh_cn\admin\common.php文件中增加:
$_LANG['my_goods_comment'] = '批注';
 
 
【7】languages\zh_cn\common.php文件中增加:
$_LANG['my_goods_comment'] = '批注';
 
 
【8】js\common.js文件中增加:
/*
 * 将用户对商品的批注写到数据库中 
 */
function addGoodsComment(obj, goodsId)
{
    /* 保存原始的内容 */
    var orgComment = obj.value;
 
 
    /* 编辑区失去焦点的处理函数 */
    obj.onblur = function(e)
    {
        var newComment = obj.value;
 
        if (newComment != orgComment)
        {
            res = Ajax.call("./goods.php?is_ajax=1", "act=edit_goods_comment&val=" + encodeURIComponent(Utils.trim(newComment)).toJSONString() + "&id=" +goodsId, null, "POST", "JSON", false);
 
 
            if (res.message)
            {
                alert(res.message);
            }
        }  
    }
}
 
 
【9】includes\lib_order.php文件中:
$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 rec_id, order_goods.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, oc.goods_comment " .
            "FROM " . $GLOBALS['ecs']->table('order_goods') . " " .
            "LEFT JOIN order_comment as oc ON oc.goods_id = order_goods.goods_id AND oc.order_id = '" . $order_id . "' ".
            "WHERE order_goods.order_id = '$order_id'";
 
 
将:
$sql = "SELECT rec_id, user_id, goods_id, goods_name, goods_sn, goods_number, " .
            "market_price, goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, is_shipping, " .
            "goods_price * goods_number AS subtotal " .
            "FROM " . $GLOBALS['ecs']->table('cart') .
            " WHERE session_id = '" . SESS_ID . "' " .
            "AND rec_type = '$type'";
改为:
$sql = "SELECT rec_id, cart.user_id, cart.goods_id, goods_name, goods_sn, goods_number, " .
            "market_price, goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, is_shipping, " .
            "goods_price * goods_number AS subtotal, gc.goods_comment " .
            "FROM " . $GLOBALS['ecs']->table('cart') . " " .
            "LEFT JOIN goods_comment as gc ON gc.goods_id = cart.goods_id AND gc.user_id = cart.user_id ".
            "WHERE session_id = '" . SESS_ID . "' " .
            "AND rec_type = '$type'";
 
 
将:
/* 循环、统计 */
    $sql = "SELECT *, IF(parent_id, parent_id, goods_id) AS pid " .
            " FROM " . $GLOBALS['ecs']->table('cart') . " " .
            " WHERE session_id = '" . SESS_ID . "' AND rec_type = '" . CART_GENERAL_GOODS . "'" .
            " ORDER BY pid, parent_id";
改为:
/* 循环、统计 */
    $sql = "SELECT *, IF(parent_id, parent_id, cart.goods_id) AS pid, gc.goods_comment " .
            " FROM " . $GLOBALS['ecs']->table('cart') . " " .
            "LEFT JOIN goods_comment as gc ON gc.goods_id = cart.goods_id AND gc.user_id = cart.user_id ".
            "WHERE session_id = '" . SESS_ID . "' AND rec_type = '" . CART_GENERAL_GOODS . "'" .
            "ORDER BY pid, parent_id";
 
 
【10】includes\lib_goods.php文件中:
$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";
改为:
$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, gc.goods_comment " .
            '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]' ".
            "LEFT JOIN goods_comment as gc ON gc.goods_id = g.goods_id AND gc.user_id = '" . $_SESSION[user_id] . "' ".
            "WHERE g.goods_id = '$goods_id' AND g.is_delete = 0 " .
            "GROUP BY g.goods_id";
支付宝扫码打赏 微信打赏

如果文章对您有帮助,就打赏一个吧

在线客服

客户服务

热线电话:

0755-36656507 15889489919 服务时间:

周一到周六:9:00-18:00

在线QQ客服

在线微信客服

关于我们 常见问题

支付方式 加盟合作

提交需求
优惠红包 购物车0 返回顶部