Quellcode durchsuchen

add deal fund data and platform revenue data

master
shenjiachi vor 1 Woche
Ursprung
Commit
42a9062391
7 geänderte Dateien mit 228 neuen und 92 gelöschten Zeilen
  1. +1
    -0
      app/hdl/institutional_management/egg_energy/hdl_basic.go
  2. +2
    -2
      app/hdl/institutional_management/egg_energy/hdl_platform_revenue.go
  3. +1
    -0
      app/md/institutional_management/egg_energy/md_basic.go
  4. +8
    -10
      app/md/institutional_management/egg_energy/md_platform_revenue.go
  5. +0
    -4
      app/task/md/md_deal_platform_revenue_data.go
  6. +107
    -37
      app/task/svc/svc_deal_fund_data.go
  7. +109
    -39
      app/task/svc/svc_deal_platform_revenue_data.go

+ 1
- 0
app/hdl/institutional_management/egg_energy/hdl_basic.go Datei anzeigen

@@ -508,6 +508,7 @@ func AddFundData(c *gin.Context) {
BalanceAmount: req.TotalAmount,
Hours: hour,
BalanceTimes: times,
Frequency: req.Frequency,
Memo: req.Memo,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),


+ 2
- 2
app/hdl/institutional_management/egg_energy/hdl_platform_revenue.go Datei anzeigen

@@ -141,8 +141,8 @@ func AddPlatformRevenue(c *gin.Context) {
Hours: hour,
BalanceTimes: times,
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)
if err != nil {


+ 1
- 0
app/md/institutional_management/egg_energy/md_basic.go Datei anzeigen

@@ -141,4 +141,5 @@ type AddFundDataReq struct {
TotalAmount string `json:"total_amount,required"` // 金额
Hours int `json:"hours,required"` // 时长(小时)
Memo string `json:"memo" example:"备注"`
Frequency int `json:"frequency"` // 频率(分钟)
}

+ 8
- 10
app/md/institutional_management/egg_energy/md_platform_revenue.go Datei anzeigen

@@ -1,7 +1,5 @@
package md

import "time"

type SetVideoRewardReq struct {
UnitPrice string `json:"unit_price,required"` // 单价
ECMP string `json:"ecmp,required"` // 当前 Ecmp 值
@@ -16,14 +14,14 @@ type ListPlatformRevenueReq 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 {


+ 0
- 4
app/task/md/md_deal_platform_revenue_data.go Datei anzeigen

@@ -4,10 +4,6 @@ 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" ` // 每次结算金额


+ 107
- 37
app/task/svc/svc_deal_fund_data.go Datei anzeigen

@@ -1,12 +1,17 @@
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"
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"
"time"
"xorm.io/xorm"
)

@@ -25,51 +30,116 @@ func DealFundData(eg *xorm.Engine, dbName string) {
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)
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{
"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
}
}
}

+ 109
- 39
app/task/svc/svc_deal_platform_revenue_data.go Datei anzeigen

@@ -1,12 +1,17 @@
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"
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"
"time"
"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 {
_ = logx.Error(err)
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)
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{
"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
}
}
}

Laden…
Abbrechen
Speichern