oak-pay-business 3.1.5 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,6 +32,9 @@ export const desc = {
32
32
  params: {
33
33
  length: 64
34
34
  }
35
+ },
36
+ latestAt: {
37
+ type: "datetime"
35
38
  }
36
39
  },
37
40
  actionType: "crud",
@@ -2,7 +2,7 @@ import { ForeignKey } from "oak-domain/lib/types/DataType";
2
2
  import { Q_DateValue, Q_BooleanValue, Q_NumberValue, Q_StringValue, NodeId, ExprOp, ExpressionKey } from "oak-domain/lib/types/Demand";
3
3
  import { MakeAction as OakMakeAction, EntityShape } from "oak-domain/lib/types/Entity";
4
4
  import { GenericAction } from "oak-domain/lib/actions/action";
5
- import { String, Boolean } from "oak-domain/lib/types/DataType";
5
+ import { String, Boolean, Datetime } from "oak-domain/lib/types/DataType";
6
6
  export type OpSchema = EntityShape & {
7
7
  name: String<32>;
8
8
  isArticle: Boolean;
@@ -10,6 +10,7 @@ export type OpSchema = EntityShape & {
10
10
  isLeaf?: Boolean | null;
11
11
  entity: String<32>;
12
12
  entityId: String<64>;
13
+ latestAt?: Datetime | null;
13
14
  } & {
14
15
  [A in ExpressionKey]?: any;
15
16
  };
@@ -25,6 +26,7 @@ export type OpFilter = {
25
26
  isLeaf: Q_BooleanValue;
26
27
  entity: Q_StringValue;
27
28
  entityId: Q_StringValue;
29
+ latestAt: Q_DateValue;
28
30
  } & ExprOp<OpAttr | string>;
29
31
  export type OpProjection = {
30
32
  "#id"?: NodeId;
@@ -39,6 +41,7 @@ export type OpProjection = {
39
41
  isLeaf?: number;
40
42
  entity?: number;
41
43
  entityId?: number;
44
+ latestAt?: number;
42
45
  } & Partial<ExprOp<OpAttr | string>>;
43
46
  export type OpSortAttr = Partial<{
44
47
  id: number;
@@ -51,6 +54,7 @@ export type OpSortAttr = Partial<{
51
54
  isLeaf: number;
52
55
  entity: number;
53
56
  entityId: number;
57
+ latestAt: number;
54
58
  [k: string]: any;
55
59
  } | ExprOp<OpAttr | string>>;
56
60
  export type OpAction = OakMakeAction<GenericAction | string>;
@@ -7,6 +7,7 @@
7
7
  "entity": "对象",
8
8
  "entityId": "对象Id",
9
9
  "isLeaf": "结点下是否存在叶子结点",
10
- "files": "文件"
10
+ "files": "文件",
11
+ "latestAt": "最近编辑"
11
12
  }
12
13
  }
@@ -25,6 +25,7 @@ async function startRefunding(context, data) {
25
25
  },
26
26
  order: {
27
27
  id: 1,
28
+ price: 1,
28
29
  paid: 1,
29
30
  refunded: 1,
30
31
  settled: 1,
@@ -112,50 +113,14 @@ async function startRefunding(context, data) {
112
113
  }
113
114
  }, { forUpdate: true });
114
115
  const { accountOper$entity: opers, } = data;
115
- // 对opers检查
116
- if (order.settled === (order.paid - order.refunded)) {
117
- // 已全部结算
118
- // 已全部结算的订单由refund传入的opers决定退款,检查opers的金额总和等于refund的金额
119
- let amount = 0;
120
- // 有明确的来源account
121
- assert(opers && opers instanceof Array, '已结算的订单退款一定要有相应的account来源');
122
- opers.forEach(({ action, data }) => {
123
- assert(action === 'create');
124
- const { type, totalPlus, availPlus, accountId } = data;
125
- assert(type === 'refund');
126
- assert(totalPlus === availPlus);
127
- const settlement = settledSettlements?.find((ele) => ele?.accountId === accountId);
128
- assert(!!settlement, '请从订单分账的相关账户中选择订单退款的account来源');
129
- amount += -totalPlus;
130
- });
131
- assert(amount === data.price);
132
- //将order的settled更新
133
- const newSettled = order.settled - data.price;
134
- await context.operate('order', {
135
- id: await generateNewIdAsync(),
136
- action: 'update',
137
- data: {
138
- settled: newSettled,
139
- },
140
- filter: {
141
- id: order.id,
142
- }
143
- }, {});
144
- }
145
- else if (order.settled === 0) {
146
- //未结算
147
- //未结算的订单无opers
148
- assert(!(opers && opers.length > 0));
149
- }
150
- else {
151
- //部分结算
152
- /**
153
- * 部分结算的订单:
154
- * 1. opers的金额总和 <= 订单已结算金额
155
- * 2. opers的金额总和 + unsettled的金额 >= 退款金额
156
- */
157
- let opersPrice = 0;
158
- if (opers && opers.length > 0) {
116
+ // 对opers检查 退款0元无需检查
117
+ if (!(data.price === 0 && order.price === 0 && pay.paid === 0)) {
118
+ if (order.settled === (order.paid - order.refunded)) {
119
+ // 已全部结算
120
+ // 已全部结算的订单由refund传入的opers决定退款,检查opers的金额总和等于refund的金额
121
+ let amount = 0;
122
+ // 有明确的来源account
123
+ assert(opers && opers instanceof Array, '已结算的订单退款一定要有相应的account来源');
159
124
  opers.forEach(({ action, data }) => {
160
125
  assert(action === 'create');
161
126
  const { type, totalPlus, availPlus, accountId } = data;
@@ -163,29 +128,70 @@ async function startRefunding(context, data) {
163
128
  assert(totalPlus === availPlus);
164
129
  const settlement = settledSettlements?.find((ele) => ele?.accountId === accountId);
165
130
  assert(!!settlement, '请从订单分账的相关账户中选择订单退款的account来源');
166
- opersPrice += -totalPlus;
131
+ amount += -totalPlus;
167
132
  });
133
+ assert(amount === data.price);
134
+ //将order的settled更新
135
+ const newSettled = order.settled - data.price;
136
+ await context.operate('order', {
137
+ id: await generateNewIdAsync(),
138
+ action: 'update',
139
+ data: {
140
+ settled: newSettled,
141
+ },
142
+ filter: {
143
+ id: order.id,
144
+ }
145
+ }, {});
168
146
  }
169
- const { paid, refunded, settled, settlePlan$order: settlePlans } = order;
170
- const orderUnsettledPrice = paid - refunded - settled;
171
- if (opersPrice > settled) {
172
- throw new refundOpersExceed(opersPrice - settled);
173
- }
174
- if (opersPrice < data.price - orderUnsettledPrice) {
175
- throw new refundOpersNotEnough(opersPrice - (data.price - orderUnsettledPrice));
147
+ else if (order.settled === 0) {
148
+ //未结算
149
+ //未结算的订单无opers
150
+ assert(!(opers && opers.length > 0));
176
151
  }
177
- //将order的settled更新
178
- const newSettled = order.settled - opersPrice;
179
- await context.operate('order', {
180
- id: await generateNewIdAsync(),
181
- action: 'update',
182
- data: {
183
- settled: newSettled,
184
- },
185
- filter: {
186
- id: order.id,
152
+ else {
153
+ //部分结算
154
+ /**
155
+ * 部分结算的订单:
156
+ * 1. opers的金额总和 <= 订单已结算金额
157
+ * 2. opers的金额总和 + unsettled的金额 >= 退款金额
158
+ */
159
+ let opersPrice = 0;
160
+ if (opers && opers.length > 0) {
161
+ opers.forEach(({ action, data }) => {
162
+ assert(action === 'create');
163
+ const { type, totalPlus, availPlus, accountId } = data;
164
+ assert(type === 'refund');
165
+ assert(totalPlus === availPlus);
166
+ const settlement = settledSettlements?.find((ele) => ele?.accountId === accountId);
167
+ assert(!!settlement, '请从订单分账的相关账户中选择订单退款的account来源');
168
+ opersPrice += -totalPlus;
169
+ });
187
170
  }
188
- }, {});
171
+ const { paid, refunded, settled, settlePlan$order: settlePlans } = order;
172
+ const orderUnsettledPrice = paid - refunded - settled;
173
+ if (opersPrice > settled) {
174
+ throw new refundOpersExceed(opersPrice - settled);
175
+ }
176
+ if (opersPrice < data.price - orderUnsettledPrice) {
177
+ throw new refundOpersNotEnough(opersPrice - (data.price - orderUnsettledPrice));
178
+ }
179
+ //将order的settled更新
180
+ const newSettled = order.settled - opersPrice;
181
+ await context.operate('order', {
182
+ id: await generateNewIdAsync(),
183
+ action: 'update',
184
+ data: {
185
+ settled: newSettled,
186
+ },
187
+ filter: {
188
+ id: order.id,
189
+ }
190
+ }, {});
191
+ }
192
+ }
193
+ else {
194
+ assert(order.price === 0 && data.price === 0, '0元订单,退款金额不可大于订单金额');
189
195
  }
190
196
  }
191
197
  data.pay = {
@@ -35,6 +35,9 @@ exports.desc = {
35
35
  params: {
36
36
  length: 64
37
37
  }
38
+ },
39
+ latestAt: {
40
+ type: "datetime"
38
41
  }
39
42
  },
40
43
  actionType: "crud",
@@ -2,7 +2,7 @@ import { ForeignKey } from "oak-domain/lib/types/DataType";
2
2
  import { Q_DateValue, Q_BooleanValue, Q_NumberValue, Q_StringValue, NodeId, ExprOp, ExpressionKey } from "oak-domain/lib/types/Demand";
3
3
  import { MakeAction as OakMakeAction, EntityShape } from "oak-domain/lib/types/Entity";
4
4
  import { GenericAction } from "oak-domain/lib/actions/action";
5
- import { String, Boolean } from "oak-domain/lib/types/DataType";
5
+ import { String, Boolean, Datetime } from "oak-domain/lib/types/DataType";
6
6
  export type OpSchema = EntityShape & {
7
7
  name: String<32>;
8
8
  isArticle: Boolean;
@@ -10,6 +10,7 @@ export type OpSchema = EntityShape & {
10
10
  isLeaf?: Boolean | null;
11
11
  entity: String<32>;
12
12
  entityId: String<64>;
13
+ latestAt?: Datetime | null;
13
14
  } & {
14
15
  [A in ExpressionKey]?: any;
15
16
  };
@@ -25,6 +26,7 @@ export type OpFilter = {
25
26
  isLeaf: Q_BooleanValue;
26
27
  entity: Q_StringValue;
27
28
  entityId: Q_StringValue;
29
+ latestAt: Q_DateValue;
28
30
  } & ExprOp<OpAttr | string>;
29
31
  export type OpProjection = {
30
32
  "#id"?: NodeId;
@@ -39,6 +41,7 @@ export type OpProjection = {
39
41
  isLeaf?: number;
40
42
  entity?: number;
41
43
  entityId?: number;
44
+ latestAt?: number;
42
45
  } & Partial<ExprOp<OpAttr | string>>;
43
46
  export type OpSortAttr = Partial<{
44
47
  id: number;
@@ -51,6 +54,7 @@ export type OpSortAttr = Partial<{
51
54
  isLeaf: number;
52
55
  entity: number;
53
56
  entityId: number;
57
+ latestAt: number;
54
58
  [k: string]: any;
55
59
  } | ExprOp<OpAttr | string>>;
56
60
  export type OpAction = OakMakeAction<GenericAction | string>;
@@ -7,6 +7,7 @@
7
7
  "entity": "对象",
8
8
  "entityId": "对象Id",
9
9
  "isLeaf": "结点下是否存在叶子结点",
10
- "files": "文件"
10
+ "files": "文件",
11
+ "latestAt": "最近编辑"
11
12
  }
12
13
  }
@@ -28,6 +28,7 @@ async function startRefunding(context, data) {
28
28
  },
29
29
  order: {
30
30
  id: 1,
31
+ price: 1,
31
32
  paid: 1,
32
33
  refunded: 1,
33
34
  settled: 1,
@@ -115,50 +116,14 @@ async function startRefunding(context, data) {
115
116
  }
116
117
  }, { forUpdate: true });
117
118
  const { accountOper$entity: opers, } = data;
118
- // 对opers检查
119
- if (order.settled === (order.paid - order.refunded)) {
120
- // 已全部结算
121
- // 已全部结算的订单由refund传入的opers决定退款,检查opers的金额总和等于refund的金额
122
- let amount = 0;
123
- // 有明确的来源account
124
- (0, assert_1.default)(opers && opers instanceof Array, '已结算的订单退款一定要有相应的account来源');
125
- opers.forEach(({ action, data }) => {
126
- (0, assert_1.default)(action === 'create');
127
- const { type, totalPlus, availPlus, accountId } = data;
128
- (0, assert_1.default)(type === 'refund');
129
- (0, assert_1.default)(totalPlus === availPlus);
130
- const settlement = settledSettlements?.find((ele) => ele?.accountId === accountId);
131
- (0, assert_1.default)(!!settlement, '请从订单分账的相关账户中选择订单退款的account来源');
132
- amount += -totalPlus;
133
- });
134
- (0, assert_1.default)(amount === data.price);
135
- //将order的settled更新
136
- const newSettled = order.settled - data.price;
137
- await context.operate('order', {
138
- id: await (0, uuid_1.generateNewIdAsync)(),
139
- action: 'update',
140
- data: {
141
- settled: newSettled,
142
- },
143
- filter: {
144
- id: order.id,
145
- }
146
- }, {});
147
- }
148
- else if (order.settled === 0) {
149
- //未结算
150
- //未结算的订单无opers
151
- (0, assert_1.default)(!(opers && opers.length > 0));
152
- }
153
- else {
154
- //部分结算
155
- /**
156
- * 部分结算的订单:
157
- * 1. opers的金额总和 <= 订单已结算金额
158
- * 2. opers的金额总和 + unsettled的金额 >= 退款金额
159
- */
160
- let opersPrice = 0;
161
- if (opers && opers.length > 0) {
119
+ // 对opers检查 退款0元无需检查
120
+ if (!(data.price === 0 && order.price === 0 && pay.paid === 0)) {
121
+ if (order.settled === (order.paid - order.refunded)) {
122
+ // 已全部结算
123
+ // 已全部结算的订单由refund传入的opers决定退款,检查opers的金额总和等于refund的金额
124
+ let amount = 0;
125
+ // 有明确的来源account
126
+ (0, assert_1.default)(opers && opers instanceof Array, '已结算的订单退款一定要有相应的account来源');
162
127
  opers.forEach(({ action, data }) => {
163
128
  (0, assert_1.default)(action === 'create');
164
129
  const { type, totalPlus, availPlus, accountId } = data;
@@ -166,29 +131,70 @@ async function startRefunding(context, data) {
166
131
  (0, assert_1.default)(totalPlus === availPlus);
167
132
  const settlement = settledSettlements?.find((ele) => ele?.accountId === accountId);
168
133
  (0, assert_1.default)(!!settlement, '请从订单分账的相关账户中选择订单退款的account来源');
169
- opersPrice += -totalPlus;
134
+ amount += -totalPlus;
170
135
  });
136
+ (0, assert_1.default)(amount === data.price);
137
+ //将order的settled更新
138
+ const newSettled = order.settled - data.price;
139
+ await context.operate('order', {
140
+ id: await (0, uuid_1.generateNewIdAsync)(),
141
+ action: 'update',
142
+ data: {
143
+ settled: newSettled,
144
+ },
145
+ filter: {
146
+ id: order.id,
147
+ }
148
+ }, {});
171
149
  }
172
- const { paid, refunded, settled, settlePlan$order: settlePlans } = order;
173
- const orderUnsettledPrice = paid - refunded - settled;
174
- if (opersPrice > settled) {
175
- throw new Exception_1.refundOpersExceed(opersPrice - settled);
176
- }
177
- if (opersPrice < data.price - orderUnsettledPrice) {
178
- throw new Exception_1.refundOpersNotEnough(opersPrice - (data.price - orderUnsettledPrice));
150
+ else if (order.settled === 0) {
151
+ //未结算
152
+ //未结算的订单无opers
153
+ (0, assert_1.default)(!(opers && opers.length > 0));
179
154
  }
180
- //将order的settled更新
181
- const newSettled = order.settled - opersPrice;
182
- await context.operate('order', {
183
- id: await (0, uuid_1.generateNewIdAsync)(),
184
- action: 'update',
185
- data: {
186
- settled: newSettled,
187
- },
188
- filter: {
189
- id: order.id,
155
+ else {
156
+ //部分结算
157
+ /**
158
+ * 部分结算的订单:
159
+ * 1. opers的金额总和 <= 订单已结算金额
160
+ * 2. opers的金额总和 + unsettled的金额 >= 退款金额
161
+ */
162
+ let opersPrice = 0;
163
+ if (opers && opers.length > 0) {
164
+ opers.forEach(({ action, data }) => {
165
+ (0, assert_1.default)(action === 'create');
166
+ const { type, totalPlus, availPlus, accountId } = data;
167
+ (0, assert_1.default)(type === 'refund');
168
+ (0, assert_1.default)(totalPlus === availPlus);
169
+ const settlement = settledSettlements?.find((ele) => ele?.accountId === accountId);
170
+ (0, assert_1.default)(!!settlement, '请从订单分账的相关账户中选择订单退款的account来源');
171
+ opersPrice += -totalPlus;
172
+ });
190
173
  }
191
- }, {});
174
+ const { paid, refunded, settled, settlePlan$order: settlePlans } = order;
175
+ const orderUnsettledPrice = paid - refunded - settled;
176
+ if (opersPrice > settled) {
177
+ throw new Exception_1.refundOpersExceed(opersPrice - settled);
178
+ }
179
+ if (opersPrice < data.price - orderUnsettledPrice) {
180
+ throw new Exception_1.refundOpersNotEnough(opersPrice - (data.price - orderUnsettledPrice));
181
+ }
182
+ //将order的settled更新
183
+ const newSettled = order.settled - opersPrice;
184
+ await context.operate('order', {
185
+ id: await (0, uuid_1.generateNewIdAsync)(),
186
+ action: 'update',
187
+ data: {
188
+ settled: newSettled,
189
+ },
190
+ filter: {
191
+ id: order.id,
192
+ }
193
+ }, {});
194
+ }
195
+ }
196
+ else {
197
+ (0, assert_1.default)(order.price === 0 && data.price === 0, '0元订单,退款金额不可大于订单金额');
192
198
  }
193
199
  }
194
200
  data.pay = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-pay-business",
3
- "version": "3.1.5",
3
+ "version": "3.2.0",
4
4
  "description": "",
5
5
  "files": [
6
6
  "lib/**/*",
@@ -33,8 +33,8 @@
33
33
  "dayjs": "^1.11.5",
34
34
  "oak-domain": "^5.1.27",
35
35
  "oak-external-sdk": "^2.3.10",
36
- "oak-frontend-base": "^5.3.35",
37
- "oak-general-business": "~5.7.9",
36
+ "oak-frontend-base": "^5.3.37",
37
+ "oak-general-business": "~5.8.1",
38
38
  "react-markdown": "^9.0.3",
39
39
  "wechat-pay-nodejs": "^0.2.3"
40
40
  },