package http import ( "time" "github.com/pkg/errors" "kpt.xdmy/apiserver/dao" "kpt.xdmy/apiserver/model" "kpt.xdmy/pkg/log" "kpt.xdmy/pkg/util" ) type OrderResp struct { Dest `json:"DEST"` Data OrderRespData `json:"DATA"` } type OrderRespData struct { Status string `json:"MSGTY"` MsgText string `json:"MSGTX"` EqNumber string `json:"EXT01"` SapNumber string `json:"EXT02"` } type OrderReq struct { Dest `json:"DEST"` Data Order `json:"DATA"` } type Order struct { CompanyCode string `json:"BUKRS"` // 公司代码 SupplierCode string `json:"LIFNR"` // 供应商编码 IsCancle string `json:"ZKHFLG"` // 是否退货 "是:X ProofType string `json:"BSART"` // 采购凭证类型 字典 OrderDate string `json:"BEDAT"` // 订单日期 Organization string `json:"EKORG"` // 采购组织 字典 Group string `json:"EKGRP"` // 采购组 字典 PayCondition string `json:"ZTERM"` // 付款条件 字典 CurrencyCode string `json:"WAERS"` // 货币码 默认:CNY EqSysCode string `json:"ZEBELN"` // 订单编号 Detail []OrderDetail `json:"TEKPO"` } type OrderDetail struct { IsOwn string `json:"PSTYP"` // 自有订单,"自有:空// 寄售:'K' " MaterialCode string `json:"MATNR"` //物料编码 Quantity string `json:"MENGE"` // 数量 DeliveryDate string `json:"EINDT"` // 交货日期 Unit string `json:"MEINS"` // 单位 NetPrice string `json:"NETPR"` // 净价 Per string `json:"PEINH"` // 每 默认:1 Factory string `json:"WERKS"` // 工厂 Location string `json:"LGORT"` //库存地点 字典 IsFree string `json:"UMSON"` //是否免费 "是:X TaxCode string `json:"MWSKZ"` // 税码 字典 RowNumber string `json:"EBELP"` //行号 Dflag string `json:"LOEKZ"` // 删除标识 "是:L// 否:空" } func (o *OrderReq) NewReq(p *model.BigBuyDetail) (e error) { path := "http OrderReq NewReq" o.Dest = Dest{ DestID: "EQMAN", BussTp: "MM007", Url: "https://app.modernfarming.cn:7443/sap/Common/MM007/PurchaseOrder", } pv := &model.Provider{ID: p.ProviderID} ps := &model.Pasture{ID: p.PastureID} bds := make([]model.BuyDetail, 0) c := util.NewMap("bigid", p.ID) sl := make([]OrderDetail, 0) if e = model.First(pv); e != nil { log.Printf("%s:采购订单供应商查不到", path) return } if e = model.First(ps); e != nil { log.Printf("%s:采购订单牧场查不到", path) return } model.Find(c, &bds) if len(bds) == 0 { e = errors.Errorf("%s:采购订单明细查询为空", path) log.Print(e.Error()) return } o.Data = Order{ IsCancle: "", SupplierCode: "100224", OrderDate: p.BuyerDate.Format("20060102"), PayCondition: "", CompanyCode: "1004", CurrencyCode: "CNY", ProofType: "ZNB4", EqSysCode: p.BuyeCode[4:], // EqSysCode: "A0001", Organization: "9099", Group: "A02", // CompanyCode: ps.PastureNumber, // SupplierCode: pv.ProviderNumber, // OrderDate: p.BuyerDate.Format("20060102"), } for _, v := range bds { dao.D.DB.Raw(`SELECT p.partcode from parts p join contract c on c.partid=p.id where c.id=?`, v.ContractID).Scan(&v.PartCode) pd := OrderDetail{ // Quantity: v.Amount, // DeliveryDate: v.ReceiveDate.Format("20060102"), // IsOwn: util.ZeroStr(c.IsZeroStock == 1, "K"), // NetPrice: v.Price, // Unit: ps.Unit, // Factory: p.Data.CompanyCode, // Location: "", // IsFree: "", MaterialCode: v.PartCode, // MaterialCode: "14.01.07.01.000243", Quantity: "11", DeliveryDate: p.BuyerDate.Add(time.Hour * 24 * 7).Format("20060102"), Unit: "EA", NetPrice: "11", Per: "1", Factory: "M001", TaxCode: "J0", RowNumber: "10", } sl = append(sl, pd) } o.Data.Detail = sl return }