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

This commit is contained in:
502647092 2023-12-05 03:10:32 +00:00
parent f73c0cca17
commit 46a0696944

View File

@ -13,6 +13,9 @@
(function () { (function () {
'use strict'; 'use strict';
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function generateRandomString(length) { function generateRandomString(length) {
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
var result = ''; var result = '';
@ -28,7 +31,7 @@
function convertSecondsToMinutesSeconds(seconds) { function convertSecondsToMinutesSeconds(seconds) {
var minutes = Math.floor(seconds / 60); var minutes = Math.floor(seconds / 60);
var remainingSeconds = seconds % 60; var remainingSeconds = seconds % 60;
return minutes + "分" + remainingSeconds + "秒"; return minutes + "分" + remainingSeconds.toFixed(2) + "秒";
} }
function getShopId() { function getShopId() {
return parseInt(localStorage.shopId) return parseInt(localStorage.shopId)
@ -78,15 +81,19 @@
// "queryType": "COOKING" // "queryType": "COOKING"
}) })
} }
async function mealComplete(orderId, cookTime) { async function mealComplete(order, cookTime) {
let orderId = cook.id
let daySn = cook.header.daySn
let result = await request('ShipmentService', 'mealComplete', { let result = await request('ShipmentService', 'mealComplete', {
"shopId": getShopId(), "shopId": getShopId(),
"orderId": orderId "orderId": orderId
}) })
debug('订单 ' + orderId + ' 上报出餐结束.') debug('订单 #' + daySn + ' 上报出餐结束.')
ele.submitOrders.push({ orderId, cookTime }) ele.submitOrders.push({ daySn, orderId, cookTime })
if (ele.submitOrders.length > ele.maxLogOrderLength) if (ele.submitOrders.length > ele.maxLogOrderLength) {
ele.submitOrders = ele.submitOrders.slice(ele.submitOrders.length - ele.maxLogOrderLength) ele.submitOrders = ele.submitOrders.slice(ele.submitOrders.length - ele.maxLogOrderLength)
}
await sleep(5)
await updateOrders() await updateOrders()
return result return result
} }
@ -101,13 +108,15 @@
if (cook.deliveryInfo.distTraceView.traceView.status == '骑士已到店' if (cook.deliveryInfo.distTraceView.traceView.status == '骑士已到店'
&& cook.mealPreparationInfo.minMealCompleteTimeCount < 0 && cook.mealPreparationInfo.minMealCompleteTimeCount < 0
&& leftTime < ele.autoSubmitLeftTimeWhenOnShop) { && leftTime < ele.autoSubmitLeftTimeWhenOnShop) {
debug('订单 ' + orderId + ' 骑手到店 且剩余时间 ' + leftTime + 's 小于 ' + ele.autoSubmitLeftTimeWhenOnShop + 's 模拟提交出餐.') debug('订单 ' + orderId + ' 骑手到店.')
return mealComplete(orderId, cookTime) debug('订单剩余时间 ' + leftTime + 's 小于 ' + ele.autoSubmitLeftTimeWhenOnShop + 's 模拟提交出餐.')
return mealComplete(cook, cookTime)
} }
if (leftTime < ele.autoSubmitLeftTime) { if (leftTime < ele.autoSubmitLeftTime) {
// 大于最小上报时长 并且距离上报超时不足120秒 直接上报出餐 // 大于最小上报时长 并且距离上报超时不足120秒 直接上报出餐
debug('订单 ' + orderId + ' 骑手未到店 且剩余时间 ' + leftTime + 's 小于 ' + ele.autoSubmitLeftTimeWhenOnShop + 's 模拟提交出餐.') debug('订单 ' + orderId + ' 骑手未到店.')
return mealComplete(orderId, cookTime) debug('订单剩余时间 ' + leftTime + 's 小于 ' + ele.autoSubmitLeftTimeWhenOnShop + 's 模拟提交出餐.')
return mealComplete(cook, cookTime)
} }
debug('订单 ' + orderId + ' 还剩 ' + cook.mealPreparationInfo.commonShowTime + 's 上报超时.') debug('订单 ' + orderId + ' 还剩 ' + cook.mealPreparationInfo.commonShowTime + 's 上报超时.')
cook.mealPreparationInfo.minMealCompleteTimeCount -= 5 cook.mealPreparationInfo.minMealCompleteTimeCount -= 5
@ -123,8 +132,9 @@
function debug(msg) { function debug(msg) {
try { try {
ele.logs.push('[' + (new Date().toLocaleTimeString()) + '] ' + msg) ele.logs.push('[' + (new Date().toLocaleTimeString()) + '] ' + msg)
if (ele.logs.length > ele.maxLogLength) if (ele.logs.length > ele.maxLogLength) {
ele.logs = ele.logs.slice(ele.logs.length - ele.maxLogLength) ele.logs = ele.logs.slice(ele.logs.length - ele.maxLogLength)
}
let title = '饿了么自动出餐 By MiaoWoo </br>' let title = '饿了么自动出餐 By MiaoWoo </br>'
let configInfo = '当前配置: </br><div class="ant-alert-content">' let configInfo = '当前配置: </br><div class="ant-alert-content">'
+ '骑手到店 提前 ' + ele.autoSubmitLeftTimeWhenOnShop + 's 出餐 ' + '骑手到店 提前 ' + ele.autoSubmitLeftTimeWhenOnShop + 's 出餐 '
@ -137,7 +147,7 @@
+ '</div>' + '</div>'
let orderInfo = '进行中的订单信息: </br><div class="ant-alert-content">' let orderInfo = '进行中的订单信息: </br><div class="ant-alert-content">'
+ (ele.processOrders.length + (ele.processOrders.length
? ele.processOrders.map(o => '订单: ' + o.id + ' 出餐状态 ' + (o.mealPreparationInfo.mealComplete ? '已出餐' : '未出餐') + ' 配送状态 ' + o.deliveryInfo.distTraceView.traceView.status).join('</br>') ? ele.processOrders.map(o => ' 订单: #' + o.header.daySn + ' 出餐状态 ' + (o.mealPreparationInfo.mealComplete ? '已出餐' : '未出餐') + ' 配送状态 ' + o.deliveryInfo.distTraceView.traceView.status).join('</br>')
: '当前没有进行中的订单.') : '当前没有进行中的订单.')
+ '</div>' + '</div>'
let logs = '运行日志: </br><div class="ant-alert-content">' let logs = '运行日志: </br><div class="ant-alert-content">'
@ -165,7 +175,7 @@
updateOrders() updateOrders()
}, 5000) }, 5000)
setInterval(() => { checkCooking() }, 5000) setInterval(() => { checkCooking() }, 5000)
setInterval(() => { updateOrders() }, 30000) setInterval(() => { updateOrders() }, 20000)
} }
var ele = { var ele = {
logs: [], logs: [],