package db import ( "context" "strings" "youngee_b_api/model/gorm_model" "youngee_b_api/model/http_model" ) func FindUserInfoByTalentId(ctx context.Context, talentId string) (*gorm_model.PlatformKuaishouUserInfo, error) { db := GetReadDB(ctx) var userInfo gorm_model.PlatformKuaishouUserInfo err := db.Model(gorm_model.PlatformKuaishouUserInfo{}).Where("talent_id = ? and platform_id = ?", talentId, 4).Find(&userInfo).Error if err != nil { return nil, err } return &userInfo, nil } // FindUserInfoByOpenId 根据openID去查找快手授权信息 func FindUserInfoByOpenId(ctx context.Context, openId string) (*gorm_model.PlatformKuaishouUserInfo, error) { db := GetReadDB(ctx) var userInfo gorm_model.PlatformKuaishouUserInfo err := db.Model(gorm_model.PlatformKuaishouUserInfo{}).Where("open_id = ? and platform_id = ?", openId, 4).Find(&userInfo).Error if err != nil { return nil, err } return &userInfo, nil } func GetProvince(ctx context.Context, request http_model.GetProviceRequest) (*http_model.GetProviceResponse, error) { db := GetReadDB(ctx) var userInfo []gorm_model.PlatformKuaishouUserInfo // 从数据库中获取所有 city 字段的数据 err := db.Model(&gorm_model.PlatformKuaishouUserInfo{}).Pluck("city", &userInfo).Error if err != nil { return nil, err } // 使用 map 来去重省份 provinceMap := make(map[string]struct{}) for _, user := range userInfo { if user.City != "" { // 按照空格分割 city 字段,取第一个部分作为省份 cityParts := strings.Split(user.City, " ") if len(cityParts) > 0 { provinceMap[cityParts[0]] = struct{}{} // 使用空结构体来去重 } } } // 将 map 中的省份名称放入切片 var provinces []string for province := range provinceMap { provinces = append(provinces, province) } // 返回省份列表 return &http_model.GetProviceResponse{ Provices: provinces, }, nil }