package api import ( "encoding/json" "fmt" "github.com/jmoiron/sqlx" "github.com/pkg/errors" "kpt.xdmy/apiserver/model" "kpt.xdmy/apiserver/model/http" "kpt.xdmy/apiserver/service" "kpt.xdmy/pkg/log" ) var svc *service.Service func Init(s *service.Service) { svc = s } type nextServiceInfo struct { laidType int64 useType int64 } func NextService(p []map[string]interface{}, tx *sqlx.Tx, vendor int64) error { isTransfer := false for _, v := range p { if v["name"] == nil || v["parammaps"] == nil { continue } sqlname := v["name"].(string) if sqlname == "updateBigPartTransfer" { isTransfer = true } else if sqlname == "insertBigPartUse" { pf := v["parammaps"].(map[string]interface{}) if pf["useType"].(float64) != 5 { if _, ok := pf["oddCode"]; !ok { return errors.New("oddCode 不能为空 !!!") } } } } if isTransfer { var bigPartTransferid float64 insertBigPartlaid := false for _, v := range p { if v["name"] == nil || v["parammaps"] == nil { continue } pf := v["parammaps"].(map[string]interface{}) sqlname := v["name"].(string) if sqlname == "updateBigPartTransfer" { bigPartTransferid = pf["id"].(float64) } else if sqlname == "insertBigPartlaid" { insertBigPartlaid = true } } if bigPartTransferid > 0 && insertBigPartlaid { //if laidType == 2 { partTransfer := make([]*model.PartTransferStr, 0) partsByte, err := service.GetDataList(tx, `select * from parttransfer where bigid = ? `, []interface{}{bigPartTransferid}) if err != nil { return errors.New("无调拨信息!!!") } if partsByte != nil { err := json.Unmarshal(partsByte, &partTransfer) if err != nil { return errors.New("调拨信息转码出错!!!") } } for _, part := range partTransfer { prByte, err := service.MapStr(tx, `select * from part_repertory where id = ? and reportery >= ? `, part.PartRepID, part.Amount) if err != nil { return errors.New("库存信息出错!!!") } if prByte != nil { data := make(map[string]interface{}) err := json.Unmarshal(prByte, &data) if err != nil { return errors.New("库存信息出错!!!") } if _, ok := data["id"]; !ok { return errors.New("库存信息出错!!!") } } else { return errors.New("库存信息出错!!!") } _, err = tx.Exec(` update part_repertory set reportery = reportery - ? where id = ? `, part.Amount, part.PartRepID) if err != nil { return errors.New("库存调整出错!!!") } } if vendor == 1 { err = service.ManualTransfer(bigPartTransferid, tx) if err != nil { return err } } } } else if vendor == 1 { for _, v := range p { if v["name"] == nil || v["parammaps"] == nil { continue } pf := v["parammaps"].(map[string]interface{}) sqlname := v["name"].(string) fmt.Println(sqlname) switch sqlname { case "insertBigPartlaid": laidType := pf["laidType"].(float64) log.Info(v) //b, _ := json.Marshal(p) //pnext := new(nextServiceInfo) //json.Unmarshal(b, &pnext) //switch pnext.laidType { //手动出库没有采购单号,所以不能传SAP //case 0: // 入库-申购、采购(申购、线上、寄售) if laidType != 2 { pr := new(http.ProofPartReq) pr.LaidCode = pf["laidCode"].(string) pr.StorageTime = pf["storageTime"].(string) err := svc.LaidProof(pr, tx) if err != nil { return err } } case "insertBigPartUse": //b, _ := json.Marshal(p) //pnext := new(nextServiceInfo) //json.Unmarshal(b, &pnext) log.Info(v) pr := new(http.ProofPartReq) pr.UseForm = pf["useForm"].(string) pr.StorageTime = pf["receiveTime"].(string) err := svc.UseProof(pf, tx) if err != nil { return err } //} case "updatePartRepertoryTHS": log.Info(v) // 退货 err := svc.RefundProof(pf, tx) if err != nil { return err } case "insertBigPartquit": log.Info(v) // 退库 err := svc.QuitProof(pf, tx) if err != nil { return err } } } } return nil }