| | |
| | | import ( |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/mitchellh/mapstructure" |
| | | "go.uber.org/zap" |
| | | "gorm.io/gorm" |
| | | "srm/global" |
| | |
| | | } |
| | | |
| | | var purchaseRecord purchase.Purchase |
| | | if err := mapstructure.Decode(params.Purchase, &purchaseRecord); err != nil { |
| | | if err := utils.AssignTo(params.Purchase, &purchaseRecord); err != nil { |
| | | global.GVA_LOG.Error("Add Purchase failed", zap.Error(err)) |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | |
| | | return |
| | | } |
| | | global.GVA_LOG.Error("创建失败!", zap.Error(err)) |
| | | response.FailWithMessage("创建失败", c) |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | response.OkWithMessage("创建成功", c) |
| | |
| | | } |
| | | |
| | | var purchaseRecord purchase.Purchase |
| | | if err := mapstructure.Decode(params.Purchase, &purchaseRecord); err != nil { |
| | | if err := utils.AssignTo(params.Purchase, &purchaseRecord); err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | |
| | | return |
| | | } |
| | | respProductList := make([]*purchaseRes.PurchaseProducts, len(productList)) |
| | | err = mapstructure.Decode(productList, &respProductList) |
| | | err = utils.AssignTo(productList, &respProductList) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | |
| | | respProductList[k].Amount = item.Amount |
| | | respProductList[k].Price = item.Price |
| | | respProductList[k].Total = item.Total |
| | | err = mapstructure.Decode(item.Product, &respProductList[k]) |
| | | err = utils.AssignTo(item.Product, &respProductList[k]) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | |
| | | } |
| | | |
| | | purchaseTypeList := make([]*purchase.PurchaseType, 0, len(params)) |
| | | if err := mapstructure.Decode(params, &purchaseTypeList); err != nil { |
| | | if err := utils.AssignTo(params, &purchaseTypeList); err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |