diff --git a/components/promate_pop/p_filter.wxs b/components/promate_pop/p_filter.wxs new file mode 100644 index 0000000..c3db5af --- /dev/null +++ b/components/promate_pop/p_filter.wxs @@ -0,0 +1,35 @@ +var g_filters = { + //-- 判断是不是有等级价 -- + set_tab_title: function (item) { + switch (item.prom_type) { + case 3: + return '优惠'; + case 5: + return '搭配'; + case 7: + return '组合'; + case 10: + return '阶梯'; + } + return ''; + }, + set_title: function (item) { + switch (item.prom_type) { + case 3: + return '优惠促销'; + case 5: + return '搭配促销'; + case 7: + return '组合购'; + case 10: + return '阶梯促销'; + } + return ''; + }, + + +} +module.exports = { + set_tab_title: g_filters.set_tab_title, + set_title: g_filters.set_title, +} \ No newline at end of file diff --git a/components/promate_pop/promate_pop.js b/components/promate_pop/promate_pop.js new file mode 100644 index 0000000..c23eaa1 --- /dev/null +++ b/components/promate_pop/promate_pop.js @@ -0,0 +1,76 @@ +Component({ + /*** 页面的初始数据***/ + data: { + type:0, //0只显示再商品详情页面 1显示再有选择按钮 + pro_pop:0, //是否弹出 + cx_prom_group:[], //弹出框的内容展示 + is_cart:0 + }, + methods: { + //-- 初始化弹出框 -- + set_init(type,cx_prom_group,is_cart){ + if(!type) type=0; + if(!is_cart) is_cart=0; + + var fd=cx_prom_group.findIndex(function (gh){ + return gh.sele + }) + if(fd==-1){ + cx_prom_group[0].sele=1; + } + this.setData({ + type:type,pro_pop:1,cx_prom_group,is_cart:is_cart + }) + }, + + /*----pop的开关,如果按钮是‘确定’,就要返回参数给父层组件---*/ + close_pro_pop: async function (e) { + this.setData({pro_pop: 0}); + if(!this.data.type) return false; + var idx=this.data.cx_prom_group.findIndex(function (e){ + return e.sele==1; + }) + this.triggerEvent('sure_cx_group',{sele_idx:idx},{bubbles: true}); + }, + + go_the_url:function (e){ + var index=e.currentTarget.dataset.index; + var item=this.data.cx_prom_group[index]; + + var prom_id = item.prom_id; + var prom_type = item.prom_type; + var url=''; + switch (parseInt(prom_type)){ + case 3: + url = "/pages/goods/goodsList/goodsList?prom_type=3&prom_id=" + prom_id; + break; + case 5: + url = "/packageA/pages/prom_list/prom_list?goods_id=" + item.main_gid; + var room_id = getApp().globalData.room_id; + if (room_id && this.data.gid == getApp().globalData.room_goods_id) { + url += "&room_id=" + room_id; + } + break; + case 7: + url="/packageB/pages/zuhegou/index/index?id=" + prom_id + break; + case 10: + url="/pages/goods/goodsList/goodsList?ladder_id=" + prom_id; + break; + } + getApp().goto(url); + }, + + //-- 选择活动 -- + sele_act:function (e){ + var index=e.currentTarget.dataset.index; + var cx_prom_group=this.data.cx_prom_group; + for (var idx=0;idx + + + + + + 促销列表 + + + + + + + + {{p_fil.set_tab_title(item)}} + + {{p_fil.set_title(item)}} + + + + {{item.title}} + {{item.title}} + 消费满{{item.condition}}享优惠({{item.limit}}) + + 搭配价:{{item.show_price}} + + + {{item.show_time}} + + + {{bm}} + + + + + + + + + + Γ + + + + + + 详情 + + + + + + + + + + + 我知道了 + 确定 + + + \ No newline at end of file diff --git a/components/promate_pop/promate_pop.wxss b/components/promate_pop/promate_pop.wxss new file mode 100644 index 0000000..17a64da --- /dev/null +++ b/components/promate_pop/promate_pop.wxss @@ -0,0 +1,251 @@ +/* 自定义弹出窗口 */ +.cx-popup { + width: 100%; + background: #fff; + z-index: 35; + border-top-left-radius: 10rpx; + border-top-right-radius: 10rpx; + position: fixed; + bottom: 0; + left:0 +} +.cx-popup.cart_show{ + bottom:100rpx +} + +.cx-popup .top { + font-size: 32rpx; + padding: 20rpx 0; + border-bottom: 2rpx solid #ebedf0; +} + +.cx-popup .top-frame { + /* width: 100%; + display: flex; + justify-content: center; + overflow: hidden; */ +} + +.xc-top-content { + width: 88%; + height: 85rpx; + padding-top: 50rpx; + font-size: 36rpx; +} +.xc-valid-coupon { + width: 90%; + height: 40rpx; + padding-top: 24rpx; + overflow: hidden; +} + +.xc-frame .list-frame { + width: 90%; + height: 100%; + overflow-y: scroll; + margin-top: 20rpx; +} + +.xc-close-frame { + margin-top: 30rpx; + width: 15%; + display: flex; +} + +.xc-close { + width: 70rpx; + height: 70rpx; + border-radius: 50%; + border: 5rpx solid #a5a5a7; + text-align: center; + line-height: 55rpx; + font-size: 80rpx; + color: #a5a5a7; + font-family: "微软正黑体"; + margin-top: 8rpx; +} +.xc-money { + color: #ff0013; +} + +.xc-coupon-effect { + width: 99%; + height: 128rpx; + border-bottom: 3rpx solid #ddd; +} + +.xc-goods-coupon { + width: 80%; + height: 100%; +} + +.xc-title { + width: 50%; + margin-left: 222rpx; +} + +.xc-coupon-money { + color: #c91e31; + font-size: 35rpx; + margin-top: 20rpx; + +} + +.xc-coupon-time { + height: 50rpx; + font-size: 27rpx; + color: #a4a4a4; +} + +.xc-coupon-time .time { + margin-left: 15rpx; + font-size: 27rpx; +} + +.xc-coupon-selection { + width: 99%; + height: 100%; +} + +.xc-confirm { + width: 90%; + height: 75rpx; + margin: 0 auto; + background: #c41830; + color: #fff; + border-radius: 10rpx; + font-size: 30rpx; + margin-top: 50rpx; +} + +.cx-confirm { + width: 100%; + padding: 20rpx; + box-sizing: border-box; + /* height: 160rpx; */ + +} + + + +.cx-confirm .confirm { + /* width: 372rpx; + height: 60rpx; */ + background-color: #f40026; + color: #fff; + border-radius: 10rpx; + line-height: 80rpx; + font-size: 28rpx; + +} + +.xc-not-Selection { + width: 60rpx; + height: 60rpx; + background: #eeeeee; +} + +.up_pro { + animation: up .7s; +} + +.down_pro { + animation: down 1s; +} + +@keyframes up_pro { + 0% { + transform: translateY(550rpx); + } + + 100% { + transform: translateY(0); + } +} + +@keyframes down_pro { + 0% { + transform: translateY(0); + } + + 100% { + transform: translateY(550rpx); + } +} + +.item_pro{ + background-color: #fceeee;height: 170rpx; position: relative; +} + +.item_pro~.item_pro{ + margin-top: 20rpx; +} + +.item_pro .item_pro_left{ + width:170rpx;flex-shrink: 0; position: relative; +} + +.item_pro .item_pro_right{ + position: relative; +} + + +.tick { + position: relative; +} + +.tick:before { + content: ''; + display: inline-block; + vertical-align: middle; + margin-top: -4rpx; + margin-right: 8rpx; + width: 22rpx; + height: 22rpx; + background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAMAAADzapwJAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAABCUExURUdwTPInDPInDPgoDfMnDPYqEvInDPInDPInDP87NPUoDv8vEvMoDPInDPIoDPMnDvInDPInDPInDPIoDPQoDfInDEON4KMAAAAVdFJOUwD45yawG4zz3gQ0DmLOfECQZpPlS54kMQ4AAAC0SURBVBjTbZFREoMgDERDS0xQQNHu/a/alEGtaIYfHrBhs0S1pujVifo40VkhC+BUHSDzQTlBhjHY8bjogXmDZ+orJKwXwMUeUoa/0PeGbH8Q4Y5CJopYOjosiOQxdpRGk1UXOkrBKdkimtN8UrKrJBVXdzsllSYSjR/0J9JaGn81WluWtonYKQ0op51P3M2L2bmZN9n8MKoVqTph/RsseyjfYxAkfgot/82CpuJVLOLSIv4Cd5AJ37BgpFwAAAAASUVORK5CYII=) no-repeat; + background-size: 22rpx auto; +} + +.r_item_pro{ + position: absolute; + right: 18rpx; + height: 100%; + display: flex; + align-items: center; + justify-content: center; +} + +.xq_btn{ + width: 100rpx; + height: 60rpx; + background-color: #e03033; + color: #fff; text-align: center; line-height: 60rpx; + border-radius:10rpx ; +} +.left_f_box{ + width:80rpx;font-weight: bolder; color:#d9001b; line-height: 44rpx;text-align: center; +} +.tab_bx{ + position: absolute;top: 0; left: 0; width: 60rpx; height: 40rpx; + background-color: #f5bcc1;color: #d9001b; display: flex; justify-content: center;align-items: center; +} + + +/*选择的圆圈*/ +.xc-hook { + width: 30rpx; + height: 30rpx; + line-height: 30rpx; + text-align: center; + border: 1rpx solid #999; + display: inline-block; +} +/*选中的时候*/ +.xc-hook.on { + transform: rotate(-135deg); + background-color: #d60021; +} + + + +@import '../../app.wxss'; diff --git a/packageE/pages/cart/cart2/cart2.js b/packageE/pages/cart/cart2/cart2.js index 851696a..f1a3afd 100644 --- a/packageE/pages/cart/cart2/cart2.js +++ b/packageE/pages/cart/cart2/cart2.js @@ -5,7 +5,12 @@ var regeneratorRuntime = require('../../../../utils/runtime.js'); var util_pay = require("../../../../utils/pay.js"); var zh_calc = require("zh_calculate.js"); var ladder_calc = require("ladder_calculate.js"); + // 防抖函数用定时器 +//公共的函数合并在一起 +const m_cx = require("../../../../utils/more_cx.js"); + +// 防抖函数用定时器 let timer; Page({ data: { @@ -126,7 +131,16 @@ Page({ tabs: ['门店自提', '快递邮寄'], currentTabIndex: 1, - in_zhact_gdmap: {}, //不同门店参与同一活动的限购 + in_zhact_gdmap: {}, //不同门店参与同一活动的限购,这些都是map表,很 + in_zhact:{}, //组合购活动在列表中的显示 + in_yhact:{}, //优惠活动在列表中的显示 + + in_zh_gd_buy_map:{}, //就是商品在组合购中的 + + in_zhact_gdmap_new: {}, //不同门店参与同一活动的限购,这些都是map表,是多促销互动专用,不能和in_zhact_gdmap重叠 + in_zhact_new:{}, //组合购活动在列表中的显示 是多促销互动专用,不能和in_zhact重叠 + in_yhact_new:{}, //组合购活动在列表中的显示 是多促销互动专用,不能和in_yhact重叠 + hid_inp: 1, user_note: "", zhhe_act_map: {}, //组合活动的map表 @@ -156,6 +170,7 @@ Page({ bconfig:null }, + onLoad: function (t) { wx.setNavigationBarTitle({ title: "填写订单", }) @@ -167,8 +182,7 @@ Page({ //清空is_pick_up getApp().request.put("/api/weshop/useraddress/updatePickUp", { data: { user_id: getApp().globalData.user_id, is_pickup: 0 }, - success: function (s) { - } + success: function (s) {} }); getApp().getConfig2(function (e) { @@ -378,6 +392,8 @@ Page({ } this.calculatePrice()//计算金额 }, + + //直接购买预存开启关闭 prestore2() { let txt = 'bn_goods.yck_off'; @@ -399,7 +415,6 @@ Page({ }else{ this.calculatePrice2()//计算金额 } - }, //计算商品预存款前置方法------------------------------------ async beforAdvancesum(cartList) { @@ -565,7 +580,7 @@ Page({ }); }, - //----------------展示页面,是再获取用户信息之后-------------- + //---------------- 展示页面,是再获取用户信息之后 -------------- async show_page() { var th = this, ta = this.data.param; //获取用户预存款 @@ -699,6 +714,38 @@ Page({ }, + + //-- 获取促销活动的组合 -- + cx_prom_group(prom_list,item1){ + var th=this; + //需要读者系统顺序 + var json_d =this.data.json_d; + var auto_promote_sale=json_d.auto_promote_sale; + var sort_type=''; + + if(!auto_promote_sale){ + sort_type='prom_type'; + }else{ + var auto_promote_sale=auto_promote_sale.split(','); + //--- 循环处理 --- + prom_list.map(function (e){ + var fd=auto_promote_sale.indexOf(e.prom_type+''); + e.sort=fd; + if(e.prom_type==item1.prom_type){ + e.sele=1; + } + }) + sort_type='sort'; + } + + //-- 排序一下,进行升序 -- + function comp(a, b) { + return a[sort_type]-b[sort_type]; //升序 + } + //使用sort排序 + prom_list.sort(comp); + }, + //-----真的获取购物车,入口-------- get_cart: function () { var th = this, app = getApp(); @@ -710,10 +757,8 @@ Page({ store_id: oo.stoid, pageSize: 600 }, success: async function (su) { - //按门店分类的数组 - var arr = new Array(); - var carr = su.data.data.pageData; + var carr = su.data.data.pageData; th.setData({ is_all_zt: 1 }); //-- 找出所有的门店 -- @@ -733,256 +778,246 @@ Page({ }) th.data.cartlist_y = carr; //存储原始购物车列表 - th.data.in_zhact_gdmap = {}; - //---是不是购买等级卡成功的返回---等级卡显示的判断--- - var is_card_back = getApp().globalData.is_card_back; + wx.showLoading(); + th.get_cart_next(carr); - //-- 判断组合购是总数量是不是存在 -- - var no_zh_num={}; + } + }); + }, - for (var i = 0; i < carr.length; i++) { - var item1 = carr[i]; - //把已经购买了多少见的内容填入 - var goodsbuynum = 0, promgoodsbuynum = 0; - //--要获得商品,该用户买了多少件,同步应用-- - await getApp().request.promiseGet("/api/weshop/ordergoods/getUserBuyGoodsNum", { - data: { - store_id: os.stoid, - user_id: getApp().globalData.user_id, - goods_id: item1.goods_id, - prom_type: item1.prom_type, - prom_id: item1.prom_id - }, - }).then(res => { - var buy_num_data = res.data.data; - if (buy_num_data.promgoodsbuynum) { - promgoodsbuynum = buy_num_data.promgoodsbuynum; - } - goodsbuynum = buy_num_data.goodsbuynum; - }) - //如果有购买活动 - item1.promgoodsbuynum = promgoodsbuynum; - - //默认是包邮和优惠的 - item1.is_order_yh=1; - item1.is_post_temp=1; - - //如果是秒杀,团购的时候 - if([1,2,6].indexOf(item1.prom_type)>-1){ - var url= "/api/weshop/activitylist/getSJGoodsPriceNew/" + os.stoid - + "/" + item1.goods_id + "/"+item1.prom_type+"/" + item1.prom_id + "/" + app.globalData.user_id; - await app.request.promiseGet(url,{}).then(res=>{ - if(res.data.code==0){ - console.log(res.data.data,"111"); - item1.is_order_yh=res.data.data.is_order_yh; - item1.is_post_temp=res.data.data.is_post_temp; - } - }) - } - - //要把优惠活动加入,prom_goods_map中,赠品不要运算,代发商品不算优惠 - if (item1.prom_type == 3 && item1.is_gift != 1 && !item1.whsle_id) { - // th.check_is_youhui(item1.goods_id, item1.pick_id); - //增加优惠活动次数限制 - let limit_num= await th.getprom(item1) //活动限制次数 - - if(!limit_num){ - await th.add_prom_goods_map(item1); - // item1.prom_id='' - // item1.prom_type='' - }else{ - let user_pre_buynum = await th.getUserBuyPromNum_pre(item1.prom_id) //用户已经参与次数 - if(user_pre_buynum { - if (res.data.code == 0 && res.data.data) { - //如果活动已经结束 - if (res.data.data.is_end == 1) { - isok = 0; - } - if (ut.gettimestamp() > res.data.data.end_time) { - isok = 0; - } - item1.act = res.data.data; + async get_cart_next(carr,is_change){ - //-- 在这里要判断一下活动的组合购总数量 -- - if(item1.act.zh_num>0 && item1.act.zh_buy_num>=item1.act.zh_num){ - store_count_ok = 0; - no_zh_num[item1.prom_id]=1; - //-- 清理一下活动的状态 -- - item1.prom_type = 0; - item1.prom_type1 = 0; - item1.prom_id = 0; - item1.prom_id1 = 0 + if(is_change) carr=this.data.cartlist_y; + //按门店分类的数组 + var arr = new Array(); - }else{ - th.data.zhhe_act_map[item1.prom_id] = res.data.data; - } + var th=this; + th.data.in_zhact_gdmap = {}; + //---是不是购买等级卡成功的返回---等级卡显示的判断--- + var is_card_back = getApp().globalData.is_card_back; - } else { - //未找到商品的活动 - is_flag = 0; - } - }) + //-- 判断组合购是总数量是不是存在 -- + var no_zh_num={}; - if (!isok) { - getApp().my_warnning("组合购的活动已经过期", 0, th); - return false; + for (var i = 0; i < carr.length; i++) { + var item1 = carr[i]; + //-- 获取一下商品的所有活动 -- + await th.buy_pro_group(item1); + //把已经购买了多少见的内容填入 + var goodsbuynum = 0, promgoodsbuynum = 0; + //--要获得商品,该用户买了多少件,同步应用-- + await getApp().request.promiseGet("/api/weshop/ordergoods/getUserBuyGoodsNum", { + data: { + store_id: os.stoid, + user_id: getApp().globalData.user_id, + goods_id: item1.goods_id, + prom_type: item1.prom_type, + prom_id: item1.prom_id + }, + }).then(res => { + var buy_num_data = res.data.data; + if (buy_num_data.promgoodsbuynum) { + promgoodsbuynum = buy_num_data.promgoodsbuynum; + } + goodsbuynum = buy_num_data.goodsbuynum; + }) + //如果有购买活动 + item1.promgoodsbuynum = promgoodsbuynum; + + //默认是包邮和优惠的 + item1.is_order_yh=1; + item1.is_post_temp=1; + + //如果是秒杀,团购的时候 + if([1,2,6].indexOf(item1.prom_type)>-1){ + var url= "/api/weshop/activitylist/getSJGoodsPriceNew/" + os.stoid + + "/" + item1.goods_id + "/"+item1.prom_type+"/" + item1.prom_id + "/" + app.globalData.user_id; + await app.request.promiseGet(url,{}).then(res=>{ + if(res.data.code==0){ + console.log(res.data.data,"111"); + item1.is_order_yh=res.data.data.is_order_yh; + item1.is_post_temp=res.data.data.is_post_temp; + } + }) + } + + //要把优惠活动加入,prom_goods_map中,赠品不要运算,代发商品不算优惠 + if (item1.prom_type == 3 && item1.is_gift != 1 && !item1.whsle_id) { + // th.check_is_youhui(item1.goods_id, item1.pick_id); + //增加优惠活动次数限制 + let limit_num= await th.getprom(item1) //活动限制次数 + + if(!limit_num){ + await th.add_prom_goods_map(item1); + // item1.prom_id='' + // item1.prom_type='' + }else{ + let user_pre_buynum = await th.getUserBuyPromNum_pre(item1.prom_id) //用户已经参与次数 + if(user_pre_buynum { + if (res.data.code == 0 && res.data.data) { + //如果活动已经结束 + if (res.data.data.is_end == 1) { + isok = 0; } + if (ut.gettimestamp() > res.data.data.end_time) { + isok = 0; + } + item1.act = res.data.data; + + //-- 在这里要判断一下活动的组合购总数量 -- + if(item1.act.zh_num>0 && item1.act.zh_buy_num>=item1.act.zh_num){ + store_count_ok = 0; + no_zh_num[item1.prom_id]=1; + //-- 清理一下活动的状态 -- + item1.prom_type = 0; + item1.prom_type1 = 0; + item1.prom_id = 0; + item1.prom_id1 = 0 - //------ 先增组合活动的总数量的时候 ------- - if(store_count_ok) { - var url1 = "/api/weshop/prom/zhbuyGoods/page"; - var req_data = { - page: 1, - pageSize: 2000, - store_id: os.stoid, - zh_id: item1.prom_id, - } - await getApp().request.promiseGet(url1, { - data: req_data - }).then(res => { - if (ut.ajax_ok(res)) { - var gdlist = res.data.data.pageData; - gdlist.forEach(i => { - if (item1.goods_id == i.goods_id && !is_flag) { - item1.prom_type = 0; - item1.prom_type1 = 0; - item1.prom_id = 0; - item1.prom_id1 = 0 - } - }) - th.data.zuhe_map_good[item1.prom_id] = gdlist; - } - }) + }else{ + th.data.zhhe_act_map[item1.prom_id] = res.data.data; } + } else { + //未找到商品的活动 + is_flag = 0; + } + }) + if (!isok) { + getApp().my_warnning("组合购的活动已经过期", 0, th); + return false; + } + //------ 先增组合活动的总数量的时候 ------- + if(store_count_ok) { + var url1 = "/api/weshop/prom/zhbuyGoods/page"; + var req_data = { + page: 1, + pageSize: 2000, + store_id: os.stoid, + zh_id: item1.prom_id, } - else { - item1.act = th.data.zhhe_act_map[item1.prom_id]; - } - } - if (item1.prom_type == 10) { - if (!th.data.ladder_map[item1.prom_id]) { - //如果有预售 - var isok = 1; - var is_flag = 1; - var act = null; - var url = "/api/weshop/prom/ladderForm/get/" + os.stoid + "/" + item1.prom_id; - await getApp().request.promiseGet(url, {}).then(res => { - console.log(res, 1000); - if (res.data.code == 0 && res.data.data) { - if (res.data.data.isuse != 1) { - isok = 0; - } - //如果活动已经结束 - if (res.data.data.is_end == 1) { - isok = 0; - } - //已经结束 - if (ut.gettimestamp() > res.data.data.end_time) { - isok = 0; - } - //还未开始 - if (ut.gettimestamp() < res.data.data.start_time) { - isok = 0; + await getApp().request.promiseGet(url1, { + data: req_data + }).then(res => { + if (ut.ajax_ok(res)) { + var gdlist = res.data.data.pageData; + gdlist.forEach(i => { + if (item1.goods_id == i.goods_id && !is_flag) { + item1.prom_type = 0; + item1.prom_type1 = 0; + item1.prom_id = 0; + item1.prom_id1 = 0 } - act = res.data.data; - - } else { - //未找到商品的活动 - is_flag = 0; - } - }) - if (!isok) { - var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item1.id; - getApp().request.delete(url, {}); - th.data.ladder_map[item1.prom_id] = -1; - continue; - } - th.data.ladder_map[item1.prom_id] = act; - - //-- 获取阶梯规则 -- - var url1 = "/api/weshop/prom/ladderList/list"; - var req_data = { - store_id: os.stoid, - form_id: item1.prom_id, + }) + th.data.zuhe_map_good[item1.prom_id] = gdlist; } - await getApp().request.promiseGet(url1, { - data: req_data - }).then(rs1 => { - if (rs1.data.code == 0 && rs1.data.data) { - var gdlist = rs1.data.data; - th.data.ladder_map[item1.prom_id].ladder_list = gdlist; - } - }) - } + }) } - //-- 判断一下,获取搭配购的消息 -- - if ((item1.prom_type == 0 || item1.prom_type == 5) && (!carr[i].collocationList || !carr[i].collocationList.length)) { - await th.set_collection(item1, carr, i); - } + } + else { + item1.act = th.data.zhhe_act_map[item1.prom_id]; + } + } + if (item1.prom_type == 10) { + if (!th.data.ladder_map[item1.prom_id]) { + //如果有预售 + var isok = 1; + var is_flag = 1; + var act = null; + var url = "/api/weshop/prom/ladderForm/get/" + os.stoid + "/" + item1.prom_id; + await getApp().request.promiseGet(url, {}).then(res => { + console.log(res, 1000); + if (res.data.code == 0 && res.data.data) { + if (res.data.data.isuse != 1) { + isok = 0; + } + //如果活动已经结束 + if (res.data.data.is_end == 1) { + isok = 0; + } + //已经结束 + if (ut.gettimestamp() > res.data.data.end_time) { + isok = 0; + } + //还未开始 + if (ut.gettimestamp() < res.data.data.start_time) { + isok = 0; + } + act = res.data.data; - //在分组的时候,就不要再调用接口,await - for (var i = 0; i < carr.length; i++) { - var item = carr[i]; - //-- 如果是等级会员注册返回 -- - if (is_card_back) { - th.data.card_name = th.data.userinfo.card_field; - //如果是秒杀的返回,就要把活动弄回0 - if (item['prom_type'] == 1) { - item['prom_type'] = 0; - item['prom_id'] = 0; + } else { + //未找到商品的活动 + is_flag = 0; } - // 拼团,搭配购不计算,赠品也不计算 - if (item['prom_type'] != 5 && item['prom_type'] != 6 && !item.is_gift && !item['is_collocation'] && item.goods_price > item[th.data.card_name]) { - item.goods_price = item[th.data.card_name]; - carr[i].goods_price = item[th.data.card_name]; + }) + if (!isok) { + var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item1.id; + getApp().request.delete(url, {}); + th.data.ladder_map[item1.prom_id] = -1; + continue; + } + th.data.ladder_map[item1.prom_id] = act; + //-- 获取阶梯规则 -- + var url1 = "/api/weshop/prom/ladderList/list"; + var req_data = { + store_id: os.stoid, + form_id: item1.prom_id, + } + await getApp().request.promiseGet(url1, { + data: req_data + }).then(rs1 => { + if (rs1.data.code == 0 && rs1.data.data) { + var gdlist = rs1.data.data; + th.data.ladder_map[item1.prom_id].ladder_list = gdlist; } - } else { - // 拼团,搭配购不计算,赠品也不计算,同时会员还未购买等级会员 - if (item[th.data.card_name] > 0 && item['prom_type'] != 5 && item['prom_type'] != 6 && !th.data.userinfo.card_field - && !item.is_gift && !item['is_collocation'] && item.goods_price > item[th.data.card_name]) { - item.cut_price1 = item.goods_price - item[th.data.card_name]; - carr[i].cut_price1 = (item.goods_price - item[th.data.card_name]) * item.goods_num; - } + }) + } + } - } + if(is_change){ + carr[i].collocationList=null; + } - item.original_img = oo.imghost + item.original_img; + //-- 判断一下,获取搭配购的消息,只有prom_type==5才会判断优惠活动 -- + if ( item1.prom_type == 5 && (!carr[i].collocationList || !carr[i].collocationList.length)) { + await th.set_collection(item1, carr, i); + } + } var car_item = item; /*----接口要弄出来的,先顶着-----*/ @@ -1019,32 +1054,51 @@ Page({ //-- 把等级卡会优惠多少钱装进去 -- if (car_item.cut_price1) arr[j].card_cut_price += car_item.cut_price1; - arr[j].goods.push(car_item); - if (car_item.collocationList) { + //在分组的时候,就不要再调用接口,await + for (var i = 0; i < carr.length; i++) { + var item = carr[i]; + //-- 如果是等级会员注册返回 -- + if (is_card_back) { + th.data.card_name = th.data.userinfo.card_field; + //如果是秒杀的返回,就要把活动弄回0 + if (item['prom_type'] == 1) { + item['prom_type'] = 0; + item['prom_id'] = 0; + } + // 拼团,搭配购不计算,赠品也不计算 + if (item['prom_type'] != 5 && item['prom_type'] != 6 && !item.is_gift && !item['is_collocation'] && item.goods_price > item[th.data.card_name]) { + item.goods_price = item[th.data.card_name]; + carr[i].goods_price = item[th.data.card_name]; - if (!arr[j].collocationList) arr[j].collocationList = car_item.collocationList; - else { - var arr_new = [...arr[j].collocationList, ...car_item.collocationList]; - arr[j].collocationList = arr_new; - } - } + } + } else { + // 拼团,搭配购不计算,赠品也不计算,同时会员还未购买等级会员 + if (item[th.data.card_name] > 0 && item['prom_type'] != 5 && item['prom_type'] != 6 && !th.data.userinfo.card_field + && !item.is_gift && !item['is_collocation'] && item.goods_price > item[th.data.card_name]) { + item.cut_price1 = item.goods_price - item[th.data.card_name]; + carr[i].cut_price1 = (item.goods_price - item[th.data.card_name]) * item.goods_num; + } + } - find = 1; - break; - } - } - } - //------如果没有找到----- - if (find == 0) { - var pikname = '', sto = null; - //----找到门店名称----- - for (var k = 0; k < th.data.allsto.length; k++) { - if (pcid == th.data.allsto[k].pickup_id) { - pikname = th.data.allsto[k].pickup_name; - sto = th.data.allsto[k]; - break; + //商品的图片不能重复的赋值 + if(item.original_img.indexOf(oo.imghost)==-1) + item.original_img = oo.imghost + item.original_img; + + var car_item = item; + /*----接口要弄出来的,先顶着-----*/ + var pcid = car_item.pick_id; + var find = 0; + //----如果有就加进去,没有就新增一个---- + //-----------循环查找门店------------- + if (arr.length > 0) { + for (var j = 0; j < arr.length; j++) { + if (arr[j].pickup_id == pcid) { + if (item.is_gift != 1) { + //确定配送方式 + if (arr[j].distr_t == 0) { + arr[j].distr_t = car_item.distr_type; } } var e_t = 0, dis_t = 0;//物流方式,配送方式 @@ -1081,53 +1135,40 @@ Page({ if (def_exp_code == item.code) { m_wind = k; } + } + arr[j].exp_type = e_t; + if (e_t == 0) th.setData({ is_all_zt: 0 }); + //else if (e_t == 1) th.setData({ is_all_zt: 1 }); } - - var ie = { - pickup_id: pcid, - pname: pikname, - goods: narr, - wind: m_wind, - distr_t: dis_t, - card_cut_price: 0, - exp_type: e_t, - goods_price: 0, - shipping_price: 0, - user_money: 0, - total_amount: 0, - order_amount: 0, - user_note: "", - sto: sto - }; - //-- 把等级卡会优惠多少钱装进去 -- - if (car_item.cut_price1) ie.card_cut_price += car_item.cut_price1; + if (car_item.cut_price1) arr[j].card_cut_price += car_item.cut_price1; + arr[j].goods.push(car_item); if (car_item.collocationList) { - ie.collocationList = car_item.collocationList; + if (!arr[j].collocationList) arr[j].collocationList = car_item.collocationList; + else { + var arr_new = [...arr[j].collocationList, ...car_item.collocationList]; + arr[j].collocationList = arr_new; + } } - - arr.push(ie); + find = 1; + break; } } - //-- 如果是回退回来的情况 -- - if (th.data.cartlist && th.data.cartlist.length > 0) { - for (var kj in th.data.cartlist) { - for (var ih in arr) { - var ie = arr[ih]; - if (ie.pickup_id == th.data.cartlist[kj].pickup_id) { - ie.exp_type = parseInt(th.data.cartlist[kj].exp_type); - ie.wind = parseInt(th.data.cartlist[kj].wind); - - //-- 是不是全部自提清空 -- - if (ie.exp_type == 0 || ie.exp_type == 2) th.setData({ is_all_zt: 0 }); - break; - } - } + } + //------如果没有找到----- + if (find == 0) { + var pikname = '', sto = null; + //----找到门店名称----- + for (var k = 0; k < th.data.allsto.length; k++) { + if (pcid == th.data.allsto[k].pickup_id) { + pikname = th.data.allsto[k].pickup_name; + sto = th.data.allsto[k]; + break; } }else{ @@ -1140,110 +1181,116 @@ Page({ th.setData({ is_all_zt: is_a_zt}); } + var e_t = 0, dis_t = 0;//物流方式,配送方式 + if (item.distr_type == 0) { + dis_t = sto.distr_type; + } else { + dis_t = item.distr_type; + } + switch (dis_t) { + case 0: + e_t = 1; + //-- 系统后台有设置要默认的 -- + if (th.data.json_d.pickupway && th.data.json_d.pickupway == 1) e_t = 0; + break; + case 1: + e_t = 1; + break; + case 2: + e_t = 0; + break; + } + //如果是物流的话,全部自提的控制要弄成0 + if (e_t == 0) th.setData({ is_all_zt: 0 }); + //else th.setData({ is_all_zt: 1 }); - var cart_commission = 0; - //-- 循环计算一下线下取价 -- - for (var k = 0; k < arr.length; k++) { - var c_item = arr[k]; - var item = arr[k].goods; - var offline_price = 0; - var offline_num = 0; - //计算佣金的商品 - var commission_gds = []; - for (var c = 0; c < item.length; c++) { - - if (!item[c].is_gift) { - var hr = { - goods_id: item[c].goods_id, - goods_num: item[c].goods_num, - prom_type: item[c].prom_type, - prom_id: item[c].prom_id, - } - let req_d1 = { - user_id: getApp().globalData.user_id, goods_ids: [hr], store_id: os.stoid - } - - await getApp().request.promisePost("/api/weshop/order/getrebateSum", { - is_json: 1, data: req_d1 - }).then(grs => { - if (grs.data.code == 0) item[c].use_commission = grs.data.data; - }); - commission_gds.push(hr); - } - if (th.data.sales_rules != 2) { - item[c].offline_price = 0; - } - //-- 如果这个商品是线下取价的时候 -- - if (item[c].offline_price > 0 && item[c].prom_type != 7) { - offline_price += (item[c].goods_price - item[c].offline_price) * item[c].goods_num; - offline_num += item[c].goods_num; + var narr = new Array(); + narr.push(car_item); + + //-----------拼装购物车结算的数组,如果有默认物流时要用默认物流编号,计算默认的物流,不管是不是自提都算一下----------------- + var m_wind = 0, def_exp_code = getApp().globalData.userInfo.def_exp_code; + if (def_exp_code && !th.data.is_default_logistics) { + for (var k = 0; k < th.data.wu_arr.length; k++) { + var item = th.data.wu_arr[k]; + if (def_exp_code == item.code) { + m_wind = k; } } - if (offline_price > 0) { - c_item.offline_price = offline_price; - c_item.offline_num = offline_num; - c_item.is_offline = 1; - } - - //获取购物车的佣金,此处要优化调用接口,获取佣金 - var req_d = { - user_id: getApp().globalData.user_id, goods_ids: commission_gds, store_id: os.stoid - } - var back_data = null; - await getApp().request.promisePost("/api/weshop/order/getrebateSum", { - is_json: 1, data: req_d - }).then(rs => { - - if (rs.data.code == 0) back_data = rs.data.data; - }); + } + if (back_data && parseFloat(back_data)) { c_item.can_usecommise = parseFloat(parseFloat(back_data).toFixed(2)); cart_commission += c_item.can_usecommise; } - } + var ie = { + pickup_id: pcid, + pname: pikname, + goods: narr, + wind: m_wind, + distr_t: dis_t, + card_cut_price: 0, + exp_type: e_t, + goods_price: 0, + shipping_price: 0, + user_money: 0, + total_amount: 0, + order_amount: 0, + user_note: "", + sto: sto + }; - if (cart_commission) { - th.setData({ cart_commission }); + //-- 把等级卡会优惠多少钱装进去 -- + if (car_item.cut_price1) ie.card_cut_price += car_item.cut_price1; + if (car_item.collocationList) { + ie.collocationList = car_item.collocationList; } - //每一个门店内的组合购要进行拆分, - //还得把组合商品的多余商品的线下价格算一算 - for (let var1 in arr) { - var u_item = arr[var1]; - //把组合购进行分组 - var obj = zh_calc.find_split(u_item); - if (!obj) continue; - //存储不同活动的商品列表 - u_item.zh_prom_goods = {}; - for (let var1 in obj) { - var h_item = obj[var1]; - var gdlist = th.data.zuhe_map_good[h_item.prom_id]; - //获取活动需要的商品列表 - u_item.zh_prom_goods[h_item.prom_id] = { gdlist: gdlist, act: h_item.act }; + + arr.push(ie); + } + } + //-- 如果是回退回来的情况 -- + if (th.data.cartlist && th.data.cartlist.length > 0) { + for (var kj in th.data.cartlist) { + for (var ih in arr) { + var ie = arr[ih]; + if (ie.pickup_id == th.data.cartlist[kj].pickup_id) { + ie.exp_type = parseInt(th.data.cartlist[kj].exp_type); + ie.wind = parseInt(th.data.cartlist[kj].wind); + + //-- 是不是全部自提清空 -- + if (ie.exp_type == 0 || ie.exp_type == 2) th.setData({ is_all_zt: 0 }); + break; } - zh_calc.fir_set_arr(u_item, th); } + } + } - //每一个门店内的阶梯促销要进行拆分, - //还得把阶梯促销商品的多余商品的线下价格算一算 - for (let var2 in arr) { - var u_item1 = arr[var2]; - - //把阶梯促销进行分组 - var obj = ladder_calc.find_split(u_item1); - if (!obj) continue; - //存储不同阶梯促销活动的商品列表 - u_item1.ladder_map = {}; - for (let var1 in obj) { - var h_item = obj[var1]; - var act = th.data.ladder_map[h_item.prom_id]; - //获取活动需要的商品列表 - u_item1.ladder_map[h_item.prom_id] = act; + var cart_commission = 0; + //-- 循环计算一下线下取价 -- + for (var k = 0; k < arr.length; k++) { + var c_item = arr[k]; + if(!is_change){ + //-- 要进行归类一下活动 -- + await m_cx.cart_cx_group(th,arr[k].goods,c_item,1,1,(show_can_cx)=>{ + arr[k].show_can_cx=show_can_cx; + }) + }else{ + var show_can_cx=this.data.cartlist[k].show_can_cx; + //-- 多促销活动的优化 -- + if(show_can_cx){ + arr[k].show_can_cx=show_can_cx; } - ladder_calc.fir_set_arr(u_item1, th); - } + } + + var item = arr[k].goods; + var offline_price = 0; + var offline_num = 0; + //计算佣金的商品 + var commission_gds = []; + for (var c = 0; c < item.length; c++) { //-- 要判断总开关有没有同城配送 -- @@ -1262,35 +1309,136 @@ Page({ } } + + if (!item[c].is_gift) { + var hr = { + goods_id: item[c].goods_id, + goods_num: item[c].goods_num, + prom_type: item[c].prom_type, + prom_id: item[c].prom_id, + + } + let req_d1 = { + user_id: getApp().globalData.user_id, goods_ids: [hr], store_id: os.stoid } + + await getApp().request.promisePost("/api/weshop/order/getrebateSum", { + is_json: 1, data: req_d1 + }).then(grs => { + if (grs.data.code == 0) item[c].use_commission = grs.data.data; + }); + commission_gds.push(hr); + } + if (th.data.sales_rules != 2) { + item[c].offline_price = 0; + } + //-- 如果这个商品是线下取价的时候 -- + if (item[c].offline_price > 0 && item[c].prom_type != 7) { + offline_price += (item[c].goods_price - item[c].offline_price) * item[c].goods_num; + offline_num += item[c].goods_num; } + } + if (offline_price > 0) { + c_item.offline_price = offline_price; + c_item.offline_num = offline_num; + c_item.is_offline = 1; + } + + //获取购物车的佣金,此处要优化调用接口,获取佣金 + var req_d = { + user_id: getApp().globalData.user_id, goods_ids: commission_gds, store_id: os.stoid + } + var back_data = null; + await getApp().request.promisePost("/api/weshop/order/getrebateSum", { + is_json: 1, data: req_d + }).then(rs => { + if (rs.data.code == 0) back_data = rs.data.data; + }); + if (back_data && parseFloat(back_data)) { + c_item.can_usecommise = parseFloat(back_data); + cart_commission += c_item.can_usecommise; + } + } - //深拷贝 - th.data.old_cartlist = JSON.parse(JSON.stringify(arr)); - th.setData({ - cartlist: arr, - }); + if (cart_commission) { + th.setData({ cart_commission }); + } - //--- 获取一下看有没有优惠券 ---- - setTimeout(function () { - var frozenQuan = null; - var url0 = "/api/weshop/users/frozenQuan/listFrozenQuan/" + app.globalData.user_id; - app.request.promiseGet(url0, { 1: 1 }).then(res => { - if (res.data.code == 0) { - frozenQuan = res.data.data; - th.data.frozenQuan = frozenQuan; - } - th.calculatePrice(); - th.get_cart_quan(); - }) - }, 500) + //每一个门店内的组合购要进行拆分, + //还得把组合商品的多余商品的线下价格算一算 + for (let var1 in arr) { + var u_item = arr[var1]; + //把组合购进行分组 + var obj = zh_calc.find_split(u_item); + if (!obj) continue; + //存储不同活动的商品列表 + u_item.zh_prom_goods = {}; + for (let var1 in obj) { + var h_item = obj[var1]; + var gdlist = th.data.zuhe_map_good[h_item.prom_id]; + //获取活动需要的商品列表 + u_item.zh_prom_goods[h_item.prom_id] = { gdlist: gdlist, act: h_item.act }; + } + zh_calc.fir_set_arr(u_item, th); + } + + //每一个门店内的阶梯促销要进行拆分, + //还得把阶梯促销商品的多余商品的线下价格算一算 + for (let var2 in arr) { + var u_item1 = arr[var2]; + + //把阶梯促销进行分组 + var obj = ladder_calc.find_split(u_item1); + if (!obj) continue; + //存储不同阶梯促销活动的商品列表 + u_item1.ladder_map = {}; + for (let var1 in obj) { + var h_item = obj[var1]; + var act = th.data.ladder_map[h_item.prom_id]; + //获取活动需要的商品列表 + u_item1.ladder_map[h_item.prom_id] = act; + } + ladder_calc.fir_set_arr(u_item1, th); + } + + //-- 要判断总开关有没有同城配送 -- + if(th.data.is_same_city) { + //----- 判断每一个商品的配送方式,和门店的配送方式 ------- + for (var ik = 0; ik < arr.length; ik++) { + if (!arr[ik].sto.is_same_city) continue; + var fd = arr[ik].goods.filter(function (e) { + return e.is_same_city != 1 || e.whsle_id > 0 + }) + if (!fd || fd.length == 0) { + arr[ik].show_same_city = 1; + } } + } + + //深拷贝 + th.data.old_cartlist = JSON.parse(JSON.stringify(arr)); + th.setData({ + cartlist: arr, }); + + //--- 获取一下看有没有优惠券 ---- + setTimeout(function () { + var frozenQuan = null; + var url0 = "/api/weshop/users/frozenQuan/listFrozenQuan/" + app.globalData.user_id; + app.request.promiseGet(url0, { 1: 1 }).then(res => { + if (res.data.code == 0) { + frozenQuan = res.data.data; + th.data.frozenQuan = frozenQuan; + } + th.calculatePrice(); + th.get_cart_quan(); + }) + }, 500) }, - //-----获取立即购买的商品信息,入口---- + //-----单个商品购买的入口判断---- get_buy_goods: function (e) { var th = this; var gg = to.get_b_now(); @@ -1401,8 +1549,6 @@ Page({ th.setData({ card_cut_price: cut_p }); } } - - //-- 当是搭配购的时候 -- gd.prom_type = gg.prom_type ? gg.prom_type : 0; @@ -1803,6 +1949,51 @@ Page({ } }, + //-- 立即购买的时候,获取商品优惠活动,is_state判断是不是单个商品购买, + // 很多活动需要判断会员的plus等级, 权益登陆,user_id调用接口是必须的 -- + //先用着,后面会用接口来代替 + async buy_pro_group(item1, is_state) { + //-- 代发商品不参与任何活动 -- + if (item1.whsle_id) return false; + var th=this; + var req_d = { + store_id: os.stoid, + user_id: getApp().globalData.user_id, + goods_id: item1.goods_id, + goods_num: item1.goods_num, + goods_price: item1.goods_price, + } + //--- 调用接口获取活动 --- + await getApp().promiseGet('/api/weshop/goods/getGoodsPromInfo', {data:req_d}).then(res => { + if(res.data.code==0){ + var more_cx=res.data.data.more_cx; + for(var i=0;i { if (res.data.code == 0 && res.data.data.condition) { var get_data = res.data.data; + item_map.cy_cx=1; item_map.is_bz = get_data.is_bz; //是不是倍增 item_map.bs = get_data.bs; //是不是倍数 item_map.is_past = get_data.is_past; //是不是包邮 @@ -1946,6 +2140,7 @@ Page({ } } } + else item_map.cy_cx=0; }) } @@ -2001,6 +2196,7 @@ Page({ if (!item_map.is_xz_yh) q_conditin = o_price; } + //--------循环计算商品是不是包邮,是不是使用优惠券,此时循环是商品从表----------- for (var j = 0; j < ord_goods.length; j++) { if (ord_goods[j].whsle_id) continue; @@ -2012,12 +2208,28 @@ Page({ ord_goods[j].account_yu_fir = th.item_map_get_goods(ord_goods[j].goods_id, item_map).account_yu_fir; ord_goods[j].account = th.item_map_get_goods(ord_goods[j].goods_id, item_map).account; ord_goods[j].account_yu = th.item_map_get_goods(ord_goods[j].goods_id, item_map).account_yu; + + //-- 如果有参与促销才来进行计算 -- + if(item_map.cy_cx) { + //--------循环计算商品是不是包邮,是不是使用优惠券,此时循环是商品从表----------- + for (var j = 0; j < ord_goods.length; j++) { + if (ord_goods[j].is_gift) continue; + if (ord_goods[j].whsle_id) continue; + if (ord_goods[j].prom_type == 3 && ord_goods[j].prom_id == item_map.prom_id) { + ord_goods[j].is_xz_yh = ord_goods[j].is_xz_yh ? ord_goods[j].is_xz_yh : item_map.is_xz_yh; + ord_goods[j].is_past = item_map.is_past; + ord_goods[j].is_order_yh = item_map.is_order_yh; + ord_goods[j].is_post_temp = item_map.is_post_temp; + + ord_goods[j].account_fir = th.item_map_get_goods(ord_goods[j].goods_id, item_map).account_fir; + ord_goods[j].account_yu_fir = th.item_map_get_goods(ord_goods[j].goods_id, item_map).account_yu_fir; + ord_goods[j].account = th.item_map_get_goods(ord_goods[j].goods_id, item_map).account; + ord_goods[j].account_yu = th.item_map_get_goods(ord_goods[j].goods_id, item_map).account_yu; + } } } - - //-- -- if (item_map.price != undefined && item_map.price != null && item_map.prom_price != undefined && item_map.prom_price != null) cart_item.cut_price += (item_map.price - item_map.prom_price); @@ -2261,7 +2473,7 @@ Page({ var cart_item = c_arr[i]; //就是每一单的意思 var pickid = cart_item.pickup_id; var o_price = 0; - var o_price_no_zh = 0; //参与订单优惠叠加--组合购的金额汇总 + var o_price_no_zh = 0; //参与订单优惠累积的金额 var o_shipping_price = 0, goods_weight = -1, goods_piece = -1; var item = c_arr[i].goods; //就是每一单的从表的意思 @@ -2351,12 +2563,12 @@ Page({ var is_no_zh = 0; if (item[jc].prom_type != 7 && item[jc].prom_type != 10) is_no_zh = 1; - //组合购的商品,且有订单优惠的叠加,is_orderyh就是优惠叠加 + //组合购的商品,且有订单优惠的叠加,is_orderyh就是优惠叠加,就要累积组合购的金额 if (item[jc].prom_type == 7 && th.data.zhhe_act_map && th.data.zhhe_act_map[item[jc].prom_id] && th.data.zhhe_act_map[item[jc].prom_id].is_orderyh) { is_no_zh = 1; } - //阶梯购的商品,且有订单优惠的叠加,is_orderyh就是优惠叠加 + //阶梯购的商品,且有订单优惠的叠加,is_orderyh就是优惠叠加,就要累积阶梯促销的金额 if (item[jc].prom_type == 10 && ladder_prom_goods && ladder_prom_goods[item[jc].prom_id] && th.data.ladder_map[item[jc].prom_id].is_useorderyh) { is_no_zh = 1; @@ -2370,14 +2582,18 @@ Page({ o_price += item[jc].goods_price * item[jc].goods_num; //--- 秒杀, 团购的时候,判断有没有订单优惠和包邮模板的叠加 --- - if( [1,2,6].indexOf(item[jc].prom_type)>-1){ + if( [1,2,3,6].indexOf(item[jc].prom_type)>-1){ + + var gd_price=item[jc].goods_price; + if(item[jc].account_fir) gd_price=item[jc].account_fir; + if(!item[jc].is_order_yh && !item[jc].whsle_id){ - no_order_yh+=item[jc].goods_price * item[jc].goods_num; + no_order_yh+=gd_price * item[jc].goods_num; if(item[jc].quan_num) no_order_yh-=item[jc].quan_num; //券要把他补回去 } if(!item[jc].is_post_temp){ - no_post_temp+=item[jc].goods_price * item[jc].goods_num; + no_post_temp+=gd_price * item[jc].goods_num; if(item[jc].quan_num) no_post_temp-=item[jc].quan_num; //券要把他补回去 } } @@ -5611,7 +5827,7 @@ Page({ for (var i in goodlist) { var gd = goodlist[i]; //--如果是秒杀就跳出,如果是赠品,如果是组合购限制使用优惠券-- - if (gd.whsle_id == 1 || gd.prom_type == 1 || gd.is_gift || (gd.prom_type == 7 && gd.act.is_xz_yh) || gd.is_xz_yh == 1) { + if (gd.whsle_id == 1 || gd.prom_type == 1 || gd.is_gift || (gd.prom_type == 7 && gd.act && gd.act.is_xz_yh) || gd.is_xz_yh == 1) { continue; } @@ -5858,6 +6074,7 @@ Page({ if (res.data.code == 0) { prom = res.data.data; + if(prom && prom.limit_num*1){ let user_pre_buynum=await th.getUserBuyPromNum_pre(prom.id) if (user_pre_buynum>=prom.limit_num) { @@ -5946,6 +6163,11 @@ Page({ if (res.data.code == 0) { var get_data = res.data.data; + + //只有在活动已经开始参与优惠促销的时候 + th.data.bn_is_order_yh=prom.is_order_yh; + th.data.bn_is_post_temp=prom.is_post_temp; + arr.is_bz = prom.is_bz; //是不是倍增 arr.is_xz_yh = arr.is_xz_yh ? arr.is_xz_yh : prom.is_xz_yh; //是不是优惠 arr.bs = get_data.bs; //是不是倍数 @@ -6127,6 +6349,9 @@ Page({ ob.goods_num = item.goods_num; ob.is_bz = prom.is_bz; ob.is_xz_yh = prom.is_xz_yh; + ob.is_xz_yh = prom.is_xz_yh; + ob.is_order_yh = prom.is_order_yh; + ob.is_post_temp = prom.is_post_temp; ob.goods = new Array(); ob.goods.push({ goods_id: item.goods_id, goods_price: item.goods_price, goods_num: item.goods_num }); map[pickid][item.prom_id] = ob; @@ -6172,6 +6397,8 @@ Page({ ob.goods_num = item.goods_num; ob.is_bz = prom.is_bz; ob.is_xz_yh = prom.is_xz_yh; + ob.is_order_yh = prom.is_order_yh; + ob.is_post_temp = prom.is_post_temp; ob.goods = new Array(); ob.goods.push({ goods_id: item.goods_id, goods_price: item.goods_price, goods_num: item.goods_num }); var obj = {}; @@ -7276,7 +7503,6 @@ Page({ if (cart_commission) { th.setData({ cart_commission }); } - th.data.old_cartlist = cart_arr; }, @@ -7289,6 +7515,208 @@ Page({ } } return false; + }, + + + //-- 开始显示活动的弹出 -- + switch_cx_group:function (e){ + var idx=e.currentTarget.dataset.index; + var gd_key=e.currentTarget.dataset.gd_key; + this.data.sele_cx_group_cidx=idx; + this.data.cx_group_gd_key=gd_key; + //-- 获取到-- + var cx_prom_group=this.data.cartlist[idx].show_can_cx[gd_key].act_arr; + + var cx_arr=[]; + + for (var h=0;h-1 + && g_item.pick_id==pk + }) + if(fg>-1){ + goods[fg].prom_type=ck_prom_type.prom_type; + goods[fg].prom_id=ck_prom_type.prom_id; + th.data.cartlist_y[idx].goods[fg].prom_type= goods[fg].prom_type; + th.data.cartlist_y[idx].goods[fg].prom_id= goods[fg].prom_id; + + } + } + + wx.showLoading({ + title: "处理中.", + mask: true + }) + //-- 重新计算一下价格 -- + th.get_cart_next(null,1); + }else{ + wx.showToast({ + title: ck_res.msg, + icon: 'none', + duration:2500 + }); + + for(var dx=0;dx 0 && num > fd['limit_num']) { + func({'code': -1, 'msg': '超出优惠促销活动的限购'}); + return false; + } + } + } + + //-- 判断组合促销是不是超出活动总数量 -- + if (nei_in_zhact && Object.keys(nei_in_zhact).length) { + for (var ky in nei_in_zhact) { + + var num0 = nei_in_zhact[ky]; + var zh = this.data.zhhe_act_map[ky]; + var buyed=0; + + //获取已经购买了多少件 + var z_url = "/api/weshop/ordergoods/getUserBuyPromNum?store_id="+os.stoid+"user_id="+getApp().globalData.user_id+"prom_type=7&prom_id="+ky; + var zbuy=await getApp().request.promiseGet(z_url,{}); + if(zbuy && zbuy.data.code==0){ + buyed=zbuy.data.data.userbuynum; + } + if (zh['zh_num'] > 0 && zh['zh_buy_num'] + num0 > zh['zh_num']) { + func({'code': -1, 'msg': '超出组合购活动总数量'}); + return false; + } + } + } + + //-- 判断组合促销是不是超出活动总数量 -- + if (nei_in_zhact_gdmap && Object.keys(nei_in_zhact_gdmap).length) { + for (var key in nei_in_zhact_gdmap) { + + var num1 = nei_in_zhact_gdmap[key]; + var key_a = key.split('.'); + var gid = key_a[0]; + var pid = key_a[1]; + + //-- 商品的限购 -- + var promgoodsbuynum = 0; + var rq = { + 'store_id': os.stoid, 'user_id': getApp().globalData.user_id, 'goods_id': gid, + 'prom_type': 7, 'prom_id': pid + }; + + var res = await getApp().request.promiseGet("/api/weshop/ordergoods/getUserBuyGoodsNum", {data: rq}); + if (res && res.data.code == 0) { + promgoodsbuynum = res.data.data.promgoodsbuynum; + } + + var gdlist_arr = this.data.zuhe_map_good[pid]; + var gdlist = gdlist_arr.find(function (e) { + return e.goods_id == gid; + }) + if (gdlist['buyqty'] > 0 && num1 + promgoodsbuynum > gdlist['buyqty']) { + func({'code': -1, 'msg': '超出组合购商品的限购'}); + return false; + } + } + } + func({'code': 0, 'msg': '成功'}) } diff --git a/packageE/pages/cart/cart2/cart2.json b/packageE/pages/cart/cart2/cart2.json index b3a5ca9..0f90a97 100644 --- a/packageE/pages/cart/cart2/cart2.json +++ b/packageE/pages/cart/cart2/cart2.json @@ -3,6 +3,7 @@ "enablePullDownRefresh": false, "usingComponents": { "warn": "/components/long_warn/long_warn", - "cart_collect_temp": "/components/cart_collect_temp/cart_collect_temp" + "cart_collect_temp": "/components/cart_collect_temp/cart_collect_temp", + "pro_pop": "/components/promate_pop/promate_pop" } } \ No newline at end of file diff --git a/packageE/pages/cart/cart2/cart2.wxml b/packageE/pages/cart/cart2/cart2.wxml index 13457be..f30e58c 100644 --- a/packageE/pages/cart/cart2/cart2.wxml +++ b/packageE/pages/cart/cart2/cart2.wxml @@ -1,3 +1,6 @@ + + + @@ -82,32 +85,89 @@ {{item.pname}} - - - - - 组合购 - - - - - {{items.goods_name}} - - - - {{filters.show_gui_ge(items.goods_spec,items.goods_color)}} + + + + + + + + 组合购 + + + + {{items.goods_name}} + + + + {{filters.show_gui_ge(items.goods_spec,items.goods_color)}} + + + + + + {{filters.toFix(items.goods_price,2)}}({{items.discount}}折) + {{filters.toFix(items.goods_price,2)}} + 佣金:{{filters.toFix(items.use_commission/items.goods_num,2)}}*{{items.goods_num}} + x{{items.goods_num}} + + + + + + + + + 促销 + + + 优惠促销 + 搭配促销 + 组合购 + 阶梯促销 + + + + + + + + - - - {{filters.toFix(items.goods_price,2)}}({{items.discount}}折) - {{filters.toFix(items.goods_price,2)}} - 佣金:{{filters.toFix(items.use_commission/items.goods_num,2)}}*{{items.goods_num}} - x{{items.goods_num}} + + + + + + + + + + 促销 + + + 优惠促销 + 搭配促销 + 组合购 + 阶梯促销 + + + + + + - - + + + - + {{show_card.CardName}} 立减 {{filters.toFix(item.card_cut_price,2) }} diff --git a/packageE/pages/cart/cart2/cart2.wxss b/packageE/pages/cart/cart2/cart2.wxss index 6b8a7c6..ea3843e 100644 --- a/packageE/pages/cart/cart2/cart2.wxss +++ b/packageE/pages/cart/cart2/cart2.wxss @@ -540,9 +540,9 @@ transform: rotate(-135deg); line-height: 35rpx; text-align: center; margin-right: 20rpx +} -} .xc-hooks { width: 30rpx; height: 30rpx; @@ -1143,3 +1143,81 @@ margin-left: 20rpx; font-size: 28rpx; } + +.cx-frame { + /* border-top:3rpx solid #eee; */ + /* width:99%; + height: 95rpx; + line-height: 95rpx; + padding-left:24rpx; */ + padding: 20rpx; + background-color: #fff; +} + +.cx-frame .cx-sizs { + /* width: 68rpx; */ + /* height: 100%; */ + /* line-height: 100rpx; */ + /* overflow: hidden; */ + /* margin-left: 10rpx; */ +} + +.xc-coupon-fram { + position: relative; + margin-right: 11rpx; + /* width:200rpx; */ + /* padding-top:30rpx; */ + +} + +.xc-coupon-fram .xc-coupon { + /* width:175rpx ; + height: 40rpx; + line-height: 40rpx; */ + background-color: #d60021; + /* margin:0 auto; */ + color: #fff; + padding: 6rpx 16rpx; + +} + +.xc-coupon-fram .xc-circular { + width: 16rpx; + height: 16rpx; + background-color: white; + position: absolute; + top: 50%; + /* left: -10rpx; */ + transform: translateY(-50%); +} + +.cx-obtain-coupon { + /* width: 65rpx; + height: 100%; + padding-left:15rpx; */ + color: #d70025; + display: flex; + align-items: center; + /* position: absolute; + right: 5rpx; */ +} + +.bg_jj { + width: 14rpx; + height: 14rpx; + border-top: 2rpx solid #d70026; + border-right: 2rpx solid #d70026; + transform: rotateZ(45deg); + display: inline-block; + margin-bottom: 3rpx; +} + +.bg_jj.down { + transform: rotateZ(135deg); +} + +.bg_jj.up { + transform: rotateZ(-45deg); + margin-top: 6rpx; +} + diff --git a/packageE/pages/cart/cart2/filter.wxs b/packageE/pages/cart/cart2/filter.wxs index c0e8d13..a4f27a9 100644 --- a/packageE/pages/cart/cart2/filter.wxs +++ b/packageE/pages/cart/cart2/filter.wxs @@ -6,6 +6,23 @@ var format = function (text) { return text.replace(reg, '\n') } + +//判断商品是不是有活动切换 +function is_more_act(items,show_can_cx){ + if([1,2,4,6,8,9].indexOf(items.prom_type)>-1) return false; + if(!show_can_cx) return false; + return true; +} + +function check_show(items,sele_prom_type){ + if([7,10].indexOf(sele_prom_type)>-1){ + if(!items.is_act_last) return false; + } + return true; +} + module.exports = { - format: format + format: format, + is_more_act:is_more_act, + check_show:check_show } diff --git a/packageE/pages/cart/cart2/ladder_calculate.js b/packageE/pages/cart/cart2/ladder_calculate.js index 9c94907..80f652c 100644 --- a/packageE/pages/cart/cart2/ladder_calculate.js +++ b/packageE/pages/cart/cart2/ladder_calculate.js @@ -129,8 +129,12 @@ module.exports = { goods.splice(idx, 1); } + + //-- 只统计是参与活动的商品 -- for (var ij in goods) { + goods[ij].is_act_last=0; + var iter = goods[ij]; if (iter.prom_type != 10 || iter.prom_id != act_item.id) { continue; @@ -138,6 +142,8 @@ module.exports = { all_price0 += iter.goods_num * iter.goods_price; } + goods[goods.length-1].is_act_last=1; + if(!c_item.ladder_prom_goods) c_item.ladder_prom_goods={}; if(!c_item.ladder_prom_goods[act_item.id]) c_item.ladder_prom_goods[act_item.id]={}; diff --git a/packageE/pages/cart/cart2/zh_calculate.js b/packageE/pages/cart/cart2/zh_calculate.js index 00136fe..ceee93a 100644 --- a/packageE/pages/cart/cart2/zh_calculate.js +++ b/packageE/pages/cart/cart2/zh_calculate.js @@ -58,13 +58,12 @@ module.exports = { var zh_b_num = item_j.promgoodsbuynum; if (item.buyqty > 0) { - var key = item.goods_id + "" + act.id; + var key = item.goods_id + "." + act.id; var cbuy = item.buyqty - zh_b_num; if (th.data.in_zhact_gdmap[key]) { var cbuy = item.buyqty - zh_b_num - th.data.in_zhact_gdmap[key]; } - //当可买的数量为0 if (cbuy <= 0) { item.num = 0; @@ -129,7 +128,7 @@ module.exports = { for (var u in act_goos) { var ite = act_goos[u]; if (ite.buyqty > 0 && ite.num > 0) { - var key = ite.goods_id + "" + act.id; + var key = ite.goods_id + "." + act.id; if (th.data.in_zhact_gdmap[key]) { th.data.in_zhact_gdmap[key] += ite.num; } else { @@ -165,7 +164,7 @@ module.exports = { if(be) { if (act.is_bzyh && zhqty_bz.length > 0) { - if (zhqty_bz.length > 1) { + let zhqty_bz_arr = []; let zhqty_bz_flag = this.zhqty_bz_fun(zhqty_bz, be, zhqty_bz_arr); if (zhqty_bz_flag) { @@ -184,28 +183,12 @@ module.exports = { } else { zhqty_len = 1; let min_bz_num = Math.min.apply(Math, zhqty_bz_arr.map(function (o) { - return o['num']; + return o['be']; })); let new_arr = zhqty_bz_arr.filter(ii => { - return ii['num'] == min_bz_num; + return ii['be'] == min_bz_num; }) - var vv = new_arr[0]; - var bz_num = be * new_arr[0].zhqty; //超量倍增 - var num = min_bz_num - new_arr[0].zhqty; //购买数量减去超量 - bz_num_ok = bz_num - num; - if (bz_num_ok <= 0) { - //超量倍增满足,超量倍增就等于倍数 - bz_num_ok = bz_num; - } else { - //超量倍增不满足,倍数要减去多出得 - // be=be-bz_num_ok; - if (num % vv.zhqty == 0) { - be = num / vv.zhqty; - } else { - be = Math.floor(num / vv.zhqty) - } - bz_num_ok = be * vv.zhqty; - } + be = new_arr[0].be; for (let i = 0; i < zhqty_bz.length; i++) { let item1 = zhqty_bz[i]; @@ -221,42 +204,11 @@ module.exports = { } aprice += be * aprice; } - } else { - var vv = zhqty_bz[0]; - var bz_num = be * vv.zhqty; //超量倍增 - var num = vv['num'] - vv.zhqty; //购买数量减去超量 - if (num > 0) { - bz_num_ok = bz_num - num; - if (bz_num_ok <= 0) { - //超量倍增满足,超量倍增就等于倍数 - bz_num_ok = bz_num; - } else { - //超量倍增不满足,倍数要减去多出得 - // be=be-bz_num_ok; - if (num % vv.zhqty == 0) { - be = num / vv.zhqty; - } else { - be = Math.floor(num / vv.zhqty) - } - bz_num_ok = be * vv.zhqty; - } - for (let j = 0; j < bz_num_ok; j++) { - let index = no_in_arr.findIndex(i => { - return vv.goods_id === i.goods_id - }) - if (index > -1) { - delete_num++ - no_in_arr.splice(index, 1) - } - } - } else { - zhqty_len = 1; - } - } + } if (!zhqty_len) { - aprice += be * act.zhprice; - let pop_num = be * act.zhbuyqty - delete_num; + aprice += be1 * act.zhprice; + let pop_num = be1 * act.zhbuyqty - delete_num; for (var m = 0; m < pop_num; m++) { no_in_arr.pop(); } @@ -327,12 +279,16 @@ module.exports = { //-- 只统计是参与活动的商品 -- for (var ij in goods) { + goods[ij].is_act_last=0; var iter = goods[ij]; if (iter.prom_type != 7 || iter.prom_id != act.id) { continue; } all_price0 += iter.goods_num * iter.goods_price; } + + goods[goods.length-1].is_act_last=1; + //-- 活动的条件已经满足 -- c_item.zh_prom_goods[act.id].is_has_zh = 1; c_item.is_has_zh = 1; @@ -524,8 +480,8 @@ module.exports = { } } - }, + zhqty_bz_fun(zhqty_bz,be,zhqty_bz_arr){ let zhqty_bz_flag =true; for(let i=0;i num) { zhqty_bz_flag=false; + + var be=0; + if (num % vv.zhqty == 0) { + be = num / vv.zhqty; + } else { + be = Math.floor(num / vv.zhqty) + } + item.be=item; + zhqty_bz_arr.push(item); // zhqty_bz.splice(i,1) } } return zhqty_bz_flag; + }, + + //-- 判断组合购有没有满足,只有在检查的时候,要用新的 --- + ch_zh_ok(act,gdlist,c_goods,th,item_act_map,is_need_ck_num){ + + //-- 寻找一下 -- + function get_num(ite) { + for (let v1 in c_goods) { + var vh = c_goods[v1]; + if (vh.goods_id == ite.goods_id) { + return vh; + } + } + return 0; + } + var goods =gdlist; + var all_num=0; + var need_to_buy=0; + var all_zhqty=0; + //-- 是综合考虑到组合购的总数量和限购数量 -- + var min_can_buy=-1; + var aid=act.id; + + let no_in_arr = []; //剩余的未加入组合购 + let out_arr = []; //超出活动限购的商品放入 + + //-- 判断组合购的总数量是不是到了 -- + if(act.zh_num>0){ + //如果是在全选的情况下,那么就需要in_zhact_new来控制数量 + var need_ck=0; + if(is_need_ck_num){ + need_ck=th.data.in_zhact_new[aid]?th.data.in_zhact_new[aid]:0; + } + if(need_ck+act.zh_buy_num>=act.zh_num ){ + return false; + }else{ + min_can_buy= act.zh_num-act.zh_buy_num-need_ck; + } + } + + //-- 判断组合购的限购是不是到了 -- + if(act.buy_limit>0){ + var need_ck0=0; + if(is_need_ck_num){ + need_ck0=th.data.in_zhact_new[aid]?th.data.in_zhact_new[aid]:0; + } + var min_can_buy0=0; + if(need_ck+item_act_map.buyed>=act.buy_limit ){ + return false; + }else{ + min_can_buy0=act.buy_limit-item_act_map.buyed-need_ck; + } + if(min_can_buy>0){ + if(min_can_buy0 0) { + var cbuy = item.buyqty - zh_b_num; + var key = item.goods_id + "." + act.id; + if (is_need_ck_num && th.data.in_zhact_gdmap_new[key]) { + var cbuy = item.buyqty - zh_b_num - th.data.in_zhact_gdmap_new[key]; + } + //当可买的数量为0 + if (cbuy <= 0) { + item.num = 0; + out_arr.push({ + goods_id: item.goods_id, + num: cart_num + }) + } else { + if (cbuy >= cart_num) item.num = cart_num; + else { + item.num = cbuy; + out_arr.push({ + goods_id: item.goods_id, + num: cart_num - cbuy + }) + } + } + } else { + item.num = cart_num; + } + + if (item.num) { + all_num += item.num; + //当有起购数的控制的时候 + if (item.zhqty) { + all_zhqty += item.zhqty; + if (item.num < item.zhqty) { + need_to_buy += item.zhqty - item.num; + } + if (item.num > item.zhqty) { + for (let i = 0; i < item.num - item.zhqty; i++) { + no_in_arr.push({ + goods_id: item.goods_id, + }) + } + } + } + else { + for (let j = 0; j < item.num; j++) { + no_in_arr.push({ + goods_id: item.goods_id, + }) + } + } + } else { + if (item.zhqty) { + need_to_buy += item.zhqty; + } + } + } + + //当满足组合的要求:总数要满足,起购数要满足 + if (all_num >= act.zhbuyqty && !need_to_buy) { + //默认数量是1 + var act_num=1; + function sortData(a, b) { + return a.price - b.price + } + if (no_in_arr.length > 0) no_in_arr.sort(sortData); + if (act.zhbuyqty > all_zhqty) { + for (let n = 0; n < act.zhbuyqty - all_zhqty; n++) { + no_in_arr.pop(); + } + } + + //看一下剩下的数量有没有满足组合购的要求,以及要不要倍增 + if (act.is_bz && no_in_arr.length >= act.zhbuyqty) { + + var bz_num_ok = 0; //超量倍增是否满足 + var zhqty_len = 0; //几个超量倍增 + var delete_num = 0; + //看一下是几倍 + let be = parseInt(no_in_arr.length / act.zhbuyqty); + //如果有总数控制的时候 + if (min_can_buy>0) { + var be1 = min_can_buy - 1; + if (be1 < be) be = be1; + } + if(be) { + if (act.is_bzyh && zhqty_bz.length > 0) { + + let zhqty_bz_arr = []; + let zhqty_bz_flag = this.zhqty_bz_fun(zhqty_bz, be, zhqty_bz_arr); + if (zhqty_bz_flag) { + for (let i = 0; i < zhqty_bz.length; i++) { + var vv = zhqty_bz[i]; + for (let j = 0; j < be * vv['zhqty']; j++) { + let index = no_in_arr.findIndex(i => { + return vv.goods_id === i.goods_id + }) + if (index > -1) { + delete_num++ + no_in_arr.splice(index, 1) + } + } + } + } else { + zhqty_len = 1; + let min_bz_num = Math.min.apply(Math, zhqty_bz_arr.map(function (o) { + return o['be']; + })); + let new_arr = zhqty_bz_arr.filter(ii => { + return ii['be'] == min_bz_num; + }) + //-- 要看一下倍数还有没有 --- + be = new_arr[0].be; + //如果有总数控制的时候 + if (min_can_buy>0) { + var be1 = min_can_buy - 1; + if (be1 < be) be = be1; + } + if(be){ + for (let i = 0; i < zhqty_bz.length; i++) { + let item1 = zhqty_bz[i]; + for (let j = 0; j < be * item1['zhqty']; j++) { + let index = no_in_arr.findIndex(i => { + return item1.goods_id === i.goods_id + }) + if (index > -1) { + no_in_arr.splice(index, 1) + } + } + } + act_num+=be; + } + } + } + if (!zhqty_len) { + let pop_num = be * act.zhbuyqty - delete_num; + for (var m = 0; m < pop_num; m++) { + no_in_arr.pop(); + } + act_num+=be; + } + } + } + + //-- 参与活动的金额要返回回去 -- + item_act_map.act_num=act_num; + let goods_map = {}; + //算一下剩余的商品 + if (no_in_arr.length) { + for (let ii in no_in_arr) { + let item = no_in_arr[ii]; + if (goods_map[item.goods_id]) { + var num = goods_map[item.goods_id]; + goods_map[item.goods_id] = ++num; + } else { + goods_map[item.goods_id] = 1; + } + } + } + //超量的部分也要计算一下 + if (out_arr.length) { + for (var m in out_arr) { + if (goods_map[item.goods_id]) { + var num = goods_map[item.goods_id]; + num += item.num + goods_map[item.goods_id] = num; + } else { + goods_map[item.goods_id] = item.num; + } + } + } + + //-- 组合购的商品限购的数组控制 -- + var in_zhact_gdmap={}; + //商品的列表 + for (var u in goods) { + var ite = goods[u]; + var cart_num = get_num(ite).goods_num; + + if (ite.buyqty > 0 && cart_num > 0) { + var key = ite.goods_id + "." + act.id; + if(goods_map[ite.goods_id]){ + cart_num-=goods_map[ite.goods_id]; + } + if(cart_num>0){ + if (in_zhact_gdmap[key]) { + in_zhact_gdmap[key] += ite.num; + } else { + in_zhact_gdmap[key] = ite.num; + } + } + + } + } + item_act_map.in_zhact_gdmap=in_zhact_gdmap; + return true; + } + return false; } diff --git a/pages/cart/cart/cart.js b/pages/cart/cart/cart.js index 0ca4195..896c136 100644 --- a/pages/cart/cart/cart.js +++ b/pages/cart/cart/cart.js @@ -8,7 +8,9 @@ var t = getApp(), zh_calc = require("zh_calculate.js"), ladder_calc = require("ladder_calculate.js"); var regeneratorRuntime = require('../../../utils/runtime.js'); - +const e = require("../../../utils/common.js"); +//公共的函数合并在一起 +const m_cx = require("../../../utils/more_cx.js"); Page({ data: { @@ -40,23 +42,77 @@ Page({ zhhe_prom: [], //组合活动需要显示差多少件 zuhe_map: {}, zuhe_map_good: {}, + in_zhact_gdmap: {}, //不同门店参与同一活动的限购 + in_zhact:{}, //组合购活动在列表中的显示 + in_yhact:{}, //优惠活动在列表中的显示 + in_zh_gd_buy_map:{}, //就是商品在组合购中的 ladder_map: {}, //阶梯促销需要的map promgoods_map: {}, - promgoods_list: {} + promgoods_list: {}, + + in_zhact_gdmap_new: {}, //不同门店参与同一活动的限购,这些都是map表,是多促销互动专用,不能和in_zhact_gdmap重叠 + in_zhact_new:{}, //组合购活动在列表中的显示 是多促销互动专用,不能和in_zhact重叠 + in_yhact_new:{}, //组合购活动在列表中的显示 是多促销互动专用,不能和in_yhact重叠 + + }, + + //-- 立即购买的时候,获取商品优惠活动,is_state判断是不是单个商品购买, + // 很多活动需要判断会员的plus等级, 权益登陆,user_id调用接口是必须的 -- + //先用着,后面会用接口来代替 + async buy_pro_group(item1, is_state) { + //-- 代发商品不参与任何活动 -- + if(item1.whsle_id) return false; + + var th=this; + var req_d = { + store_id: os.stoid, + user_id: getApp().globalData.user_id, + goods_id: item1.goods_id, + goods_num: item1.goods_num, + goods_price: item1.goods_price, + } + //--- 调用接口获取活动 --- + await getApp().promiseGet('/api/weshop/goods/getGoodsPromInfo', {data:req_d}).then(res => { + if(res.data.code==0){ + + var more_cx=res.data.data.more_cx; + for(var i=0;i 0) { var g_arr = []; for (var i = 0; i < carr.length; i++) { - - //-- 清理购物车的选中状态 -- var url = '/api/weshop/cart/update'; getApp().request.put(url, { @@ -495,8 +550,6 @@ Page({ var item = carr[i]; var good = item; - - if (item.is_gift) { var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id; getApp().request.delete(url, { @@ -550,82 +603,36 @@ Page({ } //-- 如果有优惠促销,和阶梯促销,要看下有没有组合购,搭配购,看一下优惠促销和阶梯促销谁是指定商品参与的 -- - if(item.prom_type==0 || item.prom_type==3 || item.prom_type==10){ - + if(item.prom_type==3 || item.prom_type==5 || item.prom_type==7 || item.prom_type==10){ var c_prom_type=0; var c_prom_id=0; - //因为有全场优惠活动,商品参加的活动还未开始 - var url_ch_more_act = "/api/weshop/activitylist/getGoodActInfo"; - var req_data_m = { - store_id: os.stoid, goodsidlist: item.goods_id, is_detail: 1, user_id: user_id - }; - await getApp().request.promiseGet(url_ch_more_act, { data: req_data_m }).then(async function (res) { - if (res.data.code == 0 && res.data.data && res.data.data.length) { - //-- 先看一下有没有组合购 -- - var zh_fd=res.data.data.filter(function (e) { - return e.prom_type==7; - }) - if(zh_fd && zh_fd.length){ - c_prom_type=zh_fd[0].prom_type; - c_prom_id=zh_fd[0].act_id; - return; - } - - //-- 先看一下有没有搭配购 -- - var dp_fd=res.data.data.filter(function (e) { - return e.prom_type==5; - }) - if(dp_fd && dp_fd.length){ - c_prom_type=dp_fd[0].prom_type; - c_prom_id=dp_fd[0].act_id; - return; - } - - //-- 先看一下有没有指定优惠促销 -- - var yh_fd=res.data.data.filter(function (e) { - return e.prom_type==3 && e.good_object==1; - }) - if(yh_fd && yh_fd.length){ - c_prom_type=yh_fd[0].prom_type; - c_prom_id=yh_fd[0].act_id; - return; - } + item.prom_type=c_prom_type; + item.prom_id=c_prom_id; - //-- 先看一下有没有指定阶梯促销 -- - var jt_fd=res.data.data.filter(function (e) { - return e.prom_type==10 && e.good_object==1; - }) - if(jt_fd && jt_fd.length){ - c_prom_type=jt_fd[0].prom_type; - c_prom_id=jt_fd[0].act_id; - } + if (th.data.card_field && good[th.data.card_field]) { + item.goods_price = good[th.data.card_field]; //要同步下线商品的id + } else { + item.goods_price = good.shop_price; + } - } + //-- 购物车更新 -- + var updata1 = { + id: item.id, + prom_type: c_prom_type, + prom_id:c_prom_id, + store_id: os.stoid, + user_id: getApp().globalData.userInfo.user_id + }; + getApp().request.put("/api/weshop/cart/update", { + data: updata1, }) - if(c_prom_type && (c_prom_type!=item.prom_type || c_prom_id!=item.prom_id )){ - item.prom_type=c_prom_type; - item.prom_id=c_prom_id; - //-- 购物车更新 -- - var updata1 = { - id: item.id, - prom_type: c_prom_type, - prom_id:c_prom_id, - store_id: os.stoid, - user_id: getApp().globalData.userInfo.user_id - }; - getApp().request.put("/api/weshop/cart/update", { - data: updata1, - }) - } - } //判断如果是普通商品,后面参加活动了,变成失效商品 if (item.prom_type == 0 ) { - var prom = null; var now = ut.gettimestamp(); await getApp().request.promiseGet(`/api/weshop/activitylist/listGoodActInfo2New`, { @@ -644,41 +651,20 @@ Page({ prom.push(a_item); } } - - } }) - let prom_true = 0 - let prom_id = 0 - if (prom) { - prom.map(item => { - if (item.prom_type == 3 || item.prom_type == 5 || item.prom_type == 7 || item.prom_type == 10) { - prom_true = item.prom_type - prom_id = item.act_id - } - }) - } - if (prom_true) { - //-- 购物车更新 -- - var updata1 = { - id: item.id, - prom_type: prom_true, - prom_id, - store_id: os.stoid, - user_id: getApp().globalData.userInfo.user_id - }; - item.prom_id = prom_id - item.prom_type = prom_true - getApp().request.put("/api/weshop/cart/update", { - data: updata1, - }) - } else { - if (prom && !item.is_integral_normal && !item.is_pd_normal && prom[0].prom_type != 5) { - th.disInvalid(item); + //只有一种活动,但是又是秒杀之类是互动,就要失效。不能是普通购买 + if (prom.length==1 && [1,2,4,6,8,9].indexOf(prom.prom_type)>-1 && !prom.is_integral_normal && !prom.is_pd_normal) { + th.disInvalid(item); + continue; + } + //只有秒杀和积分购的时候,不能是普通购买 + if (prom.length==2 && [1,4].indexOf(prom.prom_type)>-1 && [1,4].indexOf(prom.prom_type)>-1 && !prom.is_integral_normal && !prom.is_pd_normal) { + th.disInvalid(item); continue; - } } + } @@ -699,7 +685,6 @@ Page({ }) } - //如果秒杀活动都去掉了,或者结束了,那么这个商品也没有必要留着 if (item.prom_type == 1) { var prom = null; @@ -784,392 +769,7 @@ Page({ } - //--判断优惠活动有没有过期,-- - else if (item.prom_type == 3) { - var isok = 1, is_g_prom = 0; - - //因为有全场优惠活动,商品参加的活动还未开始 - var url = "/api/weshop/activitylist/getGoodActInfo"; - var req_data = { - store_id: os.stoid, goodsidlist: item.goods_id, is_detail: 1, user_id: user_id - }; - await getApp().request.promiseGet(url, { data: req_data }).then(async function (res) { - if (res.data.code == 0 && res.data.data && res.data.data.length) { - for (let i in res.data.data) { - let item = res.data.data[i]; - if (item.prom_type == 3) { - is_g_prom = 1; break; - } - } - } - }) - - if (is_g_prom) { - await getApp().request.promiseGet("/api/weshop/goods/getGoodsPromListNew/" + os.stoid + "/" + item.goods_id + "/1" + "/" + getApp().globalData.user_id, {}).then(res => { - if (res.data.code == 0) { - var r_data = res.data.data; - if (!r_data.promGoodsLists) { - // var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id; - // getApp().request.delete(url, {}); - //商品已经无活动 - // th.disInvalid(item); - // isok = 0; - item.prom_type = 0 - //购物车更新 - th.cartUpFn(item) - } else { - //如果活动的ID不一样,说明原先的活动已经没有参与了或者过期了 - if (item.prom_id != r_data.promGoodsLists[0].prom_id) { - // var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id; - // getApp().request.delete(url, {}); - //商品已经下架 - // th.disInvalid(item); - // isok = 0; - item.prom_type = 0 - //购物车更新 - th.cartUpFn(item) - } - } - - } else { - // var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id; - // getApp().request.delete(url, {}); - // th.disInvalid(item); - // //商品已经下架 - // isok = 0; - item.prom_type = 0 - //购物车更新 - th.cartUpFn(item) - } - }) - - } else { - await getApp().request.promiseGet("/api/weshop/goods/getGoodsPromNormal/" + os.stoid + "/" + item.goods_id, {}).then(res => { - if (res.data.code == 0) { - var r_data = res.data.data; - if (!r_data.promGoodsLists) { - // var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id; - // getApp().request.delete(url, {}); - // th.disInvalid(item); - // //商品已经无活动 - // isok = 0; - item.prom_type = 0 - //购物车更新 - th.cartUpFn(item) - } else { - //如果活动的ID不一样,说明原先的活动已经没有参与了或者过期了 - if (item.prom_id != r_data.promGoodsLists[0].prom_id) { - // var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id; - // getApp().request.delete(url, {}); - // th.disInvalid(item); - // //商品已经下架 - // isok = 0; - item.prom_type = 0 - //购物车更新 - th.cartUpFn(item) - } - } - - } else { - // var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id; - // getApp().request.delete(url, {}); - // th.disInvalid(item,1); - // //商品已经下架 - // isok = 0; - item.prom_type = 0 - //购物车更新 - th.cartUpFn(item) - } - }) - } - // if (!isok) continue; - } - else if (item.prom_type == 7) { - console.log('组合购------------'); - if (!th.data.zuhe_map[item.prom_id]) { - console.log('组1') - //如果有组合购 - var isok = 1; - var is_flag = 1; - var act = null; - var url = "/api/weshop/prom/zhbuy/get/" + os.stoid + "/" + item.prom_id + "/" + getApp().globalData.user_id; - await getApp().request.promiseGet(url, {}).then(res => { - console.log(res); - if (res.data.code == 0 && res.data.data) { - if (res.data.data.is_show != 1) { - isok = 0; - } - //如果活动已经结束 - if (res.data.data.is_end == 1) { - isok = 0; - } - //已经结束 - if (ut.gettimestamp() > res.data.data.end_time) { - isok = 0; - } - //还未开始 - if (ut.gettimestamp() < res.data.data.start_time) { - isok = 0; - } - if(res.data.data.zh_num>0 && res.data.data.zh_num<=res.data.data.zh_buy_num){ - isok = 0; - } - - act = res.data.data; - - } else { - //未找到商品的活动 - is_flag = 0; - } - }) - if (!isok) { - // var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id; - // getApp().request.delete(url, {}); - //组合购失效不处理 - // th.disInvalid(item); - // th.data.zuhe_map[item.prom_id] = -1; - // continue; - item.prom_type = 0 - //购物车更新 - th.cartUpFn(item) - } else { - th.data.zuhe_map[item.prom_id] = act; - var url1 = "/api/weshop/prom/zhbuyGoods/page"; - var req_data = { - page: 1, - pageSize: 2000, - store_id: os.stoid, - zh_id: item.prom_id, - } - await getApp().request.promiseGet(url1, { - data: req_data - }).then(res => { - console.log(res, 2000); - if (ut.ajax_ok(res)) { - var gdlist = res.data.data.pageData; - gdlist.forEach(i => { - if (item.goods_id == i.goods_id && !is_flag) { - item.prom_type = 0; - item.prom_type1 = 0; - item.prom_id = 0; - item.prom_id1 = 0 - } - }) - th.data.zuhe_map_good[item.prom_id] = gdlist; - } - }) - } - } - console.log('组2') - if (th.data.zuhe_map[item.prom_id] && th.data.zuhe_map[item.prom_id] != -1) { - console.log('组3') - var gdlist = th.data.zuhe_map_good[item.prom_id]; - var t_item = gdlist.find(function (ele) { - return ele.goods_id == item.goods_id - }) - if (!t_item) { - // var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id; - // getApp().request.delete(url, {}); - //组合购不处理 - // th.disInvalid(item,1); - // th.data.zuhe_map[item.prom_id] = -1; - // continue; - item.prom_type = 0 - //购物车更新 - th.cartUpFn(item) - } else { - let act =th.data.zuhe_map[item.prom_id] - //判断是否超出组合购次数限制 - - if(act.buy_limit !=0){ - let userbuynum = await th.getUserBuyPromNum(item.goods_prom_id) - if(userbuynum>=act.buy_limit){ - item.goods_prom_type = 0 - item.goods_prom_id = 0 - item.prom_type = 0 - item.prom_id = 0 - //购物车更新 - th.cartUpFn(item) - }else{ - item.buyqty = t_item.buyqty; - item.zh_b_num = promgoodsbuynum; - item.act = th.data.zuhe_map[item.prom_id]; - } - }else{ - item.buyqty = t_item.buyqty; - item.zh_b_num = promgoodsbuynum; - item.act = th.data.zuhe_map[item.prom_id]; - } - } - } //else{ - // var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id; - // getApp().request.delete(url, {}); - // th.data.zuhe_map[item.prom_id]=-1; - // continue; - // } - } - else if (item.prom_type == 10) { - if (!th.data.ladder_map[item.prom_id]) { - //如果有阶梯购 - var isok = 1; - var is_flag = 1; - var act = null; - var url = "/api/weshop/prom/ladderForm/getNew/" + os.stoid + "/" + user_id + "/" + item.prom_id; - await getApp().request.promiseGet(url, {}).then(res => { - console.log(res, 1000); - if (res.data.code == 0 && res.data.data) { - if (res.data.data.isuse != 1) { - isok = 0; - } - //如果活动已经结束 - if (res.data.data.is_end == 1) { - isok = 0; - } - //已经结束 - if (ut.gettimestamp() > res.data.data.end_time) { - isok = 0; - } - //还未开始 - if (ut.gettimestamp() < res.data.data.start_time) { - isok = 0; - } - act = res.data.data; - - } else { - //未找到商品的活动 - isok = 0; - } - }) - if (!isok) { - // var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id; - // getApp().request.delete(url, {}); - th.disInvalid(item, 1); - th.data.ladder_map[item.prom_id] = -1; - continue; - } - th.data.ladder_map[item.prom_id] = act; - - //-- 获取阶梯规则 -- - var url1 = "/api/weshop/prom/ladderList/list"; - var req_data = { - store_id: os.stoid, - form_id: item.prom_id, - } - await getApp().request.promiseGet(url1, { - data: req_data - }).then(rs1 => { - if (rs1.data.code == 0 && rs1.data.data) { - var gdlist = rs1.data.data; - th.data.ladder_map[item.prom_id].ladder_list = gdlist; - } - }) - } - //直接把活动赋值给元素 - if (th.data.ladder_map[item.prom_id] && th.data.ladder_map[item.prom_id] != -1) { - item.act = th.data.ladder_map[item.prom_id]; - } - - } - //判断不是代发的商品 - else if (item.prom_type == 0 && !item.whsle_id) { - - //如果有优惠活动,要更新活动 - await getApp().request.promiseGet("/api/weshop/goods/getGoodsPromList/" + os.stoid + "/" + item.goods_id + "/1" + "/" + getApp().globalData.user_id, {}).then(res => { - if (res.data.code == 0 && res.data.data) { - var r_data = res.data.data; - if (r_data.promGoodsLists) { - var url = '/api/weshop/cart/update'; - getApp().request.put(url, { - data: { - id: item.id, - store_id: oo.stoid, - prom_type: 3, - prom_id: r_data.promGoodsLists[0].prom_id - } - }); - item.prom_type = 3; - item.prom_id = r_data.promGoodsLists[0].prom_id; - } else if (r_data.ladderLists) { - item.prom_type = 10; - item.prom_id = r_data.ladderLists[0].form_id; - - } - } - }) - - //如果是阶梯购的时候 - if (item.prom_type == 10) { - - - if (!th.data.ladder_map[item.prom_id]) { - //如果有阶梯购,要判断身份 - var isok = 1; - var is_flag = 1; - var act = null; - var url = "/api/weshop/prom/ladderForm/getNew/" + os.stoid + "/" + user_id + "/" + item.prom_id; - await getApp().request.promiseGet(url, {}).then(res => { - console.log(res, 1000); - if (res.data.code == 0 && res.data.data) { - if (res.data.data.isuse != 1) { - isok = 0; - } - //如果活动已经结束 - if (res.data.data.is_end == 1) { - isok = 0; - } - //已经结束 - if (ut.gettimestamp() > res.data.data.end_time) { - isok = 0; - } - //还未开始 - if (ut.gettimestamp() < res.data.data.start_time) { - isok = 0; - } - act = res.data.data; - - } else { - //未找到商品的活动 - isok = 0; - } - }) - if (!isok) { - item.prom_type = 0; - item.prom_id = 0; - } else { - - th.data.ladder_map[item.prom_id] = act; - //-- 获取阶梯规则 -- - var url1 = "/api/weshop/prom/ladderList/list"; - var req_data = { - store_id: os.stoid, - form_id: item.prom_id, - } - await getApp().request.promiseGet(url1, { - data: req_data - }).then(rs1 => { - if (rs1.data.code == 0 && rs1.data.data) { - var gdlist = rs1.data.data; - th.data.ladder_map[item.prom_id].ladder_list = gdlist; - } - }) - } - - } - //直接把活动赋值给元素 - if (th.data.ladder_map[item.prom_id] && th.data.ladder_map[item.prom_id] != -1) { - item.act = th.data.ladder_map[item.prom_id]; - - //如果有活动,就更新商品的活动那个 - var url = '/api/weshop/cart/update'; - getApp().request.put(url, { - data: { id: item.id, store_id: oo.stoid, prom_type: 10, prom_id: item.prom_id } - }); - - } - } - - } all_num += item.goods_num; item.original_img = oo.imghost + item.original_img; @@ -1177,26 +777,9 @@ Page({ item.erpwareid = good.erpwareid; //要同步下线商品的id item.shop_price = good.shop_price; //要同步下线商品的id - //当商品要计算等级价的售 - if (item.prom_type == 0 || item.prom_type == 3 || item.prom_type == 5 || item.prom_type == 7) { - if (th.data.card_field && good[th.data.card_field]) { - item.goods_price = good[th.data.card_field]; //要同步下线商品的id - } else { - item.goods_price = good.shop_price; - } - - var t = { - id: item.id, - store_id: os.stoid, - user_id: getApp().globalData.userInfo.user_id, - goods_price: item.goods_price - } - getApp().request.put("/api/weshop/cart/update", { - isShowLoading: 0, - data: t, - }) - - } + //-- 读出每一种商品的所有的活动,方便后面的活动切换使用 -- + if(item.prom_type==0) + th.buy_pro_group(item,0); var pcid = item.pick_id; var find = 0; @@ -1251,21 +834,6 @@ Page({ } } } - - for (let u1 in arr) { - var u_item = arr[u1]; - //把组合购进行分组 - var obj = zh_calc.find_split(u_item); - if (!obj) continue; - //存储不同活动的商品列表 - u_item.zh_prom_goods = {}; - for (let var1 in obj) { - var h_item = obj[var1]; - var gdlist = th.data.zuhe_map_good[h_item.prom_id]; - //获取活动需要的商品列表 - u_item.zh_prom_goods[h_item.prom_id] = gdlist; - } - } th.setData({ requestData: arr, @@ -1533,7 +1101,6 @@ Page({ } }, - //删除商品 delete_th_item: function (t) { var e = this; @@ -1571,6 +1138,8 @@ Page({ var th = this; if (a = isNaN(t.detail.value) || t.detail.value < 1 ? 1 : parseInt(t.detail.value)) { + this.clear_req(); + var s = { goods_num: a, goods_id: e.goods_id, @@ -1582,7 +1151,17 @@ Page({ }, //-------------加数量--------------------- + clear_req:function (){ + var carr=this.data.requestData; + for(var i=0;i -1){ @@ -1657,18 +1239,24 @@ Page({ } } - var e = { - goods_num: a.goods_num - add_num, - id: a.id, - goods_id: a.goods_id, - store_id: oo.stoid - }; + if(e.goods_num<=0){ this.data.up_dating = 0; return false; + this.clear_req(); } - this.postCardList(e, t.currentTarget.dataset.item, t.currentTarget.dataset.pitems); + + var e = { + goods_num: a.goods_num - add_num, + id: a.id, + goods_id: a.goods_id, + store_id: oo.stoid + }; + this.postCardList(e, t.currentTarget.dataset.item, t.currentTarget.dataset.pitems); + + + }, @@ -1822,16 +1410,19 @@ Page({ this.data.btn_click = 1; - - var offline_price = 0; var offline_num = 0; th.data.in_zhact_gdmap = {}; - var pro_off=false + var pro_off=false; if (dda && dda.length > 0) { for (var i = 0; i < dda.length; i++) { var item = dda[i].goods; + var txt0 = "requestData[" + i + "].show_can_cx"; + e.setData({ + [txt0]: {}, + }); + if (e.data.checkAllToggle) { var txt = "requestData[" + i + "].selected"; @@ -1845,6 +1436,7 @@ Page({ if (item[j].is_gift) continue; var obj = JSON.parse(JSON.stringify(item[j])); + //-- 判断起购数量 -- if(!e.data.checkAllToggle){ //判断是不是有促销活动 @@ -1858,6 +1450,13 @@ Page({ //计算之前先移除阶梯购的计算 if (obj.prom_type == 10) ladder_calc.remove_ladder_prom(dda, i, obj); + // //计算之前先移除组合购的计算 + // if (obj.prom_type == 7) + // zh_calc.remove_zhprom(dda, i, obj); + // //计算之前先移除阶梯购的计算 + // if (obj.prom_type == 10) + // ladder_calc.remove_ladder_prom(dda, i, obj); + if (fir == 0) { @@ -1873,10 +1472,11 @@ Page({ if (e.data.checkAllToggle) obj.goods_num = 0; - //加入组合购计算 - if (obj.prom_type == 7) zh_calc.add_zhprom(dda, i, obj); - //加入阶梯促销计算 - if (obj.prom_type == 10) ladder_calc.add_ladder_prom(dda, i, obj); + // //加入组合购计算 + // if (obj.prom_type == 7) zh_calc.add_zhprom(dda, i, obj); + // //加入阶梯促销计算 + // if (obj.prom_type == 10) ladder_calc.add_ladder_prom(dda, i, obj); + //多门店,多优惠次数控制 let pro_off1=false @@ -1921,6 +1521,21 @@ Page({ offline_num += item[j].goods_num; } } + e.setData({ + [txt]: !e.data.checkAllToggle, + }) + // if (!e.data.checkAllToggle) { + // //组合购的金额要另外算 + // if (item[j].prom_type != 7 && item[j].prom_type != 10) + // tfeel += item[j].goods_num * item[j].goods_price; + // t_num += item[j].goods_num; + // } + // + // //-- 如果这个商品是线下取价的时候 -- + // if (item[j].is_offline && item[j].prom_type != 7) { + // offline_price += (item[j].goods_price - item[j].offline_price) * item[j].goods_num; + // offline_num += item[j].goods_num; + // } } @@ -1953,35 +1568,35 @@ Page({ // } //总的价格,把组合商品的价格拿出来 - var zh_calc_res = zh_calc.calculate_zh(dda, i, this); - tfeel += zh_calc_res.tfeel; - offline_price += zh_calc_res.offline_price; - offline_num += zh_calc_res.offline_num; - - //总的价格,把阶梯促销的商品的价格拿出来 - var ladder_calc_res = ladder_calc.calculate_ladder(dda, i, this); - tfeel += ladder_calc_res.tfeel; - offline_price += ladder_calc_res.offline_price; - offline_num += ladder_calc_res.offline_num; - - //当有线下取价的时候 - if (offline_price) { - var txt1 = "requestData[" + i + "].offline_price"; - var txt2 = "requestData[" + i + "].offline_num"; - th.setData({ - [txt1]: offline_price.toFixed(2), - [txt2]: offline_num, - }); - } else { - if (dda[i].offline_price > 0) { - var txt1 = "requestData[" + i + "].offline_price"; - var txt2 = "requestData[" + i + "].offline_num"; - th.setData({ - [txt1]: 0, - [txt2]: 0 - }); - } - } + // var zh_calc_res = zh_calc.calculate_zh(dda, i, this); + // tfeel += zh_calc_res.tfeel; + // offline_price += zh_calc_res.offline_price; + // offline_num += zh_calc_res.offline_num; + // + // //总的价格,把阶梯促销的商品的价格拿出来 + // var ladder_calc_res = ladder_calc.calculate_ladder(dda, i, this); + // tfeel += ladder_calc_res.tfeel; + // offline_price += ladder_calc_res.offline_price; + // offline_num += ladder_calc_res.offline_num; + // + // //当有线下取价的时候 + // if (offline_price) { + // var txt1 = "requestData[" + i + "].offline_price"; + // var txt2 = "requestData[" + i + "].offline_num"; + // th.setData({ + // [txt1]: offline_price.toFixed(2), + // [txt2]: offline_num, + // }); + // } else { + // if (dda[i].offline_price > 0) { + // var txt1 = "requestData[" + i + "].offline_price"; + // var txt2 = "requestData[" + i + "].offline_num"; + // th.setData({ + // [txt1]: 0, + // [txt2]: 0 + // }); + // } + // } } //多门店优惠次数控制 if (pro_off) { @@ -1997,9 +1612,12 @@ Page({ // checkAllToggle: !e.data.checkAllToggle, total_fee: tfeel.toFixed(2), total_num: t_num, + }); - e.all_check_prom_activity(); + this.doCheckAll(function (){ + e.all_check_prom_activity(); + }); } } @@ -2134,12 +1752,10 @@ Page({ title: '购买数量超出商品库存', icon: 'none', }); - return false; } } } - } //判断多店优惠促销次数控制 @@ -2172,17 +1788,55 @@ Page({ e.setData({ [txt]: Number(!sele), }); - } - e.data.duo_zp_num_arr = {}; - if (sele) { - await e.check_prom_activity(pitems); } - for (var i in e.data.requestData) { - if (sele && i == pitems) continue; - await e.check_prom_activity(i); + + //-- 选择了什么商品,就用什么商品来判断 -- + var sele_arr={}; + for (var i = 0; i < item.length; i++) { + sele_arr[i] = !sele; } - this.doCheckAll(); + + //-- 回调判断活动有没有冲突 -- + this.cx_check_ok(pitems,sele_arr,function (the_res) { + if(the_res.code==0) { + + + //-- 门店是所有的商品都要选择 -- + for (var i = 0; i < item.length; i++) { + var txt0 = "requestData[" + pitems + "].goods[" + i + "].selected"; + e.setData({ + [txt0]: Number(!sele), + }); + } + + //-- 门店按钮的选择 -- + var txt = "requestData[" + pitems + "].selected"; + e.setData({ + [txt]: Number(!sele), + }); + + th.doCheckAll(async function () { + + + + e.data.duo_zp_num_arr = {}; + if (sele) { + await e.check_prom_activity(pitems); + } + for (var i in e.data.requestData) { + if (sele && i == pitems) continue; + await e.check_prom_activity(i); + } + }); + }else{ + wx.showToast({ + title: the_res.msg, + icon: 'none', + }); + } + }) + }, //判断多门店,优惠促销次数的控制 @@ -2332,10 +1986,8 @@ Page({ } } - } - let pro_off=false //判断多店优惠促销次数控制 if (th.data.requestData.length>1) { @@ -2352,23 +2004,44 @@ Page({ return false; } + var txt0 = "requestData[" + pitems + "].show_can_cx"; e.setData({ - [txt]: Number(!a.selected), + [txt0]: {}, }); - if (a.prom_type == 3) { - e.data.duo_zp_num_arr = {}; - if (!a.selected) { - await e.check_prom_activity(pitems); - } - //判断商品是不是优惠活动 - for (var i in e.data.requestData) { - if (!a.selected && i == pitems) continue; - await e.check_prom_activity(i); - } - } - this.doCheckAll(); + //-- 选择了什么商品,就用什么商品来判断 -- + var sele_arr={}; + sele_arr[item]=!a.selected; + //回调判断活动有没有冲突 + this.cx_check_ok(pitems,sele_arr,function (the_res){ + if(the_res.code==0){ + th.setData({ + [txt]: Number(!a.selected), + }); + //要先处理了,再来判断要不要显示凑单 + th.doCheckAll(async function (){ + if (a.prom_type == 3) { + e.data.duo_zp_num_arr = {}; + if (!a.selected) { + await e.check_prom_activity(pitems); + } + //判断商品是不是优惠活动 + for (var i in e.data.requestData) { + if (!a.selected && i == pitems) continue; + await e.check_prom_activity(i); + } + } + + }); + }else{ + wx.showToast({ + title: the_res.msg, + icon: 'none', + }); + } + }) + } }, @@ -2459,7 +2132,7 @@ Page({ }, //----------检查是否全选--------- - doCheckAll: function () { + doCheckAll:async function (func,n_ok) { var th = this, tfeel = 0, t_num = 0, @@ -2468,100 +2141,181 @@ Page({ car2 = this.data.service_data, all_num = 0; + + //-- 如果是全部的时候,就要把它清理掉 -- + this.data.in_zhact_gdmap_new={}; + this.data.in_zhact_new={}; + this.data.in_yhact_new={}; + //-- 购物车 -- if (car && car.length > 0) { th.data.in_zhact_gdmap = {}; + + //-- 第一次过滤,show_can_cx的还要遍历一遍,确保数据的正确性 -- + var rd_arr=[]; for (var a = 0; a < car.length; a++) { - var item = car[a].goods, is_s_sele = 1; - var offline_price = 0; - var offline_num = 0; - for (var c = 0; c < item.length; c++) { - if (item[c].is_gift) continue; - all_num += item[c].goods_num; + var ite1=car[a].goods; + await m_cx.cart_cx_group(th,ite1,car[a],1,n_ok,(show_can_cx)=>{ + rd_arr.push(show_can_cx) + }) + } - //不管怎么样都要移出去 - var obj = JSON.parse(JSON.stringify(item[c])); - zh_calc.remove_zhprom(car, a, obj); - ladder_calc.remove_ladder_prom(car, a, obj); + //--- 第二次过滤 --- + for(var ui=0;ui{ + rd_arr[ui]=show_can_cx; + }) + } + } + + + + for (var a = 0; a < car.length; a++) { + //-- 把活动组装进去 --- + var show_can_cx=rd_arr[a]; + + car[a].zh_map=null; + car[a].ladder_map=null; + + + var item = car[a].goods, is_s_sele = 1; + //-- 先批量判断一下活动的类型,同时要同步跟新 -- + + var offline_price = 0; + var offline_num = 0; + for (var c = 0; c < item.length; c++) { + if (item[c].is_gift) continue; + all_num += item[c].goods_num; + + if(item[c].prom_type==7){ + item[c].act=th.data.zuhe_map[item[c].prom_id]; } - if (item[c].prom_type == 10) { - obj.goods_num = 0; - ladder_calc.add_ladder_prom(car, a, obj); + if(item[c].prom_type==10){ + item[c].act=th.data.ladder_map[item[c].prom_id]; } + //不管怎么样都要移出去 + var obj = JSON.parse(JSON.stringify(item[c])); + zh_calc.remove_zhprom(car, a, obj); + ladder_calc.remove_ladder_prom(car, a, obj); + + if (item[c].selected == 0) { + ischeck = 0; + is_s_sele = 0; + if (item[c].prom_type == 7) { + obj.goods_num = 0; + zh_calc.add_zhprom(car, a, obj); + } + + if (item[c].prom_type == 10) { + obj.goods_num = 0; + ladder_calc.add_ladder_prom(car, a, obj); + } + - } else { - if (item[c].prom_type == 7) { - //先把商品放入组合计算的专用的区域 - console.log('是组合商品---') - console.log(car); - console.log(a) - console.log(obj) - console.log('......................') - zh_calc.add_zhprom(car, a, obj); - } else if (item[c].prom_type == 10) { - ladder_calc.add_ladder_prom(car, a, obj); + } else { + + + if (item[c].prom_type == 7) { + //先把商品放入组合计算的专用的区域 + console.log('是组合商品---') + console.log(car); + console.log(a) + console.log(obj) + console.log('......................') + zh_calc.add_zhprom(car, a, obj); + } else if (item[c].prom_type == 10) { + ladder_calc.add_ladder_prom(car, a, obj); + } + else { + tfeel += item[c].goods_num * item[c].goods_price; + } + t_num += item[c].goods_num; } - else { - tfeel += item[c].goods_num * item[c].goods_price; + + //-- 如果这个商品是线下取价的时候 -- + if (item[c].is_offline && item[c].prom_type != 7) { + offline_price += (item[c].goods_price - item[c].offline_price) * item[c].goods_num; + offline_num += item[c].goods_num; } - t_num += item[c].goods_num; } - //-- 如果这个商品是线下取价的时候 -- - if (item[c].is_offline && item[c].prom_type != 7) { - offline_price += (item[c].goods_price - item[c].offline_price) * item[c].goods_num; - offline_num += item[c].goods_num; - } - } - - //总的价格,把组合商品的价格拿出来 - var zh_calc_res = zh_calc.calculate_zh(car, a, th); - console.log('.组合价-----------') - console.log(zh_calc_res) - //总的价格,把阶梯促销商品的价格拿出来 - var ladder_calc_res = ladder_calc.calculate_ladder(car, a, th); + //总的价格,把组合商品的价格拿出来 + var zh_calc_res = zh_calc.calculate_zh(car, a, th); + console.log('.组合价-----------') + console.log(zh_calc_res) + //总的价格,把阶梯促销商品的价格拿出来 + var ladder_calc_res = ladder_calc.calculate_ladder(car, a, th); - tfeel += zh_calc_res.tfeel; - offline_price += zh_calc_res.offline_price; - offline_num += zh_calc_res.offline_num; + tfeel += zh_calc_res.tfeel; + offline_price += zh_calc_res.offline_price; + offline_num += zh_calc_res.offline_num; - tfeel += ladder_calc_res.tfeel; - offline_price += ladder_calc_res.offline_price; - offline_num += ladder_calc_res.offline_num; + tfeel += ladder_calc_res.tfeel; + offline_price += ladder_calc_res.offline_price; + offline_num += ladder_calc_res.offline_num; - var txt = "requestData[" + a + "].selected"; - th.setData({ - [txt]: Number(is_s_sele) - }); + var txt = "requestData[" + a + "].selected"; + th.setData({ + [txt]: Number(is_s_sele) + }); - //当有线下取价的时候 - if (offline_price) { - var txt1 = "requestData[" + a + "].offline_price"; - var txt2 = "requestData[" + a + "].offline_num"; + var txt1 = "requestData[" + a + "].show_can_cx"; th.setData({ - [txt1]: offline_price.toFixed(2), - [txt2]: offline_num, + [txt1]: show_can_cx }); - } else { - if (car[a].offline_price > 0) { + + //-- var et={show_can_cx:show_can_cx}; + //-- rd_arr.push(et); + + //当有线下取价的时候 + if (offline_price) { var txt1 = "requestData[" + a + "].offline_price"; var txt2 = "requestData[" + a + "].offline_num"; th.setData({ - [txt1]: 0, - [txt2]: 0 + [txt1]: offline_price.toFixed(2), + [txt2]: offline_num, }); + } else { + if (car[a].offline_price > 0) { + var txt1 = "requestData[" + a + "].offline_price"; + var txt2 = "requestData[" + a + "].offline_num"; + th.setData({ + [txt1]: 0, + [txt2]: 0 + }); + } } - } - } + + + //-- 切换活动的按钮要把他返回 -- + this.data.change_act=0; + if(func) func(); } //-- 服务卡 -- @@ -2583,7 +2337,6 @@ Page({ } } - var txt = "service_data[" + a + "].selected"; th.setData({ [txt]: Number(is_s_sele) @@ -2598,53 +2351,6 @@ Page({ total_num: t_num }); }, - - //-- 循环汇总其他门店,其他活动有此商品的购买数量的汇总,不包含赠品 -- - get_goods_other(item, pitem,only){ - var goods_id = this.data.requestData[pitem].goods[item].goods_id; - var prom_type = this.data.requestData[pitem].goods[item].prom_type; - var prom_id = this.data.requestData[pitem].goods[item].prom_id; - - var num=0; - //-- 相同活动的商品汇总,秒杀,团购 -- - if(only==2){ - for (let j = 0; j < this.data.requestData.length;j++){ - if(j!=pitem){ - var goods=this.data.requestData[j].goods; - for (let k = 0; k item.goods_id == g_arr[i].goods_id) if (gitem) { @@ -3819,6 +3551,8 @@ Page({ wx.hideLoading(); return false; } + + wx.hideLoading(); wx.navigateTo({ url: "/packageE/pages/cart/cart2/cart2" @@ -3979,7 +3713,9 @@ Page({ var data = { id: g_arr[i].id, selected: 1, - store_id: oo.stoid + store_id: oo.stoid, + prom_type:g_arr[i].prom_type, + prom_id:g_arr[i].prom_id, }; //-- 如果有线下取价的时候 -- @@ -4904,6 +4640,224 @@ Page({ icon: 'none', duration: 2000 }); + }, + + + + //-- 开始显示活动的弹出 -- + switch_cx_group:function (e){ + var idx=e.currentTarget.dataset.index; + var gd_key=e.currentTarget.dataset.gd_key; + this.data.sele_cx_group_cidx=idx; + this.data.cx_group_gd_key=gd_key; + //-- 获取到-- + var cx_prom_group=this.data.requestData[idx].show_can_cx[gd_key].act_arr; + + var cx_arr=[]; + var find_sele=0; + for (var h=0;h{ + car[c_idx].show_can_cx=show_can_cx; + th.cx_check_ok2(func,car); + }); + + }, + + //--- 在点击商品和或者门店的时候调用,这个可以在活动切换的时候调用,也可以被单个选择调用--- + async cx_check_ok2(func,car) { + + //如果购物车没有带入,要进行赋值 + if(!car) { + car = JSON.parse(JSON.stringify(this.data.requestData)); + } + + var nei_in_zhact_gdmap = {}; + var nei_in_zhact = {}; + var nei_in_yhact = {}; + for (var i = 0; i < car.length; i++) { + var show_can_cx = car[i].show_can_cx; + for (var j in show_can_cx) { + var sele_act = show_can_cx[j].act_arr.find(function (m) { + return m.sele == 1; + }) + + if (!sele_act) continue; + var pid = sele_act['prom_id']; + if (sele_act['prom_type'] == 3) { + if(!nei_in_yhact[pid]) nei_in_yhact[pid] = 0; + nei_in_yhact[pid]++; + } + if (sele_act['prom_type'] == 7) { + if(!nei_in_zhact[pid]) nei_in_zhact[pid] = 0; + nei_in_zhact[pid] += sele_act['act_num']; + } + var in_zhact_gdmap1 = sele_act['in_zhact_gdmap']; + for (var vg in in_zhact_gdmap1) { + if (!nei_in_zhact_gdmap[vg]) nei_in_zhact_gdmap[vg] = 0; + nei_in_zhact_gdmap[vg] += in_zhact_gdmap1[vg]; + } + } + } + + //-- 判断优惠促销是不是超出限购 -- + if (nei_in_yhact && Object.keys(nei_in_yhact).length) { + for (var ky0 in nei_in_yhact) { + var num = nei_in_yhact[ky0]; + + var fd=null; + var fd_res = await getApp().request.promiseGet('/api/weshop/promgoods/get/'+os.stoid+'/'+ky0,{}) + if(fd_res && fd_res.data.code==0 ){ + fd=fd_res.data.data; + } + if (fd && fd['limit_num'] > 0 && num > fd['limit_num']) { + func({'code': -1, 'msg': '超出优惠促销活动的限购'}); + return false; + } + } + } + + //-- 判断组合促销是不是超出活动总数量 -- + if (nei_in_zhact && Object.keys(nei_in_zhact).length) { + for (var ky in nei_in_zhact) { + + var num0 = nei_in_zhact[ky]; + var zh = this.data.zuhe_map[ky]; + var buyed=0; + + //获取已经购买了多少件 + var z_url = "/api/weshop/ordergoods/getUserBuyPromNum?store_id="+os.stoid+"user_id="+getApp().globalData.user_id+"prom_type=7&prom_id="+ky; + var zbuy=await getApp().request.promiseGet(z_url,{}); + if(zbuy && zbuy.data.code==0){ + buyed=zbuy.data.data.userbuynum; + } + if (zh['zh_num'] > 0 && zh['zh_buy_num'] + num0 > zh['zh_num']) { + func({'code': -1, 'msg': '超出组合购活动总数量'}); + return false; + } + } + } + + //-- 判断组合促销是不是超出活动总数量 -- + if (nei_in_zhact_gdmap && Object.keys(nei_in_zhact_gdmap).length) { + for (var key in nei_in_zhact_gdmap) { + + var num1 = nei_in_zhact_gdmap[key]; + var key_a = key.split('.'); + var gid = key_a[0]; + var pid = key_a[1]; + + //-- 商品的限购 -- + var promgoodsbuynum = 0; + var rq = { + 'store_id': os.stoid, 'user_id': getApp().globalData.user_id, 'goods_id': gid, + 'prom_type': 7, 'prom_id': pid + }; + + var res = await getApp().request.promiseGet("/api/weshop/ordergoods/getUserBuyGoodsNum", {data: rq}); + if (res && res.data.code == 0) { + promgoodsbuynum = res.data.data.promgoodsbuynum; + } + + var gdlist_arr = this.data.zuhe_map_good[pid]; + var gdlist = gdlist_arr.find(function (e) { + return e.goods_id == gid; + }) + if (gdlist['buyqty'] > 0 && num1 + promgoodsbuynum > gdlist['buyqty']) { + func({'code': -1, 'msg': '超出组合购商品的限购'}); + return false; + } + } + } + func({'code': 0, 'msg': '成功'}) } + }); \ No newline at end of file diff --git a/pages/cart/cart/cart.json b/pages/cart/cart/cart.json index 70ce71e..08f0ff2 100644 --- a/pages/cart/cart/cart.json +++ b/pages/cart/cart/cart.json @@ -2,6 +2,7 @@ "navigationBarTitleText": "购物车", "usingComponents": { "warn": "/components/long_warn/long_warn", - "goods_recommend":"/components/goods_list/goods_list" + "goods_recommend":"/components/goods_list/goods_list", + "pro_pop": "/components/promate_pop/promate_pop" } } \ No newline at end of file diff --git a/pages/cart/cart/cart.wxml b/pages/cart/cart/cart.wxml index 5d07948..7f9ae3b 100644 --- a/pages/cart/cart/cart.wxml +++ b/pages/cart/cart/cart.wxml @@ -1,3 +1,6 @@ + + + @@ -38,7 +41,7 @@ - + @@ -54,80 +57,138 @@ - - - - - - - - - - - - - - 赠品 - - - 自选 - 自提 - 物流 - - - - - 还需购买{{items.zhqty-items.goods_num}}件 - - - 需购买{{items.zhqty}}件 + + + + + + + + - + + + + + + 赠品 + + + 自选 + 自提 + 物流 + + + + + + 还需购买{{items.zhqty-items.goods_num}}件 + + + 需购买{{items.zhqty}}件 + + + + + + + + {{items.goods_name}} + + + + {{items.goods_color}}{{items.goods_color?"/":''}}{{items.goods_spec}} + 规格1 + + + {{items.goods_num}}件 + + 组合限购{{items.buyqty}}件 + - - - - {{items.goods_name}} + + + + + {{items.goods_price}} - - - {{items.goods_color}}{{items.goods_color?"/":''}}{{items.goods_spec}} - 规格1 - - - {{items.goods_num}}件 - - 组合限购{{items.buyqty}}件 + 券后 ¥{{g_filter.toFix(items.offline_price,2)}} + + + + + + + + + + + + - - - - - {{items.goods_price}} + + + + + + 可参促销 + + + 优惠促销 + 搭配促销 + 组合购 + 阶梯促销 + + + + + + + + - 券后 ¥{{g_filter.toFix(items.offline_price,2)}} + + + + + + + + + + 可参促销 + + + 优惠促销 + 搭配促销 + 组合购 + 阶梯促销 + + + + + + + + + - - - - - + - - - - - - - + - + + 再买{{item.diff}} , @@ -144,8 +205,8 @@ 去凑单> + - diff --git a/pages/cart/cart/cart.wxss b/pages/cart/cart/cart.wxss index 699321e..20979b5 100644 --- a/pages/cart/cart/cart.wxss +++ b/pages/cart/cart/cart.wxss @@ -399,3 +399,81 @@ page { text-align: center; line-height: 30rpx; left: 0;bottom: 0;color: #fff; font-size: 20rpx; } + + + +.cx-frame { + /* border-top:3rpx solid #eee; */ + /* width:99%; + height: 95rpx; + line-height: 95rpx; + padding-left:24rpx; */ + padding: 20rpx; +} + +.cx-frame .cx-sizs { + /* width: 68rpx; */ + /* height: 100%; */ + /* line-height: 100rpx; */ + /* overflow: hidden; */ + /* margin-left: 10rpx; */ +} + +.xc-coupon-fram { + position: relative; + margin-right: 16rpx; + /* width:200rpx; */ + /* padding-top:30rpx; */ + +} + +.xc-coupon-fram .xc-coupon { + /* width:175rpx ; + height: 40rpx; + line-height: 40rpx; */ + background-color: #d60021; + /* margin:0 auto; */ + color: #fff; + padding: 6rpx 20rpx; + +} + +.xc-coupon-fram .xc-circular { + width: 16rpx; + height: 16rpx; + background-color: white; + position: absolute; + top: 50%; + /* left: -10rpx; */ + transform: translateY(-50%); +} + +.cx-obtain-coupon { + /* width: 65rpx; + height: 100%; + padding-left:15rpx; */ + color: #d70025; + display: flex; + align-items: center; + /* position: absolute; + right: 5rpx; */ +} + +.bg_jj { + width: 14rpx; + height: 14rpx; + border-top: 2rpx solid #d70026; + border-right: 2rpx solid #d70026; + transform: rotateZ(45deg); + display: inline-block; + margin-bottom: 3rpx; +} + +.bg_jj.down { + transform: rotateZ(135deg); +} + +.bg_jj.up { + transform: rotateZ(-45deg); + margin-top: 6rpx; +} diff --git a/pages/cart/cart/g_filter.wxs b/pages/cart/cart/g_filter.wxs index e0426fe..cb1fc35 100644 --- a/pages/cart/cart/g_filter.wxs +++ b/pages/cart/cart/g_filter.wxs @@ -28,11 +28,21 @@ var g_filters = { } val = parseFloat(val); return val.toFixed(count) - } + }, + + //判断商品是不是有活动切换 + is_more_act:function (items,show_can_cx){ + if([1,2,4,6,8,9].indexOf(items.prom_type)>-1) return false; + if(!show_can_cx) return false; + return true; + } + } module.exports = { has_char: g_filters.has_char, beg_time: g_filters.beg_time, end_time: g_filters.end_time, toFix: g_filters.toFix, + is_more_act: g_filters.is_more_act, + check_show:g_filters.check_show } \ No newline at end of file diff --git a/pages/cart/cart/zh_calculate.js b/pages/cart/cart/zh_calculate.js index 27d2900..c9eff0c 100644 --- a/pages/cart/cart/zh_calculate.js +++ b/pages/cart/cart/zh_calculate.js @@ -134,7 +134,7 @@ module.exports = { if (item.buyqty > 0) { console.log(111, th.data.in_zhact_gdmap); var cbuy = item.buyqty - zh_b_num; - var key = item.goods_id + "" + act.id; + var key = item.goods_id + "." + act.id; if (th.data.in_zhact_gdmap[key]) { var cbuy = item.buyqty - zh_b_num - th.data.in_zhact_gdmap[key]; } @@ -213,7 +213,7 @@ module.exports = { console.log(222, th.data.in_zhact_gdmap); - var key = ite.goods_id + "" + act.id; + var key = ite.goods_id + "." + act.id; if (th.data.in_zhact_gdmap[key]) { th.data.in_zhact_gdmap[key] += ite.num; } else { @@ -519,7 +519,279 @@ module.exports = { } } return zhqty_bz_flag; - } + }, + + //-- 判断组合购有没有满足,只有在检查的时候,要用新的 --- + ch_zh_ok(act,gdlist,c_goods,th,item_act_map,is_need_ck_num){ + + //-- 寻找一下 -- + function get_num(ite) { + for (let v1 in c_goods) { + var vh = c_goods[v1]; + if (vh.goods_id == ite.goods_id) { + return vh; + } + } + return 0; + } + var goods =gdlist; + var all_num=0; + var need_to_buy=0; + var all_zhqty=0; + //-- 是综合考虑到组合购的总数量和限购数量 -- + var min_can_buy=-1; + var aid=act.id; + + let no_in_arr = []; //剩余的未加入组合购 + let out_arr = []; //超出活动限购的商品放入 + + //-- 判断组合购的总数量是不是到了 -- + if(act.zh_num>0){ + //如果是在全选的情况下,那么就需要in_zhact_new来控制数量 + var need_ck=0; + if(is_need_ck_num){ + need_ck=th.data.in_zhact_new[aid]?th.data.in_zhact_new[aid]:0; + } + if(need_ck+act.zh_buy_num>=act.zh_num ){ + return false; + }else{ + min_can_buy= act.zh_num-act.zh_buy_num-need_ck; + } + } + + //-- 判断组合购的限购是不是到了 -- + if(act.buy_limit>0){ + var need_ck0=0; + if(is_need_ck_num){ + need_ck0=th.data.in_zhact_new[aid]?th.data.in_zhact_new[aid]:0; + } + var min_can_buy0=0; + if(need_ck+item_act_map.buyed>=act.buy_limit ){ + return false; + }else{ + min_can_buy0=act.buy_limit-item_act_map.buyed-need_ck; + } + if(min_can_buy>0){ + if(min_can_buy0 0) { + var cbuy = item.buyqty - zh_b_num; + var key = item.goods_id + "." + act.id; + if (is_need_ck_num && th.data.in_zhact_gdmap_new[key]) { + var cbuy = item.buyqty - zh_b_num - th.data.in_zhact_gdmap_new[key]; + } + //当可买的数量为0 + if (cbuy <= 0) { + item.num = 0; + out_arr.push({ + goods_id: item.goods_id, + num: cart_num + }) + } else { + if (cbuy >= cart_num) item.num = cart_num; + else { + item.num = cbuy; + out_arr.push({ + goods_id: item.goods_id, + num: cart_num - cbuy + }) + } + } + } else { + item.num = cart_num; + } + + if (item.num) { + all_num += item.num; + //当有起购数的控制的时候 + if (item.zhqty) { + all_zhqty += item.zhqty; + if (item.num < item.zhqty) { + need_to_buy += item.zhqty - item.num; + } + if (item.num > item.zhqty) { + for (let i = 0; i < item.num - item.zhqty; i++) { + no_in_arr.push({ + goods_id: item.goods_id, + }) + } + } + } + else { + for (let j = 0; j < item.num; j++) { + no_in_arr.push({ + goods_id: item.goods_id, + }) + } + } + } else { + if (item.zhqty) { + need_to_buy += item.zhqty; + } + } + } + + //当满足组合的要求:总数要满足,起购数要满足 + if (all_num >= act.zhbuyqty && !need_to_buy) { + //默认数量是1 + var act_num=1; + function sortData(a, b) { + return a.price - b.price + } + if (no_in_arr.length > 0) no_in_arr.sort(sortData); + if (act.zhbuyqty > all_zhqty) { + for (let n = 0; n < act.zhbuyqty - all_zhqty; n++) { + no_in_arr.pop(); + } + } + + //看一下剩下的数量有没有满足组合购的要求,以及要不要倍增 + if (act.is_bz && no_in_arr.length >= act.zhbuyqty) { + + var bz_num_ok = 0; //超量倍增是否满足 + var zhqty_len = 0; //几个超量倍增 + var delete_num = 0; + //看一下是几倍 + let be = parseInt(no_in_arr.length / act.zhbuyqty); + //如果有总数控制的时候 + if (min_can_buy>0) { + var be1 = min_can_buy - 1; + if (be1 < be) be = be1; + } + if(be) { + if (act.is_bzyh && zhqty_bz.length > 0) { + + let zhqty_bz_arr = []; + let zhqty_bz_flag = this.zhqty_bz_fun(zhqty_bz, be, zhqty_bz_arr); + if (zhqty_bz_flag) { + for (let i = 0; i < zhqty_bz.length; i++) { + var vv = zhqty_bz[i]; + for (let j = 0; j < be * vv['zhqty']; j++) { + let index = no_in_arr.findIndex(i => { + return vv.goods_id === i.goods_id + }) + if (index > -1) { + delete_num++ + no_in_arr.splice(index, 1) + } + } + } + } else { + zhqty_len = 1; + let min_bz_num = Math.min.apply(Math, zhqty_bz_arr.map(function (o) { + return o['be']; + })); + let new_arr = zhqty_bz_arr.filter(ii => { + return ii['be'] == min_bz_num; + }) + //-- 要看一下倍数还有没有 --- + be = new_arr[0].be; + //如果有总数控制的时候 + if (min_can_buy>0) { + var be1 = min_can_buy - 1; + if (be1 < be) be = be1; + } + if(be){ + for (let i = 0; i < zhqty_bz.length; i++) { + let item1 = zhqty_bz[i]; + for (let j = 0; j < be * item1['zhqty']; j++) { + let index = no_in_arr.findIndex(i => { + return item1.goods_id === i.goods_id + }) + if (index > -1) { + no_in_arr.splice(index, 1) + } + } + } + act_num+=be; + } + } + } + if (!zhqty_len) { + let pop_num = be * act.zhbuyqty - delete_num; + for (var m = 0; m < pop_num; m++) { + no_in_arr.pop(); + } + act_num+=be; + } + } + } + + //-- 参与活动的金额要返回回去 -- + item_act_map.act_num=act_num; + let goods_map = {}; + //算一下剩余的商品 + if (no_in_arr.length) { + for (let ii in no_in_arr) { + let item = no_in_arr[ii]; + if (goods_map[item.goods_id]) { + var num = goods_map[item.goods_id]; + goods_map[item.goods_id] = ++num; + } else { + goods_map[item.goods_id] = 1; + } + } + } + //超量的部分也要计算一下 + if (out_arr.length) { + for (var m in out_arr) { + if (goods_map[item.goods_id]) { + var num = goods_map[item.goods_id]; + num += item.num + goods_map[item.goods_id] = num; + } else { + goods_map[item.goods_id] = item.num; + } + } + } + + //-- 组合购的商品限购的数组控制 -- + var in_zhact_gdmap={}; + //商品的列表 + for (var u in goods) { + var ite = goods[u]; + var cart_num = get_num(ite).goods_num; + + if (ite.buyqty > 0 && cart_num > 0) { + var key = ite.goods_id + "." + act.id; + if(goods_map[ite.goods_id]){ + cart_num-=goods_map[ite.goods_id]; + } + if(cart_num>0){ + if (in_zhact_gdmap[key]) { + in_zhact_gdmap[key] += ite.num; + } else { + in_zhact_gdmap[key] = ite.num; + } + } + + } + } + item_act_map.in_zhact_gdmap=in_zhact_gdmap; + return true; + } + + item_act_map.act_num=0; + return true; + } + } \ No newline at end of file diff --git a/pages/giftpack/giftpacklist/giftpacklist.js b/pages/giftpack/giftpacklist/giftpacklist.js index d48d83b..eb1a5f7 100644 --- a/pages/giftpack/giftpacklist/giftpacklist.js +++ b/pages/giftpack/giftpacklist/giftpacklist.js @@ -76,13 +76,9 @@ Page({ screenWidth: 0, submit:0, -<<<<<<< HEAD - - is_detail:1 //是详情页面的购买 -======= + is_detail:1, //是详情页面的购买 keyword:'', //门店搜索 sec_i:-1,//选中分类门店 下标 ->>>>>>> dev_oa_lu7 }, onLoad: function (options) { diff --git a/pages/goods/goodsInfo/goodsInfo.js b/pages/goods/goodsInfo/goodsInfo.js index fa30ad1..83c0154 100644 --- a/pages/goods/goodsInfo/goodsInfo.js +++ b/pages/goods/goodsInfo/goodsInfo.js @@ -270,6 +270,7 @@ Page({ user_pre_buynum:0, //用户优惠促销参与次数 keyword:'', //门店搜索 sec_i:-1,//选中分类门店 下标 + cx_prom_group:[], //促销活动,用于显示和判断默认要用什么促销活动 }, //------初始化加载---------- @@ -297,7 +298,6 @@ Page({ self = this; - //检查测肤 getApp().check_skin_face(t, 0, gid); @@ -1209,6 +1209,7 @@ Page({ this.data.enterAddressPage && (this.data.enterAddressPage = !1); + }, onReady() { @@ -1539,10 +1540,14 @@ Page({ }) // return userbuynum }, + //优惠促销用户参与次数 async getUserBuyPromNum_pre(prom_id){ + var user_id=0 var userInfo = getApp().globalData.userInfo; - var url = `/api/weshop/ordergoods/getUserBuyPromNum?is_all=1&store_id=${os.stoid}&user_id=${userInfo.user_id}&prom_type=3&prom_id=${prom_id}`; + if(userInfo) user_id=userInfo.user_id; + + var url = `/api/weshop/ordergoods/getUserBuyPromNum?is_all=1&store_id=${os.stoid}&user_id=${user_id}&prom_type=3&prom_id=${prom_id}`; let res = await getApp().request.promiseGet(url, { data:{} }); @@ -1619,11 +1624,8 @@ Page({ prom_type: th.data.sele_g.prom_type, }; - - - //-- 代发商品不参加优惠 -- - if (th.data.sele_g.whsle_id && newd.prom_type == 3) { + if (th.data.sele_g.whsle_id) { newd.prom_type = 0; newd.prom_id = 0; } @@ -1664,6 +1666,8 @@ Page({ newd.pricing_type = o.pricing_type; } + + //获取到优惠测序类型 //-----如果是秒杀,团购,积分购,拼团----- if (th.data.prom_type == 1 || th.data.prom_type == 2) { @@ -1672,7 +1676,6 @@ Page({ newd.prom_type = 0; newd.prom_id = 0; newd.is_pd_normal = 1; - //---如果是线下门店销售的时候--- if (th.data.sales_rules >= 2) { var pick = th.get_pick_from_list(th.data.sto_sele_id) @@ -1720,10 +1723,9 @@ Page({ return false; } - newd.goods_price = th.data.prom_price; newd.member_goods_price = th.data.prom_price, - newd.prom_type = th.data.prom_type; + newd.prom_type = th.data.prom_type; newd.prom_id = th.data.prom_id; if (o.store_count <= 0 ) { @@ -1743,7 +1745,6 @@ Page({ }; th.add_cart_next(e, t, a, o, newd); //加入购物车下一步 - } else if (o.prom_type == 7) { //判断进行中的活动,是不是要判断线下库存 @@ -1817,84 +1818,17 @@ Page({ } } }) - } - //要包含积分购的普通购买 - else if (th.data.prom_type == 0 || th.data.prom_type == 3 || newd.is_integral_normal || th.data.prom_type == 5 || th.data.prom_type == 10) { + //要包含积分购的普通购买0 3,5,7,10 + else if ( [0,3,5,7,10].indexOf(th.data.prom_type)>-1 || prom.prom_type == 7) { newd.prom_type = 0; newd.prom_id = 0; - if (th.data.prom_type == 10) { - newd.prom_type = th.data.prom_type; - newd.prom_id = th.data.prom_id; - } - //---如果是线下门店销售的时候--- if (th.data.sales_rules >= 2 && !th.data.sele_g.whsle_id) { var pick = th.get_pick_from_list(th.data.sto_sele_id) //---通过接口获取门店的线下库存信息-- - // getApp().request.get("/api/weshop/goods/getWareStorages", { - // data: { - // storageNos: pick.pickup_no, - // wareIds: encodeURIComponent(th.data.sele_g.erpwareid), - // storeId: os.stoid - // }, - // success: function (res) { - // if (res.data.code == 0) { - // if (res.data.data.pageData.length > 0) { - // var CanOutQty = res.data.data.pageData[0].CanOutQty; - // if (CanOutQty < e.data.goodsInputNum) { - // wx.showToast({ - // title: '库存不足!', - // icon: 'none', - // }); - // return false; - // //return s.my_warnning("库存不足!", 0, th); - // } - // //在调一次接口,读取商品的预出库的数量,lock - // getApp().request.get("/api/weshop/order/ware/lock/page", { - // data: { - // store_id: os.stoid, - // wareId: th.data.sele_g.goods_id, - // storageId: pick.pickup_id, - // pageSize: 1000 - // }, - // success: function (res_data) { - // if (res_data.data.code == 0 && res_data.data.data.total > 0) { - // - // var lock = 0; - // for (var i in res_data.data.data.pageData) { - // lock += res_data.data.data.pageData[i].outQty; - // } - // - // if (CanOutQty <= lock) { - // wx.showToast({ - // title: '库存不足!', - // icon: 'none', - // }); - // return false; - // //return s.my_warnning("库存不足!", 0, th); - // } - // th.add_cart_next(e, t, a, o, newd, CanOutQty - lock); - // } else { - // th.add_cart_next(e, t, a, o, newd, CanOutQty); - // } - // } - // }) - // } else { - // wx.showToast({ - // title: '库存不足!', - // icon: 'none', - // }); - // return false; - // //return s.my_warnning("库存不足!", 0, th); - // } - // - // } - // } - // }) - th.check_CanOutQty(th.data.sele_g, pick, function (CanOutQty) { if (CanOutQty) { @@ -1977,7 +1911,6 @@ Page({ //if (this.data.data.goods.is_virtual) return this.buyVirtualGoods(d); if ("add" == t.currentTarget.dataset.action) { - if( [3,5,10].indexOf(newd.prom_type)>-1){ newd.prom_type=0; newd.prom_id=0; @@ -1994,6 +1927,22 @@ Page({ newd.prom_type = 7; newd.prom_id = th.data.zh_act.id; } + // if( [3,5,10].indexOf(newd.prom_type)>-1){ + // newd.prom_type=0; + // newd.prom_id=0; + // } + // + // //如果有搭配购的时候的时候 + // if(th.data.collocationGoods && newd.prom_type==0){ + // newd.prom_type = 5; + // newd.prom_id = th.data.collocationGoods.id; + // } + // + // //如果有搭配购的时候的时候 + // if(th.data.zh_act && (!th.data.zh_act.zh_num || th.data.zh_act.zh_buy_num>th.data.zh_act.zh_num ) && newd.prom_type==0){ + // newd.prom_type = 7; + // newd.prom_id = th.data.zh_act.id; + // } //----先看会员在购物车中是否加入了该商品----- i.get("/api/weshop/cart/page", { @@ -2028,7 +1977,6 @@ Page({ if(item){ item = re.data.data.pageData[0]; - //判断数量,要看下购物车中有没有该商品 if (CanOutQty) { if (item.goods_num + th.data.goodsInputNum > CanOutQty) { @@ -2082,7 +2030,6 @@ Page({ updata['groupchat_id'] = getApp().globalData.groupchat_id; } - getApp().request.put("/api/weshop/cart/update", { data: updata, success: function (t) { @@ -2110,6 +2057,7 @@ Page({ } }); + } else { //-- 这一步主要是要让立即购买 走 购物车的逻辑 参与活动,如果有zh_act就强制组合购购买 -- @@ -2245,61 +2193,14 @@ Page({ newd.prom_type = 10; newd.prom_id = th.data.ladder_act_id; + }else{ - //----先看会员在购物车中是否加入了该商品,立即购买的----- - getApp().request.get("/api/weshop/cart/page", { - data: { - store_id: os.stoid, - user_id: oo.user_id, - state: 1 - }, - success: function (res) { - //-------如果购物车中有相关的数据,先清理掉--------- - if (res.data.code == 0 && res.data.data.total > 0) { - for (let j in res.data.data.pageData) { - let item_j = res.data.data.pageData[j]; - var url = '/api/weshop/cart/del/' + e.data.stoid + '/' + item_j.id; - getApp().request.delete(url, {}); - } - } - - newd.state = 1; - getApp().request.post("/api/weshop/cart/save", { - data: newd, - success: function (t) { - th.closeSpecModal(); - getApp().goto("/packageE/pages/cart/cart2/cart2?state=1"); - } - }); - - } - }) - return false; - - } - - - //如果有搭配购的时候的时候 - if(th.data.collocationGoods && newd.prom_type==0){ - newd.prom_type = 5; - newd.prom_id = th.data.collocationGoods.id; - newd.is_coupon= th.data.collocationGoods.is_coupon; - - } - - //如果有搭配购的时候的时候 - if(th.data.zh_act && (newd.prom_type==0 || newd.prom_type==3)){ - newd.prom_type = 7; - newd.prom_id = th.data.zh_act.id; - } - - //如果有搭配购的时候的时候 - if(th.data.jt && newd.prom_type==0){ - newd.prom_type = 7; - newd.prom_id = th.data.zh_act.id; + //-- 优惠促销的商品,立即购买就判断了,就直接购买 -- + if([1,2,4,6].indexOf(newd.prom_type)==-1){ + newd.prom_type=0; + newd.id=0; } - newd['pick_name'] = th.data.sto_sele_name; newd['pick_dis'] = th.data.sto_sele_distr; th.buyNow(newd); @@ -2309,7 +2210,6 @@ Page({ //因为在购物车 普通商品和 优惠促销,搭配购,组合购 阶梯购是一样的 check_is_like(e,newd,idx){ if(e.prom_type ==newd.prom_type) return true; - if(!idx) { if (e.prom_type == 0) { if ([3, 5, 7, 10].indexOf(newd.prom_type) > -1) return true; @@ -2360,40 +2260,55 @@ Page({ } else { //要判断积分购的普通购买有没有参加优惠活动 if (e.is_integral_normal == 1 || e.is_pd_normal == 1) { - this.check_nor_promgood(e.goods_id, function (res) { - if (res && res.cat_id) { - e.prom_type = 3; - e.prom_id = res.cat_id - } - s.set_b_now(e); - /*-- - wx.redirectTo({ - url: "/pages/cart/cart2/cart2?is_bnow=1&goods_id=" + e.goods_id, - });--*/ - getApp().goto("/packageE/pages/cart/cart2/cart2?is_bnow=1&goods_id=" + e.goods_id) + e.prom_type = 0; + e.prom_id = 0 - }) - } else { - //搭配购特殊处理 - if( [3,5,7,10].indexOf(th.data.data.prom_type)>-1){ - e.prom_type=th.data.data.prom_type - e.prom_id=th.data.data.prom_id - e.collocation_goods=[] - } + } - if(th.data.collocationGoods){ - e.prom_type=5 - e.prom_id=th.data.collocationGoods.id - } - - s.set_b_now(e); - /*-- - wx.redirectTo({ - url: "/pages/cart/cart2/cart2?is_bnow=1&goods_id=" + e.goods_id, - });--*/ - getApp().goto("/packageE/pages/cart/cart2/cart2?is_bnow=1&goods_id=" + e.goods_id) + //秒杀等活动的直接跳转到cart2中的立即购买 + if([1,2,4,6].indexOf(e.prom_type)>-1){ + s.set_b_now(e); + getApp().goto("/packageE/pages/cart/cart2/cart2?is_bnow=1&goods_id=" + e.goods_id) + }else { + + //----其他就按照公众号的购物车立即购买形式来修改,先看会员在购物车中是否加入了该商品,立即购买的----- + getApp().request.get("/api/weshop/cart/page", { + data: { + store_id: os.stoid, + user_id: oo.user_id, + state: 1 + }, + success: function (res) { + //-------如果购物车中有相关的数据--------- + if (res.data.code == 0 && res.data.data.total > 0) { + for (let j in res.data.data.pageData) { + let item_j = res.data.data.pageData[j]; + var url = '/api/weshop/cart/del/' + os.stoid + '/' + item_j.id; + getApp().request.delete(url, {}); + } + } + + //-- 推迟一下,因为删除没有那么快 -- + setTimeout( ()=>{ + e.state = 1; + e.prom_type = 0; + e.prom_id = 0 + getApp().request.post("/api/weshop/cart/save", { + data: e, + success: function (t) { + th.closeSpecModal(); + getApp().goto("/packageE/pages/cart/cart2/cart2?state=1"); + } + }); + },500) + + } + }) } + + + } }, @@ -2860,26 +2775,11 @@ Page({ var r_data = res.data.data; - if(r_data.collocationList){ - th.data.ladderLists =null; - th.data.prom_goods =null; - r_data.promGoodsLists=null; - r_data.ladderLists=null; - } - if (r_data.ladderLists) { var act_id = r_data.ladderLists[0].form_id; //-- 判断会员能不能参与阶梯促销 -- await getApp().request.promiseGet("/api/weshop/prom/ladderForm/getNew/" + os.stoid + "/" + usr.user_id + "/" + act_id, {}).then(res => { if (res.data.code == 0 && res.data.data) { - var prom_content = ""; - //暂定优惠促销还不能重叠 - if (res.data.data.good_object == 0 && (r_data.promGoodsLists || th.data.zh_act)) { - return false; - } - if (res.data.data.good_object == 1) { - r_data.promGoodsLists = null; - } th.data.ladderLists = r_data.ladderLists; } }) @@ -3387,9 +3287,11 @@ Page({ //普通商品多规格的时候,商品切换 + if(this.data.base_nor_prom_type) this.data.base_nor_prom_type=parseInt(this.data.base_nor_prom_type); - if([1,2,4,8,9].indexOf(this.data.base_nor_prom_type)==-1){ + + if([1,2,4,6,8,9].indexOf(this.data.base_nor_prom_type)==-1){ this.setData({ prom_goods:null, jieti_prom:null, @@ -3448,6 +3350,7 @@ Page({ if (!item.whsle_id && ([1,2,4,6].indexOf(item.prom_type)==-1 || this.data.is_normal==1)) that.check_is_youhui(gid, that.data.is_normal,1); + //默认门店要拿下门店库存 if (that.data.sales_rules >= 2 && that.data.def_pick_store && !that.data.sele_g.whsle_id && [1,2,4,6].indexOf(item.prom_type)==-1) { var lock = 0, @@ -3465,7 +3368,7 @@ Page({ this.sele_spec_chech_activity(nor); //如果是秒杀,拼团等互动,就不重新算界面 - if([1,2,4,8,9].indexOf(this.data.base_nor_prom_type)>0){ return false; } + if([1,2,4,6,8,9].indexOf(this.data.base_nor_prom_type)>-1){ return false; } this.check_has_flash(gid); var url = '/api/weshop/activitylist/listGoodActInfo2New'; @@ -3485,6 +3388,8 @@ Page({ var arr3 = arr.filter(function (e) { return e.s_time < ut.gettimestamp() && e.prom_type==7; }) + + //-- 组合购要在面前计算 --,计算完之后,再来计算check_is_youhui -- if(arr3 && arr3.length>0){ //获取活动信息 var url = "/api/weshop/prom/zhbuy/get/" + os.stoid + "/" + @@ -3502,10 +3407,12 @@ Page({ }); th.getUserBuyPromNum(e.data.data.id) } - } + if (!item.whsle_id) that.check_is_youhui(gid, that.data.is_normal); } }); + }else{ + if (!item.whsle_id) that.check_is_youhui(gid, that.data.is_normal); } } @@ -7546,6 +7453,7 @@ Page({ } } }, + //-----显示优惠券的时候情况----- show_more_cx: function () { if (this.data.is_more_cx) { @@ -7627,21 +7535,29 @@ Page({ }) } } + var r_data=null; + //-- 如果有组合购的时候 -- + if(th.data.zh_act){ + var show_time=ut.formatTime(th.data.zh_act.start_time)+"至"+ ut.formatTime(th.data.zh_act.end_time); + //-- 开始组装数据 -- + th.add_cx_prom_group({ + id: th.data.zh_act.id, + title: th.data.zh_act.name, + show_time: show_time, + prom_type:7 + }); + } + //调用接口判断订单优惠, await getApp().request.promiseGet("/api/weshop/goods/getGoodsPromListNew1/" + os.stoid + "/" + gid + "/0" + "/" + user_id, { }).then(async res=>{ if (res.data.code == 0 && res.data.data) { r_data = res.data.data; var max = 0, min = 0; - //暂时积分够 不和 优惠,阶梯重叠 - if(th.data.zh_act){ - r_data.collocationList=null; - r_data.ladderLists=null; - r_data.promGoodsLists=null; - } + //如果是搭配购的时候 if (r_data.collocationList) { for (var i in r_data.collocationList) { if (max == 0) max = r_data.collocationList[i].price; @@ -7652,10 +7568,96 @@ Page({ } r_data.collocationPromList.max = (max + th.data.data.shop_price).toFixed(2); r_data.collocationPromList.min = (min + th.data.data.shop_price).toFixed(2); + var show_price= '¥'+r_data.collocationPromList.max+'-'+ r_data.collocationPromList.min; + var show_time=ut.formatTime(r_data.collocationPromList.start_time)+"至"+ ut.formatTime(r_data.collocationPromList.end_time); + + //-- 开始组装数据 -- + th.add_cx_prom_group({ + id: r_data.collocationPromList.id, + title: r_data.collocationPromList.title, + show_price: show_price, + show_time: show_time, + prom_type:5, + main_gid:gid + }); + } + + + //-- 如果是阶梯促销的时候 -- + if (r_data.ladderLists) { + var act_id = r_data.ladderLists[0].form_id; + //-- 判断会员能不能参与阶梯促销 -- + await getApp().request.promiseGet("/api/weshop/prom/ladderForm/getNew/" + os.stoid + "/" + user_id + "/" + act_id, {}).then(res => { + if (res.data.code == 0 && res.data.data) { + var prom_content = ""; + + for (let jj in r_data.ladderLists) { + if (r_data.ladderLists[jj].discount == 10) { + prom_content += "第" + (parseInt(jj) + 1) + "件原价,"; + } else { + prom_content += "第" + (parseInt(jj) + 1) + "件" + r_data.ladderLists[jj].discount + "折,"; + } + } + prom_content = ut.sub_last(prom_content); + + // th.data.prom_type = 10; + // th.data.prom_id = act_id; + + th.setData({ + jieti_prom: prom_content, + ladder_act_id: act_id + }) + + var s_time=res.data.data.start_time; + var e_time=res.data.data.end_time; + th.add_cx_prom_group({ + id: act_id, + title: prom_content, + show_time: ut.formatTime(s_time) + "至" + ut.formatTime(e_time), + prom_type:10 + }); + + } + }) + } + + //优惠促销的时候 + if (r_data.promGoodsLists) { + + var fir_act = r_data.promGoodsLists[0]; + //-- 计算一下限购,满足限购数才显示 -- + await this.getUserBuyPromNum_pre(fir_act.prom_id); + + if(!fir_act.limit_num || th.data.user_pre_buynum 0) more_arr.push('减价'+fir_act.money+'元'); + if (fir_act.sale > 0) more_arr.push('打'+fir_act.sale+'折'); + if (fir_act.past ==1) more_arr.push('包邮'); + if (fir_act.intValue > 0) more_arr.push('送'+fir_act.intValue+'积分'); + if (fir_act.couponId > 0) more_arr.push('送'+fir_act.couponMoney+'元优惠券'); + if (fir_act.gift_id) { + var is_more_gf=fir_act.gift_id.split(',') + if(is_more_gf.length>1){ + more_arr.push('送赠品'); + }else{ + more_arr.push('送'+fir_act.goods_name+' x'+fir_act.zp_num); + } + } + if (fir_act.lb_id) more_arr.push('送'+fir_act.lbtitle); + if (fir_act.zxlb_id) more_arr.push('送'+fir_act.zxlbtitle); + + //-- 开始组装数据 -- + th.add_cx_prom_group( { + id: fir_act.prom_id, + condition: fir_act.condition + (fir_act.prom_type == 1 ? '件' : '元'), + limit: '每人' + (fir_act.limit_num ? '限参与' + fir_act.limit_num + '次' : '参与不限次'), + more: more_arr, + prom_type:3 + + }); + } - //如果有搭配促销先不和 阶梯促销和优惠测序重合,做到后台可以重合 - r_data.ladderLists=null; - r_data.promGoodsLists=null; } //普通购买不在界面显示 @@ -7670,9 +7672,11 @@ Page({ }) } th.is_show_more_buy(); + } }) + //-- 如果有阶梯购的时候 -- if (r_data && r_data.ladderLists) { var act_id = r_data.ladderLists[0].form_id; @@ -7721,7 +7725,68 @@ Page({ var mo_num=getApp().get_limit_qty(th.data.sele_g,this.data.is_act); this.setData({goodsInputNum:mo_num}) this.setData({mo_num:mo_num}) + }, + + //获取促销活动的组合 + add_cx_prom_group(data){ + var th=this; + getApp().getConfig2(function (e) { + //需要读者系统顺序 + var json_d = JSON.parse(e.switch_list); + var auto_promote_sale=json_d.auto_promote_sale; + if(auto_promote_sale){ + var auto_promote_sale=auto_promote_sale.split(','); + var fd=auto_promote_sale.indexOf(data.prom_type+''); + data.sort=fd; + }else{ + data.sort=data.prom_type; + } + var fdix=th.data.cx_prom_group.findIndex(function (em){ + return em.prom_type==data.prom_type + }) + + if(fdix>-1){ + th.data.cx_prom_group.splice(fdix,1); + } + + th.data.cx_prom_group.push(data); + + //-- 排序一下 -- + function comp(a, b) { + return a.sort-b.sort; //升序 + } + var ppdata = th.data.cx_prom_group; + //使用sort排序 + ppdata.sort(comp); + + th.setData({ + cx_prom_group:ppdata + }) + + }) + }, + + //--- 获取默认的促销活动的默认活动 --- + check_prom_custom(ind) { + if(ind){ + if (!this.data.cx_prom_group.length) return 0; + }else{ + if (!this.data.cx_prom_group.length) return {prom_type:0,id:0}; + } + var prom=null; + //-- 看有没有选中的活动 -- + var fd=this.data.cx_prom_group.findIndex(function (a){ + return a.sele==1; + }) + + prom=this.data.cx_prom_group[0]; + if(fd>-1) prom=this.data.cx_prom_group[fd]; + + if(ind) { + return prom.prom_type; + } + return prom; }, closePoster() { @@ -7743,6 +7808,11 @@ Page({ is_show_more_buy: async function () { var prom_goods = this.data.prom_goods; + if(!prom_goods) return false; + //如果系统默认的顺序不是以优惠促销为默认第一位的时候 + if(this.check_prom_custom(1)!==3){ + return false; + } var per_price = this.data.sele_g.shop_price if (this.data.card_field && this.data.sele_g[this.data.card_field] > 0) { per_price = this.data.sele_g[this.data.card_field]; @@ -7766,9 +7836,9 @@ Page({ } } //获取用户参与优惠促销的次数 - if(con && con.prom_id){ - await this.getUserBuyPromNum_pre(con.prom_id); - } + //if(con && con.prom_id){ + //await this.getUserBuyPromNum_pre(con.prom_id); + //} this.setData({ hui_condition: con }); @@ -7892,7 +7962,7 @@ Page({ }); }, - //积分购和拼团的普通购买的的时候,要判断有没有全场优惠活动 + //-- 积分购和拼团的普通购买的的时候,要判断有没有全场优惠活动,普通购买的时候一定要注意 -- check_nor_promgood(goods_id, back) { var th=this; var user_id=getApp().globalData.user_id; @@ -7985,9 +8055,10 @@ Page({ item = this.data.sele_g; } + var prom_id=this.check_prom_custom().id; //如果有组合购 - var url = "/api/weshop/prom/zhbuy/get/" + os.stoid + "/" + item.prom_id + "/" + getApp().globalData.user_id; + var url = "/api/weshop/prom/zhbuy/get/" + os.stoid + "/" + prom_id + "/" + getApp().globalData.user_id; getApp().request.promiseGet(url, {}).then(res => { if (res.data.code == 0 && res.data.data) { if (res.data.data.is_show != 1) { @@ -8417,6 +8488,12 @@ Page({ current: url, // 当前显示图片的http链接 urls: url_arr, // 需要预览的图片http链接列表 }); + }, + + //开始显示活动的弹出 + switch_cx_group:function (){ + var pro_pop = this.selectComponent("#pro_pop"); //组件的id + pro_pop.set_init(0,this.data.cx_prom_group); } diff --git a/pages/goods/goodsInfo/goodsInfo.json b/pages/goods/goodsInfo/goodsInfo.json index feb03a7..0fd8f27 100644 --- a/pages/goods/goodsInfo/goodsInfo.json +++ b/pages/goods/goodsInfo/goodsInfo.json @@ -5,6 +5,7 @@ "nav_box": "/components/nav_box/nav_box", "warn": "/components/long_warn/long_warn", "goods_recommend": "/components/goods_list/goods_list", - "share": "/components/share/share" + "share": "/components/share/share", + "pro_pop": "/components/promate_pop/promate_pop" } } \ No newline at end of file diff --git a/pages/goods/goodsInfo/goodsInfo.wxml b/pages/goods/goodsInfo/goodsInfo.wxml index 6b3d789..156e352 100644 --- a/pages/goods/goodsInfo/goodsInfo.wxml +++ b/pages/goods/goodsInfo/goodsInfo.wxml @@ -1,3 +1,6 @@ + + + @@ -501,66 +504,66 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - 阶梯促 - - - - {{jieti_prom}} - - - - - - - - 订单优惠 @@ -576,27 +579,29 @@ - - - - 组合购 - - - - - - {{zh_act.name}} - - (活动时间:{{tool.format_tt(zh_act.start_time)}} - {{tool.format_tt(zh_act.end_time)}}) - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -623,6 +628,7 @@ + {{item.act_name}} @@ -638,35 +644,28 @@ - - - - 优惠热配 - - 查看全部 - + + + + 促销 + + + 优惠促销 + 搭配促销 + 组合购 + 阶梯促销 + - - - - - - {{collocationGoods.title}} - - 搭配价¥{{collocationGoods.min}}-{{collocationGoods.max}} - - 搭配价¥{{collocationGoods.min}} - - 活动至{{filters.format_time(collocationGoods.end_time,1)}} - + + - - + + 领券 @@ -682,6 +681,7 @@ + @@ -731,7 +731,31 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1749,6 +1773,7 @@ + @@ -1819,4 +1844,6 @@ - \ No newline at end of file + + + diff --git a/pages/goods/goodsList/goodsList.wxml b/pages/goods/goodsList/goodsList.wxml index 46542dd..e7746b3 100644 --- a/pages/goods/goodsList/goodsList.wxml +++ b/pages/goods/goodsList/goodsList.wxml @@ -1,12 +1,13 @@ - + + 每人限参与{{limit_num}}次; - 每人限参与{{limit_num}}次; 满{{item.condition}} 减{{item.content.money}}元 + 包邮 打{{item.content.sale}}折 送{{item.content.int}}积分 送{{item.content.coupon}}元优惠券 diff --git a/utils/more_cx.js b/utils/more_cx.js new file mode 100644 index 0000000..7294500 --- /dev/null +++ b/utils/more_cx.js @@ -0,0 +1,720 @@ +var regeneratorRuntime = require('runtime.js'); +module.exports = { + zhqty_bz_fun(zhqty_bz,be,zhqty_bz_arr){ + let zhqty_bz_flag =true; + for(let i=0;i num) { + zhqty_bz_flag=false; + + var be=0; + if (num % vv.zhqty == 0) { + be = num / vv.zhqty; + } else { + be = Math.floor(num / vv.zhqty) + } + item.be=item; + + zhqty_bz_arr.push(item); + // zhqty_bz.splice(i,1) + } + } + return zhqty_bz_flag; + }, + //-- 判断组合购有没有满足,只有在检查的时候,要用新的 --- + ch_zh_ok(act,gdlist,c_goods,th,item_act_map,is_need_ck_num,need_ok){ + + //-- 寻找一下 -- + function get_num(ite) { + for (let v1 in c_goods) { + var vh = c_goods[v1]; + if (vh.goods_id == ite.goods_id) { + return vh; + } + } + return 0; + } + var goods =gdlist; + var all_num=0; + var need_to_buy=0; + var all_zhqty=0; + //-- 是综合考虑到组合购的总数量和限购数量 -- + var min_can_buy=-1; + var aid=act.id; + + let no_in_arr = []; //剩余的未加入组合购 + let out_arr = []; //超出活动限购的商品放入 + + //-- 判断组合购的总数量是不是到了 -- + if(act.zh_num>0){ + //如果是在全选的情况下,那么就需要in_zhact_new来控制数量 + var need_ck=0; + if(is_need_ck_num){ + need_ck=th.data.in_zhact_new[aid]?th.data.in_zhact_new[aid]:0; + } + if(need_ck+act.zh_buy_num>=act.zh_num ){ + return false; + }else{ + min_can_buy= act.zh_num-act.zh_buy_num-need_ck; + } + } + //-- 判断组合购的限购是不是到了 -- + if(act.buy_limit>0){ + var need_ck0=0; + if(is_need_ck_num){ + need_ck0=th.data.in_zhact_new[aid]?th.data.in_zhact_new[aid]:0; + } + var min_can_buy0=0; + if(need_ck+item_act_map.buyed>=act.buy_limit ){ + return false; + }else{ + min_can_buy0=act.buy_limit-item_act_map.buyed-need_ck; + } + if(min_can_buy>0){ + if(min_can_buy0 0) { + var cbuy = item.buyqty - zh_b_num; + var key = item.goods_id + "." + act.id; + if (is_need_ck_num && th.data.in_zhact_gdmap_new[key]) { + var cbuy = item.buyqty - zh_b_num - th.data.in_zhact_gdmap_new[key]; + } + //当可买的数量为0 + if (cbuy <= 0) { + item.num = 0; + out_arr.push({ + goods_id: item.goods_id, + num: cart_num + }) + } else { + if (cbuy >= cart_num) item.num = cart_num; + else { + item.num = cbuy; + out_arr.push({ + goods_id: item.goods_id, + num: cart_num - cbuy + }) + } + } + } else { + item.num = cart_num; + } + + if (item.num) { + all_num += item.num; + //当有起购数的控制的时候 + if (item.zhqty) { + all_zhqty += item.zhqty; + if (item.num < item.zhqty) { + need_to_buy += item.zhqty - item.num; + } + if (item.num > item.zhqty) { + for (let i = 0; i < item.num - item.zhqty; i++) { + no_in_arr.push({ + goods_id: item.goods_id, + }) + } + } + } + else { + for (let j = 0; j < item.num; j++) { + no_in_arr.push({ + goods_id: item.goods_id, + }) + } + } + } else { + if (item.zhqty) { + need_to_buy += item.zhqty; + } + } + } + //当满足组合的要求:总数要满足,起购数要满足 + if (all_num >= act.zhbuyqty && !need_to_buy) { + //默认数量是1 + var act_num=1; + function sortData(a, b) { + return a.price - b.price + } + if (no_in_arr.length > 0) no_in_arr.sort(sortData); + if (act.zhbuyqty > all_zhqty) { + for (let n = 0; n < act.zhbuyqty - all_zhqty; n++) { + no_in_arr.pop(); + } + } + + //看一下剩下的数量有没有满足组合购的要求,以及要不要倍增 + if (act.is_bz && no_in_arr.length >= act.zhbuyqty) { + + var bz_num_ok = 0; //超量倍增是否满足 + var zhqty_len = 0; //几个超量倍增 + var delete_num = 0; + //看一下是几倍 + let be = parseInt(no_in_arr.length / act.zhbuyqty); + //如果有总数控制的时候 + if (min_can_buy>0) { + var be1 = min_can_buy - 1; + if (be1 < be) be = be1; + } + if(be) { + if (act.is_bzyh && zhqty_bz.length > 0) { + + let zhqty_bz_arr = []; + let zhqty_bz_flag = this.zhqty_bz_fun(zhqty_bz, be, zhqty_bz_arr); + if (zhqty_bz_flag) { + for (let i = 0; i < zhqty_bz.length; i++) { + var vv = zhqty_bz[i]; + for (let j = 0; j < be * vv['zhqty']; j++) { + let index = no_in_arr.findIndex(i => { + return vv.goods_id === i.goods_id + }) + if (index > -1) { + delete_num++ + no_in_arr.splice(index, 1) + } + } + } + } else { + zhqty_len = 1; + let min_bz_num = Math.min.apply(Math, zhqty_bz_arr.map(function (o) { + return o['be']; + })); + let new_arr = zhqty_bz_arr.filter(ii => { + return ii['be'] == min_bz_num; + }) + //-- 要看一下倍数还有没有 --- + be = new_arr[0].be; + //如果有总数控制的时候 + if (min_can_buy>0) { + var be1 = min_can_buy - 1; + if (be1 < be) be = be1; + } + if(be){ + for (let i = 0; i < zhqty_bz.length; i++) { + let item1 = zhqty_bz[i]; + for (let j = 0; j < be * item1['zhqty']; j++) { + let index = no_in_arr.findIndex(i => { + return item1.goods_id === i.goods_id + }) + if (index > -1) { + no_in_arr.splice(index, 1) + } + } + } + act_num+=be; + } + } + } + if (!zhqty_len) { + let pop_num = be * act.zhbuyqty - delete_num; + for (var m = 0; m < pop_num; m++) { + no_in_arr.pop(); + } + act_num+=be; + } + } + } + + //-- 参与活动的金额要返回回去 -- + item_act_map.act_num=act_num; + let goods_map = {}; + //算一下剩余的商品 + if (no_in_arr.length) { + for (let ii in no_in_arr) { + let item = no_in_arr[ii]; + if (goods_map[item.goods_id]) { + var num = goods_map[item.goods_id]; + goods_map[item.goods_id] = ++num; + } else { + goods_map[item.goods_id] = 1; + } + } + } + //超量的部分也要计算一下 + if (out_arr.length) { + for (var m in out_arr) { + if (goods_map[item.goods_id]) { + var num = goods_map[item.goods_id]; + num += item.num + goods_map[item.goods_id] = num; + } else { + goods_map[item.goods_id] = item.num; + } + } + } + + //-- 组合购的商品限购的数组控制 -- + var in_zhact_gdmap={}; + //商品的列表 + for (var u in goods) { + var ite = goods[u]; + var cart_num = get_num(ite).goods_num; + + if (ite.buyqty > 0 && cart_num > 0) { + var key = ite.goods_id + "." + act.id; + if(goods_map[ite.goods_id]){ + cart_num-=goods_map[ite.goods_id]; + } + if(cart_num>0){ + if (in_zhact_gdmap[key]) { + in_zhact_gdmap[key] += ite.num; + } else { + in_zhact_gdmap[key] = ite.num; + } + } + + } + } + item_act_map.in_zhact_gdmap=in_zhact_gdmap; + return true; + } + + if(!need_ok) { + item_act_map.is_no_ok=1; + return true; + } + + return false; + }, + //-- 判读一下促销分组的问题 -- + //-- is_need_ck_num 是多门店计算的时候,数量是不是要累家计算,主要是拿来计算限购 -- + //-- need_ok是判断要不要满足条件,这是在cart2的时候,才会赋值成1 -- + async cart_cx_group(th,goods,car_item,is_need_ck_num,need_ok,func){ + + var os= getApp().globalData.setting; + //更改活动的时候,就不能再重新计算活动,只有再加减数量和选择商品的时候,就要重新计算活动 + if(th.data.change_act || (car_item.show_can_cx && Object.keys(car_item.show_can_cx).length>0)){ + var show_can_cx=car_item.show_can_cx; + for(var k in show_can_cx){ + var k_item=show_can_cx[k]; + var ck_prom_type=null; + //-- 如果是多活动,先把活动按照后台的顺序排序一下, + //-- 同时确定一下商品最终要用什么活动来购买计算。 --就是要进行切换 -- + if(k_item.act_arr.length>1){ + var json_d =th.data.json_d; + var auto_promote_sale=json_d.auto_promote_sale; + var sort_type=''; + + if(!auto_promote_sale){ + sort_type='prom_type'; + }else{ + var auto_promote_sale=auto_promote_sale.split(','); + //-- 循环处理 -- + k_item.act_arr.map(function (e){ + var fd=auto_promote_sale.indexOf(e.prom_type+''); + e.sort=fd; + }) + sort_type='sort'; + } + //-- 排序一下,进行升序 -- + function comp(a, b) { + return a[sort_type]-b[sort_type]; //升序 + } + //活动要排序一下 + k_item.act_arr.sort(comp); + + //确定一下活动,先看一下有没有选择的活动 + ck_prom_type=k_item.act_arr.find(function (el){ + return el.sele; + }) + + } + //-- 此时已经确定了商品的活动是什么类型的,可以确定购物车中商品的具体活动进行金额的计算 -- + if(!ck_prom_type) ck_prom_type=k_item.act_arr[0]; + + //-- 此时要把购物车中的商品确定活动 -- + for (var b=0; b-1; + }) + if(fg>-1){ + goods[fg].prom_type=ck_prom_type.prom_type; + goods[fg].prom_id=ck_prom_type.prom_id; + } + } + + } + func(show_can_cx); + return false; + } + + //-- 促销活动对象表,最初的map表,包含活动类型,活动id,goods商品 --- + var cx_act_map=[]; + for(var i=0; i-1) continue; + + //-- 把活动进行规整 -- + var more_cx=c_item.more_cx; + if(!more_cx) continue; + for (var j=0;j{ + return e1.goods_id==c_item.goods_id && e1.buyqty>0 + }) + + var in_zhact_gdmap_new=th.data.in_zhact_gdmap_new; + var key = c_item.goods_id + "." + n_item.prom_id; + + //如果是组合购 + if(zh_gd_fd && in_zhact_gdmap_new[key] && in_zhact_gdmap_new[key]>=zh_gd_fd.buyqty){ + continue; + } + } + + + var key=n_item.prom_type+'-'+n_item.prom_id; + var fd=cx_act_map.find(function (e){ + return e.key==key; + }) + if(fd){ + fd.goods.push(c_item); + }else{ + var p_item={key:key,prom_type:n_item.prom_type,prom_id:n_item.prom_id,goods:[],act:n_item}; + if(n_item.prom_type==7){ + p_item.zh_pro=n_item.zh_pro; + } + p_item.goods.push(c_item); + cx_act_map.push(p_item); + } + } + goods[i].prom_type=0; + goods[i].prom_id=0; + } + //-- 如果活动数量大于1个,那么活动就要排序一下,有商品种类数最多排再前面,降序进行排列 -- + if(cx_act_map.length>1){ + //门店分类要排序下 + function compare(a, b) { + var value1 = a.goods.length; + var value2 = b.goods.length; + return value2 - value1; + } + cx_act_map.sort(compare); + } + //-- 能够进行最后计算的活动(包含切换) -- + var can_calc_cx=[]; + //-- 此时对数组的活动进行判断,看能不能达到购买数量的条件 -- + for(var ii=0;ii 0){ + // 优惠的促销的限购要反写进去不和 + item_act_map.limit_num=fd['limit_num']; + if(fd.hasOwnProperty('buyed')){ + item_act_map.buyed= fd.buyed; + }else{ + //-- 获取已经购买了多少件 -- + var url = "/api/weshop/ordergoods/getUserBuyPromNum?store_id="+os.stoid+"&user_id=" + +getApp().globalData.user_id+"&prom_type=3&prom_id="+aid; + await getApp().request.promiseGet(url, {}).then(rh => { + if(rh.data.code==0){ + item_act_map.buyed=rh.data.data.userbuynum; + fd.buyed=rh.data.data.userbuynum; + th.data.in_yhact[aid].buyed=rh.data.data.userbuynum; + } + }) + } + + if(item_act_map.buyed+need_num>=fd['limit_num']){ + continue; //-- 进行下一个循环 -- + } + } + + + + var fir_act=item_act_map.act.fir_act; + var t_goods=item_act_map.goods; + var all_num=0; + var all_pri=0; + for(var f=0;f { + if(rh.data.code==0){ + item_act_map.buyed=rh.data.data.userbuynum; + zh_pro0.buyed=rh.data.data.userbuynum; + } + }) + } + + //当满足组合的要求:总数要满足,起购数要满足 + if(this.ch_zh_ok(zh_pro0,zhact_gdlist,zh_goods,th,item_act_map,is_need_ck_num,need_ok)){ + can_calc_cx.push(item_act_map) + } + break; + default: + can_calc_cx.push(item_act_map); + } + + } + + //-- 此时来给满足条件的活动进行分组~~相同参与商品和数量的归纳再一起, -- + //-- 同时相同商品数量的活动,还要看取那一个来进行计算金额。 默认的时候是按照后台的顺序。-- + //-- 有选择的时候,就按照切换选择了什么就按照什么来计算 -- + //-- can_calc_cx的元素(item_act_map)最后是放到act_arr里面去了 -- + var show_can_cx={}; + if(can_calc_cx.length){ + for(var p=0;p1){ + e.is_duo_gd=1; + } + e.act_arr.push(can_calc_cx[p]); + show_can_cx[ch_map.join()]=e; + } + } + } + + for(var k in show_can_cx){ + var k_item=show_can_cx[k]; + var ck_prom_type=null; + //-- 如果是多活动,先把活动按照后台的顺序排序一下, + //-- 同时确定一下商品最终要用什么活动来购买计算。 --就是要进行切换 -- + if(k_item.act_arr.length>1){ + var json_d =th.data.json_d; + var auto_promote_sale=json_d.auto_promote_sale; + var sort_type=''; + + if(!auto_promote_sale){ + sort_type='prom_type'; + }else{ + var auto_promote_sale=auto_promote_sale.split(','); + //-- 循环处理 -- + k_item.act_arr.map(function (e){ + var fd=auto_promote_sale.indexOf(e.prom_type+''); + e.sort=fd; + }) + sort_type='sort'; + } + //-- 排序一下,进行升序 -- + function comp(a, b) { + return a[sort_type]-b[sort_type]; //升序 + } + //活动要排序一下 + k_item.act_arr.sort(comp); + + //确定一下活动,先看一下有没有选择的活动 + ck_prom_type=k_item.act_arr.find(function (el){ + return el.sele; + }) + + //如果 + + } + //-- 此时已经确定了商品的活动是什么类型的,可以确定购物车中商品的具体活动进行金额的计算 -- + if(!ck_prom_type){ + ck_prom_type=k_item.act_arr[0]; + k_item.act_arr[0].sele=1; + //-- 把当前活动进行赋值 -- + k_item.cur_act=ck_prom_type; + } + + //-- 如果是要控制数量的时候,也就是全选的时候,或者加减号的时候 -- + if(is_need_ck_num && !ck_prom_type.is_no_ok){ + var t_pid=ck_prom_type.prom_id; + switch (ck_prom_type.prom_type){ + case 3: + if(!th.data.in_yhact_new[t_pid]) th.data.in_yhact_new[t_pid]=0; + th.data.in_yhact_new[t_pid]++; + break; + case 7: + if(!th.data.in_zhact_new[t_pid]) th.data.in_zhact_new[t_pid]=0; + th.data.in_zhact_new[t_pid]+=ck_prom_type.act_num; + //-- 数组的优化 -- + var nei_gd_map=ck_prom_type.in_zhact_gdmap; + if(nei_gd_map){ + for (var vg in nei_gd_map) { + if (!th.data.in_zhact_gdmap_new[vg]) th.data.in_zhact_gdmap_new[vg] = 0; + th.data.in_zhact_gdmap_new[vg] += nei_gd_map[vg]; + } + } + break; + } + } + //-- 此时要把购物车中的商品确定活动 -- + for (var b=0; b-1; + }) + if(fg>-1){ + goods[fg].prom_type=ck_prom_type.prom_type; + goods[fg].prom_id=ck_prom_type.prom_id; + } + } + } + //-- 显示到前端,并切换 -- + //th.setData({show_can_cx}) + //--- 调用回调函数 --- + func(show_can_cx); + + }, + //-- 查看活动参与的商品是不是有重复交集的地方,是不是一样的商品数量,can_calc_cx这个数组也是按照商品的数量降序排列的-- + check_ok_cx_pro(item_act_map,can_calc_cx){ + //-- 加入第一个,返回真 -- + if(!can_calc_cx.length) return true; + var th_goods=item_act_map.goods; + for(var i=0;ith_goods.length){ + return false; + } + } + return true; + }, + //-- 判断是不是有交集,返回交集的数量 -- + hasJiao(arr1, arr2){ + var num=0; + arr1.map(function (e){ + var idx=arr2.findIndex(function (g){ + return g.goods_id==e.goods_id; + }) + if(idx>-1) num++; + }) + return num; + }, + + +} \ No newline at end of file