feat: 更新钱包规则和用户模型以支持食堂信息
- 在 `ServiceUser` 模型中添加 `canteenId` 字段以支持查询用户食堂信息 - 修改 `ServiceMchRule` 模型,增加 `rulePriceType` 字段并调整 `basePrice` 和 `multiple` 字段类型 - 更新 `CanteenProductController` 中的价格计算逻辑,支持根据食堂ID和规则类型计算额外费用
This commit is contained in:
1 parent
cf9f8da767
commit
01e14a4c1d
6 files changed
+71
-19
No files matched your search
@@ -60,7 +60,7 @@ abstract class WalletApi {
|
||||
);
|
||||
if (res.data == null) return null;
|
||||
return res.data
|
||||
?.map<ServiceMchRule>((e) => ServiceTenant.fromJson(e))
|
||||
?.map<ServiceMchRule>((e) => ServiceMchRule.fromJson(e))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,9 @@ class ServiceUser {
|
||||
/// 卡号
|
||||
String? walletCardNumber;
|
||||
|
||||
/// 查询用户食堂信息
|
||||
String? canteenId;
|
||||
|
||||
/// 构造函数
|
||||
ServiceUser({
|
||||
this.userId,
|
||||
@@ -49,6 +52,7 @@ class ServiceUser {
|
||||
this.walletBalance,
|
||||
this.walletIsFreeze,
|
||||
this.walletCardNumber,
|
||||
this.canteenId,
|
||||
});
|
||||
|
||||
factory ServiceUser.fromJson(Map<String, dynamic> json) =>
|
||||
|
||||
@@ -18,6 +18,7 @@ ServiceUser _$ServiceUserFromJson(Map<String, dynamic> json) => ServiceUser(
|
||||
walletIsFreeze:
|
||||
JsonTool.stringToBoolean(json['walletIsFreeze'] as String),
|
||||
walletCardNumber: json['walletCardNumber'] as String?,
|
||||
canteenId: json['canteenId'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ServiceUserToJson(ServiceUser instance) =>
|
||||
@@ -32,6 +33,7 @@ Map<String, dynamic> _$ServiceUserToJson(ServiceUser instance) =>
|
||||
'walletBalance': instance.walletBalance,
|
||||
'walletIsFreeze': JsonTool.booleanToString(instance.walletIsFreeze),
|
||||
'walletCardNumber': instance.walletCardNumber,
|
||||
'canteenId': instance.canteenId,
|
||||
};
|
||||
|
||||
ServiceAuth _$ServiceAuthFromJson(Map<String, dynamic> json) => ServiceAuth(
|
||||
|
||||
@@ -64,21 +64,29 @@ class ServiceMchRule {
|
||||
String targetMchId;
|
||||
|
||||
/// 规则配置id
|
||||
int rulePriceConfigId;
|
||||
String rulePriceConfigId;
|
||||
|
||||
/// 钱包规则类型
|
||||
/// 10 跨单位额外支付
|
||||
/// 20 每餐额外支付
|
||||
String? rulePriceType;
|
||||
|
||||
/// 基础价格
|
||||
int basePrice;
|
||||
@JsonKey(fromJson: JsonTool.stringToInt, toJson: JsonTool.intToString)
|
||||
int? basePrice;
|
||||
|
||||
/// 额外需要支付的倍数
|
||||
int multiple;
|
||||
@JsonKey(fromJson: JsonTool.stringToInt, toJson: JsonTool.intToString)
|
||||
int? multiple;
|
||||
|
||||
ServiceMchRule({
|
||||
required this.id,
|
||||
required this.sourceMchId,
|
||||
required this.targetMchId,
|
||||
required this.rulePriceConfigId,
|
||||
required this.basePrice,
|
||||
required this.multiple,
|
||||
this.rulePriceType,
|
||||
this.basePrice,
|
||||
this.multiple,
|
||||
});
|
||||
|
||||
factory ServiceMchRule.fromJson(Map<String, dynamic> json) =>
|
||||
|
||||
@@ -42,9 +42,10 @@ ServiceMchRule _$ServiceMchRuleFromJson(Map<String, dynamic> json) =>
|
||||
id: json['id'] as String,
|
||||
sourceMchId: json['sourceMchId'] as String,
|
||||
targetMchId: json['targetMchId'] as String,
|
||||
rulePriceConfigId: (json['rulePriceConfigId'] as num).toInt(),
|
||||
basePrice: (json['basePrice'] as num).toInt(),
|
||||
multiple: (json['multiple'] as num).toInt(),
|
||||
rulePriceConfigId: json['rulePriceConfigId'] as String,
|
||||
rulePriceType: json['rulePriceType'] as String?,
|
||||
basePrice: JsonTool.stringToInt(json['basePrice'] as String?),
|
||||
multiple: JsonTool.stringToInt(json['multiple'] as String?),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ServiceMchRuleToJson(ServiceMchRule instance) =>
|
||||
@@ -53,6 +54,7 @@ Map<String, dynamic> _$ServiceMchRuleToJson(ServiceMchRule instance) =>
|
||||
'sourceMchId': instance.sourceMchId,
|
||||
'targetMchId': instance.targetMchId,
|
||||
'rulePriceConfigId': instance.rulePriceConfigId,
|
||||
'basePrice': instance.basePrice,
|
||||
'multiple': instance.multiple,
|
||||
'rulePriceType': instance.rulePriceType,
|
||||
'basePrice': JsonTool.intToString(instance.basePrice),
|
||||
'multiple': JsonTool.intToString(instance.multiple),
|
||||
};
|
||||
@@ -71,7 +71,8 @@ class CanteenProductController extends GetxController with OrderMixin {
|
||||
try {
|
||||
await SyncProductTool.updateDatabase();
|
||||
await _getMchRule();
|
||||
} catch (e) {
|
||||
} catch (e, stack) {
|
||||
logger.e("|$_tag|初始化资源失败:error|$e|stack|$stack");
|
||||
Toast.error(msg: "初始化资源失败,请检查网络情况");
|
||||
EasyLoading.dismiss();
|
||||
Get.offAndToNamed(RouteNames.panel);
|
||||
@@ -265,11 +266,16 @@ class CanteenProductController extends GetxController with OrderMixin {
|
||||
|
||||
// 计算额外的价格
|
||||
Future<void> _computedAmountMealPrice() async {
|
||||
final price = await getAmountMealPrice(
|
||||
price: totalPrice.value,
|
||||
);
|
||||
if (ObjectUtil.isNotEmpty(price)) {
|
||||
amountMealPrice.value = int.parse(price!.toString());
|
||||
// final price = await getAmountMealPrice(
|
||||
// price: totalPrice.value,
|
||||
// );
|
||||
// if (ObjectUtil.isNotEmpty(price)) {
|
||||
// amountMealPrice.value = int.parse(price!.toString());
|
||||
// sendSubScreen();
|
||||
// }
|
||||
final extraPrice = await _getMchRulePrice(totalPrice.value);
|
||||
if (extraPrice != 0) {
|
||||
amountMealPrice.value = extraPrice;
|
||||
sendSubScreen();
|
||||
}
|
||||
}
|
||||
@@ -320,10 +326,40 @@ class CanteenProductController extends GetxController with OrderMixin {
|
||||
if (!isNetwork) return;
|
||||
final pa = {"sourceMchId": appSetting.serviceMerchantId};
|
||||
final mchRoleList = await WalletApi.getMchRoleList(pa);
|
||||
if (ObjectUtil.isEmptyList(mchRoleList)) return;
|
||||
if (mchRoleList == null) return;
|
||||
final priceSetting = await AppSettingTool.getCanteenExtraPriceConfig();
|
||||
if (priceSetting == null) return;
|
||||
priceSetting.mchRoleList = mchRoleList!;
|
||||
priceSetting.mchRoleList = mchRoleList;
|
||||
await AppSettingTool.setCanteenExtraPriceConfig(priceSetting);
|
||||
}
|
||||
|
||||
Future<int> _getMchRulePrice(int price, {String? userCanteenId}) async {
|
||||
int extraPrice = 0;
|
||||
final setting = await AppSettingTool.getCanteenExtraPriceConfig();
|
||||
if (setting == null || ObjectUtil.isEmptyList(setting.mchRoleList)) {
|
||||
return extraPrice;
|
||||
}
|
||||
for (final v in setting.mchRoleList!) {
|
||||
int? basePrice = v.basePrice;
|
||||
int? multiple = v.multiple;
|
||||
String? rulePriceType = v.rulePriceType;
|
||||
if (basePrice == null || multiple == null || rulePriceType == null) {
|
||||
continue;
|
||||
}
|
||||
if (price < basePrice) continue;
|
||||
final surplus = price - basePrice;
|
||||
// 10 跨单位额外支付
|
||||
if (rulePriceType == "10") {
|
||||
extraPrice = (surplus * multiple / 100).round();
|
||||
break;
|
||||
}
|
||||
// 20 每餐额外支付
|
||||
if (rulePriceType == "20") {
|
||||
if (userCanteenId == null || v.targetMchId != userCanteenId) continue;
|
||||
extraPrice += (surplus * multiple / 100).round();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return extraPrice;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user