"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.shipConfirmSuccess = exports.getExpressPrintInfo = exports.getMpShipState = void 0; const types_1 = require("oak-domain/lib/types"); const ship_1 = require("../utils/ship"); const shipClazz_1 = require("../utils/shipClazz"); const uuid_1 = require("oak-domain/lib/utils/uuid"); /** * 获取小程序订单发货状态 * @param params * @param context */ async function getMpShipState(params, context) { const application = context.getApplication(); const { type, } = application; if (type === 'wechatMp') { const { shipId } = params; const shipState = await (0, ship_1.getOrderShipState)(context, shipId); return shipState; } } exports.getMpShipState = getMpShipState; /** * 获取打印面单 */ async function getExpressPrintInfo(params, context) { const { shipId } = params; const [ship] = await context.select('ship', { data: { id: 1, type: 1, entity: 1, entityId: 1, extraShipId: 1, }, filter: { id: shipId, } }, { forUpdate: true }); const { type, entity, entityId, extraShipId } = ship; if (!entity || !entityId || !extraShipId || type !== 'express') { throw new types_1.OakPreConditionUnsetException("error::ship.noClazz", "ship", undefined, "oak-pay-business"); } const clazz = await (0, shipClazz_1.getShipClazz)(entity, entityId, context); return await clazz.getPrintInfo(shipId, context); } exports.getExpressPrintInfo = getExpressPrintInfo; /** * 小程序确认收货组件成功后更新ship状态 */ async function shipConfirmSuccess(params, context) { const application = context.getApplication(); const { type, } = application; if (type === 'wechatMp') { try { const { shipId } = params; const shipState = await (0, ship_1.getOrderShipState)(context, shipId); if (shipState === 'received') { //微信端已确认收货 const [ship] = await context.select('ship', { data: { id: 1, iState: 1, }, filter: { id: shipId, } }, { forUpdate: true }); if (ship.iState === 'receiving') { await context.operate('ship', { id: await (0, uuid_1.generateNewIdAsync)(), action: 'succeedReceiving', data: {}, filter: { id: shipId, }, }, {}); return true; } } } catch (err) { return false; } } return false; } exports.shipConfirmSuccess = shipConfirmSuccess;