220 lines
5.6 KiB
C#
220 lines
5.6 KiB
C#
using Autofac;
|
|
using Autofac.Integration.WebApi;
|
|
using Autofac.Integration.WebApi;
|
|
using KJD_Web;
|
|
using KJD_Web;
|
|
using KJD_Web.Requests.Shops;
|
|
using KJD_Web.Services.Shops;
|
|
using KJD_Web.Services.Users;
|
|
using Newtonsoft.Json;
|
|
using Store.Framework.DependencyInjection;
|
|
using Store.Framework.DependencyInjection;
|
|
using System;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices.ComTypes;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Timers;
|
|
using System.Web.Http;
|
|
|
|
|
|
namespace WebServiceTest;
|
|
|
|
internal class ShopTest
|
|
{
|
|
private static NUnitDebugListener? _listener;
|
|
private IContainer _container;
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
_listener = new NUnitDebugListener();
|
|
Debug.Listeners.Add(_listener);
|
|
var config = new HttpConfiguration();
|
|
_container = ContainerConfig.BuildContainer();
|
|
config.DependencyResolver = new AutofacWebApiDependencyResolver(_container);
|
|
WebApiConfig.Register(config);
|
|
}
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
_container?.Dispose();
|
|
_listener.Dispose();
|
|
}
|
|
|
|
[Test]
|
|
//[TestCase(1960967267443631281)]
|
|
//[TestCase(1960967267443631212)]
|
|
//[TestCase(1960967267443631213)]
|
|
//[TestCase(1960967267443631215)]
|
|
//[TestCase(1960967267443631216)]
|
|
//[TestCase(1960967267443631218)]
|
|
//[TestCase(1960967267443631219)]
|
|
//[TestCase(1960967267443631221)]
|
|
//[TestCase(1960967267443631222)]
|
|
//[TestCase(1960967267443631223)]
|
|
//[TestCase(1960967267443631224)]
|
|
//[TestCase(1960967267443631226)]
|
|
//[TestCase(1960967267443631227)]
|
|
//[TestCase(1960967267443631228)]
|
|
//[TestCase(1960967267443630057)]
|
|
//[TestCase(1960967267443629984)]
|
|
//[TestCase(1960967267443629858)]
|
|
[TestCase(1960967267443629855)]
|
|
//[TestCase(1960967267443629809)]
|
|
//[TestCase(1960967267443629737)]
|
|
//[TestCase(1960967267443627649)]
|
|
//[TestCase(1960967267443627648)]
|
|
public void TestAm(long id)
|
|
{
|
|
// List<long> ShopIds = new List<long>
|
|
// {
|
|
//1960967267443631281,
|
|
//1960967267443631212,
|
|
//1960967267443631213,
|
|
//1960967267443631215,
|
|
//1960967267443631216,
|
|
//1960967267443631218,
|
|
//1960967267443631219,
|
|
//1960967267443631221,
|
|
//1960967267443631222,
|
|
//1960967267443631223,
|
|
//1960967267443631224,
|
|
//1960967267443631226,
|
|
//1960967267443631227,
|
|
//1960967267443631228,
|
|
//1960967267443630057,
|
|
//1960967267443629984,
|
|
//1960967267443629858,
|
|
//1960967267443629855,
|
|
//1960967267443629809,
|
|
//1960967267443629737,
|
|
//1960967267443627649,
|
|
//1960967267443627648
|
|
// };
|
|
|
|
|
|
var shopService = _container.Resolve<ShopRevenueStatisticsService>();
|
|
//shopService.GetShopOrderAmountRange(id, DateTime.Now.AddDays(-10));
|
|
}
|
|
|
|
private static IEnumerable<DateTime> CaseArray
|
|
{
|
|
get
|
|
{
|
|
DateTime startDate = DateTime.Parse("2026/08/01");
|
|
DateTime endDate = DateTime.Parse("2026/10/08");
|
|
|
|
for (DateTime d = startDate; d <= endDate; d = d.AddDays(1))
|
|
{
|
|
yield return d;
|
|
}
|
|
}
|
|
}
|
|
[Test]
|
|
[TestCaseSource(nameof(CaseArray))]
|
|
public void StatsDataRangeShopSalesOrderTest(DateTime date)
|
|
{
|
|
var shopService = _container.Resolve<ShopRevenueStatisticsService>();
|
|
|
|
Console.WriteLine($"开始:{date.ToLongDateString()}");
|
|
try
|
|
{
|
|
shopService.ShopDailyStats(date);
|
|
}
|
|
catch
|
|
{
|
|
Console.WriteLine($"错误:{date.ToLongDateString()}");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
[Test]
|
|
public void GetShopSalesOrderTest()
|
|
{
|
|
var shopService = _container.Resolve<ShopRevenueStatisticsService>();
|
|
DateTime date = DateTime.Parse("2026/10/01");
|
|
|
|
Console.WriteLine($"开始:{date.ToLongDateString()}");
|
|
try
|
|
{
|
|
shopService.ShopDailyStats(date, [
|
|
1960967267443626508,
|
|
]);
|
|
}
|
|
catch
|
|
{
|
|
Console.WriteLine($"错误:{date.ToLongDateString()}");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
[Test]
|
|
public void UpdateStatsTest()
|
|
{
|
|
var shopService = _container.Resolve<ShopRevenueStatisticsService>();
|
|
shopService.UpdateStats(DateTime.Now.AddDays(-1).Date);
|
|
}
|
|
|
|
[Test]
|
|
public void GetShopStatsTest()
|
|
{
|
|
var shopService = _container.Resolve<ShopRevenueStatisticsService>();
|
|
var data = shopService.GetShopStats(DateTime.Parse("2026/10/01"), DateTime.Parse("2026/10/07"), "18990991234", null, ShopStatsGroupType.Day);
|
|
var sb = new System.Text.StringBuilder();
|
|
if (data == null || data.Count == 0)
|
|
{
|
|
sb.AppendLine("没有统计数据");
|
|
}
|
|
else
|
|
{
|
|
Func<long, string> yuan = fen => (fen / 100m).ToString("N2");
|
|
|
|
foreach (var shopId in data.Keys)
|
|
{
|
|
sb.AppendLine("==================== 商铺 " + shopId + " ====================");
|
|
foreach (var r in data[shopId])
|
|
{
|
|
sb.AppendLine("[日期] " + r.StatDate.ToString("yyyy-MM-dd"));
|
|
sb.AppendLine("[销售] 订单数: " + r.OrderCount
|
|
+ " | 销售额: " + yuan(r.SalesAmount)
|
|
+ " | 利润: " + yuan(r.ProfitAmount)
|
|
+ " | 佣金: " + yuan(r.PlatformFee));
|
|
sb.AppendLine("[售后] 退款单: " + r.RefundOrderCount
|
|
+ " | 已退款: " + yuan(r.RefundDone)
|
|
+ " | 退款中: " + yuan(r.RefundPending));
|
|
sb.AppendLine("[买手] 采购单: " + r.PurchaseCount
|
|
+ " | 采购额: " + yuan(r.TotalPurchase)
|
|
+ " | 已退: " + yuan(r.DoneRefund)
|
|
+ " | 未退: " + yuan(r.PendingRefund)
|
|
+ " | 拒绝: " + yuan(r.RejectedRefund)
|
|
+ " | 买手退款合计: " + yuan(r.TotalRefund));
|
|
sb.AppendLine();
|
|
}
|
|
}
|
|
}
|
|
Console.WriteLine(sb.ToString());
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
public void GetShopOrderDetailsTest()
|
|
{
|
|
var shopService = _container.Resolve<ShopRevenueStatisticsService>();
|
|
var ret = shopService.GetShopOrderDetails(DateTime.Parse("2026/10/01"), DateTime.Parse("2026/10/01"), shopIds: [
|
|
"1960967267443626517",
|
|
|
|
]);
|
|
foreach (var item in ret)
|
|
{
|
|
Console.WriteLine($"{item.OrderId} {item.OutAmount}");
|
|
}
|
|
}
|
|
}
|