diff --git a/pages/user/order_list/order_list.js b/pages/user/order_list/order_list.js index 9e486d4..2e08783 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,22 +200,23 @@ 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'; } }) } //------------对比一下有没有退款记录------------ 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; @@ -222,8 +239,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.退款被拒绝就要显示可以退款 @@ -262,16 +279,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: @@ -300,166 +317,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, + }); + } + }, + 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); + } + }, + }) + } + } + }); + }, + + /*-----------确认收货-----------*/ + 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("确认收货成功!"); + } + } + }) + } + }); + }, + + //-----删除订单----- + 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; } - } - }); - }, - - /*-----------确认收货-----------*/ - 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( "确认收货成功!"); - } + 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; + } + } + }) } - }) - } - }); - }, - - //-----删除订单----- - 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) { + }); + }, + + 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: th.data.orderList + orderList: this.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 - }); - } - } - }); - }, + //---判断是不是有退款----- + 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) { var o_index = t.currentTarget.dataset.idx; @@ -467,7 +493,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; var wlist = ""; for (var i in order_goods) { @@ -480,9 +506,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 => { @@ -577,16 +607,21 @@ 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, @@ -599,13 +634,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; @@ -652,38 +687,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 || 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) { + 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; + } + }) + } + + 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.user_price; + 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) { @@ -694,7 +730,10 @@ 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]; @@ -702,9 +741,9 @@ Page({ }) } if (gg.prom_type == 10) { - var url=`/api/weshop/prom/ladderForm/getNew/${os.stoid}/${user_id}/${gg.prom_id}`; + 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) { + if (res.data.code == 0 && res.data.data && !res.data.data.isuse || res.data.data.is_end == 1) { prom = res.data.data; } }) @@ -718,8 +757,7 @@ Page({ 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 => { @@ -747,7 +785,7 @@ Page({ if (!good.is_gift && !good.is_collocation) { 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; @@ -788,26 +826,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; + 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.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) { @@ -818,7 +858,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]; @@ -844,18 +887,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) { @@ -864,12 +907,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; } @@ -915,288 +957,332 @@ Page({ } 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){ - console.log(item,100000); - 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, { - }).then(res=>{ + }).then(res => { pickup = res.data.data; }) //--------获取商品---------- - 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; - 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; } - } - } + 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: @@ -1213,22 +1299,22 @@ Page({ 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; @@ -1237,9 +1323,9 @@ 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; @@ -1250,10 +1336,10 @@ Page({ }) break; case 10: - let user_id=getApp().globalData.userInfo.user_id; - var url=`/api/weshop/prom/ladderForm/getNew/${os.stoid}/${user_id}/${good.prom_id}`; - await getApp().request.promiseGet(url,{}).then(res=>{ - if(res.data.code==0 && res.data.data && res.data.data.isuse && res.data.data.is_end==0){ + 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; } @@ -1262,13 +1348,13 @@ Page({ } //如果有优惠促销的时候,要看下商品的优惠活动有没有过期 - if(g_item.prom_type==3 || good.prom_type==3){ + 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; + b_item.prom_type = 3; + b_item.prom_id = r_data.promGoodsLists[0].prom_id; } } }) @@ -1276,34 +1362,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) @@ -1336,100 +1429,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; } @@ -1439,7 +1533,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; @@ -1447,20 +1541,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; @@ -1485,367 +1579,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