蛋蛋星球 后台端
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.
 
 
 
 

108 lines
2.8 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. md2 "applet/app/md"
  6. "applet/app/md/member_center"
  7. "applet/app/svc"
  8. "applet/app/utils"
  9. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  10. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  11. "github.com/gin-gonic/gin"
  12. )
  13. func CertificateList(c *gin.Context) {
  14. var req *md.CertificateListReq
  15. if err := c.ShouldBindJSON(&req); err != nil {
  16. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  17. return
  18. }
  19. if req.Phone != "" {
  20. NewUserDb := implement.NewUserDb(db.Db)
  21. user, _ := NewUserDb.UserGetOneByParams(map[string]interface{}{
  22. "key": "id",
  23. "value": req.Phone,
  24. })
  25. req.Uid = "0"
  26. if user != nil {
  27. req.Uid = utils.Int64ToStr(user.Id)
  28. }
  29. }
  30. var resp md.CertificateListResp
  31. noticeList := make([]md.CertificateList, 0)
  32. NewUserCertificateDb := implement.NewUserCertificateDb(db.Db)
  33. notice, total, _ := NewUserCertificateDb.FindUserCertificate(req.Page, req.Limit, req.Uid)
  34. resp.Total = total
  35. if notice != nil {
  36. for _, v := range *notice {
  37. tmp := md.CertificateList{
  38. Id: utils.IntToStr(v.Id),
  39. Name: v.Name,
  40. No: v.No,
  41. StartTime: v.StartTime,
  42. EndTime: v.EndTime,
  43. Logo: svc.GetOssUrl(md2.Certificate.Logo),
  44. BgImg: svc.GetOssUrl(md2.Certificate.BgImg),
  45. NameIcon: svc.GetOssUrl(md2.Certificate.NameIcon),
  46. Medal: svc.GetOssUrl(md2.Certificate.Medal),
  47. Seal: svc.GetOssUrl(md2.Certificate.Seal),
  48. }
  49. noticeList = append(noticeList, tmp)
  50. }
  51. }
  52. resp.List = noticeList
  53. e.OutSuc(c, resp, nil)
  54. return
  55. }
  56. func CertificateDel(c *gin.Context) {
  57. var req *md.CertificateDelReq
  58. if err := c.ShouldBindJSON(&req); err != nil {
  59. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  60. return
  61. }
  62. db.Db.In("id", req.Id).Delete(&model.UserCertificate{})
  63. e.OutSuc(c, "success", nil)
  64. return
  65. }
  66. func CertificateSave(c *gin.Context) {
  67. var req *md.CertificateSave
  68. if err := c.ShouldBindJSON(&req); err != nil {
  69. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  70. return
  71. }
  72. var data = new(model.UserCertificate)
  73. if utils.StrToInt(req.Id) > 0 {
  74. NewUserCertificateDb := implement.NewUserCertificateDb(db.Db)
  75. space, _ := NewUserCertificateDb.GetUserCertificateById(req.Id)
  76. if space == nil {
  77. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  78. return
  79. }
  80. data = space
  81. } else {
  82. data.No = "DD" + utils.GenerateUniqueInvitationCode(12)
  83. data.No = check(1, data.No)
  84. db.Db.Insert(data)
  85. }
  86. data.Name = req.Name
  87. data.StartTime = req.StartTime
  88. data.EndTime = req.EndTime
  89. db.Db.Where("id=?", data.Id).Update(data)
  90. e.OutSuc(c, "success", nil)
  91. return
  92. }
  93. func check(num int, no string) string {
  94. NewUserCertificateDb := implement.NewUserCertificateDb(db.Db)
  95. space, _ := NewUserCertificateDb.GetUserCertificateByNo(no)
  96. if num >= 10 {
  97. return ""
  98. }
  99. if space != nil {
  100. no = "DD" + utils.GenerateUniqueInvitationCode(12)
  101. num++
  102. return check(num, no)
  103. }
  104. return no
  105. }