diff --git a/components/add_purchase/add_purchase.js b/components/add_purchase/add_purchase.js index 2e05b59..cd2ddf1 100644 --- a/components/add_purchase/add_purchase.js +++ b/components/add_purchase/add_purchase.js @@ -2912,7 +2912,7 @@ Component({ }, //---加入购物车的最后一步--- - add_cart_next(e, t, a, o, newd, CanOutQty) { + async add_cart_next(e, t, a, o, newd, CanOutQty) { if (getApp().globalData.groupchat_id) { @@ -2953,6 +2953,31 @@ Component({ newd.prom_type = 0; newd.prom_id = 0; } + if(newd.prom_type==0){ + //-- 要拿一下商品有没有组合购活动 --- + var rq_url = '/api/weshop/activitylist/listGoodActInfo2New'; + var req_d = { + "store_id": os.stoid, + "goods_id": a, + "user_id": getApp().globalData.user_id, + } + + var ck_res= await getApp().request.promiseGet(rq_url, { + data: req_d, + }); + + if (ck_res.data.code == 0 && ck_res.data.data && ck_res.data.data.length > 0) { + var arr = ck_res.data.data; + var arr3 = arr.filter(function (e) { + return e.s_time < ut.gettimestamp() && e.prom_type == 7; + }) + + if (arr3 && arr3.length > 0) { + newd.zh_prom_id=arr3[0].act_id; + } + } + } + wxlog.info(getApp().globalData.user_id + '-加入购物车:' + JSON.stringify(newd)); // @@ -2985,20 +3010,11 @@ Component({ var item = null; //-------如果购物车中有相关的数据--------- if (re.data.data.total > 0) { - for (var j = 0; j < re.data.data.pageData.length; j++) { - if (!th.check_is_like(re.data.data.pageData[j], newd, 1)) continue; - item = re.data.data.pageData[j]; - break; - } - - if (!item) { for (var j = 0; j < re.data.data.pageData.length; j++) { if (!th.check_is_like(re.data.data.pageData[j], newd)) continue; item = re.data.data.pageData[j]; break; } - } - } if (item) { @@ -3040,47 +3056,27 @@ Component({ } } - var updata = { - id: item.id, - goods_num: e.data.goodsInputNum + item.goods_num, - goods_price: newd.goods_price, - member_goods_price: newd.goods_price, - store_id: th.data.stoid, - prom_id: newd.prom_id, //把活动id带上去(用于购物车失效变成有效商品) - prom_type: newd.prom_type - }; + if(newd.zh_prom_id>0 && item.zh_prom_id && newd.zh_prom_id!=item.zh_prom_id){ + wx.hideLoading(); + wx.showModal({ + title: '温馨提示', + content: '当前商品已存在购物车,是否替换参与该活动?', + success(res) { + if (res.confirm) { + wx.showLoading(); + th.add_cart_next2(e,item,newd); + }else{ + th.data.adding = 0; + } + } + }) - if (newd.is_pd_normal) { - updata.is_pd_normal = 1 + }else{ + th. add_cart_next2(e,item,newd); } - //---是不是从收藏夹出来的--- - if (th.data.c_guide_id) { - updata['guide_id'] = th.data.c_guide_id; - updata['guide_type'] = 3; //加入购物车之后就变成了3 - } else { - if (getApp().globalData.guide_id) { - updata['guide_id'] = getApp().globalData.guide_id; - updata['guide_type'] = 0; - } - } - if (getApp().globalData.groupchat_id) { - updata['groupchat_id'] = getApp().globalData.groupchat_id; - } - getApp().request.put("/api/weshop/cart/update", { - data: updata, - success: function (t) { - wx.hideLoading(); - th.data.adding = 0; - getApp().my_warnning('加入购物车成功', 1, th, 450); - var c_num = th.data.cartGoodsNum + th.data.goodsInputNum; - th.setData({ - cartGoodsNum: c_num - }); - th.closeSpecModal(); - } - }); + } else { getApp().request.post("/api/weshop/cart/save", { data: newd, @@ -3108,6 +3104,57 @@ Component({ } }, + + add_cart_next2(e,item,newd){ + let th=this; + var updata = { + id: item.id, + goods_num: e.data.goodsInputNum + item.goods_num, + goods_price: newd.goods_price, + member_goods_price: newd.goods_price, + store_id: th.data.stoid, + prom_id: newd.prom_id, //把活动id带上去(用于购物车失效变成有效商品) + prom_type: newd.prom_type + }; + + if (newd.is_pd_normal) { + updata.is_pd_normal = 1 + } + + if (newd.zh_prom_id) { + updata.zh_prom_id = newd.zh_prom_id + } + + //---是不是从收藏夹出来的--- + if (th.data.c_guide_id) { + updata['guide_id'] = th.data.c_guide_id; + updata['guide_type'] = 3; //加入购物车之后就变成了3 + } else { + if (getApp().globalData.guide_id) { + updata['guide_id'] = getApp().globalData.guide_id; + updata['guide_type'] = 0; + } + } + if (getApp().globalData.groupchat_id) { + updata['groupchat_id'] = getApp().globalData.groupchat_id; + } + + getApp().request.put("/api/weshop/cart/update", { + data: updata, + success: function (t) { + wx.hideLoading(); + th.data.adding = 0; + getApp().my_warnning('加入购物车成功', 1, th, 450); + var c_num = th.data.cartGoodsNum + th.data.goodsInputNum; + th.setData({ + cartGoodsNum: c_num + }); + th.closeSpecModal(); + } + }); + + }, + //-------------获取购买数量的总函数---------------- get_buy_num: function (gd, func) { var map = this.data.g_buy_num, diff --git a/packageB/pages/zuhegou/index/index.js b/packageB/pages/zuhegou/index/index.js index 184d4e1..131d025 100644 --- a/packageB/pages/zuhegou/index/index.js +++ b/packageB/pages/zuhegou/index/index.js @@ -1739,6 +1739,7 @@ Page({ newd.prom_type = 7; newd.prom_id = th.data.act.id; + newd.zh_prom_id = th.data.act.id; if (th.data.adding) return false; th.data.adding = 1; @@ -1767,7 +1768,8 @@ Page({ goods_price: newd.goods_price, member_goods_price: newd.goods_price, store_id: os.stoid, - state: 0 + state: 0, + zh_prom_id:th.data.act.id }; if (th.data.s_cart_num) { updata.goods_num = th.data.s_cart_num; @@ -2509,13 +2511,6 @@ Page({ } var th = this; - var index = th.data.sele_index; - var txt = "list[" + index + "].haveAdded"; - var txt1 = "list[" + index + "].num"; - var txt2 = "list[" + index + "].showNum"; - var txt3 = "list[" + index + "].cart_id"; - var txt4 = "list[" + index + "].current_price"; - var txt5 = "list[" + index + "].cart_num"; //----先看会员在购物车中是否加入了该商品----- getApp().request.get("/api/weshop/cart/page", { @@ -2527,102 +2522,140 @@ Page({ }, success: function (re) { if (re.data.data.total > 0) { - var item = re.data.data.pageData[0]; - th.get_buy_num(th.data.sele_g, function () { - //当前的价格要更新进去 - var cur_price = th.data.sele_g.shop_price; - if (th.data.card_field && th.data.sele_g[th.data.card_field]) { - cur_price = th.data.sele_g[th.data.card_field]; + + //var item = re.data.data.pageData[0]; + var item=re.data.data.pageData.find(function (e){ + return [0,3,5,7,10].includes(parseInt(e.prom_type)) && e.is_gift==0; + }) + //购物车中未找到相应的商品 + if(!item){ func(); return false;} + //购物车中zh_prom_id为0或者和本次活动的id一致 + if(item.zh_prom_id<=0 || item.zh_prom_id==th.data.act.id){ + func(); return false; } - var prom_buybum = 0; - var gd_buynum = 0; - //加入也要控制一下限购 - var check_obj = th.data.g_buy_num.get(th.data.sele_g.goods_id); - if (check_obj.gd_buynum && check_obj.gd_buynum > 0) gd_buynum = check_obj.gd_buynum; - if (check_obj.prom_buybum && check_obj.prom_buybum > 0) prom_buybum = check_obj.prom_buybum; - - if (check_obj) { - if (check_obj.prom_buybum && check_obj.prom_buybum >= th.data.sele_g.buyqty && - th.data.sele_g.buyqty > 0 - ) { - wx.showToast({ - title: "您的已购数量超出活动的限购", - icon: 'none', - duration: 2000 - }); - return false; - } - if (check_obj.gd_buynum && check_obj.gd_buynum >= th.data.sele_g.viplimited && - th.data.sele_g.viplimited > 0 - ) { - wx.showToast({ - title: "您的已购数量超出商品的限购", - icon: 'none', - duration: 2000 - }); - return false; + wx.showModal({ + title: '温馨提示', + content: '当前商品已存在购物车,是否替换参与该活动?', + success(res) { + if (res.confirm) { + th.check_is_in_cart_next(item); } } + }) - item.cbuy = 'no'; - var cbuy = th.data.sele_g.viplimited > 0 ? th.data.sele_g.viplimited - gd_buynum : 'no'; - if (cbuy != 'no') item.cbuy = cbuy; - var cbuy2 = th.data.sele_g.buyqty > 0 ? th.data.sele_g.buyqty - prom_buybum : 'no'; - if (cbuy2 != 'no') { - if (item.cbuy == 'no' || item.cbuy > cbuy2) item.cbuy = cbuy2; - } - var num = item.goods_num; + } else { + func(); + } + } + }) + }, - var is_num_change = 0; - if (num < th.data.goodsInputNum) { - num = th.data.goodsInputNum; - is_num_change = 1; - } + check_is_in_cart_next(item){ + let th=this; - if (item.cbuy > -1 && item.cbuy < item.goods_num) { - num = item.cbuy; - } - th.setData({ - [txt1]: num, - [txt2]: true, - [txt]: true, - [txt3]: item.id, - [txt4]: cur_price, - [txt5]: item.goods_num, - }); + var index = th.data.sele_index; + var txt = "list[" + index + "].haveAdded"; + var txt1 = "list[" + index + "].num"; + var txt2 = "list[" + index + "].showNum"; + var txt3 = "list[" + index + "].cart_id"; + var txt4 = "list[" + index + "].current_price"; + var txt5 = "list[" + index + "].cart_num"; - var updata = { - id: item.id, - prom_type: 7, - goods_price: cur_price, - prom_id: th.data.act.id, - store_id: os.stoid, - state: 0 - }; - if (getApp().globalData.guide_id) { - updata['guide_id'] = getApp().globalData.guide_id; - updata['guide_type'] = 0; - } - if (is_num_change) { - updata['goods_num'] = num; - } - getApp().request.put("/api/weshop/cart/update", { - data: updata, - success: function (t) { } - }); - th.re_sum_price(); - }) + th.get_buy_num(th.data.sele_g, function () { + //当前的价格要更新进去 + var cur_price = th.data.sele_g.shop_price; + if (th.data.card_field && th.data.sele_g[th.data.card_field]) { + cur_price = th.data.sele_g[th.data.card_field]; + } - } else { - func(); + var prom_buybum = 0; + var gd_buynum = 0; + //加入也要控制一下限购 + var check_obj = th.data.g_buy_num.get(th.data.sele_g.goods_id); + if (check_obj.gd_buynum && check_obj.gd_buynum > 0) gd_buynum = check_obj.gd_buynum; + if (check_obj.prom_buybum && check_obj.prom_buybum > 0) prom_buybum = check_obj.prom_buybum; + + if (check_obj) { + if (check_obj.prom_buybum && check_obj.prom_buybum >= th.data.sele_g.buyqty && + th.data.sele_g.buyqty > 0 + ) { + wx.showToast({ + title: "您的已购数量超出活动的限购", + icon: 'none', + duration: 2000 + }); + return false; + } + if (check_obj.gd_buynum && check_obj.gd_buynum >= th.data.sele_g.viplimited && + th.data.sele_g.viplimited > 0 + ) { + wx.showToast({ + title: "您的已购数量超出商品的限购", + icon: 'none', + duration: 2000 + }); + return false; } } + + item.cbuy = 'no'; + var cbuy = th.data.sele_g.viplimited > 0 ? th.data.sele_g.viplimited - gd_buynum : 'no'; + if (cbuy != 'no') item.cbuy = cbuy; + var cbuy2 = th.data.sele_g.buyqty > 0 ? th.data.sele_g.buyqty - prom_buybum : 'no'; + if (cbuy2 != 'no') { + if (item.cbuy == 'no' || item.cbuy > cbuy2) item.cbuy = cbuy2; + } + + var num = item.goods_num; + + var is_num_change = 0; + if (num < th.data.goodsInputNum) { + num = th.data.goodsInputNum; + is_num_change = 1; + } + + if (item.cbuy > -1 && item.cbuy < item.goods_num) { + num = item.cbuy; + } + th.setData({ + [txt1]: num, + [txt2]: true, + [txt]: true, + [txt3]: item.id, + [txt4]: cur_price, + [txt5]: item.goods_num, + }); + + var updata = { + id: item.id, + prom_type: 7, + goods_price: cur_price, + prom_id: th.data.act.id, + store_id: os.stoid, + state: 0, + zh_prom_id: th.data.act.id, + }; + if (getApp().globalData.guide_id) { + updata['guide_id'] = getApp().globalData.guide_id; + updata['guide_type'] = 0; + } + if (is_num_change) { + updata['goods_num'] = num; + } + + getApp().request.put("/api/weshop/cart/update", { + data: updata, + success: function (t) { } + }); + th.re_sum_price(); }) + }, + //-- 计算统计之后的金额 -- re_sum_price: function () { var all_num = 0; //商品数量之和 diff --git a/packageE/pages/cart/cart2/cart2.js b/packageE/pages/cart/cart2/cart2.js index bb3f1d3..4b53275 100644 --- a/packageE/pages/cart/cart2/cart2.js +++ b/packageE/pages/cart/cart2/cart2.js @@ -1073,7 +1073,8 @@ Page({ goods_id: carr[iv].goods_id, goods_num: 1, is_limit_show: 0, - is_state: 0 + is_state: 0, + zh_prom_id:item1.zh_prom_id } dug_cx_arr.push(gd_ite); } diff --git a/packageE/pages/user/cardinfo/cardinfo.js b/packageE/pages/user/cardinfo/cardinfo.js index 6c2759b..c4ff0a7 100644 --- a/packageE/pages/user/cardinfo/cardinfo.js +++ b/packageE/pages/user/cardinfo/cardinfo.js @@ -43,6 +43,9 @@ Page({ IsStopBuy:0, //卡是否停用 yu_e_show:0,//装入余额的弹窗 is_show_change_pop:0, + + is_xufei_setting:0, + xufei_setting_days:0, }, /** @@ -73,6 +76,10 @@ Page({ is_card_rule: is_cardrule, plus_bg_color: swi_arr.plus_bg_color, }); + + th.data.is_xufei_setting=swi_arr.is_xufei_setting; + th.data.xufei_setting_days=swi_arr.xufei_setting_days; + }) //----------------------------获取最大的卡类----------------------- @@ -819,6 +826,27 @@ Page({ end_time=ut.format(end_time,'yyyy-MM-dd'); var errmsg=""; + + //如果有开始前多少天可续费 + if(th.data.is_xufei_setting){ + + var expiryDate=this.data.expiryDate; + + var str = expiryDate.replace(/-/g, '/'); + var end = new Date(str); + end.setDate(end.getDate()- parseInt(th.data.xufei_setting_days) ); + end = Date.parse(end) / 1000; + + var now=ut.gettimestamp(); + if(now { diff --git a/packageG/pages/user/order_detail/order_detail.js b/packageG/pages/user/order_detail/order_detail.js index 0f885db..040e941 100644 --- a/packageG/pages/user/order_detail/order_detail.js +++ b/packageG/pages/user/order_detail/order_detail.js @@ -1792,6 +1792,15 @@ Page({ else if (arr2.length > 1) { good.prom_type = g_item.prom_type; good.prom_id = g_item.prom_id; } + + var arr3 = arr.filter(function (e) { + return e.s_time < ut.gettimestamp() && e.prom_type == 7; + }) + + if (arr3 && arr3.length > 0) { + b_item.zh_prom_id= arr3[0].act_id; + } + } }) @@ -2180,10 +2189,14 @@ Page({ } }, - more_add_cart:async function(){ + more_add_cart:async function(){ + var th=this; var back_goods_arr=this.data.back_goods_arr; var err_text=""; var ok_num=0; + + var zh_prom_id_err=[]; + var zh_prom_id_err_goods=[]; for(var i in back_goods_arr){ //商品ID @@ -2221,6 +2234,13 @@ Page({ newd['prom_type']=g_item.prom_type; newd['prom_id']=g_item.prom_id; } + + + newd['zh_prom_id']=0; + + if(g_item.zh_prom_id){ + newd['zh_prom_id'] = g_item.zh_prom_id; + } var b_cart_goods=null; @@ -2271,7 +2291,20 @@ Page({ if(newd.guide_id){ updata.guide_id=newd.guide_id; updata.guide_type=newd.guide_type; - } + } + + if (newd.prom_type) { + updata.prom_type = newd.prom_type; + updata.prom_id = newd.prom_id; + } + + //如果购物车中商品zh_prom_id不一致的话,要进行提示 + if(is_has.zh_prom_id>0 && is_has.zh_prom_id!= newd['zh_prom_id'] ){ + zh_prom_id_err.push(newd.goods_name+ '已存在购物车\n'); + zh_prom_id_err_goods.push(updata); + continue; + } + await getApp().request.promisePut("/api/weshop/cart/update", { data: updata }).then(res=>{ @@ -2297,34 +2330,90 @@ Page({ wx.hideLoading(); this.data.moring=0; - if(ok_num==0){ - //-- 如果没有获取用户信息 -- - wx.showModal({ - title:'提示', - content: err_text, - success(res) {} - }); - }else{ - if(err_text==""){ - getApp().goto("/pages/cart/cart/cart"); - }else{ - // 如果没有获取用户信息 - wx.showModal({ - title:'提示', - content: err_text, - success(res) { - if (res.confirm) { - //跳转到登录页 - getApp().goto("/pages/cart/cart/cart"); - } - } - }); - - } - - } + + if(zh_prom_id_err_goods && zh_prom_id_err_goods.length){ + if(err_text){ + err_text+="同时有以下商品:\n"; + } + err_text+=zh_prom_id_err.join(''); + err_text+="是否替换参与该活动?" + + // 如果没有获取用户信息 + wx.showModal({ + title: '提示', + content: err_text, + success(res) { + if (res.confirm) { + //进行对有zh_prom_id 不一样的商品进行替换 + th.zhbuy_add_cart(zh_prom_id_err_goods) + } + } + }); + + + }else { + + if (ok_num == 0) { + //-- 如果没有获取用户信息 -- + wx.showModal({ + title: '提示', + content: err_text, + success(res) { + } + }); + } else { + if (err_text == "") { + getApp().goto("/pages/cart/cart/cart"); + } else { + // 如果没有获取用户信息 + wx.showModal({ + title: '提示', + content: err_text, + success(res) { + if (res.confirm) { + //跳转到登录页 + getApp().goto("/pages/cart/cart/cart"); + } + } + }); + + } + + } + } }, + //-- 组合购的商品重新购买 -- + zhbuy_add_cart: async function (zh_prom_id_err_goods) { + var err_text = ""; + for (var i in zh_prom_id_err_goods) { + var updata=zh_prom_id_err_goods[i]; + await getApp().request.promisePut("/api/weshop/cart/update", { + data: updata + }).then(res => { + if (res.data.code != 0) { + err_text += newd.goods_name + "加入购物车失败\n"; + } + }) + } + + if (err_text == "") { + getApp().goto("/pages/cart/cart/cart"); + }else{ + // 如果没有获取用户信息 + wx.showModal({ + title: '提示', + content: err_text, + success(res) { + if (res.confirm) { + //跳转到登录页 + getApp().goto("/pages/cart/cart/cart"); + } + } + }); + } + }, + toast(msg){ wx.showToast({ title: msg, diff --git a/pages/cart/cart/cart.js b/pages/cart/cart/cart.js index e2892ed..3be2fed 100644 --- a/pages/cart/cart/cart.js +++ b/pages/cart/cart/cart.js @@ -548,7 +548,8 @@ Page({ goods_id:carr[i].goods_id, goods_num:1, is_limit_show:0, - is_state:0 + is_state:0, + zh_prom_id:carr[i].zh_prom_id } g_arr.push(gd_ite); } diff --git a/pages/goods/goodsInfo/goodsInfo.js b/pages/goods/goodsInfo/goodsInfo.js index 21004cc..986f263 100644 --- a/pages/goods/goodsInfo/goodsInfo.js +++ b/pages/goods/goodsInfo/goodsInfo.js @@ -2096,7 +2096,7 @@ Page({ }, //---加入购物车的最后一步--- - add_cart_next(e, t, a, o, newd, CanOutQty) { + async add_cart_next(e, t, a, o, newd, CanOutQty) { if (getApp().globalData.groupchat_id) { @@ -2138,6 +2138,32 @@ Page({ newd.prom_id=0; } + if(newd.prom_type==0){ + //-- 要拿一下商品有没有组合购活动 --- + var rq_url = '/api/weshop/activitylist/listGoodActInfo2New'; + var req_d = { + "store_id": os.stoid, + "goods_id": a, + "user_id": getApp().globalData.user_id, + } + + var ck_res= await getApp().request.promiseGet(rq_url, { + data: req_d, + }); + + if (ck_res.data.code == 0 && ck_res.data.data && ck_res.data.data.length > 0) { + var arr = ck_res.data.data; + var arr3 = arr.filter(function (e) { + return e.s_time < ut.gettimestamp() && e.prom_type == 7; + }) + + if (arr3 && arr3.length > 0) { + newd.zh_prom_id=arr3[0].act_id; + } + } + } + + wxlog.info(getApp().globalData.user_id+'-加入购物车:'+JSON.stringify(newd)); // // //如果有搭配购的时候的时候 @@ -2159,8 +2185,6 @@ Page({ user_id: oo.user_id, goods_id: a, pick_id: e.data.sto_sele_id, - prom_type: newd.prom_type, - prom_id: newd.prom_id, state: 0, }, success: function (re) { @@ -2169,24 +2193,15 @@ Page({ var item = null; //-------如果购物车中有相关的数据--------- if (re.data.data.total > 0) { - for (var j = 0; j < re.data.data.pageData.length; j++) { - if (!th.check_is_like(re.data.data.pageData[j], newd, 1)) continue; - item = re.data.data.pageData[j]; - break; - } - - if (!item) { for (var j = 0; j < re.data.data.pageData.length; j++) { if (!th.check_is_like(re.data.data.pageData[j], newd)) continue; item = re.data.data.pageData[j]; break; } - } - } if (item) { - item = re.data.data.pageData[0]; + //判断数量,要看下购物车中有没有该商品 if (CanOutQty) { if (item.goods_num + th.data.goodsInputNum > CanOutQty) { @@ -2224,47 +2239,25 @@ Page({ } } - var updata = { - id: item.id, - goods_num: e.data.goodsInputNum + item.goods_num, - goods_price: newd.goods_price, - member_goods_price: newd.goods_price, - store_id: th.data.stoid, - prom_id: newd.prom_id, //把活动id带上去(用于购物车失效变成有效商品) - prom_type: newd.prom_type - }; - - if(newd.is_pd_normal){ - updata.is_pd_normal=1 - } + if(newd.zh_prom_id>0 && item.zh_prom_id && newd.zh_prom_id!=item.zh_prom_id){ + wx.hideLoading(); + wx.showModal({ + title: '温馨提示', + content: '当前商品已存在购物车,是否替换参与该活动?', + success(res) { + if (res.confirm) { + wx.showLoading(); + th.add_cart_next2(e,item,newd); + }else{ + th.data.adding = 0; + } + } + }) - //---是不是从收藏夹出来的--- - if (th.data.c_guide_id) { - updata['guide_id'] = th.data.c_guide_id; - updata['guide_type'] = 3; //加入购物车之后就变成了3 - } else { - if (getApp().globalData.guide_id) { - updata['guide_id'] = getApp().globalData.guide_id; - updata['guide_type'] = 0; - } - } - if (getApp().globalData.groupchat_id) { - updata['groupchat_id'] = getApp().globalData.groupchat_id; + }else{ + th. add_cart_next2(e,item,newd); } - getApp().request.put("/api/weshop/cart/update", { - data: updata, - success: function (t) { - wx.hideLoading(); - th.data.adding=0; - getApp().my_warnning('加入购物车成功', 1, th, 450); - var c_num = th.data.cartGoodsNum + th.data.goodsInputNum; - th.setData({ - cartGoodsNum: c_num - }); - th.closeSpecModal(); - } - }); } else { getApp().request.post("/api/weshop/cart/save", { data: newd, @@ -2284,7 +2277,6 @@ Page({ }); } else { - newd['pick_name'] = th.data.sto_sele_name; newd['pick_dis'] = th.data.sto_sele_distr; th.buyNow(newd); @@ -2292,8 +2284,61 @@ Page({ } }, + + add_cart_next2(e,item,newd){ + let th=this; + let updata = { + id: item.id, + goods_num: e.data.goodsInputNum + item.goods_num, + goods_price: newd.goods_price, + member_goods_price: newd.goods_price, + store_id: th.data.stoid, + prom_id: newd.prom_id, //把活动id带上去(用于购物车失效变成有效商品) + prom_type: newd.prom_type + }; + + if(newd.is_pd_normal){ + updata.is_pd_normal=1 + } + + if (newd.zh_prom_id) { + updata.zh_prom_id = newd.zh_prom_id + } + + //---是不是从收藏夹出来的--- + if (th.data.c_guide_id) { + updata['guide_id'] = th.data.c_guide_id; + updata['guide_type'] = 3; //加入购物车之后就变成了3 + } else { + if (getApp().globalData.guide_id) { + updata['guide_id'] = getApp().globalData.guide_id; + updata['guide_type'] = 0; + } + } + if (getApp().globalData.groupchat_id) { + updata['groupchat_id'] = getApp().globalData.groupchat_id; + } + + getApp().request.put("/api/weshop/cart/update", { + data: updata, + success: function (t) { + wx.hideLoading(); + th.data.adding=0; + getApp().my_warnning('加入购物车成功', 1, th, 450); + var c_num = th.data.cartGoodsNum + th.data.goodsInputNum; + th.setData({ + cartGoodsNum: c_num + }); + th.closeSpecModal(); + } + }); + }, + + //因为在购物车 普通商品和 优惠促销,搭配购,组合购 阶梯购是一样的 check_is_like(e, newd, idx) { + + if(e.is_gift) return false; //如果是赠品就返回 if (e.prom_type == newd.prom_type) return true; if (!idx) { if (e.prom_type == 0) { diff --git a/pages/user/order_list/order_list.js b/pages/user/order_list/order_list.js index 911ac3d..87b1672 100644 --- a/pages/user/order_list/order_list.js +++ b/pages/user/order_list/order_list.js @@ -2120,6 +2120,16 @@ Page({ else if (arr2.length > 1) { good.prom_type = g_item.prom_type; good.prom_id = g_item.prom_id; } + + + var arr3 = arr.filter(function (e) { + return e.s_time < ut.gettimestamp() && e.prom_type == 7; + }) + + if (arr3 && arr3.length > 0) { + b_item.zh_prom_id= arr3[0].act_id; + } + } }) @@ -2508,9 +2518,12 @@ Page({ }, more_add_cart: async function () { + var th=this; var back_goods_arr = this.data.back_goods_arr; var err_text = ""; var ok_num = 0; + var zh_prom_id_err=[]; + var zh_prom_id_err_goods=[]; for (var i in back_goods_arr) { //商品ID @@ -2550,6 +2563,13 @@ Page({ newd['prom_id'] = g_item.prom_id; } + newd['zh_prom_id']=0; + + if(g_item.zh_prom_id){ + newd['zh_prom_id'] = g_item.zh_prom_id; + } + + var b_cart_goods = null; await getApp().request.promiseGet("/api/weshop/cart/page", { data: { @@ -2570,13 +2590,11 @@ Page({ var is_has=null; if(b_cart_goods) { - for (let jr = 0; jr < b_cart_goods.length; jr++) { var b_cart_item = b_cart_goods[jr]; - - if (!g_item.prom_type || g_item.prom_type == 0) { - if ([0, 3, 5, 7, 10].indexOf(b_cart_item.prom_type) > -1) { + if (!g_item.prom_type || g_item.prom_type == 0 || ([0, 3, 5, 7, 10].includes(parseInt(g_item.prom_type+''))) ) { + if ([0, 3, 5, 7, 10].indexOf(b_cart_item.prom_type) > -1 && g_item.is_gift!=0) { is_has = b_cart_item; break } @@ -2607,6 +2625,13 @@ Page({ updata.prom_id = newd.prom_id; } + //如果购物车中商品zh_prom_id不一致的话,要进行提示 + if(is_has.zh_prom_id>0 && is_has.zh_prom_id!= newd['zh_prom_id'] ){ + zh_prom_id_err.push(newd.goods_name+ '已存在购物车\n'); + zh_prom_id_err_goods.push(updata); + continue; + } + await getApp().request.promisePut("/api/weshop/cart/update", { data: updata }).then(res => { @@ -2631,32 +2656,90 @@ Page({ } wx.hideLoading(); this.data.moring = 0; - if (ok_num == 0) { - //-- 如果没有获取用户信息 -- + + if(zh_prom_id_err_goods && zh_prom_id_err_goods.length){ + if(err_text){ + err_text+="同时有以下商品:\n"; + } + err_text+=zh_prom_id_err.join(''); + err_text+="是否替换参与该活动?" + + // 如果没有获取用户信息 wx.showModal({ title: '提示', content: err_text, - success(res) { } + success(res) { + if (res.confirm) { + //进行对有zh_prom_id 不一样的商品进行替换 + th.zhbuy_add_cart(zh_prom_id_err_goods) + } + } }); - } else { - if (err_text == "") { - getApp().goto("/pages/cart/cart/cart"); - } else { - // 如果没有获取用户信息 + + + }else{ + + if (ok_num == 0) { + //-- 如果没有获取用户信息 -- wx.showModal({ title: '提示', content: err_text, - success(res) { - if (res.confirm) { - //跳转到登录页 + success(res) { } + }); + } else { + + + if (err_text == "") { getApp().goto("/pages/cart/cart/cart"); + } else { + // 如果没有获取用户信息 + wx.showModal({ + title: '提示', + content: err_text, + success(res) { + if (res.confirm) { + //跳转到登录页 + getApp().goto("/pages/cart/cart/cart"); + } + } + }); } - } - }); + } + } + }, + //-- 组合购的商品重新购买 -- + zhbuy_add_cart: async function (zh_prom_id_err_goods) { + var err_text = ""; + for (var i in zh_prom_id_err_goods) { + var updata=zh_prom_id_err_goods[i]; + await getApp().request.promisePut("/api/weshop/cart/update", { + data: updata + }).then(res => { + if (res.data.code != 0) { + err_text += newd.goods_name + "加入购物车失败\n"; + } + }) } - } + + if (err_text == "") { + getApp().goto("/pages/cart/cart/cart"); + }else{ + // 如果没有获取用户信息 + wx.showModal({ + title: '提示', + content: err_text, + success(res) { + if (res.confirm) { + //跳转到登录页 + getApp().goto("/pages/cart/cart/cart"); + } + } + }); + } }, + + //获取用户参与组合购的次数 async getUserBuyPromNum(prom_id,is_buy){ var userInfo = getApp().globalData.userInfo;