supplyinfodetaillogic.go 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. var conctact consumerinfo.InfoDetailContact
  48. conctact.Phone = mc.If(mc.Int64All((*data)["contact_overt"]) == 1, mc.InterfaceToStr((*data)["contact_phone"]), "").(string)
  49. conctact.Name = mc.InterfaceToStr((*data)["contact_person"])
  50. conctact.Overt = mc.Int64All((*data)["contact_overt"])
  51. info.InfoDetailContact = &conctact
  52. info.Attach = astr
  53. info.EntId = mc.Int64All((*data)["ent_id"])
  54. info.Id = in.MsgId
  55. //其他供应信息
  56. otherData := es.GetSupplyOtherInfoByEntid(mc.InterfaceToStr(info.EntId), 5)
  57. if otherData != nil && len(*otherData) > 0 {
  58. for _, v := range *otherData {
  59. if info.Id == se.SE.EncodeString(mc.InterfaceToStr(v["_id"])) {
  60. continue
  61. }
  62. otherSupplyInfo := consumerinfo.OtherSupplyInfoByEnt{
  63. Title: mc.InterfaceToStr(v["title"]),
  64. Id: se.SE.EncodeString(mc.InterfaceToStr(v["_id"])),
  65. Province: mc.InterfaceToStr(v["province"]),
  66. City: mc.InterfaceToStr(v["city"]),
  67. PublishTime: strconv.FormatInt(mc.Int64All(v["publish_time"]), 10),
  68. CreateTime: strconv.FormatInt(mc.Int64All(v["create_time"]), 10),
  69. EntId: mc.Int64All(v["ent_id"]),
  70. }
  71. info.OtherSupplyInfo = append(info.OtherSupplyInfo, &otherSupplyInfo)
  72. }
  73. }
  74. log.Println(len(*otherData), "otherData:", info.OtherSupplyInfo)
  75. resp.Data = &info
  76. return &resp, nil
  77. }
  78. resp.ErrCode = -1
  79. resp.ErrMsg = "未查询到相关数据"
  80. resp.Data = nil
  81. return &resp, nil
  82. }
  83. return &consumerinfo.SupplyInfoDetailResp{}, nil
  84. }