infolistlogic.go 3.9 KB

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