@@ -508,6 +508,7 @@ func AddFundData(c *gin.Context) { | |||||
BalanceAmount: req.TotalAmount, | BalanceAmount: req.TotalAmount, | ||||
Hours: hour, | Hours: hour, | ||||
BalanceTimes: times, | BalanceTimes: times, | ||||
Frequency: req.Frequency, | |||||
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"), | ||||
@@ -141,8 +141,8 @@ func AddPlatformRevenue(c *gin.Context) { | |||||
Hours: hour, | Hours: hour, | ||||
BalanceTimes: times, | BalanceTimes: times, | ||||
Memo: req.Memo, | Memo: req.Memo, | ||||
CreateAt: now, | |||||
UpdateAt: now, | |||||
CreateAt: now.Format("2006-01-02 15:04:05"), | |||||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||||
} | } | ||||
id, err := platformRevenueDataDb.PlatformRevenueDataInsert(&m) | id, err := platformRevenueDataDb.PlatformRevenueDataInsert(&m) | ||||
if err != nil { | if err != nil { | ||||
@@ -141,4 +141,5 @@ type AddFundDataReq struct { | |||||
TotalAmount string `json:"total_amount,required"` // 金额 | TotalAmount string `json:"total_amount,required"` // 金额 | ||||
Hours int `json:"hours,required"` // 时长(小时) | Hours int `json:"hours,required"` // 时长(小时) | ||||
Memo string `json:"memo" example:"备注"` | Memo string `json:"memo" example:"备注"` | ||||
Frequency int `json:"frequency"` // 频率(分钟) | |||||
} | } |
@@ -1,7 +1,5 @@ | |||||
package md | package md | ||||
import "time" | |||||
type SetVideoRewardReq struct { | type SetVideoRewardReq struct { | ||||
UnitPrice string `json:"unit_price,required"` // 单价 | UnitPrice string `json:"unit_price,required"` // 单价 | ||||
ECMP string `json:"ecmp,required"` // 当前 Ecmp 值 | ECMP string `json:"ecmp,required"` // 当前 Ecmp 值 | ||||
@@ -16,14 +14,14 @@ type ListPlatformRevenueReq struct { | |||||
} | } | ||||
type PlatformRevenueDataNode struct { | type PlatformRevenueDataNode struct { | ||||
SystemID int `json:"system_id"` | |||||
Kind int `json:"kind" ` // 种类(1:开屏广告 2:banner 广告 3:信息流广告 4:插屏广告) | |||||
TotalAmount string `json:"total_amount" ` // 金额 | |||||
BalanceAmount string `json:"balance_amount" ` // 余额 | |||||
Hours int `json:"hours" ` // 时长 | |||||
BalanceTimes int `json:"balance_times" ` // 剩余执行次数 | |||||
Memo string `json:"memo" ` // 备注 | |||||
CreateAt time.Time `json:"create_at" ` // 创建时间 | |||||
SystemID int `json:"system_id"` | |||||
Kind int `json:"kind" ` // 种类(1:开屏广告 2:banner 广告 3:信息流广告 4:插屏广告) | |||||
TotalAmount string `json:"total_amount" ` // 金额 | |||||
BalanceAmount string `json:"balance_amount" ` // 余额 | |||||
Hours int `json:"hours" ` // 时长 | |||||
BalanceTimes int `json:"balance_times" ` // 剩余执行次数 | |||||
Memo string `json:"memo" ` // 备注 | |||||
CreateAt string `json:"create_at" ` // 创建时间 | |||||
} | } | ||||
type ListPlatformRevenueResp struct { | type ListPlatformRevenueResp struct { | ||||
@@ -4,10 +4,6 @@ import ( | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | "code.fnuoos.com/EggPlanet/egg_models.git/src/model" | ||||
) | ) | ||||
const ( | |||||
ExecutionInterval = 10 // 结算执行间隔 | |||||
) | |||||
type RevenueDataNode struct { | type RevenueDataNode struct { | ||||
Data model.PlatformRevenueData `json:"data"` | Data model.PlatformRevenueData `json:"data"` | ||||
EveryAmount string `json:"every_amount" ` // 每次结算金额 | EveryAmount string `json:"every_amount" ` // 每次结算金额 | ||||
@@ -1,12 +1,17 @@ | |||||
package svc | package svc | ||||
import ( | import ( | ||||
"applet/app/task/md" | |||||
"applet/app/utils" | "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/implement" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | "code.fnuoos.com/EggPlanet/egg_models.git/src/model" | ||||
zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" | |||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" | |||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" | |||||
md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" | |||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/svc" | |||||
"fmt" | "fmt" | ||||
"time" | |||||
"xorm.io/xorm" | "xorm.io/xorm" | ||||
) | ) | ||||
@@ -25,51 +30,116 @@ func DealFundData(eg *xorm.Engine, dbName string) { | |||||
return | return | ||||
} | } | ||||
fundDatas := make([]md.EggEnergyFundDataNode, len(fundDataList)) | |||||
for i, data := range fundDataList { | |||||
now := time.Now() | |||||
fundDataRecordsDb := implement.NewEggEnergyFundDataRecordsDb(eg) | |||||
for _, data := range fundDataList { | |||||
// 判断是否是第一次执行 | |||||
lastRecord, err1 := fundDataRecordsDb.EggEnergyFundDataRecordsGetLast(data.Id) | |||||
if err1 != nil { | |||||
_ = logx.Error(err1) | |||||
continue | |||||
} | |||||
if lastRecord == nil { | |||||
// 首次执行 判断当前是否可以执行 | |||||
if utils.TimeParseStd(data.CreateAt).Add(time.Duration(data.Frequency) * time.Minute).After(now) { | |||||
continue | |||||
} | |||||
} else { | |||||
// 已经被执行过 | |||||
if utils.TimeParseStd(lastRecord.CreateAt).Add(time.Duration(data.Frequency) * time.Minute).After(now) { | |||||
continue | |||||
} | |||||
} | |||||
// 总执行次数 按十分钟更新 | // 总执行次数 按十分钟更新 | ||||
times := data.Hours * 60 / md.ExecutionInterval | |||||
times := data.Hours * 60 / data.Frequency | |||||
// 每次更新金额 | // 每次更新金额 | ||||
amount := utils.AnyToFloat64(data.TotalAmount) / utils.AnyToFloat64(times) | 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), | |||||
session := eg.NewSession() | |||||
defer func() { | |||||
session.Close() | |||||
if err := recover(); err != nil { | |||||
_ = zhios_order_relate_logx.Error(err) | |||||
} | |||||
}() | |||||
session.Begin() | |||||
eggEnergyCoreData, cb, err2 := svc.GetEggEnergyCoreData(eg) | |||||
if err2 != nil { | |||||
_ = logx.Error(err2) | |||||
} | |||||
if cb != nil { | |||||
defer cb() // 释放锁 | |||||
} | |||||
//计算涨价公式 | |||||
err3, calcPriceIncreaseFormulaResp := egg_energy.CalcPriceIncreaseFormula(utils.AnyToString(amount), eggEnergyCoreData) | |||||
if err3 != nil { | |||||
_ = logx.Error(err3) | |||||
_ = session.Rollback() | |||||
continue | |||||
} | } | ||||
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, | |||||
dealAvailableEggEnergyCoinReq := md2.DealAvailableEggEnergyCoinReq{ | |||||
Amount: calcPriceIncreaseFormulaResp.GetEggEnergyNums, | |||||
AmountFee: "", | |||||
BeforePrice: calcPriceIncreaseFormulaResp.BeforePrice, | |||||
AfterPrice: calcPriceIncreaseFormulaResp.AfterPrice, | |||||
BeforePlanetTotalValue: calcPriceIncreaseFormulaResp.BeforePlanetTotalValue, | |||||
AfterPlanetTotalValue: calcPriceIncreaseFormulaResp.AfterPlanetTotalValue, | |||||
BeforeEnergyTotalNums: calcPriceIncreaseFormulaResp.BeforeEnergyTotalNums, | |||||
AfterEnergyTotalNums: calcPriceIncreaseFormulaResp.AfterEnergyTotalNums, | |||||
} | } | ||||
err4 := egg_energy.DealAvailableEggEnergyCoin(session, int(enum.CapitalInjection), eggEnergyCoreData, dealAvailableEggEnergyCoinReq) | |||||
if err4 != nil { | |||||
fmt.Println("ActivityCoinAutoExchangeEggPersonEnergy:::::err111:::", err4) | |||||
_ = session.Rollback() | |||||
continue | |||||
} | |||||
// 插入资金数据详细数据 | |||||
record := model.EggEnergyFundDataRecords{ | |||||
RecordsId: data.Id, | |||||
TotalAmount: data.TotalAmount, | |||||
BalanceAmount: utils.AnyToString(utils.AnyToFloat64(data.BalanceAmount) - amount), | |||||
BalanceTimes: data.BalanceTimes - 1, | |||||
BeforePrice: calcPriceIncreaseFormulaResp.BeforePrice, | |||||
AfterPrice: calcPriceIncreaseFormulaResp.AfterPrice, | |||||
BeforePlanetTotalValue: calcPriceIncreaseFormulaResp.BeforePlanetTotalValue, | |||||
AfterPlanetTotalValue: calcPriceIncreaseFormulaResp.AfterPlanetTotalValue, | |||||
CreateAt: now.Format("2006-01-02 15:04:05"), | |||||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||||
} | |||||
_, err5 := fundDataRecordsDb.EggEnergyFundDataRecordsInsertBySession(session, record) | |||||
if err5 != nil { | |||||
_ = session.Rollback() | |||||
continue | |||||
} | |||||
// 更新当前数据 | |||||
fundData := model.EggEnergyFundData{ | |||||
Id: data.Id, | |||||
Kind: data.Kind, | |||||
TotalAmount: data.TotalAmount, | |||||
BalanceAmount: utils.AnyToString(utils.AnyToFloat64(data.BalanceAmount) - amount), | |||||
Hours: data.Hours, | |||||
BalanceTimes: data.BalanceTimes - 1, | |||||
Frequency: data.Frequency, | |||||
Memo: data.Memo, | |||||
CreateAt: data.CreateAt, | |||||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||||
} | |||||
forceColumns := []string{ | forceColumns := []string{ | ||||
"balance_times", | "balance_times", | ||||
"balance_amount", | |||||
} | } | ||||
_, err := fundDataDb.EggEnergyFundDataUpdate(m, forceColumns...) | |||||
if err != nil { | |||||
_ = logx.Error(err) | |||||
return | |||||
_, err6 := fundDataDb.EggEnergyFundDataUpdateBySession(session, fundData, forceColumns...) | |||||
if err6 != nil { | |||||
_ = logx.Error(err6) | |||||
_ = session.Rollback() | |||||
continue | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -1,12 +1,17 @@ | |||||
package svc | package svc | ||||
import ( | import ( | ||||
"applet/app/task/md" | |||||
"applet/app/utils" | "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/implement" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | "code.fnuoos.com/EggPlanet/egg_models.git/src/model" | ||||
zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" | |||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" | |||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" | |||||
md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" | |||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/svc" | |||||
"fmt" | "fmt" | ||||
"time" | |||||
"xorm.io/xorm" | "xorm.io/xorm" | ||||
) | ) | ||||
@@ -18,58 +23,123 @@ func DealPlatformRevenueData(eg *xorm.Engine, dbName string) { | |||||
} | } | ||||
}() | }() | ||||
revenueDataDb := implement.NewPlatformRevenueDataDb(eg) | |||||
revenueDataList, err := revenueDataDb.PlatformRevenueDataFindNotFinish() | |||||
platformRevenueDataDb := implement.NewPlatformRevenueDataDb(eg) | |||||
platformRevenueDataList, err := platformRevenueDataDb.PlatformRevenueDataFindNotFinish() | |||||
if err != nil { | if err != nil { | ||||
_ = logx.Error(err) | _ = logx.Error(err) | ||||
return | return | ||||
} | } | ||||
revenueDatas := make([]md.RevenueDataNode, len(revenueDataList)) | |||||
for i, data := range revenueDataList { | |||||
now := time.Now() | |||||
recordsDb := implement.NewPlatformRevenueDataRecordsDb(eg) | |||||
for _, data := range platformRevenueDataList { | |||||
// 判断是否是第一次执行 | |||||
lastRecord, err1 := recordsDb.PlatformRevenueDataRecordsGetLast(data.Id) | |||||
if err1 != nil { | |||||
_ = logx.Error(err1) | |||||
continue | |||||
} | |||||
if lastRecord == nil { | |||||
// 首次执行 判断当前是否可以执行 | |||||
if utils.TimeParseStd(data.CreateAt).Add(time.Duration(data.Frequency) * time.Minute).After(now) { | |||||
continue | |||||
} | |||||
} else { | |||||
// 已经被执行过 | |||||
if utils.TimeParseStd(lastRecord.CreateAt).Add(time.Duration(data.Frequency) * time.Minute).After(now) { | |||||
continue | |||||
} | |||||
} | |||||
// 总执行次数 按十分钟更新 | // 总执行次数 按十分钟更新 | ||||
times := data.Hours * 60 / md.ExecutionInterval | |||||
times := data.Hours * 60 / data.Frequency | |||||
// 每次更新金额 | // 每次更新金额 | ||||
amount := utils.AnyToFloat64(data.TotalAmount) / utils.AnyToFloat64(times) | 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), | |||||
session := eg.NewSession() | |||||
defer func() { | |||||
session.Close() | |||||
if err := recover(); err != nil { | |||||
_ = zhios_order_relate_logx.Error(err) | |||||
} | |||||
}() | |||||
session.Begin() | |||||
eggEnergyCoreData, cb, err2 := svc.GetEggEnergyCoreData(eg) | |||||
if err2 != nil { | |||||
_ = logx.Error(err2) | |||||
} | |||||
if cb != nil { | |||||
defer cb() // 释放锁 | |||||
} | |||||
//计算涨价公式 | |||||
err3, calcPriceIncreaseFormulaResp := egg_energy.CalcPriceIncreaseFormula(utils.AnyToString(amount), eggEnergyCoreData) | |||||
if err3 != nil { | |||||
_ = logx.Error(err3) | |||||
_ = session.Rollback() | |||||
continue | |||||
} | } | ||||
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, | |||||
dealAvailableEggEnergyCoinReq := md2.DealAvailableEggEnergyCoinReq{ | |||||
Amount: calcPriceIncreaseFormulaResp.GetEggEnergyNums, | |||||
AmountFee: "", | |||||
BeforePrice: calcPriceIncreaseFormulaResp.BeforePrice, | |||||
AfterPrice: calcPriceIncreaseFormulaResp.AfterPrice, | |||||
BeforePlanetTotalValue: calcPriceIncreaseFormulaResp.BeforePlanetTotalValue, | |||||
AfterPlanetTotalValue: calcPriceIncreaseFormulaResp.AfterPlanetTotalValue, | |||||
BeforeEnergyTotalNums: calcPriceIncreaseFormulaResp.BeforeEnergyTotalNums, | |||||
AfterEnergyTotalNums: calcPriceIncreaseFormulaResp.AfterEnergyTotalNums, | |||||
} | } | ||||
err4 := egg_energy.DealAvailableEggEnergyCoin(session, int(enum.CapitalInjection), eggEnergyCoreData, dealAvailableEggEnergyCoinReq) | |||||
if err4 != nil { | |||||
fmt.Println("ActivityCoinAutoExchangeEggPersonEnergy:::::err111:::", err4) | |||||
_ = session.Rollback() | |||||
continue | |||||
} | |||||
// 插入平台营收详细数据 | |||||
record := model.PlatformRevenueDataRecords{ | |||||
RecordsId: data.Id, | |||||
TotalAmount: data.TotalAmount, | |||||
BalanceAmount: utils.AnyToString(utils.AnyToFloat64(data.BalanceAmount) - amount), | |||||
BalanceTimes: data.BalanceTimes - 1, | |||||
BeforePrice: calcPriceIncreaseFormulaResp.BeforePrice, | |||||
AfterPrice: calcPriceIncreaseFormulaResp.AfterPrice, | |||||
BeforePlanetTotalValue: calcPriceIncreaseFormulaResp.BeforePlanetTotalValue, | |||||
AfterPlanetTotalValue: calcPriceIncreaseFormulaResp.AfterPlanetTotalValue, | |||||
CreateAt: now.Format("2006-01-02 15:04:05"), | |||||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||||
} | |||||
_, err5 := recordsDb.PlatformRevenueDataRecordsInsertBySession(session, record) | |||||
if err5 != nil { | |||||
_ = session.Rollback() | |||||
continue | |||||
} | |||||
// 更新当前数据 | |||||
platformRevenueData := model.PlatformRevenueData{ | |||||
Id: data.Id, | |||||
Kind: data.Kind, | |||||
TotalAmount: data.TotalAmount, | |||||
BalanceAmount: utils.AnyToString(utils.AnyToFloat64(data.BalanceAmount) - amount), | |||||
Hours: data.Hours, | |||||
BalanceTimes: data.BalanceTimes - 1, | |||||
Frequency: data.Frequency, | |||||
Memo: data.Memo, | |||||
CreateAt: data.CreateAt, | |||||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||||
} | |||||
forceColumns := []string{ | forceColumns := []string{ | ||||
"balance_times", | "balance_times", | ||||
"balance_amount", | |||||
} | } | ||||
_, err := revenueDataDb.PlatformRevenueDataUpdate(m, forceColumns...) | |||||
if err != nil { | |||||
_ = logx.Error(err) | |||||
return | |||||
_, err6 := platformRevenueDataDb.PlatformRevenueDataUpdateBySession(session, platformRevenueData, forceColumns...) | |||||
if err6 != nil { | |||||
_ = logx.Error(err6) | |||||
_ = session.Rollback() | |||||
continue | |||||
} | } | ||||
} | } | ||||
} | } |