inforelatedlogic.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. queryName = ` and type=` + mc.InterfaceToStr(in.MsgType)
  34. if in.AppId != "" {
  35. queryName = queryName + ` and app_id = ` + util.StrFormat(in.AppId)
  36. }
  37. if in.EntId != 0 {
  38. queryName = queryName + ` and ent_id = ` + mc.InterfaceToStr(in.EntId)
  39. }
  40. switch in.MsgId {
  41. case 0:
  42. if in.Match != "" {
  43. queryName = 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. var allData *[]map[string]interface{}
  61. switch in.MsgType {
  62. case 1, 2, 4, 5, 6:
  63. allData = model.Mysql.SelectBySql(`SELECT * from information WHERE user_id="` + in.UserId + `"` + queryName + ` order by create_time desc limit 1`)
  64. case 3:
  65. allData = model.Mysql.SelectBySql(`SELECT * from supply_info WHERE user_id="` + in.UserId + `"` + queryName + ` order by create_time desc limit 1`)
  66. }
  67. if allData == nil || len(*allData) == 0 {
  68. return &resp, nil
  69. }
  70. for _, v := range *allData {
  71. var data consumerinfo.InfoData
  72. data.Id = se.SE.EncodeString(mc.InterfaceToStr(v["id"])) //关联信息加密
  73. data.Title = mc.InterfaceToStr(v["title"])
  74. data.Person = mc.InterfaceToStr(v["contact_person"])
  75. data.Phone = mc.InterfaceToStr(v["contact_phone"])
  76. data.Overt = mc.Int64All(v["contact_overt"])
  77. data.RecommendedService = mc.Int64All(v["recommended_service"])
  78. resp.Data = append(resp.Data, &data)
  79. }
  80. }
  81. return &resp, nil
  82. }