package db import ( "context" "github.com/caixw/lib.go/conv" "github.com/sirupsen/logrus" "gorm.io/gorm" "youngee_m_api/model/gorm_model" "youngee_m_api/model/http_model" "youngee_m_api/pack" ) func PlatformAccInfo(ctx context.Context, talentId string) (*http_model.PlatformAccInfoPreView, error) { db := GetReadDB(ctx) var gormPlatform []*gorm_model.YoungeePlatformAccountInfo // 根据 talent_id 进行筛选 db = db.Debug().Model(gorm_model.YoungeePlatformAccountInfo{}).Where("talent_id = ?", talentId) err := db.Find(&gormPlatform).Order("bind_date").Error if err != nil { if err == gorm.ErrRecordNotFound { return nil, nil } else { return nil, err } } // 查询总数 var total int64 if err = db.Count(&total).Error; err != nil { logrus.WithContext(ctx).Errorf("[PlatformAccInfo] error query mysql total, err:%+v", err) return nil, err } platform := new(http_model.PlatformAccInfoPreView) platform.PlatformAccInfoData = pack.GormPlatformToHttpPlatform(gormPlatform) platform.Total = conv.MustString(total, "") return platform, err } func AccountIncome(ctx context.Context, talentId string) (*http_model.TalentInfoResponse, error) { db := GetReadDB(ctx) var talentInfo *gorm_model.YoungeeTalentInfo // 根据 talent_id 进行筛选 err := db.Debug().Model(gorm_model.YoungeeTalentInfo{}).Where("id = ?", talentId). First(&talentInfo).Error if err != nil { if err == gorm.ErrRecordNotFound { return nil, nil } else { return nil, err } } data := new(http_model.TalentInfoResponse) data.Income = talentInfo.Income data.Withdrawed = talentInfo.Withdrawed data.Canwithdraw = talentInfo.Canwithdraw data.Withdrawing = talentInfo.Withdrawing // 查询是否绑定物流地址 IsBindLocation := talentInfo.IsBindLocation if IsBindLocation == 1 { var deliveryInfo *gorm_model.YoungeeTalentDeliveryAddress db1 := GetReadDB(ctx) err = db1.Debug().Model(gorm_model.YoungeeTalentDeliveryAddress{}). Where("talent_id = ? AND default_tag = ?", talentId, 1). First(&deliveryInfo).Error if err != nil { if err == gorm.ErrRecordNotFound { return nil, nil } else { return nil, err } } data.ReceiverName = deliveryInfo.ReceiverName data.PhoneNumber = deliveryInfo.PhoneNumber data.DetailAddr = deliveryInfo.DetailAddr } return data, err }