ECSHOP指定某商品不能使用红包

2016-09-02 16:28 来源:www.chinab4c.com 作者:ecshop专家

在ECSHOP中,自带的红包功能很好用,但是不能指定红包适用的范围,比如某些商品为特价商品的话,可以设置此商品不能使用红包,下面我们ECSHOP插件网提供如下方法即可实现 第一步:在goods表格增加一个字段 is_bonus 类型 tinyint 默认为1 (1是可以使用红包),进入后台“SQL查询”输入以下代码,提交 注意:如果你的数据表前缀 不是 ecs_ 请自行修改 ALTER TABLE `ecs_goods` ADD `is_bonus` tinyint(1) unsigned NOTNULLDEFAULT \'1\'; 第二步:修改后台模板页goods_info.htm文件,找到如下代码: {$lang.lab_is_on_sale} {$lang.on_sale_desc} 在以上这段代码的下面加: 红包使用: 打勾表示允许用使用红包,否则不允许使用。 第三步:修改后台goods.php文件,找到如下代码: $goods = array( \'goods_id\' => 0, \'goods_desc\' => \'\', \'cat_id\' => $last_choose[0], \'brand_id\' => $last_choose[1], \'is_on_sale\' => \'1\', \'is_alone_sale\' => \'1\', \'is_shipping\' => \'0\', \'other_cat\' => array(), // 扩展分类 \'goods_type\' => 0, // 商品类型 \'shop_price\' => 0, \'promote_price\' => 0, \'market_price\' => 0, \'integral\' => 0, \'goods_number\' => $_CFG[\'default_storage\'], \'warn_number\' => 1, \'promote_start_date\' => local_date(\'Y-m-d\'), \'promote_end_date\' => local_date(\'Y-m-d\', local_strtotime(\'+1 month\')), \'goods_weight\' => 0, \'give_integral\' => -1, \'rank_integral\' => -1 ); 将以上这段代码修改为如下: $goods = array( \'goods_id\' => 0, \'goods_desc\' => \'\', \'cat_id\' => $last_choose[0], \'brand_id\' => $last_choose[1], \'is_on_sale\' => \'1\', \'is_bonus\' => \'1\', \'is_alone_sale\' => \'1\', \'is_shipping\' => \'0\', \'other_cat\' => array(), // 扩展分类 \'goods_type\' => 0, // 商品类型 \'shop_price\' => 0, \'promote_price\' => 0, \'market_price\' => 0, \'integral\' => 0, \'goods_number\' => $_CFG[\'default_storage\'], \'warn_number\' => 1, \'promote_start_date\' => local_date(\'Y-m-d\'), \'promote_end_date\' => local_date(\'Y-m-d\', local_strtotime(\'+1 month\')), \'goods_weight\' => 0, \'give_integral\' => -1, \'rank_integral\' => -1 ); 再找到如下代码: if (empty($goods) === true) { /* 默认值 */ $goods = array( \'goods_id\' => 0, \'goods_desc\' => \'\', \'cat_id\' => 0, \'is_on_sale\' => \'1\', \'is_alone_sale\' => \'1\', \'is_shipping\' => \'0\', \'other_cat\' => array(), // 扩展分类 \'goods_type\' => 0, // 商品类型 \'shop_price\' => 0, \'promote_price\' => 0, \'market_price\' => 0, \'integral\' => 0, \'goods_number\' => 1, \'warn_number\' => 1, \'promote_start_date\' => local_date(\'Y-m-d\'), \'promote_end_date\' => local_date(\'Y-m-d\', gmstr2tome(\'+1 month\')), \'goods_weight\' => 0, \'give_integral\' => -1, \'rank_integral\' => -1 ); } 将以上这段代码修改为如下: if (empty($goods) === true) { /* 默认值 */ $goods = array( \'goods_id\' => 0, \'goods_desc\' => \'\', \'cat_id\' => 0, \'is_on_sale\' => \'1\', \'is_bonus\' => \'1\', \'is_alone_sale\' => \'1\', \'is_shipping\' => \'0\', \'other_cat\' => array(), // 扩展分类 \'goods_type\' => 0, // 商品类型 \'shop_price\' => 0, \'promote_price\' => 0, \'market_price\' => 0, \'integral\' => 0, \'goods_number\' => 1, \'warn_number\' => 1, \'promote_start_date\' => local_date(\'Y-m-d\'), \'promote_end_date\' => local_date(\'Y-m-d\', gmstr2tome(\'+1 month\')), \'goods_weight\' => 0, \'give_integral\' => -1, \'rank_integral\' => -1 ); } 再找到如下代码: $is_on_sale = isset($_POST[\'is_on_sale\']) ? 1 : 0; 在以上这段代码的下面加: $is_bonus = isset($_POST[\'is_bonus\']) ? 1 : 0; 再找到如下代码: if ($code == \'\') { $sql = \"INSERT INTO \" . $ecs->table(\'goods\') . \" (goods_name, goods_name_style, goods_sn, \" . \"cat_id, brand_id, shop_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, is_shipping, goods_desc, add_time, last_update, goods_type, rank_integral, suppliers_id)\" . \"VALUES (\'$_POST[goods_name]\', \'$goods_name_style\', \'$goods_sn\', \'$catgory_id\', \" . \"\'$brand_id\', \'$shop_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\', $is_shipping, \". \" \'$_POST[goods_desc]\', \'\" . gmtime() . \"\', \'\". gmtime() .\"\', \'$goods_type\', \'$rank_integral\', \'$suppliers_id\')\"; } else { $sql = \"INSERT INTO \" . $ecs->table(\'goods\') . \" (goods_name, goods_name_style, goods_sn, \" . \"cat_id, brand_id, shop_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, is_shipping, 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\', \'$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\', $is_shipping, \". \" \'$_POST[goods_desc]\', \'\" . gmtime() . \"\', \'\". gmtime() .\"\', \'$goods_type\', \'$code\', \'$rank_integral\')\"; } 将以上这段代码修改为如下: if ($code == \'\') { $sql = \"INSERT INTO \" . $ecs->table(\'goods\') . \" (goods_name, goods_name_style, goods_sn, \" . \"cat_id, brand_id, shop_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_bonus, is_alone_sale, is_shipping, goods_desc, add_time, last_update, goods_type, rank_integral, suppliers_id)\" . \"VALUES (\'$_POST[goods_name]\', \'$goods_name_style\', \'$goods_sn\', \'$catgory_id\', \" . \"\'$brand_id\', \'$shop_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_bonus\', \'$is_alone_sale\', $is_shipping, \". \" \'$_POST[goods_desc]\', \'\" . gmtime() . \"\', \'\". gmtime() .\"\', \'$goods_type\', \'$rank_integral\', \'$suppliers_id\')\"; } else { $sql = \"INSERT INTO \" . $ecs->table(\'goods\') . \" (goods_name, goods_name_style, goods_sn, \" . \"cat_id, brand_id, shop_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_bonus, is_alone_sale, is_shipping, 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\', \'$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_bonus\', \'$is_alone_sale\', $is_shipping, \". \" \'$_POST[goods_desc]\', \'\" . gmtime() . \"\', \'\". gmtime() .\"\', \'$goods_type\', \'$code\', \'$rank_integral\')\"; } 再找到如下代码: \"is_on_sale = \'$is_on_sale\', \" . 在以上这段代码的下面加: \"is_bonus = \'$is_bonus\', \" . 再找到如下代码: /*------------------------------------------------------ */ //-- 排序、分页、查询 /*------------------------------------------------------ */ elseif ($_REQUEST[\'act\'] == \'query\') 在以上这段代码的上面加: /*------------------------------------------------------ */ //-- 修改红包使用状态 /*------------------------------------------------------ */ elseif ($_REQUEST[\'act\'] == \'toggle_bonus\') { check_authz_json(\'goods_manage\'); $goods_id = intval($_POST[\'id\']); $is_bonus = intval($_POST[\'val\']); if ($exc->edit(\"is_bonus = \'$is_bonus\', last_update=\" .gmtime(), $goods_id)) { clear_cache_files(); make_json_result($is_bonus); } } 第四步:修改后台模板页goods_list.htm文件,找到如下代码: {$lang.is_hot}{$sort_is_hot} 在以上这段代码的下面加: 红包{$sort_is_bonus} 再找到如下代码: 在以上这段代码的下面加: 再找到如下代码: 在以上这段代码的下面加: 第五步:在cart表格增加一个字段 is_bonus 类型 tinyint 默认为1 (1是可以使用红包),进入后台“SQL查询”输入以下代码,提交 注意:如果你的数据表前缀 不是 ecs_ 请自行修改 ALTER TABLE `ecs_cart` ADD `is_bonus` tinyint(1) unsigned NOT NULL DEFAULT \'1\'; 第六步:打开includes/lib_order.php文件,找到如下代码: /* 商品总价 */ foreach ($goods AS $val) { /* 统计实体商品的个数 */ if ($val[\'is_real\']) { $total[\'real_goods_count\']++; } 在以上这段代码的下面加: if ($val[\'is_bonus\']) { $total[\'goods_bonus_price\'] += $val[\'goods_price\'] * $val[\'goods_number\']; } 再找到如下代码: function addto_cart($goods_id, $num = 1, $spec = array(), $parent = 0) { $GLOBALS[\'err\']->clean(); $_parent_id = $parent; /* 取得商品信息 */ $sql = \"SELECT g.goods_name, g.goods_sn, g.is_on_sale, g.is_real, \". 将以上这段代码修改为如下: function addto_cart($goods_id, $num = 1, $spec = array(), $parent = 0) { $GLOBALS[\'err\']->clean(); $_parent_id = $parent; /* 取得商品信息 */ $sql = \"SELECT g.goods_name, g.goods_sn, g.is_on_sale, g.is_real, g.is_bonus, \". 再找到如下代码: /* 初始化要插入购物车的基本件数据 */ $parent = array( \'user_id\' => $_SESSION[\'user_id\'], \'session_id\' => SESS_ID, \'goods_id\' => $goods_id, \'goods_sn\' => addslashes($goods[\'goods_sn\']), \'product_id\' => $product_info[\'product_id\'], \'goods_name\' => addslashes($goods[\'goods_name\']), \'market_price\' => $goods[\'market_price\'], \'goods_attr\' => addslashes($goods_attr), \'goods_attr_id\' => $goods_attr_id, \'is_real\' => $goods[\'is_real\'], \'extension_code\'=> $goods[\'extension_code\'], \'is_gift\' => 0, \'is_shipping\' => $goods[\'is_shipping\'], \'rec_type\' => CART_GENERAL_GOODS ); 将以上这段代码修改为如下: /* 初始化要插入购物车的基本件数据 */ $parent = array( \'user_id\' => $_SESSION[\'user_id\'], \'session_id\' => SESS_ID, \'goods_id\' => $goods_id, \'goods_sn\' => addslashes($goods[\'goods_sn\']), \'product_id\' => $product_info[\'product_id\'], \'goods_name\' => addslashes($goods[\'goods_name\']), \'market_price\' => $goods[\'market_price\'], \'goods_attr\' => addslashes($goods_attr), \'goods_attr_id\' => $goods_attr_id, \'is_real\' => $goods[\'is_real\'], \'extension_code\'=> $goods[\'extension_code\'], \'is_gift\' => 0, \'is_bonus\' => $goods[\'is_bonus\'], \'is_shipping\' => $goods[\'is_shipping\'], \'rec_type\' => CART_GENERAL_GOODS ); 第六步:打开后台admin/includes/lib_goods.php文件,找到如下代码: $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, \" . \" (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]\"; 将以上这段代码修改为如下: $sql = \"SELECT goods_id, goods_name, goods_type, goods_sn, shop_price, is_on_sale, is_best, is_new, is_hot, is_bonus, sort_order, goods_number, integral, \" . \" (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]\"; 最后一步就是打开flow.php文件,找到如下代码: /* 如果使用红包,取得用户可以使用的红包及用户选择的红包 */ if ((!isset($_CFG[\'use_bonus\']) || $_CFG[\'use_bonus\'] == \'1\') && ($flow_type != CART_GROUP_BUY_GOODS && $flow_type != CART_EXCHANGE_GOODS)) { // 取得用户可用红包 $user_bonus = user_bonus($_SESSION[\'user_id\'], $total[\'goods_price\']); 将以上这段代码修改为如下: /* 如果使用红包,取得用户可以使用的红包及用户选择的红包 */ if ((!isset($_CFG[\'use_bonus\']) || $_CFG[\'use_bonus\'] == \'1\') && ($flow_type != CART_GROUP_BUY_GOODS && $flow_type != CART_EXCHANGE_GOODS)) { // 取得用户可用红包 $user_bonus = user_bonus($_SESSION[\'user_id\'], $total[\'goods_bonus_price\']); 以下为截图: