@freedom_sky/feige-lib 4.51.0 → 4.51.1
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/buffet/index.d.ts +22 -0
- package/dist/buffet/index.js +39 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +37 -1
- package/dist/interfaces/order/order.interface.d.ts +6 -0
- package/package.json +1 -1
- package/src/buffet/index.ts +30 -0
- package/src/index.ts +33 -1
- package/src/interfaces/order/order.interface.ts +6 -0
|
@@ -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
|
@@ -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
|
+
export * from './buffet/index';
|
|
33
34
|
export { Order, Process, Content, Checkout, CONST, DishSnapshot, User, UserSafe, CertificatePath, Task, VisitTask, moment, PrintStatusEnum, PrinterDeviceTypeEnum, PrinterWidthEnum, Big, };
|
|
34
35
|
/**
|
|
35
36
|
* 小数转化为金额,去除分位之后的尾数
|
|
@@ -54,6 +55,7 @@ export declare function calcDishFinalPrice(conent: Content): number;
|
|
|
54
55
|
*
|
|
55
56
|
*/
|
|
56
57
|
export declare function calcTotalPrice(order: Order): number;
|
|
58
|
+
export declare function getOrderedCountByDishId(dishId: any, contents: Content[], beforeKey?: string): number;
|
|
57
59
|
/**
|
|
58
60
|
* 计算处理后的应收金额
|
|
59
61
|
*
|
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,47 @@ exports.calcDishFinalPrice = calcDishFinalPrice;
|
|
|
86
89
|
function calcTotalPrice(order) {
|
|
87
90
|
var totalPrice = 0;
|
|
88
91
|
order.content.forEach(function (orderContentItem) {
|
|
89
|
-
|
|
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
|
+
}
|
|
90
112
|
});
|
|
91
113
|
if (order.deliveryFee && !order.selfPickUp) {
|
|
92
114
|
totalPrice += order.deliveryFee;
|
|
93
115
|
}
|
|
116
|
+
if (order.type === order_enum_1.OrderTypeEnum.Buffet) {
|
|
117
|
+
totalPrice += index_1.calcBuffetTotalPrice(order.buffet.snapshot, order.adultNum, order.childNum);
|
|
118
|
+
}
|
|
94
119
|
return parseMoney(totalPrice);
|
|
95
120
|
}
|
|
96
121
|
exports.calcTotalPrice = calcTotalPrice;
|
|
122
|
+
function getOrderedCountByDishId(dishId, contents, beforeKey) {
|
|
123
|
+
var count = 0;
|
|
124
|
+
for (var _i = 0, _a = contents.filter(function (content) { return content.dishSnapshot._id === dishId; }); _i < _a.length; _i++) {
|
|
125
|
+
var content = _a[_i];
|
|
126
|
+
if (beforeKey && content._id === beforeKey)
|
|
127
|
+
break;
|
|
128
|
+
count += content.count;
|
|
129
|
+
}
|
|
130
|
+
return count;
|
|
131
|
+
}
|
|
132
|
+
exports.getOrderedCountByDishId = getOrderedCountByDishId;
|
|
97
133
|
/**
|
|
98
134
|
* 计算处理后的应收金额
|
|
99
135
|
*
|
|
@@ -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
|
@@ -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
|
@@ -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,43 @@ 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
|
-
|
|
110
|
+
if(order.type === OrderTypeEnum.Buffet) {
|
|
111
|
+
const buffetDishItem = getDishItemInBuffet({dishId:orderContentItem.dishSnapshot._id, buffet: order.buffet.snapshot});
|
|
112
|
+
if(buffetDishItem) {
|
|
113
|
+
const maxUpperLimit = getMaxBuffetDishUpperLimit({buffetDishItem, adultNum: order.adultNum, childNum: order.childNum});
|
|
114
|
+
const beforeCount = getOrderedCountByDishId(orderContentItem.dishSnapshot._id, order.content, orderContentItem._id);
|
|
115
|
+
const maxUpperLimitForThisItem = Math.max(maxUpperLimit - beforeCount, 0)
|
|
116
|
+
if(maxUpperLimitForThisItem>=orderContentItem.count) {
|
|
117
|
+
// price 0;
|
|
118
|
+
} else {
|
|
119
|
+
totalPrice += (orderContentItem.count-maxUpperLimitForThisItem) * calcDishFinalPrice(orderContentItem);
|
|
120
|
+
}
|
|
121
|
+
}else {
|
|
122
|
+
totalPrice += orderContentItem.count * calcDishFinalPrice(orderContentItem);
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
totalPrice += orderContentItem.count * calcDishFinalPrice(orderContentItem);
|
|
126
|
+
}
|
|
108
127
|
});
|
|
109
128
|
if (order.deliveryFee && !order.selfPickUp) {
|
|
110
129
|
totalPrice += order.deliveryFee;
|
|
111
130
|
}
|
|
131
|
+
if(order.type === OrderTypeEnum.Buffet) {
|
|
132
|
+
totalPrice += calcBuffetTotalPrice(order.buffet.snapshot, order.adultNum, order.childNum)
|
|
133
|
+
}
|
|
112
134
|
return parseMoney(totalPrice);
|
|
113
135
|
}
|
|
114
136
|
|
|
137
|
+
export function getOrderedCountByDishId(dishId, contents:Content[], beforeKey?:string): number{
|
|
138
|
+
let count = 0;
|
|
139
|
+
for(let content of contents.filter(content=>content.dishSnapshot._id===dishId)) {
|
|
140
|
+
if(beforeKey && content._id === beforeKey) break;
|
|
141
|
+
count += content.count
|
|
142
|
+
}
|
|
143
|
+
return count
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
|
|
115
147
|
/**
|
|
116
148
|
* 计算处理后的应收金额
|
|
117
149
|
*
|
|
@@ -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 {
|