|
@@ -93,7 +93,6 @@ func GenerateWxAdData(req md.GenerateWxAdData) (err error, generateWxAdData mode |
|
|
generateWxAdData = model.GenerateWxAdData{ |
|
|
generateWxAdData = model.GenerateWxAdData{ |
|
|
MediumId: originalWxAdData.MediumId, |
|
|
MediumId: originalWxAdData.MediumId, |
|
|
Uuid: originalWxAdData.Uuid, |
|
|
Uuid: originalWxAdData.Uuid, |
|
|
Platform: originalWxAdData.Platform, |
|
|
|
|
|
AppId: originalWxAdData.AppId, |
|
|
AppId: originalWxAdData.AppId, |
|
|
OriginalDataId: originalWxAdData.Id, |
|
|
OriginalDataId: originalWxAdData.Id, |
|
|
SlotId: originalWxAdData.SlotId, |
|
|
SlotId: originalWxAdData.SlotId, |
|
@@ -122,6 +121,7 @@ func GenerateWxAdData(req md.GenerateWxAdData) (err error, generateWxAdData mode |
|
|
IsGenerateReport: 0, |
|
|
IsGenerateReport: 0, |
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
Platform: originalWxAdData.Platform, |
|
|
} |
|
|
} |
|
|
generateWxAdDataDb := implement.NewGenerateWxAdDataDb(db.Db) |
|
|
generateWxAdDataDb := implement.NewGenerateWxAdDataDb(db.Db) |
|
|
_, err = generateWxAdDataDb.GenerateWxAdDataInsertBySession(session, &generateWxAdData) |
|
|
_, err = generateWxAdDataDb.GenerateWxAdDataInsertBySession(session, &generateWxAdData) |
|
@@ -272,19 +272,24 @@ func SettlementWxAdData(req md.SettlementWxAdData) (err error) { |
|
|
if mediumSettlement == nil { |
|
|
if mediumSettlement == nil { |
|
|
//新增一条数据 |
|
|
//新增一条数据 |
|
|
mediumSettlement = &model.MediumSettlement{ |
|
|
mediumSettlement = &model.MediumSettlement{ |
|
|
Uuid: originalWxAdData.Uuid, |
|
|
|
|
|
MediumId: originalWxAdData.MediumId, |
|
|
|
|
|
AppId: originalWxAdData.AppId, |
|
|
|
|
|
BusinessKind: 1, |
|
|
|
|
|
Kind: medium.SettlementType, |
|
|
|
|
|
BasicIncome: generateWxAdData.MediaRevenue, |
|
|
|
|
|
OtherIncome: 0, |
|
|
|
|
|
State: mediumSettlementState, |
|
|
|
|
|
PayState: mediumSettlementPayState, |
|
|
|
|
|
StartDate: now.Format("2006-01-02"), |
|
|
|
|
|
EndDate: "", |
|
|
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
|
|
|
Uuid: originalWxAdData.Uuid, |
|
|
|
|
|
MediumId: originalWxAdData.MediumId, |
|
|
|
|
|
AppId: originalWxAdData.AppId, |
|
|
|
|
|
BusinessKind: 1, |
|
|
|
|
|
Kind: medium.SettlementType, |
|
|
|
|
|
BasicIncome: generateWxAdData.MediaRevenue, |
|
|
|
|
|
OtherIncome: 0, |
|
|
|
|
|
OriginalIncome: originalWxAdData.PublisherIncome, |
|
|
|
|
|
PlatformRetention: generateWxAdData.PlatformRetention, |
|
|
|
|
|
CommissionRetention: generateWxAdData.CommissionRetention, |
|
|
|
|
|
PriceAdjustmentRetention: generateWxAdData.PriceAdjustmentRetention, |
|
|
|
|
|
State: mediumSettlementState, |
|
|
|
|
|
PayState: mediumSettlementPayState, |
|
|
|
|
|
StartDate: now.Format("2006-01-02"), |
|
|
|
|
|
EndDate: "", |
|
|
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
SettleFile: "", |
|
|
} |
|
|
} |
|
|
_, err = mediumSettlementDb.MediumSettlementInsertBySession(session, mediumSettlement) |
|
|
_, err = mediumSettlementDb.MediumSettlementInsertBySession(session, mediumSettlement) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@@ -293,14 +298,54 @@ func SettlementWxAdData(req md.SettlementWxAdData) (err error) { |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
//更新数据 |
|
|
//更新数据 |
|
|
basicIncomeBefore = mediumSettlement.BasicIncome |
|
|
|
|
|
mediumSettlement.BasicIncome += generateWxAdData.MediaRevenue |
|
|
|
|
|
mediumSettlement.State = mediumSettlementState |
|
|
|
|
|
mediumSettlement.PayState = mediumSettlementPayState |
|
|
|
|
|
_, err = mediumSettlementDb.UpdateMediumSettlementBySession(session, mediumSettlement, "basic_income", "pay_state", "state") |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
_ = session.Rollback() |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
if medium.SettlementType != mediumSettlement.Kind { |
|
|
|
|
|
//TODO::前后结算类型不一致,之前结算单状态自动变成"核算中" |
|
|
|
|
|
mediumSettlement.State = enum.MediumSettlementStateForAccountingInProgress |
|
|
|
|
|
//mediumSettlement.PayState = mediumSettlementPayState |
|
|
|
|
|
_, err = mediumSettlementDb.UpdateMediumSettlementBySession(session, mediumSettlement, "state") |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
_ = session.Rollback() |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//新增一条数据 |
|
|
|
|
|
mediumSettlement = &model.MediumSettlement{ |
|
|
|
|
|
Uuid: originalWxAdData.Uuid, |
|
|
|
|
|
MediumId: originalWxAdData.MediumId, |
|
|
|
|
|
AppId: originalWxAdData.AppId, |
|
|
|
|
|
BusinessKind: 1, |
|
|
|
|
|
Kind: medium.SettlementType, |
|
|
|
|
|
BasicIncome: generateWxAdData.MediaRevenue, |
|
|
|
|
|
OtherIncome: 0, |
|
|
|
|
|
OriginalIncome: originalWxAdData.PublisherIncome, |
|
|
|
|
|
PlatformRetention: generateWxAdData.PlatformRetention, |
|
|
|
|
|
CommissionRetention: generateWxAdData.CommissionRetention, |
|
|
|
|
|
PriceAdjustmentRetention: generateWxAdData.PriceAdjustmentRetention, |
|
|
|
|
|
State: mediumSettlementState, |
|
|
|
|
|
PayState: mediumSettlementPayState, |
|
|
|
|
|
StartDate: now.Format("2006-01-02"), |
|
|
|
|
|
EndDate: "", |
|
|
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
SettleFile: "", |
|
|
|
|
|
} |
|
|
|
|
|
_, err = mediumSettlementDb.MediumSettlementInsertBySession(session, mediumSettlement) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
_ = session.Rollback() |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
basicIncomeBefore = mediumSettlement.BasicIncome |
|
|
|
|
|
mediumSettlement.BasicIncome += generateWxAdData.MediaRevenue |
|
|
|
|
|
mediumSettlement.OriginalIncome += originalWxAdData.PublisherIncome |
|
|
|
|
|
mediumSettlement.PlatformRetention += generateWxAdData.PlatformRetention |
|
|
|
|
|
mediumSettlement.CommissionRetention += generateWxAdData.CommissionRetention |
|
|
|
|
|
mediumSettlement.PriceAdjustmentRetention += generateWxAdData.PriceAdjustmentRetention |
|
|
|
|
|
_, err = mediumSettlementDb.UpdateMediumSettlementBySession(session, mediumSettlement, "basic_income", "original_income", "platform_retention", "commission_retention", "price_adjustment_retention") |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
_ = session.Rollback() |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if medium.SettlementType == enum.MediumSettlementTypeForPaymentInAdvance { |
|
|
if medium.SettlementType == enum.MediumSettlementTypeForPaymentInAdvance { |
|
@@ -378,17 +423,48 @@ func SettlementWxAdData(req md.SettlementWxAdData) (err error) { |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
//更新数据 |
|
|
//更新数据 |
|
|
agentBasicIncomeBefore = agentSettlement.BasicIncome |
|
|
|
|
|
agentOtherIncomeBefore = agentSettlement.OtherIncome |
|
|
|
|
|
agentSettlement.BasicIncome += v.AgentRevenue |
|
|
|
|
|
agentSettlement.OtherIncome += v.ExtraRevenue |
|
|
|
|
|
agentSettlement.State += agentSettlementState |
|
|
|
|
|
agentSettlement.PayState += agentSettlementPayState |
|
|
|
|
|
|
|
|
if agentMap[v.AgentId].SettlementType != agentSettlement.Kind { |
|
|
|
|
|
//TODO::前后结算类型不一致,之前结算单状态自动变成"核算中" |
|
|
|
|
|
agentSettlement.State = enum.AgentSettlementStateForAccountingInProgress |
|
|
|
|
|
_, err = agentSettlementDb.UpdateAgentSettlementBySession(session, agentSettlement, "state") |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
_ = session.Rollback() |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
_, err = agentSettlementDb.UpdateAgentSettlementBySession(session, agentSettlement, "basic_income", "other_income", "pay_state", "state") |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
_ = session.Rollback() |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
//新增一条数据 |
|
|
|
|
|
agentSettlement = &model.AgentSettlement{ |
|
|
|
|
|
Uuid: v.Uuid, |
|
|
|
|
|
AgentId: v.AgentId, |
|
|
|
|
|
MediumId: originalWxAdData.MediumId, |
|
|
|
|
|
AppId: v.AppId, |
|
|
|
|
|
BusinessKind: 1, |
|
|
|
|
|
Kind: agentMap[v.AgentId].SettlementType, |
|
|
|
|
|
BasicIncome: v.AgentRevenue, |
|
|
|
|
|
OtherIncome: v.ExtraRevenue, |
|
|
|
|
|
State: agentSettlementState, |
|
|
|
|
|
PayState: agentSettlementPayState, |
|
|
|
|
|
StartDate: now.Format("2006-01-02"), |
|
|
|
|
|
EndDate: "", |
|
|
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
} |
|
|
|
|
|
_, err = agentSettlementDb.AgentSettlementInsertBySession(session, agentSettlement) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
_ = session.Rollback() |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
agentBasicIncomeBefore = agentSettlement.BasicIncome |
|
|
|
|
|
agentOtherIncomeBefore = agentSettlement.OtherIncome |
|
|
|
|
|
agentSettlement.BasicIncome += v.AgentRevenue |
|
|
|
|
|
agentSettlement.OtherIncome += v.ExtraRevenue |
|
|
|
|
|
|
|
|
|
|
|
_, err = agentSettlementDb.UpdateAgentSettlementBySession(session, agentSettlement, "basic_income", "other_income") |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
_ = session.Rollback() |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|