Commit 47b4b753eb82e93b52754a66d16d545cdae731c0
1 parent
ff3268f4
在加入购物车中的优化计算
Showing
2 changed files
with
40 additions
and
9 deletions
pages/cart/cart/cart.js
| ... | ... | @@ -695,7 +695,7 @@ Page({ | 
| 695 | 695 | }) | 
| 696 | 696 | |
| 697 | 697 | if (is_g_prom) { | 
| 698 | - await getApp().request.promiseGet("/api/weshop/goods/getGoodsPromList/" + os.stoid + "/" + item.goods_id + "/1" + "/" + getApp().globalData.user_id, {}).then(res => { | |
| 698 | + await getApp().request.promiseGet("/api/weshop/goods/getGoodsPromListNew/" + os.stoid + "/" + item.goods_id + "/1" + "/" + getApp().globalData.user_id, {}).then(res => { | |
| 699 | 699 | if (res.data.code == 0) { | 
| 700 | 700 | var r_data = res.data.data; | 
| 701 | 701 | if (!r_data.promGoodsLists) { | 
| ... | ... | @@ -1169,7 +1169,7 @@ Page({ | 
| 1169 | 1169 | let updata1 = { | 
| 1170 | 1170 | id: item.id, | 
| 1171 | 1171 | prom_type: 0, | 
| 1172 | - prom_id: item.prom_id, | |
| 1172 | + prom_id: 0, | |
| 1173 | 1173 | store_id: os.stoid, | 
| 1174 | 1174 | user_id: getApp().globalData.userInfo.user_id | 
| 1175 | 1175 | }; | 
| ... | ... | @@ -4379,7 +4379,7 @@ Page({ | 
| 4379 | 4379 | good_url = "/packageC/pages/presell/goodsInfo/goodsInfo?goods_id=" + gd + "&prom_id=" + item.act_id | 
| 4380 | 4380 | break; | 
| 4381 | 4381 | default: | 
| 4382 | - good_url = "/pages/goods/goodsInfo/goodsInfo?goods_id=" + gd + "&prom_id=" + item.act_id + "&prom_type=1"; | |
| 4382 | + good_url = "/pages/goods/goodsInfo/goodsInfo?goods_id=" + gd + "&prom_id=" + item.act_id + "&prom_type="+item.prom_type; | |
| 4383 | 4383 | break | 
| 4384 | 4384 | } | 
| 4385 | 4385 | } | ... | ... | 
pages/goods/goodsInfo/goodsInfo.js
| ... | ... | @@ -1992,11 +1992,16 @@ Page({ | 
| 1992 | 1992 | //if (this.data.data.goods.is_virtual) return this.buyVirtualGoods(d); | 
| 1993 | 1993 | if ("add" == t.currentTarget.dataset.action) { | 
| 1994 | 1994 | |
| 1995 | - if (th.data.prom_goods && !th.data.sele_g.whsle_id) { | |
| 1995 | + if (newd.prom_type==0 && th.data.prom_goods && !th.data.sele_g.whsle_id) { | |
| 1996 | 1996 | newd.prom_type = 3; | 
| 1997 | 1997 | newd.prom_id = th.data.prom_goods[0].prom_id; | 
| 1998 | 1998 | } | 
| 1999 | 1999 | |
| 2000 | + if( [3,5,10].indexOf(newd.prom_type)>-1){ | |
| 2001 | + newd.prom_type=0; | |
| 2002 | + newd.prom_id=0; | |
| 2003 | + } | |
| 2004 | + | |
| 2000 | 2005 | //----先看会员在购物车中是否加入了该商品----- | 
| 2001 | 2006 | i.get("/api/weshop/cart/page", { | 
| 2002 | 2007 | data: { | 
| ... | ... | @@ -2004,14 +2009,25 @@ Page({ | 
| 2004 | 2009 | user_id: oo.user_id, | 
| 2005 | 2010 | goods_id: a, | 
| 2006 | 2011 | pick_id: e.data.sto_sele_id, | 
| 2007 | - state: 0 | |
| 2012 | + state: 0, | |
| 2008 | 2013 | }, | 
| 2009 | 2014 | success: function (re) { | 
| 2010 | 2015 | |
| 2016 | + //-- 判断活动是不是一样 -- | |
| 2017 | + var item=null; | |
| 2011 | 2018 | //-------如果购物车中有相关的数据--------- | 
| 2012 | 2019 | if (re.data.data.total > 0) { | 
| 2013 | 2020 | |
| 2014 | - var item = re.data.data.pageData[0]; | |
| 2021 | + for (var i=0; i<re.data.data.pageData.length; i++) { | |
| 2022 | + if(th.check_is_like(re.data.data.pageData[i],newd)) continue; | |
| 2023 | + item=re.data.data.pageData[i]; | |
| 2024 | + break; | |
| 2025 | + | |
| 2026 | + } | |
| 2027 | + } | |
| 2028 | + | |
| 2029 | + if(item){ | |
| 2030 | + item = re.data.data.pageData[0]; | |
| 2015 | 2031 | |
| 2016 | 2032 | //判断数量,要看下购物车中有没有该商品 | 
| 2017 | 2033 | if (CanOutQty) { | 
| ... | ... | @@ -2066,9 +2082,7 @@ Page({ | 
| 2066 | 2082 | th.closeSpecModal(); | 
| 2067 | 2083 | } | 
| 2068 | 2084 | }); | 
| 2069 | - } else { | |
| 2070 | - | |
| 2071 | - | |
| 2085 | + }else { | |
| 2072 | 2086 | i.post("/api/weshop/cart/save", { | 
| 2073 | 2087 | data: newd, | 
| 2074 | 2088 | success: function (t) { | 
| ... | ... | @@ -2193,6 +2207,18 @@ Page({ | 
| 2193 | 2207 | } | 
| 2194 | 2208 | }, | 
| 2195 | 2209 | |
| 2210 | + //因为在购物车 普通商品和 优惠促销,搭配购,组合购 阶梯购是一样的 | |
| 2211 | + check_is_like(e,newd){ | |
| 2212 | + if(e.prom_type ==newd.prom_type) return true; | |
| 2213 | + if(e.prom_type==0){ | |
| 2214 | + if([3,5,7,10].indexOf(newd.prom_type)>-1) return true; | |
| 2215 | + } | |
| 2216 | + if(newd.prom_type==0){ | |
| 2217 | + if([3,5,7,10].indexOf(e.prom_type)>-1) return true; | |
| 2218 | + } | |
| 2219 | + return false; | |
| 2220 | + }, | |
| 2221 | + | |
| 2196 | 2222 | |
| 2197 | 2223 | //----------购买虚拟商品------ | 
| 2198 | 2224 | buyVirtualGoods: function (e) { | 
| ... | ... | @@ -7511,6 +7537,11 @@ Page({ | 
| 7511 | 7537 | |
| 7512 | 7538 | //-- 检验商品的活动情况 -- | 
| 7513 | 7539 | check_gd_prom_new: function (func) { | 
| 7540 | + | |
| 7541 | + if([1,2,4,6,8,9].indexOf(parseInt(this.data.prom_type))>-1 ){ | |
| 7542 | + func(); return false; | |
| 7543 | + } | |
| 7544 | + | |
| 7514 | 7545 | var th = this; | 
| 7515 | 7546 | var user_id = getApp().globalData.user_id; | 
| 7516 | 7547 | if (!user_id) user_id = 0; | ... | ... | 
