| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- 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 {
- g.Log().Error(err)
- return err
- }
- total, list, err := distributorServer.GetList(req)
- _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
- if err != nil {
- g.Log().Error(err)
- return err
- }
- rsp.Data = g.Map{"list": list, "total": total}
- return nil
- }
- // 创建
- 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 {
- g.Log().Error(err)
- return err
- }
- distributorServer.Create(req)
- _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
- if err != nil {
- g.Log().Error(err)
- return err
- }
- return nil
- }
- // 编辑
- 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 {
- g.Log().Error(err)
- return err
- }
- distributorServer.UpdateById(req)
- _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
- if err != nil {
- g.Log().Error(err)
- return err
- }
- return nil
- }
- //删掉
- func (p *DistributorHandler) DeleteByIds(ctx context.Context, req *model.DeleteDistributorReq, rsp *comm_def.CommonMsg) error {
- distributorServer, err := server.NewDistributorService(ctx)
- if err != nil {
- g.Log().Error(err)
- return err
- }
- err = distributorServer.DeleteByIds(req.Ids)
- g.Log().Info("req", req)
- _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
- if err != nil {
- g.Log().Error(err)
- return err
- }
- return nil
- }
|