123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- package logic
- import (
- "context"
- "fmt"
- "io/ioutil"
- "jyInfo/rpc/consumer/consumer"
- "net/http"
- "app.yhyue.com/moapp/jybase/common"
- "jyInfo/api/internal/svc"
- "jyInfo/api/internal/types"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type PubSupplyInfoLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- r *http.Request
- }
- func NewPubSupplyInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext, r *http.Request) *PubSupplyInfoLogic {
- return &PubSupplyInfoLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- r: r,
- }
- }
- func (l *PubSupplyInfoLogic) PubSupplyInfo(req *types.PubInfoReq) (resp *types.CommonRes, err error) {
- err2 := l.r.ParseMultipartForm(50 * 1024 * 1024 * 1024)
- if err2 != nil {
- fmt.Println(err2)
- }
- fhs := l.r.MultipartForm.File["file"]
- var uploads []*consumer.InfoFileUploadResp
- var upload *consumer.InfoFileUploadResp
- attach := map[string]interface{}{}
- var err0 error
- if len(fhs) > 0 {
- for _, fheader := range fhs {
- file, err1 := fheader.Open()
- if err1 != nil {
- fmt.Println(err1)
- continue
- }
- defer file.Close()
- bt, _ := ioutil.ReadAll(file)
- upload, err0 = l.svcCtx.Consumer.InfoFileUpload(l.ctx, &consumer.InfoFileUploadReq{
- FileName: fheader.Filename,
- File: bt,
- FileSize: fheader.Size,
- })
- if err0 != nil {
- continue
- }
- uploads = append(uploads, upload)
- }
- for n, v := range uploads {
- attach[common.InterfaceToStr(n+1)] = v.Data
- }
- }
- var contact consumer.Contact
- contact.Person = req.ContactPerson
- contact.Phone = req.ContactPhone
- contact.Overt = req.ContactOvert
- pubinfo, err1 := l.svcCtx.Consumer.PublishInfo(l.ctx, &consumer.PublishInfoReq{
- UserId: req.UserId,
- EntId: req.EntId,
- Title: req.Title,
- MsgType: req.MsgType,
- RelatedId: req.RelatedId,
- Code: req.Code,
- Province: req.Province,
- City: req.City,
- Industry: req.Industry,
- Buyer: req.Buyer,
- Budget: common.Float64All(req.Budget),
- Winner: req.Winner,
- Amount: common.Float64All(req.Amount),
- Detail: req.Detail,
- Attach: common.MapToJson(req.Attach),
- Contact: &contact,
- AppId: common.Int64All(req.AppId),
- Phone: req.Phone,
- Deadline: req.ValidityTime,
- })
- if err1 != nil {
- return &types.CommonRes{
- Err_code: -1,
- Err_msg: "错误",
- Data: nil,
- }, nil
- }
- return &types.CommonRes{
- Err_code: common.IntAll(pubinfo.ErrCode),
- Err_msg: pubinfo.ErrMsg,
- Data: pubinfo.PublishId,
- }, nil
- }
|