diff --git a/api/proto/zone_third_partner/proto/not_null_def_op.go b/api/proto/zone_third_partner/proto/not_null_def_op.go new file mode 100644 index 00000000..e796a143 --- /dev/null +++ b/api/proto/zone_third_partner/proto/not_null_def_op.go @@ -0,0 +1,27 @@ +package proto + +import ( + "service/library/validator" +) + +func (p *OpCreateReq) ProvideNotNullValue() (params []*validator.JsonParam) { + params = make([]*validator.JsonParam, 0) + params = append(params, validator.NewInt64PtrParam("请填写空间id!", p.ZoneThirdPartner.Zid)) + params = append(params, validator.NewInt64PtrParam("请填写代运营用户id!", p.ZoneThirdPartner.ThirdPartnerMid)) + params = append(params, validator.NewFloat64PtrParam("请填写分成比例!", p.ZoneThirdPartner.SharingRatio)) + return +} + +func (p *OpUpdateReq) ProvideNotNullValue() (params []*validator.JsonParam) { + params = make([]*validator.JsonParam, 0) + + params = append(params, validator.NewInt64PtrParam("请填写空间id!", p.Zid)) + return +} + +func (p *OpDeleteReq) ProvideNotNullValue() (params []*validator.JsonParam) { + params = make([]*validator.JsonParam, 0) + + params = append(params, validator.NewInt64PtrParam("请填写空间id!", p.Zid)) + return +} diff --git a/api/proto/zone_third_partner/proto/zone_third_partner_op.go b/api/proto/zone_third_partner/proto/zone_third_partner_op.go index 3ac35472..dec0c20b 100644 --- a/api/proto/zone_third_partner/proto/zone_third_partner_op.go +++ b/api/proto/zone_third_partner/proto/zone_third_partner_op.go @@ -22,7 +22,7 @@ type OpCreateResp struct { // op 删除 type OpDeleteReq struct { base.BaseRequest - Id int64 `json:"id"` + Zid *int64 `json:"zid"` } type OpDeleteData struct { diff --git a/app/mix/controller/zone_third_partner_op.go b/app/mix/controller/zone_third_partner_op.go index 01fb8f3c..970ad28a 100644 --- a/app/mix/controller/zone_third_partner_op.go +++ b/app/mix/controller/zone_third_partner_op.go @@ -36,7 +36,7 @@ func OpUpdateZoneThirdPartner(ctx *gin.Context) { func OpDeleteZoneThirdPartner(ctx *gin.Context) { req := ctx.MustGet("client_req").(*zone_third_partnerproto.OpDeleteReq) - ec := service.DefaultService.OpDeleteZoneThirdPartner(ctx, req.Id) + ec := service.DefaultService.OpDeleteZoneThirdPartner(ctx, util.DerefInt64(req.Zid)) if ec != errcode.ErrCodeZoneThirdPartnerSrvOk { logger.Error("OpDeleteZoneThirdPartner fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index bc7bdbf1..6ec4b0b0 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -4702,12 +4702,35 @@ func (m *Mongo) UpdateZoneThirdPartner(ctx *gin.Context, zone_third_partner *dbs return err } +func (m *Mongo) UpdateZoneThirdPartnerByZid(ctx *gin.Context, zone_third_partner *dbstruct.ZoneThirdPartner) error { + col := m.getColZoneThirdPartner() + set := util.EntityToM(zone_third_partner) + delete(set, "zid") + set["ut"] = time.Now().Unix() + up := qmgo.M{ + "$set": set, + } + filter := qmgo.M{ + "zid": zone_third_partner.GetZid(), + } + err := col.UpdateOne(ctx, filter, up) + return err +} + func (m *Mongo) DeleteZoneThirdPartner(ctx *gin.Context, id int64) error { col := m.getColZoneThirdPartner() err := col.RemoveId(ctx, id) return err } +func (m *Mongo) DeleteZoneThirdPartnerByZid(ctx *gin.Context, zid int64) error { + col := m.getColZoneThirdPartner() + err := col.Remove(ctx, qmgo.M{ + "zid": zid, + }) + return err +} + func (m *Mongo) GetZoneThirdPartnerList(ctx *gin.Context, req *zone_third_partner_proto.OpListReq) (*dbstruct.ZoneThirdPartner, error) { zoneThirdPartner := &dbstruct.ZoneThirdPartner{} col := m.getColZoneThirdPartner() diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index ddb6aaf0..38fc1e8f 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -3065,36 +3065,6 @@ func (s *Service) ApiCreateZoneThirdPartner(ctx *gin.Context, req *zone_third_pa return } -func (s *Service) ApiUpdateZoneThirdPartner(ctx *gin.Context, req *zone_third_partner_proto.ApiUpdateReq) (ec errcode.ErrCode) { - ec = errcode.ErrCodeZoneThirdPartnerSrvOk - err := _DefaultZoneThirdPartner.OpUpdate(ctx, &zone_third_partner_proto.OpUpdateReq{ - BaseRequest: req.BaseRequest, - ZoneThirdPartner: req.ZoneThirdPartner, - }) - if err == qmgo.ErrNoSuchDocuments { - ec = errcode.ErrCodeZoneThirdPartnerNotExist - err = nil - return - } - if err != nil { - logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err) - ec = errcode.ErrCodeZoneThirdPartnerSrvFail - return - } - return -} - -func (s *Service) ApiDeleteZoneThirdPartner(ctx *gin.Context, id int64) (ec errcode.ErrCode) { - ec = errcode.ErrCodeZoneThirdPartnerSrvOk - err := _DefaultZoneThirdPartner.OpDelete(ctx, id) - if err != nil { - logger.Error("OpDelete fail, id: %v, err: %v", id, err) - ec = errcode.ErrCodeZoneThirdPartnerSrvFail - return - } - return -} - func (s *Service) ApiGetZoneThirdPartnerList(ctx *gin.Context, req *zone_third_partner_proto.ApiListReq) (vo *zone_third_partner_proto.ZoneThirdPartnerApiVO, ec errcode.ErrCode) { ec = errcode.ErrCodeZoneThirdPartnerSrvOk zoneThirdPartner, err := _DefaultZoneThirdPartner.OpList(ctx, &zone_third_partner_proto.OpListReq{ diff --git a/app/mix/service/logic/zone_third_partner.go b/app/mix/service/logic/zone_third_partner.go index 1e425364..dd04baa1 100644 --- a/app/mix/service/logic/zone_third_partner.go +++ b/app/mix/service/logic/zone_third_partner.go @@ -39,43 +39,44 @@ func (p *ZoneThirdPartner) OpCreate(ctx *gin.Context, req *zone_third_partner_pr return nil } -func (p *ZoneThirdPartner) OpUpdate(ctx *gin.Context, req *zone_third_partner_proto.OpUpdateReq) error { - err := p.store.UpdateZoneThirdPartner(ctx, req.ZoneThirdPartner) +func (p *ZoneThirdPartner) OpUpdateByZid(ctx *gin.Context, req *zone_third_partner_proto.OpUpdateReq) error { + err := p.store.UpdateZoneThirdPartnerByZid(ctx, req.ZoneThirdPartner) if err != nil { - logger.Error("UpdateZoneThirdPartner fail, err: %v", err) + logger.Error("UpdateZoneThirdPartnerByZid fail, err: %v", err) return err } return nil } -func (p *ZoneThirdPartner) OpDelete(ctx *gin.Context, id int64) error { +func (p *ZoneThirdPartner) OpDeleteByZid(ctx *gin.Context, zid int64) (zoneThirdPartner *dbstruct.ZoneThirdPartner, err error) { - //1.查出原协作者信息 - zoneThirdPartner, err := p.store.GetZoneThirdPartnerById(ctx, id) + //1.查出原代运营信息 + zoneThirdPartner, err = p.store.GetZoneThirdPartnerByZid(ctx, zid) if zoneThirdPartner == nil { logger.Error("GetZoneThirdPartnerById fail, err: %v", qmgo.ErrNoSuchDocuments) - return qmgo.ErrNoSuchDocuments + err = qmgo.ErrNoSuchDocuments + return } if err != nil { logger.Error("GetZoneThirdPartnerById fail, err: %v", err) - return err + return } - //2.原协作者记录标记删除后转存到历史表 + //2.原代运营记录标记删除后转存到历史表 zoneThirdPartner.DelFlag = goproto.Int64(consts.Deleted) err = p.store.CreateZoneThirdPartnerHis(ctx, zoneThirdPartner) if err != nil { logger.Error("CreateZoneThirdPartnerHis fail, err: %v", err) - return err + return } - //3.真删除原有协作者记录 - err = p.store.DeleteZoneThirdPartner(ctx, id) + //3.真删除原有代运营记录 + err = p.store.DeleteZoneThirdPartnerByZid(ctx, zid) if err != nil { - logger.Error("DeleteZoneThirdPartner fail, err: %v", err) - return err + logger.Error("DeleteZoneThirdPartnerByZid fail, err: %v", err) + return } - return nil + return } func (p *ZoneThirdPartner) OpList(ctx *gin.Context, req *zone_third_partner_proto.OpListReq) (*dbstruct.ZoneThirdPartner, error) { diff --git a/app/mix/service/service.go b/app/mix/service/service.go index 28c24c1b..2cc3c0db 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -3770,7 +3770,20 @@ func (s *Service) OpCreateZoneThirdPartner(ctx *gin.Context, req *zone_third_par func (s *Service) OpUpdateZoneThirdPartner(ctx *gin.Context, req *zone_third_partner_proto.OpUpdateReq) (ec errcode.ErrCode) { ec = errcode.ErrCodeZoneThirdPartnerSrvOk - err := _DefaultZoneThirdPartner.OpUpdate(ctx, req) + + // 若要更新代运营,则查询原代运营信息 + var oriZtp *dbstruct.ZoneThirdPartner + if req.ZoneThirdPartner.ThirdPartnerMid != nil { + ztp, err := _DefaultZoneThirdPartner.GetZoneThirdPartnerByZid(ctx, req.ZoneThirdPartner.GetZid()) + if err != nil { + logger.Error("GetZoneThirdPartnerByZid fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeZoneThirdPartnerSrvFail + return + } + oriZtp = ztp + } + + err := _DefaultZoneThirdPartner.OpUpdateByZid(ctx, req) if err == qmgo.ErrNoSuchDocuments { ec = errcode.ErrCodeZoneThirdPartnerNotExist err = nil @@ -3781,14 +3794,32 @@ func (s *Service) OpUpdateZoneThirdPartner(ctx *gin.Context, req *zone_third_par ec = errcode.ErrCodeZoneThirdPartnerSrvFail return } + + if oriZtp != nil { + err = _DefaultVas.ZoneExit(ctx, oriZtp.GetThirdPartnerMid(), oriZtp.GetZid()) + if err != nil { + logger.Error("ZoneExit fail, err: %v", err) + ec = errcode.ErrCodeZoneThirdPartnerSrvFail + return + } + } + return } -func (s *Service) OpDeleteZoneThirdPartner(ctx *gin.Context, id int64) (ec errcode.ErrCode) { +func (s *Service) OpDeleteZoneThirdPartner(ctx *gin.Context, zid int64) (ec errcode.ErrCode) { ec = errcode.ErrCodeZoneThirdPartnerSrvOk - err := _DefaultZoneThirdPartner.OpDelete(ctx, id) + + oriZtp, err := _DefaultZoneThirdPartner.OpDeleteByZid(ctx, zid) if err != nil { - logger.Error("OpDelete fail, id: %v, err: %v", id, err) + logger.Error("OpDelete fail, id: %v, err: %v", zid, err) + ec = errcode.ErrCodeZoneThirdPartnerSrvFail + return + } + + err = _DefaultVas.ZoneExit(ctx, oriZtp.GetThirdPartnerMid(), zid) + if err != nil { + logger.Error("ZoneExit fail, err: %v", err) ec = errcode.ErrCodeZoneThirdPartnerSrvFail return }