From 0d86d93cff554f54f83927d4f8bf03ed8c847883 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期二, 29 八月 2023 17:14:54 +0800 Subject: [PATCH] fix&字段完善 --- api/v1/purchase/purchase.go | 27 +++++++++++++++++++++++---- 1 files changed, 23 insertions(+), 4 deletions(-) diff --git a/api/v1/purchase/purchase.go b/api/v1/purchase/purchase.go index c82be66..73eafdd 100644 --- a/api/v1/purchase/purchase.go +++ b/api/v1/purchase/purchase.go @@ -29,7 +29,7 @@ // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body purchaserequest.AddPurchase true "閲囪喘鍗曠敤鎴峰悕, 閲囪喘鍗曟墜鏈哄彿鐮�" +// @Param data body purchaserequest.AddPurchase true "閲囪喘鍗�,閲囪喘鍗曚骇鍝�" // @Success 200 {object} response.Response{msg=string} "鍒涘缓閲囪喘鍗�" // @Router /purchase/purchase [post] func (e *PurchaseApi) CreatePurchase(c *gin.Context) { @@ -149,7 +149,26 @@ response.FailWithMessage("鑾峰彇澶辫触", c) return } - response.OkWithDetailed(purchaseRes.PurchaseResponse{Purchase: data, ProductList: productList}, "鑾峰彇鎴愬姛", c) + respProductList := make([]*purchaseRes.PurchaseProducts, len(productList)) + err = mapstructure.Decode(productList, &respProductList) + if err != nil { + global.GVA_LOG.Error("鑾峰彇澶辫触!", zap.Error(err)) + response.FailWithMessage("鑾峰彇澶辫触", c) + return + } + for k, item := range productList { + respProductList[k].Amount = item.Amount + respProductList[k].Price = item.Price + respProductList[k].Total = item.Total + err = mapstructure.Decode(item.Product, &respProductList[k]) + if err != nil { + global.GVA_LOG.Error("鑾峰彇澶辫触!", zap.Error(err)) + response.FailWithMessage("鑾峰彇澶辫触", c) + return + } + } + + response.OkWithDetailed(purchaseRes.PurchaseResponse{Purchase: data, ProductList: respProductList}, "鑾峰彇鎴愬姛", c) } // GetPurchaseList @@ -173,14 +192,14 @@ response.FailWithMessage(err.Error(), c) return } - PurchaseList, total, err := service.NewPurchaseService().GetPurchaseList(pageInfo) + purchaseList, total, err := service.NewPurchaseService().GetPurchaseList(pageInfo) if err != nil { global.GVA_LOG.Error("鑾峰彇澶辫触!", zap.Error(err)) response.FailWithMessage("鑾峰彇澶辫触"+err.Error(), c) return } response.OkWithDetailed(response.PageResult{ - List: PurchaseList, + List: purchaseList, Total: total, Page: pageInfo.Page, PageSize: pageInfo.PageSize, -- Gitblit v1.8.0