Commit 2338ea89c7150374d7ff3960f69e714c67067dbf
1 parent
c6c469f6
多店优惠促销次数控制优化
Showing
1 changed file
with
148 additions
and
31 deletions
pages/cart/cart/cart.js
| ... | ... | @@ -1755,7 +1755,7 @@ Page({ |
| 1755 | 1755 | |
| 1756 | 1756 | |
| 1757 | 1757 | //---------------全选,全选的时候要判断是否门店的匹配方式一致-------------- |
| 1758 | - checkAll: function () { | |
| 1758 | + checkAll: async function () { | |
| 1759 | 1759 | var e = this, |
| 1760 | 1760 | th = this, |
| 1761 | 1761 | dda = e.data.requestData, |
| ... | ... | @@ -1780,7 +1780,7 @@ Page({ |
| 1780 | 1780 | var offline_price = 0; |
| 1781 | 1781 | var offline_num = 0; |
| 1782 | 1782 | th.data.in_zhact_gdmap = {}; |
| 1783 | - | |
| 1783 | + var pro_off=false | |
| 1784 | 1784 | |
| 1785 | 1785 | if (dda && dda.length > 0) { |
| 1786 | 1786 | for (var i = 0; i < dda.length; i++) { |
| ... | ... | @@ -1823,24 +1823,51 @@ Page({ |
| 1823 | 1823 | //加入阶梯促销计算 |
| 1824 | 1824 | if (obj.prom_type == 10) ladder_calc.add_ladder_prom(dda, i, obj); |
| 1825 | 1825 | |
| 1826 | - e.setData({ | |
| 1827 | - | |
| 1828 | - [txt]: !e.data.checkAllToggle, | |
| 1829 | - }) | |
| 1830 | - | |
| 1831 | - if (!e.data.checkAllToggle) { | |
| 1832 | - //组合购的金额要另外算 | |
| 1833 | - if (item[j].prom_type != 7 && item[j].prom_type != 10) | |
| 1834 | - tfeel += item[j].goods_num * item[j].goods_price; | |
| 1835 | - t_num += item[j].goods_num; | |
| 1826 | + //多门店,多优惠次数控制 | |
| 1827 | + let pro_off1=false | |
| 1828 | + if (!e.data.checkAllToggle) { | |
| 1829 | + //判断多店优惠促销次数控制 | |
| 1830 | + if (th.data.requestData.length>1) { | |
| 1831 | + if(obj.prom_type==3){ | |
| 1832 | + | |
| 1833 | + pro_off1=await th.multiple_stores_pro(i,j) | |
| 1834 | + } | |
| 1835 | + } | |
| 1836 | 1836 | } |
| 1837 | + | |
| 1838 | + if (pro_off1) { | |
| 1839 | + pro_off=true | |
| 1840 | + let txt1 = "requestData[" + i + "].pro_off"; | |
| 1841 | + e.setData({ | |
| 1842 | + [txt1]: true, | |
| 1843 | + [txt]: 0, | |
| 1844 | + }); | |
| 1837 | 1845 | |
| 1838 | - //-- 如果这个商品是线下取价的时候 -- | |
| 1839 | - if (item[j].is_offline && item[j].prom_type != 7) { | |
| 1840 | - offline_price += (item[j].goods_price - item[j].offline_price) * item[j].goods_num; | |
| 1841 | - offline_num += item[j].goods_num; | |
| 1846 | + wx.showToast({ | |
| 1847 | + title: '已超出优惠促销次数', | |
| 1848 | + icon: 'none', | |
| 1849 | + }); | |
| 1850 | + | |
| 1851 | + }else{ | |
| 1852 | + e.setData({ | |
| 1853 | + [txt]: !e.data.checkAllToggle, | |
| 1854 | + }) | |
| 1855 | + | |
| 1856 | + if (!e.data.checkAllToggle) { | |
| 1857 | + //组合购的金额要另外算 | |
| 1858 | + if (item[j].prom_type != 7 && item[j].prom_type != 10) | |
| 1859 | + tfeel += item[j].goods_num * item[j].goods_price; | |
| 1860 | + t_num += item[j].goods_num; | |
| 1861 | + } | |
| 1862 | + | |
| 1863 | + //-- 如果这个商品是线下取价的时候 -- | |
| 1864 | + if (item[j].is_offline && item[j].prom_type != 7) { | |
| 1865 | + offline_price += (item[j].goods_price - item[j].offline_price) * item[j].goods_num; | |
| 1866 | + offline_num += item[j].goods_num; | |
| 1867 | + } | |
| 1842 | 1868 | } |
| 1843 | 1869 | |
| 1870 | + | |
| 1844 | 1871 | } |
| 1845 | 1872 | } |
| 1846 | 1873 | |
| ... | ... | @@ -1852,15 +1879,23 @@ Page({ |
| 1852 | 1879 | }); |
| 1853 | 1880 | return false; |
| 1854 | 1881 | } else { |
| 1855 | - | |
| 1882 | + | |
| 1856 | 1883 | for (var i = 0; i < dda.length; i++) { |
| 1857 | 1884 | |
| 1858 | - if (!e.data.checkAllToggle) { | |
| 1859 | - var txt = "requestData[" + i + "].selected"; | |
| 1860 | - e.setData({ | |
| 1861 | - [txt]: 1, | |
| 1862 | - }); | |
| 1863 | - } | |
| 1885 | + // if (!e.data.checkAllToggle) { | |
| 1886 | + //多门店优惠促销次数控制 | |
| 1887 | + if(dda[i].pro_off){ | |
| 1888 | + var txt = "requestData[" + i + "].selected"; | |
| 1889 | + e.setData({ | |
| 1890 | + [txt]: 0, | |
| 1891 | + }); | |
| 1892 | + }else{ | |
| 1893 | + var txt = "requestData[" + i + "].selected"; | |
| 1894 | + e.setData({ | |
| 1895 | + [txt]: 1, | |
| 1896 | + }); | |
| 1897 | + } | |
| 1898 | + // } | |
| 1864 | 1899 | |
| 1865 | 1900 | //总的价格,把组合商品的价格拿出来 |
| 1866 | 1901 | var zh_calc_res = zh_calc.calculate_zh(dda, i, this); |
| ... | ... | @@ -1893,9 +1928,18 @@ Page({ |
| 1893 | 1928 | } |
| 1894 | 1929 | } |
| 1895 | 1930 | } |
| 1896 | - | |
| 1931 | + //多门店优惠次数控制 | |
| 1932 | + if (pro_off) { | |
| 1933 | + e.setData({ | |
| 1934 | + checkAllToggle: false, | |
| 1935 | + }); | |
| 1936 | + }else{ | |
| 1937 | + e.setData({ | |
| 1938 | + checkAllToggle: !e.data.checkAllToggle, | |
| 1939 | + }); | |
| 1940 | + } | |
| 1897 | 1941 | e.setData({ |
| 1898 | - checkAllToggle: !e.data.checkAllToggle, | |
| 1942 | + // checkAllToggle: !e.data.checkAllToggle, | |
| 1899 | 1943 | total_fee: tfeel.toFixed(2), |
| 1900 | 1944 | total_num: t_num, |
| 1901 | 1945 | }); |
| ... | ... | @@ -1992,7 +2036,10 @@ Page({ |
| 1992 | 2036 | return false; |
| 1993 | 2037 | } |
| 1994 | 2038 | |
| 2039 | + let pro_off=false | |
| 2040 | + | |
| 1995 | 2041 | for (var i = 0; i < item.length; i++) { |
| 2042 | + let pro_off1=false | |
| 1996 | 2043 | var txt = "requestData[" + pitems + "].goods[" + i + "].selected"; |
| 1997 | 2044 | |
| 1998 | 2045 | var gd_info = item[i]; |
| ... | ... | @@ -2036,16 +2083,37 @@ Page({ |
| 2036 | 2083 | |
| 2037 | 2084 | } |
| 2038 | 2085 | |
| 2039 | - | |
| 2040 | - | |
| 2086 | + //判断多店优惠促销次数控制 | |
| 2087 | + if (th.data.requestData.length>1) { | |
| 2088 | + if(gd_info.prom_type==3){ | |
| 2089 | + pro_off1=await th.multiple_stores_pro(pitems,i) | |
| 2090 | + } | |
| 2091 | + } | |
| 2092 | + if (pro_off1) { | |
| 2093 | + pro_off=true | |
| 2094 | + e.setData({ | |
| 2095 | + [txt]: 0, | |
| 2096 | + }); | |
| 2097 | + }else{ | |
| 2098 | + e.setData({ | |
| 2099 | + [txt]: Number(!sele), | |
| 2100 | + }); | |
| 2101 | + } | |
| 2102 | + } | |
| 2103 | + var txt = "requestData[" + pitems + "].selected"; | |
| 2104 | + if (pro_off) { | |
| 2105 | + wx.showToast({ | |
| 2106 | + title: '已超出优惠促销次数', | |
| 2107 | + icon: 'none', | |
| 2108 | + }); | |
| 2109 | + e.setData({ | |
| 2110 | + [txt]: 0, | |
| 2111 | + }); | |
| 2112 | + }else{ | |
| 2041 | 2113 | e.setData({ |
| 2042 | 2114 | [txt]: Number(!sele), |
| 2043 | 2115 | }); |
| 2044 | 2116 | } |
| 2045 | - var txt = "requestData[" + pitems + "].selected"; | |
| 2046 | - e.setData({ | |
| 2047 | - [txt]: Number(!sele), | |
| 2048 | - }); | |
| 2049 | 2117 | |
| 2050 | 2118 | e.data.duo_zp_num_arr = {}; |
| 2051 | 2119 | if (sele) { |
| ... | ... | @@ -2057,6 +2125,41 @@ Page({ |
| 2057 | 2125 | } |
| 2058 | 2126 | this.doCheckAll(); |
| 2059 | 2127 | }, |
| 2128 | + | |
| 2129 | + //判断多门店,优惠促销次数的控制 | |
| 2130 | + async multiple_stores_pro(pitems,item){ | |
| 2131 | + let a = this.data.requestData[pitems].goods[item]; | |
| 2132 | + let th=this | |
| 2133 | + let arr_pro=[] | |
| 2134 | + th.data.requestData.map((item,i)=>{ | |
| 2135 | + if (i !=pitems) { | |
| 2136 | + arr_pro.push(item) | |
| 2137 | + } | |
| 2138 | + }) | |
| 2139 | + let prom=null | |
| 2140 | + await getApp().request.promiseGet("/api/weshop/promgoods/get/" + os.stoid + "/" + a.prom_id, {}).then(res => { | |
| 2141 | + if (res.data.code == 0) { | |
| 2142 | + prom = res.data.data; | |
| 2143 | + } | |
| 2144 | + }) | |
| 2145 | + let user_pre_buynum = await this.getUserBuyPromNum_pre(a.prom_id) | |
| 2146 | + let action_num=user_pre_buynum+1; | |
| 2147 | + arr_pro.map(item=>{ | |
| 2148 | + item.goods.map(ite=>{ | |
| 2149 | + if(ite.prom_type==3 && ite.prom_id==a.prom_id && !ite.is_gift && ite.selected){ | |
| 2150 | + action_num+=1; | |
| 2151 | + } | |
| 2152 | + }) | |
| 2153 | + }) | |
| 2154 | + if (prom && action_num>prom.limit_num) { | |
| 2155 | + return true | |
| 2156 | + }else{ | |
| 2157 | + return false | |
| 2158 | + } | |
| 2159 | + }, | |
| 2160 | + | |
| 2161 | + | |
| 2162 | + | |
| 2060 | 2163 | //---------------单选,也要判断门店的配送方式是否一致-------------- |
| 2061 | 2164 | check_th_item: async function (t) { |
| 2062 | 2165 | var e = this, th = this, |
| ... | ... | @@ -2156,7 +2259,21 @@ Page({ |
| 2156 | 2259 | } |
| 2157 | 2260 | |
| 2158 | 2261 | } |
| 2262 | + let pro_off=false | |
| 2263 | + //判断多店优惠促销次数控制 | |
| 2264 | + if (th.data.requestData.length>1) { | |
| 2265 | + if(a.prom_type==3 && !a.selected){ | |
| 2266 | + pro_off=await th.multiple_stores_pro(pitems,item) | |
| 2267 | + } | |
| 2268 | + } | |
| 2159 | 2269 | |
| 2270 | + if (pro_off) { | |
| 2271 | + wx.showToast({ | |
| 2272 | + title: '已超出优惠促销次数', | |
| 2273 | + icon: 'none', | |
| 2274 | + }); | |
| 2275 | + return false; | |
| 2276 | + } | |
| 2160 | 2277 | |
| 2161 | 2278 | |
| 2162 | 2279 | e.setData({ | ... | ... |