| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- 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"
- contractmodel "dashoo.cn/micro/app/model/contract"
- projmodel "dashoo.cn/micro/app/model/proj"
- server "dashoo.cn/micro/app/service/base"
- )
- type DistributorHandler struct{}
- // GetList 获取列表
- // Swagger:Distributor 经销商代理商 查询
- func (c *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(ctx, req)
- if err != nil {
- return err
- }
- rsp.Data = g.Map{"list": list, "total": total}
- return nil
- }
- // Swagger:Distributor 经销商代理商 新增
- func (c *DistributorHandler) Create(ctx context.Context, req *model.AddDistributor, rsp *comm_def.CommonMsg) error {
- distributorServer, err := server.NewDistributorService(ctx)
- if err != nil {
- return err
- }
- _, err = distributorServer.Create(ctx, req)
- if err != nil {
- return myerrors.CreateError(err, "经销商")
- }
- return nil
- }
- // GetEntityById 详情
- func (c *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
- }
- // Swagger:Distributor 经销商代理商 修改
- func (c *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
- }
- // Swagger:Distributor 经销商代理商 转为代理商
- func (c *DistributorHandler) ToProxy(ctx context.Context, req *model.DistributorToProxyReq, rsp *comm_def.CommonMsg) error {
- g.Log().Infof("DistributorHandler.ToProxy request %#v ", *req)
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return err
- }
- distributorServer, err := server.NewDistributorService(ctx)
- if err != nil {
- return err
- }
- err = distributorServer.ToProxy(ctx, req)
- if err != nil {
- return err
- }
- return nil
- }
- // Swagger:Distributor 经销商代理商 续签
- func (c *DistributorHandler) Renew(ctx context.Context, req *model.DistributorRenewReq, rsp *comm_def.CommonMsg) error {
- g.Log().Infof("DistributorHandler.Renew request %#v ", *req)
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return err
- }
- distributorServer, err := server.NewDistributorService(ctx)
- if err != nil {
- return err
- }
- err = distributorServer.Renew(ctx, req)
- if err != nil {
- return err
- }
- return nil
- }
- // Swagger:Distributor 经销商代理商 转为经销商
- func (c *DistributorHandler) ToDist(ctx context.Context, req *model.DistributorToDistReq, rsp *comm_def.CommonMsg) error {
- g.Log().Infof("DistributorHandler.ToDist request %#v ", *req)
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return err
- }
- distributorServer, err := server.NewDistributorService(ctx)
- if err != nil {
- return err
- }
- err = distributorServer.ToDist(ctx, req)
- if err != nil {
- return err
- }
- return nil
- }
- // Swagger:Distributor 经销商代理商 历史代理
- func (c *DistributorHandler) TransRecord(ctx context.Context, req *model.DistributorTransRecordReq, rsp *comm_def.CommonMsg) error {
- g.Log().Infof("DistributorHandler.TransRecord request %#v ", *req)
- s, err := server.NewDistributorService(ctx)
- if err != nil {
- return err
- }
- total, ent, err := s.TransRecord(ctx, req)
- if err != nil {
- return err
- }
- if ent == nil {
- ent = []*model.BaseDistributorRecord{}
- }
- rsp.Data = g.Map{"list": ent, "total": total}
- return nil
- }
- // DeleteByIds 删掉
- func (c *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
- }
- // Swagger:Distributor 经销商代理商 项目列表
- func (c *DistributorHandler) ProjectList(ctx context.Context, req *model.DistributorProjectListReq, rsp *comm_def.CommonMsg) error {
- g.Log().Infof("DistributorHandler.ProjectList request %#v ", *req)
- s, err := server.NewDistributorService(ctx)
- if err != nil {
- return err
- }
- total, ent, err := s.ProjectList(ctx, req)
- if err != nil {
- return err
- }
- if ent == nil {
- ent = []*projmodel.ProjBusiness{}
- }
- rsp.Data = g.Map{"list": ent, "total": total}
- return nil
- }
- // Swagger:Distributor 经销商代理商 合同列表
- func (c *DistributorHandler) ContractList(ctx context.Context, req *model.DistributorContractListReq, rsp *comm_def.CommonMsg) error {
- g.Log().Infof("DistributorHandler.ContractList request %#v ", *req)
- s, err := server.NewDistributorService(ctx)
- if err != nil {
- return err
- }
- total, ent, err := s.ContractList(ctx, req)
- if err != nil {
- return err
- }
- if ent == nil {
- ent = []*contractmodel.CtrContractListRsp{}
- }
- rsp.Data = g.Map{"list": ent, "total": total}
- return nil
- }
- func (c *DistributorHandler) DynamicsList(ctx context.Context, req *model.DistributorDynamicsListReq, rsp *comm_def.CommonMsg) error {
- g.Log().Infof("DistributorHandler.GetDynamicsList request %#v ", *req)
- s, err := server.NewDistributorService(ctx)
- if err != nil {
- return err
- }
- total, ent, err := s.DynamicsList(ctx, req)
- if err != nil {
- return err
- }
- if ent == nil {
- ent = []*model.BaseDistributorDynamics{}
- }
- rsp.Data = g.Map{"list": ent, "total": total}
- return nil
- }
- // Swagger:Distributor 经销商代理商 系统管理员转移经销商代理商
- func (c *DistributorHandler) SysAdminTransferDistributor(ctx context.Context, req *model.SysAdminTransferDistributorReq, rsp *comm_def.CommonMsg) error {
- g.Log().Infof("DistributorHandler.SysAdminTransferDistributor request %#v ", *req)
- s, err := server.NewDistributorService(ctx)
- if err != nil {
- return err
- }
- err = s.SysAdminTransferDistributor(ctx, req)
- if err != nil {
- return err
- }
- return nil
- }
|