feat:额外收费
This commit is contained in:
1 parent
2b956342f4
commit
e730b6923c
17 files changed
+461
-153
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import 'package:common_utils/common_utils.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pj_supermarket_cloud/common/index.dart';
|
||||
|
||||
class DiscountsTool {
|
||||
/// 更新用户优惠列表
|
||||
static Future<List<DiscountsItem>?> updateUserDiscountsList({
|
||||
required String userId,
|
||||
}) async {
|
||||
final sysSetting = await AppSettingTool.getSysSetting();
|
||||
final params = {
|
||||
"userId": userId,
|
||||
"hardId": sysSetting.serviceId,
|
||||
};
|
||||
final discountsRes = await WalletApi.getDiscountsListByUserId(params);
|
||||
if (ObjectUtil.isEmpty(discountsRes)) return null;
|
||||
final app = Get.find<AppControl>();
|
||||
final userDao = app.dataBase.getUserDao;
|
||||
// 查询用户表
|
||||
final userEntity = await userDao.findByUserId(userId);
|
||||
if (ObjectUtil.isEmpty(userEntity)) return discountsRes;
|
||||
// 能更新优惠(防止同一个用户频繁更新)
|
||||
if (userEntity!.isUpdateDiscounts()) {
|
||||
userEntity.discountsList = discountsRes;
|
||||
userEntity.discountsUpdateTime = DateTime.now();
|
||||
await userDao.edit(userEntity);
|
||||
}
|
||||
// 更新到用户表
|
||||
return discountsRes;
|
||||
}
|
||||
|
||||
/// 计算额外增加的金额
|
||||
/// [totalPrice] 总金额(分)
|
||||
/// [discountsItem] 优惠项
|
||||
/// [return] 额外增加的金额(分)
|
||||
static Future<int> computedExtraPrice({
|
||||
required String userId,
|
||||
required int totalPrice,
|
||||
required String hourType,
|
||||
}) async {
|
||||
var discountsItems = await updateUserDiscountsList(userId: userId);
|
||||
discountsItems = discountsItems
|
||||
?.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;
|
||||
if (extraPer == null || extraPer <= 1.0) continue;
|
||||
extraPrice += item.computedDiscountsExtraPrice(totalPrice);
|
||||
}
|
||||
return extraPrice;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ export './app/app_setting_tool.dart';
|
||||
export './app/app_sys_tool.dart';
|
||||
export './app/app_user_tool.dart';
|
||||
|
||||
export './discounts/discounts_tool.dart';
|
||||
|
||||
export './json/json_tool.dart';
|
||||
|
||||
export './keyboard/keyboard_tool.dart';
|
||||
|
||||
@@ -56,4 +56,22 @@ abstract class JsonTool {
|
||||
if (value == null) return null;
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
static DiscountsType? stringToDiscountsType(String? value) {
|
||||
return DiscountsType.values.fromCode(value);
|
||||
}
|
||||
|
||||
static String? discountsTypeToString(DiscountsType? value) {
|
||||
if (value == null) return null;
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
static ProductHourType? stringToProductHourType(String? value) {
|
||||
return ProductHourType.values.fromCode(value);
|
||||
}
|
||||
|
||||
static String? productHourTypeToString(ProductHourType? value) {
|
||||
if (value == null) return null;
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user