同步微信自动确认收货状态
This commit is contained in:
parent
70ed1ca5a6
commit
a1e466f19c
|
|
@ -1,4 +1,4 @@
|
||||||
import { refreshtShipState } from '../utils/ship';
|
import { refreshShipState, refreshMpOrderShipState } from '../utils/ship';
|
||||||
import { mergeOperationResult } from 'oak-domain/lib/utils/operationResult';
|
import { mergeOperationResult } from 'oak-domain/lib/utils/operationResult';
|
||||||
const timers = [
|
const timers = [
|
||||||
{
|
{
|
||||||
|
|
@ -28,7 +28,34 @@ const timers = [
|
||||||
fn: async (context, data) => {
|
fn: async (context, data) => {
|
||||||
const results = [];
|
const results = [];
|
||||||
for (const ship of data) {
|
for (const ship of data) {
|
||||||
const result = await refreshtShipState(ship.id, context);
|
const result = await refreshShipState(ship.id, context);
|
||||||
|
if (result) {
|
||||||
|
results.push(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (results.length === 0) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return results.reduce((prev, cur) => mergeOperationResult(prev, cur));
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '同步微信小程序虚拟ship状态',
|
||||||
|
cron: '0 0 * * * ?',
|
||||||
|
entity: 'ship',
|
||||||
|
filter: {
|
||||||
|
type: 'virtual',
|
||||||
|
iState: {
|
||||||
|
$nin: ['received', 'cancelled', 'rejected'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
projection: {
|
||||||
|
id: 1,
|
||||||
|
},
|
||||||
|
fn: async (context, data) => {
|
||||||
|
const results = [];
|
||||||
|
for (const ship of data) {
|
||||||
|
const result = await refreshMpOrderShipState(ship.id, context);
|
||||||
if (result) {
|
if (result) {
|
||||||
results.push(result);
|
results.push(result);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,19 +14,26 @@ export declare function maskPhone(phone: string): string;
|
||||||
*/
|
*/
|
||||||
export declare function uploadShippingInfo(shipId: string, context: BRC): Promise<void>;
|
export declare function uploadShippingInfo(shipId: string, context: BRC): Promise<void>;
|
||||||
/**
|
/**
|
||||||
* 获取小程序物流状态
|
* 获取小程序订单状态
|
||||||
* @param context
|
* @param context
|
||||||
* @param shipId
|
* @param shipId
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export declare function getOrderShipState(context: BRC, shipId: string): Promise<string | undefined>;
|
export declare function getOrderShipState(context: BRC, shipId: string): Promise<string | undefined>;
|
||||||
|
/**
|
||||||
|
* 刷新小程序订单状态(自动确认收货)
|
||||||
|
* @param context
|
||||||
|
* @param shipId
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export declare function refreshMpOrderShipState(shipId: string, context: BRC): Promise<import("oak-domain/lib/types").OperationResult<EntityDict> | undefined>;
|
||||||
/**
|
/**
|
||||||
* 刷新ship的物流状态
|
* 刷新ship的物流状态
|
||||||
* @param ship
|
* @param ship
|
||||||
* @param context
|
* @param context
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export declare function refreshtShipState(shipId: string, context: BRC): Promise<import("oak-domain/lib/types").OperationResult<EntityDict> | undefined>;
|
export declare function refreshShipState(shipId: string, context: BRC): Promise<import("oak-domain/lib/types").OperationResult<EntityDict> | undefined>;
|
||||||
/**
|
/**
|
||||||
* 小程序确认收货提醒
|
* 小程序确认收货提醒
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -246,7 +246,7 @@ export async function uploadShippingInfo(shipId, context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 获取小程序物流状态
|
* 获取小程序订单状态
|
||||||
* @param context
|
* @param context
|
||||||
* @param shipId
|
* @param shipId
|
||||||
* @returns
|
* @returns
|
||||||
|
|
@ -315,13 +315,58 @@ export async function getOrderShipState(context, shipId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 刷新小程序订单状态(自动确认收货)
|
||||||
|
* @param context
|
||||||
|
* @param shipId
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export async function refreshMpOrderShipState(shipId, context) {
|
||||||
|
const [ship] = await context.select('ship', {
|
||||||
|
data: {
|
||||||
|
id: 1,
|
||||||
|
iState: 1,
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
id: shipId,
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
blockTrigger: true,
|
||||||
|
forUpdate: true
|
||||||
|
});
|
||||||
|
const mpState = await getOrderShipState(context, shipId);
|
||||||
|
let action = undefined;
|
||||||
|
switch (mpState) {
|
||||||
|
case 'shipping': //已发货
|
||||||
|
action = 'ship';
|
||||||
|
break;
|
||||||
|
case 'received': //已收货
|
||||||
|
action = 'succeedReceiving';
|
||||||
|
break;
|
||||||
|
case 'unknow': //不明
|
||||||
|
action = 'unknow';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
action = undefined;
|
||||||
|
}
|
||||||
|
if (action && ship.iState !== mpState) {
|
||||||
|
return await context.operate('ship', {
|
||||||
|
id: await generateNewIdAsync(),
|
||||||
|
action,
|
||||||
|
data: {},
|
||||||
|
filter: {
|
||||||
|
id: ship.id,
|
||||||
|
}
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 刷新ship的物流状态
|
* 刷新ship的物流状态
|
||||||
* @param ship
|
* @param ship
|
||||||
* @param context
|
* @param context
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function refreshtShipState(shipId, context) {
|
export async function refreshShipState(shipId, context) {
|
||||||
const ships = await context.select('ship', {
|
const ships = await context.select('ship', {
|
||||||
data: shipProjection,
|
data: shipProjection,
|
||||||
filter: {
|
filter: {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { mergeOperationResult } from 'oak-domain/lib/utils/operationResult';
|
import { mergeOperationResult } from 'oak-domain/lib/utils/operationResult';
|
||||||
import { shipProjection, refreshtShipState } from '../utils/ship';
|
import { shipProjection, refreshShipState } from '../utils/ship';
|
||||||
const QUERY_PAYING_STATE_GAP = process.env.NODE_ENV === 'production' ? 3600 * 1000 : 60 * 1000;
|
const QUERY_PAYING_STATE_GAP = process.env.NODE_ENV === 'production' ? 3600 * 1000 : 60 * 1000;
|
||||||
const watchers = [
|
const watchers = [
|
||||||
{
|
{
|
||||||
|
|
@ -19,7 +19,7 @@ const watchers = [
|
||||||
fn: async (context, data) => {
|
fn: async (context, data) => {
|
||||||
const results = [];
|
const results = [];
|
||||||
for (const ship of data) {
|
for (const ship of data) {
|
||||||
const result = await refreshtShipState(ship.id, context);
|
const result = await refreshShipState(ship.id, context);
|
||||||
if (result) {
|
if (result) {
|
||||||
results.push(result);
|
results.push(result);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,34 @@ const timers = [
|
||||||
fn: async (context, data) => {
|
fn: async (context, data) => {
|
||||||
const results = [];
|
const results = [];
|
||||||
for (const ship of data) {
|
for (const ship of data) {
|
||||||
const result = await (0, ship_1.refreshtShipState)(ship.id, context);
|
const result = await (0, ship_1.refreshShipState)(ship.id, context);
|
||||||
|
if (result) {
|
||||||
|
results.push(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (results.length === 0) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return results.reduce((prev, cur) => (0, operationResult_1.mergeOperationResult)(prev, cur));
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '同步微信小程序虚拟ship状态',
|
||||||
|
cron: '0 0 * * * ?',
|
||||||
|
entity: 'ship',
|
||||||
|
filter: {
|
||||||
|
type: 'virtual',
|
||||||
|
iState: {
|
||||||
|
$nin: ['received', 'cancelled', 'rejected'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
projection: {
|
||||||
|
id: 1,
|
||||||
|
},
|
||||||
|
fn: async (context, data) => {
|
||||||
|
const results = [];
|
||||||
|
for (const ship of data) {
|
||||||
|
const result = await (0, ship_1.refreshMpOrderShipState)(ship.id, context);
|
||||||
if (result) {
|
if (result) {
|
||||||
results.push(result);
|
results.push(result);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,19 +14,26 @@ export declare function maskPhone(phone: string): string;
|
||||||
*/
|
*/
|
||||||
export declare function uploadShippingInfo(shipId: string, context: BRC): Promise<void>;
|
export declare function uploadShippingInfo(shipId: string, context: BRC): Promise<void>;
|
||||||
/**
|
/**
|
||||||
* 获取小程序物流状态
|
* 获取小程序订单状态
|
||||||
* @param context
|
* @param context
|
||||||
* @param shipId
|
* @param shipId
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export declare function getOrderShipState(context: BRC, shipId: string): Promise<string | undefined>;
|
export declare function getOrderShipState(context: BRC, shipId: string): Promise<string | undefined>;
|
||||||
|
/**
|
||||||
|
* 刷新小程序订单状态(自动确认收货)
|
||||||
|
* @param context
|
||||||
|
* @param shipId
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export declare function refreshMpOrderShipState(shipId: string, context: BRC): Promise<import("oak-domain/lib/types").OperationResult<EntityDict> | undefined>;
|
||||||
/**
|
/**
|
||||||
* 刷新ship的物流状态
|
* 刷新ship的物流状态
|
||||||
* @param ship
|
* @param ship
|
||||||
* @param context
|
* @param context
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export declare function refreshtShipState(shipId: string, context: BRC): Promise<import("oak-domain/lib/types").OperationResult<EntityDict> | undefined>;
|
export declare function refreshShipState(shipId: string, context: BRC): Promise<import("oak-domain/lib/types").OperationResult<EntityDict> | undefined>;
|
||||||
/**
|
/**
|
||||||
* 小程序确认收货提醒
|
* 小程序确认收货提醒
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.notifyConfirmReceive = exports.refreshtShipState = exports.getOrderShipState = exports.uploadShippingInfo = exports.maskPhone = exports.shipProjection = void 0;
|
exports.notifyConfirmReceive = exports.refreshShipState = exports.refreshMpOrderShipState = exports.getOrderShipState = exports.uploadShippingInfo = exports.maskPhone = exports.shipProjection = void 0;
|
||||||
const tslib_1 = require("tslib");
|
const tslib_1 = require("tslib");
|
||||||
const oak_external_sdk_1 = require("oak-external-sdk");
|
const oak_external_sdk_1 = require("oak-external-sdk");
|
||||||
const assert_1 = require("oak-domain/lib/utils/assert");
|
const assert_1 = require("oak-domain/lib/utils/assert");
|
||||||
|
|
@ -252,7 +252,7 @@ async function uploadShippingInfo(shipId, context) {
|
||||||
}
|
}
|
||||||
exports.uploadShippingInfo = uploadShippingInfo;
|
exports.uploadShippingInfo = uploadShippingInfo;
|
||||||
/**
|
/**
|
||||||
* 获取小程序物流状态
|
* 获取小程序订单状态
|
||||||
* @param context
|
* @param context
|
||||||
* @param shipId
|
* @param shipId
|
||||||
* @returns
|
* @returns
|
||||||
|
|
@ -322,13 +322,59 @@ async function getOrderShipState(context, shipId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.getOrderShipState = getOrderShipState;
|
exports.getOrderShipState = getOrderShipState;
|
||||||
|
/**
|
||||||
|
* 刷新小程序订单状态(自动确认收货)
|
||||||
|
* @param context
|
||||||
|
* @param shipId
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
async function refreshMpOrderShipState(shipId, context) {
|
||||||
|
const [ship] = await context.select('ship', {
|
||||||
|
data: {
|
||||||
|
id: 1,
|
||||||
|
iState: 1,
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
id: shipId,
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
blockTrigger: true,
|
||||||
|
forUpdate: true
|
||||||
|
});
|
||||||
|
const mpState = await getOrderShipState(context, shipId);
|
||||||
|
let action = undefined;
|
||||||
|
switch (mpState) {
|
||||||
|
case 'shipping': //已发货
|
||||||
|
action = 'ship';
|
||||||
|
break;
|
||||||
|
case 'received': //已收货
|
||||||
|
action = 'succeedReceiving';
|
||||||
|
break;
|
||||||
|
case 'unknow': //不明
|
||||||
|
action = 'unknow';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
action = undefined;
|
||||||
|
}
|
||||||
|
if (action && ship.iState !== mpState) {
|
||||||
|
return await context.operate('ship', {
|
||||||
|
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||||
|
action,
|
||||||
|
data: {},
|
||||||
|
filter: {
|
||||||
|
id: ship.id,
|
||||||
|
}
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.refreshMpOrderShipState = refreshMpOrderShipState;
|
||||||
/**
|
/**
|
||||||
* 刷新ship的物流状态
|
* 刷新ship的物流状态
|
||||||
* @param ship
|
* @param ship
|
||||||
* @param context
|
* @param context
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async function refreshtShipState(shipId, context) {
|
async function refreshShipState(shipId, context) {
|
||||||
const ships = await context.select('ship', {
|
const ships = await context.select('ship', {
|
||||||
data: exports.shipProjection,
|
data: exports.shipProjection,
|
||||||
filter: {
|
filter: {
|
||||||
|
|
@ -392,7 +438,7 @@ async function refreshtShipState(shipId, context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.refreshtShipState = refreshtShipState;
|
exports.refreshShipState = refreshShipState;
|
||||||
/**
|
/**
|
||||||
* 小程序确认收货提醒
|
* 小程序确认收货提醒
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ const watchers = [
|
||||||
fn: async (context, data) => {
|
fn: async (context, data) => {
|
||||||
const results = [];
|
const results = [];
|
||||||
for (const ship of data) {
|
for (const ship of data) {
|
||||||
const result = await (0, ship_1.refreshtShipState)(ship.id, context);
|
const result = await (0, ship_1.refreshShipState)(ship.id, context);
|
||||||
if (result) {
|
if (result) {
|
||||||
results.push(result);
|
results.push(result);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { Timer } from 'oak-domain/lib/types/Timer';
|
||||||
import { EntityDict } from '@oak-app-domain';
|
import { EntityDict } from '@oak-app-domain';
|
||||||
import { BRC } from '../types/RuntimeCxt';
|
import { BRC } from '../types/RuntimeCxt';
|
||||||
import { OperationResult } from 'oak-domain/lib/types';
|
import { OperationResult } from 'oak-domain/lib/types';
|
||||||
import { refreshtShipState } from '../utils/ship';
|
import { refreshShipState, refreshMpOrderShipState } from '../utils/ship';
|
||||||
import { mergeOperationResult } from 'oak-domain/lib/utils/operationResult';
|
import { mergeOperationResult } from 'oak-domain/lib/utils/operationResult';
|
||||||
|
|
||||||
const timers: Array<Timer<EntityDict, 'ship', BRC>> = [
|
const timers: Array<Timer<EntityDict, 'ship', BRC>> = [
|
||||||
|
|
@ -33,7 +33,36 @@ const timers: Array<Timer<EntityDict, 'ship', BRC>> = [
|
||||||
fn: async (context, data) => {
|
fn: async (context, data) => {
|
||||||
const results = [] as OperationResult<EntityDict>[];
|
const results = [] as OperationResult<EntityDict>[];
|
||||||
for (const ship of data) {
|
for (const ship of data) {
|
||||||
const result = await refreshtShipState(ship.id!, context);
|
const result = await refreshShipState(ship.id!, context);
|
||||||
|
if (result) {
|
||||||
|
results.push(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (results.length === 0) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return results.reduce(
|
||||||
|
(prev, cur) => mergeOperationResult(prev, cur)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '同步微信小程序虚拟ship状态',
|
||||||
|
cron: '0 0 * * * ?',
|
||||||
|
entity: 'ship',
|
||||||
|
filter: {
|
||||||
|
type: 'virtual',
|
||||||
|
iState: {
|
||||||
|
$nin: ['received', 'cancelled', 'rejected'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
projection: {
|
||||||
|
id: 1,
|
||||||
|
},
|
||||||
|
fn: async (context, data) => {
|
||||||
|
const results = [] as OperationResult<EntityDict>[];
|
||||||
|
for (const ship of data) {
|
||||||
|
const result = await refreshMpOrderShipState(ship.id!, context);
|
||||||
if (result) {
|
if (result) {
|
||||||
results.push(result);
|
results.push(result);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -276,7 +276,7 @@ export async function uploadShippingInfo(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取小程序物流状态
|
* 获取小程序订单状态
|
||||||
* @param context
|
* @param context
|
||||||
* @param shipId
|
* @param shipId
|
||||||
* @returns
|
* @returns
|
||||||
|
|
@ -358,6 +358,54 @@ export async function getOrderShipState(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新小程序订单状态(自动确认收货)
|
||||||
|
* @param context
|
||||||
|
* @param shipId
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export async function refreshMpOrderShipState(
|
||||||
|
shipId: string,
|
||||||
|
context: BRC,
|
||||||
|
) {
|
||||||
|
const [ship] = await context.select('ship', {
|
||||||
|
data: {
|
||||||
|
id: 1,
|
||||||
|
iState: 1,
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
id: shipId,
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
blockTrigger: true,
|
||||||
|
forUpdate: true
|
||||||
|
});
|
||||||
|
const mpState = await getOrderShipState(context, shipId);
|
||||||
|
let action = undefined;
|
||||||
|
switch (mpState) {
|
||||||
|
case 'shipping': //已发货
|
||||||
|
action = 'ship';
|
||||||
|
break;
|
||||||
|
case 'received': //已收货
|
||||||
|
action = 'succeedReceiving';
|
||||||
|
break;
|
||||||
|
case 'unknow': //不明
|
||||||
|
action = 'unknow';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
action = undefined;
|
||||||
|
}
|
||||||
|
if (action && ship.iState !== mpState) {
|
||||||
|
return await context.operate('ship', {
|
||||||
|
id: await generateNewIdAsync(),
|
||||||
|
action,
|
||||||
|
data: {},
|
||||||
|
filter: {
|
||||||
|
id: ship.id,
|
||||||
|
}
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 刷新ship的物流状态
|
* 刷新ship的物流状态
|
||||||
|
|
@ -366,7 +414,7 @@ export async function getOrderShipState(
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export async function refreshtShipState(
|
export async function refreshShipState(
|
||||||
shipId: string,
|
shipId: string,
|
||||||
context: BRC,
|
context: BRC,
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { EntityDict } from '../oak-app-domain';
|
||||||
import { BRC } from '../types/RuntimeCxt';
|
import { BRC } from '../types/RuntimeCxt';
|
||||||
import { OperationResult } from 'oak-domain/lib/types';
|
import { OperationResult } from 'oak-domain/lib/types';
|
||||||
import { mergeOperationResult } from 'oak-domain/lib/utils/operationResult';
|
import { mergeOperationResult } from 'oak-domain/lib/utils/operationResult';
|
||||||
import { shipProjection, refreshtShipState } from '../utils/ship';
|
import { shipProjection, refreshShipState } from '../utils/ship';
|
||||||
|
|
||||||
const QUERY_PAYING_STATE_GAP = process.env.NODE_ENV === 'production' ? 3600 * 1000 : 60 * 1000;
|
const QUERY_PAYING_STATE_GAP = process.env.NODE_ENV === 'production' ? 3600 * 1000 : 60 * 1000;
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ const watchers: Watcher<EntityDict, 'ship', BRC>[] = [
|
||||||
fn: async (context, data) => {
|
fn: async (context, data) => {
|
||||||
const results = [] as OperationResult<EntityDict>[];
|
const results = [] as OperationResult<EntityDict>[];
|
||||||
for (const ship of data) {
|
for (const ship of data) {
|
||||||
const result = await refreshtShipState(ship.id!, context);
|
const result = await refreshShipState(ship.id!, context);
|
||||||
if (result) {
|
if (result) {
|
||||||
results.push(result);
|
results.push(result);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue