diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index 436b599f..e2a3eaf0 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -194,11 +194,13 @@ const ( DBZoneSession = "zone_session" COLZoneSession = "zone_session" - DBZoneCollaborator = "zone_collaborator" - COLZoneCollaborator = "zone_collaborator" + DBZoneCollaborator = "zone_collaborator" + COLZoneCollaborator = "zone_collaborator" + COLZoneCollaboratorHis = "zone_collaborator_his" - DBZoneThirdPartner = "zone_third_partner" - COLZoneThirdPartner = "zone_third_partner" + DBZoneThirdPartner = "zone_third_partner" + COLZoneThirdPartner = "zone_third_partner" + COLZoneThirdPartnerHis = "zone_third_partner_his" ) // 商品表 @@ -490,6 +492,16 @@ func (m *Mongo) getColZoneThirdPartner() *qmgo.Collection { return m.clientMix.Database(DBZoneThirdPartner).Collection(COLZoneThirdPartner) } +// 空间协作者历史表 +func (m *Mongo) getColZoneCollaboratorHis() *qmgo.Collection { + return m.clientMix.Database(DBZoneCollaborator).Collection(COLZoneCollaboratorHis) +} + +// 空间代运营历史表 +func (m *Mongo) getColZoneThirdPartnerHis() *qmgo.Collection { + return m.clientMix.Database(DBZoneThirdPartner).Collection(COLZoneThirdPartnerHis) +} + // 商品相关 func (m *Mongo) CreateProduct(ctx *gin.Context, product *dbstruct.Product) error { col := m.getColProduct() @@ -4521,12 +4533,7 @@ func (m *Mongo) UpdateZoneCollaborator(ctx *gin.Context, zone_collaborator *dbst func (m *Mongo) DeleteZoneCollaborator(ctx *gin.Context, id int64) error { col := m.getColZoneCollaborator() - update := qmgo.M{ - "$set": qmgo.M{ - "del_flag": 1, - }, - } - err := col.UpdateId(ctx, id, update) + err := col.RemoveId(ctx, id) return err } @@ -4566,6 +4573,28 @@ func (m *Mongo) GetZoneCollaboratorListByCMid(ctx *gin.Context, c_mid int64) ([] return list, err } +func (m *Mongo) GetZoneCollaboratorById(ctx *gin.Context, id int64) (*dbstruct.ZoneCollaborator, error) { + zoneCollaborator := &dbstruct.ZoneCollaborator{} + col := m.getColZoneCollaborator() + query := qmgo.M{ + "_id": id, + "del_flag": 0, + } + + err := col.Find(ctx, query).One(&zoneCollaborator) + if err == qmgo.ErrNoSuchDocuments { + err = nil + return nil, err + } + return zoneCollaborator, err +} + +func (m *Mongo) CreateZoneCollaboratorHis(ctx *gin.Context, zone_collaborator *dbstruct.ZoneCollaborator) error { + col := m.getColZoneCollaboratorHis() + _, err := col.InsertOne(ctx, zone_collaborator) + return err +} + // 空间代运营表相关 func (m *Mongo) CreateZoneThirdPartner(ctx *gin.Context, zone_third_partner *dbstruct.ZoneThirdPartner) error { col := m.getColZoneThirdPartner() @@ -4586,12 +4615,7 @@ func (m *Mongo) UpdateZoneThirdPartner(ctx *gin.Context, zone_third_partner *dbs func (m *Mongo) DeleteZoneThirdPartner(ctx *gin.Context, id int64) error { col := m.getColZoneThirdPartner() - update := qmgo.M{ - "$set": qmgo.M{ - "del_flag": 1, - }, - } - err := col.UpdateId(ctx, id, update) + err := col.RemoveId(ctx, id) return err } @@ -4639,6 +4663,26 @@ func (m *Mongo) GetZoneThirdPartnerByZid(ctx *gin.Context, zid int64) (*dbstruct return &one, err } +func (m *Mongo) GetZoneThirdPartnerById(ctx *gin.Context, id int64) (*dbstruct.ZoneThirdPartner, error) { + one := dbstruct.ZoneThirdPartner{} + col := m.getColZoneThirdPartner() + query := qmgo.M{ + "zid": id, + "del_flag": 0, + } + err := col.Find(ctx, query).One(&one) + if err == qmgo.ErrNoSuchDocuments { + return nil, nil + } + return &one, err +} + +func (m *Mongo) CreateZoneThirdPartnerHis(ctx *gin.Context, zone_third_partner *dbstruct.ZoneThirdPartner) error { + col := m.getColZoneThirdPartnerHis() + _, err := col.InsertOne(ctx, zone_third_partner) + return err +} + // 动态创建频次 func (m *Mongo) GetAndUpdateZoneMomentCreateTimes(ctx *gin.Context, mid int64) (momentCreateTimes *dbstruct.ZoneMomentCreateTimes, err error) { col := m.getColZoneMomentCreateTimes() diff --git a/app/mix/service/logic/zone_collaborator.go b/app/mix/service/logic/zone_collaborator.go index 59f022dc..c1203e21 100644 --- a/app/mix/service/logic/zone_collaborator.go +++ b/app/mix/service/logic/zone_collaborator.go @@ -10,6 +10,7 @@ import ( "time" "github.com/gin-gonic/gin" + "github.com/qiniu/qmgo" goproto "google.golang.org/protobuf/proto" ) @@ -55,7 +56,28 @@ func (p *ZoneCollaborator) OpUpdate(ctx *gin.Context, req *zone_collaborator_pro } func (p *ZoneCollaborator) OpDelete(ctx *gin.Context, id int64) error { - err := p.store.DeleteZoneCollaborator(ctx, id) + + //1.查出原协作者信息 + zoneCollaborator, err := p.store.GetZoneCollaboratorById(ctx, id) + if zoneCollaborator == nil { + logger.Error("GetZoneCollaboratorById fail, err: %v", qmgo.ErrNoSuchDocuments) + return qmgo.ErrNoSuchDocuments + } + if err != nil { + logger.Error("GetZoneCollaboratorById fail, err: %v", err) + return err + } + + //2.原协作者记录标记删除后转存到历史表 + zoneCollaborator.DelFlag = goproto.Int64(consts.Deleted) + err = p.store.CreateZoneCollaboratorHis(ctx, zoneCollaborator) + if err != nil { + logger.Error("CreateZoneCollaboratorHis fail, err: %v", err) + return err + } + + //3.真删除原有协作者记录 + err = p.store.DeleteZoneCollaborator(ctx, id) if err != nil { logger.Error("DeleteZoneCollaborator fail, err: %v", err) return err diff --git a/app/mix/service/logic/zone_third_partner.go b/app/mix/service/logic/zone_third_partner.go index 4d95e122..cd4d9624 100644 --- a/app/mix/service/logic/zone_third_partner.go +++ b/app/mix/service/logic/zone_third_partner.go @@ -11,6 +11,7 @@ import ( "time" "github.com/gin-gonic/gin" + "github.com/qiniu/qmgo" goproto "google.golang.org/protobuf/proto" ) @@ -48,7 +49,28 @@ func (p *ZoneThirdPartner) OpUpdate(ctx *gin.Context, req *zone_third_partner_pr } func (p *ZoneThirdPartner) OpDelete(ctx *gin.Context, id int64) error { - err := p.store.DeleteZoneThirdPartner(ctx, id) + + //1.查出原协作者信息 + zoneThirdPartner, err := p.store.GetZoneThirdPartnerById(ctx, id) + if zoneThirdPartner == nil { + logger.Error("GetZoneThirdPartnerById fail, err: %v", qmgo.ErrNoSuchDocuments) + return qmgo.ErrNoSuchDocuments + } + if err != nil { + logger.Error("GetZoneThirdPartnerById fail, err: %v", err) + return err + } + + //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 + } + + //3.真删除原有协作者记录 + err = p.store.DeleteZoneThirdPartner(ctx, id) if err != nil { logger.Error("DeleteZoneThirdPartner fail, err: %v", err) return err