infolistlogic.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jyInfo/rpc/manager/internal/svc"
  4. "app.yhyue.com/moapp/jyInfo/rpc/manager/type/manager"
  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. "strings"
  12. "app.yhyue.com/moapp/jybase/common"
  13. "github.com/zeromicro/go-zero/core/logx"
  14. )
  15. type InfoListLogic struct {
  16. ctx context.Context
  17. svcCtx *svc.ServiceContext
  18. logx.Logger
  19. }
  20. func NewInfoListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoListLogic {
  21. return &InfoListLogic{
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. Logger: logx.WithContext(ctx),
  25. }
  26. }
  27. //InfoList 信息列表
  28. func (l *InfoListLogic) InfoList(in *manager.InfoListReq) (*manager.InfoListResp, error) {
  29. var (
  30. query []string
  31. queryInfo string
  32. count int64
  33. results []*manager.InfoList
  34. allData *[]map[string]interface{}
  35. )
  36. log.Println("管理平台信息发布列表查询参数:", in)
  37. if in.MsgType != 0 {
  38. query = append(query, `type=`+common.InterfaceToStr(in.MsgType)+` `)
  39. }
  40. if in.PhoneType != 0 {
  41. if in.PhoneType == 1 {
  42. query = append(query, ` phone LIKE '%`+in.Phone+`%' `)
  43. } else {
  44. query = append(query, ` contact_phone LIKE '%`+in.Phone+`%' `)
  45. }
  46. }
  47. if in.ApplyStartTime != "" {
  48. query = append(query, ` create_time >="`+in.ApplyStartTime+`"`)
  49. }
  50. if in.RecommendedService != 0 {
  51. query = append(query, ` recommended_service =`+common.InterfaceToStr(in.RecommendedService))
  52. }
  53. if in.JyPublishingMedia != 0 {
  54. query = append(query, ` publishing_media =`+common.InterfaceToStr(in.JyPublishingMedia))
  55. }
  56. if in.IsDel != 0 {
  57. query = append(query, ` is_del =`+common.InterfaceToStr(in.IsDel))
  58. }
  59. if in.Published != 0 {
  60. query = append(query, ` published =`+common.InterfaceToStr(in.Published))
  61. }
  62. if in.ApplyEndTime != "" {
  63. query = append(query, ` create_time <="`+in.ApplyEndTime+`"`)
  64. }
  65. if in.AppId != "" {
  66. query = append(query, ` app_id = `+util.StrFormat(in.AppId))
  67. }
  68. //supQuery := query
  69. if in.ReviewStatus != 0 {
  70. query = append(query, ` status =`+common.InterfaceToStr(in.ReviewStatus))
  71. //supQuery = append(supQuery, ` status =`+common.Str(in.ReviewStatus))
  72. }
  73. if len(query) > 0 {
  74. queryInfo = fmt.Sprintf(" where %s", strings.Join(query, " and "))
  75. //querySup = fmt.Sprintf(" where %s", strings.Join(supQuery, " and "))
  76. }
  77. if in.PageSize <= 0 {
  78. in.PageSize = 10
  79. }
  80. var offset int
  81. if in.PageIndex <= 1 {
  82. offset = 0
  83. } else {
  84. offset = common.IntAll((in.PageIndex - 1) * in.PageSize)
  85. }
  86. if in.RecommendedService != 0 || in.JyPublishingMedia != 0 {
  87. count = model.Mysql.CountBySql(`SELECT count(1) from information ` + queryInfo)
  88. allData = model.Mysql.SelectBySql(`SELECT id,type,status,phone,contact_person,contact_phone,title,create_time,is_del,published from information `+queryInfo+`
  89. order by create_time limit ?,? `, offset, in.PageSize)
  90. } else {
  91. count = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id,type,status,phone,contact_person,contact_phone,title,create_time,is_del,published from information ` + queryInfo + `
  92. union all
  93. SELECT id,type,status,phone,contact_person,contact_phone,title,create_time,is_del,published from supply_info ` + queryInfo + ` ) a`)
  94. allData = model.Mysql.SelectBySql(`SELECT * from (SELECT id,type,status,phone,contact_person,contact_phone,title,create_time,is_del,published from information `+queryInfo+`
  95. union all
  96. SELECT id,type,status,phone,contact_person,contact_phone,title,create_time,is_del,published from supply_info `+queryInfo+` ) a order by a.create_time limit ?,? `, offset, in.PageSize)
  97. }
  98. if allData != nil && len(*allData) > 0 {
  99. for _, v := range *allData {
  100. res := manager.InfoList{}
  101. var contact manager.Contact
  102. res.Id = se.SE.EncodeString(common.InterfaceToStr(v["id"])) //信息id加密
  103. res.Title = common.InterfaceToStr(v["title"])
  104. res.MsgType = common.Int64All(v["type"])
  105. res.Phone = common.InterfaceToStr(v["phone"])
  106. res.ReviewStatus = common.Int64All(v["status"])
  107. res.Published = common.Int64All(v["published"])
  108. res.IsDel = common.Int64All(v["is_del"])
  109. res.ApplyTime = common.InterfaceToStr(v["create_time"])
  110. contact.Name = common.InterfaceToStr(v["contact_person"])
  111. contact.Phone = common.InterfaceToStr(v["contact_phone"])
  112. res.Contact = &contact
  113. results = append(results, &res)
  114. }
  115. }
  116. data := manager.Data{}
  117. data.Count = count
  118. data.List = results
  119. return &manager.InfoListResp{
  120. ErrCode: 0,
  121. ErrMsg: "",
  122. Data: &data,
  123. }, nil
  124. }