mypublishlistlogic.go 5.5 KB

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