更新 ele/auto-meal-complete.user.js

This commit is contained in:
502647092 2023-12-05 07:49:42 +00:00
parent 0829118cc7
commit e92b138a30

View File

@ -31,7 +31,7 @@
function convertSecondsToMinutesSeconds(seconds) {
var minutes = Math.floor(seconds / 60);
var remainingSeconds = seconds % 60;
return minutes + "分" + remainingSeconds.toFixed(2) + "秒";
return minutes + "分" + remainingSeconds.toFixed(0) + "秒";
}
function getShopId() {
return parseInt(localStorage.shopId)
@ -81,7 +81,7 @@
// "queryType": "COOKING"
})
}
async function mealComplete(cook, cookTime) {
async function mealComplete(cook, cookTime, tip) {
let orderId = cook.id
let daySn = cook.header.daySn
let result = await request('ShipmentService', 'mealComplete', {
@ -89,10 +89,11 @@
"orderId": orderId
})
debug('订单 #' + daySn + ' 上报出餐结束.')
ele.submitOrders.push({ daySn, orderId, cookTime })
ele.submitOrders.push({ completeTime: new Date().toLocaleTimeString(), daySn, orderId, tip, cookTime })
if (ele.submitOrders.length > ele.maxLogOrderLength) {
ele.submitOrders = ele.submitOrders.slice(ele.submitOrders.length - ele.maxLogOrderLength)
}
localStorage.setItem(SubmitOrdersKey, JSON.stringify(ele.submitOrders))
await sleep(5)
await updateOrders()
return result
@ -109,12 +110,12 @@
&& cook.mealPreparationInfo.minMealCompleteTimeCount < 0
&& leftTime < ele.autoSubmitLeftTimeWhenOnShop) {
debug('订单 #' + daySn + ' 骑手到店 订单剩余时间 ' + leftTime + 's 小于 ' + ele.autoSubmitLeftTimeWhenOnShop + 's 模拟提交出餐.')
return mealComplete(cook, cookTime)
return mealComplete(cook, cookTime, '骑手到店出餐')
}
if (leftTime < ele.autoSubmitLeftTime) {
// 大于最小上报时长 并且距离上报超时不足120秒 直接上报出餐
debug('订单 #' + daySn + ' 骑手未到店 订单剩余时间 ' + leftTime + 's 小于 ' + ele.autoSubmitLeftTimeWhenOnShop + 's 模拟提交出餐.')
return mealComplete(cook, cookTime)
return mealComplete(cook, cookTime, '骑手未到店出餐')
}
debug('订单 #' + daySn + ' 还剩 ' + cook.mealPreparationInfo.commonShowTime + 's 上报超时.')
cook.mealPreparationInfo.minMealCompleteTimeCount -= 5
@ -123,7 +124,6 @@
}
async function updateOrders() {
let orders = await queryInProcessOrders()
ele.autoCheckTime = Date.now() / 1000
ele.processOrders = orders.result || []
debug('更新订单数据 目前进行中订单: ' + ele.processOrders.length + '个')
}
@ -140,7 +140,8 @@
+ '</div>'
let submitInfo = '已自动出餐的订单信息: </br><div class="ant-alert-content">'
+ (ele.submitOrders.length
? ele.submitOrders.map(o => '订单: ' + o.orderId + ' 出餐用时 ' + convertSecondsToMinutesSeconds(o.cookTime)).join('</br>')
? ele.submitOrders.map(o => '[' + o.completeTime + '] 订单: #' + o.daySn
+ ' 出餐用时 ' + convertSecondsToMinutesSeconds(o.cookTime) + ' ' + o.tip).join('</br>')
: '当前没有自动出餐的订单.')
+ '</div>'
let orderInfo = '进行中的订单信息: </br><div class="ant-alert-content">'
@ -178,13 +179,14 @@
setInterval(() => { checkCooking() }, 5000)
setInterval(() => { updateOrders() }, 20000)
}
var SubmitOrdersKey = 'AutoMealComplete:SubmitOrders'
var ele = {
logs: [],
maxLogLength: 15,
maxLogOrderLength: 5,
orderStatus: {},
processOrders: [],
submitOrders: [],
submitOrders: JSON.parse(localStorage.getItem(SubmitOrdersKey)),
autoCheckTask: undefined,
autoSubmitLeftTime: 180,
autoSubmitLeftTimeWhenOnShop: 300,