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

This commit is contained in:
502647092 2023-12-13 06:55:25 +00:00
parent eea4e3aa5e
commit b284aad0d9

View File

@ -33,15 +33,12 @@
var remainingSeconds = seconds % 60; var remainingSeconds = seconds % 60;
return minutes + "分" + remainingSeconds.toFixed(0) + "秒"; return minutes + "分" + remainingSeconds.toFixed(0) + "秒";
} }
function getShopId() {
return parseInt(localStorage.shopId)
}
function getShopMeta() { function getShopMeta() {
return { return {
"appVersion": "1.0.0", "appVersion": "1.0.0",
"appName": "melody", "appName": "melody",
"ksid": localStorage.ksid, "ksid": localStorage.ksid,
"shopId": getShopId() "shopId": ele.shopId
} }
} }
function request(service, method, params) { function request(service, method, params) {
@ -76,7 +73,7 @@
function queryInProcessOrders() { function queryInProcessOrders() {
return request('OrderWebService', 'queryInProcessOrders', { return request('OrderWebService', 'queryInProcessOrders', {
"shopId": getShopId(), "shopId": ele.shopId,
"queryType": "ALL", "queryType": "ALL",
// "queryType": "COOKING" // "queryType": "COOKING"
}) })
@ -85,7 +82,7 @@
let orderId = cook.id let orderId = cook.id
let daySn = cook.header.daySn let daySn = cook.header.daySn
let result = await request('ShipmentService', 'mealComplete', { let result = await request('ShipmentService', 'mealComplete', {
"shopId": getShopId(), "shopId": ele.shopId,
"orderId": orderId "orderId": orderId
}) })
debug('订单 #' + daySn + ' 上报出餐结束.') debug('订单 #' + daySn + ' 上报出餐结束.')
@ -103,33 +100,38 @@
} }
async function checkCooking() { async function checkCooking() {
if (!ele.processOrders) return if (!ele.processOrders) return
for (const cook of ele.processOrders) { for (const order of ele.processOrders) {
let daySn = cook.header.daySn let daySn = order.header.daySn
if (!cook.mealPreparationInfo || cook.mealPreparationInfo.mealComplete) continue if (!order.mealPreparationInfo || order.mealPreparationInfo.mealComplete) continue
// 骑手到店 并且大于最小上报时长 直接上报出餐 // 骑手到店 并且大于最小上报时长 直接上报出餐
let cookTime = cook.mealPreparationInfo.cookTime -= 5 let cookTime = order.mealPreparationInfo.cookTime -= 5
let leftTime = cook.mealPreparationInfo.commonShowTime -= 5 let leftTime = order.mealPreparationInfo.commonShowTime -= 5
let submitLeft = cook.mealPreparationInfo.submitLeft -= 5 let submitLeft = order.mealPreparationInfo.submitLeft -= 5
if (cook.mealPreparationInfo.minMealCompleteTimeCount < 0) { order.mealPreparationInfo.minMealCompleteTimeCount -= 5
if (cook.deliveryInfo.deliveOnShop && leftTime < ele.autoSubmitLeftTimeWhenOnShop) { if (order.mealPreparationInfo.minMealCompleteTimeCount < 0) {
if (order.deliveryInfo.deliveOnShop && leftTime < ele.autoSubmitLeftTimeWhenOnShop) {
debug('订单 #' + daySn + ' 骑手已到店.') debug('订单 #' + daySn + ' 骑手已到店.')
debug('订单 #' + daySn + ' 剩余出餐时间 ' + leftTime + 's 小于 ' + ele.autoSubmitLeftTimeWhenOnShop + 's 模拟提交出餐.') debug('订单 #' + daySn + ' 剩余出餐时间 ' + leftTime + 's 小于 ' + ele.autoSubmitLeftTimeWhenOnShop + 's 模拟提交出餐.')
return mealComplete(cook, cookTime, '骑手已到店') return mealComplete(order, cookTime, '骑手已到店')
} }
if (leftTime < ele.autoSubmitLeftTime) { if (leftTime < ele.autoSubmitLeftTime) {
// 大于最小上报时长 并且距离上报超时不足 直接上报出餐 // 大于最小上报时长 并且距离上报超时不足 直接上报出餐
debug('订单 #' + daySn + ' 骑手未到店.') debug('订单 #' + daySn + ' 骑手未到店.')
debug('订单 #' + daySn + ' 剩余出餐时间 ' + leftTime + 's 小于 ' + ele.autoSubmitLeftTime + 's 模拟提交出餐.') debug('订单 #' + daySn + ' 剩余出餐时间 ' + leftTime + 's 小于 ' + ele.autoSubmitLeftTime + 's 模拟提交出餐.')
return mealComplete(cook, cookTime, '骑手未到店') return mealComplete(order, cookTime, '骑手未到店')
} }
if (submitLeft < 0) { if (submitLeft < 0) {
// 非预订单且备餐时间大于最大时间 // 非预订单且备餐时间大于最大时间
debug('订单 #' + daySn + ' 备餐时间过长.') debug('订单 #' + daySn + ' 备餐时间过长.')
debug('订单 #' + daySn + ' 备餐时间 ' + cookTime + 's 大于 ' + ele.autoSubmitMaxCookTime + 's 模拟提交出餐.') debug('订单 #' + daySn + ' 备餐时间 ' + cookTime + 's 大于 ' + ele.autoSubmitMaxCookTime + 's 模拟提交出餐.')
return mealComplete(cook, cookTime, '备餐已完成') return mealComplete(order, cookTime, '备餐已完成')
} }
} }
debug('订单 #' + daySn + ' 还剩 ' + leftTime + 's 上报超时 将于 ' + submitLeft + 's 后自动上报.') if (submitLeft < 20) {
debug('订单 #' + daySn + ' 还剩 ' + leftTime + 's 上报超时 将于 ' + submitLeft + 's 后自动上报.')
} else {
updateInfo()
}
} }
} }
function syncOrderTime(cook) { function syncOrderTime(cook) {
@ -153,16 +155,21 @@
for (const order of ele.processOrders) { for (const order of ele.processOrders) {
syncOrderTime(order) syncOrderTime(order)
} }
debug(originCount != ele.processOrders.length ? '更新订单数据 目前进行中订单: ' + ele.processOrders.length + '个' : '') if (originCount != ele.processOrders.length) {
debug('更新订单数据 目前进行中订单: ' + ele.processOrders.length + '个')
} else {
updateInfo()
}
} }
function debug(msg) { function debug(msg) {
ele.logs.push('[' + (new Date().toLocaleTimeString()) + '] ' + msg)
if (ele.logs.length > ele.maxLogLength) {
ele.logs = ele.logs.slice(ele.logs.length - ele.maxLogLength)
}
updateInfo()
}
function updateInfo() {
try { try {
if (msg) {
ele.logs.push('[' + (new Date().toLocaleTimeString()) + '] ' + msg)
if (ele.logs.length > ele.maxLogLength) {
ele.logs = ele.logs.slice(ele.logs.length - ele.maxLogLength)
}
}
let title = `${ele.title} Version: ${ele.version} By ${ele.author}` let title = `${ele.title} Version: ${ele.version} By ${ele.author}`
let configInfo = `当前配置: </br> let configInfo = `当前配置: </br>
<div class="ant-alert-content"> <div class="ant-alert-content">
@ -170,6 +177,17 @@
出餐 最长时间: ${ele.autoSubmitMaxCookTime}s 出餐 最长时间: ${ele.autoSubmitMaxCookTime}s
骑手未到店: ${ele.autoSubmitLeftTime}s 骑手已到店: ${ele.autoSubmitLeftTimeWhenOnShop}s</br> 骑手未到店: ${ele.autoSubmitLeftTime}s 骑手已到店: ${ele.autoSubmitLeftTimeWhenOnShop}s</br>
</div>` </div>`
let orderInfo = `进行中的订单信息 更新时间:${new Date().toLocaleTimeString()}</br>
<div class="ant-alert-content">
${ele.processOrders.length
? ele.processOrders.map(o => ' 订单: #' + o.header.daySn
+ ' 出餐状态 ' + (o.mealPreparationInfo.mealComplete ? '已出餐'
: `未出餐${o.mealPreparationInfo.minMealCompleteTimeCount > 0 ? `(${-o.mealPreparationInfo.minMealCompleteTimeCount}s)` :
o.mealPreparationInfo.submitLeft > 0 ? `(${o.mealPreparationInfo.submitLeft}s)` : ''}`)
+ ' 配送状态 ' + o.deliveryInfo.distTraceView.traceView.status + ''
+ (o.deliveryInfo.deliveryDistance ? ' ' + o.deliveryInfo.deliveryDistance : '')).join('</br>')
: '当前没有进行中的订单.'}
</div>`
let submitInfo = `已自动出餐的订单信息: </br> let submitInfo = `已自动出餐的订单信息: </br>
<div class="ant-alert-content"> <div class="ant-alert-content">
${ele.submitOrders.length ${ele.submitOrders.length
@ -178,16 +196,6 @@
+ ' 出餐用时 ' + convertSecondsToMinutesSeconds(o.cookTime) + ' ' + o.tip).join('</br>') + ' 出餐用时 ' + convertSecondsToMinutesSeconds(o.cookTime) + ' ' + o.tip).join('</br>')
: '当前没有自动出餐的订单.'} : '当前没有自动出餐的订单.'}
</div>` </div>`
let orderInfo = `进行中的订单信息 更新时间:${new Date().toLocaleTimeString()}</br>
<div class="ant-alert-content">
${ele.processOrders.length
? ele.processOrders.map(o => ' 订单: #' + o.header.daySn
+ ' 出餐状态 ' + (o.mealPreparationInfo.mealComplete ? '已出餐' : '未出餐')
+ (o.mealPreparationInfo.minMealCompleteTimeCount > 0 ? `(${o.mealPreparationInfo.minMealCompleteTimeCount}s)` : '')
+ ' 配送状态 ' + o.deliveryInfo.distTraceView.traceView.status + ''
+ (o.deliveryInfo.deliveryDistance ? ' ' + o.deliveryInfo.deliveryDistance : '')).join('</br>')
: '当前没有进行中的订单.'}
</div>`
let logs = `运行日志: </br> let logs = `运行日志: </br>
<div class="ant-alert-content"> <div class="ant-alert-content">
${ele.logs.join('</br>')} ${ele.logs.join('</br>')}
@ -235,18 +243,17 @@
title: '饿了么自动出餐', title: '饿了么自动出餐',
version: '0.0.5', version: '0.0.5',
author: 'MiaoWoo', author: 'MiaoWoo',
logs: [], shopId: parseInt(localStorage.shopId),
checkInterval: 5, checkInterval: 5,
syncInterval: 15, syncInterval: 15,
maxLogLength: 20, maxLogLength: 20,
maxLogOrderLength: 20, maxLogOrderLength: 20,
orderStatus: {},
processOrders: [],
submitOrders: JSON.parse(localStorage.getItem(SubmitOrdersKey)),
autoCheckTask: undefined,
autoSubmitLeftTime: 180, autoSubmitLeftTime: 180,
autoSubmitMaxCookTime: 420, autoSubmitMaxCookTime: 420,
autoSubmitLeftTimeWhenOnShop: 300, autoSubmitLeftTimeWhenOnShop: 300,
logs: [],
processOrders: [],
submitOrders: JSON.parse(localStorage.getItem(SubmitOrdersKey)),
debug: debug, debug: debug,
syncOrders: syncOrders, syncOrders: syncOrders,
checkCooking: checkCooking, checkCooking: checkCooking,