| | |
| | | } |
| | | number := c.Param("number") |
| | | client := product_inventory.NewProductInventoryServiceClient(grpc_init.ProductInventoryServiceConn) |
| | | info, err := client.GetInventoryProductInfo(ctx.GetCtx(), &product_inventory.GetInventoryProductInfoRequest{Number: number}) |
| | | info, err := client.GetOrderInputAndOutputInfo(ctx.GetCtx(), &product_inventory.GetOrderInputAndOutputInfoRequest{Number: number}) |
| | | if err != nil { |
| | | if strings.Contains(err.Error(), "record not found") { |
| | | ctx.Ok() |
| | |
| | | return |
| | | } |
| | | var list []response.ProductInfo |
| | | err = structx.AssignTo(info.ProductList, &list) |
| | | err = structx.AssignTo(info.OutputList, &list) |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.UnknownErr, "转换错误") |
| | | return |
| | | } |
| | | |
| | | products, err := salesDetailsService.GetProducts(number) |
| | | m := make(map[string]*model.Product) |
| | | |
| | | for _, product := range products { |
| | | m[product.Number] = product |
| | | } |
| | | for k, v := range list { |
| | | if m[v.Number] == nil { |
| | | continue |
| | | } |
| | | list[k].OrderAmount = m[v.Number].Amount.String() |
| | | } |
| | | |
| | | ctx.OkWithDetailed(list) |
| | | } |
| | | |
| | |
| | | inputProductMap := make(map[string]*response.StoreInfo) |
| | | outputProductMap := make(map[string]*response.OutputSimpleInfo) |
| | | for _, v := range grpcOutputList { |
| | | if productMap[v.Number] == nil { |
| | | continue |
| | | } |
| | | if outputProductMap[v.Number] == nil { |
| | | simpleInfo := &response.OutputSimpleInfo{ |
| | | Number: v.Number, |
| | |
| | | } |
| | | } |
| | | for _, v := range grpcInputList { |
| | | if productMap[v.Number] == nil { |
| | | continue |
| | | } |
| | | if inputProductMap[v.Number] == nil { |
| | | storeInfo := &response.StoreInfo{ |
| | | Number: v.Number, |
| | |
| | | storeInfo := inputProductMap[product.Number] |
| | | if storeInfo == nil { //没有入库信息 |
| | | storeInfo = &response.StoreInfo{ |
| | | Name: product.Number, |
| | | Name: product.Name, |
| | | Number: product.Number, |
| | | OrderAmount: product.Amount, |
| | | FinishAmount: decimal.Decimal{}, |
| | |
| | | ctx.OkWithDetailed(storeList) |
| | | } |
| | | |
| | | // ConfirmOutput |
| | | // @Tags SalesDetails |
| | | // @Summary 确认发货 |
| | | // @Produce application/json |
| | | // @Param object body request.ConfirmOutput true "明细编码" |
| | | // @Success 200 {object} response.ListResponse |
| | | // @Router /api/salesDetails/confirmOutput [post] |
| | | func (s *SalesDetailsApi) ConfirmOutput(c *gin.Context) { |
| | | var params request.ConfirmOutput |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | if len(params.Products) == 0 || params.SaleDetailNumber == "" { |
| | | ctx.FailWithMsg(ecode.ParamsErr, "参数缺失") |
| | | return |
| | | } |
| | | var flag bool |
| | | for _, p := range params.Products { |
| | | if p.OutputAmount.GreaterThan(decimal.Zero) { |
| | | flag = true |
| | | } |
| | | } |
| | | if !flag { |
| | | ctx.FailWithMsg(ecode.ParamsErr, "发货数量缺失") |
| | | return |
| | | } |
| | | |
| | | products := make([]*product_inventory.OutputProduct, 0, len(params.Products)) |
| | | for _, product := range params.Products { |
| | | products = append(products, &product_inventory.OutputProduct{ |
| | | Number: product.Number, |
| | | Amount: product.OutputAmount.String(), |
| | | }) |
| | | } |
| | | client := product_inventory.NewProductInventoryServiceClient(grpc_init.ProductInventoryServiceConn) |
| | | _, err := client.OrderProductOutput(ctx.GetCtx(), &product_inventory.OrderProductOutputRequest{ |
| | | OrderNumber: params.SaleDetailNumber, |
| | | Products: products, |
| | | }) |
| | | |
| | | if err != nil { |
| | | logx.Errorf("product_inventory.OrderProductOutput err:%v, params:%v", err, params) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "发货失败"+err.Error()) |
| | | return |
| | | } |
| | | |
| | | ctx.OkWithDetailed(nil) |
| | | } |
| | | |
| | | // confirmOutputOver |
| | | // @Tags SalesDetails |
| | | // @Summary 确认发货 |
| | | // @Produce application/json |
| | | // @Param object body request.ConfirmOutputOver true "明细编码" |
| | | // @Success 200 {object} response.ListResponse |
| | | // @Router /api/salesDetails/confirmOutputOver [post] |
| | | func (s *SalesDetailsApi) ConfirmOutputOver(c *gin.Context) { |
| | | var params request.ConfirmOutput |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | if params.SaleDetailNumber == "" { |
| | | ctx.FailWithMsg(ecode.ParamsErr, "参数缺失") |
| | | return |
| | | } |
| | | |
| | | salesDetails, err := salesDetailsService.GetSalesDetailsByNumber(params.SaleDetailNumber) |
| | | if err == gorm.ErrRecordNotFound || salesDetails.Number != params.SaleDetailNumber { |
| | | ctx.FailWithMsg(ecode.ParamsErr, "销售订单不存在") |
| | | return |
| | | } |
| | | |
| | | err = model.NewSalesDetailsSearch().SetId(salesDetails.Id).UpdateByMap(map[string]interface{}{"status": constvar.OverOutbound}) |
| | | |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.DBErr, "修改失败") |
| | | return |
| | | } |
| | | |
| | | ctx.OkWithDetailed(nil) |
| | | } |
| | | |
| | | // GetDeliveryList |
| | | // @Tags SalesDetails |
| | | // @Summary 发货明细 |