goodsspecaddlogic.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package logic
  2. import (
  3. "context"
  4. "fmt"
  5. "bp.jydev.jianyu360.cn/BaseService/goodsCenter/rpc/pb"
  6. "bp.jydev.jianyu360.cn/BaseService/goodsCenter/public/service"
  7. "bp.jydev.jianyu360.cn/BaseService/goodsCenter/api/internal/svc"
  8. "bp.jydev.jianyu360.cn/BaseService/goodsCenter/api/internal/types"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type GoodsSpecAddLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewGoodsSpecAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsSpecAddLogic {
  17. return &GoodsSpecAddLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. }
  22. }
  23. func (l *GoodsSpecAddLogic) GoodsSpecAdd(req *types.GoodsSpec) (resp *types.Reply, err error) {
  24. // todo: add your logic here and delete this line
  25. resp = &types.Reply{}
  26. goodsResp, err := service.GoodsCenterRpc.GoodsSpecAdd(l.ctx, &pb.GoodsSpecAddReq{
  27. GoodsSpec: &pb.GoodsSpec{
  28. Appid: req.AppId,
  29. Name: req.Name,
  30. GoodsCode: req.Goods_code,
  31. OriginPrice: req.Origin_price,
  32. SkuMax: req.Sku_max,
  33. CalculationType: req.Calculation_type,
  34. CalculationMode: req.Calculation_mode,
  35. CalculationFormula: req.Calculation_formula,
  36. Tag: req.Tag,
  37. Remark: req.Remark,
  38. ActualPrice: req.Actual_price,
  39. GoodsSpecChild: Format(req.Goods_spec_child, []*pb.GoodsSpec{}),
  40. },
  41. })
  42. if goodsResp.ErrorMsg != "" {
  43. resp.Error_msg = goodsResp.ErrorMsg
  44. resp.Error_code = -1
  45. l.Error(fmt.Sprintf("%+v", req), resp.Error_msg)
  46. }
  47. resp.Data = map[string]interface{}{
  48. "status": goodsResp.Status,
  49. }
  50. return
  51. }
  52. //格式转化
  53. func Format(arr []*types.GoodsSpec, child []*pb.GoodsSpec) []*pb.GoodsSpec {
  54. for _, v := range arr {
  55. child = append(child, &pb.GoodsSpec{
  56. Appid: v.AppId,
  57. Name: v.Name,
  58. GoodsCode: v.Goods_code,
  59. OriginPrice: v.Origin_price,
  60. SkuMax: v.Sku_max,
  61. CalculationType: v.Calculation_type,
  62. CalculationMode: v.Calculation_mode,
  63. CalculationFormula: v.Calculation_formula,
  64. Tag: v.Tag,
  65. Remark: v.Remark,
  66. ActualPrice: v.Actual_price,
  67. GoodsSpecChild: Format(v.Goods_spec_child, []*pb.GoodsSpec{}),
  68. })
  69. }
  70. return child
  71. }