feat: 添加商户规则支持和用户实体扩展

- 在 `UserEntity` 中添加 `canteenId` 字段以支持离线模式
- 新增 `ServiceMchRule` 模型和相关 API 方法用于获取商户规则
- 更新 `CanteenExtraPriceSetting` 模型以包含商户规则列表
- 在 `CanteenProductController` 中添加获取商户规则的逻辑
- 更新数据库表结构以支持 `canteenId` 字段
This commit is contained in:
dzc committed 2025-05-15 10:28:43 +08:00
1 parent 47ad782e9a
commit cf9f8da767
10 files changed
+104 -4

No files matched your search

+12
View File
@@ -51,4 +51,16 @@ abstract class WalletApi {
if (res.data == null) return null;
return res.data;
}
/// 获取钱包规则(android离线计算展示使用)
static Future<List<ServiceMchRule>?> getMchRoleList(dynamic pa) async {
final res = await HttpManage().dio.get(
"/wallet/mch-rule-join/ad/list",
queryParameters: pa,
);
if (res.data == null) return null;
return res.data
?.map<ServiceMchRule>((e) => ServiceTenant.fromJson(e))
.toList();
}
}
@@ -52,3 +52,37 @@ class ServicePaySetting {
Map<String, dynamic> toJson() => _$ServicePaySettingToJson(this);
}
@JsonSerializable()
class ServiceMchRule {
String id;
/// 源商户id
String sourceMchId;
/// 目标商户id
String targetMchId;
/// 规则配置id
int rulePriceConfigId;
/// 基础价格
int basePrice;
/// 额外需要支付的倍数
int multiple;
ServiceMchRule({
required this.id,
required this.sourceMchId,
required this.targetMchId,
required this.rulePriceConfigId,
required this.basePrice,
required this.multiple,
});
factory ServiceMchRule.fromJson(Map<String, dynamic> json) =>
_$ServiceMchRuleFromJson(json);
Map<String, dynamic> toJson() => _$ServiceMchRuleToJson(this);
}
@@ -36,3 +36,23 @@ Map<String, dynamic> _$ServicePaySettingToJson(ServicePaySetting instance) =>
'offLineOrderApplyEnable':
JsonTool.booleanToString(instance.offLineOrderApplyEnable),
};
ServiceMchRule _$ServiceMchRuleFromJson(Map<String, dynamic> json) =>
ServiceMchRule(
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(),
);
Map<String, dynamic> _$ServiceMchRuleToJson(ServiceMchRule instance) =>
<String, dynamic>{
'id': instance.id,
'sourceMchId': instance.sourceMchId,
'targetMchId': instance.targetMchId,
'rulePriceConfigId': instance.rulePriceConfigId,
'basePrice': instance.basePrice,
'multiple': instance.multiple,
};
@@ -222,17 +222,22 @@ class CanteenExtraPriceSetting extends Equatable {
/// 超过的倍数
double payAmountMealTimes;
// 商户支付规则列表
List<ServiceMchRule>? mchRoleList;
CanteenExtraPriceSetting({
required this.payAmountEnable,
required this.payAmountMealLimit,
required this.payAmountMealTimes,
this.mchRoleList,
});
@override
List<Object> get props => [
List<Object?> get props => [
payAmountEnable,
payAmountMealLimit,
payAmountMealTimes,
mchRoleList,
];
factory CanteenExtraPriceSetting.fromJson(Map<String, dynamic> json) =>
@@ -161,6 +161,9 @@ CanteenExtraPriceSetting _$CanteenExtraPriceSettingFromJson(
payAmountEnable: json['payAmountEnable'] as bool,
payAmountMealLimit: (json['payAmountMealLimit'] as num).toInt(),
payAmountMealTimes: (json['payAmountMealTimes'] as num).toDouble(),
mchRoleList: (json['mchRoleList'] as List<dynamic>?)
?.map((e) => ServiceMchRule.fromJson(e as Map<String, dynamic>))
.toList(),
);
Map<String, dynamic> _$CanteenExtraPriceSettingToJson(
@@ -169,4 +172,5 @@ Map<String, dynamic> _$CanteenExtraPriceSettingToJson(
'payAmountEnable': instance.payAmountEnable,
'payAmountMealLimit': instance.payAmountMealLimit,
'payAmountMealTimes': instance.payAmountMealTimes,
'mchRoleList': instance.mchRoleList,
};
+6 -1
View File
@@ -136,7 +136,7 @@ class _$AppDatabase extends AppDatabase {
await database.execute(
'CREATE TABLE IF NOT EXISTS `print_history` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `orderId` TEXT NOT NULL, `serviceOrderId` TEXT NOT NULL, `servicePrintId` TEXT NOT NULL, `invoiceUrl` TEXT NOT NULL, `status` TEXT NOT NULL, `printTime` TEXT, `syncTime` TEXT, `createTime` TEXT NOT NULL)');
await database.execute(
'CREATE TABLE IF NOT EXISTS `user_record` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `userId` TEXT NOT NULL, `nickname` TEXT NOT NULL, `mobile` TEXT, `avatar` TEXT, `walletCardNumber` TEXT, `walletId` TEXT, `walletTypeId` TEXT, `walletBalance` INTEGER, `createTime` TEXT, `updateTime` TEXT)');
'CREATE TABLE IF NOT EXISTS `user_record` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `userId` TEXT NOT NULL, `nickname` TEXT NOT NULL, `mobile` TEXT, `avatar` TEXT, `walletCardNumber` TEXT, `walletId` TEXT, `walletTypeId` TEXT, `walletBalance` INTEGER, `canteenId` INTEGER, `createTime` TEXT, `updateTime` TEXT)');
await database.execute(
'CREATE TABLE IF NOT EXISTS `face` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `userId` TEXT NOT NULL, `sampleId` TEXT NOT NULL, `userName` TEXT NOT NULL, `deptId` TEXT, `deptName` TEXT, `imagePath` TEXT NOT NULL, `path` TEXT, `faceModel` TEXT, `createTime` TEXT, `updateTime` TEXT)');
await database.execute(
@@ -1381,6 +1381,7 @@ class _$UserDao extends UserDao {
'walletId': item.walletId,
'walletTypeId': item.walletTypeId,
'walletBalance': item.walletBalance,
'canteenId': item.canteenId,
'createTime': _dateTimeEmptyConverter.encode(item.createTime),
'updateTime': _dateTimeEmptyConverter.encode(item.updateTime)
}),
@@ -1398,6 +1399,7 @@ class _$UserDao extends UserDao {
'walletId': item.walletId,
'walletTypeId': item.walletTypeId,
'walletBalance': item.walletBalance,
'canteenId': item.canteenId,
'createTime': _dateTimeEmptyConverter.encode(item.createTime),
'updateTime': _dateTimeEmptyConverter.encode(item.updateTime)
}),
@@ -1415,6 +1417,7 @@ class _$UserDao extends UserDao {
'walletId': item.walletId,
'walletTypeId': item.walletTypeId,
'walletBalance': item.walletBalance,
'canteenId': item.canteenId,
'createTime': _dateTimeEmptyConverter.encode(item.createTime),
'updateTime': _dateTimeEmptyConverter.encode(item.updateTime)
});
@@ -1445,6 +1448,7 @@ class _$UserDao extends UserDao {
walletId: row['walletId'] as String?,
walletTypeId: row['walletTypeId'] as String?,
walletBalance: row['walletBalance'] as int?,
canteenId: row['canteenId'] as int?,
createTime:
_dateTimeEmptyConverter.decode(row['createTime'] as String),
updateTime:
@@ -1466,6 +1470,7 @@ class _$UserDao extends UserDao {
walletId: row['walletId'] as String?,
walletTypeId: row['walletTypeId'] as String?,
walletBalance: row['walletBalance'] as int?,
canteenId: row['canteenId'] as int?,
createTime:
_dateTimeEmptyConverter.decode(row['createTime'] as String),
updateTime:
@@ -35,6 +35,9 @@ class UserEntity extends Equatable {
/// 钱包余额
int? walletBalance;
/// 用户所属的商户id(主要用于机器的离线模式)
int? canteenId;
/// 创建时间
DateTime? createTime;
@@ -51,6 +54,7 @@ class UserEntity extends Equatable {
this.walletId,
this.walletTypeId,
this.walletBalance,
this.canteenId,
this.createTime,
this.updateTime,
});
@@ -16,6 +16,7 @@ UserEntity _$UserEntityFromJson(Map<String, dynamic> json) => UserEntity(
walletId: json['walletId'] as String?,
walletTypeId: json['walletTypeId'] as String?,
walletBalance: (json['walletBalance'] as num?)?.toInt(),
canteenId: (json['canteenId'] as num?)?.toInt(),
createTime: json['createTime'] == null
? null
: DateTime.parse(json['createTime'] as String),
@@ -35,6 +36,7 @@ Map<String, dynamic> _$UserEntityToJson(UserEntity instance) =>
'walletId': instance.walletId,
'walletTypeId': instance.walletTypeId,
'walletBalance': instance.walletBalance,
'canteenId': instance.canteenId,
'createTime': instance.createTime?.toIso8601String(),
'updateTime': instance.updateTime?.toIso8601String(),
};
+2 -2
View File
@@ -10,9 +10,9 @@ class Constants {
static const pwdEncKey = 'pigxpigxpigxpigx';
/// 服务 url
static const apiUrl = 'https://stgl.pj.gov.cn/api';
// static const apiUrl = 'https://stgl.pj.gov.cn/api';
// static const apiUrl = 'http://192.168.101.125:9999';
static const apiUrl = 'http://192.168.101.125:9999';
/// 静态资源 url
static const ossUrl = apiUrl;
+14
View File
@@ -70,6 +70,7 @@ class CanteenProductController extends GetxController with OrderMixin {
// 更新分类和商品
try {
await SyncProductTool.updateDatabase();
await _getMchRule();
} catch (e) {
Toast.error(msg: "初始化资源失败,请检查网络情况");
EasyLoading.dismiss();
@@ -312,4 +313,17 @@ class CanteenProductController extends GetxController with OrderMixin {
int _computedProductTotalPrice(int price, int number) {
return price * number;
}
/// 获取商户规则
Future<void> _getMchRule() async {
final isNetwork = AppNetworkTool.isAutoNetwork();
if (!isNetwork) return;
final pa = {"sourceMchId": appSetting.serviceMerchantId};
final mchRoleList = await WalletApi.getMchRoleList(pa);
if (ObjectUtil.isEmptyList(mchRoleList)) return;
final priceSetting = await AppSettingTool.getCanteenExtraPriceConfig();
if (priceSetting == null) return;
priceSetting.mchRoleList = mchRoleList!;
await AppSettingTool.setCanteenExtraPriceConfig(priceSetting);
}
}