infolistlogic.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.IsDel != 0 {
  48. query = append(query, ` is_del =`+common.InterfaceToStr(in.IsDel))
  49. }
  50. if in.Published != 0 {
  51. query = append(query, ` published =`+common.InterfaceToStr(in.Published))
  52. }
  53. if in.ApplyEndTime != "" {
  54. query = append(query, ` create_time <="`+in.ApplyEndTime+`"`)
  55. }
  56. if in.AppId != "" {
  57. query = append(query, ` app_id = `+util.StrFormat(in.AppId))
  58. }
  59. //supQuery := query
  60. if in.ReviewStatus != 0 {
  61. query = append(query, ` status =`+common.InterfaceToStr(in.ReviewStatus))
  62. //supQuery = append(supQuery, ` status =`+common.Str(in.ReviewStatus))
  63. }
  64. if len(query) > 0 {
  65. queryInfo = fmt.Sprintf(" where %s", strings.Join(query, " and "))
  66. //querySup = fmt.Sprintf(" where %s", strings.Join(supQuery, " and "))
  67. }
  68. if in.PageSize <= 0 {
  69. in.PageSize = 10
  70. }
  71. 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 + `
  72. union all
  73. SELECT id,type,status,phone,contact_person,contact_phone,title,create_time,is_del,published from supply_info ` + queryInfo + ` ) a`)
  74. var offset int
  75. if in.PageIndex <= 1 {
  76. offset = 0
  77. } else {
  78. offset = common.IntAll((in.PageIndex - 1) * in.PageSize)
  79. }
  80. allData := model.Mysql.SelectBySql(`SELECT * from (SELECT id,type,status,phone,contact_person,contact_phone,title,create_time,is_del,published from information `+queryInfo+`
  81. union all
  82. 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)
  83. if allData != nil && len(*allData) > 0 {
  84. for _, v := range *allData {
  85. res := manager.InfoList{}
  86. var contact manager.Contact
  87. res.Id = se.SE.EncodeString(common.InterfaceToStr(v["id"])) //信息id加密
  88. res.Title = common.InterfaceToStr(v["title"])
  89. res.MsgType = common.Int64All(v["type"])
  90. res.Phone = common.InterfaceToStr(v["phone"])
  91. res.ReviewStatus = common.Int64All(v["status"])
  92. res.Published = common.Int64All(v["published"])
  93. res.IsDel = common.Int64All(v["is_del"])
  94. res.ApplyTime = common.InterfaceToStr(v["create_time"])
  95. contact.Name = common.InterfaceToStr(v["contact_person"])
  96. contact.Phone = common.InterfaceToStr(v["contact_phone"])
  97. res.Contact = &contact
  98. results = append(results, &res)
  99. }
  100. }
  101. data := manager.Data{}
  102. data.Count = count
  103. data.List = results
  104. return &manager.InfoListResp{
  105. ErrCode: 0,
  106. ErrMsg: "",
  107. Data: &data,
  108. }, nil
  109. }