From c8820000a270526de41c91fa0add6958027c38a8 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Mon, 26 Jun 2023 15:49:15 +0800 Subject: [PATCH] feat:promotionAgetns --- domain/model/promotion_m/model.go | 30 +++++++++++ domain/model/promotion_m/promotion_info.go | 63 ++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 domain/model/promotion_m/model.go create mode 100644 domain/model/promotion_m/promotion_info.go diff --git a/domain/model/promotion_m/model.go b/domain/model/promotion_m/model.go new file mode 100644 index 0000000..fbdc5b4 --- /dev/null +++ b/domain/model/promotion_m/model.go @@ -0,0 +1,30 @@ +package promotion_m + +import "git.hilo.cn/hilo-common/resource/mysql" + +// 推广员 +type PromotionAgent struct { + mysql.Entity + ManagerId mysql.ID + AgentId mysql.ID +} + +// 邀请关系 +type PromotionInvite struct { + mysql.Entity + ManagerId mysql.ID + AgentId mysql.ID + Invitee mysql.ID + Platform string + PlatformId string + Reason string + InviteDate string +} + +// 邀请关系日志 +type PromotionInviteLog struct { + mysql.Entity + AgentId mysql.ID + Invitee mysql.ID + AddReduce mysql.AddReduce +} diff --git a/domain/model/promotion_m/promotion_info.go b/domain/model/promotion_m/promotion_info.go new file mode 100644 index 0000000..a91bc30 --- /dev/null +++ b/domain/model/promotion_m/promotion_info.go @@ -0,0 +1,63 @@ +package promotion_m + +import ( + "git.hilo.cn/hilo-common/domain" + "git.hilo.cn/hilo-common/resource/mysql" + "gorm.io/gorm" +) + +// 获取推广员平台 +func GetPromotionPlatforms(model *domain.Model) []string { + return []string{"Falla", "Yalla", "Whisper", "Ahlan", "Mashi", "YoYo", "Yoho", "Echo", "Hawa", "Yalla Ludo", "Hafla"} +} + +// 检查是否推广员 +func IsPromotionAgent(model *domain.Model, userId mysql.ID) bool { + var promotionAgent PromotionAgent + if err := model.Db.Model(PromotionAgent{}).Where("agent_id = ?", userId).First(&promotionAgent).Error; err != nil { + if err != gorm.ErrRecordNotFound { + model.Log.Errorf("IsPromotionAgent fail:%v", err) + } + } else if promotionAgent.ID > 0 { + return true + } + return false +} + +// 检查被邀请人是否存在 +func IsPromotionInvitee(model *domain.Model, userId mysql.ID) (bool, error) { + var promotionInvite PromotionInvite + if err := model.Db.Model(PromotionInvite{}).Where("invitee = ?", userId).First(&promotionInvite).Error; err != nil { + if err != gorm.ErrRecordNotFound { + return false, err + } + return false, nil + } + // err == nil, record exists + return true, nil +} + +// 添加推广邀请关系 +func AddPromotionInvite(model *domain.Model, managerId, agentId, invitee mysql.ID, platform, platformId, reason, inviteDate string) error { + if err := model.Db.Create(&PromotionInvite{ + ManagerId: managerId, + AgentId: agentId, + Invitee: invitee, + Platform: platform, + PlatformId: platformId, + Reason: reason, + InviteDate: inviteDate, + }).Error; err != nil { + return err + } + return addPromotionInviteLog(model, agentId, invitee, mysql.ADD) +} + +// 添加推广邀请关系-日志 +func addPromotionInviteLog(model *domain.Model, agentId, invitee mysql.ID, addReduce mysql.AddReduce) error { + return model.Db.Create(&PromotionInviteLog{ + AgentId: agentId, + Invitee: invitee, + AddReduce: addReduce, + }).Error +} -- 2.22.0