|
@@ -8,6 +8,7 @@ import (
|
|
|
"gorm.io/gorm"
|
|
|
"reflect"
|
|
|
"time"
|
|
|
+ "youngee_m_api/consts"
|
|
|
"youngee_m_api/model/common_model"
|
|
|
"youngee_m_api/model/gorm_model"
|
|
|
"youngee_m_api/model/http_model"
|
|
@@ -265,6 +266,95 @@ func GetCreatorList(ctx context.Context, pageSize, pageNum int32, conditions *co
|
|
|
}
|
|
|
|
|
|
var CreatorList []*http_model.CreatorListPreview
|
|
|
+
|
|
|
CreatorList = pack.TalentListToCreatorListData(talentList)
|
|
|
return CreatorList, total, nil
|
|
|
}
|
|
|
+
|
|
|
+func AccountInfo(ctx context.Context, pageSize, pageNum int32, conditions *common_model.AccountInfoConditions) ([]*http_model.AccountInfoData, int64, error) {
|
|
|
+ db := GetReadDB(ctx)
|
|
|
+ db = db.Debug().Model(gorm_model.YoungeePlatformAccountInfo{})
|
|
|
+ // 根据 条件过滤
|
|
|
+ conditionType := reflect.TypeOf(conditions).Elem()
|
|
|
+ conditionValue := reflect.ValueOf(conditions).Elem()
|
|
|
+ for i := 0; i < conditionType.NumField(); i++ {
|
|
|
+ field := conditionType.Field(i)
|
|
|
+ tag := field.Tag.Get("condition")
|
|
|
+ value := conditionValue.FieldByName(field.Name)
|
|
|
+ if !util.IsBlank(value) && tag != "bind_date" && tag != "fans_low" && tag != "fans_high" {
|
|
|
+ db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
|
+ } else if tag == "bind_date" && value.Interface() != nil {
|
|
|
+ db = db.Where(fmt.Sprintf("bind_date like '%s%%'", value.Interface()))
|
|
|
+ }
|
|
|
+ if !util.IsBlank(value) && tag == "fans_low" {
|
|
|
+ db = db.Where(fmt.Sprintf("%s >= ?", "fans_count"), value.Interface())
|
|
|
+ }
|
|
|
+ if !util.IsBlank(value) && tag == "fans_high" {
|
|
|
+ db = db.Where(fmt.Sprintf("%s <= ?", "fans_count"), value.Interface())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ db = db.Debug().Where("deleted = ?", 0)
|
|
|
+ var total int64
|
|
|
+ if err := db.Count(&total).Error; err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[GetAccountInfo] error query mysql total, err:%+v", err)
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
+ var PlatformAccountInfos []*gorm_model.YoungeePlatformAccountInfo
|
|
|
+ // 查询该页数据
|
|
|
+ limit := pageSize
|
|
|
+ offset := pageSize * pageNum // assert pageNum start with 0
|
|
|
+ err := db.Order("bind_date desc").Limit(int(limit)).Offset(int(offset)).Find(&PlatformAccountInfos).Error
|
|
|
+ if err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[GetAccountInfo] error query mysql total, err:%+v", err)
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
+ phoneMap := map[string]string{}
|
|
|
+ for _, PlatformAccountInfo := range PlatformAccountInfos {
|
|
|
+ if _, ok := phoneMap[PlatformAccountInfo.TalentID]; !ok {
|
|
|
+ phoneMap[PlatformAccountInfo.TalentID] = getPhoneByTalentID(ctx, PlatformAccountInfo.TalentID)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var accountInfoDatas []*http_model.AccountInfoData
|
|
|
+ for _, PlatformAccountInfo := range PlatformAccountInfos {
|
|
|
+ accountInfo := new(http_model.AccountInfoData)
|
|
|
+ accountInfo.BindDate = conv.MustString(PlatformAccountInfo.BindDate, "")[0:19]
|
|
|
+ accountInfo.Platform = consts.GetProjectPlatform(PlatformAccountInfo.PlatformID)
|
|
|
+ accountInfo.PlatformNickname = PlatformAccountInfo.PlatformNickname
|
|
|
+ accountInfo.TalentId = PlatformAccountInfo.TalentID
|
|
|
+ accountInfo.Phone = phoneMap[PlatformAccountInfo.TalentID]
|
|
|
+ accountInfo.Fans = PlatformAccountInfo.FansCount
|
|
|
+ accountInfo.HomePageUrl = PlatformAccountInfo.HomePageUrl
|
|
|
+ accountInfo.HomePageCaptureUrl = PlatformAccountInfo.HomePageCaptureUrl
|
|
|
+ accountInfoDatas = append(accountInfoDatas, accountInfo)
|
|
|
+ }
|
|
|
+ return accountInfoDatas, total, nil
|
|
|
+}
|
|
|
+
|
|
|
+func getPhoneByTalentID(ctx context.Context, talentID string) string {
|
|
|
+ db := GetReadDB(ctx)
|
|
|
+ talentInfo := gorm_model.YoungeeTalentInfo{}
|
|
|
+ err := db.Debug().Where("id = ?", talentID).First(&talentInfo).Error
|
|
|
+ if err != nil {
|
|
|
+ if err == gorm.ErrRecordNotFound {
|
|
|
+ return ""
|
|
|
+ } else {
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return talentInfo.TalentPhoneNumber
|
|
|
+}
|
|
|
+
|
|
|
+func DeleteAccount(ctx context.Context, PlatformID, PlatformNickname, TalentId string) error {
|
|
|
+ db := GetReadDB(ctx)
|
|
|
+ accountInfo := gorm_model.YoungeePlatformAccountInfo{}
|
|
|
+ db = db.Debug().Where("talent_id = ? "+
|
|
|
+ "AND platform_nickname = ? "+
|
|
|
+ "AND platform_id = ?",
|
|
|
+ TalentId, PlatformNickname, PlatformID).First(&accountInfo)
|
|
|
+ err := db.Update("deleted", 1).Error
|
|
|
+ if err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[user db] call DeleteAccount error,err:%+v", err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|