Commit dd20e2fef40fe2c267035078d27454c861e8ed87
1 parent
6be0cc8c
1. 视频号商品在支付拼团尾款的时候要带场景
2. 多赠品的优化
Showing
4 changed files
with
149 additions
and
123 deletions
pages/cart/cart/cart.js
| @@ -2952,7 +2952,6 @@ Page({ | @@ -2952,7 +2952,6 @@ Page({ | ||
| 2952 | th.data.promgoods_list[p_item[0]]=promgoods_list; | 2952 | th.data.promgoods_list[p_item[0]]=promgoods_list; |
| 2953 | } | 2953 | } |
| 2954 | 2954 | ||
| 2955 | - var is_duo_gift=0; | ||
| 2956 | for (var i in promgoods_list) { | 2955 | for (var i in promgoods_list) { |
| 2957 | var item = promgoods_list[i]; | 2956 | var item = promgoods_list[i]; |
| 2958 | if (item.prom_type == 0) { | 2957 | if (item.prom_type == 0) { |
| @@ -2965,21 +2964,6 @@ Page({ | @@ -2965,21 +2964,6 @@ Page({ | ||
| 2965 | } | 2964 | } |
| 2966 | make_up_arr.push(elem); | 2965 | make_up_arr.push(elem); |
| 2967 | break; | 2966 | break; |
| 2968 | - }else{ | ||
| 2969 | - var json=JSON.parse(item.preferential_type); | ||
| 2970 | - json.prom_id=prom.id; | ||
| 2971 | - json.prom_name=prom.name; | ||
| 2972 | - if(json.is_gift){ | ||
| 2973 | - | ||
| 2974 | - var idx=send_gift_arr.findIndex(function (e) { | ||
| 2975 | - return e.prom_id==prom.id; | ||
| 2976 | - }) | ||
| 2977 | - if(idx!=-1){ | ||
| 2978 | - send_gift_arr[idx]=json; | ||
| 2979 | - }else { | ||
| 2980 | - send_gift_arr.push(json); | ||
| 2981 | - } | ||
| 2982 | - } | ||
| 2983 | } | 2967 | } |
| 2984 | } else { | 2968 | } else { |
| 2985 | if (ob.num < item.condition) { | 2969 | if (ob.num < item.condition) { |
| @@ -2991,35 +2975,13 @@ Page({ | @@ -2991,35 +2975,13 @@ Page({ | ||
| 2991 | } | 2975 | } |
| 2992 | make_up_arr.push(elem); | 2976 | make_up_arr.push(elem); |
| 2993 | break; | 2977 | break; |
| 2994 | - }else{ | ||
| 2995 | - var json=JSON.parse(item.preferential_type); | ||
| 2996 | - json.prom_id=prom.id; | ||
| 2997 | - json.prom_name=prom.name; | ||
| 2998 | - if(json.is_gift){ | ||
| 2999 | - var idx=send_gift_arr.findIndex(function (e) { | ||
| 3000 | - return e.prom_id==prom.id; | ||
| 3001 | - }) | ||
| 3002 | - if(idx!=-1){ | ||
| 3003 | - send_gift_arr[idx]=json; | ||
| 3004 | - }else { | ||
| 3005 | - send_gift_arr.push(json); | ||
| 3006 | - } | ||
| 3007 | - } | ||
| 3008 | } | 2978 | } |
| 3009 | } | 2979 | } |
| 3010 | } | 2980 | } |
| 3011 | 2981 | ||
| 3012 | - //找到要送的活动 | ||
| 3013 | - var idx=send_gift_arr.findIndex(function (e) { | ||
| 3014 | - return e.prom_id==prom.id; | ||
| 3015 | - }) | ||
| 3016 | - if(idx!=-1){ | ||
| 3017 | - var cur_json=send_gift_arr[idx]; | ||
| 3018 | - if(parseInt(cur_json.zp_mode)==1) is_duo_gift=1; | ||
| 3019 | - } | ||
| 3020 | 2982 | ||
| 3021 | - //-- 只有在单赠品的时候,才要进行计算 -- | ||
| 3022 | - if(!is_duo_gift && idx>-1) { | 2983 | + |
| 2984 | + //-- 只有在单赠品的时候,才要进行计算 -- | ||
| 3023 | await getApp().request.promiseGet("/api/weshop/goods/getDiscount", { | 2985 | await getApp().request.promiseGet("/api/weshop/goods/getDiscount", { |
| 3024 | data: { | 2986 | data: { |
| 3025 | price: ob.price, | 2987 | price: ob.price, |
| @@ -3032,80 +2994,107 @@ Page({ | @@ -3032,80 +2994,107 @@ Page({ | ||
| 3032 | if (res.data.code == 0) discount = res.data.data; | 2994 | if (res.data.code == 0) discount = res.data.data; |
| 3033 | }) | 2995 | }) |
| 3034 | 2996 | ||
| 3035 | - if(!discount.zp_num || parseInt(discount.zp_num)==0) discount.zp_num=1; | ||
| 3036 | - //---如果有打折的信息,赠送的信息,赠送的时候要判断是不是限购数量--- | ||
| 3037 | - if (discount && discount['goods_id'] && discount.limit_num >= discount.bs*discount.zp_num | ||
| 3038 | - && discount.gift_storecount >= discount.bs*discount.zp_num) { | ||
| 3039 | - //如果这礼品超了情况下 | ||
| 3040 | - if (no_gift_arr.indexOf(discount.gift_id) != -1) continue; | ||
| 3041 | - var o = discount.goodsinfo; | ||
| 3042 | - //-- 默认等于1,兼容旧的活动 -- | ||
| 3043 | - | ||
| 3044 | - var newd = { | ||
| 3045 | - goods_id: o.goods_id, | ||
| 3046 | - goods_num: discount.bs*discount.zp_num, //是赠品的翻倍 | ||
| 3047 | - pick_id: list.pid, | ||
| 3048 | - user_id: app.globalData.user_id, | ||
| 3049 | - store_id: os.stoid, | ||
| 3050 | - goods_price: 0, | ||
| 3051 | - guide_id: ob.guide_id ? ob.guide_id : 0, | ||
| 3052 | - guide_type: ob.guide_type ? ob.guide_type : 0, | ||
| 3053 | - member_goods_price: 0, | ||
| 3054 | - goods_name: o.goods_name, | ||
| 3055 | - goods_sn: o.goods_sn, | ||
| 3056 | - sku: o.sku, | ||
| 3057 | - is_gift: 1, | ||
| 3058 | - prom_id: p_item[0], | ||
| 3059 | - prom_type: 3, | ||
| 3060 | - selected: 1, | ||
| 3061 | - gift_id: discount.gift_id, | ||
| 3062 | - original_img: th.data.imgUrl + o.original_img | ||
| 3063 | - }; | ||
| 3064 | - | ||
| 3065 | - list2.goods.push(newd); | ||
| 3066 | - var all_num = 0; | ||
| 3067 | - var all_limit_num = 0; | ||
| 3068 | - | ||
| 3069 | - for (var i in alllist) { | ||
| 3070 | - var list_item = alllist[i]; | ||
| 3071 | - for (var j in list_item.goods) { | ||
| 3072 | - //如果赠品的ID一样,要进行统计数量 | ||
| 3073 | - if (list_item.goods[j].is_gift == 1 && list_item.goods[j].gift_id == newd.gift_id) { | ||
| 3074 | - all_num += list_item.goods[j].goods_num; | ||
| 3075 | - } | ||
| 3076 | - if (list_item.goods[j].is_gift == 1 && list_item.goods[j].gift_id == newd.gift_id && list_item.goods[j].prom_id == p_item[0]) { | ||
| 3077 | - all_limit_num += list_item.goods[j].goods_num; | ||
| 3078 | - } | ||
| 3079 | - | ||
| 3080 | - } | ||
| 3081 | - } | ||
| 3082 | - | ||
| 3083 | - //-- 赠品的数量超出库存数量和会员的限制,这里是保证所有的赠品部会超出 -- | ||
| 3084 | - if (discount.gift_storecount < all_num || discount.limit_num < all_limit_num) { | ||
| 3085 | - no_gift_arr.push(discount.gift_id); | ||
| 3086 | - //--进入下一个循环 -- | ||
| 3087 | - continue; | ||
| 3088 | - } | ||
| 3089 | - | ||
| 3090 | - | ||
| 3091 | - var url = "/api/weshop/cart/delGift?store_id=" + newd.store_id + "&user_id=" + | ||
| 3092 | - newd.user_id + "&goods_id=" + newd.goods_id + "&is_gift=1&pick_id=" + newd.pick_id + "&prom_id=" + newd.prom_id | ||
| 3093 | - await getApp().request.promiseDelete(url, {}) | ||
| 3094 | - | ||
| 3095 | - var add_data = null; | ||
| 3096 | - await getApp().request.promisePost("/api/weshop/cart/save", { | ||
| 3097 | - data: newd | ||
| 3098 | - }).then(res => { | ||
| 3099 | - if (res.data.code == 0) { | ||
| 3100 | - add_data = res.data.data; | ||
| 3101 | - } | ||
| 3102 | - }) | ||
| 3103 | - if (add_data) { | ||
| 3104 | - newd.id = add_data.id; | ||
| 3105 | - list.goods.push(newd); | ||
| 3106 | - } | ||
| 3107 | - } | ||
| 3108 | - } | 2997 | + if(discount) { |
| 2998 | + | ||
| 2999 | + if (!discount.zp_num || parseInt(discount.zp_num) == 0) discount.zp_num = 1; | ||
| 3000 | + //判断一下赠品的模式 | ||
| 3001 | + if (parseInt(discount.zp_mode)== 1 ) | ||
| 3002 | + { | ||
| 3003 | + | ||
| 3004 | + var a_stock_num=0; | ||
| 3005 | + var a_limit_num=0; | ||
| 3006 | + for(let iy in discount.giftsinfo){ | ||
| 3007 | + let item=discount.giftsinfo[iy]; | ||
| 3008 | + a_stock_num+= parseInt(item.gift_storecount); | ||
| 3009 | + a_limit_num+=parseInt(item.limit_num); | ||
| 3010 | + } | ||
| 3011 | + | ||
| 3012 | + var t_zp_num=parseInt(discount.zp_num)*parseInt(discount.bs); | ||
| 3013 | + if(a_limit_num>=t_zp_num && a_stock_num>=t_zp_num ) { | ||
| 3014 | + | ||
| 3015 | + var json={}; | ||
| 3016 | + json.prom_id=prom.id; | ||
| 3017 | + json.prom_name=prom.name; | ||
| 3018 | + send_gift_arr.push(json); | ||
| 3019 | + } | ||
| 3020 | + | ||
| 3021 | + } | ||
| 3022 | + else | ||
| 3023 | + { | ||
| 3024 | + //---如果有打折的信息,赠送的信息,赠送的时候要判断是不是限购数量--- | ||
| 3025 | + if (discount && discount['goods_id'] && discount.limit_num >= discount.bs * discount.zp_num | ||
| 3026 | + && discount.gift_storecount >= discount.bs * discount.zp_num) { | ||
| 3027 | + //如果这礼品超了情况下 | ||
| 3028 | + if (no_gift_arr.indexOf(discount.gift_id) != -1) continue; | ||
| 3029 | + var o = discount.goodsinfo; | ||
| 3030 | + //-- 默认等于1,兼容旧的活动 -- | ||
| 3031 | + | ||
| 3032 | + var newd = { | ||
| 3033 | + goods_id: o.goods_id, | ||
| 3034 | + goods_num: discount.bs * discount.zp_num, //是赠品的翻倍 | ||
| 3035 | + pick_id: list.pid, | ||
| 3036 | + user_id: app.globalData.user_id, | ||
| 3037 | + store_id: os.stoid, | ||
| 3038 | + goods_price: 0, | ||
| 3039 | + guide_id: ob.guide_id ? ob.guide_id : 0, | ||
| 3040 | + guide_type: ob.guide_type ? ob.guide_type : 0, | ||
| 3041 | + member_goods_price: 0, | ||
| 3042 | + goods_name: o.goods_name, | ||
| 3043 | + goods_sn: o.goods_sn, | ||
| 3044 | + sku: o.sku, | ||
| 3045 | + is_gift: 1, | ||
| 3046 | + prom_id: p_item[0], | ||
| 3047 | + prom_type: 3, | ||
| 3048 | + selected: 1, | ||
| 3049 | + gift_id: discount.gift_id, | ||
| 3050 | + original_img: th.data.imgUrl + o.original_img | ||
| 3051 | + }; | ||
| 3052 | + | ||
| 3053 | + list2.goods.push(newd); | ||
| 3054 | + var all_num = 0; | ||
| 3055 | + var all_limit_num = 0; | ||
| 3056 | + | ||
| 3057 | + for (var i in alllist) { | ||
| 3058 | + var list_item = alllist[i]; | ||
| 3059 | + for (var j in list_item.goods) { | ||
| 3060 | + //如果赠品的ID一样,要进行统计数量 | ||
| 3061 | + if (list_item.goods[j].is_gift == 1 && list_item.goods[j].gift_id == newd.gift_id) { | ||
| 3062 | + all_num += list_item.goods[j].goods_num; | ||
| 3063 | + } | ||
| 3064 | + if (list_item.goods[j].is_gift == 1 && list_item.goods[j].gift_id == newd.gift_id && list_item.goods[j].prom_id == p_item[0]) { | ||
| 3065 | + all_limit_num += list_item.goods[j].goods_num; | ||
| 3066 | + } | ||
| 3067 | + | ||
| 3068 | + } | ||
| 3069 | + } | ||
| 3070 | + | ||
| 3071 | + //-- 赠品的数量超出库存数量和会员的限制,这里是保证所有的赠品部会超出 -- | ||
| 3072 | + if (discount.gift_storecount < all_num || discount.limit_num < all_limit_num) { | ||
| 3073 | + no_gift_arr.push(discount.gift_id); | ||
| 3074 | + //--进入下一个循环 -- | ||
| 3075 | + continue; | ||
| 3076 | + } | ||
| 3077 | + | ||
| 3078 | + | ||
| 3079 | + var url = "/api/weshop/cart/delGift?store_id=" + newd.store_id + "&user_id=" + | ||
| 3080 | + newd.user_id + "&goods_id=" + newd.goods_id + "&is_gift=1&pick_id=" + newd.pick_id + "&prom_id=" + newd.prom_id | ||
| 3081 | + await getApp().request.promiseDelete(url, {}) | ||
| 3082 | + | ||
| 3083 | + var add_data = null; | ||
| 3084 | + await getApp().request.promisePost("/api/weshop/cart/save", { | ||
| 3085 | + data: newd | ||
| 3086 | + }).then(res => { | ||
| 3087 | + if (res.data.code == 0) { | ||
| 3088 | + add_data = res.data.data; | ||
| 3089 | + } | ||
| 3090 | + }) | ||
| 3091 | + if (add_data) { | ||
| 3092 | + newd.id = add_data.id; | ||
| 3093 | + list.goods.push(newd); | ||
| 3094 | + } | ||
| 3095 | + } | ||
| 3096 | + } | ||
| 3097 | + } | ||
| 3109 | 3098 | ||
| 3110 | } | 3099 | } |
| 3111 | //--更新购物车的前台渲染-- | 3100 | //--更新购物车的前台渲染-- |
| @@ -3126,9 +3115,6 @@ Page({ | @@ -3126,9 +3115,6 @@ Page({ | ||
| 3126 | }); | 3115 | }); |
| 3127 | } | 3116 | } |
| 3128 | 3117 | ||
| 3129 | - send_gift_arr=send_gift_arr.filter(function (e) { | ||
| 3130 | - return e.zp_mode==="1"; | ||
| 3131 | - }) | ||
| 3132 | var gift_text = "requestData[" + cindex + "].send_gift_arr"; | 3118 | var gift_text = "requestData[" + cindex + "].send_gift_arr"; |
| 3133 | //-- 如果有凑单的话 -- | 3119 | //-- 如果有凑单的话 -- |
| 3134 | if (send_gift_arr.length > 0) { | 3120 | if (send_gift_arr.length > 0) { |
pages/cart/cart/cart.wxml
| @@ -162,7 +162,7 @@ | @@ -162,7 +162,7 @@ | ||
| 162 | 162 | ||
| 163 | <!-- 赠品的提示 --> | 163 | <!-- 赠品的提示 --> |
| 164 | <block wx:if="{{item.send_gift_arr}}"> | 164 | <block wx:if="{{item.send_gift_arr}}"> |
| 165 | - <view bindtap="show_gift_toast" wx:for="{{item.send_gift_arr}}" wx:if="{{item.zp_mode}}" | 165 | + <view bindtap="show_gift_toast" wx:for="{{item.send_gift_arr}}" |
| 166 | class="fs28 pdr20 pdl20 pdb20 c-red2 flex jc_sb" style="padding: 10rpx 30rpx"> | 166 | class="fs28 pdr20 pdl20 pdb20 c-red2 flex jc_sb" style="padding: 10rpx 30rpx"> |
| 167 | <text style="color: #333333">送赠品</text> | 167 | <text style="color: #333333">送赠品</text> |
| 168 | <text bindtap="tishi_gift">{{item.prom_name}}></text> | 168 | <text bindtap="tishi_gift">{{item.prom_name}}></text> |
pages/cart/cart2/cart2.js
| @@ -1210,7 +1210,13 @@ Page({ | @@ -1210,7 +1210,13 @@ Page({ | ||
| 1210 | item_map.s_intValue = get_data.intValue; | 1210 | item_map.s_intValue = get_data.intValue; |
| 1211 | item_map.s_coupon_id = get_data.coupon_id; | 1211 | item_map.s_coupon_id = get_data.coupon_id; |
| 1212 | item_map.s_coupon_num = get_data.coupon_num; | 1212 | item_map.s_coupon_num = get_data.coupon_num; |
| 1213 | - if (get_data.gift_id && get_data.goodsinfo) { | 1213 | + |
| 1214 | + | ||
| 1215 | + if (get_data.gift_id && parseInt(get_data.zp_mode)!=1 | ||
| 1216 | + && get_data.zp_num* item_map.bs<=get_data.limit_num | ||
| 1217 | + && get_data.zp_num* item_map.bs<=get_data.gift_storecount | ||
| 1218 | + ){ | ||
| 1219 | + | ||
| 1214 | item_map.gift_id = get_data.gift_id; | 1220 | item_map.gift_id = get_data.gift_id; |
| 1215 | item_map.gift_goods_id = get_data.goods_id; | 1221 | item_map.gift_goods_id = get_data.goods_id; |
| 1216 | item_map.gift_goods_name = get_data.goods_name; | 1222 | item_map.gift_goods_name = get_data.goods_name; |
| @@ -1233,9 +1239,26 @@ Page({ | @@ -1233,9 +1239,26 @@ Page({ | ||
| 1233 | 1239 | ||
| 1234 | if(parseInt(get_data.zp_mode)==1){ | 1240 | if(parseInt(get_data.zp_mode)==1){ |
| 1235 | if(!send_gf[pickid]) send_gf[pickid]=[]; | 1241 | if(!send_gf[pickid]) send_gf[pickid]=[]; |
| 1236 | - send_gf[pickid].push({ | ||
| 1237 | - pickup_id:pickid,giftsinfo:get_data.giftsinfo,zp_num:get_data.zp_num*get_data.bs, | ||
| 1238 | - gf_pr_name:item_map.name,prom_id:item_map.prom_id}); | 1242 | + |
| 1243 | + var a_stock_num=0; | ||
| 1244 | + var a_limit_num=0; | ||
| 1245 | + for(let iy in get_data.giftsinfo){ | ||
| 1246 | + let item=get_data.giftsinfo[iy]; | ||
| 1247 | + a_stock_num+= parseInt(item.gift_storecount); | ||
| 1248 | + a_limit_num+=parseInt(item.limit_num); | ||
| 1249 | + } | ||
| 1250 | + | ||
| 1251 | + var t_zp_num=parseInt(get_data.zp_num)*parseInt(get_data.bs); | ||
| 1252 | + if(a_limit_num>=t_zp_num && a_stock_num>=t_zp_num) { | ||
| 1253 | + | ||
| 1254 | + send_gf[pickid].push({ | ||
| 1255 | + pickup_id: pickid, | ||
| 1256 | + giftsinfo: get_data.giftsinfo, | ||
| 1257 | + zp_num: get_data.zp_num * get_data.bs, | ||
| 1258 | + gf_pr_name: item_map.name, | ||
| 1259 | + prom_id: item_map.prom_id | ||
| 1260 | + }); | ||
| 1261 | + } | ||
| 1239 | } | 1262 | } |
| 1240 | } | 1263 | } |
| 1241 | }) | 1264 | }) |
| @@ -4080,9 +4103,23 @@ Page({ | @@ -4080,9 +4103,23 @@ Page({ | ||
| 4080 | var pickid=gg.pick_id; | 4103 | var pickid=gg.pick_id; |
| 4081 | if(parseInt(get_data.zp_mode)==1){ | 4104 | if(parseInt(get_data.zp_mode)==1){ |
| 4082 | if(!send_gf[pickid]) send_gf[pickid]=[]; | 4105 | if(!send_gf[pickid]) send_gf[pickid]=[]; |
| 4083 | - send_gf[pickid].push({ | 4106 | + |
| 4107 | + var a_stock_num=0; | ||
| 4108 | + var a_limit_num=0; | ||
| 4109 | + for(let iy in get_data.giftsinfo){ | ||
| 4110 | + let item=get_data.giftsinfo[iy]; | ||
| 4111 | + a_stock_num+= parseInt(item.gift_storecount); | ||
| 4112 | + a_limit_num+=parseInt(item.limit_num); | ||
| 4113 | + } | ||
| 4114 | + | ||
| 4115 | + var t_zp_num=parseInt(get_data.zp_num)*parseInt(get_data.bs); | ||
| 4116 | + if(a_limit_num>= t_zp_num && a_stock_num>=t_zp_num ){ | ||
| 4117 | + send_gf[pickid].push({ | ||
| 4084 | pickup_id:pickid,giftsinfo:get_data.giftsinfo,zp_num:get_data.zp_num*get_data.bs, | 4118 | pickup_id:pickid,giftsinfo:get_data.giftsinfo,zp_num:get_data.zp_num*get_data.bs, |
| 4085 | gf_pr_name:prom.name,prom_id:prom.prom_id}); | 4119 | gf_pr_name:prom.name,prom_id:prom.prom_id}); |
| 4120 | + | ||
| 4121 | + } | ||
| 4122 | + | ||
| 4086 | th.setData({send_gf:send_gf}); | 4123 | th.setData({send_gf:send_gf}); |
| 4087 | } | 4124 | } |
| 4088 | } | 4125 | } |
pages/cart/cart_wk/cart_wk.js
| @@ -376,6 +376,9 @@ Page({ | @@ -376,6 +376,9 @@ Page({ | ||
| 376 | dd.shipping_price = parseFloat(th.data.exp_price); | 376 | dd.shipping_price = parseFloat(th.data.exp_price); |
| 377 | dd.addressid = th.data.user_addr.address_id; | 377 | dd.addressid = th.data.user_addr.address_id; |
| 378 | } | 378 | } |
| 379 | + if(getApp().globalData.scene){ | ||
| 380 | + dd.scene=getApp().globalData.scene; | ||
| 381 | + } | ||
| 379 | 382 | ||
| 380 | var arr = []; | 383 | var arr = []; |
| 381 | arr.push(dd); | 384 | arr.push(dd); |