更新统计接口 增加外部调用 无验签

This commit is contained in:
chfei committed 2026-10-13 14:33:53 +08:00
1 parent 3a43a2205a
commit 306b9ec18e
3 files changed
+60 -5

No files matched your search

@@ -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);
}
/// <summary>
/// 外部调用
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public IHttpActionResult GetShopStatsExternal(ShopStatsRequest request)
{
Dictionary<string, List<ShopStatsResponse>> 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<string, string> dict = _freeSql.Select<WXShopEntity>()
.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<string, List<ShopStatsResponse>>();
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));
}
}
/// <summary>
/// 商铺销售趋势:按天返回所有商铺合计的销售额和订单数(无数据的天补 0)
@@ -53,7 +53,7 @@ public class ShopRevenueStatisticsService : ITransientDependency
public Dictionary<string, List<ShopStatsResponse>> GetShopStats(DateTime startTime, DateTime endTime, string userName, List<string> shopIds = null, ShopStatsGroupType groupType = ShopStatsGroupType.Summary)
{
var result = new Dictionary<string, List<ShopStatsResponse>>();
if (startTime > endTime) throw new ArgumentException("开始时间不能大于结束时间");
(Dictionary<string, List<ShopDailyStatsEntity>> shopGroups, Dictionary<string, List<BuyerDailyStatsEntity>> buyerGroups) ret;
if (shopIds != null && shopIds.Count > 0)
ret = getShopStats(startTime, endTime, shopIds);
+4 -3
View File
@@ -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<ShopService>();
var shopIds =shopService.GetShopIds("taiyuanqiji");
shopIds = null;
var shopStatsService = _container.Resolve<ShopRevenueStatisticsService>();
DateTime date = DateTime.Parse("2026/09/10");
DateTime date = DateTime.Parse("2026/10/11");
Console.WriteLine($"开始:{date.ToLongDateString()}");
try