蛋蛋星球 后台端
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_certificate.go 3.1 KiB

2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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": "phone",
  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. NewUserDb := implement.NewUserDb(db.Db)
  38. user, _ := NewUserDb.UserGetOneByParams(map[string]interface{}{
  39. "key": "id",
  40. "value": v.Uid,
  41. })
  42. phone := ""
  43. if user != nil {
  44. phone = user.Phone
  45. }
  46. tmp := md.CertificateList{
  47. Id: utils.IntToStr(v.Id),
  48. Name: v.Name,
  49. Phone: phone,
  50. Uid: utils.IntToStr(v.Uid),
  51. No: v.No,
  52. StartTime: v.StartTime,
  53. EndTime: v.EndTime,
  54. Logo: svc.GetOssUrl(md2.Certificate.Logo),
  55. BgImg: svc.GetOssUrl(md2.Certificate.BgImg),
  56. NameIcon: svc.GetOssUrl(md2.Certificate.NameIcon),
  57. Medal: svc.GetOssUrl(md2.Certificate.Medal),
  58. Seal: svc.GetOssUrl(md2.Certificate.Seal),
  59. }
  60. noticeList = append(noticeList, tmp)
  61. }
  62. }
  63. resp.List = noticeList
  64. e.OutSuc(c, resp, nil)
  65. return
  66. }
  67. func CertificateDel(c *gin.Context) {
  68. var req *md.CertificateDelReq
  69. if err := c.ShouldBindJSON(&req); err != nil {
  70. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  71. return
  72. }
  73. db.Db.In("id", req.Id).Delete(&model.UserCertificate{})
  74. e.OutSuc(c, "success", nil)
  75. return
  76. }
  77. func CertificateSave(c *gin.Context) {
  78. var req *md.CertificateSave
  79. if err := c.ShouldBindJSON(&req); err != nil {
  80. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  81. return
  82. }
  83. var data = new(model.UserCertificate)
  84. if utils.StrToInt(req.Id) > 0 {
  85. NewUserCertificateDb := implement.NewUserCertificateDb(db.Db)
  86. space, _ := NewUserCertificateDb.GetUserCertificateById(req.Id)
  87. if space == nil {
  88. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  89. return
  90. }
  91. data = space
  92. } else {
  93. data.Uid = utils.StrToInt(req.Uid)
  94. data.No = "DD" + utils.GenerateUniqueInvitationCode(12)
  95. data.No = check(1, data.No)
  96. db.Db.Insert(data)
  97. }
  98. data.Name = req.Name
  99. data.StartTime = req.StartTime
  100. data.EndTime = req.EndTime
  101. db.Db.Where("id=?", data.Id).Update(data)
  102. e.OutSuc(c, "success", nil)
  103. return
  104. }
  105. func check(num int, no string) string {
  106. NewUserCertificateDb := implement.NewUserCertificateDb(db.Db)
  107. space, _ := NewUserCertificateDb.GetUserCertificateByNo(no)
  108. if num >= 10 {
  109. return ""
  110. }
  111. if space != nil {
  112. no = "DD" + utils.GenerateUniqueInvitationCode(12)
  113. num++
  114. return check(num, no)
  115. }
  116. return no
  117. }