From da6805ad9d93638b821fe7ba4f53313df84c5cd9 Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Thu, 14 Nov 2024 11:06:04 +0800 Subject: [PATCH] add deal platform revenue and fund data --- .../egg_energy/hdl_basic.go | 4 +- .../egg_energy/hdl_platform_revenue.go | 4 +- .../egg_energy/md_basic.go | 5 +- .../egg_energy/md_platform_revenue.go | 1 - app/task/md/md_deal_fund_data.go | 10 +++ app/task/md/md_deal_platform_revenue_data.go | 17 +++++ app/task/svc/svc_deal_fund_data.go | 75 +++++++++++++++++++ .../svc/svc_deal_platform_revenue_data.go | 58 ++++++++++++++ 8 files changed, 170 insertions(+), 4 deletions(-) create mode 100644 app/task/md/md_deal_fund_data.go create mode 100644 app/task/md/md_deal_platform_revenue_data.go create mode 100644 app/task/svc/svc_deal_fund_data.go diff --git a/app/hdl/institutional_management/egg_energy/hdl_basic.go b/app/hdl/institutional_management/egg_energy/hdl_basic.go index 3b03bf7..e427cdc 100644 --- a/app/hdl/institutional_management/egg_energy/hdl_basic.go +++ b/app/hdl/institutional_management/egg_energy/hdl_basic.go @@ -500,12 +500,14 @@ func AddFundData(c *gin.Context) { if req.Hours > 24 { hour = 24 } + // 十分钟执行一次 + times := req.Hours * 60 / md.ExecutionInterval m := model.EggEnergyFundData{ Kind: req.Kind, TotalAmount: req.TotalAmount, BalanceAmount: req.TotalAmount, Hours: hour, - BalanceTimes: req.Times, + BalanceTimes: times, Memo: req.Memo, CreateAt: now.Format("2006-01-02 15:04:05"), UpdateAt: now.Format("2006-01-02 15:04:05"), diff --git a/app/hdl/institutional_management/egg_energy/hdl_platform_revenue.go b/app/hdl/institutional_management/egg_energy/hdl_platform_revenue.go index 58c8a12..d48a204 100644 --- a/app/hdl/institutional_management/egg_energy/hdl_platform_revenue.go +++ b/app/hdl/institutional_management/egg_energy/hdl_platform_revenue.go @@ -132,12 +132,14 @@ func AddPlatformRevenue(c *gin.Context) { if req.Hours > 24 { hour = 24 } + // 十分钟执行一次 + times := req.Hours * 60 / md.ExecutionInterval m := model.PlatformRevenueData{ Kind: req.Kind, TotalAmount: req.TotalAmount, BalanceAmount: req.TotalAmount, Hours: hour, - BalanceTimes: req.Times, + BalanceTimes: times, Memo: req.Memo, CreateAt: now, UpdateAt: now, diff --git a/app/md/institutional_management/egg_energy/md_basic.go b/app/md/institutional_management/egg_energy/md_basic.go index 699b42a..da69f26 100644 --- a/app/md/institutional_management/egg_energy/md_basic.go +++ b/app/md/institutional_management/egg_energy/md_basic.go @@ -4,6 +4,10 @@ import ( "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" ) +const ( + ExecutionInterval = 10 // 结算执行间隔 +) + type VirtualCoin struct { Id int `json:"id" ` Name string `json:"name" ` // 名称 @@ -136,6 +140,5 @@ type AddFundDataReq struct { Kind int `json:"kind,required"` // 种类(1:公司补贴 2:资方投资 3:市场期望) TotalAmount string `json:"total_amount,required"` // 金额 Hours int `json:"hours,required"` // 时长(小时) - Times int `json:"times,required"` // 剩余执行次数 Memo string `json:"memo" example:"备注"` } diff --git a/app/md/institutional_management/egg_energy/md_platform_revenue.go b/app/md/institutional_management/egg_energy/md_platform_revenue.go index ed77364..853ede0 100644 --- a/app/md/institutional_management/egg_energy/md_platform_revenue.go +++ b/app/md/institutional_management/egg_energy/md_platform_revenue.go @@ -36,6 +36,5 @@ type AddPlatformRevenueReq struct { Kind int `json:"kind,required"` // 种类(1:开屏广告 2:banner 广告 3:信息流广告 4:插屏广告) TotalAmount string `json:"total_amount,required"` // 金额 Hours int `json:"hours,required"` // 时长(小时) - Times int `json:"times,required"` // 剩余执行次数 Memo string `json:"memo" example:"备注"` } diff --git a/app/task/md/md_deal_fund_data.go b/app/task/md/md_deal_fund_data.go new file mode 100644 index 0000000..3c40d8a --- /dev/null +++ b/app/task/md/md_deal_fund_data.go @@ -0,0 +1,10 @@ +package md + +import ( + "code.fnuoos.com/EggPlanet/egg_models.git/src/model" +) + +type EggEnergyFundDataNode struct { + Data model.EggEnergyFundData `json:"data"` + EveryAmount string `json:"every_amount" ` // 每次结算金额 +} diff --git a/app/task/md/md_deal_platform_revenue_data.go b/app/task/md/md_deal_platform_revenue_data.go new file mode 100644 index 0000000..bd31dcf --- /dev/null +++ b/app/task/md/md_deal_platform_revenue_data.go @@ -0,0 +1,17 @@ +package md + +import ( + "code.fnuoos.com/EggPlanet/egg_models.git/src/model" +) + +const ( + ExecutionInterval = 10 // 结算执行间隔 +) + +type RevenueDataNode struct { + Data model.PlatformRevenueData `json:"data"` + EveryAmount string `json:"every_amount" ` // 每次结算金额 +} + +type name struct { +} diff --git a/app/task/svc/svc_deal_fund_data.go b/app/task/svc/svc_deal_fund_data.go new file mode 100644 index 0000000..f2b7817 --- /dev/null +++ b/app/task/svc/svc_deal_fund_data.go @@ -0,0 +1,75 @@ +package svc + +import ( + "applet/app/task/md" + "applet/app/utils" + "applet/app/utils/logx" + "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" + "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + "fmt" + "xorm.io/xorm" +) + +func DealFundData(eg *xorm.Engine, dbName string) { + fmt.Println("deal_fund_data...") + defer func() { + if err := recover(); err != nil { + _ = logx.Error(err) + } + }() + + fundDataDb := implement.NewEggEnergyFundDataDb(eg) + fundDataList, err := fundDataDb.EggEnergyFundDataFindNotFinish() + if err != nil { + _ = logx.Error(err) + return + } + + fundDatas := make([]md.EggEnergyFundDataNode, len(fundDataList)) + for i, data := range fundDataList { + // 总执行次数 按十分钟更新 + times := data.Hours * 60 / md.ExecutionInterval + // 每次更新金额 + amount := utils.AnyToFloat64(data.TotalAmount) / utils.AnyToFloat64(times) + tempData := md.EggEnergyFundDataNode{ + Data: model.EggEnergyFundData{ + Id: data.Id, + Kind: data.Kind, + TotalAmount: data.TotalAmount, + BalanceAmount: data.BalanceAmount, + Hours: data.Hours, + BalanceTimes: data.BalanceTimes, + Memo: data.Memo, + CreateAt: data.CreateAt, + UpdateAt: data.UpdateAt, + }, + EveryAmount: utils.AnyToString(amount), + } + fundDatas[i] = tempData + } + + // 修改当前数据 + for _, data := range fundDatas { + // 变更后余额 + balanceAmount := utils.AnyToFloat64(data.Data.BalanceAmount) - utils.AnyToFloat64(data.EveryAmount) + m := model.EggEnergyFundData{ + Id: data.Data.Id, + Kind: data.Data.Kind, + TotalAmount: data.Data.TotalAmount, + BalanceAmount: utils.AnyToString(balanceAmount), + Hours: data.Data.Hours, + BalanceTimes: data.Data.BalanceTimes - 1, + Memo: data.Data.Memo, + CreateAt: data.Data.CreateAt, + UpdateAt: data.Data.UpdateAt, + } + forceColumns := []string{ + "balance_times", + } + _, err := fundDataDb.EggEnergyFundDataUpdate(m, forceColumns...) + if err != nil { + _ = logx.Error(err) + return + } + } +} diff --git a/app/task/svc/svc_deal_platform_revenue_data.go b/app/task/svc/svc_deal_platform_revenue_data.go index 368caaf..165d456 100644 --- a/app/task/svc/svc_deal_platform_revenue_data.go +++ b/app/task/svc/svc_deal_platform_revenue_data.go @@ -1,7 +1,11 @@ package svc import ( + "applet/app/task/md" + "applet/app/utils" "applet/app/utils/logx" + "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" + "code.fnuoos.com/EggPlanet/egg_models.git/src/model" "fmt" "xorm.io/xorm" ) @@ -14,4 +18,58 @@ func DealPlatformRevenueData(eg *xorm.Engine, dbName string) { } }() + revenueDataDb := implement.NewPlatformRevenueDataDb(eg) + revenueDataList, err := revenueDataDb.PlatformRevenueDataFindNotFinish() + if err != nil { + _ = logx.Error(err) + return + } + + revenueDatas := make([]md.RevenueDataNode, len(revenueDataList)) + for i, data := range revenueDataList { + // 总执行次数 按十分钟更新 + times := data.Hours * 60 / md.ExecutionInterval + // 每次更新金额 + amount := utils.AnyToFloat64(data.TotalAmount) / utils.AnyToFloat64(times) + tempData := md.RevenueDataNode{ + Data: model.PlatformRevenueData{ + Id: data.Id, + Kind: data.Kind, + TotalAmount: data.TotalAmount, + BalanceAmount: data.BalanceAmount, + Hours: data.Hours, + BalanceTimes: data.BalanceTimes, + Memo: data.Memo, + CreateAt: data.CreateAt, + UpdateAt: data.UpdateAt, + }, + EveryAmount: utils.AnyToString(amount), + } + revenueDatas[i] = tempData + } + + // 修改当前数据 + for _, data := range revenueDatas { + // 变更后余额 + balanceAmount := utils.AnyToFloat64(data.Data.BalanceAmount) - utils.AnyToFloat64(data.EveryAmount) + m := model.PlatformRevenueData{ + Id: data.Data.Id, + Kind: data.Data.Kind, + TotalAmount: data.Data.TotalAmount, + BalanceAmount: utils.AnyToString(balanceAmount), + Hours: data.Data.Hours, + BalanceTimes: data.Data.BalanceTimes - 1, + Memo: data.Data.Memo, + CreateAt: data.Data.CreateAt, + UpdateAt: data.Data.UpdateAt, + } + forceColumns := []string{ + "balance_times", + } + _, err := revenueDataDb.PlatformRevenueDataUpdate(m, forceColumns...) + if err != nil { + _ = logx.Error(err) + return + } + } }