From 8fc6be0a690d9809c7d5ee86ea923592688a358f Mon Sep 17 00:00:00 2001 From: dzc <2388224167@qq.com> Date: Thu, 10 Apr 2025 18:27:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:android=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/common/api/hard_api.dart | 14 +++ lib/common/models/api/hard_api_models.dart | 49 +++++++++ lib/common/models/api/hard_api_models.g.dart | 28 +++++ .../widgets/order/mixin/order_mixin.dart | 2 +- lib/pages/canteen_order_total/controller.dart | 25 ++++- lib/pages/canteen_order_total/view.dart | 103 ++++++++++++++---- 6 files changed, 195 insertions(+), 26 deletions(-) diff --git a/lib/common/api/hard_api.dart b/lib/common/api/hard_api.dart index ad412ce..29d6ce0 100644 --- a/lib/common/api/hard_api.dart +++ b/lib/common/api/hard_api.dart @@ -118,4 +118,18 @@ abstract class HardApi { if (res.data == null) return null; return res.data?.map((e) => e.toString()).toList(); } + + /// 统计每天、每周、每月、每年的交易人数和次数 + static Future?> chartLatitude( + dynamic formData, + ) async { + final res = await HttpManage().dio.get( + "/hard/hard-api/ad/chart-latitude", + queryParameters: formData, + ); + if (res.data == null) return null; + return res.data + ?.map((e) => ServiceChartLatitude.fromJson(e)) + .toList(); + } } diff --git a/lib/common/models/api/hard_api_models.dart b/lib/common/models/api/hard_api_models.dart index ddecc63..c7b1c87 100644 --- a/lib/common/models/api/hard_api_models.dart +++ b/lib/common/models/api/hard_api_models.dart @@ -316,3 +316,52 @@ class ServiceOpenCardPage extends ServicePageBase { Map toJson() => _$ServiceOpenCardPageToJson(this); } + +@JsonSerializable() +class ServiceChartLatitude { + /// 早餐、中餐、晚餐 + final String? hourType; + + /// 每天的交易量 + final String? dayCount; + + /// 每天的交易金额 + final String? dayPrice; + + /// 每周的交易量 + final String? weekCount; + + /// 每周的交易金额 + final String? weekPrice; + + /// 每月的交易量 + final String? monthCount; + + /// 每月的交易金额 + final String? monthPrice; + + /// 每年的交易量 + final String? yearCount; + + /// 每年的交易金额 + final String? yearPrice; + + ServiceChartLatitude({ + this.hourType, + this.dayCount, + this.dayPrice, + this.weekCount, + this.weekPrice, + this.monthCount, + this.monthPrice, + this.yearCount, + this.yearPrice, + }); + + factory ServiceChartLatitude.fromJson(Map json) => + _$ServiceChartLatitudeFromJson( + json, + ); + + Map toJson() => _$ServiceChartLatitudeToJson(this); +} diff --git a/lib/common/models/api/hard_api_models.g.dart b/lib/common/models/api/hard_api_models.g.dart index 3cd1992..e8de680 100644 --- a/lib/common/models/api/hard_api_models.g.dart +++ b/lib/common/models/api/hard_api_models.g.dart @@ -190,3 +190,31 @@ Map _$ServiceOpenCardPageToJson( 'total': instance.total, 'records': instance.records, }; + +ServiceChartLatitude _$ServiceChartLatitudeFromJson( + Map json) => + ServiceChartLatitude( + hourType: json['hourType'] as String?, + dayCount: json['dayCount'] as String?, + dayPrice: json['dayPrice'] as String?, + weekCount: json['weekCount'] as String?, + weekPrice: json['weekPrice'] as String?, + monthCount: json['monthCount'] as String?, + monthPrice: json['monthPrice'] as String?, + yearCount: json['yearCount'] as String?, + yearPrice: json['yearPrice'] as String?, + ); + +Map _$ServiceChartLatitudeToJson( + ServiceChartLatitude instance) => + { + 'hourType': instance.hourType, + 'dayCount': instance.dayCount, + 'dayPrice': instance.dayPrice, + 'weekCount': instance.weekCount, + 'weekPrice': instance.weekPrice, + 'monthCount': instance.monthCount, + 'monthPrice': instance.monthPrice, + 'yearCount': instance.yearCount, + 'yearPrice': instance.yearPrice, + }; diff --git a/lib/common/widgets/order/mixin/order_mixin.dart b/lib/common/widgets/order/mixin/order_mixin.dart index 37c8ec8..16c10e2 100644 --- a/lib/common/widgets/order/mixin/order_mixin.dart +++ b/lib/common/widgets/order/mixin/order_mixin.dart @@ -334,7 +334,7 @@ mixin OrderMixin { await orderDao.edit(sqlOrderDetail); if (sqlOrderDetail.payPrice != 0) { final price = AppriceTool.fenToYuan(sqlOrderDetail.payPrice); - await TtsManage.speak("购买成功总金额$price元"); + TtsManage.speak("购买成功总金额$price元"); } Toast.success(msg: "购买成功"); } catch (e, stack) { diff --git a/lib/pages/canteen_order_total/controller.dart b/lib/pages/canteen_order_total/controller.dart index a32b777..0febbfa 100644 --- a/lib/pages/canteen_order_total/controller.dart +++ b/lib/pages/canteen_order_total/controller.dart @@ -1,17 +1,26 @@ import 'package:get/get.dart'; +import 'package:pj_supermarket_cloud/common/index.dart'; class CanteenOrderTotalController extends GetxController { CanteenOrderTotalController(); + final appC = Get.find(); + + Rx sysSetting = Rx(null); + + Rx morgingChartLatitude = ServiceChartLatitude().obs; + Rx noonChartLatitude = ServiceChartLatitude().obs; + Rx nightChartLatitude = ServiceChartLatitude().obs; + _initData() { update(["canteen_order_total"]); } - void onTap() {} - @override - void onInit() { + void onInit() async { super.onInit(); + sysSetting.value = await AppSettingTool.getSysSetting(); + await getChartLatitude(); } @override @@ -24,4 +33,14 @@ class CanteenOrderTotalController extends GetxController { void onClose() { super.onClose(); } + + /// 获取统计数据 + Future getChartLatitude() async { + final pa = {"merchantId": sysSetting.value?.serviceMerchantId}; + final list = await HardApi.chartLatitude(pa); + if (list == null) return; + morgingChartLatitude.value = list.firstWhere((v) => v.hourType == "1"); + noonChartLatitude.value = list.firstWhere((v) => v.hourType == "2"); + nightChartLatitude.value = list.firstWhere((v) => v.hourType == "3"); + } } diff --git a/lib/pages/canteen_order_total/view.dart b/lib/pages/canteen_order_total/view.dart index a4f4d59..b21d355 100644 --- a/lib/pages/canteen_order_total/view.dart +++ b/lib/pages/canteen_order_total/view.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:ducafe_ui_core/ducafe_ui_core.dart'; import 'package:flutter/material.dart'; import 'package:forui/forui.dart'; @@ -12,26 +14,71 @@ class CanteenOrderTotalPage extends GetView { // 主视图 Widget _buildView(BuildContext context) { + final widht = context.width; return [ + Obx( + () => _buildHeaderTotalItem( + context, + title: "全部交易统计", + morgingChartLatitude: controller.morgingChartLatitude.value, + noonChartLatitude: controller.noonChartLatitude.value, + nightChartLatitude: controller.nightChartLatitude.value, + ).width(widht * 0.6), + ), + SizedBox(height: 30.h), _buildHeaderTotal(context), - _buildCharts(context), - ].toColumn(); + ].toColumn().marginSymmetric(vertical: 20.w, horizontal: 20.w); } // headerTotal Widget _buildHeaderTotal(BuildContext context) { return [ - _buildHeaderTotalItem(context, title: "本日交易统计"), - _buildHeaderTotalItem(context, title: "本周交易统计"), - _buildHeaderTotalItem(context, title: "本月交易统计"), - _buildHeaderTotalItem(context, title: "本年易统计"), - ].toRow(mainAxisAlignment: MainAxisAlignment.spaceAround); + Obx( + () => _buildHeaderTotalItem( + context, + title: "本日交易统计", + morgingChartLatitude: controller.morgingChartLatitude.value, + noonChartLatitude: controller.noonChartLatitude.value, + nightChartLatitude: controller.nightChartLatitude.value, + ), + ), + Obx( + () => _buildHeaderTotalItem( + context, + title: "本周交易统计", + morgingChartLatitude: controller.morgingChartLatitude.value, + noonChartLatitude: controller.noonChartLatitude.value, + nightChartLatitude: controller.nightChartLatitude.value, + ), + ), + Obx( + () => _buildHeaderTotalItem( + context, + title: "本月交易统计", + morgingChartLatitude: controller.morgingChartLatitude.value, + noonChartLatitude: controller.noonChartLatitude.value, + nightChartLatitude: controller.nightChartLatitude.value, + ), + ), + Obx( + () => _buildHeaderTotalItem( + context, + title: "本年易统计", + morgingChartLatitude: controller.morgingChartLatitude.value, + noonChartLatitude: controller.noonChartLatitude.value, + nightChartLatitude: controller.nightChartLatitude.value, + ), + ), + ].toRow(mainAxisAlignment: MainAxisAlignment.spaceBetween); } // headerTotalItem Widget _buildHeaderTotalItem( BuildContext context, { required String title, + required ServiceChartLatitude morgingChartLatitude, + required ServiceChartLatitude noonChartLatitude, + required ServiceChartLatitude nightChartLatitude, }) { final theme = FTheme.of(context); return [ @@ -40,6 +87,18 @@ class CanteenOrderTotalPage extends GetView { ProductHourType.values .map((v) { if (v.code == "-1") return const SizedBox.shrink(); + String count = "0"; + String price = "0"; + if (v.code == "1") { + count = morgingChartLatitude.dayCount ?? "0"; + price = morgingChartLatitude.dayPrice ?? "0"; + } else if (v.code == "2") { + count = noonChartLatitude.dayCount ?? "0"; + price = noonChartLatitude.dayPrice ?? "0"; + } else if (v.code == "3") { + count = nightChartLatitude.dayCount ?? "0"; + price = nightChartLatitude.dayPrice ?? "0"; + } return [ FIcon( v.icon, @@ -49,34 +108,34 @@ class CanteenOrderTotalPage extends GetView { Text( v.title, maxLines: 1, - style: theme.typography.xl.copyWith(height: 1), + style: theme.typography.lg.copyWith(height: 1), ), - FDivider( - axis: Axis.vertical, - style: theme.dividerStyles.verticalStyle.copyWith( - color: theme.colorScheme.primary, - padding: EdgeInsets.zero, - ), - ), - SizedBox(width: 5.w), Text( "共用餐", maxLines: 1, - style: theme.typography.xl.copyWith(height: 1), + style: theme.typography.lg.copyWith(height: 1), ), Text( - "次", + count, maxLines: 1, - style: theme.typography.xl.copyWith(height: 1), + style: theme.typography.lg.copyWith( + height: 1, + color: theme.colorScheme.error, + ), + ), + Text( + "次,", + maxLines: 1, + style: theme.typography.lg.copyWith(height: 1), ), - SizedBox(width: 5.w), Text( "总金额", maxLines: 1, - style: theme.typography.xl.copyWith(height: 1), + style: theme.typography.lg.copyWith(height: 1), ), + appPrice(context, price), ] - .toRow() + .toRow(mainAxisAlignment: MainAxisAlignment.center) .paddingSymmetric(horizontal: 10.w, vertical: 5.w) .marginSymmetric(vertical: 10.h) .decorated(