distributor.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package base
  2. import (
  3. "context"
  4. "dashoo.cn/common_definition/comm_def"
  5. "dashoo.cn/opms_libary/myerrors"
  6. "github.com/gogf/gf/frame/g"
  7. "github.com/gogf/gf/util/gvalid"
  8. model "dashoo.cn/micro/app/model/base"
  9. server "dashoo.cn/micro/app/service/base"
  10. )
  11. type DistributorHandler struct{}
  12. // GetList 获取列表
  13. func (p *DistributorHandler) GetList(ctx context.Context, req *model.BaseDistributorSearchReq, rsp *comm_def.CommonMsg) error {
  14. distributorServer, err := server.NewDistributorService(ctx)
  15. if err != nil {
  16. return err
  17. }
  18. total, list, err := distributorServer.GetList(req)
  19. if err != nil {
  20. return err
  21. }
  22. rsp.Data = g.Map{"list": list, "total": total}
  23. return nil
  24. }
  25. // Create 创建
  26. func (p *DistributorHandler) Create(ctx context.Context, req *model.AddDistributor, rsp *comm_def.CommonMsg) error {
  27. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  28. return err
  29. }
  30. distributorServer, err := server.NewDistributorService(ctx)
  31. if err != nil {
  32. return err
  33. }
  34. _, err = distributorServer.Create(req)
  35. if err != nil {
  36. return myerrors.CreateError(err, "经销商")
  37. }
  38. return nil
  39. }
  40. // GetEntityById 详情
  41. func (p *DistributorHandler) GetEntityById(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
  42. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  43. return err
  44. }
  45. distributorServer, err := server.NewDistributorService(ctx)
  46. if err != nil {
  47. return err
  48. }
  49. list, err := distributorServer.GetEntityById(req.Id)
  50. if err != nil {
  51. return err
  52. }
  53. rsp.Data = g.Map{"list": list}
  54. return nil
  55. }
  56. // UpdateById 编辑
  57. func (p *DistributorHandler) UpdateById(ctx context.Context, req *model.UpdateDistributorReq, rsp *comm_def.CommonMsg) error {
  58. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  59. return err
  60. }
  61. distributorServer, err := server.NewDistributorService(ctx)
  62. if err != nil {
  63. return err
  64. }
  65. err = distributorServer.UpdateById(req)
  66. if err != nil {
  67. return err
  68. }
  69. return nil
  70. }
  71. // DeleteByIds 删掉
  72. func (p *DistributorHandler) DeleteByIds(ctx context.Context, req *model.DeleteDistributorReq, rsp *comm_def.CommonMsg) error {
  73. distributorServer, err := server.NewDistributorService(ctx)
  74. if err != nil {
  75. return err
  76. }
  77. err = distributorServer.DeleteByIds(req.Ids)
  78. if err != nil {
  79. return err
  80. }
  81. return nil
  82. }