platform_kuaishou_user.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package db
  2. import (
  3. "context"
  4. "strings"
  5. "youngee_b_api/model/gorm_model"
  6. "youngee_b_api/model/http_model"
  7. )
  8. func FindUserInfoByTalentId(ctx context.Context, talentId string) (*gorm_model.PlatformKuaishouUserInfo, error) {
  9. db := GetReadDB(ctx)
  10. var userInfo gorm_model.PlatformKuaishouUserInfo
  11. err := db.Model(gorm_model.PlatformKuaishouUserInfo{}).Where("talent_id = ? and platform_id = ?", talentId, 4).Find(&userInfo).Error
  12. if err != nil {
  13. return nil, err
  14. }
  15. return &userInfo, nil
  16. }
  17. // FindUserInfoByOpenId 根据openID去查找快手授权信息
  18. func FindUserInfoByOpenId(ctx context.Context, openId string) (*gorm_model.PlatformKuaishouUserInfo, error) {
  19. db := GetReadDB(ctx)
  20. var userInfo gorm_model.PlatformKuaishouUserInfo
  21. err := db.Model(gorm_model.PlatformKuaishouUserInfo{}).Where("open_id = ? and platform_id = ?", openId, 4).Find(&userInfo).Error
  22. if err != nil {
  23. return nil, err
  24. }
  25. return &userInfo, nil
  26. }
  27. func GetProvince(ctx context.Context, request http_model.GetProviceRequest) (*http_model.GetProviceResponse, error) {
  28. db := GetReadDB(ctx)
  29. var userInfo []gorm_model.PlatformKuaishouUserInfo
  30. // 从数据库中获取所有 city 字段的数据
  31. err := db.Model(&gorm_model.PlatformKuaishouUserInfo{}).Pluck("city", &userInfo).Error
  32. if err != nil {
  33. return nil, err
  34. }
  35. // 使用 map 来去重省份
  36. provinceMap := make(map[string]struct{})
  37. for _, user := range userInfo {
  38. if user.City != "" {
  39. // 按照空格分割 city 字段,取第一个部分作为省份
  40. cityParts := strings.Split(user.City, " ")
  41. if len(cityParts) > 0 {
  42. provinceMap[cityParts[0]] = struct{}{} // 使用空结构体来去重
  43. }
  44. }
  45. }
  46. // 将 map 中的省份名称放入切片
  47. var provinces []string
  48. for province := range provinceMap {
  49. provinces = append(provinces, province)
  50. }
  51. // 返回省份列表
  52. return &http_model.GetProviceResponse{
  53. Provices: provinces,
  54. }, nil
  55. }