ship trigger修改
This commit is contained in:
parent
26ce61bc5e
commit
b0479c3f90
|
|
@ -1,42 +1,25 @@
|
|||
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
|
||||
import { DATA_SUBSCRIBER_KEYS } from '../config/constants';
|
||||
import { uploadShippingInfo } from '../utils/ship';
|
||||
import { getShipState, uploadShippingInfo } from '../utils/ship';
|
||||
const triggers = [
|
||||
{
|
||||
name: '当虚拟发货创建后自动发货',
|
||||
entity: 'ship',
|
||||
action: 'create',
|
||||
when: 'commit',
|
||||
strict: 'makeSure',
|
||||
asRoot: true,
|
||||
check: (operation) => operation.data.type === 'virtual',
|
||||
fn: async ({ ids }, context, option) => {
|
||||
for (const id of ids) {
|
||||
const [ship] = await context.select('ship', {
|
||||
data: {
|
||||
id: 1,
|
||||
type: 1,
|
||||
deposit$ship: {
|
||||
$entity: 'deposit',
|
||||
data: {
|
||||
id: 1,
|
||||
iState: 1,
|
||||
}
|
||||
}
|
||||
},
|
||||
await context.operate('ship', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'ship',
|
||||
data: {},
|
||||
filter: {
|
||||
id,
|
||||
}
|
||||
}, {});
|
||||
const { type } = ship;
|
||||
if (type === 'virtual') {
|
||||
await context.operate('ship', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'ship',
|
||||
data: {},
|
||||
filter: {
|
||||
id,
|
||||
}
|
||||
}, option);
|
||||
}
|
||||
}, option);
|
||||
}
|
||||
return;
|
||||
},
|
||||
|
|
@ -58,21 +41,6 @@ const triggers = [
|
|||
$entity: 'deposit',
|
||||
data: {
|
||||
id: 1,
|
||||
pay$deposit: {
|
||||
$entity: 'pay',
|
||||
data: {
|
||||
id: 1,
|
||||
entity: 1,
|
||||
entityId: 1,
|
||||
meta: 1,
|
||||
applicationId: 1,
|
||||
},
|
||||
filter: {
|
||||
iState: 'paid',
|
||||
},
|
||||
indexFrom: 0,
|
||||
count: 1,
|
||||
}
|
||||
},
|
||||
indexFrom: 0,
|
||||
count: 1,
|
||||
|
|
@ -83,9 +51,14 @@ const triggers = [
|
|||
const { type, deposit$ship: deposits } = ship || {};
|
||||
if (type === 'virtual') {
|
||||
const deposit = deposits?.[0];
|
||||
const result = await uploadShippingInfo({ depositId: deposit?.id, }, context);
|
||||
if (result) {
|
||||
return 1;
|
||||
//当已发货的订单再次调用小程序发货信息录入接口视为重新发货(仅可重新发货一次)
|
||||
//发货前先查询,检查是否为未同步微信端发货状态
|
||||
const shipState = await getShipState(context, deposit);
|
||||
if (shipState === 'unshipped') {
|
||||
const result = await uploadShippingInfo({ depositId: deposit?.id, }, context);
|
||||
if (result) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -224,30 +224,30 @@ export async function getShipState(context, deposit, order) {
|
|||
if (!inComplaint) {
|
||||
//未处于纠纷中
|
||||
let state = undefined;
|
||||
let action = undefined;
|
||||
// let action = undefined;
|
||||
switch (orderState) {
|
||||
case 1: //待发货
|
||||
state = 'unshipped';
|
||||
break;
|
||||
case 2: //已发货
|
||||
state = 'shipping';
|
||||
action = 'ship';
|
||||
// action = 'ship';
|
||||
break;
|
||||
case 3: //确认收货
|
||||
state = 'received';
|
||||
action = 'receive';
|
||||
// action = 'receive';
|
||||
break;
|
||||
}
|
||||
if (action && ship?.iState !== state) {
|
||||
await context.operate('ship', {
|
||||
id: await generateNewIdAsync(),
|
||||
action,
|
||||
data: {},
|
||||
filter: {
|
||||
id: shipId,
|
||||
}
|
||||
}, {});
|
||||
}
|
||||
// if (action && ship?.iState !== state) {
|
||||
// await context.operate('ship', {
|
||||
// id: await generateNewIdAsync(),
|
||||
// action,
|
||||
// data: {},
|
||||
// filter: {
|
||||
// id: shipId,
|
||||
// }
|
||||
// }, {});
|
||||
// }
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,10 @@ const tslib_1 = require("tslib");
|
|||
const i18n_1 = tslib_1.__importDefault(require("./i18n"));
|
||||
const path_1 = tslib_1.__importDefault(require("./path"));
|
||||
const actionAuth_1 = tslib_1.__importDefault(require("./actionAuth"));
|
||||
const shipCompany_1 = tslib_1.__importDefault(require("./shipCompany"));
|
||||
exports.default = {
|
||||
i18n: i18n_1.default,
|
||||
path: path_1.default,
|
||||
actionAuth: actionAuth_1.default,
|
||||
shipCompany: shipCompany_1.default,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,36 +9,19 @@ const triggers = [
|
|||
entity: 'ship',
|
||||
action: 'create',
|
||||
when: 'commit',
|
||||
strict: 'makeSure',
|
||||
asRoot: true,
|
||||
check: (operation) => operation.data.type === 'virtual',
|
||||
fn: async ({ ids }, context, option) => {
|
||||
for (const id of ids) {
|
||||
const [ship] = await context.select('ship', {
|
||||
data: {
|
||||
id: 1,
|
||||
type: 1,
|
||||
deposit$ship: {
|
||||
$entity: 'deposit',
|
||||
data: {
|
||||
id: 1,
|
||||
iState: 1,
|
||||
}
|
||||
}
|
||||
},
|
||||
await context.operate('ship', {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
action: 'ship',
|
||||
data: {},
|
||||
filter: {
|
||||
id,
|
||||
}
|
||||
}, {});
|
||||
const { type } = ship;
|
||||
if (type === 'virtual') {
|
||||
await context.operate('ship', {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
action: 'ship',
|
||||
data: {},
|
||||
filter: {
|
||||
id,
|
||||
}
|
||||
}, option);
|
||||
}
|
||||
}, option);
|
||||
}
|
||||
return;
|
||||
},
|
||||
|
|
@ -60,21 +43,6 @@ const triggers = [
|
|||
$entity: 'deposit',
|
||||
data: {
|
||||
id: 1,
|
||||
pay$deposit: {
|
||||
$entity: 'pay',
|
||||
data: {
|
||||
id: 1,
|
||||
entity: 1,
|
||||
entityId: 1,
|
||||
meta: 1,
|
||||
applicationId: 1,
|
||||
},
|
||||
filter: {
|
||||
iState: 'paid',
|
||||
},
|
||||
indexFrom: 0,
|
||||
count: 1,
|
||||
}
|
||||
},
|
||||
indexFrom: 0,
|
||||
count: 1,
|
||||
|
|
@ -85,9 +53,14 @@ const triggers = [
|
|||
const { type, deposit$ship: deposits } = ship || {};
|
||||
if (type === 'virtual') {
|
||||
const deposit = deposits?.[0];
|
||||
const result = await (0, ship_1.uploadShippingInfo)({ depositId: deposit?.id, }, context);
|
||||
if (result) {
|
||||
return 1;
|
||||
//当已发货的订单再次调用小程序发货信息录入接口视为重新发货(仅可重新发货一次)
|
||||
//发货前先查询,检查是否为未同步微信端发货状态
|
||||
const shipState = await (0, ship_1.getShipState)(context, deposit);
|
||||
if (shipState === 'unshipped') {
|
||||
const result = await (0, ship_1.uploadShippingInfo)({ depositId: deposit?.id, }, context);
|
||||
if (result) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -229,30 +229,30 @@ async function getShipState(context, deposit, order) {
|
|||
if (!inComplaint) {
|
||||
//未处于纠纷中
|
||||
let state = undefined;
|
||||
let action = undefined;
|
||||
// let action = undefined;
|
||||
switch (orderState) {
|
||||
case 1: //待发货
|
||||
state = 'unshipped';
|
||||
break;
|
||||
case 2: //已发货
|
||||
state = 'shipping';
|
||||
action = 'ship';
|
||||
// action = 'ship';
|
||||
break;
|
||||
case 3: //确认收货
|
||||
state = 'received';
|
||||
action = 'receive';
|
||||
// action = 'receive';
|
||||
break;
|
||||
}
|
||||
if (action && ship?.iState !== state) {
|
||||
await context.operate('ship', {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
action,
|
||||
data: {},
|
||||
filter: {
|
||||
id: shipId,
|
||||
}
|
||||
}, {});
|
||||
}
|
||||
// if (action && ship?.iState !== state) {
|
||||
// await context.operate('ship', {
|
||||
// id: await generateNewIdAsync(),
|
||||
// action,
|
||||
// data: {},
|
||||
// filter: {
|
||||
// id: shipId,
|
||||
// }
|
||||
// }, {});
|
||||
// }
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { BRC } from '../types/RuntimeCxt';
|
|||
import { DATA_SUBSCRIBER_KEYS } from '../config/constants';
|
||||
import assert from 'assert';
|
||||
import dayjs from 'dayjs';
|
||||
import { uploadShippingInfo } from '@project/utils/ship';
|
||||
import { getShipState, uploadShippingInfo } from '@project/utils/ship';
|
||||
|
||||
const triggers: Trigger<EntityDict, 'ship', BRC>[] = [
|
||||
{
|
||||
|
|
@ -13,37 +13,20 @@ const triggers: Trigger<EntityDict, 'ship', BRC>[] = [
|
|||
entity: 'ship',
|
||||
action: 'create',
|
||||
when: 'commit',
|
||||
strict: 'makeSure',
|
||||
asRoot: true,
|
||||
check: (operation: EntityDict['ship']['Create']) => (operation as EntityDict['ship']['CreateSingle']).data.type === 'virtual',
|
||||
fn: async ({ ids }, context, option) => {
|
||||
for (const id of ids) {
|
||||
const [ship] = await context.select('ship', {
|
||||
await context.operate('ship', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'ship',
|
||||
data: {
|
||||
id: 1,
|
||||
type: 1,
|
||||
deposit$ship: {
|
||||
$entity: 'deposit',
|
||||
data: {
|
||||
id: 1,
|
||||
iState: 1,
|
||||
}
|
||||
}
|
||||
},
|
||||
filter: {
|
||||
id,
|
||||
}
|
||||
}, {})
|
||||
const { type } = ship;
|
||||
if (type === 'virtual') {
|
||||
await context.operate('ship', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'ship',
|
||||
data: {
|
||||
},
|
||||
filter: {
|
||||
id,
|
||||
}
|
||||
}, option);
|
||||
}
|
||||
}, option);
|
||||
}
|
||||
return;
|
||||
},
|
||||
|
|
@ -65,21 +48,6 @@ const triggers: Trigger<EntityDict, 'ship', BRC>[] = [
|
|||
$entity: 'deposit',
|
||||
data: {
|
||||
id: 1,
|
||||
pay$deposit: {
|
||||
$entity: 'pay',
|
||||
data: {
|
||||
id: 1,
|
||||
entity: 1,
|
||||
entityId: 1,
|
||||
meta: 1,
|
||||
applicationId: 1,
|
||||
},
|
||||
filter: {
|
||||
iState: 'paid',
|
||||
},
|
||||
indexFrom: 0,
|
||||
count: 1,
|
||||
}
|
||||
},
|
||||
indexFrom: 0,
|
||||
count: 1,
|
||||
|
|
@ -90,9 +58,14 @@ const triggers: Trigger<EntityDict, 'ship', BRC>[] = [
|
|||
const { type, deposit$ship: deposits } = ship || {};
|
||||
if (type === 'virtual') {
|
||||
const deposit = deposits?.[0];
|
||||
const result = await uploadShippingInfo({ depositId: deposit?.id, }, context);
|
||||
if (result) {
|
||||
return 1;
|
||||
//当已发货的订单再次调用小程序发货信息录入接口视为重新发货(仅可重新发货一次)
|
||||
//发货前先查询,检查是否为未同步微信端发货状态
|
||||
const shipState = await getShipState(context, deposit);
|
||||
if (shipState === 'unshipped') {
|
||||
const result = await uploadShippingInfo({ depositId: deposit?.id, }, context);
|
||||
if (result) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -262,30 +262,30 @@ export async function getShipState(
|
|||
if (!inComplaint) {
|
||||
//未处于纠纷中
|
||||
let state = undefined;
|
||||
let action = undefined;
|
||||
// let action = undefined;
|
||||
switch (orderState) {
|
||||
case 1: //待发货
|
||||
state = 'unshipped';
|
||||
break;
|
||||
case 2: //已发货
|
||||
state = 'shipping';
|
||||
action = 'ship';
|
||||
// action = 'ship';
|
||||
break;
|
||||
case 3: //确认收货
|
||||
state = 'received';
|
||||
action = 'receive'
|
||||
// action = 'receive';
|
||||
break;
|
||||
}
|
||||
if (action && ship?.iState !== state) {
|
||||
await context.operate('ship', {
|
||||
id: await generateNewIdAsync(),
|
||||
action,
|
||||
data: {},
|
||||
filter: {
|
||||
id: shipId,
|
||||
}
|
||||
}, {});
|
||||
}
|
||||
// if (action && ship?.iState !== state) {
|
||||
// await context.operate('ship', {
|
||||
// id: await generateNewIdAsync(),
|
||||
// action,
|
||||
// data: {},
|
||||
// filter: {
|
||||
// id: shipId,
|
||||
// }
|
||||
// }, {});
|
||||
// }
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue