Commit 406c237b authored by hujiebin's avatar hujiebin

trust

parent 2fcefb22
package headwear_cv
import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
"hilo-user/_const/enum/headwear_e"
"hilo-user/domain/model/cp_m"
"hilo-user/domain/model/res_m"
"hilo-user/domain/model/user_m"
"hilo-user/myerr"
......@@ -12,11 +14,12 @@ import (
)
type CvHeadwear struct {
Id uint64 `json:"id"`
Using bool `json:"using"`
PicUrl mysql.Str `json:"picUrl"`
EffectUrl mysql.Str `json:"effectUrl"`
TimeLeft int64 `json:"timeLeft"` // 离到期还有多少秒(过期则是负数)
Id uint64 `json:"id"`
Using bool `json:"using"`
PicUrl mysql.Str `json:"picUrl"`
EffectUrl mysql.Str `json:"effectUrl"`
TimeLeft int64 `json:"timeLeft"` // 离到期还有多少秒(过期则是负数)
HeadwearIcon string `json:"headwearIcon"`
}
type CvHeadwearDiamond struct {
......@@ -69,7 +72,7 @@ func GetHeadwearList(db *gorm.DB, userId uint64) ([]CvHeadwear, error) {
}
}
// 如果没有一个using,则找第一个没过期的充当
if ! hasUsing {
if !hasUsing {
for i, e := range result {
if e.TimeLeft > 0 {
result[i].Using = true
......@@ -128,16 +131,39 @@ func BatchGetCvHeadwears(userIds []uint64) (map[uint64]CvHeadwear, error) {
for i, _ := range resHeadwears {
resHeadwearMap[resHeadwears[i].ID] = resHeadwears[i]
}
// cp 相关
var model = domain.CreateModelNil()
cpRelations := cp_m.MGetCpRelation(model, userIds)
var m = make(map[uint64]cp_m.CpRelation)
var cpUserIds []uint64
for i, v := range cpRelations {
m[v.UserId1] = cpRelations[i]
m[v.UserId2] = cpRelations[i]
cpUserIds = append(cpUserIds, v.UserId1)
cpUserIds = append(cpUserIds, v.UserId2)
}
users, _ := user_m.GetUserMapByIds(model, cpUserIds)
var response = make(map[uint64]string)
for _, uid := range userIds {
if cpRelation, ok := m[uid]; ok {
cpUserId := cpRelation.UserId2
if cpUserId == uid {
cpUserId = cpRelation.UserId1
}
response[uid] = users[cpUserId].Avatar
}
}
result := make(map[uint64]CvHeadwear, 0)
for _, r := range rows {
headwear, flag := resHeadwearMap[r.HeadwearId]
if flag {
result[r.UserId] = CvHeadwear{
Id: headwear.ID,
PicUrl: headwear.PicUrl,
EffectUrl: headwear.EffectUrl,
Using: r.Using == headwear_e.YesUsing,
Id: headwear.ID,
PicUrl: headwear.PicUrl,
EffectUrl: headwear.EffectUrl,
Using: r.Using == headwear_e.YesUsing,
HeadwearIcon: response[r.UserId],
}
}
......@@ -145,4 +171,3 @@ func BatchGetCvHeadwears(userIds []uint64) (map[uint64]CvHeadwear, error) {
return result, nil
}
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