1. 每个ecshop登录的用户在购物过程中的商品列表页、商品详细页、购物车都可以对商品进行批注;
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】themesdefaultlibrarygoods_list.lbi文件中:
{$lang.compare}
后边增加:
{$lang.my_goods_comment}:
【3】themesdefaultuser_transaction.dwt文件中:
{$lang.goods_name} |
{$lang.goods_attr} |
后面增加:
{$lang.my_goods_comment} |
在:
{$goods.goods_attr|nl2br}
后边增加:
{$goods.goods_comment}
【4】themesdefaultgoods.dwt文件中:
后边增加:
{$lang.my_goods_comment}:
【5】themesdefaultflow.dwt文件中:
{$lang.goods_name} |
{$lang.goods_attr} |
后边增加:
{$lang.my_goods_comment} |
在:
{$goods.goods_attr|nl2br}
后边增加:
在:
{$lang.goods_name} |
{$lang.goods_attr} |
后边增加:
{$lang.my_goods_comment} |
在:
({$lang.free_goods})
{$goods.goods_attr|nl2br}
后边增加:
【6】languageszh_cnadmincommon.php文件中增加:
$_LANG['my_goods_comment'] = '批注';
【7】languageszh_cncommon.php文件中增加:
$_LANG['my_goods_comment'] = '批注';
【8】jscommon.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】includeslib_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】includeslib_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";
【11】includescls_template.php文件中:
注释掉:
if (file_put_contents($hash_dir . '/' . $cachename . '.php', '' . $data . $out, LOCK_EX) === false)
{
trigger_error('can't write:' . $hash_dir . '/' . $cachename . '.php');
}
【12】includescls_mysql.php文件中:
var $max_cache_time的值改为0。如下:
var $max_cache_time = 0; // 最大的缓存时间,以秒为单位
【13】dataorder_print.html文件中:
{$lang.goods_name}
{$lang.goods_sn}
{$lang.goods_attr}
{$lang.goods_price}
{$lang.goods_number}
{$lang.subtotal}
{$goods.goods_name}
{if $goods.is_gift}{if $goods.goods_price gt 0}{$lang.remark_favourable}{else}{$lang.remark_gift}{/if}{/if}
{if $goods.parent_id gt 0}{$lang.remark_fittings}{/if}
{$goods.goods_sn}
{$attr.name}:{$attr.value}
{$goods.formated_goods_price}
{$goods.goods_number}
{$goods.formated_subtotal}
{if $order.inv_payee}
{$lang.label_inv_payee}{$order.inv_payee}
{$lang.label_inv_content}{$order.inv_content}
{/if}
{$lang.label_goods_amount}{$order.formated_goods_amount}
改为:
{$lang.goods_name}
{$lang.goods_sn}
{$lang.goods_attr}
{$lang.my_goods_comment}
{$lang.goods_price}
{$lang.goods_number}
{$lang.subtotal}
{$goods.goods_name}
{if $goods.is_gift}{if $goods.goods_price gt 0}{$lang.remark_favourable}{else}{$lang.remark_gift}{/if}{/if}
{if $goods.parent_id gt 0}{$lang.remark_fittings}{/if}
{$goods.goods_sn}
{$attr.name}:{$attr.value}
{$goods.goods_comment}
{$goods.formated_goods_price}
{$goods.goods_number}
{$goods.formated_subtotal}
{if $order.inv_payee}
{$lang.label_inv_payee}{$order.inv_payee}
{$lang.label_inv_content}{$order.inv_content}
{/if}
{$lang.label_goods_amount}{$order.formated_goods_amount}
【14】admintemplatesorder_info.htm文件中:
{$lang.goods_info}{$lang.edit} |
{$lang.goods_name_brand}
{$lang.goods_sn}
{$lang.product_sn}
{$lang.goods_price}
{$lang.goods_number}
{$lang.goods_attr}
{$lang.storage}
{$lang.subtotal}
{foreach from=$goods_list item=goods}
{if $goods.goods_id gt 0 && $goods.extension_code neq 'package_buy'}
{$goods.goods_name} {if $goods.brand_name}[ {$goods.brand_name} ]{/if}
{if $goods.is_gift}{if $goods.goods_price > 0}{$lang.remark_favourable}{else}{$lang.remark_gift}{/if}{/if}
{if $goods.parent_id > 0}{$lang.remark_fittings}{/if}
{elseif $goods.goods_id gt 0 && $goods.extension_code eq 'package_buy'}
{$goods.goods_name}{$lang.remark_package}
{foreach from=$goods.package_goods_list item=package_goods_list}
{$package_goods_list.goods_name}
{/foreach}
{/if}
{$goods.goods_sn}
{$goods.product_sn}
{$goods.formated_goods_price}
{$goods.goods_number}
{$goods.goods_attr|nl2br}
{$goods.storage}
{$goods.formated_subtotal}
{/foreach}
{if $order.total_weight}{$lang.label_total_weight}
{/if}
{if $order.total_weight}{$order.total_weight}
{/if}
{$lang.label_total}
{$order.formated_goods_amount}
改为:
{$lang.goods_info}{$lang.edit} |
{$lang.goods_name_brand}
{$lang.goods_sn}
{$lang.product_sn}
{$lang.goods_price}
{$lang.goods_number}
{$lang.goods_attr}
{$lang.my_goods_comment}
{$lang.storage}
{$lang.subtotal}
{foreach from=$goods_list item=goods}
{if $goods.goods_id gt 0 && $goods.extension_code neq 'package_buy'}
{$goods.goods_name} {if $goods.brand_name}[ {$goods.brand_name} ]{/if}
{if $goods.is_gift}{if $goods.goods_price > 0}{$lang.remark_favourable}{else}{$lang.remark_gift}{/if}{/if}
{if $goods.parent_id > 0}{$lang.remark_fittings}{/if}
{elseif $goods.goods_id gt 0 && $goods.extension_code eq 'package_buy'}
{$goods.goods_name}{$lang.remark_package}
{foreach from=$goods.package_goods_list item=package_goods_list}
{$package_goods_list.goods_name}
{/foreach}
{/if}
{$goods.goods_sn}
{$goods.product_sn}
{$goods.formated_goods_price}
{$goods.goods_number}
{$goods.goods_attr|nl2br}
{$goods.goods_comment}
{$goods.storage}
{$goods.formated_subtotal}
{/foreach}
{if $order.total_weight}{$lang.label_total_weight}
{/if}
{if $order.total_weight}{$order.total_weight}
{/if}
{$lang.label_total}
{$order.formated_goods_amount}
【15】order_goods_info.htm文件改为:
{$lang.goods_name_brand}
{$lang.goods_sn}
{$lang.goods_price}
{$lang.goods_number}
{$lang.goods_attr}
{$lang.my_goods_comment}
{$lang.storage}
{$lang.subtotal}
{foreach from=$goods_list item=goods}
{if $goods.goods_id gt 0 && $goods.extension_code neq 'package_buy'}
{$goods.goods_name} {if $goods.brand_name}[ {$goods.brand_name} ]{/if}
{if $goods.is_gift}{if $goods.goods_price > 0}{$lang.remark_favourable}{else}{$lang.remark_gift}{/if}{/if}
{if $goods.parent_id > 0}{$lang.remark_fittings}{/if}
{else}
{$goods.goods_name}{$lang.remark_package}
{/if}
{$goods.goods_sn}
{$goods.formated_goods_price}
{$goods.goods_number}
{$goods.goods_attr|nl2br}
{$goods.goods_comment}
{$goods.storage}
{$goods.formated_subtotal}
{/foreach}
【16】adminorder.php文件中:
$sql = "SELECT o.*, IF(o.product_id > 0, p.product_number, g.goods_number) AS storage, o.goods_attr, g.suppliers_id, IFNULL(b.brand_name, '') AS brand_name, p.product_sn
FROM " . $ecs->table('order_goods') . " AS o
LEFT JOIN " . $ecs->table('products') . " AS p
ON p.product_id = o.product_id
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.*, IF(o.product_id > 0, p.product_number, g.goods_number) AS storage, o.goods_attr, g.suppliers_id, IFNULL(b.brand_name, '') AS brand_name, p.product_sn
, oc.goods_comment FROM " . $ecs->table('order_goods') . " AS o
LEFT JOIN " . $ecs->table('products') . " AS p
ON p.product_id = o.product_id
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 " .
"LEFT JOIN order_comment as oc ON oc.goods_id = o.goods_id AND oc.order_id = '" . $order[order_id] . "' ".
"WHERE o.order_id = '$order[order_id]'";
把:
$sql = "SELECT o.*, g.goods_thumb, 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_id}' ";
改为:
$sql = "SELECT o.*, g.goods_thumb, g.goods_number AS storage, o.goods_attr, IFNULL(b.brand_name, '') AS brand_name, oc.goods_comment " .
"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 " .
"LEFT JOIN order_comment as oc ON oc.goods_id = o.goods_id AND oc.order_id = '" . $order_id . "' ".
"WHERE o.order_id = '$order_id' ";
【17】user.php文件中:
if ($rt > 0)
{
update_user_info();
recalculate_price();
$ucdata = isset($user->ucdata)? $user->ucdata : '';
show_message($_LANG['login_success'] . $ucdata , array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act,'user.php'), 'info');
}
改为:
if ($rt > 0)
{
//Delete the goods_comment when the user login
$sql = "DELETE FROM goods_comment WHERE user_id = '". $_SESSION["user_id"] ."'";
$GLOBALS['db']->query($sql);
update_user_info();
recalculate_price();
$ucdata = isset($user->ucdata)? $user->ucdata : '';
show_message($_LANG['login_success'] . $ucdata , array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act,'user.php'), 'info');
}
【18】index.php中注释掉:
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
$uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i";
if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap'))
{
$Loaction = 'mobile/';
if (!empty($Loaction))
{
ecs_header("Location: $Loactionn");
exit;
}
}
【19】goods.php中增加函数:
/*------------------------------------------------------ */
//-- 修改商品批注
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'edit_goods_comment')
{
include('includes/cls_json.php');
$json = new JSON;
$res = array('err_msg' => '', 'result' => '');
$goods_id = intval($_POST['id']);
$_POST['val'] = json_str_iconv($_POST['val']);
$goods_comment = $json->decode($_POST['val']);
$sql = "DELETE FROM goods_comment WHERE goods_id = '". $goods_id. "' AND user_id = '". $_SESSION["user_id"] ."'";
$GLOBALS['db']->query($sql);
$sql = "INSERT INTO goods_comment (goods_id, user_id, goods_comment) VALUES ('". $goods_id."', '".$_SESSION["user_id"]."', '".$goods_comment."')";
$GLOBALS['db']->query($sql);
$res['result'] = $goods_comment;
die($json->encode($res));
}
【20】flow.php文件中:
在:
/* 插入订单商品 */
$sql = "INSERT INTO " . $ecs->table('order_goods') . "( " .
"order_id, goods_id, goods_name, goods_sn, product_id, goods_number, market_price, ".
"goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, goods_attr_id) ".
" SELECT '$new_order_id', goods_id, goods_name, goods_sn, product_id, goods_number, market_price, ".
"goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, goods_attr_id".
" FROM " .$ecs->table('cart') .
" WHERE session_id = '".SESS_ID."' AND rec_type = '$flow_type'";
$db->query($sql);
后边增加:
/* 插入订单商品批注 */
$sql = "INSERT INTO order_comment (order_id, goods_id, goods_comment) ".
"(SELECT '$new_order_id', cart.goods_id, gc.goods_comment ".
"FROM cart LEFT JOIN goods_comment as gc ON gc.goods_id = cart.goods_id AND gc.user_id = cart.user_id)";
$db->query($sql);
【21】category.php文件中:
/* 获得商品列表 */
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_sn, g.goods_weight, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " .
'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' .
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' .
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " .
"WHERE $where $ext ORDER BY $sort $order";
改为:
/* 获得商品列表 */
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_sn, g.goods_weight, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " .
'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img, gc.goods_comment ' .
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
'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 $where $ext ORDER BY $sort $order";
在:
$arr[$row['goods_id']]['name'] = $row['goods_name'];
$arr[$row['goods_id']]['goods_brief'] = $row['goods_brief'];
$arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);
$arr[$row['goods_id']]['market_price'] = price_format($row['market_price']);
$arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
$arr[$row['goods_id']]['type'] = $row['goods_type'];
$arr[$row['goods_id']]['promote_price'] = ($promote_price > 0) ? price_format($promote_price) : '';
$arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$arr[$row['goods_id']]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
$arr[$row['goods_id']]['goods_sn'] = $row['goods_sn'];
$arr[$row['goods_id']]['goods_weight'] = $row['goods_weight'];
后边增加:
/* 获取批注 */
$arr[$row['goods_id']]['goods_comment'] = $row['goods_comment'];
打赏
打赏
扫码打赏,你说多少就多少
打开支付宝扫一扫,即可进行扫码打赏哦
百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!