Commit de1adffa6a40c47a6aab258bd69218aed9760c78
1 parent
2d90d4d3
fix:服务卡订单立即支付限制库存限购
Showing
1 changed file
with
163 additions
and
22 deletions
pages/user/order_list/order_list.js
... | ... | @@ -2224,35 +2224,176 @@ Page({ |
2224 | 2224 | }, |
2225 | 2225 | |
2226 | 2226 | // 卡项订单 - 立即支付 |
2227 | - pay(e) { | |
2227 | + pay: async function(e) { | |
2228 | 2228 | let index = e.currentTarget.dataset.index; |
2229 | 2229 | let item = this.data.cardList[index]; |
2230 | 2230 | let order_sn = item.order_sn; |
2231 | 2231 | let order_id = item.order_id; |
2232 | 2232 | let store_id = app.globalData.setting.stoid; |
2233 | - // console.log('go1!!!!!!!!!!!!!!!!!!!!!!!!!',index,item,order_sn,store_id); | |
2233 | + let user_id = oo.user_id; | |
2234 | + let flag = true; | |
2235 | + | |
2236 | + | |
2237 | + // 如果是普通购买或单独购买,不用判断 | |
2238 | + // 如果是秒杀购买:1、判断活动是否变化;2、是否超出限购 | |
2239 | + | |
2240 | + let list = item.list; | |
2241 | + for(const it of list) { | |
2242 | + if(it.prom_type == 1) { | |
2243 | + let act_details = null; | |
2244 | + let redis_num = 0; | |
2245 | + let promcardbuynum = 0; | |
2246 | + let qty = it.qty; | |
2247 | + | |
2248 | + | |
2249 | + await getApp().request.promiseGet('/api/ms/flash_sale/getNew/' + store_id + '/' + user_id + '/' + it.prom_id, {}).then(res => { | |
2250 | + console.log('11111111====>>>'); | |
2251 | + if(res.data.code == 0) { | |
2252 | + console.log('当前的秒杀活动信息:', res.data.data); | |
2253 | + act_details = res.data.data; | |
2254 | + if(act_details.is_end == 1) { | |
2255 | + wx.showModal({ | |
2256 | + title: '提示', | |
2257 | + content: '活动已结束,无法支付,请取消订单!', | |
2258 | + showCancel: false, | |
2259 | + }); | |
2260 | + flag = false; | |
2261 | + return false; | |
2262 | + }; | |
2263 | + if(act_details.id != it.prom_id) { | |
2264 | + wx.showModal({ | |
2265 | + title: '提示', | |
2266 | + content: '活动发生了变化,无法支付,请取消订单,重新购买!', | |
2267 | + showCancel: false, | |
2268 | + }); | |
2269 | + flag = false; | |
2270 | + return false; | |
2271 | + }; | |
2272 | + }; | |
2273 | + }); | |
2274 | + | |
2275 | + await getApp().request.promiseGet('/api/weshop/activitylist/getActLen/' + store_id + '/' + it.prom_type + '/' + it.prom_id, { | |
2276 | + 1: 1 | |
2277 | + }).then(res => { | |
2278 | + console.log('222222222====>>>'); | |
2279 | + if (res.data.code == 0) { | |
2280 | + // 当前可以购买的数量 | |
2281 | + console.log('redis当前可以购买的数量:', res.data.data); | |
2282 | + redis_num = res.data.data; | |
2283 | + // if(redis_num <=0) { | |
2284 | + // wx.showModal({ | |
2285 | + // title: '提示', | |
2286 | + // content: '活动库存不足,无法支付,请取消订单!', | |
2287 | + // showCancel: false, | |
2288 | + // }); | |
2289 | + // // flag = false; | |
2290 | + // return true; | |
2291 | + // }; | |
2292 | + }; | |
2293 | + }); | |
2294 | + | |
2295 | + await getApp().request.promiseGet("/api/weshop/rechargeServicelist/getUserBuyGoodsNum", { | |
2296 | + data: { | |
2297 | + store_id: store_id, | |
2298 | + user_id: user_id, | |
2299 | + card_id: it.card_id, | |
2300 | + prom_type: it.prom_type, | |
2301 | + prom_id: it.prom_id, | |
2302 | + } | |
2303 | + }).then(res => { | |
2304 | + console.log('333333333====>>>'); | |
2305 | + if (res.data.code == 0) { | |
2306 | + console.log('已经购买的数量:', res.data.data); | |
2307 | + promcardbuynum = res.data.data.promcardbuynum; | |
2308 | + | |
2309 | + | |
2310 | + let limited = act_details.buy_limit; // 限购数量a | |
2311 | + let buyedNum = promcardbuynum; // 自己已经购买的数量b | |
2312 | + let canBuyNum = limited - buyedNum; // 自己还可购买的数量c | |
2313 | + | |
2314 | + | |
2315 | + if(canBuyNum <= 0) { | |
2316 | + wx.showModal({ | |
2317 | + title: '提示', | |
2318 | + content: '您已超出活动限购数量,无法支付,请取消订单!', | |
2319 | + showCancel: false, | |
2320 | + }); | |
2321 | + flag = false; | |
2322 | + return false; | |
2323 | + }; | |
2324 | + | |
2325 | + if(limited > redis_num) { | |
2326 | + if(canBuyNum <= redis_num) { | |
2327 | + if(qty > canBuyNum) { | |
2328 | + wx.showModal({ | |
2329 | + title: '提示', | |
2330 | + content: '您已超出活动限购数量,无法支付,请取消订单!', | |
2331 | + showCancel: false, | |
2332 | + }); | |
2333 | + flag = false; | |
2334 | + return false; | |
2335 | + }; | |
2336 | + | |
2337 | + }; | |
2338 | + | |
2339 | + if(canBuyNum > redis_num) { | |
2340 | + if(qty > redis_num) { | |
2341 | + wx.showModal({ | |
2342 | + title: '提示', | |
2343 | + content: '活动库存不足,无法支付,请取消订单!', | |
2344 | + showCancel: false, | |
2345 | + }); | |
2346 | + flag = false; | |
2347 | + return false; | |
2348 | + }; | |
2349 | + | |
2350 | + }; | |
2351 | + }; | |
2352 | + | |
2353 | + if(limited <= redis_num) { | |
2354 | + if(qty > canBuyNum) { | |
2355 | + wx.showModal({ | |
2356 | + title: '提示', | |
2357 | + content: '您已超出活动限购数量,无法支付,请取消订单!', | |
2358 | + showCancel: false, | |
2359 | + }); | |
2360 | + flag = false; | |
2361 | + return false; | |
2362 | + }; | |
2363 | + }; | |
2364 | + }; | |
2365 | + }); | |
2366 | + | |
2367 | + }; | |
2368 | + | |
2369 | + }; | |
2370 | + | |
2234 | 2371 | |
2235 | - app.request.post('/api/weshop/order/pay/createRechargeOrder', { | |
2236 | - data: { | |
2237 | - parentSn: order_sn, | |
2238 | - store_id: store_id, | |
2239 | - }, | |
2372 | + if(flag) { | |
2373 | + await app.request.promisePost('/api/weshop/order/pay/createRechargeOrder', { | |
2374 | + data: { | |
2375 | + parentSn: order_sn, | |
2376 | + store_id: store_id, | |
2377 | + }, | |
2378 | + }).then(res => { | |
2379 | + // success: function(res) { | |
2380 | + var n = res.data.data; | |
2381 | + self.weixinPay(n, function() { | |
2382 | + app.showWarning('支付成功'); | |
2383 | + | |
2384 | + }, function() { | |
2385 | + app.showWarning('支付失败'); | |
2386 | + // setTimeout(function() { | |
2387 | + // wx.reLaunch({ | |
2388 | + // url: '/packageA/pages/cardList/cardList', | |
2389 | + // }) | |
2390 | + // }, 1000) | |
2391 | + }); | |
2392 | + // } | |
2393 | + }); | |
2394 | + }; | |
2395 | + | |
2240 | 2396 | |
2241 | - success: function(res) { | |
2242 | - var n = res.data.data; | |
2243 | - self.weixinPay(n, function() { | |
2244 | - app.showWarning('支付成功'); | |
2245 | - | |
2246 | - }, function() { | |
2247 | - app.showWarning('支付失败'); | |
2248 | - // setTimeout(function() { | |
2249 | - // wx.reLaunch({ | |
2250 | - // url: '/packageA/pages/cardList/cardList', | |
2251 | - // }) | |
2252 | - // }, 1000) | |
2253 | - }); | |
2254 | - } | |
2255 | - }) | |
2256 | 2397 | }, |
2257 | 2398 | |
2258 | 2399 | //------调起支付框-------- | ... | ... |