feat:特色菜收费
This commit is contained in:
1 parent
e5e24231e7
commit
3729e3b896
18 files changed
+93
-26
No files matched your search
@@ -30,12 +30,13 @@ class DiscountsTool {
|
||||
}
|
||||
|
||||
/// 计算额外增加的金额
|
||||
/// [totalPrice] 总金额(分)
|
||||
/// [discountsItem] 优惠项
|
||||
/// [userId] 用户id
|
||||
/// [shopCardList] 购物车列表
|
||||
/// [hourType] 优惠类型
|
||||
/// [return] 额外增加的金额(分)
|
||||
static Future<int> computedExtraPrice({
|
||||
required String userId,
|
||||
required int totalPrice,
|
||||
required List<ShopCardEntity> shopCardList,
|
||||
required String hourType,
|
||||
}) async {
|
||||
var discountsItems = await updateUserDiscountsList(userId: userId);
|
||||
@@ -43,10 +44,30 @@ class DiscountsTool {
|
||||
?.where((element) => element.hourType?.code == hourType)
|
||||
.toList();
|
||||
if (ObjectUtil.isEmpty(discountsItems)) return 0;
|
||||
|
||||
/// 计算额外价格
|
||||
var extraPrice = 0;
|
||||
for (final item in discountsItems!) {
|
||||
final extraPer = item.extraPer;
|
||||
final specialDishEnable = item.specialDishEnable;
|
||||
if (extraPer == null || extraPer <= 1.0) continue;
|
||||
// 计算总价
|
||||
int totalPrice = 0;
|
||||
// 特色菜不额外收费
|
||||
if (!specialDishEnable) {
|
||||
totalPrice = shopCardList
|
||||
.where((item) => item.isPriceIncreased)
|
||||
.map((item) => item.totalPrice)
|
||||
.reduce((value, element) => value + element);
|
||||
extraPrice += item.computedDiscountsExtraPrice(totalPrice);
|
||||
}
|
||||
// 特色菜额外收费
|
||||
if (specialDishEnable) {
|
||||
totalPrice = shopCardList
|
||||
.map((item) => item.totalPrice)
|
||||
.reduce((value, element) => value + element);
|
||||
extraPrice += item.computedDiscountsExtraPrice(totalPrice);
|
||||
}
|
||||
extraPrice += item.computedDiscountsExtraPrice(totalPrice);
|
||||
}
|
||||
return extraPrice;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import 'package:pj_supermarket_cloud/common/index.dart';
|
||||
|
||||
abstract class JsonTool {
|
||||
static bool stringToBoolean(String value) {
|
||||
static bool stringToBoolean(String? value) {
|
||||
if (value == null) return false;
|
||||
return value == '1';
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user