inforelatedlogic.go 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 InfoRelatedLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewInfoRelatedLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoRelatedLogic {
  19. return &InfoRelatedLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. // 关联公告
  26. func (l *InfoRelatedLogic) InfoRelated(in *consumerinfo.UserIdReq) (*consumerinfo.InfoRelatedResp, error) {
  27. // todo: add your logic here and delete this line
  28. var (
  29. queryName string
  30. resp consumerinfo.InfoRelatedResp
  31. )
  32. log.Println("关联公告接口调用", in)
  33. if in.AppId != "" {
  34. queryName += ` and app_id = ` + util.StrFormat(in.AppId)
  35. }
  36. if in.EntId != 0 {
  37. queryName += ` and ent_id = ` + mc.InterfaceToStr(in.EntId)
  38. }
  39. switch in.MsgId {
  40. case 0:
  41. queryName += ` and type=` + mc.InterfaceToStr(in.MsgType)
  42. if in.Match != "" {
  43. queryName += ` and title LIKE '%` + in.Match + `%' `
  44. }
  45. allData := model.Mysql.SelectBySql(`SELECT * from information WHERE user_id="` + in.UserId + `" and published=2 and is_del=1` + queryName + ` order by create_time desc limit 50`)
  46. if allData == nil || len(*allData) == 0 {
  47. return &resp, nil
  48. }
  49. for _, v := range *allData {
  50. var data consumerinfo.InfoData
  51. data.Id = se.SE.EncodeString(mc.InterfaceToStr(v["id"])) //关联信息加密
  52. data.Title = mc.InterfaceToStr(v["title"])
  53. data.Person = mc.InterfaceToStr(v["contact_person"])
  54. data.Phone = mc.InterfaceToStr(v["contact_phone"])
  55. data.Overt = mc.Int64All(v["contact_overt"])
  56. data.RecommendedService = mc.Int64All(v["recommended_service"])
  57. resp.Data = append(resp.Data, &data)
  58. }
  59. case 1:
  60. allData := model.Mysql.SelectBySql(`SELECT a.id,a.title,a.create_time,a.contact_person,a.contact_phone,a.contact_overt from (SELECT id,title,create_time,contact_person,contact_phone,contact_overt from information WHERE user_id= "` + in.UserId + `"
  61. union all
  62. SELECT id,title,create_time,contact_person,contact_phone,contact_overt from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ) a order by a.create_time desc limit 1`)
  63. oneData := model.Mysql.SelectBySql(`SELECT * from information WHERE user_id="` + in.UserId + `" order by create_time desc limit 1`)
  64. if allData == nil || len(*allData) == 0 {
  65. return &resp, nil
  66. }
  67. for _, v := range *allData {
  68. var data consumerinfo.InfoData
  69. data.Id = se.SE.EncodeString(mc.InterfaceToStr(v["id"])) //关联信息加密
  70. data.Title = mc.InterfaceToStr(v["title"])
  71. data.Person = mc.InterfaceToStr(v["contact_person"])
  72. data.Phone = mc.InterfaceToStr(v["contact_phone"])
  73. data.Overt = mc.Int64All(v["contact_overt"])
  74. if oneData != nil && len(*oneData) > 0 {
  75. data.RecommendedService = mc.Int64All((*oneData)[0]["recommended_service"])
  76. }
  77. resp.Data = append(resp.Data, &data)
  78. }
  79. }
  80. return &resp, nil
  81. }