| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- /// 营收管理相关 API 调用服务
- /// 当前使用 mock 数据,后端 API 就绪后替换为真实请求
- class RevenueService {
- RevenueService._internal();
- static final RevenueService instance = RevenueService._internal();
- factory RevenueService() => instance;
-
- // ==================== Mock 数据 ====================
-
- /// 获取月度账单列表
- Future<List<BillItem>> getBillList({String? period, BillStatus? status}) async {
- await Future.delayed(const Duration(milliseconds: 800));
- final bills = [
- BillItem(
- id: 'B202405-001',
- customerName: '张三',
- customerAddress: '阳光小区3-501',
- meterId: 'S001-501',
- period: '2024-05',
- previousReading: 1250.0,
- currentReading: 1285.5,
- usage: 35.5,
- unitPrice: 2.41,
- amount: 85.50,
- status: BillStatus.paid,
- dueDate: DateTime(2024, 6, 15),
- payTime: DateTime(2024, 6, 10, 14, 30),
- payMethod: PayMethod.wechat,
- ),
- BillItem(
- id: 'B202405-002',
- customerName: '李四',
- customerAddress: '翠湖花园2-302',
- meterId: 'S002-302',
- period: '2024-05',
- previousReading: 890.0,
- currentReading: 940.0,
- usage: 50.0,
- unitPrice: 2.41,
- amount: 120.00,
- status: BillStatus.unpaid,
- dueDate: DateTime(2024, 6, 15),
- ),
- BillItem(
- id: 'B202405-003',
- customerName: '王五',
- customerAddress: '东方名城8-101',
- meterId: 'S003-101',
- period: '2024-05',
- previousReading: 2100.0,
- currentReading: 2127.0,
- usage: 27.0,
- unitPrice: 2.41,
- amount: 65.20,
- status: BillStatus.paid,
- dueDate: DateTime(2024, 6, 15),
- payTime: DateTime(2024, 6, 8, 9, 15),
- payMethod: PayMethod.alipay,
- ),
- BillItem(
- id: 'B202405-004',
- customerName: '赵六',
- customerAddress: '锦绣家园5-601',
- meterId: 'S004-601',
- period: '2024-05',
- previousReading: 1560.0,
- currentReading: 1601.0,
- usage: 41.0,
- unitPrice: 2.41,
- amount: 98.80,
- status: BillStatus.overdue,
- dueDate: DateTime(2024, 6, 15),
- ),
- BillItem(
- id: 'B202405-005',
- customerName: '孙七',
- customerAddress: '阳光小区1-203',
- meterId: 'S001-203',
- period: '2024-05',
- previousReading: 780.0,
- currentReading: 810.0,
- usage: 30.0,
- unitPrice: 2.41,
- amount: 72.30,
- status: BillStatus.unpaid,
- dueDate: DateTime(2024, 6, 15),
- ),
- BillItem(
- id: 'B202405-006',
- customerName: '周八',
- customerAddress: '城东商铺A-12',
- meterId: 'S005-A12',
- period: '2024-05',
- previousReading: 3200.0,
- currentReading: 3450.0,
- usage: 250.0,
- unitPrice: 3.85,
- amount: 962.50,
- status: BillStatus.paid,
- dueDate: DateTime(2024, 6, 15),
- payTime: DateTime(2024, 6, 5, 10, 0),
- payMethod: PayMethod.bankTransfer,
- ),
- BillItem(
- id: 'B202405-007',
- customerName: '吴九',
- customerAddress: '翠湖花园5-102',
- meterId: 'S002-102',
- period: '2024-05',
- previousReading: 450.0,
- currentReading: 478.0,
- usage: 28.0,
- unitPrice: 2.41,
- amount: 67.48,
- status: BillStatus.paid,
- dueDate: DateTime(2024, 6, 15),
- payTime: DateTime(2024, 6, 12, 16, 45),
- payMethod: PayMethod.cash,
- ),
- BillItem(
- id: 'B202405-008',
- customerName: '郑十',
- customerAddress: '东方名城3-802',
- meterId: 'S003-802',
- period: '2024-05',
- previousReading: 1100.0,
- currentReading: 1155.0,
- usage: 55.0,
- unitPrice: 2.41,
- amount: 132.55,
- status: BillStatus.overdue,
- dueDate: DateTime(2024, 6, 15),
- ),
- ];
-
- var result = bills;
- if (status != null) {
- result = result.where((b) => b.status == status).toList();
- }
- if (period != null) {
- result = result.where((b) => b.period == period).toList();
- }
- return result;
- }
-
- /// 搜索用户(抄表录入用)
- Future<List<CustomerInfo>> searchCustomers(String keyword) async {
- await Future.delayed(const Duration(milliseconds: 500));
- final customers = [
- CustomerInfo(id: 'C001', name: '张三', address: '阳光小区3-501', meterId: 'S001-501', meterModel: 'LXS-20E', phone: '13800138001'),
- CustomerInfo(id: 'C002', name: '李四', address: '翠湖花园2-302', meterId: 'S002-302', meterModel: 'LXS-25E', phone: '13800138002'),
- CustomerInfo(id: 'C003', name: '王五', address: '东方名城8-101', meterId: 'S003-101', meterModel: 'LXS-20E', phone: '13800138003'),
- CustomerInfo(id: 'C004', name: '赵六', address: '锦绣家园5-601', meterId: 'S004-601', meterModel: 'LXS-32E', phone: '13800138004'),
- CustomerInfo(id: 'C005', name: '孙七', address: '阳光小区1-203', meterId: 'S001-203', meterModel: 'LXS-20E', phone: '13800138005'),
- CustomerInfo(id: 'C006', name: '周八', address: '城东商铺A-12', meterId: 'S005-A12', meterModel: 'LXS-50E', phone: '13800138006'),
- CustomerInfo(id: 'C007', name: '吴九', address: '翠湖花园5-102', meterId: 'S002-102', meterModel: 'LXS-20E', phone: '13800138007'),
- CustomerInfo(id: 'C008', name: '郑十', address: '东方名城3-802', meterId: 'S003-802', meterModel: 'LXS-25E', phone: '13800138008'),
- ];
- if (keyword.isEmpty) return customers;
- return customers
- .where((c) =>
- c.name.contains(keyword) ||
- c.meterId.contains(keyword) ||
- c.address.contains(keyword))
- .toList();
- }
-
- /// 提交抄表读数
- Future<bool> submitMeterReading({
- required String meterId,
- required double reading,
- String? photoPath,
- String? remark,
- }) async {
- await Future.delayed(const Duration(milliseconds: 700));
- return true;
- }
-
- /// 获取缴费记录
- Future<List<PaymentRecord>> getPaymentRecords({PaymentStatus? status}) async {
- await Future.delayed(const Duration(milliseconds: 700));
- final records = [
- PaymentRecord(
- id: 'P2024-001',
- customerName: '张三',
- customerAddress: '阳光小区3-501',
- meterId: 'S001-501',
- amount: 85.50,
- period: '2024-05',
- payTime: DateTime(2024, 6, 10, 14, 30),
- method: PayMethod.wechat,
- status: PaymentStatus.success,
- operator: '系统',
- ),
- PaymentRecord(
- id: 'P2024-002',
- customerName: '王五',
- customerAddress: '东方名城8-101',
- meterId: 'S003-101',
- amount: 65.20,
- period: '2024-05',
- payTime: DateTime(2024, 6, 8, 9, 15),
- method: PayMethod.alipay,
- status: PaymentStatus.success,
- operator: '系统',
- ),
- PaymentRecord(
- id: 'P2024-003',
- customerName: '周八',
- customerAddress: '城东商铺A-12',
- meterId: 'S005-A12',
- amount: 962.50,
- period: '2024-05',
- payTime: DateTime(2024, 6, 5, 10, 0),
- method: PayMethod.bankTransfer,
- status: PaymentStatus.success,
- operator: '柜台-李芳',
- ),
- PaymentRecord(
- id: 'P2024-004',
- customerName: '吴九',
- customerAddress: '翠湖花园5-102',
- meterId: 'S002-102',
- amount: 67.48,
- period: '2024-05',
- payTime: DateTime(2024, 6, 12, 16, 45),
- method: PayMethod.cash,
- status: PaymentStatus.success,
- operator: '柜台-李芳',
- ),
- PaymentRecord(
- id: 'P2024-005',
- customerName: '赵六',
- customerAddress: '锦绣家园5-601',
- meterId: 'S004-601',
- amount: 98.80,
- period: '2024-05',
- payTime: null,
- method: null,
- status: PaymentStatus.pending,
- operator: null,
- ),
- PaymentRecord(
- id: 'P2024-006',
- customerName: '郑十',
- customerAddress: '东方名城3-802',
- meterId: 'S003-802',
- amount: 132.55,
- period: '2024-05',
- payTime: null,
- method: null,
- status: PaymentStatus.overdue,
- operator: null,
- ),
- ];
- if (status != null) {
- return records.where((r) => r.status == status).toList();
- }
- return records;
- }
-
- /// 执行缴费操作
- Future<PaymentResult> payBill({
- required String billId,
- required PayMethod method,
- }) async {
- await Future.delayed(const Duration(milliseconds: 1000));
- return PaymentResult(
- success: true,
- transactionId: 'TXN${DateTime.now().millisecondsSinceEpoch}',
- message: '缴费成功',
- );
- }
-
- /// 获取营收概览
- Future<RevenueSummary> getRevenueSummary() async {
- await Future.delayed(const Duration(milliseconds: 600));
- return const RevenueSummary(
- totalAmount: 358620,
- paidAmount: 312450,
- unpaidAmount: 46170,
- overdueAmount: 12800,
- totalCustomers: 1280,
- paidCustomers: 1050,
- unpaidCustomers: 180,
- overdueCustomers: 50,
- collectionRate: 87.1,
- monthOverMonth: 5.8,
- );
- }
- }
-
- // ==================== 数据模型 ====================
-
- /// 账单状态
- enum BillStatus {
- paid('已缴费'),
- unpaid('待缴费'),
- overdue('欠费');
-
- final String label;
- const BillStatus(this.label);
- }
-
- /// 支付方式
- enum PayMethod {
- wechat('微信支付'),
- alipay('支付宝'),
- bankTransfer('银行转账'),
- cash('现金'),
- other('其他');
-
- final String label;
- const PayMethod(this.label);
- }
-
- /// 缴费状态
- enum PaymentStatus {
- success('已缴'),
- pending('待缴'),
- overdue('欠费');
-
- final String label;
- const PaymentStatus(this.label);
- }
-
- /// 账单
- class BillItem {
- final String id;
- final String customerName;
- final String customerAddress;
- final String meterId;
- final String period;
- final double previousReading;
- final double currentReading;
- final double usage;
- final double unitPrice;
- final double amount;
- final BillStatus status;
- final DateTime dueDate;
- final DateTime? payTime;
- final PayMethod? payMethod;
-
- const BillItem({
- required this.id,
- required this.customerName,
- required this.customerAddress,
- required this.meterId,
- required this.period,
- required this.previousReading,
- required this.currentReading,
- required this.usage,
- required this.unitPrice,
- required this.amount,
- required this.status,
- required this.dueDate,
- this.payTime,
- this.payMethod,
- });
- }
-
- /// 客户信息
- class CustomerInfo {
- final String id;
- final String name;
- final String address;
- final String meterId;
- final String meterModel;
- final String phone;
-
- const CustomerInfo({
- required this.id,
- required this.name,
- required this.address,
- required this.meterId,
- required this.meterModel,
- required this.phone,
- });
- }
-
- /// 缴费记录
- class PaymentRecord {
- final String id;
- final String customerName;
- final String customerAddress;
- final String meterId;
- final double amount;
- final String period;
- final DateTime? payTime;
- final PayMethod? method;
- final PaymentStatus status;
- final String? operator;
-
- const PaymentRecord({
- required this.id,
- required this.customerName,
- required this.customerAddress,
- required this.meterId,
- required this.amount,
- required this.period,
- this.payTime,
- this.method,
- required this.status,
- this.operator,
- });
-
- String get payTimeStr {
- if (payTime == null) return '-';
- return '${payTime!.year}-${payTime!.month.toString().padLeft(2, '0')}-${payTime!.day.toString().padLeft(2, '0')} '
- '${payTime!.hour.toString().padLeft(2, '0')}:${payTime!.minute.toString().padLeft(2, '0')}';
- }
- }
-
- /// 缴费结果
- class PaymentResult {
- final bool success;
- final String transactionId;
- final String message;
-
- const PaymentResult({
- required this.success,
- required this.transactionId,
- required this.message,
- });
- }
-
- /// 营收概览
- class RevenueSummary {
- final double totalAmount;
- final double paidAmount;
- final double unpaidAmount;
- final double overdueAmount;
- final int totalCustomers;
- final int paidCustomers;
- final int unpaidCustomers;
- final int overdueCustomers;
- final double collectionRate;
- final double monthOverMonth;
-
- const RevenueSummary({
- required this.totalAmount,
- required this.paidAmount,
- required this.unpaidAmount,
- required this.overdueAmount,
- required this.totalCustomers,
- required this.paidCustomers,
- required this.unpaidCustomers,
- required this.overdueCustomers,
- required this.collectionRate,
- required this.monthOverMonth,
- });
- }
|