@freedom_sky/feige-lib 4.51.0 → 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.
@@ -0,0 +1,22 @@
1
+ import { BuffetCombosItems, BuffetDishItem } from "../index";
2
+ /**
3
+ * 计算自助餐总价
4
+ */
5
+ export declare function calcBuffetTotalPrice(buffetCombosItem: BuffetCombosItems, adultNum: number, childNum: number): number;
6
+ export declare function dishShowPriceWithBuffet({ dishPrice, dishId, buffet, orderedCound, adultNum, childNum }: {
7
+ dishPrice: number;
8
+ dishId: string;
9
+ buffet?: BuffetCombosItems;
10
+ orderedCound: number;
11
+ adultNum: number;
12
+ childNum: number;
13
+ }): number;
14
+ export declare function getDishItemInBuffet({ dishId, buffet }: {
15
+ dishId: string;
16
+ buffet?: BuffetCombosItems;
17
+ }): BuffetDishItem | undefined;
18
+ export declare function getMaxBuffetDishUpperLimit({ buffetDishItem, adultNum, childNum }: {
19
+ buffetDishItem: BuffetDishItem;
20
+ adultNum: number;
21
+ childNum: number;
22
+ }): number;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * 计算自助餐总价
5
+ */
6
+ function calcBuffetTotalPrice(buffetCombosItem, adultNum, childNum) {
7
+ return buffetCombosItem.price.adult * adultNum * buffetCombosItem.price.child * childNum;
8
+ }
9
+ exports.calcBuffetTotalPrice = calcBuffetTotalPrice;
10
+ function dishShowPriceWithBuffet(_a) {
11
+ var dishPrice = _a.dishPrice, dishId = _a.dishId, buffet = _a.buffet, orderedCound = _a.orderedCound, adultNum = _a.adultNum, childNum = _a.childNum;
12
+ var buffetDishItem = getDishItemInBuffet({ dishId: dishId, buffet: buffet });
13
+ if (buffetDishItem) {
14
+ if (orderedCound < getMaxBuffetDishUpperLimit({ buffetDishItem: buffetDishItem, adultNum: adultNum, childNum: childNum })) {
15
+ return 0;
16
+ }
17
+ else {
18
+ return dishPrice;
19
+ }
20
+ }
21
+ else {
22
+ return dishPrice;
23
+ }
24
+ }
25
+ exports.dishShowPriceWithBuffet = dishShowPriceWithBuffet;
26
+ function getDishItemInBuffet(_a) {
27
+ var dishId = _a.dishId, buffet = _a.buffet;
28
+ return buffet === null || buffet === void 0 ? void 0 : buffet.dishes.find(function (item) { return item.dishId === dishId; });
29
+ }
30
+ exports.getDishItemInBuffet = getDishItemInBuffet;
31
+ function getMaxBuffetDishUpperLimit(_a) {
32
+ var buffetDishItem = _a.buffetDishItem, adultNum = _a.adultNum, childNum = _a.childNum;
33
+ if (!buffetDishItem)
34
+ throw 'No buffet dish item';
35
+ if (!buffetDishItem.upperLimit.enable)
36
+ return Infinity;
37
+ return Math.ceil(buffetDishItem.upperLimit.adult * adultNum + buffetDishItem.upperLimit.child * childNum);
38
+ }
39
+ exports.getMaxBuffetDishUpperLimit = getMaxBuffetDishUpperLimit;
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,8 @@ 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';
34
+ export * from './buffet/index';
33
35
  export { Order, Process, Content, Checkout, CONST, DishSnapshot, User, UserSafe, CertificatePath, Task, VisitTask, moment, PrintStatusEnum, PrinterDeviceTypeEnum, PrinterWidthEnum, Big, };
34
36
  /**
35
37
  * 小数转化为金额,去除分位之后的尾数
@@ -54,6 +56,15 @@ export declare function calcDishFinalPrice(conent: Content): number;
54
56
  *
55
57
  */
56
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;
67
+ export declare function getOrderedCountByDishId(dishId: any, contents: Content[], beforeKey?: string): number;
57
68
  /**
58
69
  * 计算处理后的应收金额
59
70
  *
package/dist/index.js CHANGED
@@ -33,6 +33,9 @@ exports.moment = moment;
33
33
  var big_js_1 = require("big.js");
34
34
  exports.Big = big_js_1.default;
35
35
  var tax_enum_1 = require("./enum/tax.enum");
36
+ var order_enum_1 = require("./enum/order.enum");
37
+ var index_1 = require("./buffet/index");
38
+ __export(require("./buffet/index"));
36
39
  /**
37
40
  * 小数转化为金额,去除分位之后的尾数
38
41
  *
@@ -86,14 +89,60 @@ exports.calcDishFinalPrice = calcDishFinalPrice;
86
89
  function calcTotalPrice(order) {
87
90
  var totalPrice = 0;
88
91
  order.content.forEach(function (orderContentItem) {
89
- totalPrice += orderContentItem.count * calcDishFinalPrice(orderContentItem);
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
+ });
90
101
  });
91
102
  if (order.deliveryFee && !order.selfPickUp) {
92
103
  totalPrice += order.deliveryFee;
93
104
  }
105
+ if (order.type === order_enum_1.OrderTypeEnum.Buffet) {
106
+ totalPrice += index_1.calcBuffetTotalPrice(order.buffet.snapshot, order.adultNum, order.childNum);
107
+ }
94
108
  return parseMoney(totalPrice);
95
109
  }
96
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;
135
+ function getOrderedCountByDishId(dishId, contents, beforeKey) {
136
+ var count = 0;
137
+ for (var _i = 0, _a = contents.filter(function (content) { return content.dishSnapshot._id === dishId; }); _i < _a.length; _i++) {
138
+ var content = _a[_i];
139
+ if (beforeKey && content._id === beforeKey)
140
+ break;
141
+ count += content.count;
142
+ }
143
+ return count;
144
+ }
145
+ exports.getOrderedCountByDishId = getOrderedCountByDishId;
97
146
  /**
98
147
  * 计算处理后的应收金额
99
148
  *
@@ -2,6 +2,7 @@ import { DishSnapshot } from '../store/dishSnapshot.interface';
2
2
  import { PrintStatusEnum } from '../../enum/printer.enum';
3
3
  import { OrderTypeEnum } from '../../enum/order.enum';
4
4
  import { TaxTypeEnum } from '../../enum/tax.enum';
5
+ import { BuffetCombosItems } from '../store/store.interface';
5
6
  export interface Order {
6
7
  readonly _id: string;
7
8
  readonly serialOrderId: string;
@@ -45,6 +46,11 @@ export interface Order {
45
46
  name: string;
46
47
  volume: number;
47
48
  }[];
49
+ readonly buffet?: {
50
+ snapshot: BuffetCombosItems;
51
+ };
52
+ readonly adultNum?: number;
53
+ readonly childNum?: number;
48
54
  }
49
55
  export interface Content {
50
56
  _id?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freedom_sky/feige-lib",
3
- "version": "4.51.0",
3
+ "version": "4.51.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -0,0 +1,30 @@
1
+ import {BuffetCombosItems, BuffetDishItem} from "../index"
2
+ /**
3
+ * 计算自助餐总价
4
+ */
5
+ export function calcBuffetTotalPrice(buffetCombosItem:BuffetCombosItems, adultNum: number, childNum: number): number {
6
+ return buffetCombosItem.price.adult*adultNum * buffetCombosItem.price.child* childNum
7
+ }
8
+
9
+ export function dishShowPriceWithBuffet({dishPrice, dishId, buffet, orderedCound, adultNum, childNum}:{dishPrice:number, dishId:string, buffet?: BuffetCombosItems, orderedCound: number, adultNum: number, childNum: number}) {
10
+ const buffetDishItem = getDishItemInBuffet({dishId, buffet})
11
+ if(buffetDishItem) {
12
+ if(orderedCound<getMaxBuffetDishUpperLimit({buffetDishItem, adultNum, childNum})) {
13
+ return 0;
14
+ } else {
15
+ return dishPrice;
16
+ }
17
+ } else {
18
+ return dishPrice;
19
+ }
20
+ }
21
+
22
+ export function getDishItemInBuffet({dishId, buffet}:{dishId:string, buffet?: BuffetCombosItems}):BuffetDishItem|undefined {
23
+ return buffet?.dishes.find((item)=>item.dishId===dishId)
24
+ }
25
+
26
+ export function getMaxBuffetDishUpperLimit({buffetDishItem, adultNum, childNum}:{buffetDishItem:BuffetDishItem, adultNum: number, childNum: number}):number {
27
+ if(!buffetDishItem) throw 'No buffet dish item'
28
+ if(!buffetDishItem.upperLimit.enable) return Infinity;
29
+ return Math.ceil(buffetDishItem.upperLimit.adult*adultNum + buffetDishItem.upperLimit.child*childNum);
30
+ }
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';
@@ -32,6 +32,9 @@ export { PayCompanyEnum } from './enum/pay-company.enum';
32
32
  import * as moment from 'moment';
33
33
  import Big from 'big.js';
34
34
  import { TaxTypeEnum } from './enum/tax.enum';
35
+ import { OrderTypeEnum } from './enum/order.enum';
36
+ import { calcBuffetTotalPrice, getDishItemInBuffet, getMaxBuffetDishUpperLimit } from './buffet/index';
37
+ export * from './buffet/index';
35
38
  export {
36
39
  Order,
37
40
  Process,
@@ -104,14 +107,54 @@ export function calcDishFinalPrice(conent: Content): number {
104
107
  export function calcTotalPrice(order: Order): number {
105
108
  let totalPrice = 0;
106
109
  order.content.forEach((orderContentItem) => {
107
- totalPrice += orderContentItem.count * calcDishFinalPrice(orderContentItem);
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
+ })
108
118
  });
109
119
  if (order.deliveryFee && !order.selfPickUp) {
110
120
  totalPrice += order.deliveryFee;
111
121
  }
122
+ if(order.type === OrderTypeEnum.Buffet) {
123
+ totalPrice += calcBuffetTotalPrice(order.buffet.snapshot, order.adultNum, order.childNum)
124
+ }
112
125
  return parseMoney(totalPrice);
113
126
  }
114
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});
131
+ if(buffetDishItem) {
132
+ const maxUpperLimit = getMaxBuffetDishUpperLimit({buffetDishItem, adultNum: adultNum, childNum: childNum});
133
+ const beforeCount = getOrderedCountByDishId(orderContentItem.dishSnapshot._id, contents, orderContentItem._id);
134
+ const maxUpperLimitForThisItem = Math.max(maxUpperLimit - beforeCount, 0)
135
+ if(maxUpperLimitForThisItem>=orderContentItem.count) {
136
+ return 0;
137
+ } else {
138
+ return (orderContentItem.count-maxUpperLimitForThisItem) * calcDishFinalPrice(orderContentItem);
139
+ }
140
+ }else {
141
+ return orderContentItem.count * calcDishFinalPrice(orderContentItem);
142
+ }
143
+ } else {
144
+ return orderContentItem.count * calcDishFinalPrice(orderContentItem);
145
+ }
146
+ }
147
+
148
+ export function getOrderedCountByDishId(dishId, contents:Content[], beforeKey?:string): number{
149
+ let count = 0;
150
+ for(let content of contents.filter(content=>content.dishSnapshot._id===dishId)) {
151
+ if(beforeKey && content._id === beforeKey) break;
152
+ count += content.count
153
+ }
154
+ return count
155
+ }
156
+
157
+
115
158
  /**
116
159
  * 计算处理后的应收金额
117
160
  *
@@ -2,6 +2,7 @@ import { DishSnapshot } from '../store/dishSnapshot.interface';
2
2
  import { PrintStatusEnum } from '../../enum/printer.enum';
3
3
  import { OrderTypeEnum } from '../../enum/order.enum';
4
4
  import { TaxTypeEnum } from '../../enum/tax.enum';
5
+ import { BuffetCombosItems } from '../store/store.interface';
5
6
  export interface Order {
6
7
  readonly _id: string;
7
8
  readonly serialOrderId: string;
@@ -45,6 +46,11 @@ export interface Order {
45
46
  name: string;
46
47
  volume: number;
47
48
  }[];
49
+ readonly buffet?:{
50
+ snapshot: BuffetCombosItems,
51
+ };
52
+ readonly adultNum?: number;
53
+ readonly childNum?: number;
48
54
  }
49
55
 
50
56
  export interface Content {