milk_hall.go 780 B

1234567891011121314151617181920212223242526272829303132333435
  1. package backend
  2. import (
  3. "context"
  4. "encoding/json"
  5. "kpt-pasture/model"
  6. "gitee.com/xuyiping_admin/pkg/xerr"
  7. )
  8. // MilkBrand 奶厅品牌接口
  9. type MilkBrand interface {
  10. SaveData(ctx context.Context, body *model.MilkHallBody) error
  11. }
  12. func (s *StoreEntry) MilkHallOriginal(ctx context.Context, req []byte) error {
  13. body := &model.MilkHallBody{}
  14. if err := json.Unmarshal(req, body); err != nil {
  15. return xerr.WithStack(err)
  16. }
  17. var milkBrand MilkBrand
  18. switch body.Brand {
  19. case model.AFIMilk:
  20. milkBrand = &AFIMILK{store: s}
  21. case model.AFI:
  22. milkBrand = &AFI{store: s}
  23. case model.GEA:
  24. milkBrand = &GEAMILK{store: s}
  25. default:
  26. return xerr.Customf("不支持的品牌: %s", body.Brand)
  27. }
  28. // 调用品牌的 SaveData 方法
  29. return milkBrand.SaveData(ctx, body)
  30. }