Browse Source

add deal platform revenue and fund data

master
shenjiachi 1 week ago
parent
commit
da6805ad9d
8 changed files with 170 additions and 4 deletions
  1. +3
    -1
      app/hdl/institutional_management/egg_energy/hdl_basic.go
  2. +3
    -1
      app/hdl/institutional_management/egg_energy/hdl_platform_revenue.go
  3. +4
    -1
      app/md/institutional_management/egg_energy/md_basic.go
  4. +0
    -1
      app/md/institutional_management/egg_energy/md_platform_revenue.go
  5. +10
    -0
      app/task/md/md_deal_fund_data.go
  6. +17
    -0
      app/task/md/md_deal_platform_revenue_data.go
  7. +75
    -0
      app/task/svc/svc_deal_fund_data.go
  8. +58
    -0
      app/task/svc/svc_deal_platform_revenue_data.go

+ 3
- 1
app/hdl/institutional_management/egg_energy/hdl_basic.go View File

@@ -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"),


+ 3
- 1
app/hdl/institutional_management/egg_energy/hdl_platform_revenue.go View File

@@ -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,


+ 4
- 1
app/md/institutional_management/egg_energy/md_basic.go View File

@@ -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:"备注"`
}

+ 0
- 1
app/md/institutional_management/egg_energy/md_platform_revenue.go View File

@@ -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:"备注"`
}

+ 10
- 0
app/task/md/md_deal_fund_data.go View File

@@ -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" ` // 每次结算金额
}

+ 17
- 0
app/task/md/md_deal_platform_revenue_data.go View File

@@ -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 {
}

+ 75
- 0
app/task/svc/svc_deal_fund_data.go View File

@@ -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
}
}
}

+ 58
- 0
app/task/svc/svc_deal_platform_revenue_data.go View File

@@ -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
}
}
}

Loading…
Cancel
Save