diff --git a/domain/model/diamond_m/diamond.go b/domain/model/diamond_m/diamond.go index 22b63b09cd28aa404b98abfea955265d4b46d48e..26b9ff9dbc47111131ff0b101700d77ab9981d8c 100644 --- a/domain/model/diamond_m/diamond.go +++ b/domain/model/diamond_m/diamond.go @@ -1,6 +1,7 @@ package diamond_m import ( + "fmt" "git.hilo.cn/hilo-common/_const/enum/diamond_e" "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/resource/mysql" @@ -37,6 +38,11 @@ type DiamondAccountDetail struct { diamondAccount *DiamondAccount `gorm:"-"` } +func (DiamondAccountDetail) TableName() string { + month := time.Now().Format("200601") + return fmt.Sprintf("diamond_account_detail_%s", month) +} + // 粉钻详情 type DiamondPinkAccountDetail struct { mysql.Entity @@ -107,7 +113,7 @@ func (diamondAccount *DiamondAccount) addDiamondAccountDetail(operateType diamon var count int64 if diamondOperateSet.FrequencyDay == -1 { if diamondOperateSet.FrequencyNum != -1 { - diamondAccount.Db.Model(&DiamondAccountDetail{}).Where(&DiamondAccountDetail{ + diamondAccount.DB().Table(DiamondAccountDetail{}.TableName()).Where(&DiamondAccountDetail{ UserId: diamondAccount.UserId, OperateType: operateType, }).Count(&count) @@ -122,7 +128,7 @@ func (diamondAccount *DiamondAccount) addDiamondAccountDetail(operateType diamon return nil, myerr.WrapErr(err) } //一天的次数 - diamondAccount.Db.Model(&DiamondAccountDetail{}).Where(&DiamondAccountDetail{ + diamondAccount.DB().Table(DiamondAccountDetail{}.TableName()).Where(&DiamondAccountDetail{ UserId: diamondAccount.UserId, OperateType: operateType, }).Where("created_time >= ? ", beginTime).Count(&count) @@ -130,7 +136,7 @@ func (diamondAccount *DiamondAccount) addDiamondAccountDetail(operateType diamon return nil, bizerr.DiamondFrequency } //终极拦截,利用 - diamondAccount.SetCheckUpdateCondition(" EXISTS (SELECT * from (SELECT COUNT(1) as n from diamond_account_detail d where d.user_id = " + strconv.FormatUint(diamondAccount.UserId, 10) + " and d.operate_type = " + strconv.FormatUint(uint64(operateType), 10) + " and d.created_time >= from_unixtime(" + strconv.FormatInt(utils.GetZeroTime(time.Now()).Unix(), 10) + ")) t where t.n < " + strconv.Itoa(diamondOperateSet.FrequencyNum) + " )") + diamondAccount.SetCheckUpdateCondition(" EXISTS (SELECT * from (SELECT COUNT(1) as n from " + DiamondAccountDetail{}.TableName() + " d where d.user_id = " + strconv.FormatUint(diamondAccount.UserId, 10) + " and d.operate_type = " + strconv.FormatUint(uint64(operateType), 10) + " and d.created_time >= from_unixtime(" + strconv.FormatInt(utils.GetZeroTime(time.Now()).Unix(), 10) + ")) t where t.n < " + strconv.Itoa(diamondOperateSet.FrequencyNum) + " )") } //-1,代表值无效,由参数给与 diff --git a/domain/model/diamond_m/repo.go b/domain/model/diamond_m/repo.go index 7b48c1552015245e4cd901f46563f4ac861f1645..be53567148a720ac02668233825af900040f3584 100755 --- a/domain/model/diamond_m/repo.go +++ b/domain/model/diamond_m/repo.go @@ -3,7 +3,6 @@ package diamond_m import ( "git.hilo.cn/hilo-common/resource/mysql" "gorm.io/gorm" - "hilo-user/domain/model" "hilo-user/myerr" "strconv" ) @@ -32,7 +31,10 @@ func (diamondAccountDetail *DiamondAccountDetail) PersistentNoInTransactional() } //持久化diamondAccountDetail - if err := model.Persistent(diamondAccountDetail.Db, diamondAccountDetail); err != nil { + //if err := model.Persistent(diamondAccountDetail.Db, diamondAccountDetail); err != nil { + // return myerr.WrapErr(err) + //} + if err := diamondAccountDetail.DB().Table(diamondAccountDetail.TableName()).Save(diamondAccountDetail).Error; err != nil { return myerr.WrapErr(err) } //改变diamondAccount值 @@ -41,7 +43,7 @@ func (diamondAccountDetail *DiamondAccountDetail) PersistentNoInTransactional() } var newDiamondAccount DiamondAccount - if err := diamondAccountDetail.Db.First(&newDiamondAccount, diamondAccountDetail.diamondAccount.ID).Error; err != nil { + if err := diamondAccountDetail.DB().Table(DiamondAccountDetail{}.TableName()).First(&newDiamondAccount, diamondAccountDetail.diamondAccount.ID).Error; err != nil { return myerr.WrapErr(err) }