广告平台(站长使用)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

svc_division_strategy.go 6.0 KiB

3 months ago
3 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. mediumData.UpdateAt = time.Now().Format("2006-01-02 15:04:05")
  115. _, err := sess.Where("id=?", mediumData.Id).Cols("update_at,agreement_sharing_rate,platform_retention_rate,commission_retention_rate,media_revenue_rate,agent_revenue_rate,extra_revenue_rate").Update(mediumData)
  116. if err != nil {
  117. sess.Rollback()
  118. return err
  119. }
  120. NewMediumDivisionStrategyWithAgentFlowDb := implement.NewMediumDivisionStrategyWithAgentFlowDb(eg)
  121. for _, v := range req.AgentList {
  122. flow, _ := NewMediumDivisionStrategyWithAgentFlowDb.GetMediumDivisionStrategyWithAgentFlowSess(sess, mediumData.Id, utils.StrToInt(v.AgentId))
  123. if flow == nil {
  124. flow = &model.MediumDivisionStrategyWithAgentFlow{
  125. StrategyId: mediumData.Id,
  126. AgentId: utils.StrToInt(v.AgentId),
  127. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  128. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  129. }
  130. _, err = sess.Insert(flow)
  131. if err != nil {
  132. sess.Rollback()
  133. return err
  134. }
  135. }
  136. flow.ExtraRevenueRate = utils.StrToInt(v.ExtraRevenueRate)
  137. flow.AgentRevenueRate = utils.StrToInt(v.AgentRevenueRate)
  138. flow.UpdateAt = time.Now().Format("2006-01-02 15:04:05")
  139. _, err = sess.Where("id=?", flow.Id).Cols("extra_revenue_rate,agent_revenue_rate,update_at").Update(flow)
  140. if err != nil {
  141. sess.Rollback()
  142. return err
  143. }
  144. }
  145. sess.Commit()
  146. return nil
  147. }