Commit 886dff492207e70b23eee711507cae9670ee113d
1 parent
4599ce51
积分购预存使用
Showing
2 changed files
with
273 additions
and
36 deletions
packageE/pages/cart/cart2/cart2.js
| ... | ... | @@ -2702,7 +2702,7 @@ Page({ |
| 2702 | 2702 | var quan_no = null; |
| 2703 | 2703 | if (th.data.using_quan[bn_pick] != null && th.data.using_quan[bn_pick] != undefined) |
| 2704 | 2704 | quan_no = th.data.using_quan[bn_pick].coupon_no; |
| 2705 | - | |
| 2705 | + | |
| 2706 | 2706 | if (quan_no) { |
| 2707 | 2707 | //如果是一件代发就不要找商品 |
| 2708 | 2708 | if (th.data.using_quan[bn_pick].isby != 1 && !good.whsle_id) { |
| ... | ... | @@ -2715,6 +2715,7 @@ Page({ |
| 2715 | 2715 | WareIds: th.data.check_quan_ware_list |
| 2716 | 2716 | } |
| 2717 | 2717 | }).then(res => { |
| 2718 | + | |
| 2718 | 2719 | if (res.data.code == 0 && res.data.data && res.data.data.length > 0) { |
| 2719 | 2720 | quan_price = res.data.data[0].WareCashSum; |
| 2720 | 2721 | } |
| ... | ... | @@ -4114,21 +4115,24 @@ Page({ |
| 4114 | 4115 | util_pay.pay(data.data, async function () { |
| 4115 | 4116 | //app.my_warnning("支付成功",1,th); |
| 4116 | 4117 | //setTimeout(function () { |
| 4117 | - if (th.data.formData && th.data.formData.prestore * 1 > 0) { //有使用预存的处理 | |
| 4118 | - let length = pdata.length | |
| 4119 | - wx.showLoading({ title: "加载中", mask: true }); | |
| 4120 | - for (let yi = 0; yi < length; yi++) { | |
| 4121 | - await th.setAdvancesum(pdata[yi], data.data) | |
| 4122 | - } | |
| 4123 | - wx.hideLoading() | |
| 4124 | - wx.redirectTo({ | |
| 4125 | - url: "/pages/payment/pay_success/pay_success?type=2&order_sn=" + data.data | |
| 4126 | - }) | |
| 4127 | - } else { | |
| 4128 | - wx.redirectTo({ | |
| 4129 | - url: "/pages/payment/pay_success/pay_success?type=2&order_sn=" + data.data | |
| 4130 | - }) | |
| 4131 | - } | |
| 4118 | + // if (th.data.formData && th.data.formData.prestore * 1 > 0) { //有使用预存的处理 | |
| 4119 | + // let length = pdata.length | |
| 4120 | + // wx.showLoading({ title: "加载中", mask: true }); | |
| 4121 | + // for (let yi = 0; yi < length; yi++) { | |
| 4122 | + // await th.setAdvancesum(pdata[yi], data.data) | |
| 4123 | + // } | |
| 4124 | + // wx.hideLoading() | |
| 4125 | + // wx.redirectTo({ | |
| 4126 | + // url: "/pages/payment/pay_success/pay_success?type=2&order_sn=" + data.data | |
| 4127 | + // }) | |
| 4128 | + // } else { | |
| 4129 | + // wx.redirectTo({ | |
| 4130 | + // url: "/pages/payment/pay_success/pay_success?type=2&order_sn=" + data.data | |
| 4131 | + // }) | |
| 4132 | + // } | |
| 4133 | + wx.redirectTo({ | |
| 4134 | + url: "/pages/payment/pay_success/pay_success?type=2&order_sn=" + data.data | |
| 4135 | + }) | |
| 4132 | 4136 | //},1000) |
| 4133 | 4137 | |
| 4134 | 4138 | }, function () { |
| ... | ... | @@ -4160,24 +4164,27 @@ Page({ |
| 4160 | 4164 | if (t.data.code == 0) { |
| 4161 | 4165 | //app.my_warnning("支付成功",1,th); |
| 4162 | 4166 | //setTimeout(function () { |
| 4163 | - if (th.data.formData && th.data.formData.prestore * 1 > 0) { //有使用预存的处理 | |
| 4164 | - let length = pdata.length | |
| 4165 | - wx.showLoading({ title: "加载中", mask: true }); | |
| 4166 | - for (let yi = 0; yi < length; yi++) { | |
| 4167 | - await th.setAdvancesum(pdata[yi], data.data) | |
| 4168 | - } | |
| 4169 | - wx.hideLoading() | |
| 4170 | - th.setData({ isclose: 0 }); | |
| 4171 | - wx.redirectTo({ | |
| 4172 | - url: "/pages/payment/pay_success/pay_success?type=2&order_sn=" + data.data, | |
| 4173 | - }) | |
| 4174 | - } else { | |
| 4175 | - th.setData({ isclose: 0 }); | |
| 4176 | - wx.redirectTo({ | |
| 4177 | - url: "/pages/payment/pay_success/pay_success?type=2&order_sn=" + data.data, | |
| 4178 | - }) | |
| 4179 | - } | |
| 4180 | - | |
| 4167 | + // if (th.data.formData && th.data.formData.prestore * 1 > 0) { //有使用预存的处理 | |
| 4168 | + // let length = pdata.length | |
| 4169 | + // wx.showLoading({ title: "加载中", mask: true }); | |
| 4170 | + // for (let yi = 0; yi < length; yi++) { | |
| 4171 | + // await th.setAdvancesum(pdata[yi], data.data) | |
| 4172 | + // } | |
| 4173 | + // wx.hideLoading() | |
| 4174 | + // th.setData({ isclose: 0 }); | |
| 4175 | + // wx.redirectTo({ | |
| 4176 | + // url: "/pages/payment/pay_success/pay_success?type=2&order_sn=" + data.data, | |
| 4177 | + // }) | |
| 4178 | + // } else { | |
| 4179 | + // th.setData({ isclose: 0 }); | |
| 4180 | + // wx.redirectTo({ | |
| 4181 | + // url: "/pages/payment/pay_success/pay_success?type=2&order_sn=" + data.data, | |
| 4182 | + // }) | |
| 4183 | + // } | |
| 4184 | + th.setData({ isclose: 0 }); | |
| 4185 | + wx.redirectTo({ | |
| 4186 | + url: "/pages/payment/pay_success/pay_success?type=2&order_sn=" + data.data, | |
| 4187 | + }) | |
| 4181 | 4188 | //}, 1000) |
| 4182 | 4189 | } |
| 4183 | 4190 | }, | ... | ... |
pages/cart/cart2_inte/cart2_inte.js
| ... | ... | @@ -76,7 +76,7 @@ Page({ |
| 76 | 76 | //--订单优惠-- |
| 77 | 77 | order_prom: {}, |
| 78 | 78 | show_submit: 0, //提交按钮变正常显示 |
| 79 | - | |
| 79 | + udata: null,//用户预存值,数据 | |
| 80 | 80 | }, |
| 81 | 81 | onLoad: function (t) { |
| 82 | 82 | wx.setNavigationBarTitle({ title: "填写订单", }) |
| ... | ... | @@ -193,7 +193,117 @@ Page({ |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | }, |
| 196 | + //获取预存款余额 | |
| 197 | + async getAdvancesum() { | |
| 198 | + /*-----获取线下会员的预存款和优惠券的数量-----*/ | |
| 199 | + let url = "/api/weshop/users/getinfo/" + os.stoid + "/" + getApp().globalData.userInfo.user_id | |
| 200 | + await getApp().request.promiseGet(url, { | |
| 201 | + data: { | |
| 202 | + isShowLoading: 0, | |
| 203 | + }, | |
| 204 | + }).then(su => { | |
| 205 | + if (su.data.code == 0 && su.data.data) { | |
| 206 | + var data = su.data.data; | |
| 207 | + if (!data) data = {}; | |
| 208 | + data.cashcount = parseInt(data.cashcount); | |
| 209 | + this.setData({ | |
| 210 | + udata: data, | |
| 211 | + }); | |
| 212 | + } | |
| 213 | + }) | |
| 196 | 214 | |
| 215 | + }, | |
| 216 | + //购物车预存开启关闭 | |
| 217 | + prestore(e) { | |
| 218 | + let ind = e.currentTarget.dataset.ind; | |
| 219 | + let item = e.currentTarget.dataset.item | |
| 220 | + let txt = 'cartlist[' + ind + '].yck_off'; | |
| 221 | + let txt1 = 'old_cartlist[' + ind + '].yck_off'; | |
| 222 | + if (item.yck_off == 2) { | |
| 223 | + this.setData({ [txt]: 1, [txt1]: 1 }) | |
| 224 | + } else if (item.yck_off == 1) { | |
| 225 | + this.setData({ [txt]: 2, [txt1]: 2 }) | |
| 226 | + } | |
| 227 | + this.calculatePrice()//计算金额 | |
| 228 | + }, | |
| 229 | + //直接购买预存开启关闭 | |
| 230 | + prestore2() { | |
| 231 | + let txt = 'bn_goods.yck_off'; | |
| 232 | + if (this.data.bn_goods.yck_off == 2) { | |
| 233 | + this.setData({ [txt]: 1 }) | |
| 234 | + } else if (this.data.bn_goods.yck_off == 1) { | |
| 235 | + this.setData({ [txt]: 2 }) | |
| 236 | + } | |
| 237 | + this.calculatePrice2()//计算金额 | |
| 238 | + }, | |
| 239 | + //计算商品预存款前置方法------------------------------------ | |
| 240 | + async beforAdvancesum(cartList) { | |
| 241 | + // let cartList= this.data.cartlist | |
| 242 | + // let cartList= arr | |
| 243 | + // let length = cartList.length | |
| 244 | + wx.showLoading({ | |
| 245 | + title: '加载中', | |
| 246 | + mask: true | |
| 247 | + }) | |
| 248 | + // for (let i = 0; i < length; i++) { | |
| 249 | + let item = cartList; | |
| 250 | + let goods = item.goods | |
| 251 | + let keyid = item.sto.keyid | |
| 252 | + let listform = [] | |
| 253 | + goods.map(ite => { | |
| 254 | + let obj = { | |
| 255 | + wareno: ite.goods_sn, | |
| 256 | + price: ite.goods_price, | |
| 257 | + qty: ite.goods_num | |
| 258 | + } | |
| 259 | + listform.push(obj) | |
| 260 | + }) | |
| 261 | + let arr = await this.getGoodsAdvancesum(keyid, listform, cartList) | |
| 262 | + // } | |
| 263 | + wx.hideLoading() | |
| 264 | + return arr | |
| 265 | + }, | |
| 266 | + //计算商品预存款请求方法------------------------------------ | |
| 267 | + async getGoodsAdvancesum(storageid, listform, cartList) { | |
| 268 | + let res = await getApp().request.promisePost(`/api/weshop/delphiapi/saveErpApi`, { | |
| 269 | + data: { | |
| 270 | + accdb: getApp().globalData.config.erpid, | |
| 271 | + ApiName: 'api.pos.shop.advancesum.seek', | |
| 272 | + usercode: "admin", | |
| 273 | + vipid: this.data.userinfo.erpvipid, | |
| 274 | + oddsum: "0", | |
| 275 | + advancesum: cartList.order_amount, | |
| 276 | + storageid: storageid, | |
| 277 | + listform | |
| 278 | + }, | |
| 279 | + is_json: 1 | |
| 280 | + }) | |
| 281 | + console.log('计算商品的预存款'); | |
| 282 | + console.log(res); | |
| 283 | + let yck = 0 | |
| 284 | + let yckid = "" | |
| 285 | + let yckIdArr = [] | |
| 286 | + let pre_json = null | |
| 287 | + if (res.data.code == 0 && res.data.data && res.data.data.length > 0) { | |
| 288 | + let resData = res.data.data | |
| 289 | + resData.map(ite => { | |
| 290 | + yck += ite.advancesum | |
| 291 | + yckIdArr.push(ite.advanceitemid) | |
| 292 | + }) | |
| 293 | + pre_json = resData | |
| 294 | + } | |
| 295 | + yckid = yckIdArr.join() | |
| 296 | + let obj = {} | |
| 297 | + if (yck * 1 > 0) { | |
| 298 | + obj.yck_off = 1 | |
| 299 | + } else { | |
| 300 | + obj.yck_off = 0 | |
| 301 | + } | |
| 302 | + obj.yck = yck | |
| 303 | + obj.yckid = yckid | |
| 304 | + obj.pre_json = pre_json | |
| 305 | + return obj | |
| 306 | + }, | |
| 197 | 307 | //-------------------获取物流--------------- |
| 198 | 308 | get_wuliu(func) { |
| 199 | 309 | var th = this; |
| ... | ... | @@ -242,9 +352,11 @@ Page({ |
| 242 | 352 | }, |
| 243 | 353 | |
| 244 | 354 | //----------------展示页面,是再获取用户信息之后-------------- |
| 245 | - show_page: function () { | |
| 355 | + show_page:async function () { | |
| 246 | 356 | var th = this, ta = this.data.param; |
| 247 | 357 | //th.setData({ userinfo: getApp().globalData.userInfo,}); |
| 358 | + //获取用户预存款 | |
| 359 | + await th.getAdvancesum() | |
| 248 | 360 | |
| 249 | 361 | var user = getApp().globalData.userInfo; |
| 250 | 362 | getApp().request.get("/api/weshop/users/get/" + oo.stoid + "/" + user.user_id, { |
| ... | ... | @@ -617,6 +729,105 @@ Page({ |
| 617 | 729 | order_m = 0; coupon_price = parseFloat(order_m).toFixed(2); |
| 618 | 730 | } |
| 619 | 731 | |
| 732 | + //预存金额使用参与计算 | |
| 733 | + if (th.data.udata && th.data.udata.Balance > 0 && order_m * 1 > 0) { | |
| 734 | + if (!th.data.bn_goods.keyid) { | |
| 735 | + //获取门店信息 | |
| 736 | + await getApp().request.promiseGet("/api/weshop/pickup/list", { | |
| 737 | + data: { | |
| 738 | + store_id: os.stoid, | |
| 739 | + ids: th.data.bn_pick | |
| 740 | + } | |
| 741 | + }).then(res => { | |
| 742 | + if (ut.ajax_ok(res)) { | |
| 743 | + console.log(res); | |
| 744 | + if (res.data.code == 0) { | |
| 745 | + let resData = res.data.data.pageData | |
| 746 | + if (resData && resData[0]) { | |
| 747 | + let keyid = resData[0].keyid | |
| 748 | + let txt = 'bn_goods.keyid' | |
| 749 | + th.setData({ | |
| 750 | + [txt]: keyid | |
| 751 | + }) | |
| 752 | + } | |
| 753 | + } | |
| 754 | + } | |
| 755 | + }) | |
| 756 | + } | |
| 757 | + if (th.data.bn_goods.keyid) { | |
| 758 | + let cart_yc = await th.beforAdvancesum({ | |
| 759 | + order_amount: order_m, | |
| 760 | + goods: [{ | |
| 761 | + goods_sn: th.data.bn_goods.goods_sn, | |
| 762 | + goods_price: th.data.bn_goods.shop_price || th.data.bn_goods.goods_price, | |
| 763 | + goods_num: th.data.bn_goods.buynum || th.data.bn_goods.goods_num, | |
| 764 | + }], | |
| 765 | + sto: { | |
| 766 | + keyid: th.data.bn_goods.keyid | |
| 767 | + } | |
| 768 | + }) | |
| 769 | + | |
| 770 | + if (!good.yck_off) { | |
| 771 | + good.yck_off = cart_yc.yck_off | |
| 772 | + } | |
| 773 | + good.yck = cart_yc.yck | |
| 774 | + good.yckid = cart_yc.yckid | |
| 775 | + good.pre_json = cart_yc.pre_json | |
| 776 | + let yct1 = 'bn_goods.yck_off'; | |
| 777 | + let yct2 = 'bn_goods.yck'; | |
| 778 | + let yct3 = 'bn_goods.yckid'; | |
| 779 | + let yct4 = 'bn_goods.pre_json'; | |
| 780 | + th.setData({ | |
| 781 | + [yct1]: good.yck_off, | |
| 782 | + [yct2]: good.yck, | |
| 783 | + [yct3]: good.yckid, | |
| 784 | + [yct4]: good.pre_json, | |
| 785 | + }) | |
| 786 | + | |
| 787 | + if (good.yck_off && good.yck_off == 2) { | |
| 788 | + let order_amount = (order_m - good.yck).toFixed(2); | |
| 789 | + let yck = 0 | |
| 790 | + if (order_amount * 1 > 0) { | |
| 791 | + order_m = order_amount; | |
| 792 | + // all_prestore+=parseFloat(good.yck); | |
| 793 | + yck = parseFloat(good.yck) | |
| 794 | + } else { | |
| 795 | + // all_prestore+=order_m*1 | |
| 796 | + yck = parseFloat(order_m) | |
| 797 | + order_m = 0 | |
| 798 | + } | |
| 799 | + let atxt10 = "formData.prestore"; //预存金额 | |
| 800 | + let atxt11 = "formData.pre_json"; //预存json | |
| 801 | + let atxt12 = "formData.all_yck_arr"; //预存真实抵扣列表 | |
| 802 | + th.setData({ | |
| 803 | + [atxt10]: yck, | |
| 804 | + [atxt11]: [good.pre_json], | |
| 805 | + [atxt12]: [yck], | |
| 806 | + }) | |
| 807 | + // formData.prestore | |
| 808 | + // all_yck_arr.push(yck) //真实预存款抵扣金额 | |
| 809 | + // all_pre_json.push(good.pre_json) | |
| 810 | + // all_prestore = parseFloat(all_prestore); //真实预存款抵扣金额总和 | |
| 811 | + } | |
| 812 | + } | |
| 813 | + } else { | |
| 814 | + let yct1 = 'bn_goods.yck_off'; | |
| 815 | + let yct2 = 'bn_goods.yck'; | |
| 816 | + let yct3 = 'bn_goods.yckid'; | |
| 817 | + let yct4 = 'bn_goods.pre_json'; | |
| 818 | + let atxt10 = "formData.prestore"; //预存金额 | |
| 819 | + let atxt11 = "formData.pre_json"; //预存json | |
| 820 | + let atxt12 = "formData.all_yck_arr"; //预存真实抵扣列表 | |
| 821 | + th.setData({ | |
| 822 | + [yct2]: 0, | |
| 823 | + [yct3]: '', | |
| 824 | + [yct4]: '', | |
| 825 | + [atxt10]: 0, | |
| 826 | + [atxt11]: '', | |
| 827 | + [atxt12]: [], | |
| 828 | + }) | |
| 829 | + } | |
| 830 | + | |
| 620 | 831 | //判断是否同城配送,而且没有调用过 |
| 621 | 832 | if(th.data.bn_exp_type==2 && th.data.user_addr) { |
| 622 | 833 | |
| ... | ... | @@ -873,6 +1084,25 @@ Page({ |
| 873 | 1084 | |
| 874 | 1085 | |
| 875 | 1086 | if (pdata.length == 0) return; |
| 1087 | + //如果有使用预存,要处理 | |
| 1088 | + if (th.data.formData && th.data.formData.prestore * 1 > 0) { | |
| 1089 | + let formData = th.data.formData | |
| 1090 | + let pre_json = formData.pre_json | |
| 1091 | + let all_yck_arr = formData.all_yck_arr | |
| 1092 | + pdata.map((item, i) => { | |
| 1093 | + item.pre_cut = all_yck_arr[i] ? all_yck_arr[i] : 0 | |
| 1094 | + item.pre_preferential = 0 | |
| 1095 | + item.pre_json = pre_json[i] ? JSON.stringify(pre_json[i]) : '' | |
| 1096 | + }) | |
| 1097 | + } | |
| 1098 | + if (!pdata.keyid && th.data.bn_goods) { | |
| 1099 | + pdata.map(ite => { | |
| 1100 | + ite.keyid = th.data.bn_goods.keyid | |
| 1101 | + }) | |
| 1102 | + // pdata.keyid = th.data.bn_goods.keyid | |
| 1103 | + } | |
| 1104 | + //------------------------------------------ | |
| 1105 | + | |
| 876 | 1106 | var str = JSON.stringify(pdata); |
| 877 | 1107 | |
| 878 | 1108 | wx.showLoading({ title: "加载中" }); | ... | ... |