Commit 406c237b authored by hujiebin's avatar hujiebin

trust

parent 2fcefb22
package headwear_cv package headwear_cv
import ( import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm" "gorm.io/gorm"
"hilo-user/_const/enum/headwear_e" "hilo-user/_const/enum/headwear_e"
"hilo-user/domain/model/cp_m"
"hilo-user/domain/model/res_m" "hilo-user/domain/model/res_m"
"hilo-user/domain/model/user_m" "hilo-user/domain/model/user_m"
"hilo-user/myerr" "hilo-user/myerr"
...@@ -17,6 +19,7 @@ type CvHeadwear struct { ...@@ -17,6 +19,7 @@ type CvHeadwear struct {
PicUrl mysql.Str `json:"picUrl"` PicUrl mysql.Str `json:"picUrl"`
EffectUrl mysql.Str `json:"effectUrl"` EffectUrl mysql.Str `json:"effectUrl"`
TimeLeft int64 `json:"timeLeft"` // 离到期还有多少秒(过期则是负数) TimeLeft int64 `json:"timeLeft"` // 离到期还有多少秒(过期则是负数)
HeadwearIcon string `json:"headwearIcon"`
} }
type CvHeadwearDiamond struct { type CvHeadwearDiamond struct {
...@@ -69,7 +72,7 @@ func GetHeadwearList(db *gorm.DB, userId uint64) ([]CvHeadwear, error) { ...@@ -69,7 +72,7 @@ func GetHeadwearList(db *gorm.DB, userId uint64) ([]CvHeadwear, error) {
} }
} }
// 如果没有一个using,则找第一个没过期的充当 // 如果没有一个using,则找第一个没过期的充当
if ! hasUsing { if !hasUsing {
for i, e := range result { for i, e := range result {
if e.TimeLeft > 0 { if e.TimeLeft > 0 {
result[i].Using = true result[i].Using = true
...@@ -128,6 +131,28 @@ func BatchGetCvHeadwears(userIds []uint64) (map[uint64]CvHeadwear, error) { ...@@ -128,6 +131,28 @@ func BatchGetCvHeadwears(userIds []uint64) (map[uint64]CvHeadwear, error) {
for i, _ := range resHeadwears { for i, _ := range resHeadwears {
resHeadwearMap[resHeadwears[i].ID] = resHeadwears[i] 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) result := make(map[uint64]CvHeadwear, 0)
for _, r := range rows { for _, r := range rows {
...@@ -138,6 +163,7 @@ func BatchGetCvHeadwears(userIds []uint64) (map[uint64]CvHeadwear, error) { ...@@ -138,6 +163,7 @@ func BatchGetCvHeadwears(userIds []uint64) (map[uint64]CvHeadwear, error) {
PicUrl: headwear.PicUrl, PicUrl: headwear.PicUrl,
EffectUrl: headwear.EffectUrl, EffectUrl: headwear.EffectUrl,
Using: r.Using == headwear_e.YesUsing, Using: r.Using == headwear_e.YesUsing,
HeadwearIcon: response[r.UserId],
} }
} }
...@@ -145,4 +171,3 @@ func BatchGetCvHeadwears(userIds []uint64) (map[uint64]CvHeadwear, error) { ...@@ -145,4 +171,3 @@ func BatchGetCvHeadwears(userIds []uint64) (map[uint64]CvHeadwear, error) {
return result, nil 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