| | |
| | | "errors" |
| | | "fmt" |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | | "strconv" |
| | | "strings" |
| | | "time" |
| | |
| | | operation.ReceiverPhone = req.Phone |
| | | operation.ReceiverAddr = req.Address |
| | | operation.Source = req.Source |
| | | operation.CompanyID = int(req.ClientId) |
| | | operation.OperationSource = constvar.OperationSource(req.OperationSource) |
| | | operation.CompanyID = strconv.FormatInt(req.ClientId, 10) |
| | | operation.CompanyName = req.ClientName |
| | | if req.DeliverType == 1 { |
| | | for _, product := range req.ProductList { |
| | |
| | | "wms_operation.number,wms_operation.waybill_number, logistic_company.name, wms_operation.base_operation_type, wms_operation.status, wms_operation.created_at"). |
| | | Joins("left join wms_operation on wms_operation.id = wms_operation_details.operation_id"). |
| | | Joins("left join logistic_company on logistic_company.id = wms_operation.logistic_company_id"). |
| | | Where("wms_operation.source_number = ?", req.Number). |
| | | Where("wms_operation.sales_details_number = ?", req.Number). |
| | | Where("wms_operation.base_operation_type in ?", []constvar.BaseOperationType{ |
| | | constvar.BaseOperationTypeIncoming, constvar.BaseOperationTypeOutgoing}). |
| | | Where("wms_operation.status in ?", []constvar.OperationStatus{constvar.OperationStatus_Ready, constvar.OperationStatus_Finish}) |
| | |
| | | } |
| | | |
| | | func (s *Server) OrderProductOutput(ctx context.Context, req *OrderProductOutputRequest) (resp *OrderProductOutputResponse, err error) { |
| | | resp = new(OrderProductOutputResponse) |
| | | if req.OrderNumber == "" || len(req.Products) == 0 { |
| | | return nil, errors.New("参数缺失") |
| | | } |
| | |
| | | inputLocationAmountMap := make(map[int64]map[string]decimal.Decimal) |
| | | outputLocationAmountMap := make(map[int64]map[string]decimal.Decimal) |
| | | for _, v := range outputList { |
| | | if req.WarehouseId != 0 && v.WareHouseID != req.WarehouseId { |
| | | continue |
| | | } |
| | | if outputProductMap[v.Number] == nil { |
| | | simpleInfo := &OutputSimpleInfo{ |
| | | Number: v.Number, |
| | |
| | | } |
| | | } |
| | | for _, v := range inputList { |
| | | if req.WarehouseId != 0 && v.WareHouseID != req.WarehouseId { |
| | | continue |
| | | } |
| | | if inputProductMap[v.Number] == nil { |
| | | storeInfo := &StoreInfo{ |
| | | Number: v.Number, |
| | |
| | | |
| | | LocationIDWarehouseIDMap := make(map[int64]int64) |
| | | for _, output := range outputList { |
| | | if req.WarehouseId != 0 && output.WareHouseID != req.WarehouseId { |
| | | continue |
| | | } |
| | | if outputLocationAmountMap[output.LocationID] == nil { |
| | | outputLocationAmountMap[output.LocationID] = make(map[string]decimal.Decimal) |
| | | } |
| | |
| | | outputLocationAmountMap[output.LocationID][output.Number] = outputAmount |
| | | } |
| | | for _, input := range inputList { |
| | | if req.WarehouseId != 0 && input.WareHouseID != req.WarehouseId { |
| | | continue |
| | | } |
| | | LocationIDWarehouseIDMap[input.LocationID] = input.WareHouseID |
| | | |
| | | if inputLocationAmountMap[input.LocationID] == nil { |
| | |
| | | productHasSendAmount[productNumber] = productHasSendAmount[productNumber].Add(locationSendAmount) |
| | | } |
| | | outputInfoList = append(outputInfoList, &service.OutputInfo{ |
| | | LocationID: int(locationID), |
| | | WarehouseID: int(LocationIDWarehouseIDMap[locationID]), |
| | | Products: productInfoList, |
| | | OperationID: 0, |
| | | SourceNumber: req.OrderNumber, |
| | | LocationID: int(locationID), |
| | | WarehouseID: int(LocationIDWarehouseIDMap[locationID]), |
| | | Products: productInfoList, |
| | | OperationID: 0, |
| | | SourceNumber: req.OrderNumber, |
| | | SaleDetailsNumber: req.OrderNumber, |
| | | }) |
| | | } |
| | | |
| | | err = service.AddOutputOperations(outputInfoList) |
| | | |
| | | if err != nil { |
| | | logx.Errorf("OrderProductOutput AddOutputOperations err:%v", err) |
| | | return nil, err |
| | | } |
| | | |
| | | resp.Code = 1 |
| | | resp.Msg = "success" |
| | | return nil, nil |
| | | return resp, nil |
| | | } |
| | | |
| | | func (s *Server) GetOutputOperationInfo(ctx context.Context, req *GetOutputOperationInfoRequest) (*GetOutputOperationInfoResponse, error) { |
| | | if req.Number == "" { |
| | | return nil, errors.New("参数不能为空") |
| | | } |
| | | result := new(GetOutputOperationInfoResponse) |
| | | first, err := models.NewOperationSearch().SetSourceNumber(req.Number).SetBaseOperationType(constvar.BaseOperationTypeOutgoing).SetStatus(constvar.OperationStatus_Finish).First() |
| | | if err != nil { |
| | | if err == gorm.ErrRecordNotFound { |
| | | return result, nil |
| | | } |
| | | return nil, err |
| | | } |
| | | details, err := models.NewOperationDetailsSearch().SetOperationId(first.Id).FindNotTotal() |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | list := make([]*OutputProduct, 0) |
| | | for _, detail := range details { |
| | | var op OutputProduct |
| | | op.Number = detail.ProductId |
| | | op.Amount = detail.Amount.String() |
| | | list = append(list, &op) |
| | | } |
| | | result.Products = list |
| | | |
| | | return result, nil |
| | | } |