广告平台(站长使用)
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

149 lignes
5.7 KiB

  1. package svc
  2. import (
  3. "applet/app/md"
  4. "applet/app/utils"
  5. db "code.fnuoos.com/zhimeng/model.git/src"
  6. "code.fnuoos.com/zhimeng/model.git/src/super/implement"
  7. "code.fnuoos.com/zhimeng/model.git/src/super/model"
  8. "github.com/gin-gonic/gin"
  9. "time"
  10. )
  11. func DivisionStrategyList(c *gin.Context, req md.DivisionStrategyReq) md.DivisionStrategyRes {
  12. engine := db.Db
  13. NewMediumDivisionStrategyDb := implement.NewMediumDivisionStrategyDb(engine)
  14. mediumId := GetMediumId(c, req.Name)
  15. MediumList, total, _ := NewMediumDivisionStrategyDb.FindMediumDivisionStrategyList(c.GetString("mid"), mediumId, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  16. data := make([]md.DivisionStrategyData, 0)
  17. if len(MediumList) > 0 {
  18. for _, v := range MediumList {
  19. var tmp = md.DivisionStrategyData{
  20. Id: utils.IntToStr(v.Id),
  21. MediumId: utils.IntToStr(v.MediumId),
  22. Account: "",
  23. Name: "",
  24. PlatformRetentionRate: utils.IntToStr(v.PlatformRetentionRate),
  25. CommissionRetentionRate: utils.IntToStr(v.CommissionRetentionRate),
  26. MediaRevenueRate: utils.IntToStr(v.MediaRevenueRate),
  27. AgentRevenueRate: utils.IntToStr(v.AgentRevenueRate),
  28. ExtraRevenueRate: utils.IntToStr(v.ExtraRevenueRate),
  29. AgreementSharingRate: utils.IntToStr(v.AgreementSharingRate),
  30. }
  31. tmpMedium := GetMediumInfo(c, v.MediumId)
  32. if tmpMedium["account"] != "" {
  33. tmp.Account = tmpMedium["account"]
  34. }
  35. if tmpMedium["name"] != "" {
  36. tmp.Name = tmpMedium["name"]
  37. }
  38. data = append(data, tmp)
  39. }
  40. }
  41. res := md.DivisionStrategyRes{
  42. List: data,
  43. Total: total,
  44. }
  45. return res
  46. }
  47. func DivisionStrategyDetail(c *gin.Context, req md.DivisionStrategyDetailReq) md.DivisionStrategyDetailRes {
  48. eg := db.Db
  49. NewMediumDivisionStrategyDb := implement.NewMediumDivisionStrategyDb(eg)
  50. mediumData, _ := NewMediumDivisionStrategyDb.GetOriginalWxAdDataByMediumId(utils.StrToInt(req.MediumId))
  51. tmpMedium := GetMediumInfo(c, mediumData.MediumId)
  52. agentList := make([]md.DivisionStrategyDetailByAgent, 0)
  53. res := md.DivisionStrategyDetailRes{
  54. MediumId: req.MediumId,
  55. Account: "",
  56. Name: "",
  57. PlatformRetentionRate: utils.IntToStr(mediumData.PlatformRetentionRate),
  58. CommissionRetentionRate: utils.IntToStr(mediumData.CommissionRetentionRate),
  59. MediaRevenueRate: utils.IntToStr(mediumData.MediaRevenueRate),
  60. AgentRevenueRate: utils.IntToStr(mediumData.AgentRevenueRate),
  61. ExtraRevenueRate: utils.IntToStr(mediumData.ExtraRevenueRate),
  62. AgreementSharingRate: utils.IntToStr(mediumData.AgreementSharingRate),
  63. AgentList: agentList,
  64. }
  65. if tmpMedium["account"] != "" {
  66. res.Account = tmpMedium["account"]
  67. }
  68. if tmpMedium["name"] != "" {
  69. res.Name = tmpMedium["name"]
  70. }
  71. NewAgentWithMediumDb := implement.NewAgentWithMediumDb(eg)
  72. agent, _ := NewAgentWithMediumDb.FindAgentWithMediumListByMediumIdAll(mediumData.MediumId)
  73. if agent != nil {
  74. NewMediumDivisionStrategyWithAgentFlowDb := implement.NewMediumDivisionStrategyWithAgentFlowDb(eg)
  75. strategy, _ := NewMediumDivisionStrategyWithAgentFlowDb.FindMediumDivisionStrategyWithAgentFlowByStrategyId(mediumData.Id)
  76. strategyMap := make(map[int]model.MediumDivisionStrategyWithAgentFlow)
  77. if strategy != nil {
  78. for _, v := range *strategy {
  79. strategyMap[v.AgentId] = v
  80. }
  81. }
  82. for _, v := range agent {
  83. tmp := md.DivisionStrategyDetailByAgent{
  84. AgentId: utils.IntToStr(v.AgentId),
  85. AgentRevenueRate: utils.IntToStr(strategyMap[v.AgentId].AgentRevenueRate),
  86. ExtraRevenueRate: utils.IntToStr(strategyMap[v.AgentId].ExtraRevenueRate),
  87. }
  88. tmpAgent := GetAgentInfo(c, v.AgentId)
  89. if tmpAgent["account"] != "" {
  90. tmp.Account = tmpAgent["account"]
  91. }
  92. if tmpAgent["name"] != "" {
  93. tmp.Name = tmpAgent["name"]
  94. }
  95. agentList = append(agentList, tmp)
  96. }
  97. }
  98. res.AgentList = agentList
  99. return res
  100. }
  101. func DivisionStrategySave(c *gin.Context, req md.DivisionStrategyDetailRes) error {
  102. eg := db.Db
  103. sess := eg.NewSession()
  104. defer sess.Close()
  105. sess.Begin()
  106. NewMediumDivisionStrategyDb := implement.NewMediumDivisionStrategyDb(eg)
  107. mediumData, _ := NewMediumDivisionStrategyDb.GetOriginalWxAdDataByMediumIdSess(sess, utils.StrToInt(req.MediumId))
  108. mediumData.PlatformRetentionRate = utils.StrToInt(req.PlatformRetentionRate)
  109. mediumData.CommissionRetentionRate = utils.StrToInt(req.CommissionRetentionRate)
  110. mediumData.MediaRevenueRate = utils.StrToInt(req.MediaRevenueRate)
  111. mediumData.AgentRevenueRate = utils.StrToInt(req.AgentRevenueRate)
  112. mediumData.ExtraRevenueRate = utils.StrToInt(req.ExtraRevenueRate)
  113. mediumData.AgreementSharingRate = utils.StrToInt(req.AgreementSharingRate)
  114. _, err := sess.Where("id=?", mediumData.Id).Update(mediumData)
  115. if err != nil {
  116. sess.Rollback()
  117. return err
  118. }
  119. NewMediumDivisionStrategyWithAgentFlowDb := implement.NewMediumDivisionStrategyWithAgentFlowDb(eg)
  120. for _, v := range req.AgentList {
  121. flow, _ := NewMediumDivisionStrategyWithAgentFlowDb.GetMediumDivisionStrategyWithAgentFlowSess(sess, mediumData.Id, utils.StrToInt(v.AgentId))
  122. if flow == nil {
  123. flow = &model.MediumDivisionStrategyWithAgentFlow{
  124. StrategyId: mediumData.Id,
  125. AgentId: utils.StrToInt(v.AgentId),
  126. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  127. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  128. }
  129. _, err = sess.Insert(flow)
  130. if err != nil {
  131. sess.Rollback()
  132. return err
  133. }
  134. }
  135. flow.ExtraRevenueRate = utils.StrToInt(v.ExtraRevenueRate)
  136. flow.AgentRevenueRate = utils.StrToInt(v.AgentRevenueRate)
  137. flow.UpdateAt = time.Now().Format("2006-01-02 15:04:05")
  138. _, err = sess.Where("id=?", flow.Id).Update(flow)
  139. if err != nil {
  140. sess.Rollback()
  141. return err
  142. }
  143. }
  144. sess.Commit()
  145. return nil
  146. }