| | |
| | | |
| | | import ( |
| | | "aps_crm/conf" |
| | | "aps_crm/model" |
| | | "aps_crm/model/request" |
| | | "aps_crm/model/response" |
| | | "aps_crm/pkg/contextx" |
| | | "aps_crm/pkg/ecode" |
| | | "aps_crm/pkg/logx" |
| | | "aps_crm/proto/product" |
| | | "aps_crm/utils" |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/shopspring/decimal" |
| | | "github.com/spf13/cast" |
| | | "google.golang.org/grpc" |
| | | "google.golang.org/grpc/credentials/insecure" |
| | |
| | | if err != nil { |
| | | logx.Errorf("grpc dial product service error: %v", err.Error()) |
| | | return |
| | | } |
| | | } |
| | | |
| | | func CloseProductServiceConn() { |
| | | if productServiceConn != nil { |
| | | productServiceConn.Close() |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | cli := product.NewProductServiceClient(productServiceConn) |
| | | |
| | | getProductListResponse, err := cli.GetProductList(ctx.GetCtx(), &product.GetProductListRequest{ |
| | | Page: cast.ToInt32(params.Page), |
| | | PageSize: cast.ToInt32(params.PageSize), |
| | | ProductNumber: params.ProductNumber, |
| | | ProductName: params.ProductName, |
| | | }) |
| | | rawProductList := getProductListResponse.List |
| | | productList := make([]model.Product, len(rawProductList)) |
| | | |
| | | for k, v := range rawProductList { |
| | | productList[k].Number = v.Number |
| | | productList[k].Name = v.Name |
| | | productList[k].Price = decimal.NewFromFloat(v.SalePrice).Round(2) |
| | | productList[k].Amount = decimal.NewFromFloat(1) |
| | | productList[k].Total = productList[k].Price.Mul(productList[k].Amount).Round(2) |
| | | } |
| | | |
| | | if err != nil { |
| | | logx.Errorf("GetProductList err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | |
| | | return |
| | | } |
| | | ctx.OkWithDetailed(response.ListResponse{ |
| | | Data: getProductListResponse.List, |
| | | Data: productList, |
| | | Count: getProductListResponse.Total, |
| | | }) |
| | | } |
| | |
| | | } |
| | | ctx.OkWithDetailed(getProductInfoResponse.Data) |
| | | } |
| | | |
| | | // GetProductOrderInfo |
| | | // |
| | | // @Tags 产品 |
| | | // @Summary 获取产品订单信息 |
| | | // @Produce application/json |
| | | // @Param number path string true "明细编码" |
| | | // @Success 200 {object} contextx.Response{data=[]product.WorkOrderInfo} "成功" |
| | | // |
| | | // @Router /api/product/getProductOrderInfo/{number} [get] |
| | | func (ci *ProductApi) GetProductOrderInfo(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | number := c.Param("number") |
| | | first, err := model.NewSalesDetailsSearch().SetNumber(number).SetPreload(true).First() |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.UnknownErr, "明细详情查找失败") |
| | | return |
| | | } |
| | | params := make([]*product.Info, 0) |
| | | for _, p := range first.Products { |
| | | var pa product.Info |
| | | pa.ProductId = p.Number |
| | | pa.Time = utils.TimeToString(first.UpdatedAt) |
| | | params = append(params, &pa) |
| | | } |
| | | client := product.NewProductServiceClient(productServiceConn) |
| | | info, err := client.GetProductOrder(ctx.GetCtx(), &product.GetProductOrderRequest{Params: params}) |
| | | if err != nil { |
| | | logx.Errorf("GetProductOrder err: %v", err.Error()) |
| | | ctx.FailWithMsg(ecode.UnknownErr, "内部错误") |
| | | return |
| | | } |
| | | ctx.OkWithDetailed(info.List) |
| | | } |