mypublishlistlogic.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package logic
  2. import (
  3. se "app.yhyue.com/moapp/jybase/encrypt"
  4. "context"
  5. "jyInfo/rpc/consumer/consumer"
  6. "jyInfo/rpc/consumer/internal/svc"
  7. "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. quryName string
  28. data consumer.MyPublishListResp
  29. amount, inReview, approved, auditFailed, total int64
  30. ListData consumer.MyPublishListData
  31. )
  32. if in.Match != "" {
  33. quryName = ` and title LIKE '%` + in.Match + `%' `
  34. }
  35. if in.MsgType != 0 {
  36. quryName = quryName + ` and type=` + mc.InterfaceToStr(in.MsgType)
  37. }
  38. if in.PageIndex == 1 {
  39. //全部
  40. amount = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryName + `
  41. union all
  42. SELECT id from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryName + `) a`)
  43. //审核中
  44. inReview = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryName + ` and status in (0,1,2,3,4) and published = 1
  45. union all
  46. SELECT id from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryName + ` and status in (0,1,2,3,4) and published = 1) a`)
  47. //审核通过
  48. approved = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryName + ` and published = 2
  49. union all
  50. SELECT id from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryName + ` and published = 2) a`)
  51. //审核不通过
  52. auditFailed = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryName + ` and status in (-1,-2) and published = 1` + `
  53. union all
  54. SELECT id from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryName + ` and status in (-1,-2) and published = 1) a`)
  55. }
  56. if in.ReviewStatus != 0 {
  57. if in.ReviewStatus == 1 {
  58. quryName = quryName + ` and status in (0,1,2,3,4) and published = 1`
  59. } else if in.ReviewStatus == 2 {
  60. quryName = quryName + ` and published = 2`
  61. } else if in.ReviewStatus == 3 {
  62. quryName = quryName + ` and status in (-1,-2)`
  63. }
  64. }
  65. if in.PageSize <= 0 {
  66. in.PageSize = 10
  67. }
  68. var offset int
  69. if in.PageIndex <= 1 {
  70. offset = 0
  71. } else {
  72. offset = mc.IntAll((in.PageIndex - 1) * in.PageSize)
  73. }
  74. if in.PageIndex == 1 {
  75. 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 + `" ` + quryName + `
  76. union all
  77. SELECT id,type,title,create_time,status,published from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + quryName + ` ) a`)
  78. total = mc.Int64All(mc.MathCeil(mc.Float64All(count) / mc.Float64All(in.PageSize)))
  79. }
  80. 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+`" `+quryName+`
  81. union all
  82. SELECT id,type,title,create_time,status,published from supply_info WHERE is_del = 1 and user_id= "`+in.UserId+`" `+quryName+` ) a order by a.create_time desc limit ?,?`, offset, in.PageSize)
  83. if allData != nil && len(*allData) > 0 {
  84. for _, v := range *allData {
  85. var vs = consumer.ListResp{}
  86. vs.Id = se.SE.EncodeString(mc.InterfaceToStr(v["id"])) //信息id加密
  87. vs.ReviewStatus = 1
  88. status := mc.IntAll(v["status"])
  89. published := mc.IntAll(v["published"])
  90. //1 审核中 2 已发布(审核通过)3 status(-1,-2) 审核不通过
  91. if published == 2 {
  92. vs.ReviewStatus = 2
  93. } else if status == -2 || status == -1 {
  94. vs.ReviewStatus = 3
  95. }
  96. ListData.Total = total
  97. vs.MsgType = mc.Int64All(v["type"])
  98. vs.CreateTime = mc.InterfaceToStr(v["create_time"])
  99. vs.Title = mc.InterfaceToStr(v["title"])
  100. ListData.List = append(ListData.List, &vs)
  101. }
  102. }
  103. ListData.Amount = amount
  104. ListData.Approved = approved
  105. ListData.InReview = inReview
  106. ListData.AuditFailed = auditFailed
  107. data.Results = &ListData
  108. return &data, nil
  109. }