Browse Source

SPU聚合增加营业额

GOIAggregation
shanji 2 years ago
parent
commit
699f7ecfb6
  1. 29
      SiNan.Business/AggregationBusiness.cs
  2. 16
      SiNan.Business/GOIBusiness.cs
  3. 12
      SiNan.Model/Core/ActualAmountBySpu.cs
  4. 6
      SiNan.Model/Db/Aggregation/AggregationJDPopularizeSpuDaily.cs
  5. 202
      SiNan.Model/Db/Order/OrderSku.cs

29
SiNan.Business/AggregationBusiness.cs

@ -1,6 +1,7 @@
using FreeSql;
using SiNan.Common.Log;
using SiNan.Common.Models;
using SiNan.Model;
using SiNan.Model.Core;
using SiNan.Model.Db;
using SiNan.Model.Dto;
@ -99,9 +100,9 @@ namespace SiNan.Business
var i = 0;
var spuGroups = (from s in spuIdList
let num = i++
group s by num / 10 into g
select g.ToArray()).ToList(); //10个spu为一组
let num = i++
group s by num / 10 into g
select g.ToArray()).ToList(); //10个spu为一组
var spuGroupCount = spuGroups.Count();
var spuGroupIndex = 0;
@ -121,6 +122,7 @@ namespace SiNan.Business
var aggregationDate_ProductLevelList = goiBusiness.StatisticsProductLevelGOI(currentGroupSkuIdList, startDate_aggregationDate, endDate_aggregationDate);
var aggregationDate_PopularizeLevelList = goiBusiness.StatisticsPopularizeLevelGOI(currentGroupSkuIdList, startDate_aggregationDate, endDate_aggregationDate);
var aggregationDate_SpuActualAmountList = StatisticsActualAmountBySpu(spuGroup, startDate_aggregationDate, endDate_aggregationDate);
IList<GOIBySku> recent7d_ProductLevelList = null;
IList<GOIBySku> recent7d_PopularizeLevelList = null;
IList<GOIBySku> recent30d_ProductLevelList = null;
@ -177,7 +179,8 @@ namespace SiNan.Business
ProductLevelProfit = spugoi_AggregationDate_ProductLevel?.Profit ?? 0M,
ProductLevelGOI = spugoi_AggregationDate_ProductLevel?.GOI ?? 0M,
PopularizeLevelProfit = spugoi_AggregationDate_PopularizeLevel?.Profit ?? 0M,
PopularizeLevelGOI = spugoi_AggregationDate_PopularizeLevel?.GOI ?? 0M
PopularizeLevelGOI = spugoi_AggregationDate_PopularizeLevel?.GOI ?? 0M,
ActualAmount = aggregationDate_SpuActualAmountList.FirstOrDefault(x => x.Spu == spuId)?.ActualAmount ?? 0M
};
insertAggregationSpuDailyList.Add(spuDailyAggregation);
#endregion
@ -369,6 +372,24 @@ namespace SiNan.Business
});
}
}
private IList<ActualAmountBySpu> StatisticsActualAmountBySpu(IList<string> spuList, DateTime startDate, DateTime endDate)
{
var list = fsql.Select<OrderSku, Order>().InnerJoin((osku, o) => osku.OrderId == o.Id)
.Where((osku, o) => o.OrderState != Enums.OrderState. &&
o.IsGift == false &&
o.StartTime >= startDate &&
o.EndTime <= endDate &&
osku.Price > 0 &&
spuList.Contains(osku.ProductId))
.GroupBy((osku, o) => osku.ProductId)
.ToList(g => new ActualAmountBySpu
{
ActualAmount = g.Sum(g.Value.Item1.ActualAmount),
Spu = g.Key
});
return list;
}
#endregion
#region 计划聚合任务

16
SiNan.Business/GOIBusiness.cs

@ -37,7 +37,8 @@ namespace SiNan.Business
ocd.IsEnabled &&
o.StartTime >= startDate &&
o.StartTime <= endDate &&
o.OrderState != Enums.OrderState.)
o.OrderState != Enums.OrderState. &&
o.IsGift == false)
.GroupBy((ocd, o) => ocd.SkuId)
.ToList(g => new
{
@ -74,10 +75,10 @@ namespace SiNan.Business
var profits = fsql.Select<JDOrderPopularizeRelation, OrderCostDetail, Order>()
.InnerJoin((jr, ocd, o) => jr.OrderId == ocd.OrderId)
.InnerJoin((jr, ocd, o) => jr.OrderId == o.Id)
.Where((jr, ocd, o) => skuIdList.Contains(jr.PopularizeSku))
.Where((jr, ocd, o) => o.OrderState != Enums.OrderState. && o.IsGift == false && ocd.IsEnabled == true)
.WhereIf(startDate != null, (jr, ocd, o) => jr.CookieTime >= startDate)
.WhereIf(endDate != null, (jr, ocd, o) => jr.CookieTime <= endDate)
.Where((jr, ocd, o) => ocd.IsEnabled == true && o.OrderState != Enums.OrderState.)
.Where((jr, ocd, o) => skuIdList.Contains(jr.PopularizeSku))
.GroupBy((jr, ocd, o) => jr.PopularizeSku)
.ToList(g => new
{
@ -109,7 +110,8 @@ namespace SiNan.Business
ocd.IsEnabled &&
o.StartTime >= startDate &&
o.StartTime <= endDate &&
o.OrderState != Enums.OrderState.)
o.OrderState != Enums.OrderState. &&
o.IsGift == false)
.ToAggregate((ocd, o) => ocd.Sum(ocd.Key.SkuGrossProfit));
return new GOIByShop()
@ -137,7 +139,8 @@ namespace SiNan.Business
.Where((jr, oc, o) => campaignIdList.Contains(jr.CampaignId.Value) &&
jr.CookieTime >= startDate &&
jr.CookieTime <= endDate &&
o.OrderState != Enums.OrderState.)
o.OrderState != Enums.OrderState. &&
o.IsGift == false)
.GroupBy((jr, oc, o) => jr.CampaignId)
.ToList(g => new
{
@ -174,7 +177,8 @@ namespace SiNan.Business
.Where((jr, oc, o) => adGroupIdList.Contains(jr.AdGroupId.Value) &&
jr.CookieTime >= startDate &&
jr.CookieTime <= endDate &&
o.OrderState != Enums.OrderState.)
o.OrderState != Enums.OrderState. &&
o.IsGift == false)
.GroupBy((jr, oc, o) => jr.AdGroupId)
.ToList(g => new
{

12
SiNan.Model/Core/ActualAmountBySpu.cs

@ -0,0 +1,12 @@
namespace SiNan.Model.Core
{
public class ActualAmountBySpu
{
/// <summary>
/// 实收金额
/// </summary>
public decimal ActualAmount { get; set; }
public string Spu { get; set; }
}
}

6
SiNan.Model/Db/Aggregation/AggregationJDPopularizeSpuDaily.cs

@ -54,6 +54,12 @@ namespace SiNan.Model.Db
[Column(DbType = "bigint")]
public long? ShopId { get; set; }
/// <summary>
/// 商品营业额(SKU实收之和)
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? ActualAmount { get; set; } = 0.00M;
}
}

202
SiNan.Model/Db/Order/OrderSku.cs

@ -1,27 +1,153 @@
using FreeSql.DataAnnotations;
using FreeSql.DataAnnotations;
namespace SiNan.Model.Db
{
/// <summary>
/// 订单SKU
/// </summary>
[Table(Name = "ordersku", DisableSyncStructure = true)]
public partial class OrderSku
{
/// <summary>
/// 商家Id
/// </summary>
[Column(IsIgnore = true)]
public long ShopId { get; set; }
[Column(DbType = "bigint(1)", IsPrimary = true)]
[Column(DbType = "bigint", IsPrimary = true)]
public long Id { get; set; }
/// <summary>
/// 京东支付优惠,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? JdZhiFuYouHui { get; set; } = 0.00M;
/// <summary>
/// plus会员95折优惠,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? Plus95 { get; set; } = 0.00M;
/// <summary>
/// 余额,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? Balance { get; set; } = 0.00M;
/// <summary>
/// 基础优惠,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? BaseDiscount { get; set; } = 0.00M;
/// <summary>
/// 基础运费,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? BaseFee { get; set; } = 0.00M;
/// <summary>
/// 优惠券,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? Coupon { get; set; } = 0.00M;
[Column(DbType = "datetime")]
public DateTime? CreateTime { get; set; }
/// <summary>
/// 东券,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? DongQuan { get; set; } = 0.00M;
/// <summary>
/// 满期赠促销
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? ExpiryGiftDiscount { get; set; } = 0.00M;
/// <summary>
/// 全球购一般贸易税(包税),计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? GlobalGeneralIncludeTax { get; set; } = 0.00M;
/// <summary>
/// 全球购一般贸易税,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? GlobalGeneralTax { get; set; } = 0.00M;
/// <summary>
/// 是否退款
/// </summary>
public bool? IsRefund { get; set; } = false;
/// <summary>
/// 销售数量
/// </summary>
[Column(DbType = "int(1)")]
[Column(DbType = "int")]
public int? ItemTotal { get; set; }
/// <summary>
/// 京豆,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? JingDou { get; set; } = 0.00M;
/// <summary>
/// 京券,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? JingQuan { get; set; } = 0.00M;
/// <summary>
/// 京享礼金(首单礼金或重逢礼金),计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? JingXiangLiJin { get; set; } = 0.00M;
/// <summary>
/// 礼金优惠,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? LiJinYouHui { get; set; } = 0.00M;
/// <summary>
/// Logo
/// </summary>
public string Logo { get; set; }
/// <summary>
/// 落地配服务,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? LuoDiPeiService { get; set; } = 0.00M;
/// <summary>
/// 满减,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? ManJian { get; set; } = 0.00M;
/// <summary>
/// 代发Id
/// </summary>
[Column(DbType = "bigint")]
public long? OrderDropShippingId { get; set; }
[Column(StringLength = 50)]
public string OrderId { get; set; }
/// <summary>
/// 按比例平台承担优惠券,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? PingTaiChengDanYouHuiQuan { get; set; } = 0.00M;
/// <summary>
/// 销售单价
/// </summary>
@ -37,32 +163,80 @@ namespace SiNan.Model.Db
[Column(StringLength = 50)]
public string ProductNo { get; set; }
/// <summary>
/// 跨店满减促销
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? PromotionDiscount { get; set; } = 0.00M;
/// <summary>
/// 偏远运费,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? RemoteFee { get; set; } = 0.00M;
/// <summary>
/// 应付金额,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? ShouldPay { get; set; } = 0.00M;
[Column(StringLength = 50, IsNullable = false)]
public string SkuId { get; set; }
/// <summary>
/// 超级红包,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? SuperRedEnvelope { get; set; } = 0.00M;
/// <summary>
/// 全球购税费,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? TaxFee { get; set; } = 0.00M;
/// <summary>
/// Sku标题
/// </summary>
[Column(StringLength = 255)]
public string Title { get; set; }
[Column(StringLength = 255)]
public string Logo { get; set; }
/// <summary>
/// 退换货无忧,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? TuiHuanHuoWuYou { get; set; } = 0.00M;
/// <summary>
/// 代发信息Id
/// 商家运费,计价单位:元
/// </summary>
[Column(DbType = "bigint(1)", IsNullable = true)]
public long? OrderDropShippingId { get; set; }
[Column(DbType = "decimal(18,2)")]
public decimal? VenderFee { get; set; } = 0.00M;
/// <summary>
/// 是否售后
/// 限品类东券,计价单位:元
/// </summary>
[Column(DbType = "bit")]
public bool IsRefund { get; set; } = false;
[Column(DbType = "decimal(18,2)")]
public decimal? XianPinLeiDongQuan { get; set; } = 0.00M;
/// <summary>
/// 限品类京券,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? XianPinLeiJingQuan { get; set; } = 0.00M;
/// <summary>
/// 支付营销优惠,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? ZhiFuYingXiaoYouHui { get; set; } = 0.00M;
/// <summary>
/// 实收金额,计价单位:元
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? ActualAmount { get; set; } = 0.00M;
[Column(IsIgnore = true)]
public long ShopId { get; set; }
}
}

Loading…
Cancel
Save