diff --git a/app.js b/app.js index 638efc4..3ba33ea 100644 --- a/app.js +++ b/app.js @@ -50,7 +50,7 @@ App({ config: null, //门店参数 config2: null, //门店配置 code: null, - user_id:null,//3277,// 6519901,//6453964,// 4687,// 6519870,//5682094, + user_id:null,// 6519870,//5682094, buy_now:null, picklist:null, //门店列表 wuliuprice: null, //物流价格表 @@ -661,8 +661,10 @@ App({ this.globalData.config=null; //清除config的缓存 this.globalData.gr_index=0; //商品分组的序列 this.globalData.pk_store=null; - this.globalData.wxapp_buy_obj=null - + this.globalData.wxapp_buy_obj=null; + this.globalData.dis_buy_obj=null; //等级卡的购买记录 + this.globalData.storeFooter=null; //底部的导航 + this.globalData.full_screen=null; //全屏 }, clear_word:function (word) { diff --git a/components/diy_goodsGroup/diy_goodsGroup.wxml b/components/diy_goodsGroup/diy_goodsGroup.wxml index c691911..3f5b5b3 100644 --- a/components/diy_goodsGroup/diy_goodsGroup.wxml +++ b/components/diy_goodsGroup/diy_goodsGroup.wxml @@ -669,7 +669,7 @@ - + diff --git a/components/diy_pingd_buy/diy_pingd_buy.js b/components/diy_pingd_buy/diy_pingd_buy.js index 72ad1e6..be709c4 100644 --- a/components/diy_pingd_buy/diy_pingd_buy.js +++ b/components/diy_pingd_buy/diy_pingd_buy.js @@ -47,7 +47,12 @@ Component({ th.countDown2(th); }, 1000); } - } + }, + + hide:function () { + // 页面被被销毁的时候,清除定时器 + clearInterval(this.data.timer); + } }, diff --git a/components/diy_seckill/diy_seckill.js b/components/diy_seckill/diy_seckill.js index e1bdff7..fdd208d 100644 --- a/components/diy_seckill/diy_seckill.js +++ b/components/diy_seckill/diy_seckill.js @@ -35,6 +35,7 @@ Component({ ylp_img: "https://mshopimg.yolipai.net/", imghost: os.imghost, timer: null, + user_id:0 }, pageLifetimes: { @@ -43,7 +44,12 @@ Component({ //会员身份变化 var th = this; var g_id = this.data.object; - this.init(g_id); + //只有再会员登陆之后,才重新调用接口 + + if(this.data.user_id!=getApp().globalData.user_id){ + this.data.user_id=getApp().globalData.user_id + this.init(g_id); + } setTimeout(function () { if (th.data.goods_array && th.data.goods_array.length > 0) { th.data.timer = setInterval(function () { @@ -51,12 +57,18 @@ Component({ }, 1000); } },600) + }, + + hide:function () { + // 页面被被销毁的时候,清除定时器 + clearInterval(this.data.timer); } }, ready: function () { var g_id = this.data.object; this.init(g_id); + this.data.user_id=getApp().globalData.user_id; }, detached() { // 页面被被销毁的时候,清除定时器 diff --git a/components/goods_list/goods_list.js b/components/goods_list/goods_list.js index 8b1ccfc..5c9ce87 100644 --- a/components/goods_list/goods_list.js +++ b/components/goods_list/goods_list.js @@ -207,5 +207,11 @@ Component({ func(ob); }) }, + + go_url:function (e) { + var url=e.currentTarget.dataset.url; + getApp().goto(url); + } + }, }) \ No newline at end of file diff --git a/components/goods_list/goods_list.wxml b/components/goods_list/goods_list.wxml index 3be78b8..7675f86 100644 --- a/components/goods_list/goods_list.wxml +++ b/components/goods_list/goods_list.wxml @@ -5,17 +5,17 @@ - + - + {{item.goods_name}} - + {{item.prom_integral}}积分 diff --git a/custom-tab-bar/index.js b/custom-tab-bar/index.js index 2cf2e5b..e229a34 100644 --- a/custom-tab-bar/index.js +++ b/custom-tab-bar/index.js @@ -9,33 +9,43 @@ Component({ list:app.def_list, cartGoodsNum:0, }, - lifetimes: { attached: function() { var th=this; - getApp().promiseGet("/api/weshop/storeDistribut/get/"+os.stoid,{}).then(rs=>{ var dis=rs.data.data; if( dis && dis.switch==0){ th.setData({is_no_distri:1}) } - }) - - getApp().promiseGet("/store/storemoduleendtime/page?store_id=" +os.stoid + "&type=5",{}).then(res=>{ - if(res.data.code==0){ - var arr = res.data.data.pageData; - if (arr.length > 0) { - var item=arr[0]; - if(item.is_sy==0){ - var now = Date.parse(new Date());now = now / 1000; - if(item.end_time 0) { + var item=arr[0]; + if(item.is_sy==0){ + var now = Date.parse(new Date());now = now / 1000; + if(item.end_time{ + if(res.data.code==0){ + var arr = res.data.data.pageData; + getApp().globalData.dis_buy_obj=arr; + if (arr.length > 0) { + var item=arr[0]; + if(item.is_sy==0){ + var now = Date.parse(new Date());now = now / 1000; + if(item.end_time { - getApp().globalData.is_read=true; - var e = res; - if(e.data.code != -1 && e.data.data && e.data.data.data){ - var itemList = e.data.data.data; - itemList = JSON.parse(itemList) - //如果是有定义自定义导航的小程序链接 - if(itemList[0].weappurl && itemList[0].weappurl!=""){ - getApp().globalData.custum_data=e.data.data; - var custum_data=e.data.data; - th.set_list(custum_data); - } - - } - - }) + + //全局缓存 + if(getApp().globalData.storeFooter) { + var itemList = getApp().globalData.storeFooter; + itemList = JSON.parse(itemList) + //-- 如果是有定义自定义导航的小程序链接 -- + if (itemList[0].weappurl && itemList[0].weappurl != "") { + getApp().globalData.custum_data = e.data.data; + var custum_data = e.data.data; + th.set_list(custum_data); + } + + }else{ + var stoid = os.stoid; + getApp().request.promiseGet("/api/weshop/storeFooter/get/" + stoid, {}).then(res => { + getApp().globalData.is_read = true; + var e = res; + if (e.data.code != -1 && e.data.data && e.data.data.data) { + var itemList = e.data.data.data; + getApp().globalData.storeFooter=itemList; + itemList = JSON.parse(itemList) + //-- 如果是有定义自定义导航的小程序链接 -- + if (itemList[0].weappurl && itemList[0].weappurl != "") { + getApp().globalData.custum_data = e.data.data; + var custum_data = e.data.data; + th.set_list(custum_data); + } + } + + }) + } } }, }, diff --git a/packageA/pages/goodsInfo/goodsInfo.js b/packageA/pages/goodsInfo/goodsInfo.js index d92a8ec..379e3f8 100644 --- a/packageA/pages/goodsInfo/goodsInfo.js +++ b/packageA/pages/goodsInfo/goodsInfo.js @@ -333,7 +333,7 @@ Page({ 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}, }).then(res=>{ - if(res.data.code==0){ + if(ut.ajax_ok(res)){ e=res.data.data.pageData[0]; if (e){ e.is_no_dis=ee.is_no_dis; diff --git a/packageA/pages/my_service/appment_main.js b/packageA/pages/my_service/appment_main.js index f2795f4..977611f 100644 --- a/packageA/pages/my_service/appment_main.js +++ b/packageA/pages/my_service/appment_main.js @@ -697,7 +697,7 @@ Page({ } }).then(res => { //-- 如果是门店的话 -- - if (res.data.code == 0 && res.data.data && res.data.data.pageData) { + if (res.data.code == 0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length) { var store_data=null; for(var i in res.data.data.pageData){ var it=res.data.data.pageData[i]; diff --git a/packageA/pages/profile/profile.js b/packageA/pages/profile/profile.js index 19609b7..3878500 100644 --- a/packageA/pages/profile/profile.js +++ b/packageA/pages/profile/profile.js @@ -1246,13 +1246,15 @@ Page({ getApp().request.promiseGet("/api/weshop/pickup/list", { data: dd, }).then(res => { - var top_store=res.data.data.pageData[0]; - th.setData({ - stoname: top_store.pickup_name, - sto_sele_name: top_store.pickup_name, - sto_sele_id: top_store.pickup_id, - sto_sele_distr: top_store.distr_type, - }) + if(ut.ajax_ok(res)){ + var top_store=res.data.data.pageData[0]; + th.setData({ + stoname: top_store.pickup_name, + sto_sele_name: top_store.pickup_name, + sto_sele_id: top_store.pickup_id, + sto_sele_distr: top_store.distr_type, + }) + } }) }else{ diff --git a/packageA/pages/prom_list/prom_list.js b/packageA/pages/prom_list/prom_list.js index f4349c0..546becc 100644 --- a/packageA/pages/prom_list/prom_list.js +++ b/packageA/pages/prom_list/prom_list.js @@ -120,7 +120,7 @@ Page({ 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}, }).then(res=>{ - if(res.data.code==0 && res.data.data && res.data.data.pageData){ + if(res.data.code==0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length){ e=res.data.data.pageData[0]; if (e){ appd.pk_store=e; @@ -1030,7 +1030,7 @@ Page({ }) }).then(res=>{ if(res.data.code==0){ - if(res.data.data.pageData){ + if(res.data.data.pageData && res.data.data.pageData.length){ var plist=res.data.data.pageData; var def_pick_store=th.data.def_pick_store; //以原来的数组为外循环,保证距离的顺序 diff --git a/packageB/pages/user/add_comment/add_comment.js b/packageB/pages/user/add_comment/add_comment.js index 859847a..13d5b01 100644 --- a/packageB/pages/user/add_comment/add_comment.js +++ b/packageB/pages/user/add_comment/add_comment.js @@ -1,4 +1,4 @@ -var t = getApp(), oo = t.globalData, a = t.globalData.setting, os = a, e = t.request, s = require("../../../../utils/util.js"), +var t = getApp(), oo = t.globalData, a = t.globalData.setting, os = a, e = t.request, s = require("../../../../utils/util.js"),ut=s, i = require("../../../../utils/selectFiles.js"); var regeneratorRuntime = require('../../../../utils/runtime.js'); @@ -27,9 +27,11 @@ Page({ var th = this; await getApp().request.promiseGet("/api/weshop/ordergoods/pageGoods", { data:{store_id:os.stoid,goods_id:a.goods_id, order_id:a.order_id}}).then(res => { - a.img = th.data.iurl + res.data.data.pageData[0].original_img; - a.goods_name=res.data.data.pageData[0].goods_name; - a.goods_num=res.data.data.pageData[0].goods_num; + if(ut.ajax_ok(res)) { + a.img = th.data.iurl + res.data.data.pageData[0].original_img; + a.goods_name = res.data.data.pageData[0].goods_name; + a.goods_num = res.data.data.pageData[0].goods_num; + } }) this.setData({ options: a }); t.getUserInfo(function (e) { diff --git a/pages/activity/pind_list/pind_list.js b/pages/activity/pind_list/pind_list.js index c12e46f..254970d 100644 --- a/pages/activity/pind_list/pind_list.js +++ b/pages/activity/pind_list/pind_list.js @@ -129,12 +129,13 @@ Page({ await getApp().request.promiseGet(i, {isShowLoading:1,data:{store_id:os.stoid,is_end:0,is_show:1}} ).then(res=>{ - plist=res.data.data.pageData; + if(ut.ajax_ok(res)) plist=res.data.data.pageData; }); - if(plist.length<=0){ + if(!plist || plist.length<=0){ getApp().showWarning("没有更多数据"); th.data.ismore=0; + return false; } //--循环读取接口--- for(var i=0;i{ - plist=res.data.data.pageData; - console.log("是什么即将开始",plist); + if(ut.ajax_ok(res)) plist=res.data.data.pageData; + }); if(plist.length<=0){ diff --git a/pages/cart/cart/cart.js b/pages/cart/cart/cart.js index c8695bf..c6ddec8 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) { @@ -353,21 +356,22 @@ 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 + 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; + let item=res.data.data[i]; + if(item.prom_type==3) { + is_g_prom=1; break; + } } } @@ -430,6 +434,7 @@ Page({ } if (!isok) continue; + } else if (item.prom_type == 7) { if(!th.data.zuhe_map[item.prom_id]){ @@ -517,6 +522,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/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() { + 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 => { @@ -529,9 +596,79 @@ Page({ }); item.prom_type=3; item.prom_id=r_data.promGoodsLists[0].prom_id; + }else if(r_data.ladderLists){ + var url = '/api/weshop/cart/update'; + getApp().request.put(url, { + data:{id:item.id,store_id:oo.stoid,prom_type:10,prom_id:r_data.ladderLists[0].form_id} + }); + 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() { + 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]; + } + } + } all_num += item.goods_num; @@ -622,9 +759,6 @@ Page({ } } - // console.log('AAAAAAAAAAAA', all_num); - // getApp().globalData.cartGoodsNum = all_num; - th.setData({ requestData: arr, all_num: all_num, @@ -995,11 +1129,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 { @@ -1012,8 +1148,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, @@ -1021,7 +1161,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; } @@ -1059,6 +1199,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"; @@ -1363,8 +1509,7 @@ Page({ if(car && car.length>0){ th.data.in_zhact_gdmap={}; for (var a = 0; a < car.length; a++) { - var item = car[a].goods, - is_s_sele = 1; + 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++) { @@ -1373,7 +1518,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; @@ -1381,11 +1529,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; @@ -1400,10 +1557,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) @@ -1456,9 +1620,6 @@ Page({ }); } } - - // getApp().globalData.cartGoodsNum = all_num; - // console.log('CCCCCCC', all_num, getApp().globalData.cartGoodsNum); this.setData({ checkAllToggle: ischeck, @@ -1494,6 +1655,8 @@ Page({ // console.log('update'); // console.log('9995959595959',t); + var e = this,th=e; + var user_id = getApp().globalData.user_id; rq.get("/api/weshop/goods/get/" + oo.stoid + "/" + t.goods_id, { isShowLoading: 0, async success(d) { @@ -1523,8 +1686,10 @@ Page({ } goodsbuynum = buy_num_data.goodsbuynum; + }) + var buyed_mum2 = t.goods_num + goodsbuynum; if (buyed_mum2 > limit && limit > 0) { wx.showModal({ @@ -1778,7 +1943,7 @@ Page({ await getApp().request.promiseGet("/api/weshop/goods/getWareStorages",{ data:{storageNos:pick_no,wareIds:encodeURIComponent(erpwareid),storeId:os.stoid} }).then(res=>{ - if(res.data.code==0){ + if(ut.ajax_ok(res)){ plist=res.data.data.pageData[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..c08e8f0 --- /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 car_item.goods[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 @@ -560,6 +631,7 @@ Page({ } 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}); //} //-- 把等级卡会优惠多少钱装进去 -- @@ -688,31 +760,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({ @@ -1270,6 +1342,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); @@ -1302,6 +1375,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); //---循环购物车--- @@ -1333,7 +1408,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; @@ -1361,12 +1439,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_useorderyh ) { + 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; @@ -1385,13 +1475,25 @@ Page({ //找到那些可以订单优惠叠加的 for(let ij in zh_prom_goods){ let kitem=zh_prom_goods[ij]; - var is_has_zh=kitem.is_has_zh; if(kitem.act.is_orderyh) o_price_no_zh-=kitem.cut_price; } } } + //如果有组合购优惠的钱,就要减价 + 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]; + if(th.data.ladder_map[ij].is_useorderyh ) + o_price_no_zh-=kitem.cut_price; + } + } + } + //-- 计算线下取价的功能 -- if (cart_item.is_offline == 1) { o_price = o_price - cart_item.offline_price; @@ -1581,6 +1683,13 @@ Page({ o_condition=o_price_no_zh-quan_price; } + //看一下是不是不用组合购的订单优惠的叠加 + if(is_has_ladder){ + o_condition=o_price_no_zh-quan_price; + } + + + var order_m = 0; //---判断是不是有订单优惠--- await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", { @@ -1664,6 +1773,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); } @@ -1677,6 +1787,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"; @@ -1687,12 +1798,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(); @@ -2380,13 +2492,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; } @@ -2423,6 +2544,15 @@ Page({ //房间号的ids var room_ids = ""; + + //-- 把券的钱,写入从表 --- + if (t_item.quan_youhui_list && t_item.coupon_price) { + for (var kk in t_item.quan_youhui_list) { + var you_item = t_item.quan_youhui_list[kk]; + //-- 对券的价格进行平摊 -- + await th.split_set_goods_quanprice(you_item,t_item); + } + } //-------------让商品添加到商品列表-------------------- for (var k = 0; k < t_item.goods.length; k++) { var g_item = t_item.goods[k]; @@ -2445,22 +2575,15 @@ Page({ goods.offline_cut = (g_item.goods_price - g_item.offline_price).toFixed(2); goods.pricing_type = g_item.pricing_type; } - - //--把券的钱,写入从表--- - if (t_item.quan_youhui_list && t_item.coupon_price) { - for (var kk in t_item.quan_youhui_list) { - var you_item = t_item.quan_youhui_list[kk]; - if (g_item.prom_type!=7 && g_item.erpwareid == you_item.WareId) { - goods.quan_num = you_item.WareCashSum; - goods.quan_no = you_item.CashRepNo; - } - } + if(g_item.quan_num){ + goods.quan_num=g_item.quan_num; + goods.quan_no=g_item.quan_no; } - //--判断活动的类型-- switch (g_item.prom_type) { case 1: case 2: + case 10: goods.prom_type = g_item.prom_type; goods.prom_id = g_item.prom_id; break; @@ -2525,6 +2648,12 @@ Page({ goods.room_id = g_item.room_id; room_ids += g_item.room_id + ","; } + + //如果有阶梯促销 + if(g_item.ladder_list_id){ + goods.ladder_list_id=g_item.ladder_list_id; + } + item.order_goods.push(goods); } @@ -3409,6 +3538,7 @@ Page({ get_cart_quan: async function (order_prom_list_cart) { var th = this; var is_xz_yh = 1; + var user_id=getApp().globalData.user_id; //等待值的出现 //getApp().waitfor2(this,"g_cart_q_time","order_prom_list_cart",async function () { //var arr=th.data.order_prom_list_cart; @@ -3442,7 +3572,19 @@ Page({ }).then(res => { if (res.data.code == 0) prom1 = res.data.data; }) - if(!prom1.isQuan){ + if(prom1 && !prom1.isQuan){ + continue; + } + } + + //--如果是团购,要判断有没有限制使用优惠券 + if(gd.prom_type == 10){ + var prom1=null; + await getApp().request.promiseGet("/api/weshop/prom/ladderForm/getNew/"+ os.stoid +"/"+user_id+"/"+ gd.prom_id, { + }).then(res => { + if (res.data.code == 0) prom1 = res.data.data; + }) + if(prom1 && prom1.isuse && prom1. is_usecoupon){ continue; } } @@ -3899,6 +4041,73 @@ Page({ go_url:function (e) { var url = e.currentTarget.dataset.url; getApp().goto(url); + }, + + //进行对商品的平摊g_item是单个商品,you_item是这个商品分多少优惠券的钱,goods是商品列表 + split_set_goods_quanprice:async function (you_item,t_item) { + var coupon_price=you_item.WareCashSum; + var goods=t_item.goods; + var arr=[]; + //判断是不是有goods_id重复 + for(var i=0;i { + if (res.data.code == 0) { + pt_res = res.data.data; + } + }) + if (pt_res) { + var q_s_num = 0; + for (var i in pt_res) { + var idx = pt_res[i].idx; + //有account的实收价,就要用account实收价 + var price=(t_item.goods[idx].account?t_item.goods[idx].account:t_item.goods[idx].goods_price); + price=(price - pt_res[i].fisrt_account)* t_item.goods[idx].goods_num; + t_item.goods[idx].quan_num =price; + + t_item.goods[idx].quan_num =Math.floor(t_item.goods[idx].quan_num * 100) / 100; + t_item.goods[idx].quan_no=t_item.quan_no; + q_s_num += t_item.goods[idx].quan_num; + } + + if (q_s_num > parseFloat(coupon_price) || q_s_num < parseFloat(coupon_price)){ + for (var ik in arr) { + if (arr[ik].goods_num == 1) { + var id = arr[ik].idx; + var pri=Math.floor(coupon_price*100)/100-Math.floor(q_s_num*100)/100 + t_item.goods[id].quan_num+=pri; + break; + } + } + } + } } 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..4c23827 --- /dev/null +++ b/pages/cart/cart2/ladder_calculate.js @@ -0,0 +1,242 @@ +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); + } + + function sortData(a, b) { + return a.price - b.price + } + no_in_arr.sort(sortData); + + //开始阶梯计算价格 + 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; + //如果有平摊到单品的时候,account要显示 + if(!th.data.ispt_goods) new_g.account = account.toFixed(2); + new_g.discount = item_j.discount; + new_g.goods_price =new_price; + new_g.ladder_list_id =item_j.id; + 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_inte/cart2_inte.js b/pages/cart/cart2_inte/cart2_inte.js index 6bbe117..0f2a7f6 100644 --- a/pages/cart/cart2_inte/cart2_inte.js +++ b/pages/cart/cart2_inte/cart2_inte.js @@ -839,7 +839,7 @@ Page({ await getApp().request.promiseGet("/api/weshop/goods/getWareStorages",{ data:{storageNos:pick_no,wareIds:encodeURIComponent(erpwareid),storeId:os.stoid} }).then(res=>{ - if(res.data.code==0){ + if(res.data.code==0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length){ plist=res.data.data.pageData[0]; } }) diff --git a/pages/cart/cart2_pt/cart2_pt.js b/pages/cart/cart2_pt/cart2_pt.js index 680b6cf..c088f9b 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 9331966..a19b497 100644 --- a/pages/goods/goodsInfo/goodsInfo.js +++ b/pages/goods/goodsInfo/goodsInfo.js @@ -845,7 +845,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 || ee.data.data.prom_type == 9) { + 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 == 9 || ee.data.data.prom_type == 10) { //默认门店要拿下门店库存 if (that.data.sales_rules == 2 && that.data.is_newsales_rules) { //获取门店 @@ -1348,10 +1348,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) @@ -1444,6 +1449,7 @@ Page({ user_id: oo.user_id, goods_id: a, pick_id: e.data.sto_sele_id, + state:0 }, success: function (re) { @@ -1512,9 +1518,41 @@ 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) { + 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("/pages/cart/cart2/cart2?state=1"); + } + }); + + + } + }) + return false; + } + + if (th.data.prom_goods) { var prom_d = th.data.prom_goods; for (var i in prom_d) { @@ -1820,6 +1858,7 @@ Page({ }); }, + openSpecModel: function (t) { var th = this; var open_store = t.currentTarget.dataset.ind; @@ -1864,9 +1903,35 @@ Page({ //var is_open=th.data.config th.get_off_price(); }) + //--先判断会员状态-- + 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; //回调。判断是不是优惠促销 @@ -2256,10 +2321,12 @@ Page({ switch (goodsinfo.prom_type) { case 1: - await getApp().request.promiseGet("/api/ms/flash_sale/get/" + os.stoid + "/" + goodsinfo.prom_id, { - }).then(res => { - if (res.data.code == 0) prom = res.data.data; - }) + + if(goodsinfo.prom_id) { + await getApp().request.promiseGet("/api/ms/flash_sale/get/" + os.stoid + "/" + goodsinfo.prom_id, {}).then(res => { + if (res.data.code == 0) prom = res.data.data; + }) + } break; case 6: @@ -3035,7 +3102,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 || prom_type == 9) { + if (prom_type == 3 || prom_type == 0 || prom_type == 5 || prom_type == 7 || prom_type == 9 || prom_type == 10) { this.setData({ prom_type: 0,isshow: 1, }); @@ -5655,12 +5722,40 @@ Page({ //---检查有没有优惠活动--- check_is_youhui: function (gid, is_nor) { var th = this; + var user_id=getApp().globalData.user_id; + if(!user_id) user_id=0; //如果是普通购买的时候,要进行调用 if (is_nor) { getApp().request.get("/api/weshop/goods/getGoodsPromNormal/" + os.stoid + "/" + gid, { success: function (res) { if (res.data.code == 0) { var r_data = res.data.data; + + if(r_data.ladderLists){ + var act_id=r_data.ladderLists[0].form_id; + //-- 判断会员能不能参与阶梯促销 -- + 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 + }) + } + }) + } + th.setData({ prom_goods: r_data.promGoodsLists, }) @@ -5674,7 +5769,7 @@ Page({ getApp().request.get("/api/weshop/goods/getGoodsPromList/" + os.stoid + "/" + gid + "/0", { success: function (res) { console.log(res); - if (res.data.code == 0) { + if (res.data.code == 0 && res.data.data) { var r_data = res.data.data; var max = 0, min = 0; if (r_data.collocationList) { @@ -5688,6 +5783,32 @@ 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); } + + if(r_data.ladderLists){ + var act_id=r_data.ladderLists[0].form_id; + //-- 判断会员能不能参与阶梯促销 -- + 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 + }) + } + }) + } + th.setData({ order_prom: r_data.promOrder, collocationGoods: r_data.collocationPromList, @@ -5696,11 +5817,8 @@ Page({ th.is_show_more_buy(); } } - }) } - - }, closePoster() { @@ -6021,13 +6139,31 @@ 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; + var new_arr=[]; + for(let i in arr_data){ + let item=arr_data[i]; + //找不到活动要剔除 + if(!item.act_name) continue; + if(item.prom_type!=1) continue; + new_arr.push(item); + } + + if(new_arr.length==1){ + th.data.prom_id=new_arr[0].act_id; + th.data.prom_type=new_arr[0].prom_type; + } + + th.setData({more_flash:new_arr}); } }) }, @@ -6053,7 +6189,6 @@ Page({ success(res) {} }) }, - get_normal(gid){ this.setData({ prom_type: 0, @@ -6063,10 +6198,12 @@ Page({ this.get_sto(); this.check_is_youhui(gid,1); this.data.is_normal=1; + }, + 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 4f7c113..02dd02b 100644 --- a/pages/goods/goodsInfo/goodsInfo.wxml +++ b/pages/goods/goodsInfo/goodsInfo.wxml @@ -612,6 +612,24 @@ + + + + 阶梯促 + + + + {{jieti_prom}} + + + + + + + + + @@ -652,26 +670,30 @@ - - - - 秒杀 - - - - - - {{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)}}) + + + + - - + + @@ -679,8 +701,6 @@ - - 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.js b/pages/goods/goodsList/goodsList.js index 0268b85..8270dde 100644 --- a/pages/goods/goodsList/goodsList.js +++ b/pages/goods/goodsList/goodsList.js @@ -22,7 +22,8 @@ Page({ is_hot:0, prom_goods_list:null, rq_data:null, - isToggle: false, //切换商品视图控制符 + isToggle: false, //切换商品视图控制符 + show_all:1, //判断显示 }, onLoad: function(t) { @@ -69,8 +70,18 @@ Page({ if (0 != t.is_new && t.is_new != undefined) { url += "&is_new=" + t.is_new; } if (0 != t.is_hot && t.is_hot != undefined) { url += "&is_hot=" + t.is_hot; } - - + if (0 != t.ladder_id && t.ladder_id != undefined) { + url += "&ladder_id=" + t.ladder_id; + this.setData({ + ladder_id:t.ladder_id, + baseUrl:url, + }) + } + + var user_id=getApp().globalData.user_id; + if(!user_id) user_id=0; + url += "&user_id="+user_id; + // 优惠促销列表 if(t.prom_goods_id) { url += '&prom_goods_id=' + t.prom_goods_id; @@ -96,6 +107,53 @@ Page({ } }) } + + //--- 阶梯优惠活动的凑单 --- + if(t.ladder_id){ + var user_id=getApp().globalData.user_id; + if(!user_id) user_id=0; + getApp().request.promiseGet("/api/weshop/prom/ladderForm/getNew/"+oo.stoid+"/"+user_id+"/"+t.ladder_id,{ + }).then(res=>{ + if(res.data.code==0 && res.data.data){ + var arr= res.data.data; + + if(arr.is_end==1){ + th.setData({show_all:0}); + th.setData({err_txt:'活动已结束'}); + return false; + } + if(arr.start_time>ut.gettimestamp()){ + th.setData({show_all:0}); + th.setData({err_txt:'活动还未开始'}); + return false; + } + if(arr.end_time - + @@ -12,12 +12,14 @@ 送{{item.content.lb_name}} + + 阶梯促销:{{jieti_prom}} + - - 搜索店铺商品 + 搜索店铺商品 @@ -330,4 +332,11 @@ - \ No newline at end of file + + + + + {{err_txt}} + 回到首页 + + \ No newline at end of file diff --git a/pages/goods/search/search.js b/pages/goods/search/search.js index ae5119f..0423a75 100644 --- a/pages/goods/search/search.js +++ b/pages/goods/search/search.js @@ -108,7 +108,13 @@ Page({ if (0 != t.brand_id && t.brand_id!=undefined){ url += "&brand_id=" + t.brand_id;} if (0 != t.nation_id && t.nation_id!=undefined) { url += "&nation_id=" + t.nation_id;} if (0 != t.max_price && t.max_price!=undefined) { url += "&min_pirce=" + t.min_pirce + "&max_price=" + t.max_price;} - + if (0 != t.ladder_id && t.ladder_id != undefined) { + url += "&ladder_id=" + t.ladder_id; + this.setData({ + baseUrl:url, + + }) + } if (url != this.data.baseUrl) return this.requestSearch(url); this.openSearchModal(); // 获取历史搜索记录 @@ -200,23 +206,43 @@ Page({ break } if(url!=null && url!=''){ - await getApp().request.promiseGet(url, {}).then(res => { + await getApp().request.promiseGet(url, {}).then(async res => { var prom =null; - if(res && res.data) prom=res.data.data; - if (prom != null && prom.is_end==0 && prom.end_time>now && (prom.start_time{ + let pd_list=pd.data.data.pageData; + if(res.data.code==0 && pd_list.length>0){ + flag =pd_list.some(pd=>{ + return pd.goods_id==item.goods_id + }) + } + if (prom != null && prom.is_end==0 && prom.end_time>now && flag && (prom.start_time{ - //判断是不是有全屏广告 - if(res.data.code==0 && res.data.data.pageData && res.data.data.pageData.length>0){ - th.setData({ - is_full_screen_show:1, - full_ad:res.data.data.pageData[0], - }) - //--定时关闭-- - th.data.full_screen=setInterval(function(){ - if(!th.data.sec_show) { - clearInterval(th.data.full_screen); - th.close_full_screen(); - return false; - } - th.data.sec_show--; - th.setData({sec_show:th.data.sec_show}); - },1000) - } + //判断是不是有全屏广告 + if(res.data.code==0 && res.data.data.pageData && res.data.data.pageData.length>0){ + getApp().globalData.full_screen=res.data.data.pageData[0]; + th.setData({ + is_full_screen_show:1, + full_ad:res.data.data.pageData[0], + }) + //--定时关闭-- + th.data.full_screen=setInterval(function(){ + if(!th.data.sec_show) { + clearInterval(th.data.full_screen); + th.close_full_screen(); + return false; + } + th.data.sec_show--; + th.setData({sec_show:th.data.sec_show}); + },1000) + }else{ + getApp().globalData.full_screen=true; + } }) + + + + } } \ No newline at end of file diff --git a/pages/index/index/index.js b/pages/index/index/index.js index b30c650..a5bb279 100644 --- a/pages/index/index/index.js +++ b/pages/index/index/index.js @@ -318,74 +318,99 @@ Page({ } } - var pre_data={store_id:os.stoid,is_end:0,timetype:1,isuse:1}; - if(user_id){ - pre_data.user_id= user_id; - } + console.log(this.data.isTemplate,'首页'); - getApp().request.get("/api/weshop/marketing/marketingPresellList/page",{ - data:pre_data, - success:function (e) { - if(e.data.code==0 && e.data.data.pageData && e.data.data.pageData.length>0 ){ - var pre_data=e.data.data.pageData; - var arr = new Array(); - //--三个三个一组--- - for (var i = 0; i < pre_data.length; i += 3) { - arr.push(pre_data.slice(i, i + 3)); + if(!this.data.isTemplate){ + var pre_data={store_id:os.stoid,is_end:0,timetype:1,isuse:1}; + if(user_id){ + pre_data.user_id= user_id; + } + + getApp().request.get("/api/weshop/marketing/marketingPresellList/page",{ + data:pre_data, + success:function (e) { + if(e.data.code==0 && e.data.data.pageData && e.data.data.pageData.length>0 ){ + var pre_data=e.data.data.pageData; + var arr = new Array(); + //--三个三个一组--- + for (var i = 0; i < pre_data.length; i += 3) { + arr.push(pre_data.slice(i, i + 3)); + } + th.setData({ + preGoods: arr + }); + }else{ + th.setData({ + preGoods: null + }); } + } + }) + + // 获取幸运购活动列表 + getApp().request.promiseGet('/api/weshop/prom/luckyActivity/page', { + data: { + store_id: getApp().globalData.setting.stoid, + is_end: 0, + timetype: 1, + } + }).then(res => { + if(res.data.code == 0) { th.setData({ - preGoods: arr + luckGo_list: res.data.data.pageData.slice(0,3), + }); + } + }); + + //-----秒杀----- + var flash_data = null; + var f_req={ + store_id: os.stoid, + timetype: 2, + is_end: 0, + is_show: 1, + pageSize: 9, + user_id:0 + }; + if(user_id) f_req.user_id=user_id; + //--获取活动-- + await getApp().request.promiseGet("/api/ms/flash_sale/spikepage", { + data:f_req , + }).then(res => { + var e = res; + if (e.data.code == 0) { + flash_data = e.data.data.pageData; + if (flash_data == null || flash_data.length <= 0) return false; + + //当前时间戳 + var nt = ut.gettimestamp(); + + flash_data.forEach(function (val, ind) { + + if(val.user_price) val.price=val.user_price; + if (val.start_time > nt) flash_data[ind].status = 0; + else if (val.end_time > nt) flash_data[ind].status = 1; + if (val.buy_num >= val.goods_num) flash_data[ind].status = 2; }); - }else{ + + var arr = new Array(); + //--三个三个一组--- + for (var i = 0; i < flash_data.length; i += 3) { + arr.push(flash_data.slice(i, i + 3)); + } th.setData({ - preGoods: null + saleGoods: arr }); } - } - }) + }); + + } + + + + - //-----秒杀----- - var flash_data = null; - var f_req={ - store_id: os.stoid, - timetype: 2, - is_end: 0, - is_show: 1, - pageSize: 9, - user_id:0 - }; - if(user_id) f_req.user_id=user_id; - //--获取活动-- - await getApp().request.promiseGet("/api/ms/flash_sale/spikepage", { - data:f_req , - }).then(res => { - var e = res; - if (e.data.code == 0) { - flash_data = e.data.data.pageData; - if (flash_data == null || flash_data.length <= 0) return false; - - //当前时间戳 - var nt = ut.gettimestamp(); - - flash_data.forEach(function (val, ind) { - - if(val.user_price) val.price=val.user_price; - if (val.start_time > nt) flash_data[ind].status = 0; - else if (val.end_time > nt) flash_data[ind].status = 1; - if (val.buy_num >= val.goods_num) flash_data[ind].status = 2; - }); - - var arr = new Array(); - //--三个三个一组--- - for (var i = 0; i < flash_data.length; i += 3) { - arr.push(flash_data.slice(i, i + 3)); - } - th.setData({ - saleGoods: arr - }); - } - }); @@ -394,7 +419,7 @@ Page({ var json_d = JSON.parse(e.switch_list); th.setData({ is_closecoupon: json_d.is_closecoupon }) th.setData({ is_topstore: json_d.is_show_storeselect }) - th.setData({is_gz_h5:json_d.is_gz_h5}) + if(json_d.is_gz_h5) th.setData({is_gz_h5:json_d.is_gz_h5}) }, 1) if (typeof this.getTabBar === 'function' && this.getTabBar()) { @@ -403,7 +428,7 @@ Page({ active: index //数字是当前页面在tabbar的索引 }) - //sty + getApp().requestCardNum(this); } @@ -434,22 +459,6 @@ Page({ } }, 1500) - - // 获取幸运购活动列表 - getApp().request.promiseGet('/api/weshop/prom/luckyActivity/page', { - data: { - store_id: getApp().globalData.setting.stoid, - is_end: 0, - timetype: 1, - } - }).then(res => { - if(res.data.code == 0) { - th.setData({ - luckGo_list: res.data.data.pageData.slice(0,3), - }); - } - }); - }, //当隐藏的时候就关闭计时器 diff --git a/pages/payment/pay_success/pay_success.js b/pages/payment/pay_success/pay_success.js index a48406b..9b415c8 100644 --- a/pages/payment/pay_success/pay_success.js +++ b/pages/payment/pay_success/pay_success.js @@ -1,5 +1,6 @@ var e = getApp(); var regeneratorRuntime = require('../../../utils/runtime.js'); +var ut = require("../../../utils/util.js"); Page({ /** * 页面的初始数据 @@ -30,21 +31,28 @@ Page({ if(type==1){ await getApp().request.promiseGet("/api/weshop/order/page", {data:{store_id:e.globalData.setting.stoid,order_sn:order_sn}}).then(res=>{ - order=res.data.data.pageData[0]; - th.setData({order:order,order_sn:order_sn}) + if(ut.ajax_ok(res)){ + order=res.data.data.pageData[0]; + th.setData({order:order,order_sn:order_sn}) + } + }) }else{ await getApp().request.promiseGet("/api/weshop/order/page", {data:{store_id:e.globalData.setting.stoid,parent_sn:order_sn}}).then(res=>{ - var allmoney=0,user_money=0; - for(var i in res.data.data.pageData){ - var item=res.data.data.pageData[i]; - allmoney+=item.order_amount; - user_money += item.user_money?item.user_money:0; - } - order=res.data.data.pageData[0]; - th.setData({ order: order, type: 2, allmoney: allmoney, order_sn: order_sn, user_money: user_money}) + if(ut.ajax_ok(res)){ + var allmoney=0,user_money=0; + for(var i in res.data.data.pageData){ + var item=res.data.data.pageData[i]; + allmoney+=item.order_amount; + user_money += item.user_money?item.user_money:0; + } + order=res.data.data.pageData[0]; + th.setData({ order: order, type: 2, allmoney: allmoney, order_sn: order_sn, user_money: user_money}) + } + + }) } //--获取门店-- diff --git a/pages/team/team_show/team_show.js b/pages/team/team_show/team_show.js index 83ba2f1..4e3f654 100644 --- a/pages/team/team_show/team_show.js +++ b/pages/team/team_show/team_show.js @@ -561,7 +561,9 @@ Page({ is_show: 1 } }).then(res => { - pageteam = res.data.data.pageData; + if(ut.ajax_ok(res)){ + pageteam = res.data.data.pageData; + } }); //-- 获取用户的默认门店 -- @@ -604,7 +606,7 @@ Page({ 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}, }).then(res=>{ - if(res.data.code==0){ + if(ut.ajax_ok(res)){ e=res.data.data.pageData[0]; if (e){ appd.pk_store=e; diff --git a/pages/user/cardinfo/cardinfo.js b/pages/user/cardinfo/cardinfo.js index 34da177..7c9780e 100644 --- a/pages/user/cardinfo/cardinfo.js +++ b/pages/user/cardinfo/cardinfo.js @@ -765,7 +765,7 @@ Page({ var th = this,is_card = 0,end_time=0; await getApp().request.promiseGet("/store/storemoduleendtime/page?store_id="+os.stoid+"&type=3", {1:1}).then(res => { - if (res.data.code == 0) { + if (ut.ajax_ok(res)) { end_time=res.data.data.pageData[0].end_time; } }) @@ -828,7 +828,7 @@ Page({ var th = this,card_id =e.currentTarget.dataset.cid ,end_time=0; await getApp().request.promiseGet("/store/storemoduleendtime/page?store_id="+os.stoid+"&type=3", {1:1}).then(res => { - if (res.data.code == 0) { + if (ut.ajax_ok(res)) { end_time=res.data.data.pageData[0].end_time; } }) diff --git a/pages/user/deposit/prepaid/prepaid.js b/pages/user/deposit/prepaid/prepaid.js index a70b9a1..7de3b9b 100644 --- a/pages/user/deposit/prepaid/prepaid.js +++ b/pages/user/deposit/prepaid/prepaid.js @@ -125,7 +125,16 @@ Page({ } }).then(res => { console.log(res); - + var getcode=res.data.code; + if (getcode!=0) + { + wx.showModal({ + title: '提示', + content:res.data.msg + }); + return false; + } + var msg = res.data.data; var parentSn = msg.order_sn; diff --git a/pages/user/index/index.js b/pages/user/index/index.js index 935d344..0f68d0e 100644 --- a/pages/user/index/index.js +++ b/pages/user/index/index.js @@ -63,7 +63,7 @@ Page({ //-- 读取会员中心按钮列表 -- getApp().request.get("/api/weshop/userTool/page?pageSize=100", { success:function(res){ - if(res.data.code==0 ){ + if(ut.ajax_ok(res)) { var d_list=res.data.data.pageData; getApp().promiseGet("/api/weshop/storeDistribut/get/"+os.stoid,{}).then(rs=>{ var dis=rs.data.data; @@ -79,7 +79,7 @@ Page({ enabled: 1 }, success:function(res){ - if(res.data.code==0 && res.data.data){ + if(res.data.code==0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length){ var item=res.data.data.pageData[0]; if (item && item.ad_code) th.setData({ad_img:item.ad_code}) } diff --git a/pages/user/my_service/appment_main.js b/pages/user/my_service/appment_main.js index 7f47914..25c05eb 100644 --- a/pages/user/my_service/appment_main.js +++ b/pages/user/my_service/appment_main.js @@ -657,7 +657,7 @@ Page({ } }).then(res => { //-- 如果是门店的话 -- - if (res.data.code == 0 && res.data.data && res.data.data.pageData) { + if (res.data.code == 0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length) { var store_data=null; for(var i in res.data.data.pageData){ var it=res.data.data.pageData[i]; diff --git a/pages/user/order_detail/order_detail.js b/pages/user/order_detail/order_detail.js index 06114b2..e93dc83 100644 --- a/pages/user/order_detail/order_detail.js +++ b/pages/user/order_detail/order_detail.js @@ -101,7 +101,25 @@ Page({ r.order_status_detail = "组团中"; - r['is_all_return'] = 0; + r['is_all_return'] = 0; + + var discount_price=r['discount_amount']; + var dis_json=r['prom_pt_json']; + + if(dis_json && discount_price){ + var prom_pt_json=JSON.parse(dis_json); + var ladder_amount=0; + for (var ll_item of prom_pt_json) { + if(ll_item['ladder_prom_id']){ + ladder_amount += ll_item['dis']; + } + } + r['ladder_amount']=ladder_amount; + r['discount_amount']=Math.floor((discount_price-ladder_amount)*100)/100; + } + + + //------获取订单商品------- rq.get("/api/weshop/ordergoods/list",{ @@ -553,7 +571,7 @@ Page({ await getApp().request.promiseGet("/api/weshop/integralbuy/pageIntegralBuyGoodsList?stype=1&stypeup=1",{ data:{store_id:os.stoid,goods_id:gg.goods_id} }).then(res=>{ - if(res.data.code==0 && res.data.data && res.data.data.pageData){ + if(res.data.code==0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length){ prom=res.data.data.pageData[0]; } }) @@ -672,7 +690,7 @@ Page({ await getApp().request.promiseGet("/api/weshop/integralbuy/pageIntegralBuyGoodsList?stype=1&stypeup=1",{ data:{store_id:os.stoid,goods_id:goodsinfo.goods_id} }).then(res=>{ - if(res.data.code==0 && res.data.data && res.data.data.pageData){ + if(res.data.code==0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length){ prom=res.data.data.pageData[0]; } }) @@ -993,7 +1011,8 @@ Page({ var back_goods_arr=[]; var err_text=""; for(var i in goods_list){ - var g_item=goods_list[i]; + var g_item=goods_list[i]; + var b_item={}; //--如果是赠品,不加入购物车-- if(g_item['is_gift']) continue; if(g_item['prom_type']==4 ){ @@ -1015,7 +1034,22 @@ Page({ }).then(res=>{ good=res.data.data; - }) + }) + + //调用接口判断订单优惠, + const res = await getApp().request.promiseGet("/api/weshop/goods/getGoodsPromList/" + os.stoid + "/" + g_item.goods_id + "/0", {}) + if (res.data.code == 0 && res.data.data) { + var r_data = res.data.data; + if (r_data.ladderLists) { + var act_id = r_data.ladderLists[0].form_id; + //-- 判断会员能不能参与阶梯促销 -- + const data = await getApp().request.promiseGet("/api/weshop/prom/ladderForm/getNew/" + os.stoid + "/" + user_id + "/" + act_id, {}) + if (data.data.code == 0 && data.data.data && data.data.data.isuse && data.data.data.is_end == 0) { + b_item.prom_type = 10; + b_item.prom_id = data.data.data.id; + } + } + } if(!good){ err_text+= g_item['goods_name']+"未找到商品\n"; @@ -1045,7 +1079,7 @@ Page({ } var prom=null; - var b_item={} + b_item.goods_id=g_item.goods_id; b_item.goods_name=g_item.goods_name; b_item.goods_num=g_item.goods_num; @@ -1110,28 +1144,38 @@ Page({ b_item.price = prom.price; } break; - case 6: - b_item.is_pd_normal = 1; - break; - case 7: - //如果有组合购 - var url = "/api/weshop/prom/zhbuy/get/" + os.stoid + "/" + good.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_show == 1 && res.data.data.is_end == 0 - && ut.gettimestamp() < res.data.data.end_time - && ut.gettimestamp() > res.data.data.start_time - ) { - b_item.prom_type = 7; - b_item.prom_id = res.data.data.id; - good.prom_type = 7; - good.prom_id = res.data.data.id; - } - } - }) - break; - } - } + case 6: + b_item.is_pd_normal = 1; + break; + case 7: + //如果有组合购 + var url = "/api/weshop/prom/zhbuy/get/" + os.stoid + "/" + good.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_show == 1 && res.data.data.is_end == 0 + && ut.gettimestamp() < res.data.data.end_time + && ut.gettimestamp() > res.data.data.start_time + ) { + b_item.prom_type = 7; + b_item.prom_id = res.data.data.id; + good.prom_type = 7; + good.prom_id = res.data.data.id; + } + } + }) + break; + case 10: + let user_id = getApp().globalData.userInfo.user_id; + var url = `/api/weshop/prom/ladderForm/getNew/${os.stoid}/${user_id}/${good.prom_id}`; + await getApp().request.promiseGet(url, {}).then(res => { + if (res.data.code == 0 && res.data.data && res.data.data.isuse && res.data.data.is_end == 0) { + b_item.prom_type = 10; + b_item.prom_id = res.data.data.id; + } + }) + break; + } + } //如果有优惠促销的时候,要看下商品的优惠活动有没有过期 if(g_item.prom_type==3 || good.prom_type==3){ diff --git a/pages/user/order_detail/order_detail.wxml b/pages/user/order_detail/order_detail.wxml index a3e3417..36ab62f 100644 --- a/pages/user/order_detail/order_detail.wxml +++ b/pages/user/order_detail/order_detail.wxml @@ -32,7 +32,7 @@ - ¥{{item.member_goods_price}} + ¥{{item.member_goods_price}}({{item.ladder_discount}}折) ×{{item.goods_num}} @@ -120,7 +120,12 @@ 优惠活动 - ¥ {{order.discount_amount}}元 + ¥ {{filters.toFix(order.discount_amount,2)}}元 + + + + 阶梯优惠活动 + ¥ {{filters.toFix(order.ladder_amount,2)}}元 diff --git a/pages/user/order_list/order_list.js b/pages/user/order_list/order_list.js index c73fdd1..3623e3c 100644 --- a/pages/user/order_list/order_list.js +++ b/pages/user/order_list/order_list.js @@ -1205,6 +1205,7 @@ Page({ var err_text=""; for(var i in goods_list){ var g_item=goods_list[i]; + var b_item={}; //--如果是赠品,不加入购物车-- if(g_item['is_gift']) continue; if(g_item['prom_type']==4 ){ @@ -1228,6 +1229,20 @@ Page({ good=res.data.data; }) + //调用接口判断订单优惠, + // const res = await getApp().request.promiseGet("/api/weshop/goods/getGoodsPromList/" + os.stoid + "/" + g_item.goods_id + "/0", {}) + // if (res.data.code == 0 && res.data.data) { + // var r_data = res.data.data; + // if (r_data.ladderLists) { + // var act_id = r_data.ladderLists[0].form_id; + // //-- 判断会员能不能参与阶梯促销 -- + // const data = await getApp().request.promiseGet("/api/weshop/prom/ladderForm/getNew/" + os.stoid + "/" + user_id + "/" + act_id, {}) + // if (data.data.code == 0 && data.data.data && data.data.data.isuse && data.data.data.is_end == 0) { + // b_item.prom_type = 10; + // b_item.prom_id = data.data.data.id; + // } + // } + // } if(!good){ err_text+= g_item['goods_name']+"未找到商品\n"; continue; @@ -1256,7 +1271,7 @@ Page({ } var prom=null; - var b_item={} + b_item.goods_id=g_item.goods_id; b_item.goods_name=g_item.goods_name; b_item.goods_num=g_item.goods_num; @@ -1287,7 +1302,6 @@ Page({ } } }) - if(!prom) { //--判断商品当前的活动情况-- switch (good.prom_type) { @@ -1342,6 +1356,16 @@ Page({ } }) break; + case 10: + let user_id = getApp().globalData.userInfo.user_id; + var url = `/api/weshop/prom/ladderForm/getNew/${os.stoid}/${user_id}/${good.prom_id}`; + await getApp().request.promiseGet(url, {}).then(res => { + if (res.data.code == 0 && res.data.data && res.data.data.isuse && res.data.data.is_end == 0) { + b_item.prom_type = 10; + b_item.prom_id = res.data.data.id; + } + }) + break; } } @@ -1682,7 +1706,8 @@ Page({ store_id: os.stoid, user_id: oo.user_id, goods_id: g_item.goods_id, - pick_id: g_item.pickup_id, + pick_id: g_item.pickup_id, + state:0, }, }).then(res=>{ //-------如果购物车中有相关的数据------- diff --git a/pages/user/order_list/order_list.wxml b/pages/user/order_list/order_list.wxml index aeb9884..9bc26c9 100644 --- a/pages/user/order_list/order_list.wxml +++ b/pages/user/order_list/order_list.wxml @@ -148,7 +148,7 @@ {{filters.toFix(goods.goods_price,2)}} - {{filters.toFix(goods.member_goods_price,2)}} + {{filters.toFix(goods.member_goods_price,2)}} ({{goods.ladder_discount}}折) x{{goods.goods_num}} diff --git a/pages/user/userqy/userqy.js b/pages/user/userqy/userqy.js index 2343904..574c301 100644 --- a/pages/user/userqy/userqy.js +++ b/pages/user/userqy/userqy.js @@ -81,7 +81,7 @@ Page({ await getApp().request.promiseGet("/api/weshop/users/grade/vipgradeinfo/page",{ data:{ storeId:os.stoid} }).then(res=>{ - if (res.data.data) + if (res.data.data && res.data.data.pageData && res.data.data.pageData.length) backClass=res.data.data.pageData; }) @@ -100,7 +100,7 @@ Page({ await getApp().request.promiseGet("/api/weshop/users/grade/vipprivilegeinfo/page",{ data:{storeId:os.stoid,pageSize:100} }).then(res=>{ - if (res.data.data) + if (res.data.data && res.data.data.pageData && res.data.data.pageData.length) qy_list=res.data.data.pageData; }) @@ -108,7 +108,7 @@ Page({ await getApp().request.promiseGet("/api/weshop/users/grade/privilegeform/list/page",{ data: { storeId: os.stoid, GradeId: gradeId, userId: gl_data.user_id, pageSize: 100 } }).then(res=>{ - if (res.data.data) + if (res.data.data && res.data.data.pageData && res.data.data.pageData.length) g_qy_list=res.data.data.pageData; }); @@ -227,7 +227,7 @@ Page({ await getApp().request.promiseGet("/api/weshop/users/grade/privilegeform/list/page",{ data: { storeId: os.stoid, GradeId: gr_id, userId: gl_data.user_id, pageSize: 100} }).then(res=>{ - g_qy_list=res.data.data.pageData; + if(ut.ajax_ok(res)) g_qy_list=res.data.data.pageData; }) for(var i in qy_list){ diff --git a/utils/LoadMore.js b/utils/LoadMore.js index 7c405f1..15e6cf2 100644 --- a/utils/LoadMore.js +++ b/utils/LoadMore.js @@ -59,52 +59,49 @@ var e = function() { var n = !0; var i, r = s.data.listName, l = s.data.resultName, d = s.data.resultListName; - i = "" != r ? t.data.data[r] : t.data.data.pageData; //data.pageData是接口固定会出现的,封装好了 + i = "" != r ? t.data.data[r] : (t.data.data && t.data.data.pageData?t.data.data.pageData:null); //data.pageData是接口固定会出现的,封装好了 var u = !1, g = null, c = s.data.page; - console.log('loadmore'); - console.log(t.data.data.pageData); - console.log(c ); - //如果已经的第二页的时候,就是把数据加入数组 if (c !=undefined && c.data[l]) { u = !0; var f = null; f = "" != d ? c.data[l][d] : c.data[l], [].push.apply(f, i), g = c.data[l]; - } else g = t.data.data.pageData; + } else g = (t.data.data && t.data.data.pageData?t.data.data.pageData:null); //格式化 var glist=""; - - for (var ii = 0; ii < g.length; ii++) { - //if(g[i].prom_type == 1 || g[i].prom_type == 2 || g[i].prom_type == 6) { - if (g[ii].prom_type && g[ii].prom_type == 1) { - glist += g[ii].goods_id+","; - } - if (g[ii].original_img!=undefined){ - if (g[ii].original_img.indexOf(oo.imghost)==-1) - g[ii].original_img = oo.imghost + g[ii].original_img; - } - - if (g[ii].add_time != undefined && rurl.indexOf("goodscollect")<0){ - var tx = g[ii].add_time + ""; - if (tx.indexOf('-') == -1) { - g[ii].add_time = ut.formatTime(g[ii].add_time, 'yyyy-MM-dd hh:mm:ss'); + if(g) { + for (var ii = 0; ii < g.length; ii++) { + //if(g[i].prom_type == 1 || g[i].prom_type == 2 || g[i].prom_type == 6) { + if (g[ii].prom_type && g[ii].prom_type == 1) { + glist += g[ii].goods_id + ","; + } + if (g[ii].original_img != undefined) { + if (g[ii].original_img.indexOf(oo.imghost) == -1) + g[ii].original_img = oo.imghost + g[ii].original_img; + } + + if (g[ii].add_time != undefined && rurl.indexOf("goodscollect") < 0) { + var tx = g[ii].add_time + ""; + if (tx.indexOf('-') == -1) { + g[ii].add_time = ut.formatTime(g[ii].add_time, 'yyyy-MM-dd hh:mm:ss'); + } + } + if (rurl.indexOf('comment/page') != -1) { + console.log('comment/page'); + console.log(g[ii].img); + var tx1 = g[ii].img; + + if (tx1 != "" && tx1 != null && ut.isString(tx1)) { + var arr = ut.unserialize(tx1); + g[ii].img = arr; + } else if (!ut.isArray(tx1)) { + g[ii].img = ""; + } + } } - } - if (rurl.indexOf('comment/page')!=-1){ - console.log('comment/page'); - console.log(g[ii].img); - var tx1 = g[ii].img; - - if (tx1 != "" && tx1 != null && ut.isString(tx1)){ - var arr = ut.unserialize(tx1); - g[ii].img=arr; - } else if (!ut.isArray(tx1)){ - g[ii].img=""; - } - } }