mypublishlistlogic.go 4.9 KB

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