1
0
Fork 0

fix: 订单重复发货处理

master
502647092 1 year ago
parent b0d882e3d3
commit effbbc5f77
  1. 35
      mcbbs/vending-machine.user.js

@ -1,7 +1,7 @@
// ==UserScript==
// @name MCBBS自动售卖机
// @namespace https://miaowoo.cc/
// @version 0.7.2
// @version 0.8.0
// @description 自动售卖道具
// @author MiaoWoo
// @match https://www.mcbbs.net/home.php?mod=magic**
@ -36,12 +36,14 @@
}
async function main() {
params = location.href.split('?')[1].split('&').map(s => s.split('=')).reduce((pre, cur, index) => { pre[cur[0]] = cur[1]; return pre }, {})
if (!params.nodeType) { return console.log('nodeType is undefined skip...') }
if (!params.action) { return refresh() }
if (document.getElementsByTagName('h1')[0].innerText.startsWith(504)) {
let errorh1 = document.getElementsByTagName('h1')[0]
if (errorh1 && errorh1.innerText.startsWith(50)) {
return refresh()
}
let taskId = setTimeout(refresh, 60000)
createMenu()
if (!params.nodeType) { return console.log('nodeType is undefined skip...') }
if (!params.action) { return refresh() }
console.log(params)
try {
storeUsername = document.getElementsByClassName('username')[0].innerText
@ -52,6 +54,7 @@
} else {
updateStatus('')
}
clearTimeout(taskId)
switch (params.nodeType) {
case "master":
master(params)
@ -135,9 +138,6 @@
async function clearOrderCache(order_id) {
await fetch('https://reward.yumc.pw/mcbbs/clearOrderCache/order_id/' + order_id).then(r => r.json())
}
async function duplicateNotify(order_id, goods_amount) {
await fetch(`https://reward.yumc.pw/mcbbs/duplicateNotify/order_id/${order_id}/goods_amount/${goods_amount}`).then(r => r.json())
}
async function handleLowStock(order, stock) {
if (order.allowAutoBuy) {
await clearOrderCache(order.order_id)
@ -209,8 +209,23 @@
clearTimeout(timeoutTask)
return setTimeout(() => sendOrderAction(openFn), 2000)
}
try { openFn() } catch (ex) { }
let order = result.data
if (store.getItem(lastOrderKey) == order.order_id) {
let finish = await fetch('https://reward.yumc.pw/mcbbs/updateOrder', {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"order_id": order.order_id,
"status": 2,
"remark": "当前订单可能重复发货 如未到帐 请联系管理员!"
})
}).then(r => r.json())
return
}
try { openFn() } catch (ex) { }
if (!order || !order.order_id) { return setTimeout(() => sendOrderAction(openFn), 2000) }
console.log(`开始发送订单 ${order.order_id}`)
let username = undefined
@ -228,7 +243,6 @@
amount.value = order.goods_amount
let remark = username.parentNode.parentNode.nextElementSibling.nextElementSibling.childNodes[3].childNodes[0]
remark.value = `圈云盒子 自动发货订单: ${order.order_id} 物品: ${order.goods_name} 数量: ${order.goods_amount} 发货账号: ${storeUsername}`
store.setItem(lastOrderKey, order.order_id)
await sleep(300)
jq('#operatesubmit').click()
await sleep(500)
@ -250,6 +264,9 @@
await handleLowStock(order, stock)
}
try {
if (!info && !error) {
store.setItem(lastOrderKey, order.order_id)
}
let finish = await fetch('https://reward.yumc.pw/mcbbs/updateOrder', {
method: "POST",
headers: {

Loading…
Cancel
Save