广告平台(站长使用)
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.
 
 
 
 
 

158 lines
4.7 KiB

  1. package svc
  2. import (
  3. "applet/app/e"
  4. "applet/app/lib/validate"
  5. "applet/app/md"
  6. "applet/app/utils"
  7. db "code.fnuoos.com/zhimeng/model.git/src"
  8. implement2 "code.fnuoos.com/zhimeng/model.git/src/implement"
  9. "code.fnuoos.com/zhimeng/model.git/src/super/implement"
  10. "code.fnuoos.com/zhimeng/model.git/src/super/model"
  11. "github.com/gin-gonic/gin"
  12. "strings"
  13. "time"
  14. )
  15. func AgentBindMediumList(c *gin.Context) { //代理 查旗下 媒体
  16. var req md.MediumListReq
  17. err := c.ShouldBindJSON(&req)
  18. if err != nil {
  19. err = validate.HandleValidateErr(err)
  20. err1 := err.(e.E)
  21. e.OutErr(c, err1.Code, err1.Error())
  22. return
  23. }
  24. engine := db.Db
  25. agentWithMediumDb := implement.NewAgentWithMediumDb(engine)
  26. data, total, _ := agentWithMediumDb.FindAgentWithMediumList(req.Name, req.State, utils.StrToInt(req.Id), 0, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  27. list := make([]md.MediumListData, 0)
  28. NewMediumDb := implement2.NewMediumDb(MasterDb(c))
  29. if data != nil {
  30. for _, v := range data {
  31. tmp := md.MediumListData{
  32. Id: utils.IntToStr(v.AgentWithMedium.Id),
  33. MediumId: utils.IntToStr(v.AgentWithMedium.MediumId),
  34. CompanyName: v.MediumList.CompanyName,
  35. UnifiedSocialCreditCode: v.MediumList.UnifiedSocialCreditCode,
  36. State: utils.IntToStr(v.MediumList.State),
  37. Memo: v.MediumList.Memo,
  38. LegalRepresentative: v.MediumList.LegalRepresentative,
  39. BusinessLicenseAddress: v.MediumList.BusinessLicenseAddress,
  40. }
  41. medium := NewMediumDb.GetSuperAdmin(v.AgentWithMedium.MediumId)
  42. if medium != nil {
  43. tmp.Account = medium.Username
  44. }
  45. list = append(list, tmp)
  46. }
  47. }
  48. res := md.MediumListRes{
  49. List: list,
  50. Total: total,
  51. State: []md.SelectData{
  52. {Name: "待提交", Value: "0"},
  53. {Name: "待审核", Value: "1"},
  54. {Name: "审核通过", Value: "2"},
  55. {Name: "审核拒绝", Value: "3"},
  56. },
  57. }
  58. e.OutSuc(c, res, nil)
  59. return
  60. }
  61. func MediumBindAgentList(c *gin.Context) {
  62. var req md.MediumListReq
  63. err := c.ShouldBindJSON(&req)
  64. if err != nil {
  65. err = validate.HandleValidateErr(err)
  66. err1 := err.(e.E)
  67. e.OutErr(c, err1.Code, err1.Error())
  68. return
  69. }
  70. engine := db.Db
  71. agentWithMediumDb := implement.NewAgentWithMediumDb(engine)
  72. data, total, _ := agentWithMediumDb.FindAgentWithMediumList(req.Name, req.State, 0, utils.StrToInt(req.Id), utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  73. list := make([]md.MediumListData, 0)
  74. NewAgentDb := implement2.NewAgentDb(MasterDb(c))
  75. if data != nil {
  76. for _, v := range data {
  77. tmp := md.MediumListData{
  78. Id: utils.IntToStr(v.AgentWithMedium.Id),
  79. MediumId: utils.IntToStr(v.AgentWithMedium.AgentId),
  80. CompanyName: v.AgentList.CompanyName,
  81. UnifiedSocialCreditCode: v.AgentList.UnifiedSocialCreditCode,
  82. State: utils.IntToStr(v.AgentList.State),
  83. Memo: v.AgentList.Memo,
  84. LegalRepresentative: v.AgentList.LegalRepresentative,
  85. BusinessLicenseAddress: v.AgentList.BusinessLicenseAddress,
  86. }
  87. agent := NewAgentDb.GetSuperAdmin(v.AgentWithMedium.AgentId)
  88. if agent != nil {
  89. tmp.Account = agent.Username
  90. }
  91. list = append(list, tmp)
  92. }
  93. }
  94. res := md.MediumListRes{
  95. List: list,
  96. Total: total,
  97. State: []md.SelectData{
  98. {Name: "待提交", Value: "0"},
  99. {Name: "待审核", Value: "1"},
  100. {Name: "审核通过", Value: "2"},
  101. {Name: "审核拒绝", Value: "3"},
  102. },
  103. }
  104. e.OutSuc(c, res, nil)
  105. return
  106. }
  107. func MediumBindAgentSave(c *gin.Context) {
  108. var req md.MediumListSaveReq
  109. err := c.ShouldBindJSON(&req)
  110. if err != nil {
  111. err = validate.HandleValidateErr(err)
  112. err1 := err.(e.E)
  113. e.OutErr(c, err1.Code, err1.Error())
  114. return
  115. }
  116. agentDb := implement2.NewAgentDb(MasterDb(c))
  117. username, _ := agentDb.GetSuperAgentByUsername(req.Username)
  118. if username == nil {
  119. e.OutErr(c, 400, e.NewErr(400, "渠道代理不存在"))
  120. return
  121. }
  122. mediumDb := implement.NewAgentWithMediumDb(db.Db)
  123. data := mediumDb.GetAgentWithMediumByMediumIdAndAgentId(utils.StrToInt(req.MediumId), username.AgentId)
  124. if data != nil {
  125. e.OutErr(c, 400, e.NewErr(400, "已绑定过该渠道代理"))
  126. return
  127. }
  128. var tmp = model.AgentWithMedium{
  129. AgentId: username.AgentId,
  130. MediumId: utils.StrToInt(req.MediumId),
  131. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  132. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  133. }
  134. db.Db.InsertOne(&tmp)
  135. e.OutSuc(c, "success", nil)
  136. return
  137. }
  138. func MediumBindAgentDel(c *gin.Context) {
  139. var req md.MediumListDelReq
  140. err := c.ShouldBindJSON(&req)
  141. if err != nil {
  142. err = validate.HandleValidateErr(err)
  143. err1 := err.(e.E)
  144. e.OutErr(c, err1.Code, err1.Error())
  145. return
  146. }
  147. db.Db.In("id", strings.Split(req.Id, ",")).Delete(&model.AgentWithMedium{})
  148. e.OutSuc(c, "success", nil)
  149. return
  150. }