package base import ( "context" "dashoo.cn/common_definition/comm_def" "dashoo.cn/opms_libary/myerrors" "github.com/gogf/gf/frame/g" "github.com/gogf/gf/util/gvalid" model "dashoo.cn/micro/app/model/base" server "dashoo.cn/micro/app/service/base" ) type DistributorHandler struct{} // GetList 获取列表 func (p *DistributorHandler) GetList(ctx context.Context, req *model.BaseDistributorSearchReq, rsp *comm_def.CommonMsg) error { distributorServer, err := server.NewDistributorService(ctx) if err != nil { return err } total, list, err := distributorServer.GetList(req) if err != nil { return err } rsp.Data = g.Map{"list": list, "total": total} return nil } // Create 创建 func (p *DistributorHandler) Create(ctx context.Context, req *model.AddDistributor, rsp *comm_def.CommonMsg) error { if err := gvalid.CheckStruct(ctx, req, nil); err != nil { return err } distributorServer, err := server.NewDistributorService(ctx) if err != nil { return err } _, err = distributorServer.Create(req) if err != nil { return myerrors.CreateError(err, "经销商") } return nil } // GetEntityById 详情 func (p *DistributorHandler) GetEntityById(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error { if err := gvalid.CheckStruct(ctx, req, nil); err != nil { return err } distributorServer, err := server.NewDistributorService(ctx) if err != nil { return err } list, err := distributorServer.GetEntityById(req.Id) if err != nil { return err } rsp.Data = g.Map{"list": list} return nil } // UpdateById 编辑 func (p *DistributorHandler) UpdateById(ctx context.Context, req *model.UpdateDistributorReq, rsp *comm_def.CommonMsg) error { if err := gvalid.CheckStruct(ctx, req, nil); err != nil { return err } distributorServer, err := server.NewDistributorService(ctx) if err != nil { return err } err = distributorServer.UpdateById(req) if err != nil { return err } return nil } // DeleteByIds 删掉 func (p *DistributorHandler) DeleteByIds(ctx context.Context, req *model.DeleteDistributorReq, rsp *comm_def.CommonMsg) error { distributorServer, err := server.NewDistributorService(ctx) if err != nil { return err } err = distributorServer.DeleteByIds(req.Ids) if err != nil { return err } return nil }