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

преди 2 месеца
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package svc
  2. import (
  3. "applet/app/e"
  4. "applet/app/lib/validate"
  5. "applet/app/md"
  6. "applet/app/utils"
  7. "code.fnuoos.com/zhimeng/model.git/src/implement"
  8. "code.fnuoos.com/zhimeng/model.git/src/model"
  9. "github.com/gin-gonic/gin"
  10. "github.com/jinzhu/copier"
  11. "time"
  12. )
  13. func AppletApplicationList(c *gin.Context) {
  14. var req md.AppletApplicationListReq
  15. err := c.ShouldBindJSON(&req)
  16. if err != nil {
  17. err = validate.HandleValidateErr(err)
  18. err1 := err.(e.E)
  19. e.OutErr(c, err1.Code, err1.Error())
  20. return
  21. }
  22. engine := MasterDb(c)
  23. NewAppletApplicationDb := implement.NewAppletApplicationDb(engine)
  24. state := make([]string, 0)
  25. if req.CooperateState != "" {
  26. if req.CooperateState == "0" {
  27. state = []string{"0", "1"}
  28. } else {
  29. state = []string{req.CooperateState}
  30. }
  31. }
  32. user := GetUser(c)
  33. appletApplicationList, total, _ := NewAppletApplicationDb.FindAppletApplicationList(req.Name, req.Platform, state, user.MediumId, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
  34. data := make([]md.AppletApplicationListData, 0)
  35. if len(appletApplicationList) > 0 {
  36. for _, v := range appletApplicationList {
  37. var tmp md.AppletApplicationListData
  38. copier.Copy(&tmp, &v)
  39. tmp.Id = utils.IntToStr(v.Id)
  40. tmp.State = utils.IntToStr(v.State)
  41. if v.State == 1 {
  42. v.State = 0
  43. }
  44. tmp.CooperateState = utils.IntToStr(v.State)
  45. data = append(data, tmp)
  46. }
  47. }
  48. res := md.AppletApplicationListRes{
  49. List: data,
  50. Total: total,
  51. Platform: []md.SelectData{
  52. {
  53. Name: "微信小程序",
  54. Value: "wx_applet",
  55. },
  56. },
  57. State: []md.SelectData{
  58. {
  59. Name: "待审核",
  60. Value: "0",
  61. },
  62. {
  63. Name: "审核中",
  64. Value: "1",
  65. },
  66. {
  67. Name: "审核通过",
  68. Value: "2",
  69. },
  70. {
  71. Name: "审核拒绝",
  72. Value: "3",
  73. },
  74. {
  75. Name: "封禁中",
  76. Value: "4",
  77. },
  78. },
  79. CooperateState: []md.SelectData{
  80. {
  81. Name: "未运行",
  82. Value: "0",
  83. },
  84. {
  85. Name: "运行中",
  86. Value: "2",
  87. },
  88. {
  89. Name: "审核拒绝",
  90. Value: "3",
  91. },
  92. {
  93. Name: "封禁中",
  94. Value: "4",
  95. },
  96. },
  97. }
  98. e.OutSuc(c, res, nil)
  99. return
  100. }
  101. func AppletApplicationSave(c *gin.Context) {
  102. var req md.AppletApplicationSaveReq
  103. err := c.ShouldBindJSON(&req)
  104. if err != nil {
  105. err = validate.HandleValidateErr(err)
  106. err1 := err.(e.E)
  107. e.OutErr(c, err1.Code, err1.Error())
  108. return
  109. }
  110. if req.AppId == "" {
  111. e.OutErr(c, 400, e.NewErr(400, "请填写小程序appid"))
  112. return
  113. }
  114. user := GetUser(c)
  115. engine := MasterDb(c)
  116. NewAppletApplicationDb := implement.NewAppletApplicationDb(engine)
  117. var data *model.AppletApplication
  118. if utils.StrToInt(req.Id) > 0 {
  119. data, _ = NewAppletApplicationDb.GetAppletApplicationList(utils.StrToInt(req.Id))
  120. if data == nil {
  121. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  122. return
  123. }
  124. if data.State != 3 {
  125. e.OutErr(c, 400, e.NewErr(400, "您已提交审核,不能再次修改!"))
  126. return
  127. }
  128. tmp, _ := NewAppletApplicationDb.GetAppletApplicationListByAppid(req.AppId)
  129. if tmp != nil && tmp.Id != data.Id {
  130. e.OutErr(c, 400, e.NewErr(400, "该小程序已提交过"))
  131. return
  132. }
  133. } else {
  134. tmp, _ := NewAppletApplicationDb.GetAppletApplicationListByAppid(req.AppId)
  135. if tmp != nil {
  136. e.OutErr(c, 400, e.NewErr(400, "该小程序已提交过"))
  137. return
  138. }
  139. data = &model.AppletApplication{
  140. Platform: req.Platform,
  141. State: 0,
  142. MediumId: user.MediumId,
  143. AppId: req.AppId,
  144. CreateAt: time.Now(),
  145. }
  146. engine.Insert(data)
  147. }
  148. data.UpdateAt = time.Now()
  149. data.State = 0
  150. data.Name = req.Name
  151. data.Logo = req.Logo
  152. data.AppId = req.AppId
  153. data.OriginalId = req.OriginalId
  154. engine.Where("id=?", data.Id).Update(data)
  155. e.OutSuc(c, "success", nil)
  156. return
  157. }