diff --git a/lib/common/api/wallet_api.dart b/lib/common/api/wallet_api.dart index 7ce02df..f044165 100644 --- a/lib/common/api/wallet_api.dart +++ b/lib/common/api/wallet_api.dart @@ -51,4 +51,16 @@ abstract class WalletApi { if (res.data == null) return null; return res.data; } + + /// 获取钱包规则(android离线计算展示使用) + static Future?> 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((e) => ServiceTenant.fromJson(e)) + .toList(); + } } diff --git a/lib/common/models/api/wallet_api_models.dart b/lib/common/models/api/wallet_api_models.dart index 5244663..1ca1e44 100644 --- a/lib/common/models/api/wallet_api_models.dart +++ b/lib/common/models/api/wallet_api_models.dart @@ -52,3 +52,37 @@ class ServicePaySetting { Map 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 json) => + _$ServiceMchRuleFromJson(json); + + Map toJson() => _$ServiceMchRuleToJson(this); +} diff --git a/lib/common/models/api/wallet_api_models.g.dart b/lib/common/models/api/wallet_api_models.g.dart index c571f6c..8565c95 100644 --- a/lib/common/models/api/wallet_api_models.g.dart +++ b/lib/common/models/api/wallet_api_models.g.dart @@ -36,3 +36,23 @@ Map _$ServicePaySettingToJson(ServicePaySetting instance) => 'offLineOrderApplyEnable': JsonTool.booleanToString(instance.offLineOrderApplyEnable), }; + +ServiceMchRule _$ServiceMchRuleFromJson(Map 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 _$ServiceMchRuleToJson(ServiceMchRule instance) => + { + 'id': instance.id, + 'sourceMchId': instance.sourceMchId, + 'targetMchId': instance.targetMchId, + 'rulePriceConfigId': instance.rulePriceConfigId, + 'basePrice': instance.basePrice, + 'multiple': instance.multiple, + }; diff --git a/lib/common/models/database/database_models.dart b/lib/common/models/database/database_models.dart index f2bd1d3..84f6716 100644 --- a/lib/common/models/database/database_models.dart +++ b/lib/common/models/database/database_models.dart @@ -222,17 +222,22 @@ class CanteenExtraPriceSetting extends Equatable { /// 超过的倍数 double payAmountMealTimes; + // 商户支付规则列表 + List? mchRoleList; + CanteenExtraPriceSetting({ required this.payAmountEnable, required this.payAmountMealLimit, required this.payAmountMealTimes, + this.mchRoleList, }); @override - List get props => [ + List get props => [ payAmountEnable, payAmountMealLimit, payAmountMealTimes, + mchRoleList, ]; factory CanteenExtraPriceSetting.fromJson(Map json) => diff --git a/lib/common/models/database/database_models.g.dart b/lib/common/models/database/database_models.g.dart index 756dd66..504f932 100644 --- a/lib/common/models/database/database_models.g.dart +++ b/lib/common/models/database/database_models.g.dart @@ -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?) + ?.map((e) => ServiceMchRule.fromJson(e as Map)) + .toList(), ); Map _$CanteenExtraPriceSettingToJson( @@ -169,4 +172,5 @@ Map _$CanteenExtraPriceSettingToJson( 'payAmountEnable': instance.payAmountEnable, 'payAmountMealLimit': instance.payAmountMealLimit, 'payAmountMealTimes': instance.payAmountMealTimes, + 'mchRoleList': instance.mchRoleList, }; diff --git a/lib/common/services/database/database.g.dart b/lib/common/services/database/database.g.dart index 8f53433..3a7c983 100644 --- a/lib/common/services/database/database.g.dart +++ b/lib/common/services/database/database.g.dart @@ -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: diff --git a/lib/common/services/database/entity/user_entity.dart b/lib/common/services/database/entity/user_entity.dart index e317704..d426389 100644 --- a/lib/common/services/database/entity/user_entity.dart +++ b/lib/common/services/database/entity/user_entity.dart @@ -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, }); diff --git a/lib/common/services/database/entity/user_entity.g.dart b/lib/common/services/database/entity/user_entity.g.dart index 7a15502..1654a56 100644 --- a/lib/common/services/database/entity/user_entity.g.dart +++ b/lib/common/services/database/entity/user_entity.g.dart @@ -16,6 +16,7 @@ UserEntity _$UserEntityFromJson(Map 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 _$UserEntityToJson(UserEntity instance) => 'walletId': instance.walletId, 'walletTypeId': instance.walletTypeId, 'walletBalance': instance.walletBalance, + 'canteenId': instance.canteenId, 'createTime': instance.createTime?.toIso8601String(), 'updateTime': instance.updateTime?.toIso8601String(), }; diff --git a/lib/common/values/constants.dart b/lib/common/values/constants.dart index 059717c..bbbd4d5 100644 --- a/lib/common/values/constants.dart +++ b/lib/common/values/constants.dart @@ -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; diff --git a/lib/pages/canteen_product/controller.dart b/lib/pages/canteen_product/controller.dart index 491ed01..df1c554 100644 --- a/lib/pages/canteen_product/controller.dart +++ b/lib/pages/canteen_product/controller.dart @@ -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 _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); + } }