Commit 33487c6e authored by hujiebin's avatar hujiebin

feat:去掉tmp

parent 0e1cc5ac
......@@ -27,7 +27,7 @@ type CpAnniversary struct {
// 初始化6个cp纪念日
// 1)我们在一起;2)XXX的生日;3)XXX的生日;4)第一次说我爱你;5)第一次亲吻;6)结婚纪念日
func InitCpAnniversary(model *domain.Model, cp CpRelationTmp, lang string) error {
func InitCpAnniversary(model *domain.Model, cp CpRelation, lang string) error {
users, err := user_m.GetUserMapByIds(model, []uint64{cp.UserId1, cp.UserId2})
if err != nil {
return err
......@@ -68,9 +68,9 @@ func GetTranslate(msgId uint, lang string) string {
}
// 添加cp纪念日
func AddCpAnniversary(model *domain.Model, Type cp_e.AnniversaryItemType, cp CpRelationTmp, content string, ts int64, isRemind bool, sort int) error {
func AddCpAnniversary(model *domain.Model, Type cp_e.AnniversaryItemType, cp CpRelation, content string, ts int64, isRemind bool, sort int) error {
return model.DB().Model(CpAnniversary{}).Create(&CpAnniversary{
CpId: cp.ID,
CpId: cp.Id,
Type: Type,
UserId1: cp.UserId1,
UserId2: cp.UserId2,
......@@ -103,7 +103,7 @@ func GetAllCpAnniversary(model *domain.Model, userId mysql.ID) []CpAnniversary {
if !exists {
return res
}
if err := model.DB().Model(CpAnniversary{}).Where("cp_id = ?", relation.ID).Order("`sort` DESC,updated_time DESC,id ASC").Find(&res).Error; err != nil {
if err := model.DB().Model(CpAnniversary{}).Where("cp_id = ?", relation.Id).Order("`sort` DESC,updated_time DESC,id ASC").Find(&res).Error; err != nil {
model.Log.Errorf("GetAllCpAnniversary fail:%v", err)
}
return res
......
......@@ -11,27 +11,6 @@ import (
"time"
)
type CpRelationTmp struct {
mysql.Entity
UserId1 mysql.ID
UserId2 mysql.ID
}
func (CpRelationTmp) TableName() string {
return "cp_relation"
}
type CpCancelTmp struct {
mysql.Entity
UserId mysql.ID
RecUserId mysql.ID
Status int // 状态1.未处理2.发起者已撤销3.对方已确认4.到期自动确认
}
func (CpCancelTmp) TableName() string {
return "cp_cancel"
}
// cp等级
type CpLevel struct {
mysql.Entity
......@@ -84,8 +63,8 @@ func AddCpLevelDetail(model *domain.Model, detail CpLevelDetail) error {
}
// 获取cpRelation
func GetCpRelation(model *domain.Model, userId mysql.ID) (cpRelation CpRelationTmp, exits bool) {
if err := model.DB().Model(CpRelationTmp{}).Where("user_id1 = ? or user_id2 = ?", userId, userId).First(&cpRelation).Error; err != nil {
func GetCpRelation(model *domain.Model, userId mysql.ID) (cpRelation CpRelation, exits bool) {
if err := model.DB().Model(CpRelation{}).Where("user_id1 = ? or user_id2 = ?", userId, userId).First(&cpRelation).Error; err != nil {
if err != gorm.ErrRecordNotFound {
model.Log.Errorf("GetCpRelation fail:%v", err)
return
......@@ -97,14 +76,14 @@ func GetCpRelation(model *domain.Model, userId mysql.ID) (cpRelation CpRelationT
}
// 获取cpRelation pair
func GetCpRelationPair(model *domain.Model, userId1, userId2 mysql.ID) (cpRelation CpRelationTmp, exits bool) {
if err := model.DB().Model(CpRelationTmp{}).Where("user_id1 = ? AND user_id2 = ?", userId1, userId2).First(&cpRelation).Error; err != nil {
func GetCpRelationPair(model *domain.Model, userId1, userId2 mysql.ID) (cpRelation CpRelation, exits bool) {
if err := model.DB().Model(CpRelation{}).Where("user_id1 = ? AND user_id2 = ?", userId1, userId2).First(&cpRelation).Error; err != nil {
if err != gorm.ErrRecordNotFound {
model.Log.Errorf("GetCpRelation fail:%v", err)
return
} else {
// gorm.ErrRecordNotFound
if err := model.DB().Model(CpRelationTmp{}).Where("user_id1 = ? AND user_id2 = ?", userId2, userId1).First(&cpRelation).Error; err != nil {
if err := model.DB().Model(CpRelation{}).Where("user_id1 = ? AND user_id2 = ?", userId2, userId1).First(&cpRelation).Error; err != nil {
if err != gorm.ErrRecordNotFound {
model.Log.Errorf("GetCpRelation fail:%v", err)
return
......@@ -120,8 +99,8 @@ func GetCpRelationPair(model *domain.Model, userId1, userId2 mysql.ID) (cpRelati
}
// 获取cpRelation pair
func MGetCpRelation(model *domain.Model, userIds []mysql.ID) (cpRelation []CpRelationTmp) {
if err := model.DB().Model(CpRelationTmp{}).Where("user_id1 in ? or user_id2 in ?", userIds, userIds).Find(&cpRelation).Error; err != nil {
func MGetCpRelation(model *domain.Model, userIds []mysql.ID) (cpRelation []CpRelation) {
if err := model.DB().Model(CpRelation{}).Where("user_id1 in ? or user_id2 in ?", userIds, userIds).Find(&cpRelation).Error; err != nil {
model.Log.Errorf("GetCpRelation fail:%v", err)
}
return
......@@ -130,7 +109,7 @@ func MGetCpRelation(model *domain.Model, userIds []mysql.ID) (cpRelation []CpRel
// 获取是否申请解绑中
func GetApplyToUnbind(model *domain.Model, userId, cpUserId mysql.ID) bool {
var total int64
if err := model.DB().Table(CpCancelTmp{}.TableName()).Where("user_id = ? AND rec_user_id = ? AND status = 1", userId, cpUserId).Count(&total).Error; err != nil {
if err := model.DB().Model(CpCancel{}).Where("user_id = ? AND rec_user_id = ? AND status = 1", userId, cpUserId).Count(&total).Error; err != nil {
model.Log.Errorf("GetApplyToUnbind fail:%v", err)
}
return total > 0
......@@ -153,20 +132,20 @@ func InitCpLevel(model *domain.Model, cpId, userId1, userId2 mysql.ID) error {
// 2.记录存在
// 2.1 在有效期内,直接加points后判断新level,升级需要更新有效期
// 2.2 不有效期内,算首充,重置points后判断新level,升级需要更新有效期
func AddCpLevelPoints(model *domain.Model, cpRelation CpRelationTmp, points mysql.Num) (err error) {
func AddCpLevelPoints(model *domain.Model, cpRelation CpRelation, points mysql.Num) (err error) {
start := time.Now()
defer func() {
model.Log.Infof("AddCpLevelPoints cost:%v,err:%v", time.Now().Sub(start), err)
}()
var cpLevel CpLevel
var cpLevelDetails []CpLevelDetail
if err := model.DB().Model(CpLevel{}).Where("cp_id = ?", cpRelation.ID).First(&cpLevel).Error; err != nil {
if err := model.DB().Model(CpLevel{}).Where("cp_id = ?", cpRelation.Id).First(&cpLevel).Error; err != nil {
if err != gorm.ErrRecordNotFound {
return myerr.WrapErr(err)
}
// 明细
cpLevelDetails = append(cpLevelDetails, CpLevelDetail{
CpId: cpRelation.ID,
CpId: cpRelation.Id,
UserId1: cpRelation.UserId1,
UserId2: cpRelation.UserId2,
AddReduce: mysql.ADD,
......@@ -187,7 +166,7 @@ func AddCpLevelPoints(model *domain.Model, cpRelation CpRelationTmp, points mysq
points = points - cp_e.CpLevelPoints[level] // 减去用于已用于升级的积分
// 明细
cpLevelDetails = append(cpLevelDetails, CpLevelDetail{
CpId: cpRelation.ID,
CpId: cpRelation.Id,
UserId1: cpRelation.UserId1,
UserId2: cpRelation.UserId2,
AddReduce: mysql.REDUCE,
......@@ -198,7 +177,7 @@ func AddCpLevelPoints(model *domain.Model, cpRelation CpRelationTmp, points mysq
})
}
cpLevel = CpLevel{
CpId: cpRelation.ID,
CpId: cpRelation.Id,
UserId1: cpRelation.UserId1,
UserId2: cpRelation.UserId2,
Points: points,
......@@ -212,7 +191,7 @@ func AddCpLevelPoints(model *domain.Model, cpRelation CpRelationTmp, points mysq
cpLevel.Points += points
// 明细
cpLevelDetails = append(cpLevelDetails, CpLevelDetail{
CpId: cpRelation.ID,
CpId: cpRelation.Id,
UserId1: cpRelation.UserId1,
UserId2: cpRelation.UserId2,
AddReduce: mysql.ADD,
......@@ -236,7 +215,7 @@ func AddCpLevelPoints(model *domain.Model, cpRelation CpRelationTmp, points mysq
cpLevel.ExpireAt = time.Now().AddDate(0, 0, cp_e.EffectDays)
// 明细
cpLevelDetails = append(cpLevelDetails, CpLevelDetail{
CpId: cpRelation.ID,
CpId: cpRelation.Id,
UserId1: cpRelation.UserId1,
UserId2: cpRelation.UserId2,
AddReduce: mysql.REDUCE,
......@@ -252,7 +231,7 @@ func AddCpLevelPoints(model *domain.Model, cpRelation CpRelationTmp, points mysq
cpLevel.Points = points
// 明细
cpLevelDetails = append(cpLevelDetails, CpLevelDetail{
CpId: cpRelation.ID,
CpId: cpRelation.Id,
UserId1: cpRelation.UserId1,
UserId2: cpRelation.UserId2,
AddReduce: mysql.ADD,
......@@ -271,7 +250,7 @@ func AddCpLevelPoints(model *domain.Model, cpRelation CpRelationTmp, points mysq
cpLevel.Points -= cp_e.CpLevelPoints[cpLevel.Level] // 减去已用于升级的积分
// 明细
cpLevelDetails = append(cpLevelDetails, CpLevelDetail{
CpId: cpRelation.ID,
CpId: cpRelation.Id,
UserId1: cpRelation.UserId1,
UserId2: cpRelation.UserId2,
AddReduce: mysql.REDUCE,
......
......@@ -19,11 +19,11 @@ type CpDayRank struct {
}
// 增加cp排行榜-天
func AddCpDayRank(model *domain.Model, cpRelation CpRelationTmp, score mysql.Num) (err error) {
func AddCpDayRank(model *domain.Model, cpRelation CpRelation, score mysql.Num) (err error) {
date := time.Now().Format("2006-01-02")
rank := &CpDayRank{
Date: date,
CpId: cpRelation.ID,
CpId: cpRelation.Id,
UserId1: cpRelation.UserId1,
UserId2: cpRelation.UserId2,
Score: score,
......
......@@ -33,7 +33,7 @@ func CpGiftEvent() {
model.Log.Errorf("AddCpDayRank fail:%v", err)
}
// 检查最新的等级
if cpLevel := cp_m.GetCpLevel(model, cpRelation.ID); cpLevel.CpId >= 0 {
if cpLevel := cp_m.GetCpLevel(model, cpRelation.Id); cpLevel.CpId >= 0 {
points := cpLevel.Points + cp_e.CpLevelPoints[cpLevel.Level]
if err := cp_m.UpdateCpAchievement(model, cpLevel.CpId, cpRelation.UserId1, cpRelation.UserId2, cp_e.CpAchievementLevel, points); err != nil {
model.Log.Errorf("UpdateCpAchievement fail:%v", err)
......@@ -56,8 +56,8 @@ func CpGiftEvent() {
endDate = now.EndOfMonth().Format("2006-01-02")
cpAchievementType = cp_e.CpAchievementMonthRank
}
if data := cp_m.GetCpDayRank(model, beginDate, endDate, cpRelation.ID); data.Score > 0 {
if err := cp_m.UpdateCpAchievement(model, cpRelation.ID, cpRelation.UserId1, cpRelation.UserId2, cpAchievementType, data.Score); err != nil {
if data := cp_m.GetCpDayRank(model, beginDate, endDate, cpRelation.Id); data.Score > 0 {
if err := cp_m.UpdateCpAchievement(model, cpRelation.Id, cpRelation.UserId1, cpRelation.UserId2, cpAchievementType, data.Score); err != nil {
model.Log.Errorf("UpdateCpAchievement fail:%v", err)
}
}
......
......@@ -204,8 +204,8 @@ func ReplyCpInvite(c *gin.Context) (*mycontext.MyContext, error) {
return err
}
// 初始化cp纪念日
if err := cp_m.InitCpAnniversary(model, cp_m.CpRelationTmp{
Entity: mysql.Entity{ID: mysql.ID(cpId)},
if err := cp_m.InitCpAnniversary(model, cp_m.CpRelation{
Id: mysql.ID(cpId),
UserId1: userSender.ID,
UserId2: user.ID,
}, lang); err != nil {
......
......@@ -202,7 +202,7 @@ func CpMy(c *gin.Context) (*mycontext.MyContext, error) {
} else {
userIds = append(userIds, relation.UserId1)
}
rank := cp_m.GetCpDayRank(model, beginDate, endDate, relation.ID)
rank := cp_m.GetCpDayRank(model, beginDate, endDate, relation.Id)
scores = rank.Score
} else {
userIds = append(userIds, userId)
......@@ -213,7 +213,7 @@ func CpMy(c *gin.Context) (*mycontext.MyContext, error) {
return myCtx, err
}
response := cp_cv.CvCpRank{
CpId: relation.ID,
CpId: relation.Id,
Score: scores,
}
if relation.UserId1 > 0 {
......@@ -224,7 +224,7 @@ func CpMy(c *gin.Context) (*mycontext.MyContext, error) {
response.Ranking = "30+"
ranks := cp_m.PageCpDayRank(model, beginDate, endDate, 0, 30)
for i, rank := range ranks {
if relation.ID == rank.CpId {
if relation.Id == rank.CpId {
response.Ranking = fmt.Sprintf("%d", i+1)
break
}
......
......@@ -50,7 +50,7 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) {
nextPoints, curPoints := cp_e.CpLevelPoints[cp_e.CpLevel1], mysql.Num(0)
cpRelation, exists := cp_m.GetCpRelation(model, targetUserInfo.ID)
if exists {
level := cp_m.GetCpLevel(model, cpRelation.ID)
level := cp_m.GetCpLevel(model, cpRelation.Id)
if level.ExpireAt.Before(time.Now()) {
level.ExpireAt = time.Now().AddDate(0, 1, 0)
}
......@@ -60,13 +60,13 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) {
// cp 存在的时候,发布访问cp空间事件
if err := cp_ev.PublishCpSpaceVisit(model, &cp_ev.SpaceVisitEvent{
UserId: userId,
CpId: cpRelation.ID,
CpId: cpRelation.Id,
UserId1: cpRelation.UserId1,
UserId2: cpRelation.UserId2,
}); err != nil {
return myContext, err
}
visitTimes = cp_m.CountCpSpaceVisitors(model, cpRelation.ID)
visitTimes = cp_m.CountCpSpaceVisitors(model, cpRelation.Id)
cpUserId := cpRelation.UserId2
if cpUserId == userId {
cpUserId = cpRelation.UserId1
......@@ -130,7 +130,7 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) {
}
// 需要提醒的纪念日
if exists && (userId == cpRelation.UserId1 || userId == cpRelation.UserId2) {
anniversary := cp_m.GetUserTodayCpAnniversary(model, cpRelation.ID)
anniversary := cp_m.GetUserTodayCpAnniversary(model, cpRelation.Id)
for _, a := range anniversary {
response.CpAnniversary = append(response.CpAnniversary, cp_cv.CvCpAnniversary{
Id: a.ID,
......
......@@ -121,7 +121,7 @@ func GetUserCp(c *gin.Context) (*mycontext.MyContext, error) {
return myContext, nil
}
var myPrivilegeList []cp_cv.CvPrivilege
level := cp_m.GetCpLevel(model, cpRelation.ID)
level := cp_m.GetCpLevel(model, cpRelation.Id)
if level.ExpireAt.Before(time.Now()) {
level.ExpireAt = time.Now().AddDate(0, 1, 0)
}
......@@ -197,7 +197,7 @@ func GetUserCpRelation(c *gin.Context) (*mycontext.MyContext, error) {
}
cpUser, _ := user_m.GetUser(model, cpUserId)
response = cp_cv.CvCpRelation{
CpId: cpRelation.ID,
CpId: cpRelation.Id,
UserId: userId,
CpUserId: cpUserId,
CpUserAvatar: cpUser.Avatar,
......@@ -223,7 +223,7 @@ func MGetUserCpRelation(c *gin.Context) (*mycontext.MyContext, error) {
return myContext, err
}
cpRelations := cp_m.MGetCpRelation(model, req.Ids)
var m = make(map[uint64]cp_m.CpRelationTmp)
var m = make(map[uint64]cp_m.CpRelation)
var userIds []uint64
for i, v := range cpRelations {
m[v.UserId1] = cpRelations[i]
......@@ -243,7 +243,7 @@ func MGetUserCpRelation(c *gin.Context) (*mycontext.MyContext, error) {
cpUserId = cpRelation.UserId1
}
response[uid] = cp_cv.CvCpRelation{
CpId: cpRelation.ID,
CpId: cpRelation.Id,
UserId: uid,
CpUserId: cpUserId,
CpUserAvatar: users[cpUserId].Avatar,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment