diff --git a/KJD_WebService/Model/WxModel/ShopRevenueStatistics.cs b/KJD_WebService/Model/WxModel/ShopRevenueStatistics.cs
index 728a3b8..b83132e 100644
--- a/KJD_WebService/Model/WxModel/ShopRevenueStatistics.cs
+++ b/KJD_WebService/Model/WxModel/ShopRevenueStatistics.cs
@@ -54,6 +54,11 @@ public class ShopRevenueStatistics
/// 利润
///
public int Profit { get; set; }
+ ///
+ /// 快递包裹费用
+ ///
+ public int PackageAmount { get; set; }
+
///
/// 采购类型
///
diff --git a/KJD_WebService/Responses/Shops/ShopOrderDetailResponse.cs b/KJD_WebService/Responses/Shops/ShopOrderDetailResponse.cs
index 3938ce4..1984c3b 100644
--- a/KJD_WebService/Responses/Shops/ShopOrderDetailResponse.cs
+++ b/KJD_WebService/Responses/Shops/ShopOrderDetailResponse.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
@@ -59,6 +59,9 @@ public class ShopOrderDetailResponse
///
public int OutAmount { get; set; }
+ /// 快递包裹净费用(分)
+ public int PackageAmount { get; set; }
+
///
/// 买手未退回金额(分),即买手订单中退款未成功的退款金额之和;无售后时为 0
///
diff --git a/KJD_WebService/Responses/Shops/ShopStatsResponse.cs b/KJD_WebService/Responses/Shops/ShopStatsResponse.cs
index 6c968c2..b721ef5 100644
--- a/KJD_WebService/Responses/Shops/ShopStatsResponse.cs
+++ b/KJD_WebService/Responses/Shops/ShopStatsResponse.cs
@@ -54,8 +54,10 @@ public class ShopStatsResponse
/// 退款处理中金额
///
public long RefundPending { get; set; }
-
-
+ ///
+ /// 包裹金额
+ ///
+ public long PackageAmount { get; set; }
diff --git a/KJD_WebService/Services/Shops/ShopRevenueStatisticsService.cs b/KJD_WebService/Services/Shops/ShopRevenueStatisticsService.cs
index bd64ed8..4b0214d 100644
--- a/KJD_WebService/Services/Shops/ShopRevenueStatisticsService.cs
+++ b/KJD_WebService/Services/Shops/ShopRevenueStatisticsService.cs
@@ -1,4 +1,4 @@
-using KJD_Web.Model.WxModel;
+using KJD_Web.Model.WxModel;
using KJD_Web.Requests.Shops;
using KJD_Web.Responses.Shops;
using KJD_Web.Services.Users;
@@ -8,6 +8,7 @@ using MAX.Core.Logger;
using MySqlX.XDevAPI.Relational;
using Store.Contracts.Order.Entitys;
using Store.Contracts.Shops;
+using Store.Contracts.User.Entitys;
using Store.Contracts.User.Interfaces;
using System;
using System.Collections.Generic;
@@ -93,6 +94,7 @@ public class ShopRevenueStatisticsService : ITransientDependency
resp.RefundOrderCount = ss.Sum(x => x.RefundOrderCount);
resp.RefundDone = ss.Sum(x => x.RefundDone);
resp.RefundPending = ss.Sum(x => x.RefundPending);
+ resp.PackageAmount = ss.Sum(a => a.PackageAmount);
}
if (bDict.TryGetValue(key, out var bb))
@@ -196,6 +198,7 @@ public class ShopRevenueStatisticsService : ITransientDependency
if (orders.Count == 0) return result;
// 加载买手订单(直拍和中转仓都要查),并回填商铺订单的退款金额
+ FillPackageAmount(orders);
FillRefunds(orders);
LoadBuyerOrder(orders);
CalcProfit(orders);
@@ -240,6 +243,7 @@ public class ShopRevenueStatisticsService : ITransientDependency
ProfitAmount = order.Profit,
PlatformFee = order.HasRefund ? 0 : order.PredictCommissionFee,
OutAmount = order.OutAmount,
+ PackageAmount = order.PackageAmount,
UnrefundedAmount = unrefundedAmount,
BuyerOrders = buyerOrders,
});
@@ -337,6 +341,7 @@ public class ShopRevenueStatisticsService : ITransientDependency
{
var orders = LoadOrders(date, shopId);
+ FillPackageAmount(orders);
FillRefunds(orders);
LoadBuyerOrder(orders);
CalcProfit(orders);
@@ -667,7 +672,39 @@ public class ShopRevenueStatisticsService : ITransientDependency
}
}
}
+ ///
+ /// 填充快递费
+ ///
+ ///
+ private void FillPackageAmount(List orders)
+ {
+ int[] types = { 20, 23, 24, 26, 28, 38, 31, 32, 33, 35, 36, 37 };
+ var amounts = orders.Select(o => o.OrderId).Distinct().ToDictionary(id => id, id => 0m);
+ foreach (var batch in Batch(amounts.Keys.ToList(), BatchSize))
+ {
+ var ids = new HashSet(batch);
+ var search = string.Join(" ", batch.Select(id => "\"" + id + "\""));
+ var payments = _freeSql.Select()
+ .Where(p => p.IsDeleted == 0 && types.Contains(p.Type))
+ .Where("MATCH(remark) AGAINST(?search IN BOOLEAN MODE)", new { search })
+ .ToList(p => new { p.Remark, p.Type, p.Amount });
+ foreach (var payment in payments)
+ {
+ // 全文索引只筛候选流水,按完整单号核对,同一备注重复提及只计一次。
+ var matches = Regex.Matches(payment.Remark, @"[A-Za-z0-9_-]+").Cast()
+ .Select(m => m.Value).Where(ids.Contains).Distinct();
+ var amount = payment.Amount ?? 0m;
+ if (payment.Type == 23 || payment.Type == 32 || payment.Type == 38 || payment.Type == 36)
+ amount = -amount;
+ foreach (var id in matches)
+ amounts[id] += amount;
+ }
+ }
+
+ foreach (var order in orders)
+ order.PackageAmount = decimal.ToInt32(decimal.Round(amounts[order.OrderId] * 100m, 0, MidpointRounding.AwayFromZero));
+ }
/// 回填商铺订单的退款信息
private void FillRefunds(List orders)
{
@@ -761,6 +798,7 @@ public class ShopRevenueStatisticsService : ITransientDependency
.Sum(i => (long)i.RefundAmount),
RefundPending = afterSaleItems.Where(i => !i.IsRefundSuccessed && i.IsAfterSale)
.Sum(i => (long)i.RefundAmount),
+ PackageAmount = shopGroup.Sum(a => a.PackageAmount)
});
}
diff --git a/Store.Contracts/Shops/ShopDailyStatsEntity.cs b/Store.Contracts/Shops/ShopDailyStatsEntity.cs
index 1cb79a1..51f2773 100644
--- a/Store.Contracts/Shops/ShopDailyStatsEntity.cs
+++ b/Store.Contracts/Shops/ShopDailyStatsEntity.cs
@@ -72,7 +72,11 @@ public class ShopDailyStatsEntity
///
[Column(Name = "refund_pending")]
public long RefundPending { get; set; }
-
+ ///
+ /// 包裹费用
+ ///
+ [Column(Name = "package_amount")]
+ public long PackageAmount { get; set; }
///
/// 创建时间
///
diff --git a/test/WebServiceTest/ShopTest.cs b/test/WebServiceTest/ShopTest.cs
index 4876593..dc6d49a 100644
--- a/test/WebServiceTest/ShopTest.cs
+++ b/test/WebServiceTest/ShopTest.cs
@@ -105,8 +105,8 @@ internal class ShopTest
{
get
{
- DateTime startDate = DateTime.Parse("2026/10/5");
- DateTime endDate = DateTime.Parse("2026/10/14");
+ DateTime startDate = DateTime.Parse("2026/10/1");
+ DateTime endDate = DateTime.Parse("2026/10/31");
for (DateTime d = startDate; d <= endDate; d = d.AddDays(1))
{
@@ -134,22 +134,19 @@ internal class ShopTest
[Test]
- [TestCase("2026/10/18")]
- [TestCase("2026/10/19")]
- [TestCase("2026/10/20")]
- [TestCase("2026/10/21")]
- public void GetShopSalesOrderTest(string dateString)
+ [TestCaseSource(nameof(CaseArray))]
+ public void GetShopSalesOrderTest(DateTime date)
{
var shopService = _container.Resolve();
- var shopIds =shopService.GetShopIds("15937791563");
+ var shopIds =shopService.GetShopIds("18990991234");
//shopIds = null;
var shopStatsService = _container.Resolve();
- DateTime date = DateTime.Parse("2026/10/17");
+ //DateTime date = DateTime.Parse("2026/10/1");
- if (!string.IsNullOrEmpty(dateString))
- {
- date = DateTime.Parse(dateString);
- }
+ //if (!string.IsNullOrEmpty(dateString))
+ //{
+ // date = DateTime.Parse(dateString);
+ //}
Console.WriteLine($"开始:{date.ToLongDateString()}");
try
{
diff --git a/test/WebServiceTest/UnitTest1.cs b/test/WebServiceTest/UnitTest1.cs
index 19a3977..b6c1348 100644
--- a/test/WebServiceTest/UnitTest1.cs
+++ b/test/WebServiceTest/UnitTest1.cs
@@ -21,7 +21,7 @@ namespace WebServiceTest
WXOemManage manage = new WXOemManage();
string ret = manage.OemWithdrawals(new KJD_Web.BLL.WXXD.Requests.OemWithdrawalQueryRequest
{
- UserName = "18990991234",
+ UserName = "13459139999",
});
Console.WriteLine(ret);
}