diff --git a/pages/cart/cart/cart.js b/pages/cart/cart/cart.js index 5d65ea5..dc19a39 100644 --- a/pages/cart/cart/cart.js +++ b/pages/cart/cart/cart.js @@ -5,8 +5,9 @@ var t = getApp(), app = getApp(), rq = t.request, ut = require("../../../utils/util.js"), - zh_calc = require("zh_calculate.js"); - var regeneratorRuntime = require('../../../utils/runtime.js'); + zh_calc = require("zh_calculate.js"), + ladder_calc = require("ladder_calculate.js"); + var regeneratorRuntime = require('../../../utils/runtime.js'); Page({ data: { @@ -38,6 +39,8 @@ Page({ zuhe_map:{}, zuhe_map_good:{}, in_zhact_gdmap:{}, //不同门店参与同一活动的限购 + + ladder_map:{}, //阶梯促销需要的map }, onLoad: function() { var a = this,ee=a; @@ -83,7 +86,6 @@ Page({ th.setData({ bconfig: e,sales_rules:e.sales_rules }); - getApp().request.promiseGet("/store/storemoduleendtime/page?store_id=" +os.stoid + "&type=6",{}).then(res=>{ //未购买 if(res.data.code!=0 || !res.data.data || !res.data.data.pageData || !res.data.data.pageData.length){ @@ -210,6 +212,8 @@ Page({ get_cart: function() { var th = this; th.data.in_zhact_gdmap={}; + th.data.ladder_map={}; + var rd = Math.random().toString(36).substr(2, 15); var user_id=getApp().globalData.userInfo.user_id; getApp().request.get("/api/weshop/cart/list", { @@ -223,8 +227,7 @@ Page({ success:async function(su) { console.log(su,10000); //按门店分类的数组 - var arr = new Array(), - carr = su.data.data.pageData; + var arr = new Array(), carr = su.data.data.pageData; var all_num = 0; if(carr && carr.length>0) { @@ -354,35 +357,86 @@ Page({ } } - //--判断优惠活动有没有过期-- + //--判断优惠活动有没有过期,-- else if (item.prom_type == 3) { - var isok = 1; - await getApp().request.promiseGet("/api/weshop/goods/getGoodsPromList/" + os.stoid + "/" + item.goods_id + "/1", {}).then(res => { - if (res.data.code == 0) { - var r_data = res.data.data; - if (!r_data.promGoodsLists) { + 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 + }; + 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/getGoodsPromList/" + os.stoid + "/" + item.goods_id + "/1", {}).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, {}); + //商品已经无活动 + isok = 0; + }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, {}); + //商品已经下架 + isok = 0; + } + } + + } else { var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id; getApp().request.delete(url, {}); - //商品已经无活动 + //商品已经下架 isok = 0; - }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, {}); - //商品已经下架 - isok = 0; - } - } - - } else { - var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id; - getApp().request.delete(url, {}); - //商品已经下架 - isok = 0; - } - }) + } + }) + + }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, {}); + //商品已经无活动 + isok = 0; + }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, {}); + //商品已经下架 + isok = 0; + } + } + + } else { + var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id; + getApp().request.delete(url, {}); + //商品已经下架 + isok = 0; + } + }) + + } + if (!isok) continue; + + + } else if (item.prom_type == 7) { if(!th.data.zuhe_map[item.prom_id]){ @@ -470,6 +524,68 @@ Page({ // 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/get/"+os.stoid+"/"+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() { + 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) { //如果有优惠活动,要更新活动 await getApp().request.promiseGet("/api/weshop/goods/getGoodsPromList/" + os.stoid + "/" + item.goods_id + "/1", {}).then(res => { @@ -575,9 +691,6 @@ Page({ } } - // console.log('AAAAAAAAAAAA', all_num); - // getApp().globalData.cartGoodsNum = all_num; - th.setData({ requestData: arr, all_num: all_num, @@ -948,11 +1061,13 @@ Page({ if(item[j].is_gift) continue; var obj=JSON.parse(JSON.stringify(item[j])); - //计算之前先移除 + //计算之前先移除组合购的计算 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) { fir = item[j].distr_type; } else { @@ -965,8 +1080,12 @@ Page({ var txt = "requestData[" + i + "].goods[" + j + "].selected"; if(e.data.checkAllToggle) obj.goods_num=0; - if(obj.prom_type==7) - zh_calc.add_zhprom(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); + e.setData({ [txt]: !e.data.checkAllToggle, @@ -974,7 +1093,7 @@ Page({ if (!e.data.checkAllToggle) { //组合购的金额要另外算 - if(item[j].prom_type!=7) + 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; } @@ -1012,6 +1131,12 @@ Page({ 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"; @@ -1326,7 +1451,10 @@ Page({ //不管怎么样都要移出去 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; @@ -1334,11 +1462,20 @@ Page({ 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){ - //先把商品放入组合计算的专用的区域 - zh_calc.add_zhprom(car,a,obj); - }else{ + //先把商品放入组合计算的专用的区域 + 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; @@ -1353,10 +1490,17 @@ Page({ //总的价格,把组合商品的价格拿出来 var zh_calc_res=zh_calc.calculate_zh(car,a,th); + //总的价格,把阶梯促销商品的价格拿出来 + 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+=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) @@ -1409,9 +1553,6 @@ Page({ }); } } - - // getApp().globalData.cartGoodsNum = all_num; - // console.log('CCCCCCC', all_num, getApp().globalData.cartGoodsNum); this.setData({ checkAllToggle: ischeck, @@ -1423,11 +1564,8 @@ Page({ //----------------------更新购物数量,加减,调用接口--------------------- postCardList: function(t, item, pitem) { - var e = this,th=e; var user_id = getApp().globalData.user_id; - // console.log('update'); - // console.log('9995959595959',t); rq.get("/api/weshop/goods/get/" + oo.stoid + "/" + t.goods_id, { isShowLoading: 0, async success(d) { @@ -1456,12 +1594,9 @@ Page({ th.setData({[txt]:promgoodsbuynum}); } goodsbuynum = buy_num_data.goodsbuynum; - - - // console.log('goodsbuynum===========', goodsbuynum); + }) - var buyed_mum2 = t.goods_num + goodsbuynum; if (buyed_mum2 > limit && limit > 0) { diff --git a/pages/cart/cart/cart.wxml b/pages/cart/cart/cart.wxml index bbd4c83..8329100 100644 --- a/pages/cart/cart/cart.wxml +++ b/pages/cart/cart/cart.wxml @@ -164,6 +164,15 @@ + + + + + {{item.title}} + 去凑单 + + + diff --git a/pages/cart/cart/ladder_calculate.js b/pages/cart/cart/ladder_calculate.js new file mode 100644 index 0000000..779e1d2 --- /dev/null +++ b/pages/cart/cart/ladder_calculate.js @@ -0,0 +1,212 @@ +module.exports = { + //辅助数组添加元素功能 + find_in_add: function(list, ele) { + var idx=list.findIndex(function (e) { + return e.goods_id==ele.goods_id; + }) + if(idx>-1) return false; + list.push(ele); + }, + //辅助数组添加元素功能 + find_in_remove: function(list, ele) { + var idx=list.findIndex(function (e) { + return e.goods_id==ele.goods_id; + }) + if(idx==-1) return false; + list.splice(idx, 1); + }, + + //主要是把组合购的商品分离出来 + add_ladder_prom: function(car, a, ele) { + var point = car[a]; + if (point.ladder_map) { + if (point.ladder_map[ele.prom_id]) { + this.find_in_add(point.ladder_map[ele.prom_id].goods, ele); + } else { + point.ladder_map[ele.prom_id] = { + goods: [], + act: ele.act + }; + point.ladder_map[ele.prom_id].goods.push(ele); + } + } else { + point.ladder_map = {}; + point.ladder_map[ele.prom_id] = { + goods: [], + act: ele.act + }; + point.ladder_map[ele.prom_id].goods.push(ele); + } + }, + //未选中的商品,要从中剔除 + remove_ladder_prom: function(car, a, ele) { + var point = car[a]; + if (point.ladder_map) { + if (point.ladder_map[ele.prom_id]) { + this.find_in_remove(point.ladder_map[ele.prom_id].goods, ele); + } + } + }, + + //把组合购的商品价格计算出来,同时每个会员都有购买组合商品的上限!ladder_b_num是已经购买了多少件 + calculate_ladder: function(car, a, th) { + var car_item = car[a]; + var tfeel = 0,offline_price = 0,offline_num = 0; + var txt = "requestData[" + a + "].l_need_list"; + var need_to=[]; + + //活动的列表都存储在这里面,可以快速查询 + if (!car_item.ladder_map) { + var res = { + tfeel: tfeel, + offline_price: offline_price, + offline_num: offline_num + }; + th.setData({ + [txt]: null + }); + return res; + } + + //因为可能有多个组合购的活动 + for (var mi in car_item.ladder_map) { + var bitem = car_item.ladder_map[mi]; + var act = bitem.act; //获取到组合购的详情 + var all_num = 0; //商品数量之和 + var all_price = 0; + var aprice=0; + var no_in_arr = []; //剩余的未加入组合购 + + var title =""; //提示语; + var goods = car_item.goods; + + //-- 每件商品要剔除的量 -- + for (let v3 in car_item.goods) { + car_item.goods[v3].l_need_downlow_num=0; + } + + //寻找一下 + function get_num2(ite) { + var vh=car_item.goods.findIndex(function (e) { + return e.goods_id == ite.goods_id + }) + if(vh>-1) return vh; + return 0; + } + + for (var i in goods) { + if(goods[i].prom_type!=10) continue; + if(!goods[i].selected) continue; + if(goods[i].prom_id!=act.id) continue; + var item = goods[i]; + item.goods_price=item.goods_price; + item.offline_price=item.offline_price; + item.cart_num =item.goods_num; + all_num += item.cart_num; + for (var j = 0; j < item.cart_num; j++) { + no_in_arr.push({ + price: item.goods_price,offline_price:item.offline_price,goods_id:item.goods_id,shop_price:item.shop_price + }) + } + } + + function sortData(a, b) { + return a.price - b.price + } + no_in_arr.sort(sortData); + + //开始阶梯计算价格 + var lev=0; + for(let j in act.ladder_list){ + if(no_in_arr.length==0) break; + let item_j=act.ladder_list[j]; + var end=no_in_arr.pop(); + var new_price=parseInt(item_j.discount_field)==1?end.shop_price:end.price; + aprice+=new_price* parseFloat(item_j.discount)/10; + lev++; + } + + //获取阶梯促销的下一个促销 + if(lev>0 && lev { - 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; + if(item1.prom_type == 7) { + if(!th.data.zuhe_map_good[item1.prom_id]) { + var isok = 1; + var is_flag = 1; + //如果有组合购 + var url = "/api/weshop/prom/zhbuy/get/" + os.stoid + "/" + item1.prom_id + '/' + getApp().globalData.userInfo.user_id; + await getApp().request.promiseGet(url, {}).then(res => { + 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; + } else { + //未找到商品的活动 + is_flag = 0; } - item1.act = res.data.data; - } else { - //未找到商品的活动 - is_flag = 0; + }) + if (!isok) { + getApp().my_warnning("组合购的活动已经过期", 0, th); + return false; } - }) - if (!isok) { - getApp().my_warnning("组合购的活动已经过期", 0, th); - return false; - } - var url1 = "/api/weshop/prom/zhbuyGoods/page"; - var req_data = { - page: 1, - pageSize: 2000, - store_id: os.stoid, - zh_id: item1.prom_id, + 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; + } + }) } - 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 + } + 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; } - }) - th.data.zuhe_map_good[item1.prom_id]=gdlist; + //如果活动已经结束 + if(res.data.data.is_end==1){ + isok=0; + } + //已经结束 + if(ut.gettimestamp()>res.data.data.end_time){ + isok=0; + } + //还未开始 + if(ut.gettimestamp() { + if (rs1.data.code==0 && rs1.data.data) { + var gdlist = rs1.data.data; + th.data.ladder_map[item1.prom_id].ladder_list=gdlist; + } + }) + } } + } //在分组的时候,就不要再调用接口,await @@ -688,31 +759,31 @@ Page({ //存储不同活动的商品列表 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; - // var h_item = obj[var1]; - // var gdlist = null; - // var url1 = "/api/weshop/prom/zhbuyGoods/page"; - // var req_data = { - // page: 1, - // pageSize: 2000, - // store_id: os.stoid, - // zh_id: h_item.prom_id, - // } - // await getApp().request.promiseGet(url1, { - // data: req_data - // }).then(res => { - // if (ut.ajax_ok(res)) { - // gdlist = res.data.data.pageData; - // } - // }) + 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 var1 in arr) { + //把阶梯促销进行分组 + var obj = ladder_calc.find_split(u_item); + if (!obj) continue; + //存储不同阶梯促销活动的商品列表 + u_item.ladder_map = {}; + for (let var1 in obj) { + var h_item=obj[var1]; + var act= th.data.ladder_map[h_item.prom_id]; + //获取活动需要的商品列表 + u_item.ladder_map[h_item.prom_id] =act; + } + ladder_calc.fir_set_arr(u_item, th); + } + //深拷贝 th.data.old_cartlist = JSON.parse(JSON.stringify(arr)); th.setData({ @@ -1269,6 +1340,7 @@ Page({ var all_coupon_price_m = 0; //所有的订单用户使用优惠券价格 var all_cutprice = 0; //所有的优惠减 var all_zh_cutprice = 0; //所有的组合优惠减 + var all_ladder_cutprice = 0; //所有的阶梯促销优惠减 var all_order_prom = 0; //所有的订单优惠 var umoney = th.data.userinfo.user_money - th.data.txmon - (th.data.userinfo.frozen_money ? th.data.userinfo.frozen_money : 0); @@ -1301,6 +1373,8 @@ Page({ await th.calc_per(c_arr); //调用函数计算每件组合购商品的单价, await zh_calc.calc_zh_split_price(c_arr,th); + //调用函数计算每件阶梯促销商品的单价, + await ladder_calc.calc_split_price(c_arr,th); //调用函数计算,优惠券优惠什么商品价格,优惠券优惠什么商品 await th.get_cart_quan(c_arr); //---循环购物车--- @@ -1332,7 +1406,10 @@ Page({ var coupon_price = 0; var quan_no = null; var is_has_zh=c_arr[i].is_has_zh; - var zh_prom_goods=c_arr[i].zh_prom_goods; //组合购计算的原始数据存储空间 + var is_has_ladder=c_arr[i].is_has_ladder; + + var zh_prom_goods=c_arr[i].zh_prom_goods; //组合购计算的原始数据存储空间 + var ladder_prom_goods=c_arr[i].ladder_prom_goods; //组合购计算的原始数据存储空间 if (th.data.using_quan[pickid] != null && th.data.using_quan[pickid] != undefined) quan_no = th.data.using_quan[pickid].coupon_no; @@ -1360,12 +1437,24 @@ Page({ //--------循环计算总价----------- for (var j = 0; j < item.length; j++) { - if(item[j].prom_type!=7){ - o_price_no_zh += item[j].goods_price * item[j].goods_num; + + var is_no_zh=0; + if(item[j].prom_type!=7 || item[j].prom_type!=10 ) is_no_zh=1; + + //组合购的商品,且有订单优惠的叠加,is_orderyh就是优惠叠加 + if(item[j].prom_type==7 && zh_prom_goods && zh_prom_goods[item[j].prom_id] + && zh_prom_goods[item[j].prom_id].act.is_orderyh ) + { + is_no_zh=1; } //组合购的商品,且有订单优惠的叠加,is_orderyh就是优惠叠加 - else if(zh_prom_goods && zh_prom_goods[item[j].prom_id] && zh_prom_goods[item[j].prom_id].act.is_orderyh ) + if(item[j].prom_type==10 && ladder_prom_goods && ladder_prom_goods[item[j].prom_id] + && th.data.ladder_map[item[j].prom_id].is_orderyh ) { + is_no_zh=1; + } + + if(is_no_zh){ o_price_no_zh += item[j].goods_price * item[j].goods_num; } o_price += item[j].goods_price * item[j].goods_num; @@ -1391,6 +1480,20 @@ Page({ } } + //如果有组合购优惠的钱,就要减价 + if (c_arr[i].ladder_cut_price>0 || c_arr[i].ladder_cut_price<0){ + o_price -= c_arr[i].ladder_cut_price; + if(o_price_no_zh>0){ + //找到那些可以订单优惠叠加的 + for(let ij in ladder_prom_goods){ + let kitem=ladder_prom_goods[ij]; + var is_has_zh=kitem.is_has_ladder; + if(th.data.ladder_map[ij].is_orderyh ) + o_price_no_zh-=kitem.cut_price; + } + } + } + //-- 计算线下取价的功能 -- if (cart_item.is_offline == 1) { o_price = o_price - cart_item.offline_price; @@ -1663,6 +1766,7 @@ Page({ all_coupon_price_m += parseFloat(cart_item.coupon_price); all_cutprice += parseFloat(cart_item.cut_price); all_zh_cutprice += parseFloat(cart_item.zh_cut_price); + all_ladder_cutprice += parseFloat(cart_item.ladder_cut_price); all_order_prom += parseFloat(cart_item.order_prom_amount); } @@ -1676,6 +1780,7 @@ Page({ all_cutprice = all_cutprice.toFixed(2); all_order_prom = all_order_prom.toFixed(2); all_zh_cutprice = parseFloat(all_zh_cutprice).toFixed(2); + all_ladder_cutprice = parseFloat(all_ladder_cutprice).toFixed(2); var atxt = "formData.total_amount"; var atxt1 = "formData.order_amount"; @@ -1686,12 +1791,13 @@ Page({ var atxt6 = "formData.cut_price"; var atxt7 = "formData.order_prom_amount"; var atxt8 = "formData.zh_cut_price"; + var atxt9 = "formData.ladder_cut_price"; th.setData({ [atxt]: all_total_m, [atxt1]: all_order_m, [atxt2]: all_price, [atxt3]: all_user_m, [atxt4]: all_shipping_m, [atxt5]: all_coupon_price_m, [atxt6]: all_cutprice, - [atxt7]: all_order_prom, show_submit: 1, [atxt8]: all_zh_cutprice + [atxt7]: all_order_prom, show_submit: 1, [atxt8]: all_zh_cutprice, [atxt9]: all_ladder_cutprice }) th.data.order_prom_list_cart = c_arr; th.set_can_num(); @@ -2379,13 +2485,22 @@ Page({ //--判断优惠活动的提交-- if (t_item.cut_price > 0) { order_prom_list.discount_amount += t_item.cut_price; - order_prom_list.prom_pt_json = JSON.stringify(t_item.prom_pt_json); } //--判断组合优惠活动的提交-- if (t_item.zh_cut_price > 0 || t_item.zh_cut_price<0) { order_prom_list.discount_amount += t_item.zh_cut_price; order_prom_list.zh_pt_json = JSON.stringify(t_item.zh_pt_json); } + + //--判断阶梯优惠活动的提交-- + if (t_item.ladder_cut_price > 0 || t_item.ladder_cut_price<0) { + order_prom_list.discount_amount += t_item.ladder_cut_price; + } + + if(t_item.prom_pt_json){ + order_prom_list.prom_pt_json = JSON.stringify(t_item.prom_pt_json); + } + if (t_item.s_intValue > 0) { order_prom_list.give_integral = t_item.s_intValue; } diff --git a/pages/cart/cart2/cart2.wxml b/pages/cart/cart2/cart2.wxml index 0983b21..95bea2b 100644 --- a/pages/cart/cart2/cart2.wxml +++ b/pages/cart/cart2/cart2.wxml @@ -95,7 +95,8 @@ - {{filters.toFix(items.goods_price,2)}} + {{filters.toFix(items.goods_price,2)}}({{items.discount}}折) + {{filters.toFix(items.goods_price,2)}} x{{items.goods_num}} @@ -431,6 +432,11 @@ 组合购优惠 - ¥ {{filters.toFix(formData.zh_cut_price,2)}}元 + + + 阶梯促销优惠 + - ¥ {{filters.toFix(formData.ladder_cut_price,2)}}元 + diff --git a/pages/cart/cart2/ladder_calculate.js b/pages/cart/cart2/ladder_calculate.js new file mode 100644 index 0000000..49bc958 --- /dev/null +++ b/pages/cart/cart2/ladder_calculate.js @@ -0,0 +1,234 @@ +var regeneratorRuntime = require('../../../utils/runtime.js'); +module.exports = { + //主要的作用,就是把阶梯促销多余的商品进行拆分, + //如果没有达成阶梯促销的要求,所有的商品都打回原价购买 + fir_set_arr: function (c_item, th) { + //寻找一下 + function get_num2(ite) { + var vh = c_item.goods.findIndex(function (e) { + return e.goods_id == ite.goods_id + }) + if (vh > -1) return vh; + return 0; + } + + //组合活动,以及组合活动从表的商品 + let ladder_map = c_item.ladder_map; + let goods = c_item.goods; //一个门店中所有的商品 + let tfeel = 0, cut_price = 0, offline_price = 0, offline_num = 0; + //多个活动要拿来循环一下 + for (let i in ladder_map) { + let title = ""; //提示语; + //其中的一个活动 + let act_item = ladder_map[i]; + let ladder_list = act_item.ladder_list; + + let all_num = 0; //商品数量之和 + let all_price0 = 0; //商品数量之和 + let aprice = 0; //达到活动条件的购买价格 + + let no_in_arr = []; //剩余的未加入组合购 + let del_g=[]; + for (var li in goods) { + if (goods[li].prom_type != 10) continue; + if (goods[li].prom_id != act_item.id) continue; + var item = goods[li]; + item.goods_price = item.goods_price; + item.offline_price = item.offline_price; + item.cart_num = item.goods_num; + all_num += item.cart_num; + for (var j = 0; j < item.cart_num; j++) { + no_in_arr.push({ + price: item.goods_price, + offline_price: item.offline_price, + goods_id: item.goods_id, + shop_price: item.shop_price, + item:item + }) + } + del_g.push(item); + } + + //开始阶梯计算价格 + var lev = 0; + for (let j in ladder_list) { + if (no_in_arr.length == 0) break; + let item_j =ladder_list[j]; + var end = no_in_arr.pop(); + var new_price = parseInt(item_j.discount_field) == 1 ? end.shop_price : end.price; + var account=new_price * parseFloat(item_j.discount) / 10; + aprice +=account; + + //-- 单个文件新增 -- + let new_g = JSON.parse(JSON.stringify(end.item)); + new_g.goods_num = 1; + new_g.account = account.toFixed(2); + new_g.discount = item_j.discount; + new_g.goods_price =new_price; + goods.push(new_g); + lev++; + } + + let goods_map = {}; + //算一下剩余的商品 + if (no_in_arr.length) { + for (let ii in no_in_arr) { + let item = no_in_arr[ii]; + if (item.offline_price) { + offline_price += item.price - item.offline_price; + offline_num += 1; + } + 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 (Object.keys(goods_map).length) { + //这里就开始拆分提交订单时的列表 + for (let j in goods_map) { + //map中存的就是商品的数量 + let num = goods_map[j]; + //找到相应的商品 + let idx = goods.findIndex(function (ele) { + return ele.goods_id == j; + }) + //goods[idx].goods_num -= num; + let new_g = JSON.parse(JSON.stringify(goods[idx])); + new_g.goods_num = num; + new_g.prom_type = 0; + new_g.prom_id = 0; + goods.push(new_g); + goods.splice(idx, 1); + } + } + + for(var h in del_g){ + var it=del_g[h]; + let idx = goods.findIndex(function (ele) { + return ele.goods_id == it.goods_id; + }) + goods.splice(idx, 1); + } + + //-- 只统计是参与活动的商品 -- + for (var ij in goods) { + var iter = goods[ij]; + if (iter.prom_type != 10 || iter.prom_id != act_item.id) { + continue; + } + all_price0 += iter.goods_num * iter.goods_price; + } + + 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]={}; + + //-- 活动的条件已经满足 -- + c_item.ladder_prom_goods[act_item.id].is_has_ladder = 1; + c_item.is_has_ladder = 1; + c_item.ladder_prom_goods[act_item.id].actual_price = aprice; + c_item.ladder_prom_goods[act_item.id].cut_price = all_price0 - aprice; + + tfeel += aprice; + cut_price += all_price0 - aprice; + + } + + c_item.ladder_all_price = tfeel; + c_item.ladder_cut_price = cut_price; + + if (c_item.is_offline == 1) { + c_item.offline_price += offline_price; + c_item.offline_num += offline_num; + } else { + c_item.is_offline == 1; + c_item.offline_price = offline_price; + c_item.offline_num = offline_num; + } + }, + //筛选组合购,纯粹的数组按活动id分组 + find_split: function (arr) { + //过滤只有团购的商品 + let oarr = arr.goods.filter(function (ele) { + return ele.prom_type == 10 + }) + if (!oarr || oarr.length == 0) return null; + //看一下有多少个不同的团购 + let map = {}, + dest = []; + for (let i = 0; i < oarr.length; i++) { + let ai = oarr[i]; + let index = map[ai.prom_id] + if (!index) { + dest.push({ + prom_id: ai.prom_id, + act: ai.act, + data: [ai] + }); + map[ai.prom_id] = dest.length; //存储下标 + } else { + let dj = dest[index - 1]; + dj.data.push(ai); + } + } + return dest; + }, + + //-- 平摊组合购的价格 -- + calc_split_price: async function (c_arr, th) { + //-- 循环处理 -- + for (var k in c_arr) { + var cart_item = c_arr[k]; //就是每一单的意思 + var ord_goods = c_arr[k].goods; //就是每一单的从表的意思 + + var ladder_map = cart_item.ladder_prom_goods; //一单中所有的组合购的集合 + var item_map = {}; + for (let i in ladder_map) { + let item = ladder_map[i]; + let prom_id = i; + //如果这个活动还没有达到要求,继续下一个计算 + if (!item.is_has_ladder) continue; + //过滤出相应组合购活动的商品 + let glist = ord_goods.filter(function (ele) { + return ele.prom_type == 10 && ele.prom_id == i; + }) + + var all_good_price = 0; + var post_gd = []; + for (let j in glist) { + let item = glist[j]; + all_good_price += item.goods_price * item.goods_num; + var gitem = { + goods_id: item.goods_id, + goods_num: item.goods_num, + goods_price: item.goods_price + } + post_gd.push(gitem); + } + //要进行优惠的计算 + if (all_good_price - item.actual_price) { + if (cart_item.prom_pt_json) { + cart_item.prom_pt_json.push({ + "ladder_prom_id": prom_id, + "dis": (all_good_price - item.actual_price).toFixed(2), + "ispt": 0 + }) + } else { + cart_item.prom_pt_json = [{ + "ladder_prom_id": prom_id, + "dis": (all_good_price - item.actual_price).toFixed(2), + "ispt": 0 + }]; + } + } + } + + + } + } + + +} diff --git a/pages/cart/cart2_pt/cart2_pt.js b/pages/cart/cart2_pt/cart2_pt.js index 56341a8..87ad774 100644 --- a/pages/cart/cart2_pt/cart2_pt.js +++ b/pages/cart/cart2_pt/cart2_pt.js @@ -296,7 +296,7 @@ Page({ th.setData({ user_addr: ie }); if (!th.data.user_addr || th.data.user_addr.address_id != ie.address_id) { th.setData({ add_back: 1 }); - if (this.data.bn_goods) th.calculatePrice2(); + if (th.data.bn_goods) th.calculatePrice2(); } }) //--更新默认地址--,看一下是不是跳到地址页面 diff --git a/pages/goods/goodsInfo/goodsInfo.js b/pages/goods/goodsInfo/goodsInfo.js index 71003ad..0f18f2a 100644 --- a/pages/goods/goodsInfo/goodsInfo.js +++ b/pages/goods/goodsInfo/goodsInfo.js @@ -469,7 +469,7 @@ Page({ } else { //要用接口是获取距离,js的计算不准 getApp().request.promiseGet("/api/weshop/pickup/list", { - data: { store_id: os.stoid, pickup_id: e.pickup_id, lat: th.data.lat, lon: th.data.lon,is_pos:1,isstop:0 }, + data: { store_id: os.stoid, pickup_id: e.pickup_id, lat: th.data.lat, lon: th.data.lon }, }).then(res => { if (res.data.code == 0) { e = res.data.data.pageData[0]; @@ -840,7 +840,7 @@ Page({ //获取统一条形码,普通商品和优惠促销的商品 - if (ee.data.data.prom_type == 0 || ee.data.data.prom_type == 3 || ee.data.data.prom_type == 5 || ee.data.data.prom_type == 7) { + if (ee.data.data.prom_type == 0 || ee.data.data.prom_type == 3 || ee.data.data.prom_type == 5 || ee.data.data.prom_type == 7 || ee.data.data.prom_type == 10) { //默认门店要拿下门店库存 if (that.data.sales_rules == 2 && that.data.is_newsales_rules) { //获取门店 @@ -1056,7 +1056,7 @@ Page({ if (this.data.prom_type == 1 || this.data.prom_type == 2) { this.getactLen(function (num) { if (num < th.data.goodsInputNum) { - getApp().my_warnning("秒杀库存不足!", 0, th); + getApp().my_warnning("活动库存不足!", 0, th); return false; } else { th.add_cart_func(t); @@ -1342,10 +1342,15 @@ Page({ }) } - else if (th.data.prom_type == 0 || th.data.prom_type == 3 || th.data.prom_type == 4 || th.data.prom_type == 5) { + else if (th.data.prom_type == 0 || th.data.prom_type == 3 || th.data.prom_type == 4 || th.data.prom_type == 5 || th.data.prom_type==10) { 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) { var pick = th.get_pick_from_list(th.data.sto_sele_id) @@ -1506,9 +1511,39 @@ Page({ }); } - //else "exchange" == t.currentTarget.dataset.action ? this.exchange(d) : this.buyNow(d); else { + + if(newd.prom_type==10){ + //----先看会员在购物车中是否加入了该商品,立即购买的----- + getApp().request.get("/api/weshop/cart/page", { + data: { + store_id: e.data.stoid, + user_id: oo.user_id, + state:1 + }, + success: function (res) { + //-------如果购物车中有相关的数据--------- + if (res.data.code==0 && res.data.data.total > 0) { + var item=res.data.data.pageData[0]; + var url = '/api/weshop/cart/del/' +e.data.stoid+ '/' + item.id; + getApp().request.delete(url, {}); + } + newd.state=1; + getApp().request.post("/api/weshop/cart/save", { + data: newd, + success: function (t) { + th.closeSpecModal(); + getApp().goto("/pages/cart/cart2/cart2?state=1"); + } + }); + + + } + }) + } + + if (th.data.prom_goods) { var prom_d = th.data.prom_goods; for (var i in prom_d) { @@ -1803,39 +1838,43 @@ Page({ }); }, - openSpecModel: function (t) { - var th = this; - var open_store = t.currentTarget.dataset.ind; - this.setData({ - store: 0, - choice_sort_store: 0, - sort_store: 0, - open_ind_store: open_store, - }) - //--先判断会员状态-- - var user_info = getApp().globalData.userInfo; - if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) { - wx.navigateTo({ - url: '/pages/togoin/togoin', - }) - return false; - } - - if(th.data.more_flash && open_store==1){ - th.setData({is_pop_more:1}); - }else{ - var ind = t.currentTarget.dataset.ind; - //回调。判断是不是优惠促销 - th.check_is_prom_goods(function () { - th.setData({ - openSpecModal: !0, - openSpecModal_ind: ind, - }); - //var is_open=th.data.config - th.get_off_price(); + openSpecModel: function (t) { + var th = this; + var open_store = t.currentTarget.dataset.ind; + this.setData({ + store: 0, + choice_sort_store: 0, + sort_store: 0, + open_ind_store: open_store, }) - } - }, + //--先判断会员状态-- + var user_info = getApp().globalData.userInfo; + if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) { + wx.navigateTo({ + url: '/pages/togoin/togoin', + }) + return false; + } + var is_go_next = 1; + if (th.data.more_flash && th.data.more_flash.length > 1 && open_store == 1) { + is_go_next = 0; + } + if (is_go_next) { + var ind = t.currentTarget.dataset.ind; + //回调。判断是不是优惠促销 + th.check_is_prom_goods(function () { + th.setData({ + openSpecModal: !0, + openSpecModal_ind: ind, + }); + //var is_open=th.data.config + th.get_off_price(); + }) + } else { + th.setData({is_pop_more: 1}); + + } + }, open_next(){ var th=this; @@ -2498,7 +2537,6 @@ Page({ dd = { store_id: o.stoid, isstop: 0, - is_pos: 1, pageSize: 2000 } } @@ -2997,7 +3035,7 @@ Page({ var user_id=getApp().globalData.user_id; if(!user_id) user_id=0; - if (prom_type == 3 || prom_type == 0 || prom_type == 5 || prom_type == 7) { + if (prom_type == 3 || prom_type == 0 || prom_type == 5 || prom_type == 7 || prom_type == 10) { this.setData({ prom_type: 0,isshow: 1, }); @@ -3101,6 +3139,7 @@ Page({ } + if (prom_type == 1 && prom_id==0){ this.setData({ prom_type: 0,isshow: 1, @@ -6019,13 +6058,43 @@ Page({ check_has_flash:function () { var th=this; var url="/api/weshop/activitylist/getGoodActInfo"; + var user_id=getApp().globalData.user_id; + if(!user_id) user_id=0; + var req_data={ - store_id:os.stoid,goodsidlist:this.data.data.goods_id,is_detail:1 + store_id:os.stoid,goodsidlist:this.data.data.goods_id,is_detail:1,user_id:user_id }; //获取秒杀的多规格 - getApp().request.promiseGet(url, {data:req_data}).then(res=>{ + getApp().request.promiseGet(url, {data:req_data}).then(async function (res) { if(res.data.code==0 && res.data.data && res.data.data.length){ - th.setData({more_flash:res.data.data}); + var arr_data=res.data.data; + for(let i in arr_data){ + let item=arr_data[i]; + if(item.prom_type==10){ + var url1="/api/weshop/prom/ladderList/list?store_id="+os.stoid+"&form_id="+item.act_id; + await getApp().request.promiseGet(url1, {}).then(rs=>{ + if(rs.data.code==0 && rs.data.data && rs.data.data.length) { + var prom_content=""; + for(let jj in rs.data.data){ + if(rs.data.data[jj].discount==10){ + prom_content+="第"+(jj+1)+"件原价,"; + }else{ + prom_content+="第"+(jj+1)+"件"+rs.data.data[jj].discount+"折,"; + } + } + prom_content=ut.sub_last(prom_content); + item.prom_content=prom_content; + } + }) + } + } + + if(res.data.data.length=1){ + th.data.prom_id=res.data.data[0].act_id; + th.data.prom_type=res.data.data[0].prom_type; + } + + th.setData({more_flash:arr_data}); } }) }, @@ -6050,9 +6119,12 @@ Page({ corpId: id, success(res) {} }) - } - + }, + go_more_ladder:function (e) { + var prom_id=e.currentTarget.dataset.id; + getApp().goto("/pages/goods/goodsList/goodsList?ladder_id="+prom_id); + } }); diff --git a/pages/goods/goodsInfo/goodsInfo.wxml b/pages/goods/goodsInfo/goodsInfo.wxml index 09c23f6..1c30b8d 100644 --- a/pages/goods/goodsInfo/goodsInfo.wxml +++ b/pages/goods/goodsInfo/goodsInfo.wxml @@ -655,23 +655,33 @@ - - 秒杀 - - - - - - {{item.act_name}} - - (活动时间:{{tool.format_tt(item.s_time)}} - {{tool.format_tt(item.e_time)}}) + 秒杀 + + + + + + {{item.act_name}} + + (活动时间:{{tool.format_tt(item.s_time)}} - {{tool.format_tt(item.e_time)}}) + + - + + + + + + + 阶梯促 + + {{item.prom_content}} + + + - - diff --git a/pages/goods/goodsInfo/goodsInfo.wxss b/pages/goods/goodsInfo/goodsInfo.wxss index 66fc945..3a065c7 100644 --- a/pages/goods/goodsInfo/goodsInfo.wxss +++ b/pages/goods/goodsInfo/goodsInfo.wxss @@ -2875,4 +2875,6 @@ button.custom-service::after{ line-height: 70rpx; border-radius: 50%; color: #aaa; -} \ No newline at end of file +} + +.jie_show{ display: inline-block; width: 40rpx; height: 40rpx; background-color:#ff0505;border-radius:50%;color: #fff;text-align: center; margin: 0 20rpx } \ No newline at end of file diff --git a/pages/goods/goodsList/goodsList.wxml b/pages/goods/goodsList/goodsList.wxml index 381a377..e1c104b 100644 --- a/pages/goods/goodsList/goodsList.wxml +++ b/pages/goods/goodsList/goodsList.wxml @@ -12,8 +12,10 @@ 送{{item.content.lb_name}} + + 阶梯促销:第一件原价,第二件9折,第三件8折 + -