Commit cd2a6c7b63f745f754dd6fad88944a4296f0a426
1 parent
73dd8c11
卡顿的bug优化
Showing
2 changed files
with
165 additions
and
92 deletions
packageE/pages/cart/cart2/cart2.js
| ... | ... | @@ -176,6 +176,9 @@ Page({ |
| 176 | 176 | show_can_cx_map:{}, |
| 177 | 177 | //优惠促销活动的集合 |
| 178 | 178 | yhcx_act_map: {}, |
| 179 | + | |
| 180 | + //优惠促销购买次数 | |
| 181 | + yhcx_buy_map:{} | |
| 179 | 182 | }, |
| 180 | 183 | |
| 181 | 184 | |
| ... | ... | @@ -1364,7 +1367,10 @@ Page({ |
| 1364 | 1367 | // item1.prom_id='' |
| 1365 | 1368 | // item1.prom_type='' |
| 1366 | 1369 | } else { |
| 1370 | + | |
| 1367 | 1371 | let user_pre_buynum = await th.getUserBuyPromNum_pre(item1.prom_id) //用户已经参与次数 |
| 1372 | + | |
| 1373 | + | |
| 1368 | 1374 | if (user_pre_buynum < limit_num) { |
| 1369 | 1375 | await th.add_prom_goods_map(item1); |
| 1370 | 1376 | } else { |
| ... | ... | @@ -1606,12 +1612,12 @@ Page({ |
| 1606 | 1612 | let req_d1 = { |
| 1607 | 1613 | user_id: getApp().globalData.user_id, goods_ids: [hr], store_id: os.stoid |
| 1608 | 1614 | } |
| 1609 | - | |
| 1610 | 1615 | await getApp().request.promisePost("/api/weshop/order/getrebateSum", { |
| 1611 | 1616 | is_json: 1, data: req_d1 |
| 1612 | 1617 | }).then(grs => { |
| 1613 | 1618 | if (grs.data.code == 0) item[c].use_commission = grs.data.data; |
| 1614 | 1619 | }); |
| 1620 | + | |
| 1615 | 1621 | commission_gds.push(hr); |
| 1616 | 1622 | } |
| 1617 | 1623 | } |
| ... | ... | @@ -6968,6 +6974,12 @@ Page({ |
| 6968 | 6974 | }, |
| 6969 | 6975 | //优惠促销用户参与次数 |
| 6970 | 6976 | async getUserBuyPromNum_pre(prom_id){ |
| 6977 | + | |
| 6978 | + //如果有缓存的数据,就用缓存的数据 | |
| 6979 | + if(this.data.in_yhact[prom_id] && this.data.in_yhact[prom_id].buyed!=undefined){ | |
| 6980 | + let user_pre_buynum=this.data.in_yhact[prom_id].buyed; | |
| 6981 | + return user_pre_buynum; | |
| 6982 | + } | |
| 6971 | 6983 | var userInfo = getApp().globalData.userInfo; |
| 6972 | 6984 | var url = `/api/weshop/ordergoods/getUserBuyPromNum?is_all=1&store_id=${os.stoid}&user_id=${userInfo.user_id}&prom_type=3&prom_id=${prom_id}`; |
| 6973 | 6985 | let res = await getApp().request.promiseGet(url, { | ... | ... |
pages/cart/cart/cart.js
| ... | ... | @@ -62,11 +62,13 @@ Page({ |
| 62 | 62 | //送赠品的优化 |
| 63 | 63 | cart_zp:{}, |
| 64 | 64 | //-- dp_cart深拷贝的缓存 -- |
| 65 | - dp_cart:null | |
| 65 | + dp_cart:null, | |
| 66 | 66 | |
| 67 | + //优惠促销活动的集合 | |
| 68 | + yhcx_act_map: {}, | |
| 67 | 69 | }, |
| 68 | 70 | |
| 69 | - | |
| 71 | + | |
| 70 | 72 | onLoad: function () { |
| 71 | 73 | var a = this, |
| 72 | 74 | ee = a; |
| ... | ... | @@ -559,9 +561,15 @@ Page({ |
| 559 | 561 | i_fd=i_fd.goodsPromInfoRespDto; |
| 560 | 562 | //-- 赋值多促销活动的优化-- |
| 561 | 563 | carr[ia].more_cx=i_fd.more_cx; |
| 564 | + //商品优惠促销的缓存 | |
| 565 | + if (i_fd.yhcx_pro) { | |
| 566 | + th.data.yhcx_act_map[i_fd.yhcx_pro.id] = i_fd.yhcx_pro; | |
| 567 | + } | |
| 568 | + //商品组合促销的缓存 | |
| 562 | 569 | if (i_fd.zh_pro) { |
| 563 | 570 | th.data.zuhe_map[i_fd.zh_pro.id] = i_fd.zh_pro; |
| 564 | 571 | } |
| 572 | + //商品阶梯促销的缓存 | |
| 565 | 573 | if (i_fd.ladder_pro) { |
| 566 | 574 | var ladder_pro = i_fd.ladder_pro; |
| 567 | 575 | th.data.ladder_map[ladder_pro.id] = ladder_pro; |
| ... | ... | @@ -699,7 +707,6 @@ Page({ |
| 699 | 707 | th.disInvalid(item); |
| 700 | 708 | continue; |
| 701 | 709 | } |
| 702 | - | |
| 703 | 710 | } |
| 704 | 711 | |
| 705 | 712 | } |
| ... | ... | @@ -1593,7 +1600,6 @@ Page({ |
| 1593 | 1600 | } |
| 1594 | 1601 | |
| 1595 | 1602 | |
| 1596 | - | |
| 1597 | 1603 | //-- 判断起购数量 -- |
| 1598 | 1604 | if (!e.data.checkAllToggle) { |
| 1599 | 1605 | //判断是不是有促销活动 |
| ... | ... | @@ -1634,31 +1640,29 @@ Page({ |
| 1634 | 1640 | // if (obj.prom_type == 10) ladder_calc.add_ladder_prom(dda, i, obj); |
| 1635 | 1641 | |
| 1636 | 1642 | //多门店,多优惠次数控制 |
| 1637 | - let pro_off1 = false | |
| 1638 | - if (!e.data.checkAllToggle) { | |
| 1639 | - //判断多店优惠促销次数控制 | |
| 1640 | - if (th.data.requestData.length > 1) { | |
| 1641 | - if (obj.prom_type == 3) { | |
| 1642 | - | |
| 1643 | - pro_off1 = await th.multiple_stores_pro(i, j) | |
| 1644 | - } | |
| 1645 | - } | |
| 1646 | - } | |
| 1647 | - | |
| 1648 | - if (pro_off1) { | |
| 1649 | - pro_off = true | |
| 1650 | - let txt1 = "requestData[" + i + "].pro_off"; | |
| 1651 | - e.setData({ | |
| 1652 | - [txt1]: true, | |
| 1653 | - [txt]: 0, | |
| 1654 | - }); | |
| 1655 | - | |
| 1656 | - wx.showToast({ | |
| 1657 | - title: '已超出优惠促销次数', | |
| 1658 | - icon: 'none', | |
| 1659 | - }); | |
| 1643 | + // let pro_off1 = false | |
| 1644 | + // if (!e.data.checkAllToggle) { | |
| 1645 | + // //判断多店优惠促销次数控制 | |
| 1646 | + // if (th.data.requestData.length > 1) { | |
| 1647 | + // if (obj.prom_type == 3) { | |
| 1648 | + // pro_off1 = await th.multiple_stores_pro(i, j) | |
| 1649 | + // } | |
| 1650 | + // } | |
| 1651 | + // } | |
| 1652 | + // if (pro_off1) { | |
| 1653 | + // pro_off = true | |
| 1654 | + // let txt1 = "requestData[" + i + "].pro_off"; | |
| 1655 | + // e.setData({ | |
| 1656 | + // [txt1]: true, | |
| 1657 | + // [txt]: 0, | |
| 1658 | + // }); | |
| 1659 | + // | |
| 1660 | + // wx.showToast({ | |
| 1661 | + // title: '已超出优惠促销次数', | |
| 1662 | + // icon: 'none', | |
| 1663 | + // }); | |
| 1660 | 1664 | |
| 1661 | - } else { | |
| 1665 | + // } else { | |
| 1662 | 1666 | |
| 1663 | 1667 | if (!e.data.checkAllToggle) { |
| 1664 | 1668 | //组合购的金额要另外算 |
| ... | ... | @@ -1672,11 +1676,16 @@ Page({ |
| 1672 | 1676 | offline_price += (item[j].goods_price - item[j].offline_price) * item[j].goods_num; |
| 1673 | 1677 | offline_num += item[j].goods_num; |
| 1674 | 1678 | } |
| 1675 | - } | |
| 1676 | 1679 | |
| 1677 | - e.setData({ | |
| 1678 | - [txt]: !e.data.checkAllToggle, | |
| 1679 | - }) | |
| 1680 | + e.setData({ | |
| 1681 | + [txt]: !e.data.checkAllToggle, | |
| 1682 | + }) | |
| 1683 | + | |
| 1684 | + //} | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1680 | 1689 | // if (!e.data.checkAllToggle) { |
| 1681 | 1690 | // //组合购的金额要另外算 |
| 1682 | 1691 | // if (item[j].prom_type != 7 && item[j].prom_type != 10) |
| ... | ... | @@ -1952,36 +1961,44 @@ Page({ |
| 1952 | 1961 | } |
| 1953 | 1962 | |
| 1954 | 1963 | //判断多店优惠促销次数控制 |
| 1955 | - if (th.data.requestData.length > 1) { | |
| 1956 | - if (gd_info.prom_type == 3) { | |
| 1957 | - pro_off1 = await th.multiple_stores_pro(pitems, i) | |
| 1958 | - } | |
| 1959 | - } | |
| 1960 | - if (pro_off1) { | |
| 1961 | - pro_off = true | |
| 1962 | - e.setData({ | |
| 1963 | - [txt]: 0, | |
| 1964 | - }); | |
| 1965 | - } else { | |
| 1966 | - e.setData({ | |
| 1967 | - [txt]: Number(!sele), | |
| 1968 | - }); | |
| 1969 | - } | |
| 1970 | - } | |
| 1971 | - var txt = "requestData[" + pitems + "].selected"; | |
| 1972 | - if (pro_off) { | |
| 1973 | - wx.showToast({ | |
| 1974 | - title: '已超出优惠促销次数', | |
| 1975 | - icon: 'none', | |
| 1976 | - }); | |
| 1977 | - e.setData({ | |
| 1978 | - [txt]: 0, | |
| 1979 | - }); | |
| 1980 | - } else { | |
| 1964 | + // if (th.data.requestData.length > 1) { | |
| 1965 | + // if (gd_info.prom_type == 3) { | |
| 1966 | + // pro_off1 = await th.multiple_stores_pro(pitems, i) | |
| 1967 | + // } | |
| 1968 | + // } | |
| 1969 | + // if (pro_off1) { | |
| 1970 | + // pro_off = true | |
| 1971 | + // e.setData({ | |
| 1972 | + // [txt]: 0, | |
| 1973 | + // }); | |
| 1974 | + // } else { | |
| 1975 | + // e.setData({ | |
| 1976 | + // [txt]: Number(!sele), | |
| 1977 | + // }); | |
| 1978 | + // } | |
| 1981 | 1979 | e.setData({ |
| 1982 | 1980 | [txt]: Number(!sele), |
| 1983 | 1981 | }); |
| 1982 | + | |
| 1984 | 1983 | } |
| 1984 | + var txt = "requestData[" + pitems + "].selected"; | |
| 1985 | + // if (pro_off) { | |
| 1986 | + // wx.showToast({ | |
| 1987 | + // title: '已超出优惠促销次数', | |
| 1988 | + // icon: 'none', | |
| 1989 | + // }); | |
| 1990 | + // e.setData({ | |
| 1991 | + // [txt]: 0, | |
| 1992 | + // }); | |
| 1993 | + // } else { | |
| 1994 | + // e.setData({ | |
| 1995 | + // [txt]: Number(!sele), | |
| 1996 | + // }); | |
| 1997 | + // } | |
| 1998 | + | |
| 1999 | + e.setData({ | |
| 2000 | + [txt]: Number(!sele), | |
| 2001 | + }); | |
| 1985 | 2002 | |
| 1986 | 2003 | //-- 选择了什么商品,就用什么商品来判断 -- |
| 1987 | 2004 | var sele_arr = {}; |
| ... | ... | @@ -2040,6 +2057,7 @@ Page({ |
| 2040 | 2057 | |
| 2041 | 2058 | //判断多门店,优惠促销次数的控制 |
| 2042 | 2059 | async multiple_stores_pro(pitems, item) { |
| 2060 | + | |
| 2043 | 2061 | let a = this.data.requestData[pitems].goods[item]; |
| 2044 | 2062 | let th = this |
| 2045 | 2063 | let arr_pro = [] |
| ... | ... | @@ -2049,21 +2067,31 @@ Page({ |
| 2049 | 2067 | } |
| 2050 | 2068 | }) |
| 2051 | 2069 | let prom = null |
| 2052 | - await getApp().request.promiseGet("/api/weshop/promgoods/get/" + os.stoid + "/" + a.prom_id, {}).then(res => { | |
| 2053 | - if (res.data.code == 0) { | |
| 2054 | - prom = res.data.data; | |
| 2055 | - } | |
| 2056 | - }) | |
| 2057 | - let user_pre_buynum = await this.getUserBuyPromNum_pre(a.prom_id) | |
| 2070 | + //使用缓存,不在调用接口 | |
| 2071 | + if(!prom && th.data.yhcx_act_map && th.data.yhcx_act_map[a.prom_id] ){ | |
| 2072 | + prom=th.data.yhcx_act_map[a.prom_id]; | |
| 2073 | + } | |
| 2074 | + if(!prom) { | |
| 2075 | + await getApp().request.promiseGet("/api/weshop/promgoods/get/" + os.stoid + "/" + a.prom_id, {}).then(res => { | |
| 2076 | + if (res.data.code == 0) { | |
| 2077 | + prom = res.data.data; | |
| 2078 | + } | |
| 2079 | + }) | |
| 2080 | + } | |
| 2058 | 2081 | |
| 2082 | + let user_pre_buynum = await this.getUserBuyPromNum_pre(a.prom_id); | |
| 2059 | 2083 | if (user_pre_buynum >= prom.limit_num) { |
| 2060 | 2084 | return false |
| 2061 | 2085 | } else { |
| 2086 | + | |
| 2062 | 2087 | let action_num = user_pre_buynum + 1; |
| 2063 | 2088 | arr_pro.map(item => { |
| 2089 | + let found = false; | |
| 2064 | 2090 | item.goods.map(ite => { |
| 2091 | + if(found) return; | |
| 2065 | 2092 | if (ite.prom_type == 3 && ite.prom_id == a.prom_id && !ite.is_gift && ite.selected) { |
| 2066 | 2093 | action_num += 1; |
| 2094 | + found=true; | |
| 2067 | 2095 | } |
| 2068 | 2096 | }) |
| 2069 | 2097 | }) |
| ... | ... | @@ -2226,23 +2254,22 @@ Page({ |
| 2226 | 2254 | } |
| 2227 | 2255 | } |
| 2228 | 2256 | |
| 2229 | - | |
| 2230 | - let pro_off = false | |
| 2231 | - //判断多店优惠促销次数控制 | |
| 2232 | - if (th.data.requestData.length > 1) { | |
| 2233 | - if (a.prom_type == 3 && !a.selected) { | |
| 2234 | - //pro_off = await th.multiple_stores_pro(pitems, item) | |
| 2235 | - } | |
| 2236 | - } | |
| 2237 | - | |
| 2238 | - if (pro_off) { | |
| 2239 | - wx.showToast({ | |
| 2240 | - title: '已超出优惠促销次数', | |
| 2241 | - icon: 'none', | |
| 2242 | - }); | |
| 2243 | - th.clear_clicking(); | |
| 2244 | - return false; | |
| 2245 | - } | |
| 2257 | + // let pro_off = false | |
| 2258 | + // //判断多店优惠促销次数控制 | |
| 2259 | + // if (th.data.requestData.length > 1) { | |
| 2260 | + // if (a.prom_type == 3 && !a.selected) { | |
| 2261 | + // pro_off = await th.multiple_stores_pro(pitems, item) | |
| 2262 | + // } | |
| 2263 | + // } | |
| 2264 | + // | |
| 2265 | + // if (pro_off) { | |
| 2266 | + // wx.showToast({ | |
| 2267 | + // title: '已超出优惠促销次数', | |
| 2268 | + // icon: 'none', | |
| 2269 | + // }); | |
| 2270 | + // th.clear_clicking(); | |
| 2271 | + // return false; | |
| 2272 | + // } | |
| 2246 | 2273 | |
| 2247 | 2274 | var txt0 = "requestData[" + pitems + "].show_can_cx"; |
| 2248 | 2275 | e.setData({ |
| ... | ... | @@ -2492,6 +2519,9 @@ Page({ |
| 2492 | 2519 | //-- 先批量判断一下活动的类型,同时要同步跟新 -- |
| 2493 | 2520 | var offline_price = 0; |
| 2494 | 2521 | var offline_num = 0; |
| 2522 | + | |
| 2523 | + //-- 优惠促销活动限购次数的优化 -- | |
| 2524 | + var ch_yc_map={}; | |
| 2495 | 2525 | for (var c = 0; c < item.length; c++) { |
| 2496 | 2526 | //清理一下赠品 |
| 2497 | 2527 | if (item[c].is_gift) { |
| ... | ... | @@ -2504,6 +2534,20 @@ Page({ |
| 2504 | 2534 | continue; |
| 2505 | 2535 | } |
| 2506 | 2536 | |
| 2537 | + let pro_off1 = false; | |
| 2538 | + //-- 判断活动超出限购,要有选中的情况 -- | |
| 2539 | + if (item[c].prom_type == 3 && item[c].selected && !ch_yc_map[a.prom_id]) { | |
| 2540 | + //一个门店一个优惠促销就判断一次 | |
| 2541 | + ch_yc_map[a.prom_id]=1; | |
| 2542 | + pro_off1 = await th.multiple_stores_pro(a, c) | |
| 2543 | + } | |
| 2544 | + if (pro_off1) { | |
| 2545 | + wx.showToast({ | |
| 2546 | + title: '已超出优惠促销次数', | |
| 2547 | + icon: 'none', | |
| 2548 | + }); | |
| 2549 | + } | |
| 2550 | + | |
| 2507 | 2551 | all_num += item[c].goods_num; |
| 2508 | 2552 | |
| 2509 | 2553 | if (item[c].prom_type == 7) { |
| ... | ... | @@ -2608,6 +2652,13 @@ Page({ |
| 2608 | 2652 | } |
| 2609 | 2653 | } |
| 2610 | 2654 | |
| 2655 | + | |
| 2656 | + | |
| 2657 | + | |
| 2658 | + | |
| 2659 | + | |
| 2660 | + | |
| 2661 | + | |
| 2611 | 2662 | //总的价格,把组合商品的价格拿出来 |
| 2612 | 2663 | var zh_calc_res = zh_calc.calculate_zh(car, a, th); |
| 2613 | 2664 | console.log('.组合价-----------') |
| ... | ... | @@ -4766,6 +4817,11 @@ Page({ |
| 4766 | 4817 | |
| 4767 | 4818 | async all_check_prom_activity() { |
| 4768 | 4819 | this.data.duo_zp_num_arr = {}; |
| 4820 | + //用来存销赠品的--2024-2-1 | |
| 4821 | + let cart_zp=this.data.cart_zp; | |
| 4822 | + //要清空一下赠品数组 | |
| 4823 | + cart_zp={}; | |
| 4824 | + | |
| 4769 | 4825 | for (var i in this.data.requestData) { |
| 4770 | 4826 | var cindex = i; |
| 4771 | 4827 | var make_up_arr = new Array(); |
| ... | ... | @@ -4781,11 +4837,6 @@ Page({ |
| 4781 | 4837 | |
| 4782 | 4838 | var no_gift_arr = []; |
| 4783 | 4839 | |
| 4784 | - //用来存销赠品的--2024-2-1 | |
| 4785 | - let cart_zp=this.data.cart_zp; | |
| 4786 | - //要清空一下赠品数组 | |
| 4787 | - cart_zp={}; | |
| 4788 | - | |
| 4789 | 4840 | //主要判断有没有促销活动 |
| 4790 | 4841 | var is_sele_prom = 0; |
| 4791 | 4842 | var is_gift_del = 0; |
| ... | ... | @@ -4857,11 +4908,20 @@ Page({ |
| 4857 | 4908 | if (th.data.promgoods_map[p_item[0]]) { |
| 4858 | 4909 | prom = th.data.promgoods_map[p_item[0]]; |
| 4859 | 4910 | } else { |
| 4860 | - await getApp().request.promiseGet("/api/weshop/promgoods/get/" + os.stoid + "/" + p_item[0], {}).then(res => { | |
| 4861 | - if (res.data.code == 0) { | |
| 4862 | - prom = res.data.data; | |
| 4863 | - } | |
| 4864 | - }) | |
| 4911 | + | |
| 4912 | + //使用缓存,不在调用接口 | |
| 4913 | + if(!prom && th.data.yhcx_act_map && th.data.yhcx_act_map[p_item[0]] ){ | |
| 4914 | + prom=th.data.yhcx_act_map[p_item[0]]; | |
| 4915 | + } | |
| 4916 | + if(!prom){ | |
| 4917 | + await getApp().request.promiseGet("/api/weshop/promgoods/get/" + os.stoid + "/" + p_item[0], {}).then(res => { | |
| 4918 | + if (res.data.code == 0) { | |
| 4919 | + prom = res.data.data; | |
| 4920 | + } | |
| 4921 | + }) | |
| 4922 | + } | |
| 4923 | + | |
| 4924 | + | |
| 4865 | 4925 | } |
| 4866 | 4926 | let limit_num = 0 |
| 4867 | 4927 | let user_pre_buynum = 0 |
| ... | ... | @@ -4910,6 +4970,7 @@ Page({ |
| 4910 | 4970 | if (!promgoods_list) continue; |
| 4911 | 4971 | th.data.promgoods_list[p_item[0]] = promgoods_list; |
| 4912 | 4972 | } |
| 4973 | + | |
| 4913 | 4974 | if (!limit_num || user_pre_buynum < limit_num) { |
| 4914 | 4975 | for (var i in promgoods_list) { |
| 4915 | 4976 | var item = promgoods_list[i]; | ... | ... |