diff --git a/KJD_WebService/Controllers/WX/WXShopRevenueStatisticsController.cs b/KJD_WebService/Controllers/WX/WXShopRevenueStatisticsController.cs
index 94af99b..3ef2a9f 100644
--- a/KJD_WebService/Controllers/WX/WXShopRevenueStatisticsController.cs
+++ b/KJD_WebService/Controllers/WX/WXShopRevenueStatisticsController.cs
@@ -5,6 +5,7 @@ using KJD_Web.Responses.Shops;
using KJD_Web.Services.Shops;
using KJD_Web.Utils;
using Newtonsoft.Json.Converters;
+using Store.Contracts.Shops;
using Store.Framework.Models;
using System;
using System.Collections.Generic;
@@ -22,10 +23,12 @@ namespace KJD_Web.Controllers.WX
public class WXShopRevenueStatisticsController : AsmxApiController
{
private readonly ShopRevenueStatisticsService _statsService;
+ private readonly IFreeSql _freeSql;
- public WXShopRevenueStatisticsController(ShopRevenueStatisticsService statsService)
+ public WXShopRevenueStatisticsController(ShopRevenueStatisticsService statsService, IFreeSql freeSql)
{
_statsService = statsService;
+ _freeSql = freeSql;
}
public IHttpActionResult get_shop_order_amount()
{
@@ -47,6 +50,57 @@ namespace KJD_Web.Controllers.WX
{
return GetShopStats(request, request.GroupType);
}
+ ///
+ /// 外部调用
+ ///
+ ///
+ ///
+ public IHttpActionResult GetShopStatsExternal(ShopStatsRequest request)
+ {
+ Dictionary> ret; try
+ {
+ if (request == null) throw new ArgumentNullException(nameof(request));
+ if (request.StartDate == null) throw new ArgumentNullException(nameof(request.StartDate));
+ if (request.EndDate == null) throw new ArgumentNullException(nameof(request.EndDate));
+ if (request.ShopIds == null || request.ShopIds.Count == 0) throw new ArgumentNullException(nameof(request.ShopIds));
+ Dictionary dict = _freeSql.Select()
+ .Where(a => request.ShopIds.Contains(a.AppKey))
+ .ToList(a => new { a.Id, a.AppKey })
+ .ToDictionary(a => a.Id.ToString(), a => a.AppKey);
+ var shopIds = dict.Keys.ToList();
+ ret = _statsService.GetShopStats(request.StartDate, request.EndDate, "", shopIds, request.GroupType);
+ var newRet = new Dictionary>();
+
+ foreach (var item in ret)
+ {
+
+ if (dict.TryGetValue(item.Key, out var appKey))
+ {
+ item.Value.ForEach(a => a.ShopId = appKey);
+ newRet[appKey] = item.Value;
+ }
+ else
+ {
+ newRet[item.Key] = item.Value;
+ }
+ }
+
+ return Ok(ApiResult.Success(newRet));
+ }
+ catch (ArgumentNullException ex)
+ {
+ return Ok(ApiResult.Fail(ex.Message, ResultCode.Fail));
+ }
+ catch (ArgumentException ex)
+ {
+ return Ok(ApiResult.Fail(ex.Message, ResultCode.Fail));
+
+ }
+ catch (Exception ex)
+ {
+ return Ok(ApiResult.Fail("查询失败:", ResultCode.ServerError));
+ }
+ }
///
/// 商铺销售趋势:按天返回所有商铺合计的销售额和订单数(无数据的天补 0)
diff --git a/KJD_WebService/Services/Shops/ShopRevenueStatisticsService.cs b/KJD_WebService/Services/Shops/ShopRevenueStatisticsService.cs
index b20a29f..612108c 100644
--- a/KJD_WebService/Services/Shops/ShopRevenueStatisticsService.cs
+++ b/KJD_WebService/Services/Shops/ShopRevenueStatisticsService.cs
@@ -53,7 +53,7 @@ public class ShopRevenueStatisticsService : ITransientDependency
public Dictionary> GetShopStats(DateTime startTime, DateTime endTime, string userName, List shopIds = null, ShopStatsGroupType groupType = ShopStatsGroupType.Summary)
{
var result = new Dictionary>();
-
+ if (startTime > endTime) throw new ArgumentException("开始时间不能大于结束时间");
(Dictionary> shopGroups, Dictionary> buyerGroups) ret;
if (shopIds != null && shopIds.Count > 0)
ret = getShopStats(startTime, endTime, shopIds);
diff --git a/test/WebServiceTest/ShopTest.cs b/test/WebServiceTest/ShopTest.cs
index 41faf9a..deee5d0 100644
--- a/test/WebServiceTest/ShopTest.cs
+++ b/test/WebServiceTest/ShopTest.cs
@@ -105,8 +105,8 @@ internal class ShopTest
{
get
{
- DateTime startDate = DateTime.Parse("2026/08/01");
- DateTime endDate = DateTime.Parse("2026/10/08");
+ DateTime startDate = DateTime.Parse("2026/06/01");
+ DateTime endDate = DateTime.Parse("2026/07/31");
for (DateTime d = startDate; d <= endDate; d = d.AddDays(1))
{
@@ -138,8 +138,9 @@ internal class ShopTest
{
var shopService = _container.Resolve();
var shopIds =shopService.GetShopIds("taiyuanqiji");
+ shopIds = null;
var shopStatsService = _container.Resolve();
- DateTime date = DateTime.Parse("2026/09/10");
+ DateTime date = DateTime.Parse("2026/10/11");
Console.WriteLine($"开始:{date.ToLongDateString()}");
try