supplyinfodetaillogic.go 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jyInfo/rpc/model"
  4. es "app.yhyue.com/moapp/jyInfo/rpc/model/es"
  5. se "app.yhyue.com/moapp/jybase/encrypt"
  6. "context"
  7. "log"
  8. "regexp"
  9. "strconv"
  10. "app.yhyue.com/moapp/jyInfo/rpc/consumer/consumerinfo"
  11. "app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc"
  12. mc "app.yhyue.com/moapp/jybase/common"
  13. "github.com/zeromicro/go-zero/core/logx"
  14. )
  15. type SupplyInfoDetailLogic struct {
  16. ctx context.Context
  17. svcCtx *svc.ServiceContext
  18. logx.Logger
  19. }
  20. func NewSupplyInfoDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SupplyInfoDetailLogic {
  21. return &SupplyInfoDetailLogic{
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. Logger: logx.WithContext(ctx),
  25. }
  26. }
  27. // 供应信息详情
  28. func (l *SupplyInfoDetailLogic) SupplyInfoDetail(in *consumerinfo.StatusReq) (*consumerinfo.SupplyInfoDetailResp, error) {
  29. var resp consumerinfo.SupplyInfoDetailResp
  30. msgId := se.SE.DecodeString(in.MsgId) //信息id解密
  31. logx.Info(msgId, "-------msgid:", in.MsgId)
  32. if in.Type == 0 {
  33. data := model.Mysql.FindOne("supply_info", map[string]interface{}{"id": msgId}, "", "")
  34. if *data != nil {
  35. astr := mc.InterfaceToStr((*data)["attach"])
  36. regfid := regexp.MustCompile(`"fid":".*?",`)
  37. regoss := regexp.MustCompile(`"ossurl":".*?",`)
  38. astr = regfid.ReplaceAllString(astr, "")
  39. astr = regoss.ReplaceAllString(astr, "")
  40. var info consumerinfo.SupplyInfoDetailData
  41. info.Title = mc.InterfaceToStr((*data)["title"])
  42. info.Detail = mc.InterfaceToStr((*data)["detail"])
  43. info.PublishTime = mc.InterfaceToStr((*data)["publish_time"])
  44. info.ValidityTime = mc.InterfaceToStr((*data)["validity_time"])
  45. info.Province = mc.InterfaceToStr((*data)["province"])
  46. info.City = mc.InterfaceToStr((*data)["city"])
  47. info.EntName = mc.InterfaceToStr((*data)["ent_name"])
  48. var conctact consumerinfo.InfoDetailContact
  49. conctact.Phone = mc.If(mc.Int64All((*data)["contact_overt"]) == 1, mc.InterfaceToStr((*data)["contact_phone"]), "").(string)
  50. conctact.Name = mc.InterfaceToStr((*data)["contact_person"])
  51. conctact.Overt = mc.Int64All((*data)["contact_overt"])
  52. info.InfoDetailContact = &conctact
  53. info.Attach = astr
  54. info.EntId = se.SE.Encode2HexByCheck(mc.InterfaceToStr((*data)["ent_id"]))
  55. info.Id = in.MsgId
  56. //其他供应信息
  57. otherData := es.GetSupplyOtherInfoByEntid(mc.InterfaceToStr((*data)["ent_id"]), 6)
  58. if otherData != nil && len(*otherData) > 0 {
  59. for _, v := range *otherData {
  60. if info.Id == se.SE.EncodeString(mc.InterfaceToStr(v["_id"])) {
  61. continue
  62. }
  63. if len(info.OtherSupplyInfo) >= 5 {
  64. break
  65. }
  66. otherSupplyInfo := consumerinfo.OtherSupplyInfoByEnt{
  67. Title: mc.InterfaceToStr(v["title"]),
  68. Id: se.SE.EncodeString(mc.InterfaceToStr(v["_id"])),
  69. Province: mc.InterfaceToStr(v["province"]),
  70. City: mc.InterfaceToStr(v["city"]),
  71. PublishTime: strconv.FormatInt(mc.Int64All(v["publish_time"]), 10),
  72. CreateTime: strconv.FormatInt(mc.Int64All(v["create_time"]), 10),
  73. EntId: se.SE.Encode2HexByCheck(mc.InterfaceToStr(v["ent_id"])),
  74. }
  75. info.OtherSupplyInfo = append(info.OtherSupplyInfo, &otherSupplyInfo)
  76. }
  77. }
  78. log.Println(len(*otherData), "otherData:", info.OtherSupplyInfo)
  79. resp.Data = &info
  80. return &resp, nil
  81. }
  82. resp.ErrCode = -1
  83. resp.ErrMsg = "未查询到相关数据"
  84. resp.Data = nil
  85. return &resp, nil
  86. }
  87. return &consumerinfo.SupplyInfoDetailResp{}, nil
  88. }