mypublishlistlogic.go 5.0 KB

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