diff --git a/pages/cart/cart/cart.js b/pages/cart/cart/cart.js index 38dc02a..754de97 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,20 +357,34 @@ Page({ } } - //--判断优惠活动有没有过期-- + //--判断优惠活动有没有过期,-- else if (item.prom_type == 3) { var isok = 1,is_g_prom=0; +<<<<<<< HEAD //因为有全场优惠活动,商品参加的活动还未开始 var url="/api/weshop/activitylist/getGoodActInfo"; var req_data={ store_id:os.stoid,goodsidlist:item.goods_id,is_detail:1,user_id:user_id +======= + + //因为有全场优惠活动,商品参加的活动还未开始 + var url="/api/weshop/activitylist/getGoodActInfo"; + var req_data={ + store_id:os.stoid,goodsidlist:item.goods_id,is_detail:1 +>>>>>>> d4b9dbf03fa79fb3ff3c5889f79eea201fb49b74 }; 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){ +<<<<<<< HEAD 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; +>>>>>>> d4b9dbf03fa79fb3ff3c5889f79eea201fb49b74 } } } @@ -430,6 +447,9 @@ Page({ } if (!isok) continue; + + + } else if (item.prom_type == 7) { if(!th.data.zuhe_map[item.prom_id]){ @@ -517,6 +537,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 => { @@ -622,9 +704,6 @@ Page({ } } - // console.log('AAAAAAAAAAAA', all_num); - // getApp().globalData.cartGoodsNum = all_num; - th.setData({ requestData: arr, all_num: all_num, @@ -995,11 +1074,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 +1093,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 +1106,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 +1144,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"; @@ -1373,7 +1464,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 +1475,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 +1503,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 +1566,6 @@ Page({ }); } } - - // getApp().globalData.cartGoodsNum = all_num; - // console.log('CCCCCCC', all_num, getApp().globalData.cartGoodsNum); this.setData({ checkAllToggle: ischeck, @@ -1494,6 +1601,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 +1632,10 @@ Page({ } goodsbuynum = buy_num_data.goodsbuynum; + }) + var buyed_mum2 = t.goods_num + goodsbuynum; if (buyed_mum2 > limit && limit > 0) { wx.showModal({ 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({ @@ -1270,6 +1341,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 +1374,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 +1407,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 +1438,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 +1474,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 +1682,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 +1772,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 +1786,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 +1797,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 +2491,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; } @@ -2461,6 +2581,7 @@ Page({ 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 +2646,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 +3536,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 +3570,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; } } 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..ec1c9aa --- /dev/null +++ b/pages/cart/cart2/ladder_calculate.js @@ -0,0 +1,235 @@ +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; + 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_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 bae9519..492e59a 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({ }); }, +<<<<<<< HEAD openSpecModel: function (t) { var th = this; var open_store = t.currentTarget.dataset.ind; @@ -1864,8 +1903,34 @@ 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; @@ -3037,7 +3102,11 @@ Page({ var user_id=getApp().globalData.user_id; if(!user_id) user_id=0; +<<<<<<< HEAD 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 == 10) { +>>>>>>> d4b9dbf03fa79fb3ff3c5889f79eea201fb49b74 this.setData({ prom_type: 0,isshow: 1, }); @@ -5657,6 +5726,8 @@ 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, { @@ -5676,7 +5747,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) { @@ -5690,6 +5761,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, @@ -5698,11 +5795,8 @@ Page({ th.is_show_more_buy(); } } - }) } - - }, closePoster() { @@ -6023,13 +6117,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}); } }) }, @@ -6055,6 +6167,7 @@ Page({ success(res) {} }) }, +<<<<<<< HEAD get_normal(gid){ this.setData({ @@ -6067,7 +6180,13 @@ Page({ this.data.is_normal=1; } +======= +>>>>>>> d4b9dbf03fa79fb3ff3c5889f79eea201fb49b74 + 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 9c6a6e5..4bd71dd 100644 --- a/pages/goods/goodsList/goodsList.js +++ b/pages/goods/goodsList/goodsList.js @@ -69,8 +69,12 @@ 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; } + + 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 +100,34 @@ 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; + var url1="/api/weshop/prom/ladderList/list?store_id="+oo.stoid+"&form_id="+arr.id; + 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+="第"+(parseInt(jj)+1)+"件原价,"; + }else{ + prom_content+="第"+(parseInt(jj)+1)+"件"+rs.data.data[jj].discount+"折,"; + } + } + prom_content=ut.sub_last(prom_content); + th.setData({jieti_prom:prom_content}) + } + }) + } + }) + } + this.requestGoodsList(url); getApp().getConfig2(function(rs){ //计算等级价相关 diff --git a/pages/goods/goodsList/goodsList.wxml b/pages/goods/goodsList/goodsList.wxml index b90eee8..d8011d4 100644 --- a/pages/goods/goodsList/goodsList.wxml +++ b/pages/goods/goodsList/goodsList.wxml @@ -12,8 +12,10 @@ 送{{item.content.lb_name}} + + 阶梯促销:{{jieti_prom}} + - diff --git a/pages/user/order_list/order_list.js b/pages/user/order_list/order_list.js index c73fdd1..898caa7 100644 --- a/pages/user/order_list/order_list.js +++ b/pages/user/order_list/order_list.js @@ -1,151 +1,159 @@ const app = getApp(); -var t = function(t) { - return t && t.__esModule ? t : { - default: t - }; - }(require("../../../utils/LoadMore.js")), - e = getApp(), - os = e.globalData.setting, - oo = e.globalData, - r = e.request, - rq = r, - a = require("../../../utils/common.js"), - s = new t.default(); +var t = function (t) { + return t && t.__esModule ? t : { + default: t + }; + }(require("../../../utils/LoadMore.js")), + e = getApp(), + os = e.globalData.setting, + oo = e.globalData, + r = e.request, + rq = r, + a = require("../../../utils/common.js"), + s = new t.default(); var regeneratorRuntime = require('../../../utils/runtime.js'); -var ut= require('../../../utils/util.js'); +var ut = require('../../../utils/util.js'); var t = require("../../../utils/pay.js"); Page({ - data: { - url: e.globalData.setting.url, - resourceUrl: e.globalData.setting.imghost, - iurl: e.globalData.setting.imghost, - categories: [{ - name: "全部", - id: 0 - }, { - name: "待付款", - id: 1 - }, { - name: "待发货", - id: 2 - }, { - name: "待收货", - id: 3 - }, { - name: "待评价", - id: 4 - }], - activeCategoryId: 0, - orderList: null, - currentPage: 1, - //已经读取过接口 - is_get: 0, - conf: null, - iscodeall: null, - sales_rules:1, //默认是显示线上库存 - - //会员的等级价位 - card_field:null, - - back_goods_arr:null, //返回商品的列表 - currentIndex: 0, - - startDate: '', - endDate: '', - list2: [], - currentPage2: 1, - currentDate: '', - total: 0, //读取时段内记录数量 - is_no_data2: 0, - is_no_more2: 0, - - - // 搜索内容 - searchContent: '', - }, - onLoad: function(t) { - // 设置日期选择器的结束时间为当前日期 - var now=new Date(); - var nowDate = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate(); - var date = new Date(now.getTime() - 7 * 24 * 3600 * 1000); - var startDate=date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate(); - - - if(t.index) { - this.setData({ - currentIndex: t.index - }); - }; - - this.setData({ - currentDate: this.currentDate(), - startDate:startDate, - endDate:nowDate, - }); - - - var th = this; - if (t.type != undefined) this.setData({ - activeCategoryId: t.type - }); - s.init(this, "", "orderList"); - }, - onShow: function() { - var th=this; - //---查看会员的等级价--- - getApp().getConfig2(function(e) { - th.setData({conf: e,sales_rules:e.sales_rules }); - //--- 看后台是不是有开通等级卡 --- - if(e.switch_list){ - var s_list=JSON.parse(e.switch_list); - var user=getApp().globalData.userInfo; - var is_open_offline=s_list.is_pricing_open; - //-- 如果后台有开启等级价的功能 -- - if(parseInt(s_list.rank_switch)==2 && user['card_expiredate']){ - var str = user['card_expiredate'].replace(/-/g, '/'); - var end = new Date(str); - end = Date.parse(end) / 1000; - var now = ut.gettimestamp(); - //--- 判断是等级会员,且在有效期范围内 --- - if(user.card_field && now{ - //未购买 - if(res.data.code!=0 || !res.data.data || !res.data.data.pageData || !res.data.data.pageData.length){ - is_open_offline=0; - }else{ - //已经过期 - var item=res.data.data.pageData[0]; - if(item.end_time { + //未购买 + if (res.data.code != 0 || !res.data.data || !res.data.data.pageData || !res.data.data.pageData.length) { + is_open_offline = 0; + } else { + //已经过期 + var item = res.data.data.pageData[0]; + if (item.end_time < ut.gettimestamp()) { + is_open_offline = 0; + } + } + + th.data.is_open_offline = is_open_offline; + }) + } + }, 1) + + this.resetData(), this.requestOrderList(this.data.activeCategoryId); + + }, + changeTab: function (t) { + if (this.data.activeCategoryId == t.currentTarget.id) return false; + this.resetData(), this.requestOrderList(t.currentTarget.id); + }, + resetData: function () { + s.resetConfig(), this.data.orderList = null, this.data.currentPage = 1; + }, /*---------获取订单列表--------*/ requestOrderList: function (t) { var rd = Math.random() * 100; - var e = this, th = e, r = e.data.url + "/api/weshop/order/page?rd=" + rd, a = ""; + var e = this, + th = e, + r = e.data.url + "/api/weshop/order/page?rd=" + rd, + a = ""; switch (t) { case "1": r += "&wait_status=0"; @@ -164,16 +172,24 @@ Page({ if (this.data.searchContent) { r += "&keyWord=" + this.data.searchContent; } - this.setData({activeCategoryId: t}); + this.setData({ + activeCategoryId: t + }); r = r + "&page=" + e.data.currentPage; s.request(r, function (t) { - th.setData({is_get: 1}); + th.setData({ + is_get: 1 + }); var data = e.data.orderList; data.forEach(async function (item, ind) { var tt = null; await getApp().request.promiseGet('/api/weshop/ordergoods/list', { - data: {order_id: item.order_id, store_id: os.stoid, pageSize: 600}, + data: { + order_id: item.order_id, + store_id: os.stoid, + pageSize: 600 + }, }).then(res => { tt = res; }) @@ -184,14 +200,13 @@ Page({ } } - data[ind]['ord_url']='/pages/user/order_detail/order_detail'; + data[ind]['ord_url'] = '/pages/user/order_detail/order_detail'; //-- 如果是优惠活动 -- - if(glist[0].prom_type==8){ - await getApp().request.promiseGet('/api/weshop/order/orderPresell/get/'+os.stoid+'/'+item.order_id, { - }).then(res => { - if(res.data.code==0){ + if (glist[0].prom_type == 8) { + await getApp().request.promiseGet('/api/weshop/order/orderPresell/get/' + os.stoid + '/' + item.order_id, {}).then(res => { + if (res.data.code == 0) { data[ind]['presell'] = res.data.data; - data[ind]['ord_url']='/packageC/pages/presell/cart/cart'; + data[ind]['ord_url'] = '/packageC/pages/presell/cart/cart'; } }) } @@ -220,8 +235,10 @@ Page({ //------------对比一下有没有退款记录------------ await getApp().request.promiseGet("/api/weshop/order/returngoods/page", { data: { - order_id: item.order_id, store_id: os.stoid, - user_id: oo.user_id, pageSize: 20 + order_id: item.order_id, + store_id: os.stoid, + user_id: oo.user_id, + pageSize: 20 } }).then(rs => { var ttd = rs; @@ -244,8 +261,8 @@ Page({ }); } else { //--------整单退-------- - if (ttd.data.data.pageData[0]['goods_id_list'] != null - && ttd.data.data.pageData[0]['goods_id_list'] != '') { + if (ttd.data.data.pageData[0]['goods_id_list'] != null && + ttd.data.data.pageData[0]['goods_id_list'] != '') { var eea = ttd.data.data.pageData[0]; //1.退款正在进行中, //2.退款被拒绝就要显示可以退款 @@ -284,16 +301,16 @@ Page({ if (eea.goods_id == eeb.goods_id) { switch (eea.status) { case 0: - case 1://退款处理中 + case 1: //退款处理中 data[ind]['has_rt'] = 1; //有部分退 goodslist[iii]['return_btn'] = 2; break; - case 2://退款完成 + case 2: //退款完成 data[ind]['has_rt'] = 1; //有部分退 goodslist[iii]['return_btn'] = 4; rt_ok_num++; break; - case 3://已拒绝,重新退款 + case 3: //已拒绝,重新退款 goodslist[iii]['return_btn'] = 3; break; default: @@ -322,166 +339,175 @@ Page({ }); data[ind]['g_num'] = g_num; }) - th.setData({orderList: data,}); + th.setData({ + orderList: data, + }); }); - e.data.currentPage++ , + e.data.currentPage++, wx.stopPullDownRefresh(); - }, null, {store_id: os.stoid, user_id: oo.user_id}); + }, null, { + store_id: os.stoid, + user_id: oo.user_id + }); }, - //滑倒底部 - onReachBottom: function() { - if(this.data.currentIndex == 0) { - if (s.data.goodsLoadFinishFlag) { - this.setData({ - iscodeall: 1 - }) - } - s.canloadMore() && this.requestOrderList(this.data.activeCategoryId); - } else { - this.request_list({ - store_id: os.stoid, - user_id: oo.user_id, - page: this.data.currentPage2, - }); - } - }, - onPullDownRefresh: function(t) { - // sty取消 - // this.resetData(), this.requestOrderList(this.data.activeCategoryId); - }, - - /*-----------取消订单-----------*/ - cancelOrder: function(t) { - var e = this, - a = t.currentTarget.dataset.id, - th = this; - var is_zsorder = parseFloat(t.currentTarget.dataset.zsorder); - var index = t.currentTarget.dataset.orderindex; - var order = th.data.orderList[index]; - var is_skill = 0; - var order_goods = order.order_goods; - //--判断是不是秒杀-- - order_goods.forEach(function(val, ind) { - if (val.prom_type == 1) { - is_skill = 1; - return false; - } - }) - - wx.showModal({ - title: "是否取消订单?", - success: function(t) { - //如果是秒杀和拼单的商品,取消订单要返回redis,并取消订单 - if (t.confirm) { - //if(is_skill==1 || is_zsorder>=2){ - getApp().request.post("/api/weshop/order/cancelOrder/"+os.stoid+"/"+a+"/"+getApp().globalData.user_id, { - data: {}, - success: function(t) { - if (t.data.code == 0) { - 0 == e.data.activeCategoryId ? - (e.resetData(), e.requestOrderList(e.data.activeCategoryId)) : e.deleteOrderData2(a); - } else { - getApp().confirmBox(e.data.msg); - } - }, - }) + //滑倒底部 + onReachBottom: function () { + if (this.data.currentIndex == 0) { + if (s.data.goodsLoadFinishFlag) { + this.setData({ + iscodeall: 1 + }) + } + s.canloadMore() && this.requestOrderList(this.data.activeCategoryId); + } else { + this.request_list({ + store_id: os.stoid, + user_id: oo.user_id, + page: this.data.currentPage2, + }); } - } - }); - }, - - /*-----------确认收货-----------*/ - confirmOrder: function(t) { - var e = this,a = t.currentTarget.dataset.id; - var is_zsorder = t.currentTarget.dataset.zsorder; - var th = this; - - wx.showModal({ - title: "是否确认收货?", - success: function(t) { - t.confirm && rq.post("/api/weshop/order/confirmOrder/"+os.stoid+"/"+a+"/"+getApp().globalData.user_id,{ - success:function (e) { - if(e.data.code==0){ - th.deleteOrderData2(a); - getApp().confirmBox( "确认收货成功!"); - } + }, + onPullDownRefresh: function (t) { + // sty取消 + // this.resetData(), this.requestOrderList(this.data.activeCategoryId); + }, + + /*-----------取消订单-----------*/ + cancelOrder: function (t) { + var e = this, + a = t.currentTarget.dataset.id, + th = this; + var is_zsorder = parseFloat(t.currentTarget.dataset.zsorder); + var index = t.currentTarget.dataset.orderindex; + var order = th.data.orderList[index]; + var is_skill = 0; + var order_goods = order.order_goods; + //--判断是不是秒杀-- + order_goods.forEach(function (val, ind) { + if (val.prom_type == 1) { + is_skill = 1; + return false; } - }) - } - }); - }, - - //-----删除订单----- - deleteOrderData: function(t) { - var th = this; - var order_id = t.currentTarget.dataset.order_id; - var index = t.currentTarget.dataset.index; - var up_data={order_id: order_id,isdel:1}; - var order=th.data.orderList[index]; - if(order.order_status!=6){ - up_data.order_status=5; - } - wx.showModal({ - title: "是否删除订单?", - success: function(tt) { - tt.confirm && rq.put("/api/weshop/order/updatebyId", { - data: up_data, - success: function(t) { - for (var e = 0; e < th.data.orderList.length; e++) - if (th.data.orderList[e].order_id == order_id) { - th.data.orderList.splice(e, 1), th.setData({ - orderList: th.data.orderList - }); - break; - } - } }) - } - }); - }, - - deleteOrderData2: function(order_id) { - var th = this; - for (var e = 0; e < th.data.orderList.length; e++) - if (th.data.orderList[e].order_id == order_id) { - th.data.orderList.splice(e, 1), th.setData({ - orderList: this.data.orderList + + wx.showModal({ + title: "是否取消订单?", + success: function (t) { + //如果是秒杀和拼单的商品,取消订单要返回redis,并取消订单 + if (t.confirm) { + //if(is_skill==1 || is_zsorder>=2){ + getApp().request.post("/api/weshop/order/cancelOrder/" + os.stoid + "/" + a + "/" + getApp().globalData.user_id, { + data: {}, + success: function (t) { + if (t.data.code == 0) { + 0 == e.data.activeCategoryId ? + (e.resetData(), e.requestOrderList(e.data.activeCategoryId)) : e.deleteOrderData2(a); + } else { + getApp().confirmBox(e.data.msg); + } + }, + }) + } + } }); - break; - } - }, - - //---判断是不是有退款----- - checkReturnGoodsStatus: function(t) { - var e = t.currentTarget.dataset.recid; - var oid = t.currentTarget.dataset.oid; - r.get("/api/weshop/order/returngoods/page", { - data: { - goods_id: e, - order_id: oid, - store_id: os.stoid - }, - success: function(t) { - if (t.data.code == 0) { - var r = t.data.data.total; - if (0 == r) return wx.navigateTo({ - url: "/pages/user/return_goods/return_goods?rec_id=" + e + "&order_id=" + oid, - }); - //--如果拒绝,就重新申请退款-- - if (t.data.data.pageData[0].status == 3) { - return wx.navigateTo({ - url: "/pages/user/return_goods/return_goods?rec_id=" + e + "&order_id=" + oid, - }); - } + }, + + /*-----------确认收货-----------*/ + confirmOrder: function (t) { + var e = this, + a = t.currentTarget.dataset.id; + var is_zsorder = t.currentTarget.dataset.zsorder; + var th = this; - wx.navigateTo({ - url: "/pages/user/return_goods_info/return_goods_info?id=" + r - }); + wx.showModal({ + title: "是否确认收货?", + success: function (t) { + t.confirm && rq.post("/api/weshop/order/confirmOrder/" + os.stoid + "/" + a + "/" + getApp().globalData.user_id, { + success: function (e) { + if (e.data.code == 0) { + th.deleteOrderData2(a); + getApp().confirmBox("确认收货成功!"); + } + } + }) + } + }); + }, + + //-----删除订单----- + deleteOrderData: function (t) { + var th = this; + var order_id = t.currentTarget.dataset.order_id; + var index = t.currentTarget.dataset.index; + var up_data = { + order_id: order_id, + isdel: 1 + }; + var order = th.data.orderList[index]; + if (order.order_status != 6) { + up_data.order_status = 5; } - } - }); - }, + wx.showModal({ + title: "是否删除订单?", + success: function (tt) { + tt.confirm && rq.put("/api/weshop/order/updatebyId", { + data: up_data, + success: function (t) { + for (var e = 0; e < th.data.orderList.length; e++) + if (th.data.orderList[e].order_id == order_id) { + th.data.orderList.splice(e, 1), th.setData({ + orderList: th.data.orderList + }); + break; + } + } + }) + } + }); + }, + + deleteOrderData2: function (order_id) { + var th = this; + for (var e = 0; e < th.data.orderList.length; e++) + if (th.data.orderList[e].order_id == order_id) { + th.data.orderList.splice(e, 1), th.setData({ + orderList: this.data.orderList + }); + break; + } + }, + + //---判断是不是有退款----- + checkReturnGoodsStatus: function (t) { + var e = t.currentTarget.dataset.recid; + var oid = t.currentTarget.dataset.oid; + r.get("/api/weshop/order/returngoods/page", { + data: { + goods_id: e, + order_id: oid, + store_id: os.stoid + }, + success: function (t) { + if (t.data.code == 0) { + var r = t.data.data.total; + if (0 == r) return wx.navigateTo({ + url: "/pages/user/return_goods/return_goods?rec_id=" + e + "&order_id=" + oid, + }); + //--如果拒绝,就重新申请退款-- + if (t.data.data.pageData[0].status == 3) { + return wx.navigateTo({ + url: "/pages/user/return_goods/return_goods?rec_id=" + e + "&order_id=" + oid, + }); + } + + wx.navigateTo({ + url: "/pages/user/return_goods_info/return_goods_info?id=" + r + }); + } + } + }); + }, /*----------跳转支付-----------*/ async jumpToCart4(t) { @@ -490,7 +516,7 @@ Page({ var th = this; var order = e; var order_goods = e.order_goods; - var user_id=getApp().globalData.userInfo.user_id; + var user_id = getApp().globalData.userInfo.user_id; // 幸运购检查库存量 api/weshop/activitylist/getActLen/{store_id}/{prom_type}/{prom_id} if (parseInt(order_goods['0']['prom_type']) == 9) { @@ -522,9 +548,13 @@ Page({ }); return false; } - + //要每件每件的商品进行检查,看有么有超出库存,超出限购 - var good = order_goods[i], goodsbuynum = 0, promgoodsbuynum = 0, gg = null,presellList=null; + var good = order_goods[i], + goodsbuynum = 0, + promgoodsbuynum = 0, + gg = null, + presellList = null; //获取单品的现在的活动状态 await getApp().request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + good.goods_id, {}).then(res => { @@ -619,16 +649,22 @@ Page({ } //如果是预售的时候, - if(good.prom_type==8) { - await getApp().request.promiseGet("/api/weshop/order/orderPresell/countBuyGoodsSum",{ - data: {store_id: os.stoid, user_id: user_id, goods_id: good.goods_id, prom_id: good.prom_id}, - }).then(e=>{ + + if (good.prom_type == 8) { + await getApp().request.promiseGet("/api/weshop/order/orderPresell/countBuyGoodsSum", { + data: { + store_id: os.stoid, + user_id: user_id, + goods_id: good.goods_id, + prom_id: good.prom_id + }, + }).then(e => { if (e.data.code == 0) { - promgoodsbuynum=e.data.data.sumgoodsnum; + promgoodsbuynum = e.data.data.sumgoodsnum; } }) - var presell_id =good.prom_id; + var presell_id = good.prom_id; var url = "/api/weshop/marketing/marketingPresellList/list" var rd = { store_id: os.stoid, @@ -641,13 +677,13 @@ Page({ }).then(res => { if (res.data.code == 0 && res.data.data && res.data.data.length > 0) { var arr = res.data.data[0]; - presellList=arr + presellList = arr } }) - if(presellList){ + if (presellList) { - if(good.goods_num>presellList.presell_sumqty-presellList.buy_goodnum){ + if (good.goods_num > presellList.presell_sumqty - presellList.buy_goodnum) { var content = good.goods_name + '购买数量超出商品库存,请取消订单'; th.toast(content); return false; @@ -733,39 +769,39 @@ Page({ } //商品的普通购买 ,不要进行判断 - if ((good.prom_type == 1 || good.prom_type == 2 || good.prom_type == 6 || good.prom_type == 4 || good.prom_type == 8) - && !good.is_gift && !good.is_collocation && !good.is_integral_normal && !good.is_pd_normal) { - if (gg.prom_type != good.prom_type && gg.prom_type>0) { + if ((good.prom_type == 1 || good.prom_type == 2 || good.prom_type == 6 || good.prom_type == 4 || good.prom_type == 8) && + !good.is_gift && !good.is_collocation && !good.is_integral_normal && !good.is_pd_normal) { + if (gg.prom_type != good.prom_type && gg.prom_type > 0) { var content = gg.goods_name + '商品的活动发生了变化,请取消订单重新购买'; th.toast(content); return false; } - } else { - if ((gg.prom_type == 1 || good.prom_type == 2 || gg.prom_type == 3 || gg.prom_type == 5 || gg.prom_type == 6 || gg.prom_type == 4) - && !good.is_collocation && !good.is_gift && !good.is_integral_normal && !good.is_pd_normal) { - var prom = null; + } else { + if ((gg.prom_type == 1 || gg.prom_type == 2 || gg.prom_type == 3 || gg.prom_type == 4 || gg.prom_type == 5 || gg.prom_type == 6 || gg.prom_type == 10) && + !good.is_collocation && !good.is_gift && !good.is_integral_normal && !good.is_pd_normal) { //---如果是活动的时候--- - var prom = null, th = this; + var prom = null, + th = this; if (gg.prom_type == 1) { - await getApp().request.promiseGet("/api/ms/flash_sale/getNew/" + os.stoid + "/"+ user_id + "/" + gg.prom_id, {}).then(res => { + await getApp().request.promiseGet("/api/ms/flash_sale/getNew/" + os.stoid + "/" + user_id + "/" + gg.prom_id, {}).then(res => { if (res.data.code == 0) { prom = res.data.data; - prom.price=prom.user_price; + prom.price = prom.user_price; } }) } - - if (gg.prom_type == 2) { - await getApp().request.promiseGet("/api/weshop/goods/groupBuy/getActInfo/" + os.stoid + "/"+ gg.goods_id + "/" + gg.prom_id, {}).then(res => { - if (res.data.code == 0) { - prom = res.data.data; - prom.price=prom.price; - } - }) - } - - + + if (gg.prom_type == 2) { + await getApp().request.promiseGet("/api/weshop/goods/groupBuy/getActInfo/" + os.stoid + "/" + gg.goods_id + "/" + gg.prom_id, {}).then(res => { + if (res.data.code == 0) { + prom = res.data.data; + prom.price = prom.price; + } + }) + } + + if (gg.prom_type == 6) { await getApp().request.promiseGet("/api/weshop/teamlist/get/" + os.stoid + "/" + gg.prom_id, {}).then(res => { if (res.data.code == 0) { @@ -776,25 +812,34 @@ Page({ if (gg.prom_type == 4) { await getApp().request.promiseGet("/api/weshop/integralbuy/pageIntegralBuyGoodsList?stype=1&stypeup=1", { - data: {store_id: os.stoid, goods_id: gg.goods_id} + data: { + store_id: os.stoid, + goods_id: gg.goods_id + } }).then(res => { if (res.data.code == 0 && res.data.data && res.data.data.pageData) { prom = res.data.data.pageData[0]; } }) } + if (gg.prom_type == 10) { + var url = `/api/weshop/prom/ladderForm/getNew/${os.stoid}/${user_id}/${gg.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 == 1) { + prom = res.data.data; + } + }) + } if (prom) { var t_now = ut.gettimestamp(); if (prom.is_end == 0 && prom.start_time < t_now && prom.end_time > t_now) { - var content = gg.goods_name + '商品的活动发生了变化,请取消订单重新购买'; th.toast(content); return false; } } - } - else { + } else { if (!good.is_gift && good.prom_type != 3) { var t_ok = 1; await getApp().request.promiseGet("/api/weshop/goods/getGoodsPromList/" + os.stoid + "/" + good.goods_id + "/0", {}).then(res => { @@ -804,6 +849,7 @@ Page({ if (r_data.promGoodsLists) { var content = gg.goods_name + '商品的活动发生了变化,请取消订单重新购买'; th.toast(content); + console.log(3); t_ok = 0; } } @@ -821,7 +867,7 @@ Page({ if (!good.is_gift && !good.is_collocation && gg.prom_type != 9) { if (card_field && gg[card_field] > 0) { if (good.goods_price != gg[card_field] && good.offline_cut <= 0) isok = 0; - if (good.goods_price > gg[card_field] && good.offline_cut > 0) isok = 0; //如果线下价格比较贵,则不通过 + if (good.goods_price > gg[card_field] && good.offline_cut > 0) isok = 0; //如果线下价格比较贵,则不通过 } else { if (good.goods_price != gg.shop_price && good.offline_cut <= 0) isok = 0; @@ -832,6 +878,7 @@ Page({ var content = gg.goods_name + '商品的价格发生了变化,请取消订单重新购买1' th.toast(content); + console.log(4); return false; } } @@ -861,26 +908,28 @@ Page({ } //---如果是活动的时候--- - var prom = null, goodsinfo = good, th = this; + var prom = null, + goodsinfo = good, + th = this; if (goodsinfo.prom_type == 1) { - await getApp().request.promiseGet("/api/ms/flash_sale/getNew/" + os.stoid + "/"+ user_id + "/" + goodsinfo.prom_id, {}).then(res => { + await getApp().request.promiseGet("/api/ms/flash_sale/getNew/" + os.stoid + "/" + user_id + "/" + goodsinfo.prom_id, {}).then(res => { + if (res.data.code == 0) { + prom = res.data.data; + prom.price = prom.user_price; + } + }) + } + + if (goodsinfo.prom_type == 2) { + await getApp().request.promiseGet("/api/weshop/goods/groupBuy/getActInfo/" + os.stoid + "/" + good.goods_id + "/" + goodsinfo.prom_id, {}).then(res => { if (res.data.code == 0) { prom = res.data.data; - prom.price=prom.user_price; + prom.price = prom.price; } }) } - - if (goodsinfo.prom_type == 2) { - await getApp().request.promiseGet("/api/weshop/goods/groupBuy/getActInfo/" + os.stoid + "/"+ good.goods_id + "/" + goodsinfo.prom_id, {}).then(res => { - if (res.data.code == 0) { - prom = res.data.data; - prom.price=prom.price; - } - }) - } - - + + if (goodsinfo.prom_type == 6 && !good.is_pd_normal) { await getApp().request.promiseGet("/api/weshop/teamlist/get/" + os.stoid + "/" + goodsinfo.prom_id, {}).then(res => { if (res.data.code == 0) { @@ -891,7 +940,10 @@ Page({ if (goodsinfo.prom_type == 4 && !good.is_integral_normal) { await getApp().request.promiseGet("/api/weshop/integralbuy/pageIntegralBuyGoodsList?stype=1&stypeup=1", { - data: {store_id: os.stoid, goods_id: goodsinfo.goods_id} + data: { + store_id: os.stoid, + goods_id: goodsinfo.goods_id + } }).then(res => { if (res.data.code == 0 && res.data.data && res.data.data.pageData) { prom = res.data.data.pageData[0]; @@ -917,18 +969,18 @@ Page({ } // --看一下会员的秒杀价格是不是发生了变化,因为会员的身份发生了变化 - if(goodsinfo.prom_type==1 && goodsinfo.goods_price!=prom.price){ - var content=goodsinfo.goods_name+'秒杀活动的价格发生了变化'; + if (goodsinfo.prom_type == 1 && goodsinfo.goods_price != prom.price) { + var content = goodsinfo.goods_name + '秒杀活动的价格发生了变化'; + th.toast(content); + return false; + } + + // --看一下会员的团购价格是不是发生了变化 + if (goodsinfo.prom_type == 2 && goodsinfo.goods_price != prom.price) { + var content = goodsinfo.goods_name + '秒杀活动的价格发生了变化'; th.toast(content); return false; } - - // --看一下会员的团购价格是不是发生了变化 - if(goodsinfo.prom_type==2 && goodsinfo.goods_price!=prom.price){ - var content=goodsinfo.goods_name+'秒杀活动的价格发生了变化'; - th.toast(content); - return false; - } if (goodsinfo.prom_type == 4) { if (good.goods_num > prom.limitqty - prom.buy_num) { @@ -937,12 +989,12 @@ Page({ th.toast(content); return false; } - } else if(goodsinfo.prom_type == 1 || goodsinfo.prom_type == 2 || goodsinfo.prom_type == 6 ) { - if(order.add_time+5*60 { + }, ).then(res => { if (res.data.code == 0 && res.data.data && res.data.data.length > 0) { offarr = res.data.data; } @@ -981,201 +1032,229 @@ Page({ var content = good.goods_name + '商品的价格发生了变化,请取消订单重新购买'; th.toast(content); + console.log(5); return false; } } } th.pay_next(e, o_index); }, - - - pay_next(e,o_index){ - var th=this; - if (e.order_amount == 0) { - var dd = { - parent_sn: e.order_sn, - store_id: e.store_id, - type: 1, - }; - getApp().request.post("/api/weshop/order/pay/createOrder", { - data: dd, - success: function(t) { - if (t.data.code == 0) { - th.onload(); - } else { - getApp().confirmBox(t.data.msg + "请您取消该订单"); - } - } - }) - return false; - } - - /*--- - a.jumpToCart4({ - order_sn: e.order_sn, - order_amount: e.order_amount, - type: 1 //正常单 - });--*/ - - t.pay(e.order_sn, function() { - wx.showToast({title: '支付成功'}) - th.data.orderList.splice(o_index,1); - th.setData({orderList:th.data.orderList}); - },null,os.stoid,1); - - - }, - + + + pay_next(e, o_index) { + var th = this; + if (e.order_amount == 0) { + var dd = { + parent_sn: e.order_sn, + store_id: e.store_id, + type: 1, + }; + getApp().request.post("/api/weshop/order/pay/createOrder", { + data: dd, + success: function (t) { + if (t.data.code == 0) { + th.onload(); + } else { + getApp().confirmBox(t.data.msg + "请您取消该订单"); + } + } + }) + return false; + } + + /*--- + a.jumpToCart4({ + order_sn: e.order_sn, + order_amount: e.order_amount, + type: 1 //正常单 + });--*/ + + t.pay(e.order_sn, function () { + wx.showToast({ + title: '支付成功' + }) + th.data.orderList.splice(o_index, 1); + th.setData({ + orderList: th.data.orderList + }); + }, null, os.stoid, 1); + + + }, + //---检验线下库存的数量的子函数--- - async check_down_line_next(gg,num,pick_id,func){ - - var lock=0,pick_no,plist; - //先读取门店的lock - await getApp().request.promiseGet("/api/weshop/order/ware/lock/page",{ - data:{store_id:os.stoid,wareId:gg.goods_id,storageId:pick_id} - }).then(res=>{ - if(res.data.code==0 && res.data.data.total>0){ - for(var i in res.data.data.pageData) - lock+=res.data.data.pageData[i].outQty; - } - }) - //先获取门店的编号 - await getApp().request.promiseGet("/api/weshop/pickup/get/"+os.stoid+"/"+pick_id,{ - data:{storeId:os.stoid,goodsId:gg.goods_id,pickupId:pick_id} - }).then(res=>{ - if(res.data.code==0){ - pick_no=res.data.data.pickup_no; - } - }) - //读取线下的门店库存 - await getApp().request.promiseGet("/api/weshop/goods/getWareStorages",{ - data:{storageNos:pick_no,wareIds:encodeURIComponent(gg.erpwareid),storeId:os.stoid} - }).then(res=>{ - if(res.data.code==0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length>0){ - plist=res.data.data.pageData[0]; - } - }) - - var ob={}; ob.code=1; - if(!plist){ - ob.code=-1; ob.CanOutQty=0; - func(ob);return false; - } - - if(num>plist.CanOutQty-lock){ - ob.code=-1; - ob.CanOutQty=plist.CanOutQty-lock - if(ob.CanOutQty<0) ob.CanOutQty=0; - } - func(ob) + async check_down_line_next(gg, num, pick_id, func) { + + var lock = 0, + pick_no, plist; + //先读取门店的lock + await getApp().request.promiseGet("/api/weshop/order/ware/lock/page", { + data: { + store_id: os.stoid, + wareId: gg.goods_id, + storageId: pick_id + } + }).then(res => { + if (res.data.code == 0 && res.data.data.total > 0) { + for (var i in res.data.data.pageData) + lock += res.data.data.pageData[i].outQty; + } + }) + //先获取门店的编号 + await getApp().request.promiseGet("/api/weshop/pickup/get/" + os.stoid + "/" + pick_id, { + data: { + storeId: os.stoid, + goodsId: gg.goods_id, + pickupId: pick_id + } + }).then(res => { + if (res.data.code == 0) { + pick_no = res.data.data.pickup_no; + } + }) + //读取线下的门店库存 + await getApp().request.promiseGet("/api/weshop/goods/getWareStorages", { + data: { + storageNos: pick_no, + wareIds: encodeURIComponent(gg.erpwareid), + storeId: os.stoid + } + }).then(res => { + if (res.data.code == 0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length > 0) { + plist = res.data.data.pageData[0]; + } + }) + + var ob = {}; + ob.code = 1; + if (!plist) { + ob.code = -1; + ob.CanOutQty = 0; + func(ob); + return false; + } + + if (num > plist.CanOutQty - lock) { + ob.code = -1; + ob.CanOutQty = plist.CanOutQty - lock + if (ob.CanOutQty < 0) ob.CanOutQty = 0; + } + func(ob) }, - - - - //------图片失败,默认图片--------- - bind_bnerr: function(e) { - var _errImg = e.currentTarget.dataset.errorimg; - var _errObj = {}; - _errObj[_errImg] = "public/images/default_goods_image_240.gif"; - this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; - }, - - //--------跳转到退款详情----------- - gotoreturn: function(t) { - var e = t.currentTarget.dataset.recid; - var oid = t.currentTarget.dataset.oid; - var wh = ""; - if (e != undefined && e != null && e != "") { - wh = "&goods_id=" + e; - } - wx.navigateTo({ - url: "/pages/user/return_goods_info/return_goods_info?order_id=" + oid + wh, - }); - }, - - //-----支付尾款------ - pay_wk: function(ee) { - console.log("pay_wk"); - var order_id = ee.currentTarget.dataset.order_id; - wx.navigateTo({ - url: "/pages/cart/cart_wk/cart_wk?order_id=" + order_id, - }); - - }, - - //--判断是不是可以单个商品退-- - check_for_return_btn: function(item) { - if (item.coupon_no) return false; //有用优惠券 - if (item.order_prom_id) return false; //有订单优惠 - if (item.order_status >= 2) return false; //订单状态>2 - var istrue = true; - //----判断是不是有优惠活动和赠送商品---- - for (var g in item.goodslist) { - var g_item = item.goodslist[g]; - if ((g_item.prom_type == 3 && g_item.discount_amount > 0) || - (g_item.prom_type == 3 && g_item.goods_price <= 0) - ) { - istrue = false; - break - } - if (g_item.prom_type == 5) { - istrue = false; - break - } - } - if (!istrue) return false; - var conf = this.data.conf; - //判断是不是原路退回 - if (conf.refund_type == 1) return true; - else { - if (item.order_amount == 0 || item.user_money == 0) return true; - } - return false; - }, - //跳到首页 - goto: function(e) { - wx.navigateTo({ - url: '/pages/index/index/index', - }) - }, - - //显示核销码 - code_show: function(e) { - var th = this; - //--获取成功的时候-- - var no = e.currentTarget.dataset.order_sn; - var qc_com = th.selectComponent("#qc_com"); //组件的id - var obj = { - val: no, - content: "请将二维码展示给核销员,收货更快捷" - }; - qc_com.open(obj) - }, - - //再来一单的功能的实现 - moreOrder:function(e){ - - if(this.data.moring) return false; - this.data.moring=1; - - var th=this; - var index=e.currentTarget.dataset.index; - var item=th.data.orderList[index]; - th.check_more_order(item); - }, - - - check_more_order:async function(item){ - var pickup=null,th=this; - var user_id=getApp().globalData.user_id; + + + + //------图片失败,默认图片--------- + bind_bnerr: function (e) { + var _errImg = e.currentTarget.dataset.errorimg; + var _errObj = {}; + _errObj[_errImg] = "public/images/default_goods_image_240.gif"; + this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; + }, + + //--------跳转到退款详情----------- + gotoreturn: function (t) { + var e = t.currentTarget.dataset.recid; + var oid = t.currentTarget.dataset.oid; + var wh = ""; + if (e != undefined && e != null && e != "") { + wh = "&goods_id=" + e; + } + wx.navigateTo({ + url: "/pages/user/return_goods_info/return_goods_info?order_id=" + oid + wh, + }); + }, + + //-----支付尾款------ + pay_wk: function (ee) { + console.log("pay_wk"); + var order_id = ee.currentTarget.dataset.order_id; + wx.navigateTo({ + url: "/pages/cart/cart_wk/cart_wk?order_id=" + order_id, + }); + + }, + + //--判断是不是可以单个商品退-- + check_for_return_btn: function (item) { + if (item.coupon_no) return false; //有用优惠券 + if (item.order_prom_id) return false; //有订单优惠 + if (item.order_status >= 2) return false; //订单状态>2 + var istrue = true; + //----判断是不是有优惠活动和赠送商品---- + for (var g in item.goodslist) { + var g_item = item.goodslist[g]; + if ((g_item.prom_type == 3 && g_item.discount_amount > 0) || + (g_item.prom_type == 3 && g_item.goods_price <= 0) + ) { + istrue = false; + break + } + if (g_item.prom_type == 5) { + istrue = false; + break + } + } + if (!istrue) return false; + var conf = this.data.conf; + //判断是不是原路退回 + if (conf.refund_type == 1) return true; + else { + if (item.order_amount == 0 || item.user_money == 0) return true; + } + return false; + }, + //跳到首页 + goto: function (e) { + wx.navigateTo({ + url: '/pages/index/index/index', + }) + }, + + //显示核销码 + code_show: function (e) { + var th = this; + //--获取成功的时候-- + var no = e.currentTarget.dataset.order_sn; + var qc_com = th.selectComponent("#qc_com"); //组件的id + var obj = { + val: no, + content: "请将二维码展示给核销员,收货更快捷" + }; + qc_com.open(obj) + }, + + //再来一单的功能的实现 + moreOrder: function (e) { + + if (this.data.moring) return false; + this.data.moring = 1; + + var th = this; + var index = e.currentTarget.dataset.index; + var item = th.data.orderList[index]; + th.check_more_order(item); + }, + + + check_more_order: async function (item) { + console.log(item, 100000); + var pickup = null, + th = this; + var user_id = getApp().globalData.user_id; wx.showLoading(); //--------获取门店----------- await getApp().request.promiseGet("/api/weshop/pickup/get/" + os.stoid + "/" + item.pickup_id, { +<<<<<<< HEAD }).then(res=>{ if(res.data.code==0){ pickup = res.data.data; } +======= + }).then(res => { + pickup = res.data.data; +>>>>>>> d4b9dbf03fa79fb3ff3c5889f79eea201fb49b74 }) if(!pickup){ wx.hideLoading(); @@ -1199,96 +1278,118 @@ Page({ return false; } //--------获取商品---------- - var goods_list=item.order_goods; + var goods_list = item.order_goods; //--- 返回的内容 --- - var back_goods_arr=[]; - var err_text=""; - for(var i in goods_list){ - var g_item=goods_list[i]; + var back_goods_arr = []; + 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 ){ - err_text+= g_item['goods_name']+"积分购商品不加入购物车\n"; + if (g_item['is_gift']) continue; + if (g_item['prom_type'] == 4) { + err_text += g_item['goods_name'] + "积分购商品不加入购物车\n"; continue; } - if(g_item['prom_type']==5){ - err_text+= g_item['goods_name']+"搭配购商品不加入购物车\n"; + if (g_item['prom_type'] == 5) { + err_text += g_item['goods_name'] + "搭配购商品不加入购物车\n"; continue; } - if(g_item['prom_type']==6 ){ - err_text+= g_item['goods_name']+"拼团商品不加入购物车\n"; + if (g_item['prom_type'] == 6) { + err_text += g_item['goods_name'] + "拼团商品不加入购物车\n"; continue; } //--获取商品-- - var good=null; + var good = null; await getApp().request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + g_item.goods_id, { - }).then(res=>{ - good=res.data.data; - }) + }).then(res => { + good = res.data.data; - if(!good){ - err_text+= g_item['goods_name']+"未找到商品\n"; + }) + //调用接口判断订单优惠, + 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; } if (good.is_on_sale != 1) { - err_text+= g_item['goods_name']+"已经下架\n"; + err_text += g_item['goods_name'] + "已经下架\n"; continue; } var timestamp = ut.gettimestamp(); if (good.on_time > timestamp) { - err_text+= g_item['goods_name']+"还未上架\n"; + err_text += g_item['goods_name'] + "还未上架\n"; continue; } if (good.down_time > 0) { if (good.down_time < timestamp) { - err_text+=g_item['goods_name']+"已经下架\n"; + err_text += g_item['goods_name'] + "已经下架\n"; continue; } } //如果商品的配送方式和门店不匹配 - if(good['distr_type']>0 && pickup['distr_type']>0 && good['distr_type']!=pickup['distr_type'] ){ - err_text+= good['goods_name']+"配送方式不一致\n"; + if (good['distr_type'] > 0 && pickup['distr_type'] > 0 && good['distr_type'] != pickup['distr_type']) { + err_text += good['goods_name'] + "配送方式不一致\n"; continue; } - 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; - b_item.guide_id=g_item.guide_id; - b_item.guide_type=g_item.guide_type; - b_item.pickup_id=item.pickup_id; - b_item.price=good.shop_price; - b_item.goods_sn=good.goods_sn; - b_item.sku=good.sku; - b_item.is_integral_normal=g_item.is_integral_normal; - + var prom = null; + b_item.goods_id = g_item.goods_id; + b_item.goods_name = g_item.goods_name; + b_item.goods_num = g_item.goods_num; + b_item.guide_id = g_item.guide_id; + b_item.guide_type = g_item.guide_type; + b_item.pickup_id = item.pickup_id; + b_item.price = good.shop_price; + b_item.goods_sn = good.goods_sn; + b_item.sku = good.sku; + b_item.is_integral_normal = g_item.is_integral_normal; + console.log(b_item, 'b_item'); //-- 如果会员是等级卡的时候,同时商品也有设置相应的卡价格 -- - var card_field=th.data.card_field; - if(card_field && good[card_field]>0){ - b_item.price=good[card_field]; + var card_field = th.data.card_field; + if (card_field && good[card_field] > 0) { + b_item.price = good[card_field]; } - var url="/api/weshop/activitylist/getGoodActInfo"; - var req_data={ - store_id:g_item.store_id,goodsidlist:g_item.goods_id,is_detail:1 + var url = "/api/weshop/activitylist/getGoodActInfo"; + var req_data = { + store_id: g_item.store_id, + goodsidlist: g_item.goods_id, + is_detail: 1 }; - await getApp().request.promiseGet(url, {data:req_data}).then(res=>{ - if(res.data.code==0){ - var list = res.data.data; - for(let i in list){ - let item=list[i]; - if(item.prom_type==1){ good.prom_type=1; good.prom_id=item.act_id; } - } - } + await getApp().request.promiseGet(url, { + data: req_data + }).then(res => { + if (res.data.code == 0) { + var list = res.data.data; + console.log('list', list); + for (let i in list) { + let item = list[i]; + if (item.prom_type == 1) { + good.prom_type = 1; + good.prom_id = item.act_id; + } + } + } }) - if(!prom) { + if (!prom) { //--判断商品当前的活动情况-- switch (good.prom_type) { case 1: @@ -1298,29 +1399,29 @@ Page({ flash = res.data.data; } }) - //----已经结束----- + //----进行中----- if (flash && flash.is_end == 0 && flash.end_time > timestamp && flash.start_time < timestamp) { prom = flash; prom.price = prom.user_price; b_item.price = prom.user_price; } break; - - case 2: - var group = null; - await getApp().request.promiseGet("/api/weshop/goods/groupBuy/getActInfo/" + os.stoid + "/" + good.goods_id + "/" + good.prom_id, {}).then(res => { - if (res.data.code == 0) { - group = res.data.data; - } - }) - //----已经结束----- - if (group && group.is_end == 0 && group.end_time > timestamp && group.start_time < timestamp) { - prom = group; - prom.price = prom.price; - b_item.price = prom.price; - } - break; - + + case 2: + var group = null; + await getApp().request.promiseGet("/api/weshop/goods/groupBuy/getActInfo/" + os.stoid + "/" + good.goods_id + "/" + good.prom_id, {}).then(res => { + if (res.data.code == 0) { + group = res.data.data; + } + }) + //----进行中----- + if (group && group.is_end == 0 && group.end_time > timestamp && group.start_time < timestamp) { + prom = group; + prom.price = prom.price; + b_item.price = prom.price; + } + break; + case 6: b_item.is_pd_normal = 1; break; @@ -1329,23 +1430,32 @@ Page({ 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 + 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 = b_item.prom_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; + } + }) } } //如果有优惠促销的时候,要看下商品的优惠活动有没有过期 +<<<<<<< HEAD if(g_item.prom_type==3 || good.prom_type==3){ var is_g_prom=0; //因为有全场优惠活动,商品参加的活动还未开始 @@ -1361,6 +1471,15 @@ Page({ is_g_prom=1; break; } } +======= + if (g_item.prom_type == 3 || good.prom_type == 3) { + await getApp().request.promiseGet("/api/weshop/goods/getGoodsPromList/" + os.stoid + "/" + good.goods_id + "/1", {}).then(res => { + if (res.data.code == 0) { + var r_data = res.data.data; + if (r_data.promGoodsLists) { + b_item.prom_type = 3; + b_item.prom_id = r_data.promGoodsLists[0].prom_id; +>>>>>>> d4b9dbf03fa79fb3ff3c5889f79eea201fb49b74 } }) if(is_g_prom) { @@ -1389,34 +1508,41 @@ Page({ //判断是不是线下库存的购买, 是不是秒杀活动 - if(th.data.sales_rules==2 && !prom){ + if (th.data.sales_rules == 2 && !prom) { //-- 看一下购物车上有多少商品 -- - var cart_num=0; + var cart_num = 0; await getApp().request.promiseGet("/api/weshop/cart/page", { data: { store_id: os.stoid, user_id: getApp().globalData.user_id, - state:0, is_gift:0, - goods_id:good.goods_id, + state: 0, + is_gift: 0, + goods_id: good.goods_id, pick_id: b_item.pickup_id } - }).then(res=>{ + }).then(res => { var num = 0; - if(res.data.code==0 && res.data.data && res.data.data.pageData) { + if (res.data.code == 0 && res.data.data && res.data.data.pageData) { for (var i = 0; i < res.data.data.pageData.length; i++) { num += res.data.data.pageData[i].goods_num; } } - cart_num=num; + cart_num = num; }) - var lock=0,plist=null; + var lock = 0, + plist = null; - if(b_item.prom_type!=7) { + if (b_item.prom_type != 7) { //先读取门店的lock, await getApp().request.promiseGet("/api/weshop/order/ware/lock/page", { - data: {store_id: os.stoid, wareId: good.goods_id, storageId: b_item.pickup_id, pageSize: 1000} + data: { + store_id: os.stoid, + wareId: good.goods_id, + storageId: b_item.pickup_id, + pageSize: 1000 + } }).then(res => { if (res.data.code == 0 && res.data.data.total > 0) { for (var i in res.data.data.pageData) @@ -1449,100 +1575,101 @@ Page({ b_item.goods_num = plist.CanOutQty - lock; } } - var req_data={ + var req_data = { store_id: os.stoid, user_id: getApp().globalData.user_id, goods_id: good.goods_id, }; - if(b_item.prom_type==7){ - req_data.prom_type=7; - req_data.prom_id=b_item.prom_id; + if (b_item.prom_type == 7) { + req_data.prom_type = 7; + req_data.prom_id = b_item.prom_id; } - var buynum=0; - var promnum=0; + var buynum = 0; + var promnum = 0; //---要获得商品,该用户买了多少件,同步应用--- await getApp().request.promiseGet("/api/weshop/ordergoods/getUserBuyGoodsNum", { data: req_data, }).then(res => { - if(res.data.code==0){ + if (res.data.code == 0) { var buy_num_data = res.data.data; buynum = buy_num_data.goodsbuynum; - if(buy_num_data.promgoodsbuynum){ - promnum=buy_num_data.promgoodsbuynum; + if (buy_num_data.promgoodsbuynum) { + promnum = buy_num_data.promgoodsbuynum; } } }) //---- 要计算商品的限购 ----- - if(good['viplimited']>0){ - if(cart_num+buynum>good['viplimited']){ - err_text+= good['goods_name']+"超出限购\n"; + if (good['viplimited'] > 0) { + if (cart_num + buynum > good['viplimited']) { + err_text += good['goods_name'] + "超出限购\n"; continue; } - good['viplimited']-=(cart_num+buynum); - if(b_item.goods_num>good['viplimited']){ - b_item.goods_num=good['viplimited']; + good['viplimited'] -= (cart_num + buynum); + if (b_item.goods_num > good['viplimited']) { + b_item.goods_num = good['viplimited']; } } //不需要计算组合购的限购 - back_goods_arr.push(b_item); //返回商品元素 + back_goods_arr.push(b_item); //返回商品元素 - }else{ + } else { //-- 看一下购物车上有多少商品 -- - var cart_num=0; + var cart_num = 0; await getApp().request.promiseGet("/api/weshop/cart/page", { data: { store_id: os.stoid, user_id: getApp().globalData.user_id, - state:0, is_gift:0, - goods_id:good.goods_id + state: 0, + is_gift: 0, + goods_id: good.goods_id } - }).then(res=>{ + }).then(res => { var num = 0; - if(res.data.code==0 && res.data.data && res.data.data.pageData) { + if (res.data.code == 0 && res.data.data && res.data.data.pageData) { for (var i = 0; i < res.data.data.pageData.length; i++) { num += res.data.data.pageData[i].goods_num; } } - cart_num=num; + cart_num = num; }) - if(good.store_count<=0){ - err_text+= good['goods_name']+"库存不足\n"; + if (good.store_count <= 0) { + err_text += good['goods_name'] + "库存不足\n"; continue; } - if(b_item.goods_num>good.store_count) - b_item.goods_num=good.store_count; + if (b_item.goods_num > good.store_count) + b_item.goods_num = good.store_count; - var buynum=0; //商品已经购买多少件 - var promgoodsbuynum=0; //活动已经购买多少件 - var redis_num = 0; //redis库存 + var buynum = 0; //商品已经购买多少件 + var promgoodsbuynum = 0; //活动已经购买多少件 + var redis_num = 0; //redis库存 - var req_data={ + var req_data = { store_id: os.stoid, user_id: getApp().globalData.user_id, goods_id: good.goods_id, }; - if(prom){ - req_data.prom_type= good.prom_type; - req_data.prom_id= good.prom_id; - b_item.prom_type=good.prom_type; - b_item.prom_id=good.prom_id; + if (prom) { + req_data.prom_type = good.prom_type; + req_data.prom_id = good.prom_id; + b_item.prom_type = good.prom_type; + b_item.prom_id = good.prom_id; //------判断活动是否抢光----- await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + good.prom_type + "/" + good.prom_id, { - 1: 1 - }).then(res => { + 1: 1 + }).then(res => { redis_num = res.data.data; }); - if(redis_num<=0){ - err_text+= good['goods_name']+"活动不足\n"; + if (redis_num <= 0) { + err_text += good['goods_name'] + "活动不足\n"; continue; } @@ -1552,7 +1679,7 @@ Page({ await getApp().request.promiseGet("/api/weshop/ordergoods/getUserBuyGoodsNum", { data: req_data, }).then(res => { - if(res.data.code==0){ + if (res.data.code == 0) { var buy_num_data = res.data.data; if (buy_num_data.promgoodsbuynum) promgoodsbuynum = buy_num_data.promgoodsbuynum; buynum = buy_num_data.goodsbuynum; @@ -1560,20 +1687,20 @@ Page({ }) //---- 要计算商品的限购 ----- - if(good['viplimited']>0){ - if(cart_num+buynum>good['viplimited']){ - err_text+= good['goods_name']+"超出限购\n"; + if (good['viplimited'] > 0) { + if (cart_num + buynum > good['viplimited']) { + err_text += good['goods_name'] + "超出限购\n"; continue; } - good['viplimited']-=(cart_num+buynum); - if(b_item.goods_num>good['viplimited']){ - b_item.goods_num=good['viplimited']; + good['viplimited'] -= (cart_num + buynum); + if (b_item.goods_num > good['viplimited']) { + b_item.goods_num = good['viplimited']; } } //-- 判断活动的库存 -- - if(prom) { + if (prom) { if (prom['goods_num'] <= prom['buy_num']) { err_text += good['goods_name'] + "超出活动库存\n"; continue; @@ -1598,367 +1725,378 @@ Page({ } } } - - - back_goods_arr.push(b_item); //返回商品元素 + back_goods_arr.push(b_item); //返回商品元素 } } //有重新购买的数据是时候,就要重新生成订单 - if(back_goods_arr.length>0){ - th.setData({back_goods_arr:back_goods_arr}); - if(!err_text){ + if (back_goods_arr.length > 0) { + th.setData({ + back_goods_arr: back_goods_arr + }); + if (!err_text) { th.more_add_cart(); - }else{ + } else { wx.hideLoading(); // 如果没有获取用户信息 wx.showModal({ - title:'确定', - content: err_text+',确定要买其他商品码?', + title: '确定', + content: err_text + ',确定要买其他商品吗?', success(res) { if (res.confirm) { //跳转到登录页 th.more_add_cart(); - }else{ - th.data.moring=0; + } else { + th.data.moring = 0; wx.hideLoading(); } - },fail(){ - th.data.moring=0; + }, + fail() { + th.data.moring = 0; wx.hideLoading(); } }); } - }else{ - th.data.moring=0; + } else { + th.data.moring = 0; wx.hideLoading(); getApp().confirmBox(err_text); } }, - - more_add_cart:async function(){ - var back_goods_arr=this.data.back_goods_arr; - var err_text=""; - var ok_num=0; - - for(var i in back_goods_arr){ - //商品ID - var g_item=back_goods_arr[i]; - var newd = { - goods_id: g_item.goods_id, - goods_num: g_item.goods_num, - pick_id: g_item.pickup_id, - user_id: oo.user_id, - store_id: os.stoid, - goods_price: g_item.price, - member_goods_price: g_item.price, - goods_name: g_item.goods_name, - goods_sn: g_item.goods_sn, - sku: g_item.sku, - }; - - if(g_item.guide_id){ - newd['guide_id']=g_item.guide_id; - newd['guide_type']=g_item.guide_type; - } - - if(g_item.is_integral_normal){ - newd['is_integral_normal']=g_item.is_integral_normal; - } - if(g_item.is_pd_normal){ - newd['is_pd_normal']=g_item.is_pd_normal; - } - - if(g_item.prom_type){ - newd['prom_type']=g_item.prom_type; - newd['prom_id']=g_item.prom_id; - } - - - var b_cart_goods=null; - await getApp().request.promiseGet("/api/weshop/cart/page", { - data: { - store_id: os.stoid, - user_id: oo.user_id, - goods_id: g_item.goods_id, - pick_id: g_item.pickup_id, - }, - }).then(res=>{ - //-------如果购物车中有相关的数据------- - if (res.data.data.total > 0) { - b_cart_goods= res.data.data.pageData[0]; - } - }) - - //-- 如果就加入过购物车 -- - if(b_cart_goods){ - var updata = { - id: b_cart_goods.id, - goods_num: newd.goods_num + b_cart_goods.goods_num, - goods_price: newd.goods_price, - member_goods_price:newd.goods_price, - store_id: os.stoid, - }; - if(newd.guide_id){ - updata.guide_id=newd.guide_id; - updata.guide_type=newd.guide_type; - } - if(newd.prom_type){ - updata.prom_type=newd.prom_type; - updata.prom_id=newd.prom_id; - } - - await getApp().request.promisePut("/api/weshop/cart/update", { - data: updata - }).then(res=>{ - if(res.data.code==0) { - ok_num++; - }else{ - err_text+=newd.goods_name+"加入购物车失败\n"; - } - }) - - }else{ - await getApp().request.promisePost("/api/weshop/cart/save", { - data: newd - }).then(res=>{ - if(res.data.code==0) { - ok_num++; - }else{ - err_text+=newd.goods_name+"加入购物车失败\n"; - } - }) - } - } - wx.hideLoading(); - this.data.moring=0; - if(ok_num==0){ - //-- 如果没有获取用户信息 -- - wx.showModal({ - title:'提示', - content: err_text, - success(res) {} - }); - }else{ - if(err_text==""){ - getApp().goto("/pages/cart/cart/cart"); - }else{ - // 如果没有获取用户信息 - wx.showModal({ - title:'提示', - content: err_text, - success(res) { - if (res.confirm) { - //跳转到登录页 - getApp().goto("/pages/cart/cart/cart"); - } - } - }); - - } - } - }, - - request_list: function(data, callback){ - // console.log('进入request_list'); - - var th = this; - if(this.data.is_load2) return false; //-- 正在加载 - if(this.data.is_no_data2) return false; //-- 没有数据 - if(this.data.is_no_more2) return false; //-- 没有更多 - - // 开启加载状态 - this.data.is_load2=1; - - // var req_data = { - // page:th.data.currentPage2 - // } - - app.request.promiseGet("/api/weshop/order/pagePosOrder", { - data: data - }).then(res=>{ - // 关闭加载状态 - th.data.is_load2=0; - // 请求成功 - if(res.data.code==0) { - if(res.data.data.pageData.length>0) { - th.data.currentPage2++; - var data = res.data.data.pageData; - // 判断有无更多数据可以加载,如果大于则没有更多数据,反之则有 - if(res.data.data.page*res.data.data.pageSize > res.data.data.total){th.setData({is_no_more2:1});} - var list=th.data.list2; - list=list.concat(data); - th.setData({list2:list}); - } else { - if(th.data.currentPage2==1){ - th.setData({is_no_data2:1}); - } else { - th.setData({is_no_more2:1}); - } - } - if(callback) callback(res); - } else { - wx.showToast({ - title: res.data.msg, - icon: 'none', - duration: 2000 - }) - } - }) - }, - - - onClickTab(e) { - let currentIndex = e.target.dataset.index; - this.setData({ - currentIndex: currentIndex - }); - console.log(this.data.currentIndex); - this.setData({ - is_no_data2: 0, - is_no_more2: 0, - currentPage2: 1, - }); - if(currentIndex == 0) { - console.log('线上订单'); - /*--- - this.setData({ - startDate: '选择开始时间', - endDate: '选择结束时间', - });--*/ - } else if(currentIndex == 1) { - console.log('线下订单'); - this.request_list({ - store_id: os.stoid, - user_id: oo.user_id, - page: 1, - BeginDate: this.data.startDate, - EndDate: this.data.endDate - }); - }; - }, - - bindDateChange1: function(e) { - console.log('picker发送选择改变,携带值为', e.detail.value) - this.setData({ - startDate: e.detail.value - }) - }, - - bindDateChange2: function(e) { - console.log('picker发送选择改变,携带值为', e.detail.value) - this.setData({ - endDate: e.detail.value - }) - }, - - bindInput(e) { - this.data.searchContent = e.detail.value; - }, - - searchOnline() { - console.log('online',this.data.searchContent); - if(this.data.searchContent) { - console.log(this.data.searchContent); - this.resetData(), this.requestOrderList(this.data.activeCategoryId); - } else { - wx.showToast({ - title: '您还没有输入搜索内容~', - icon: 'none', - }) - }; - }, - - searchOffline() { - console.log('执行查询'); - let th = this; - let startDate = this.data.startDate; - let endDate = this.data.endDate; - - // this.data.is_no_data2 = 0; - this.setData({ - currentPage2: 1, - list2: [], - is_no_data2: 0, - }); - - - if(startDate == '选择开始时间' || endDate == '选择结束时间') { - wx.showToast({ - title: '请选择完整的查询时间~', - icon: 'none', - }) - }; - - if(new Date(startDate) > new Date(endDate)) { - wx.showToast({ - title: '不对噢!开始时间不能晚于结束时间~', - icon: 'none', - }) - return; - }; - - - this.request_list({ - store_id: os.stoid, - user_id: oo.user_id, - page: 1, - BeginDate: this.data.startDate, - EndDate: this.data.endDate - }, function(res) { - if(res.data.data.total == 0) { - wx.showToast({ - title: '没有找到相关订单', - icon: 'none', - duration: 2000 - }) - } else { - th.setData({ - total: res.data.data.total - }); - } - }); - }, - - currentDate() { - var now = new Date(); - var year = now.getFullYear(); //年 - var month = now.getMonth() + 1; //月 - var day = now.getDate(); //日 - - var clock = year + "-"; - - if(month < 10) month += "0"; - clock += month + "-"; - - if(day < 10) day += "0"; - clock += day; - - // if(hh < 10) - // clock += "0"; - - // clock += hh + ":"; - // if (mm < 10) clock += '0'; - // clock += mm + ":"; - - // if (ss < 10) clock += '0'; - // clock += ss; - return clock; - }, - - toast(msg){ - wx.showToast({ - title: msg, - icon: 'none', - duration: 3000 - }) - }, - - go_url(e){ - var url=e.currentTarget.dataset.url; - getApp().goto(url); + + more_add_cart: async function () { + var back_goods_arr = this.data.back_goods_arr; + var err_text = ""; + var ok_num = 0; + + for (var i in back_goods_arr) { + //商品ID + var g_item = back_goods_arr[i]; + console.log(g_item, 'g_item'); + var newd = { + goods_id: g_item.goods_id, + goods_num: g_item.goods_num, + pick_id: g_item.pickup_id, + user_id: oo.user_id, + store_id: os.stoid, + goods_price: g_item.price, + member_goods_price: g_item.price, + goods_name: g_item.goods_name, + goods_sn: g_item.goods_sn, + sku: g_item.sku, + }; + + if (g_item.guide_id) { + newd['guide_id'] = g_item.guide_id; + newd['guide_type'] = g_item.guide_type; + } + + if (g_item.is_integral_normal) { + newd['is_integral_normal'] = g_item.is_integral_normal; + } + if (g_item.is_pd_normal) { + newd['is_pd_normal'] = g_item.is_pd_normal; + } + if (g_item.prom_type) { + newd['prom_type'] = g_item.prom_type; + newd['prom_id'] = g_item.prom_id; + } + + + var b_cart_goods = null; + await getApp().request.promiseGet("/api/weshop/cart/page", { + data: { + store_id: os.stoid, + user_id: oo.user_id, + goods_id: g_item.goods_id, + pick_id: g_item.pickup_id, + }, + }).then(res => { + //-------如果购物车中有相关的数据------- + if (res.data.data.total > 0) { + b_cart_goods = res.data.data.pageData[0]; + } + }) + + //-- 如果就加入过购物车 -- + if (b_cart_goods) { + var updata = { + id: b_cart_goods.id, + goods_num: newd.goods_num + b_cart_goods.goods_num, + goods_price: newd.goods_price, + member_goods_price: newd.goods_price, + store_id: os.stoid, + }; + if (newd.guide_id) { + updata.guide_id = newd.guide_id; + updata.guide_type = newd.guide_type; + } + if (newd.prom_type) { + updata.prom_type = newd.prom_type; + updata.prom_id = newd.prom_id; + } + + await getApp().request.promisePut("/api/weshop/cart/update", { + data: updata + }).then(res => { + if (res.data.code == 0) { + ok_num++; + } else { + err_text += newd.goods_name + "加入购物车失败\n"; + } + }) + + } else { + await getApp().request.promisePost("/api/weshop/cart/save", { + data: newd + }).then(res => { + if (res.data.code == 0) { + ok_num++; + } else { + err_text += newd.goods_name + "加入购物车失败\n"; + } + }) + } + } + wx.hideLoading(); + this.data.moring = 0; + if (ok_num == 0) { + //-- 如果没有获取用户信息 -- + wx.showModal({ + title: '提示', + content: err_text, + success(res) {} + }); + } else { + if (err_text == "") { + getApp().goto("/pages/cart/cart/cart"); + } else { + // 如果没有获取用户信息 + wx.showModal({ + title: '提示', + content: err_text, + success(res) { + if (res.confirm) { + //跳转到登录页 + getApp().goto("/pages/cart/cart/cart"); + } + } + }); + + } + } + }, + + request_list: function (data, callback) { + // console.log('进入request_list'); + + var th = this; + if (this.data.is_load2) return false; //-- 正在加载 + if (this.data.is_no_data2) return false; //-- 没有数据 + if (this.data.is_no_more2) return false; //-- 没有更多 + + // 开启加载状态 + this.data.is_load2 = 1; + + // var req_data = { + // page:th.data.currentPage2 + // } + + app.request.promiseGet("/api/weshop/order/pagePosOrder", { + data: data + }).then(res => { + // 关闭加载状态 + th.data.is_load2 = 0; + // 请求成功 + if (res.data.code == 0) { + if (res.data.data.pageData.length > 0) { + th.data.currentPage2++; + var data = res.data.data.pageData; + // 判断有无更多数据可以加载,如果大于则没有更多数据,反之则有 + if (res.data.data.page * res.data.data.pageSize > res.data.data.total) { + th.setData({ + is_no_more2: 1 + }); + } + var list = th.data.list2; + list = list.concat(data); + th.setData({ + list2: list + }); + } else { + if (th.data.currentPage2 == 1) { + th.setData({ + is_no_data2: 1 + }); + } else { + th.setData({ + is_no_more2: 1 + }); + } + } + if (callback) callback(res); + } else { + wx.showToast({ + title: res.data.msg, + icon: 'none', + duration: 2000 + }) + } + }) + }, + + + onClickTab(e) { + let currentIndex = e.target.dataset.index; + this.setData({ + currentIndex: currentIndex + }); + console.log(this.data.currentIndex); + this.setData({ + is_no_data2: 0, + is_no_more2: 0, + currentPage2: 1, + }); + if (currentIndex == 0) { + console.log('线上订单'); + /*--- + this.setData({ + startDate: '选择开始时间', + endDate: '选择结束时间', + });--*/ + } else if (currentIndex == 1) { + console.log('线下订单'); + this.request_list({ + store_id: os.stoid, + user_id: oo.user_id, + page: 1, + BeginDate: this.data.startDate, + EndDate: this.data.endDate + }); + }; + }, + + bindDateChange1: function (e) { + console.log('picker发送选择改变,携带值为', e.detail.value) + this.setData({ + startDate: e.detail.value + }) + }, + + bindDateChange2: function (e) { + console.log('picker发送选择改变,携带值为', e.detail.value) + this.setData({ + endDate: e.detail.value + }) + }, + + bindInput(e) { + this.data.searchContent = e.detail.value; + }, + + searchOnline() { + console.log('online', this.data.searchContent); + if (this.data.searchContent) { + console.log(this.data.searchContent); + this.resetData(), this.requestOrderList(this.data.activeCategoryId); + } else { + wx.showToast({ + title: '您还没有输入搜索内容~', + icon: 'none', + }) + }; + }, + + searchOffline() { + console.log('执行查询'); + let th = this; + let startDate = this.data.startDate; + let endDate = this.data.endDate; + + // this.data.is_no_data2 = 0; + this.setData({ + currentPage2: 1, + list2: [], + is_no_data2: 0, + }); + + + if (startDate == '选择开始时间' || endDate == '选择结束时间') { + wx.showToast({ + title: '请选择完整的查询时间~', + icon: 'none', + }) + }; + + if (new Date(startDate) > new Date(endDate)) { + wx.showToast({ + title: '不对噢!开始时间不能晚于结束时间~', + icon: 'none', + }) + return; + }; + + + this.request_list({ + store_id: os.stoid, + user_id: oo.user_id, + page: 1, + BeginDate: this.data.startDate, + EndDate: this.data.endDate + }, function (res) { + if (res.data.data.total == 0) { + wx.showToast({ + title: '没有找到相关订单', + icon: 'none', + duration: 2000 + }) + } else { + th.setData({ + total: res.data.data.total + }); + } + }); + }, + + currentDate() { + var now = new Date(); + var year = now.getFullYear(); //年 + var month = now.getMonth() + 1; //月 + var day = now.getDate(); //日 + + var clock = year + "-"; + + if (month < 10) month += "0"; + clock += month + "-"; + + if (day < 10) day += "0"; + clock += day; + + // if(hh < 10) + // clock += "0"; + + // clock += hh + ":"; + // if (mm < 10) clock += '0'; + // clock += mm + ":"; + + // if (ss < 10) clock += '0'; + // clock += ss; + return clock; + }, + + toast(msg) { + wx.showToast({ + title: msg, + icon: 'none', + duration: 3000 + }) + }, + + go_url(e) { + var url = e.currentTarget.dataset.url; + getApp().goto(url); } - - + + }); \ No newline at end of file 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=""; - } - } }