@@ -500,12 +500,14 @@ func AddFundData(c *gin.Context) { | |||||
if req.Hours > 24 { | if req.Hours > 24 { | ||||
hour = 24 | hour = 24 | ||||
} | } | ||||
// 十分钟执行一次 | |||||
times := req.Hours * 60 / md.ExecutionInterval | |||||
m := model.EggEnergyFundData{ | m := model.EggEnergyFundData{ | ||||
Kind: req.Kind, | Kind: req.Kind, | ||||
TotalAmount: req.TotalAmount, | TotalAmount: req.TotalAmount, | ||||
BalanceAmount: req.TotalAmount, | BalanceAmount: req.TotalAmount, | ||||
Hours: hour, | Hours: hour, | ||||
BalanceTimes: req.Times, | |||||
BalanceTimes: times, | |||||
Memo: req.Memo, | Memo: req.Memo, | ||||
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"), | ||||
@@ -132,12 +132,14 @@ func AddPlatformRevenue(c *gin.Context) { | |||||
if req.Hours > 24 { | if req.Hours > 24 { | ||||
hour = 24 | hour = 24 | ||||
} | } | ||||
// 十分钟执行一次 | |||||
times := req.Hours * 60 / md.ExecutionInterval | |||||
m := model.PlatformRevenueData{ | m := model.PlatformRevenueData{ | ||||
Kind: req.Kind, | Kind: req.Kind, | ||||
TotalAmount: req.TotalAmount, | TotalAmount: req.TotalAmount, | ||||
BalanceAmount: req.TotalAmount, | BalanceAmount: req.TotalAmount, | ||||
Hours: hour, | Hours: hour, | ||||
BalanceTimes: req.Times, | |||||
BalanceTimes: times, | |||||
Memo: req.Memo, | Memo: req.Memo, | ||||
CreateAt: now, | CreateAt: now, | ||||
UpdateAt: now, | UpdateAt: now, | ||||
@@ -4,6 +4,10 @@ import ( | |||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" | "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" | ||||
) | ) | ||||
const ( | |||||
ExecutionInterval = 10 // 结算执行间隔 | |||||
) | |||||
type VirtualCoin struct { | type VirtualCoin struct { | ||||
Id int `json:"id" ` | Id int `json:"id" ` | ||||
Name string `json:"name" ` // 名称 | Name string `json:"name" ` // 名称 | ||||
@@ -136,6 +140,5 @@ type AddFundDataReq struct { | |||||
Kind int `json:"kind,required"` // 种类(1:公司补贴 2:资方投资 3:市场期望) | Kind int `json:"kind,required"` // 种类(1:公司补贴 2:资方投资 3:市场期望) | ||||
TotalAmount string `json:"total_amount,required"` // 金额 | TotalAmount string `json:"total_amount,required"` // 金额 | ||||
Hours int `json:"hours,required"` // 时长(小时) | Hours int `json:"hours,required"` // 时长(小时) | ||||
Times int `json:"times,required"` // 剩余执行次数 | |||||
Memo string `json:"memo" example:"备注"` | Memo string `json:"memo" example:"备注"` | ||||
} | } |
@@ -36,6 +36,5 @@ type AddPlatformRevenueReq struct { | |||||
Kind int `json:"kind,required"` // 种类(1:开屏广告 2:banner 广告 3:信息流广告 4:插屏广告) | Kind int `json:"kind,required"` // 种类(1:开屏广告 2:banner 广告 3:信息流广告 4:插屏广告) | ||||
TotalAmount string `json:"total_amount,required"` // 金额 | TotalAmount string `json:"total_amount,required"` // 金额 | ||||
Hours int `json:"hours,required"` // 时长(小时) | Hours int `json:"hours,required"` // 时长(小时) | ||||
Times int `json:"times,required"` // 剩余执行次数 | |||||
Memo string `json:"memo" example:"备注"` | Memo string `json:"memo" example:"备注"` | ||||
} | } |
@@ -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" ` // 每次结算金额 | |||||
} |
@@ -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 { | |||||
} |
@@ -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 | |||||
} | |||||
} | |||||
} |
@@ -1,7 +1,11 @@ | |||||
package svc | package svc | ||||
import ( | import ( | ||||
"applet/app/task/md" | |||||
"applet/app/utils" | |||||
"applet/app/utils/logx" | "applet/app/utils/logx" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | |||||
"fmt" | "fmt" | ||||
"xorm.io/xorm" | "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 | |||||
} | |||||
} | |||||
} | } |