Commit b75d2157449c895e031ce185782aecdfc7371ec8
1 parent
58fb3145
购物车要达到优惠促销的条件,才来判断商品是不是要判断限购
Showing
1 changed file
with
82 additions
and
5 deletions
pages/cart/cart/cart.js
... | ... | @@ -3235,6 +3235,8 @@ Page({ |
3235 | 3235 | |
3236 | 3236 | var i_arr = this.data.requestData[i].goods; |
3237 | 3237 | |
3238 | + //判断一下商品能不能满足优惠促销的条件 | |
3239 | + await th.check_can_yh_pro(i_arr); | |
3238 | 3240 | |
3239 | 3241 | for (var j = 0; j < i_arr.length; j++) { |
3240 | 3242 | if (i_arr[j].selected && i_arr[j].is_gift != 1) { |
... | ... | @@ -3255,7 +3257,6 @@ Page({ |
3255 | 3257 | if (this.data.requestData[i].show_can_cx && (i_arr[j].prom_type == 3 || i_arr[j].prom_type == 7)) { |
3256 | 3258 | |
3257 | 3259 | var show_can_cx=this.data.requestData[i].show_can_cx; |
3258 | - | |
3259 | 3260 | //-- 查找选中了什么 -- |
3260 | 3261 | for (var ik in show_can_cx) { |
3261 | 3262 | var ch_map = show_can_cx[ik].ch_map; |
... | ... | @@ -3279,8 +3280,9 @@ Page({ |
3279 | 3280 | if(yh_by_map[ky]){ |
3280 | 3281 | ky_n+=yh_by_map[ky]; |
3281 | 3282 | } |
3282 | - //-- 判断优惠促销活动的商品的限购 -- | |
3283 | - if(i_arr[j].prom_type==3 && fd1.act.goodslimit>0){ | |
3283 | + | |
3284 | + //-- 判断优惠促销活动的商品的限购,can_yh 表示商品满足优惠促销的条件 -- | |
3285 | + if(i_arr[j].prom_type==3 && fd1.act.goodslimit>0 && i_arr[j].can_yh ){ | |
3284 | 3286 | var p_can_by=fd1.act.goodslimit-fd1.act.goodslimited; |
3285 | 3287 | if(i_arr[j].goods_num+ky_n>p_can_by){ |
3286 | 3288 | getApp().confirmBox(i_arr[j].goods_name + "超出活动限购数量"+fd1.act.goodslimit+"件"); |
... | ... | @@ -3989,6 +3991,7 @@ Page({ |
3989 | 3991 | |
3990 | 3992 | |
3991 | 3993 | }, |
3994 | + | |
3992 | 3995 | //跳到首页 |
3993 | 3996 | goto: function (e) { |
3994 | 3997 | var url = '/pages/index/index/index'; |
... | ... | @@ -4321,6 +4324,7 @@ Page({ |
4321 | 4324 | } |
4322 | 4325 | |
4323 | 4326 | }, |
4327 | + | |
4324 | 4328 | //优惠促销用户参与次数 |
4325 | 4329 | async getUserBuyPromNum_pre(prom_id) { |
4326 | 4330 | var userInfo = getApp().globalData.userInfo; |
... | ... | @@ -4765,8 +4769,6 @@ Page({ |
4765 | 4769 | }); |
4766 | 4770 | }, |
4767 | 4771 | |
4768 | - | |
4769 | - | |
4770 | 4772 | //-- 开始显示活动的弹出 -- |
4771 | 4773 | switch_cx_group: function (e) { |
4772 | 4774 | var idx = e.currentTarget.dataset.index; |
... | ... | @@ -5002,6 +5004,81 @@ Page({ |
5002 | 5004 | 'code': 0, |
5003 | 5005 | 'msg': '成功' |
5004 | 5006 | }) |
5007 | + }, | |
5008 | + | |
5009 | + //-- 判断一下有没有满足优惠促销的条件 -- | |
5010 | + check_can_yh_pro:async function (i_arr){ | |
5011 | + var map={}; | |
5012 | + for (let i = 0; i < i_arr.length; i++) { | |
5013 | + var item=i_arr[i]; | |
5014 | + if(item.is_gift) continue; | |
5015 | + if(item.prom_type!=3) continue; | |
5016 | + | |
5017 | + if (map[item.prom_id]) { | |
5018 | + var ob = map[item.prom_id]; | |
5019 | + //-- 避免同一件商品重复添加 -- | |
5020 | + if (ob.goods && ob.goods.length) { | |
5021 | + var fid = ob.goods.findIndex(function (e) { | |
5022 | + e.goods_id == item.goods_id | |
5023 | + }) | |
5024 | + if (fid > -1) continue; | |
5025 | + } | |
5026 | + ob.price += item.goods_price * item.goods_num; | |
5027 | + ob.goods_num += item.goods_num; | |
5028 | + ob.goods.push({ goods_id: item.goods_id, goods_price: item.goods_price, goods_num: item.goods_num }); | |
5029 | + } else { | |
5030 | + var prom = null; | |
5031 | + await getApp().request.promiseGet("/api/weshop/promgoods/get/" + os.stoid + "/" + item.prom_id, {}).then(res => { | |
5032 | + if (res.data.code == 0) { | |
5033 | + prom = res.data.data; | |
5034 | + } | |
5035 | + }) | |
5036 | + | |
5037 | + var ob = {}; | |
5038 | + ob.is_bz = prom.is_bz; | |
5039 | + ob.prom_id=item.prom_id; | |
5040 | + ob.price = item.goods_price * item.goods_num; | |
5041 | + ob.goods_num = item.goods_num; | |
5042 | + ob.goods = new Array(); | |
5043 | + ob.goods.push({ goods_id: item.goods_id, goods_price: item.goods_price, goods_num: item.goods_num }); | |
5044 | + map[item.prom_id] = ob; | |
5045 | + } | |
5046 | + } | |
5047 | + | |
5048 | + var res=null; | |
5049 | + for (const mapKey in map) { | |
5050 | + var item_map=map[mapKey]; | |
5051 | + //开始判断能不能参与优惠 | |
5052 | + res=await getApp().request.promiseGet("/api/weshop/goods/getDiscount", { | |
5053 | + data: { | |
5054 | + price: parseFloat(item_map.price).toFixed(2), prom_id: item_map.prom_id, | |
5055 | + goods_num: item_map.goods_num, user_id: getApp().globalData.user_id, | |
5056 | + is_bz: item_map.is_bz | |
5057 | + } | |
5058 | + }) | |
5059 | + if (res.data.code == 0 && res.data.data.condition) { | |
5060 | + | |
5061 | + for (let i = 0; i < i_arr.length; i++) { | |
5062 | + var item_g = i_arr[i]; | |
5063 | + if (item_g.is_gift) continue; | |
5064 | + | |
5065 | + //-- 避免同一件商品重复添加 -- | |
5066 | + if (item_map.goods && item_map.goods.length) { | |
5067 | + var fid = item_map.goods.findIndex(function (e) { | |
5068 | + e.goods_id == item_g.goods_id | |
5069 | + }) | |
5070 | + if (fid > -1) continue; | |
5071 | + } | |
5072 | + //判断商品是可以参与优惠促销的 | |
5073 | + i_arr[i].can_yh=1; | |
5074 | + } | |
5075 | + | |
5076 | + } | |
5077 | + | |
5078 | + } | |
5079 | + | |
5080 | + | |
5081 | + | |
5005 | 5082 | } |
5006 | 5083 | |
5007 | 5084 | ... | ... |