|
- package svc
-
- import (
- "applet/app/e"
- "applet/app/md"
- "applet/app/utils"
- "applet/app/utils/cache"
- db "code.fnuoos.com/zhimeng/model.git/src"
- implement2 "code.fnuoos.com/zhimeng/model.git/src/implement"
- "code.fnuoos.com/zhimeng/model.git/src/super/implement"
- "code.fnuoos.com/zhimeng/model.git/src/super/model"
- "errors"
- "fmt"
- "github.com/gin-gonic/gin"
- )
-
- func DataCenterIncomeDataList(c *gin.Context, req md.DataCenterGenerateDataReq) md.DataCenterIncomeDataRes {
- engine := db.Db
- NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(engine)
- appId := GetAppletId(c, req.Name, req.Platform)
- slotId := GetSlotId(c, req.State)
- MediumList, total, _ := NewGenerateWxAdDataDb.FindGenerateWxAdDataListMedium(c.GetString("mid"), appId, slotId, req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
- data := make([]md.DataCenterIncomeDataData, 0)
- if len(MediumList) > 0 {
- for _, v := range MediumList {
- var tmp = md.DataCenterIncomeDataData{
- AgreementSharing: utils.Float64ToStr(float64(v.AgreementSharing) / 100),
- AgentRevenue: utils.Float64ToStr(float64(v.AgentRevenue) / 100),
- Id: utils.IntToStr(v.Id),
- ExposureCount: utils.IntToStr(v.ExposureCount),
- ClickCount: utils.IntToStr(v.ClickCount),
- ClickRate: v.ClickRate,
- Ecpm: utils.Float64ToStr(utils.StrToFloat64(v.Ecpm) / 100),
- Date: v.Date,
- MediaRevenue: utils.Float64ToStr(float64(v.MediaRevenue) / 100),
- SettleAmount: utils.Float64ToStr(float64(v.MediaRevenue+v.AgentRevenue+v.AgreementSharing) / 100),
- }
- tmpApplet := GetAppletInfo(c, v.AppId)
- if tmpApplet["platform"] != "" {
- tmp.Platform = tmpApplet["platform"]
- }
- if tmpApplet["name"] != "" {
- tmp.Name = tmpApplet["name"]
- }
- tmpSlot := GetSlotInfo(c, v.SlotId)
- if tmpSlot["state"] != "" {
- tmp.State = tmpSlot["state"]
- }
- if tmpSlot["name"] != "" {
- tmp.AdvName = tmpSlot["name"]
- }
- data = append(data, tmp)
- }
- }
- res := md.DataCenterIncomeDataRes{
- List: data,
- Total: total,
- State: md.AdState,
- Platform: md.AdPlatform,
- }
- return res
- }
- func DataCenterIncomeDataDetail(c *gin.Context, req md.DataCenterGenerateDataCommReq) {
- NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(db.Db)
- data, _ := NewGenerateWxAdDataDb.GetGenerateWxAdData(utils.StrToInt(req.Id))
- if data == nil {
- e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
- return
- }
- agentReward := make([]md.DataCenterGenerateDataDetailAgentRewardSecond, 0)
- NewGenerateWxAdDataWithAgentFlowDb := implement.NewGenerateWxAdDataWithAgentFlowDb(db.Db)
- agent, _ := NewGenerateWxAdDataWithAgentFlowDb.FindGenerateWxAdDataWithAgentFlowByStrategyId(data.Id)
- if agent != nil {
- for _, v := range *agent {
- tmp := md.DataCenterGenerateDataDetailAgentRewardSecond{
- Name: "",
- Account: "",
- AgentRevenue: utils.Float64ToStr(float64(v.AgentRevenue) / 100),
- AgentRevenueRate: utils.IntToStr(data.AgentRevenueRate),
- }
- tmpApplet := GetAgentInfo(c, v.AgentId)
- if tmpApplet["name"] != "" {
- tmp.Name = tmpApplet["name"]
- }
- if tmpApplet["account"] != "" {
- tmp.Account = tmpApplet["account"]
- }
- agentReward = append(agentReward, tmp)
- }
- }
- res := md.DataCenterIncomeDataDetail{
- MediaRevenue: utils.Float64ToStr(float64(data.MediaRevenue) / 100),
- AgreementSharing: utils.Float64ToStr(float64(data.AgreementSharing) / 100),
- AgentRevenue: utils.Float64ToStr(float64(data.AgentRevenue) / 100),
- DataSource: "手动同步",
- CreateAt: data.CreateAt,
- UpdateAt: data.UpdateAt,
- MediaRevenueRate: utils.IntToStr(data.MediaRevenueRate),
- AgentRevenueRate: utils.IntToStr(data.AgentRevenueRate),
- AgreementSharingRate: utils.IntToStr(data.AgreementSharingRate),
- AgentReward: agentReward,
- }
- tmpApplet := GetAppletInfo(c, data.AppId)
- if tmpApplet["platform"] != "" {
- res.Platform = tmpApplet["platform"]
- }
- NewAppletApplicationDb := implement2.NewAppletApplicationDb(MasterDb(c))
- app, _ := NewAppletApplicationDb.GetAppletApplicationListByAppid(data.AppId)
- tmp := GetMediumInfo(c, app.MediumId)
- if tmp["name"] != "" {
- res.MediumName = tmp["name"]
- if tmp["account"] != "" {
- res.MediumName += "(" + tmp["account"] + ")"
- }
- }
- e.OutSuc(c, res, nil)
- return
- }
-
- func DataCenterGenerateDataList(c *gin.Context, req md.DataCenterGenerateDataReq) md.DataCenterGenerateDataRes {
- engine := db.Db
- NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(engine)
- appId := GetAppletId(c, req.Name, req.Platform)
- slotId := GetSlotId(c, req.State)
- MediumList, total, _ := NewGenerateWxAdDataDb.FindGenerateWxAdDataList(c.GetString("mid"), appId, slotId, req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
- data := make([]md.DataCenterGenerateDataData, 0)
- if len(MediumList) > 0 {
- NewOriginalWxAdDataDb := implement.NewOriginalWxAdDataDb(engine)
- for _, v := range MediumList {
- wxData, _ := NewOriginalWxAdDataDb.GetOriginalWxAdData(v.OriginalDataId)
- var tmp = md.DataCenterGenerateDataData{
- Id: utils.IntToStr(v.Id),
- ExposureCount: utils.IntToStr(v.ExposureCount),
- ClickCount: utils.IntToStr(v.ClickCount),
- ClickRate: v.ClickRate,
- Ecpm: utils.Float64ToStr(utils.StrToFloat64(v.Ecpm) / 100),
- IsGenerateReport: utils.IntToStr(v.IsGenerateReport),
- Date: v.Date,
- PlatformRetention: utils.Float64ToStr(float64(v.PlatformRetention) / 100),
- CommissionRetention: utils.Float64ToStr(float64(v.CommissionRetention) / 100),
- PriceAdjustmentRetention: utils.Float64ToStr(float64(v.PriceAdjustmentRetention) / 100),
- MediaRevenue: utils.Float64ToStr(float64(v.MediaRevenue) / 100),
- AgentRevenue: utils.Float64ToStr(float64(v.AgentRevenue) / 100),
- ExtraRevenue: utils.Float64ToStr(float64(v.ExtraRevenue) / 100),
- AgreementSharing: utils.Float64ToStr(float64(v.AgreementSharing) / 100),
- AgreementSharingTotal: utils.Float64ToStr(float64(v.AgreementSharingTotal) / 100),
- }
- if wxData != nil {
- tmp.OldClickRate = wxData.ClickRate
- tmp.OldClickCount = utils.IntToStr(wxData.ClickCount)
- tmp.OldEcpm = utils.Float64ToStr(utils.StrToFloat64(wxData.Ecpm) / 100)
- tmp.OldExposureCount = utils.IntToStr(wxData.ExposureCount)
- }
- tmpApplet := GetAppletInfo(c, v.AppId)
- if tmpApplet["platform"] != "" {
- tmp.Platform = tmpApplet["platform"]
- }
- if tmpApplet["name"] != "" {
- tmp.Name = tmpApplet["name"]
- }
- tmpSlot := GetSlotInfo(c, v.SlotId)
- if tmpSlot["state"] != "" {
- tmp.State = tmpSlot["state"]
- }
- if tmpSlot["name"] != "" {
- tmp.AdvName = tmpSlot["name"]
- }
- data = append(data, tmp)
- }
- }
- res := md.DataCenterGenerateDataRes{
- List: data,
- Total: total,
- State: md.AdState,
- Platform: md.AdPlatform,
- }
- return res
- }
-
- func DataCenterGenerateDataDel(c *gin.Context, req md.DataCenterGenerateDataCommReq) error {
- NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(db.Db)
- data, _ := NewGenerateWxAdDataDb.GetGenerateWxAdData(utils.StrToInt(req.Id))
- if data == nil {
- return errors.New("记录不存在")
- }
- if data.IsGenerateReport == 1 {
- return errors.New("记录已应用,不能删除")
- }
- _, err := db.Db.Where("id=?", req.Id).Delete(&model.GenerateWxAdData{})
- if err != nil {
- return err
- }
- db.Db.Where("id=?", data.OriginalDataId).Cols("is_apply").Update(&model.OriginalWxAdData{IsApply: 0})
- return nil
- }
- func DataCenterGenerateDataDetail(c *gin.Context, req md.DataCenterGenerateDataCommReq) {
- NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(db.Db)
- data, _ := NewGenerateWxAdDataDb.GetGenerateWxAdData(utils.StrToInt(req.Id))
- if data == nil {
- e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
- return
- }
- agentReward := make([]md.DataCenterGenerateDataDetailAgentReward, 0)
- NewGenerateWxAdDataWithAgentFlowDb := implement.NewGenerateWxAdDataWithAgentFlowDb(db.Db)
- agent, _ := NewGenerateWxAdDataWithAgentFlowDb.FindGenerateWxAdDataWithAgentFlowByStrategyId(data.Id)
- if agent != nil {
- for _, v := range *agent {
- tmp := md.DataCenterGenerateDataDetailAgentReward{
- Name: "",
- Account: "",
- AgentRevenue: utils.Float64ToStr(float64(v.AgentRevenue) / 100),
- AgentRevenueRate: utils.IntToStr(data.AgentRevenueRate),
- ExtraRevenue: utils.Float64ToStr(float64(v.ExtraRevenue) / 100),
- ExtraRevenueRate: utils.IntToStr(data.ExtraRevenueRate),
- }
- tmpApplet := GetAgentInfo(c, v.AgentId)
- if tmpApplet["name"] != "" {
- tmp.Name = tmpApplet["name"]
- }
- if tmpApplet["account"] != "" {
- tmp.Account = tmpApplet["account"]
- }
- agentReward = append(agentReward, tmp)
- }
- }
- res := md.DataCenterGenerateDataDetailData{
- PlatformRetentionRate: utils.IntToStr(data.PlatformRetentionRate),
- CommissionRetentionRate: utils.IntToStr(data.CommissionRetentionRate),
- MediaRevenueRate: utils.IntToStr(data.MediaRevenueRate),
- AgentRevenueRate: utils.IntToStr(data.AgentRevenueRate),
- ExtraRevenueRate: utils.IntToStr(data.ExtraRevenueRate),
- AgreementSharingRate: utils.IntToStr(data.AgreementSharingRate),
- AgentReward: agentReward,
- }
- e.OutSuc(c, res, nil)
- return
- }
- func DataCenterGenerateDataDoing(c *gin.Context, req md.DataCenterGenerateDataCommReq) error {
- NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(db.Db)
- data, _ := NewGenerateWxAdDataDb.GetGenerateWxAdData(utils.StrToInt(req.Id))
- if data == nil {
- return e.NewErr(400, "记录不存在")
- }
- if data.IsGenerateReport == 1 {
- return e.NewErr(400, "该记录已完成操作")
- }
- // 加锁 防止并发提取
- mutexKey := fmt.Sprintf("%s:DataCenterGenerateDataDoing:%s", c.GetString("mid"), req.Id)
- withdrawAvailable, err := cache.Do("SET", mutexKey, 1, "EX", 5, "NX")
- if err != nil {
- return err
- }
- if withdrawAvailable != "OK" {
- return e.NewErr(400000, "请求过于频繁,请稍后再试")
- }
- args := md.SettlementWxAdData{
- GenerateDataId: utils.StrToInt(req.Id),
- }
- err = SettlementWxAdData(args)
- if err != nil {
- return err
- }
- return nil
- }
|