1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package res_m
import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
"hilo-group/_const/enum/res_e"
"hilo-group/myerr"
)
type ResGroupSupport struct {
mysql.Entity
*domain.Model `gorm:"-"`
Grade res_e.ResGroupSupportGrade
ContributeUserNum mysql.Num
ContributeDiamondNum mysql.Num
MgrNum mysql.Num
AdminAward mysql.Num
MgrAward mysql.Num
Status mysql.UserYesNo
}
func GetResGroupSupportById(model *domain.Model, id mysql.ID) (ResGroupSupport, error) {
resGroupSupport := ResGroupSupport{}
if err := model.Db.Model(&ResGroupSupport{}).Where(&ResGroupSupport{Status: mysql.USER}).First(&resGroupSupport, id).Error; err != nil {
return ResGroupSupport{}, myerr.WrapErr(err)
}
return resGroupSupport, nil
}
func GetResGroupSupportByValid(model *domain.Model) ([]ResGroupSupport, error) {
resGroupSupports := []ResGroupSupport{}
if err := model.Db.Model(&ResGroupSupport{}).Where(&ResGroupSupport{
Status: mysql.USER,
}).Order("grade asc").Find(&resGroupSupports).Error; err != nil {
return nil, myerr.WrapErr(err)
}
return resGroupSupports, nil
}
func GetResGroupSupportBy(model *domain.Model, contributeUserNum uint32, contributeDiamondNum uint64) (*ResGroupSupport, error) {
resGroupSupport := ResGroupSupport{}
if err := model.Db.Model(&ResGroupSupport{}).Where(&ResGroupSupport{
Status: mysql.USER,
}).Where("contribute_user_num <= ? AND contribute_diamond_num <= ?", contributeUserNum, contributeDiamondNum).Order("grade DESC").First(&resGroupSupport).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return nil, nil
} else {
return nil, myerr.WrapErr(err)
}
}
return &resGroupSupport, nil
}