pubinfologic.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package logic
  2. import (
  3. "context"
  4. "fmt"
  5. "io/ioutil"
  6. "jyInfo/rpc/consumer/consumer"
  7. "net/http"
  8. "app.yhyue.com/moapp/jybase/common"
  9. "jyInfo/api/internal/svc"
  10. "jyInfo/api/internal/types"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type PubInfoLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. r *http.Request
  18. }
  19. func NewPubInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext, r *http.Request) *PubInfoLogic {
  20. return &PubInfoLogic{
  21. Logger: logx.WithContext(ctx),
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. r: r,
  25. }
  26. }
  27. func (l *PubInfoLogic) PubInfo(req *types.PubInfoReq) (resp *types.CommonRes, err error) {
  28. err2 := l.r.ParseMultipartForm(50 * 1024 * 1024 * 1024)
  29. if err2 != nil {
  30. fmt.Println(err2)
  31. }
  32. fhs := l.r.MultipartForm.File["file"]
  33. var uploads []*consumer.InfoFileUploadResp
  34. var upload *consumer.InfoFileUploadResp
  35. attach := map[string]interface{}{}
  36. var err0 error
  37. if len(fhs) > 0 {
  38. for _, fheader := range fhs {
  39. file, err1 := fheader.Open()
  40. if err1 != nil {
  41. fmt.Println(err1)
  42. continue
  43. }
  44. defer file.Close()
  45. bt, _ := ioutil.ReadAll(file)
  46. upload, err0 = l.svcCtx.Consumer.InfoFileUpload(l.ctx, &consumer.InfoFileUploadReq{
  47. FileName: fheader.Filename,
  48. File: bt,
  49. FileSize: fheader.Size,
  50. })
  51. if err0 != nil {
  52. continue
  53. }
  54. uploads = append(uploads, upload)
  55. }
  56. for n, v := range uploads {
  57. attach[common.InterfaceToStr(n+1)] = v.Data
  58. }
  59. }
  60. var contact consumer.Contact
  61. //contact.Person = req.Contact.Person
  62. //contact.Phone = req.Contact.Phone
  63. //contact.Overt = req.Contact.Overt
  64. contact.Person = req.ContactPerson
  65. contact.Phone = req.ContactPhone
  66. contact.Overt = req.ContactOvert
  67. pubinfo, err1 := l.svcCtx.Consumer.PublishInfo(l.ctx, &consumer.PublishInfoReq{
  68. UserId: req.UserId,
  69. EntId: req.EntId,
  70. Title: req.Title,
  71. MsgType: req.MsgType,
  72. RelatedId: req.RelatedId,
  73. Code: req.Code,
  74. Province: req.Province,
  75. City: req.City,
  76. Industry: req.Industry,
  77. Buyer: req.Buyer,
  78. Budget: common.Float64All(req.Budget),
  79. Winner: req.Winner,
  80. Amount: common.Float64All(req.Amount),
  81. Detail: req.Detail,
  82. Attach: common.MapToJson(attach),
  83. Contact: &contact,
  84. AppId: common.Int64All(req.AppId),
  85. Phone: req.Phone,
  86. })
  87. if err1 != nil {
  88. return &types.CommonRes{
  89. Err_code: -1,
  90. Err_msg: "错误",
  91. Data: nil,
  92. }, nil
  93. }
  94. return &types.CommonRes{
  95. Err_code: common.IntAll(pubinfo.ErrCode),
  96. Err_msg: pubinfo.ErrMsg,
  97. Data: pubinfo.PublishId,
  98. }, nil
  99. }