mypublishlistlogic.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package logic
  2. import (
  3. se "app.yhyue.com/moapp/jybase/encrypt"
  4. "context"
  5. "app.yhyue.com/moapp/jyInfo/rpc/consumer/consumer"
  6. "app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc"
  7. "app.yhyue.com/moapp/jyInfo/rpc/model"
  8. mc "app.yhyue.com/moapp/jybase/common"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type MyPublishListLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewMyPublishListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MyPublishListLogic {
  17. return &MyPublishListLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. // MyPublishList 我的发布列表
  24. func (l *MyPublishListLogic) MyPublishList(in *consumer.MyPublishListReq) (*consumer.MyPublishListResp, error) {
  25. // todo: add your logic here and delete this line
  26. var (
  27. queryName string
  28. data consumer.MyPublishListResp
  29. amount, inReview, approved, auditFailed, total int64
  30. ListData consumer.MyPublishListData
  31. )
  32. if in.Match != "" {
  33. queryName = ` and title LIKE '%` + in.Match + `%' `
  34. }
  35. if in.MsgType != 0 {
  36. queryName = queryName + ` and type=` + mc.InterfaceToStr(in.MsgType)
  37. }
  38. if in.AppId != "" {
  39. queryName = queryName + ` and app_id = "` + in.AppId + `"`
  40. }
  41. if in.PageIndex == 1 {
  42. //全部
  43. amount = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + `
  44. union all
  45. SELECT id from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + `) a`)
  46. //审核中
  47. inReview = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` and status in (0,1,2,3,4) and published = 1
  48. union all
  49. SELECT id from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` and status in (0,1,2,3,4) and published = 1) a`)
  50. //审核通过
  51. approved = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` and published = 2
  52. union all
  53. SELECT id from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` and published = 2) a`)
  54. //审核不通过
  55. auditFailed = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` and status in (-1,-2) and published = 1` + `
  56. union all
  57. SELECT id from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` and status in (-1,-2) and published = 1) a`)
  58. }
  59. if in.ReviewStatus != 0 {
  60. if in.ReviewStatus == 1 {
  61. queryName = queryName + ` and status in (0,1,2,3,4) and published = 1`
  62. } else if in.ReviewStatus == 2 {
  63. queryName = queryName + ` and published = 2`
  64. } else if in.ReviewStatus == 3 {
  65. queryName = queryName + ` and status in (-1,-2)`
  66. }
  67. }
  68. if in.PageSize <= 0 {
  69. in.PageSize = 10
  70. }
  71. var offset int
  72. if in.PageIndex <= 1 {
  73. offset = 0
  74. } else {
  75. offset = mc.IntAll((in.PageIndex - 1) * in.PageSize)
  76. }
  77. if in.PageIndex == 1 {
  78. count := model.Mysql.CountBySql(`SELECT count(1) from (SELECT id,type,title,create_time,status,published from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + `
  79. union all
  80. SELECT id,type,title,create_time,status,published from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` ) a`)
  81. total = mc.Int64All(mc.MathCeil(mc.Float64All(count) / mc.Float64All(in.PageSize)))
  82. }
  83. allData := model.Mysql.SelectBySql(`SELECT a.id,a.type,a.title,a.create_time,a.published,a.status from (SELECT id,type,title,create_time,status,published from information WHERE is_del = 1 and user_id= "`+in.UserId+`" `+queryName+`
  84. union all
  85. SELECT id,type,title,create_time,status,published from supply_info WHERE is_del = 1 and user_id= "`+in.UserId+`" `+queryName+` ) a order by a.create_time desc limit ?,?`, offset, in.PageSize)
  86. if allData != nil && len(*allData) > 0 {
  87. for _, v := range *allData {
  88. var vs = consumer.ListResp{}
  89. vs.Id = se.SE.EncodeString(mc.InterfaceToStr(v["id"])) //信息id加密
  90. vs.ReviewStatus = 1
  91. status := mc.IntAll(v["status"])
  92. published := mc.IntAll(v["published"])
  93. //1 审核中 2 已发布(审核通过)3 status(-1,-2) 审核不通过
  94. if published == 2 {
  95. vs.ReviewStatus = 2
  96. } else if status == -2 || status == -1 {
  97. vs.ReviewStatus = 3
  98. }
  99. ListData.Total = total
  100. vs.MsgType = mc.Int64All(v["type"])
  101. vs.CreateTime = mc.InterfaceToStr(v["create_time"])
  102. vs.Title = mc.InterfaceToStr(v["title"])
  103. ListData.List = append(ListData.List, &vs)
  104. }
  105. }
  106. ListData.Amount = amount
  107. ListData.Approved = approved
  108. ListData.InReview = inReview
  109. ListData.AuditFailed = auditFailed
  110. data.Results = &ListData
  111. return &data, nil
  112. }