功能同需求
背景:现有财务销售成本表为每日取 订单利润表数据 ,作为更新逻辑,但店铺费用存在无关联ID , 导致更新可能出错;
调整:销售成本表( rb_Finance_Settlement) 利润表(RB_Report_OrderSettlement)
现状: 在销售成本表中, 店铺类别数据无ID 维度,导致更新覆盖可能存在重复。
调整1:在销售成本表中,每日汇总 利润表 每项店铺类型---每项总金额---> 插入 销售成本表 ,每项店铺类型---每项总金额。
1.1 汇总数据存储到中间表,再插入销售成本表
调整2:按销售成本表原逻辑,每天判断 前一天发货时间,校验金额为原币小数点 1位数;
调整3:当发货时间,店铺费用(每项店铺类型---每项总金额) 不等于时 ,在第二天做 差值 更新
调整4:删除 关帐时间(checkdate) 2021 年 10 月 1 ----- 至 现在 所有 销售成本表内容; 再调整 SYN 时间为 9 月1 号 ,数据重跑。
调整4.1:数据重跑后,checkdate = 1 月,并且 发货时间 = 10 月 范围, 则 调整checkdate = 发货时间
调整4.2:数据重跑后,checkdate = 1 月,并且 发货时间 = 11 月 范围 ,则 调整checkdate = 发货时间
调整4.3:数据重跑后,checkdate = 1 月,并且 发货时间 = 12 月 范围 ,则 调整checkdate = 发货时间
调整4.4:数据重跑后,checkdate = 1 月,并且 发货时间 = 8-9 月 范围 ,则 调整checkdate = 10 月 20 号000000
重新覆盖后,线上跟踪 1周 作为校验。
--------------------------------------------------------------------------------------------------------------------------------
参考如下修复订单逻辑但没有效果:
DECLARE @CustomerID INT
DECLARE @OrderSourceType INT
DECLARE @BeginTime NVARCHAR(20)
DECLARE @EndTime NVARCHAR(20)
SET @CustomerID=1
SET @OrderSourceType=2
SET @BeginTime='2021-11-01'
SET @EndTime='2021-12-01'
--修改Finance 11月Ebay OrderSourceOtherDebits<>0 数据 商户号为-2
UPDATE dbo.RB_Finance_Settlement SET CustomerID=-2 WHERE
CustomerID=@CustomerID
AND OrderSourceType=@OrderSourceType
AND ShipTime>=@BeginTime
AND ShipTime<@EndTime
AND OrderSourceOtherDebits<>0;
--插入利润表到财务结算表
INSERT INTO RB_Finance_Settlement
(
[CustomerID],
[CheckDate],
[SettlementDate],
[OrderSourceID],
[OrderSourceName],
[PayTime],
[ShipTime],
[WarehouseID],
[WareHouseName],
[OrderSourceType],
[OrderSourceTypeName],
[Ordercode],
[ClientOrderCode],
[TransactionId],
[SKU],
[ClientSKU],
[SellerSKU],
[ProductNameCN],
[SaleNum],
[Currency],
[ExchangeRMB],
[USD_ExchangeRMB],
[Country],
[Profits],
[Incomes],
[SalesPrice],
[TransportPay],
[SalesRefunds],
[PromotionRebates],
[OtherCredits],
[CommisionFee],
[FBATransactionFees],
[OrderSourceOtherDebits],
[CostOfAdvertising],
[BuyPrice],
[PackageFees],
[SalesAdminID],
[SalesAdminName],
[SalesTeamID],
[SalesTeamName],
[remark],
[AddTime],
[UpdateTime],
[AddCommisionFee],
[TransportID],
[Transport_API_Class]
)
SELECT CustomerID,SettlementDate,SettlementDate,OrderSourceID,OrderSourceName,
PayTime,ShipTime,
WareHouseID,WareHouseName,OrderSourceType,OrderSourceTypeName,OrderCode,ClientOrderCode,
TransactionId,SKU,ClientSKU,SellerSKU,ProductNameCN,(ProductNum+ProdutNumUpdate) AS SaleNum,
Currency,ExchangeRMB,USD_ExchangeRMB,OrderSourceContry,Profits,Incomes,SalesPrice,TransportPay,
SalesRefunds,PromotionRebates,OtherCredits,CommisionFee,FBATransactionFees,OrderSourceOtherDebits,
CostOfAdvertising,BuyPrice,PackageFees,SalesAdminID,SalesAdminName,SalesTeamID,SalesTeamName,
'利润覆盖20211216' AS remark,
SettlementDate AS AddTime,SettlementDate AS UpdateTime,0 AS AddCommisionFee,TransportID,0 AS Transport_API_Class
FROM dbo.RB_Report_OrderSettlement(NOLOCK)
WHERE
CustomerID=@CustomerID
AND OrderSourceType=@OrderSourceType
AND ShipTime>=@BeginTime
AND ShipTime<@EndTime
AND OrderSourceOtherDebits<>0

优化方式:利润同步到销售成本表,店铺类型利润(OrderCode为空),根据利润ID判断重复做差异同步,以防同步重复;已同步的利润ID,在下一轮同步按照ID先冲销售成本表中查询已同步金额,跟当前需同步的店铺费用求差异金额,只同步差异部分。
1、修改上一次服务运行后的SnyID和SnyTime到需要的时间节点。
UPDATE RB_Warehouse_Record_SynTime SET SynTime='2021-11-18 20:47:14.557',SynID=58605700 WHERE SynType=10
2、准备利润数据
3、同步利润到销售成本