@freedom_sky/feige-lib 4.51.1 → 4.51.2

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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Order, Process, Content, Checkout, Task } from './interfaces/order/order.interface';
2
- import { Store } from './interfaces/store/store.interface';
2
+ import { BuffetCombosItems, Store } from './interfaces/store/store.interface';
3
3
  import { VisitTask } from './interfaces/visit-task/visit-task.interface';
4
4
  import { User, UserSafe, CertificatePath } from './interfaces/user/user.interface';
5
5
  import { DishSnapshot } from './interfaces/store/dishSnapshot.interface';
@@ -30,6 +30,7 @@ export * from './interfaces/store/dish.interface';
30
30
  export { PayCompanyEnum } from './enum/pay-company.enum';
31
31
  import * as moment from 'moment';
32
32
  import Big from 'big.js';
33
+ import { OrderTypeEnum } from './enum/order.enum';
33
34
  export * from './buffet/index';
34
35
  export { Order, Process, Content, Checkout, CONST, DishSnapshot, User, UserSafe, CertificatePath, Task, VisitTask, moment, PrintStatusEnum, PrinterDeviceTypeEnum, PrinterWidthEnum, Big, };
35
36
  /**
@@ -55,6 +56,14 @@ export declare function calcDishFinalPrice(conent: Content): number;
55
56
  *
56
57
  */
57
58
  export declare function calcTotalPrice(order: Order): number;
59
+ export declare function calcContentPrice({ orderContentItem, buffetItem, orderType, adultNum, childNum, contents }: {
60
+ orderContentItem: Content;
61
+ buffetItem: BuffetCombosItems;
62
+ orderType: OrderTypeEnum;
63
+ adultNum: number;
64
+ childNum: number;
65
+ contents: Content[];
66
+ }): number;
58
67
  export declare function getOrderedCountByDishId(dishId: any, contents: Content[], beforeKey?: string): number;
59
68
  /**
60
69
  * 计算处理后的应收金额
package/dist/index.js CHANGED
@@ -89,26 +89,15 @@ exports.calcDishFinalPrice = calcDishFinalPrice;
89
89
  function calcTotalPrice(order) {
90
90
  var totalPrice = 0;
91
91
  order.content.forEach(function (orderContentItem) {
92
- if (order.type === order_enum_1.OrderTypeEnum.Buffet) {
93
- var buffetDishItem = index_1.getDishItemInBuffet({ dishId: orderContentItem.dishSnapshot._id, buffet: order.buffet.snapshot });
94
- if (buffetDishItem) {
95
- var maxUpperLimit = index_1.getMaxBuffetDishUpperLimit({ buffetDishItem: buffetDishItem, adultNum: order.adultNum, childNum: order.childNum });
96
- var beforeCount = getOrderedCountByDishId(orderContentItem.dishSnapshot._id, order.content, orderContentItem._id);
97
- var maxUpperLimitForThisItem = Math.max(maxUpperLimit - beforeCount, 0);
98
- if (maxUpperLimitForThisItem >= orderContentItem.count) {
99
- // price 0;
100
- }
101
- else {
102
- totalPrice += (orderContentItem.count - maxUpperLimitForThisItem) * calcDishFinalPrice(orderContentItem);
103
- }
104
- }
105
- else {
106
- totalPrice += orderContentItem.count * calcDishFinalPrice(orderContentItem);
107
- }
108
- }
109
- else {
110
- totalPrice += orderContentItem.count * calcDishFinalPrice(orderContentItem);
111
- }
92
+ var _a;
93
+ totalPrice += calcContentPrice({
94
+ orderContentItem: orderContentItem,
95
+ buffetItem: (_a = order.buffet) === null || _a === void 0 ? void 0 : _a.snapshot,
96
+ orderType: order.type,
97
+ adultNum: order.adultNum,
98
+ childNum: order.childNum,
99
+ contents: order.content
100
+ });
112
101
  });
113
102
  if (order.deliveryFee && !order.selfPickUp) {
114
103
  totalPrice += order.deliveryFee;
@@ -119,6 +108,30 @@ function calcTotalPrice(order) {
119
108
  return parseMoney(totalPrice);
120
109
  }
121
110
  exports.calcTotalPrice = calcTotalPrice;
111
+ function calcContentPrice(_a) {
112
+ var orderContentItem = _a.orderContentItem, buffetItem = _a.buffetItem, orderType = _a.orderType, adultNum = _a.adultNum, childNum = _a.childNum, contents = _a.contents;
113
+ if (orderType === order_enum_1.OrderTypeEnum.Buffet) {
114
+ var buffetDishItem = index_1.getDishItemInBuffet({ dishId: orderContentItem.dishSnapshot._id, buffet: buffetItem });
115
+ if (buffetDishItem) {
116
+ var maxUpperLimit = index_1.getMaxBuffetDishUpperLimit({ buffetDishItem: buffetDishItem, adultNum: adultNum, childNum: childNum });
117
+ var beforeCount = getOrderedCountByDishId(orderContentItem.dishSnapshot._id, contents, orderContentItem._id);
118
+ var maxUpperLimitForThisItem = Math.max(maxUpperLimit - beforeCount, 0);
119
+ if (maxUpperLimitForThisItem >= orderContentItem.count) {
120
+ return 0;
121
+ }
122
+ else {
123
+ return (orderContentItem.count - maxUpperLimitForThisItem) * calcDishFinalPrice(orderContentItem);
124
+ }
125
+ }
126
+ else {
127
+ return orderContentItem.count * calcDishFinalPrice(orderContentItem);
128
+ }
129
+ }
130
+ else {
131
+ return orderContentItem.count * calcDishFinalPrice(orderContentItem);
132
+ }
133
+ }
134
+ exports.calcContentPrice = calcContentPrice;
122
135
  function getOrderedCountByDishId(dishId, contents, beforeKey) {
123
136
  var count = 0;
124
137
  for (var _i = 0, _a = contents.filter(function (content) { return content.dishSnapshot._id === dishId; }); _i < _a.length; _i++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freedom_sky/feige-lib",
3
- "version": "4.51.1",
3
+ "version": "4.51.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Order, Process, Content, Checkout, Task } from './interfaces/order/order.interface';
2
- import { Store } from './interfaces/store/store.interface';
2
+ import { BuffetCombosItems, Store } from './interfaces/store/store.interface';
3
3
  import { VisitTask } from './interfaces/visit-task/visit-task.interface';
4
4
  import { User, UserSafe, CertificatePath } from './interfaces/user/user.interface';
5
5
  import { DishSnapshot } from './interfaces/store/dishSnapshot.interface';
@@ -107,31 +107,42 @@ export function calcDishFinalPrice(conent: Content): number {
107
107
  export function calcTotalPrice(order: Order): number {
108
108
  let totalPrice = 0;
109
109
  order.content.forEach((orderContentItem) => {
110
- if(order.type === OrderTypeEnum.Buffet) {
111
- const buffetDishItem = getDishItemInBuffet({dishId:orderContentItem.dishSnapshot._id, buffet: order.buffet.snapshot});
110
+ totalPrice+=calcContentPrice({
111
+ orderContentItem,
112
+ buffetItem: order.buffet?.snapshot,
113
+ orderType: order.type,
114
+ adultNum: order.adultNum,
115
+ childNum: order.childNum,
116
+ contents: order.content
117
+ })
118
+ });
119
+ if (order.deliveryFee && !order.selfPickUp) {
120
+ totalPrice += order.deliveryFee;
121
+ }
122
+ if(order.type === OrderTypeEnum.Buffet) {
123
+ totalPrice += calcBuffetTotalPrice(order.buffet.snapshot, order.adultNum, order.childNum)
124
+ }
125
+ return parseMoney(totalPrice);
126
+ }
127
+
128
+ export function calcContentPrice({orderContentItem,buffetItem, orderType, adultNum, childNum,contents}:{orderContentItem:Content, buffetItem: BuffetCombosItems, orderType: OrderTypeEnum, adultNum: number, childNum: number, contents:Content[]}): number {
129
+ if(orderType === OrderTypeEnum.Buffet) {
130
+ const buffetDishItem = getDishItemInBuffet({dishId:orderContentItem.dishSnapshot._id, buffet: buffetItem});
112
131
  if(buffetDishItem) {
113
- const maxUpperLimit = getMaxBuffetDishUpperLimit({buffetDishItem, adultNum: order.adultNum, childNum: order.childNum});
114
- const beforeCount = getOrderedCountByDishId(orderContentItem.dishSnapshot._id, order.content, orderContentItem._id);
132
+ const maxUpperLimit = getMaxBuffetDishUpperLimit({buffetDishItem, adultNum: adultNum, childNum: childNum});
133
+ const beforeCount = getOrderedCountByDishId(orderContentItem.dishSnapshot._id, contents, orderContentItem._id);
115
134
  const maxUpperLimitForThisItem = Math.max(maxUpperLimit - beforeCount, 0)
116
135
  if(maxUpperLimitForThisItem>=orderContentItem.count) {
117
- // price 0;
136
+ return 0;
118
137
  } else {
119
- totalPrice += (orderContentItem.count-maxUpperLimitForThisItem) * calcDishFinalPrice(orderContentItem);
138
+ return (orderContentItem.count-maxUpperLimitForThisItem) * calcDishFinalPrice(orderContentItem);
120
139
  }
121
140
  }else {
122
- totalPrice += orderContentItem.count * calcDishFinalPrice(orderContentItem);
141
+ return orderContentItem.count * calcDishFinalPrice(orderContentItem);
123
142
  }
124
143
  } else {
125
- totalPrice += orderContentItem.count * calcDishFinalPrice(orderContentItem);
144
+ return orderContentItem.count * calcDishFinalPrice(orderContentItem);
126
145
  }
127
- });
128
- if (order.deliveryFee && !order.selfPickUp) {
129
- totalPrice += order.deliveryFee;
130
- }
131
- if(order.type === OrderTypeEnum.Buffet) {
132
- totalPrice += calcBuffetTotalPrice(order.buffet.snapshot, order.adultNum, order.childNum)
133
- }
134
- return parseMoney(totalPrice);
135
146
  }
136
147
 
137
148
  export function getOrderedCountByDishId(dishId, contents:Content[], beforeKey?:string): number{