package user_s import ( "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/mycontext" "git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/rpc" "gorm.io/gorm" "hilo-user/cv/headwear_cv" "hilo-user/cv/medal_cv" "hilo-user/cv/property_cv" "hilo-user/cv/user_cv" "hilo-user/domain/model/group_m" "hilo-user/domain/model/noble_m" "hilo-user/domain/model/user_m" "hilo-user/myerr" ) type UserService struct { svc *domain.Service } func NewUserService(myContext *mycontext.MyContext) *UserService { svc := domain.CreateService(myContext) return &UserService{svc} } //用户基本信息 func (s *UserService) GetUserDetail(userId mysql.ID, myUserId mysql.ID, lang ...string) (*user_cv.CvUserDetail, error) { model := domain.CreateModelContext(s.svc.MyContext) model.Log.Infof("GetUserDetail %d begin", userId) var user user_m.User var err error if err = model.DB().First(&user, userId).Error; err != nil { return nil, myerr.WrapErr(err) } //统计喜欢 var likeN int64 if err := model.DB().Model(&user_m.UserLike{}).Where(&user_m.UserLike{ UserId: myUserId, LikeUserId: userId, }).Count(&likeN).Error; err != nil { return nil, myerr.WrapErr(err) } var likeMe int64 if err := model.DB().Model(&user_m.UserLike{}).Where(&user_m.UserLike{ UserId: userId, LikeUserId: myUserId, }).Count(&likeMe).Error; err != nil { return nil, myerr.WrapErr(err) } rel := make(map[mysql.ID]user_m.Relation, 1) rel[userId], _ = user_m.GetRelation(model, myUserId, userId) var wealthUserScore user_m.MatchWealthUserScore if err := mysql.Db.Model(&user_m.MatchWealthUserScore{}).Where(&user_m.MatchWealthUserScore{UserId: userId}).First(&wealthUserScore).Error; err != nil { if err != nil { if err == gorm.ErrRecordNotFound { wealthUserScore = user_m.MatchWealthUserScore{ UserId: userId, Score: 0, Grade: 0, } } else { return nil, myerr.WrapErr(err) } } } var charmUserScore user_m.MatchCharmUserScore if err := mysql.Db.Model(&user_m.MatchCharmUserScore{}).Where(&user_m.MatchCharmUserScore{ UserId: userId, }).First(&charmUserScore).Error; err != nil { if err != nil { if err == gorm.ErrRecordNotFound { charmUserScore = user_m.MatchCharmUserScore{ UserId: userId, Score: 0, Grade: 0, } } else { return nil, myerr.WrapErr(err) } } } var activityUserScore user_m.MatchActityUserScore if err := mysql.Db.Model(&user_m.MatchActityUserScore{}).Where(&user_m.MatchActityUserScore{ UserId: userId, }).First(&activityUserScore).Error; err != nil { if err != nil { if err == gorm.ErrRecordNotFound { activityUserScore = user_m.MatchActityUserScore{ UserId: userId, Score: 0, Grade: 0, } } else { return nil, myerr.WrapErr(err) } } } isVip, expireTime, err := user_m.IsVip(userId) if err != nil { return nil, myerr.WrapErr(err) } svip, err := rpc.GetUserSvip(model, userId) if err != nil { return nil, myerr.WrapErr(err) } headwear, err := headwear_cv.GetCvHeadwear(userId) if err != nil { return nil, err } medals := make(map[uint64][]uint32, 0) medals[userId], err = user_m.GetUserMedalMerge(model.Log, mysql.Db, userId) if err != nil { return nil, err } medals, medalInfo, err := medal_cv.GetMedalInfoMap(mysql.Db, medals) if err != nil { return nil, err } rooms, err := group_m.RoomLivingUserIdFilter(model, []uint64{userId}) if err != nil { return nil, err } // 2022-05-13 个人详情页:当用户在加锁的房间时,不显示进入房间的图标 if g, ok := rooms[userId]; ok { gi, err := group_m.GetGroupInfo(model, g) if err != nil { return nil, err } if gi != nil && len(gi.Password) > 0 { rooms[userId] = "" } } cp, _ := rpc.GetUserCp(model, userId, lang...) // todo last groupPowerId, groupPowerName, err := groupPower_m.GetUserGroupPower(model, userId) if err != nil { return nil, err } powers := map[mysql.ID]uint64{userId: groupPowerId} powerNames := map[mysql.ID]string{userId: groupPowerName} groupPower, _ := rpc.GetGroupPower(model, groupPowerId) up := user_m.UserProperty{} rides, err := up.BatchGet(mysql.Db, []uint64{userId}) if err != nil { return nil, err } //rp := res_m.ResProperty{} //properties, err := rp.GetAll(mysql.Db) properties, err := property_cv.GetPropertyAll(mysql.Db) if err != nil { return nil, err } ride := property_cv.CvProperty{ Id: rides[user.ID], PicUrl: properties[rides[user.ID]].PicUrl, EffectUrl: properties[rides[user.ID]].EffectUrl, SenderAvatar: properties[rides[user.ID]].SenderAvatar, ReceiverAvatar: properties[rides[user.ID]].ReceiverAvatar, Using: true, } noble, err := noble_m.FindActiveNoble(mysql.Db, userId) if err != nil { return nil, err } //判断是不是工会 userTradeUnion, err := bv.GetUserTradeUnion(myUserId) if err != nil { return nil, err } superManagerMap, err := GetSuperManagerMap([]uint64{userId}) if err != nil { return nil, err } // 群组信息 myGroups, err := group_m.FindGroupByOwner(model, userId) if err != nil { return nil, err } // 手机绑定信息 // 第三方账号绑定信息 phoneInfo := new(model2.UserPhoneInfo) var thirdList []int8 if userId == myUserId { thirdList = make([]int8, 0, 5) // 手机绑定信息 bindInfo, err := dao.UserBindInfoDb.GetByUserId(userId) if err != nil && err != gorm.ErrRecordNotFound { return nil, err } if bindInfo != nil { if len(bindInfo.Phone) > 2 { phoneInfo.Phone = bindInfo.Phone[:2] + "****" + bindInfo.Phone[len(bindInfo.Phone)-2:] } phoneInfo.PhoneCountry = bindInfo.PhoneCountry phoneInfo.AreaCode = bindInfo.AreaCode phoneInfo.Icon = bindInfo.Icon thirdList = append(thirdList, 1) } // 第三方账号绑定信息 thirdInfoList, err := dao.UserOauthDb.GetByUserId(userId, 0) if err != nil { return nil, err } if thirdInfoList != nil { for _, v := range thirdInfoList { thirdList = append(thirdList, v.ThirdPartyType) } } } // 国家管理员 countryManager, err := country_m.GetCountryMgr(model, userId) if err != nil { return nil, err } var cvCountryManager *CVCountryManager if countryManager != nil { cvCountryManager = &CVCountryManager{ Country: countryManager.Country, Role: countryManager.Role, } } return userToDetailOne(model, &user, myUserId, userTradeUnion, likeN > 0, likeMe > 0, rel, isVip, expireTime, svip, headwear, ride, wealthUserScore.Grade, charmUserScore.Grade, activityUserScore.Grade, medals[userId], medalInfo[userId], rooms[userId], powers[userId], powerNames[userId], groupPower, noble, superManagerMap[userId], myGroups, phoneInfo, thirdList, cvCountryManager, cp) }