package logic import ( "context" "fmt" "bp.jydev.jianyu360.cn/BaseService/goodsCenter/rpc/pb" "bp.jydev.jianyu360.cn/BaseService/goodsCenter/public/service" "bp.jydev.jianyu360.cn/BaseService/goodsCenter/api/internal/svc" "bp.jydev.jianyu360.cn/BaseService/goodsCenter/api/internal/types" "github.com/zeromicro/go-zero/core/logx" ) type GoodsSpecAddLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewGoodsSpecAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsSpecAddLogic { return &GoodsSpecAddLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *GoodsSpecAddLogic) GoodsSpecAdd(req *types.GoodsSpec) (resp *types.Reply, err error) { // todo: add your logic here and delete this line resp = &types.Reply{} goodsResp, err := service.GoodsCenterRpc.GoodsSpecAdd(l.ctx, &pb.GoodsSpecAddReq{ GoodsSpec: &pb.GoodsSpec{ Appid: req.AppId, Name: req.Name, GoodsCode: req.Goods_code, OriginPrice: req.Origin_price, SkuMax: req.Sku_max, CalculationType: req.Calculation_type, CalculationMode: req.Calculation_mode, CalculationFormula: req.Calculation_formula, Tag: req.Tag, Remark: req.Remark, ActualPrice: req.Actual_price, GoodsSpecChild: Format(req.Goods_spec_child, []*pb.GoodsSpec{}), }, }) if goodsResp.ErrorMsg != "" { resp.Error_msg = goodsResp.ErrorMsg resp.Error_code = -1 l.Error(fmt.Sprintf("%+v", req), resp.Error_msg) } resp.Data = map[string]interface{}{ "status": goodsResp.Status, } return } //格式转化 func Format(arr []*types.GoodsSpec, child []*pb.GoodsSpec) []*pb.GoodsSpec { for _, v := range arr { child = append(child, &pb.GoodsSpec{ Appid: v.AppId, Name: v.Name, GoodsCode: v.Goods_code, OriginPrice: v.Origin_price, SkuMax: v.Sku_max, CalculationType: v.Calculation_type, CalculationMode: v.Calculation_mode, CalculationFormula: v.Calculation_formula, Tag: v.Tag, Remark: v.Remark, ActualPrice: v.Actual_price, GoodsSpecChild: Format(v.Goods_spec_child, []*pb.GoodsSpec{}), }) } return child }