@freedom_sky/feige-lib 4.54.2 → 4.55.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.
package/dist/index.d.ts CHANGED
@@ -185,6 +185,7 @@ export declare function getLanguageFromCountryCode(countryCode: any): string;
185
185
  * 根据dishID返回已经下单的数量
186
186
  *
187
187
  * @param {Order} order 店铺
188
- * @returns {Number} 返回当前数量
188
+ * @param dishId
189
+ * @returns {number} 返回当前数量
189
190
  */
190
- export declare function getDishCountByIdInAllUncanceledTasks(order: Order, dishId: string): Number;
191
+ export declare function getDishCountByIdInAllUncanceledTasks(order: Order, dishId: string): number;
package/dist/index.js CHANGED
@@ -169,6 +169,7 @@ exports.getOrderedCountByDishId = getOrderedCountByDishId;
169
169
  */
170
170
  function calcReceivablePrice(order, processArr, noTax) {
171
171
  if (noTax === void 0) { noTax = false; }
172
+ var _a;
172
173
  var totalDiscountPrice = 0;
173
174
  var resultProcessArr = [];
174
175
  var totalPrice = calcTotalPrice(order);
@@ -262,6 +263,16 @@ function calcReceivablePrice(order, processArr, noTax) {
262
263
  taxObj[taxKey] = (taxObj[taxKey] || 0) + parseMoney(taxFare);
263
264
  });
264
265
  });
266
+ // buffet price
267
+ if (order.type === order_enum_1.OrderTypeEnum.Buffet) {
268
+ var buffetTotalPrice_1 = index_1.calcBuffetTotalPrice((_a = order.buffet) === null || _a === void 0 ? void 0 : _a.snapshot, order.adultNum, order.childNum);
269
+ var sharedMarkDown_1 = (totalMarkDown * buffetTotalPrice_1) / receivablePriceAfterDiscount;
270
+ order.buffet.taxes.forEach(function (tax) {
271
+ var taxFare = (buffetTotalPrice_1 - sharedMarkDown_1) * tax.rate;
272
+ var taxKey = tax.name + "(" + big_js_1.default(tax.rate).times(100) + "%)";
273
+ taxObj[taxKey] = (taxObj[taxKey] || 0) + parseMoney(taxFare);
274
+ });
275
+ }
265
276
  }
266
277
  else if (order.taxType === tax_enum_1.TaxTypeEnum.PriceHaveTaxBindOrder && !noTax) {
267
278
  var totalTaxRate_1 = 0;
@@ -521,13 +532,19 @@ exports.getLanguageFromCountryCode = getLanguageFromCountryCode;
521
532
  * 根据dishID返回已经下单的数量
522
533
  *
523
534
  * @param {Order} order 店铺
524
- * @returns {Number} 返回当前数量
535
+ * @param dishId
536
+ * @returns {number} 返回当前数量
525
537
  */
526
538
  function getDishCountByIdInAllUncanceledTasks(order, dishId) {
527
539
  var count = 0;
528
540
  if (order.tasks) {
529
- count = order.tasks.filter(function (task) { return task.status !== const_1.CONST.STATUS.CANCELLED; }).reduce(function (count, task) {
530
- return count + task.content.filter(function (item) { return String(item.dishSnapshot._id) === String(dishId); }).reduce(function (value, item) { return value + item.count; }, 0);
541
+ count = order.tasks
542
+ .filter(function (task) { return task.status !== const_1.CONST.STATUS.CANCELLED; })
543
+ .reduce(function (count, task) {
544
+ return (count +
545
+ task.content
546
+ .filter(function (item) { return String(item.dishSnapshot._id) === String(dishId); })
547
+ .reduce(function (value, item) { return value + item.count; }, 0));
531
548
  }, 0);
532
549
  }
533
550
  return count;
@@ -48,6 +48,10 @@ export interface Order {
48
48
  }[];
49
49
  readonly buffet?: {
50
50
  snapshot: BuffetCombosItems;
51
+ taxes: {
52
+ name: string;
53
+ rate: number;
54
+ }[];
51
55
  };
52
56
  readonly adultNum?: number;
53
57
  readonly childNum?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freedom_sky/feige-lib",
3
- "version": "4.54.2",
3
+ "version": "4.55.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -144,7 +144,7 @@ export function calcContentPrice({
144
144
  childNum: number;
145
145
  contents: Content[];
146
146
  }): number {
147
- if(orderContentItem.retreated) return 0;
147
+ if (orderContentItem.retreated) return 0;
148
148
  if (orderType === OrderTypeEnum.Buffet) {
149
149
  const buffetDishItem = getDishItemInBuffet({ dishId: orderContentItem.dishSnapshot._id, buffet: buffetItem });
150
150
  if (buffetDishItem) {
@@ -179,10 +179,12 @@ export function calcContentPrice({
179
179
  */
180
180
  export function getOrderedCountByDishId(dishId, contents: Content[], beforeKey?: string): number {
181
181
  let count = 0;
182
- for (const content of contents.filter((content) => !content.retreated && String(content.dishSnapshot._id) === String(dishId))) {
182
+ for (const content of contents.filter(
183
+ (content) => !content.retreated && String(content.dishSnapshot._id) === String(dishId),
184
+ )) {
183
185
  if (beforeKey && String(content._id) === String(beforeKey)) break;
184
186
  count += content.count;
185
- }
187
+ }
186
188
  return count;
187
189
  }
188
190
 
@@ -302,6 +304,16 @@ export function calcReceivablePrice(
302
304
  taxObj[taxKey] = (taxObj[taxKey] || 0) + parseMoney(taxFare);
303
305
  });
304
306
  });
307
+ // buffet price
308
+ if (order.type === OrderTypeEnum.Buffet) {
309
+ const buffetTotalPrice = calcBuffetTotalPrice(order.buffet?.snapshot, order.adultNum, order.childNum);
310
+ const sharedMarkDown = (totalMarkDown * buffetTotalPrice) / receivablePriceAfterDiscount;
311
+ order.buffet.taxes.forEach((tax) => {
312
+ const taxFare = (buffetTotalPrice - sharedMarkDown) * tax.rate;
313
+ const taxKey = `${tax.name}(${Big(tax.rate).times(100)}%)`;
314
+ taxObj[taxKey] = (taxObj[taxKey] || 0) + parseMoney(taxFare);
315
+ });
316
+ }
305
317
  } else if (order.taxType === TaxTypeEnum.PriceHaveTaxBindOrder && !noTax) {
306
318
  let totalTaxRate = 0;
307
319
  order.priceHaveTaxBindOrderTaxes.forEach((item) => {
@@ -566,14 +578,22 @@ export function getLanguageFromCountryCode(countryCode): string {
566
578
  * 根据dishID返回已经下单的数量
567
579
  *
568
580
  * @param {Order} order 店铺
569
- * @returns {Number} 返回当前数量
581
+ * @param dishId
582
+ * @returns {number} 返回当前数量
570
583
  */
571
- export function getDishCountByIdInAllUncanceledTasks(order: Order, dishId: string): Number {
584
+ export function getDishCountByIdInAllUncanceledTasks(order: Order, dishId: string): number {
572
585
  let count = 0;
573
586
  if (order.tasks) {
574
- count = order.tasks.filter(task=>task.status!==CONST.STATUS.CANCELLED).reduce((count, task) => {
575
- return count + task.content.filter(item=>String(item.dishSnapshot._id)===String(dishId)).reduce((value, item) => value+item.count,0);
576
- },0);
587
+ count = order.tasks
588
+ .filter((task) => task.status !== CONST.STATUS.CANCELLED)
589
+ .reduce((count, task) => {
590
+ return (
591
+ count +
592
+ task.content
593
+ .filter((item) => String(item.dishSnapshot._id) === String(dishId))
594
+ .reduce((value, item) => value + item.count, 0)
595
+ );
596
+ }, 0);
577
597
  }
578
598
  return count;
579
- }
599
+ }
@@ -48,6 +48,10 @@ export interface Order {
48
48
  }[];
49
49
  readonly buffet?: {
50
50
  snapshot: BuffetCombosItems;
51
+ taxes: {
52
+ name: string;
53
+ rate: number;
54
+ }[];
51
55
  };
52
56
  readonly adultNum?: number;
53
57
  readonly childNum?: number;