package db import ( "context" "github.com/caixw/lib.go/conv" "github.com/sirupsen/logrus" "gorm.io/gorm" "youngee_m_api/consts" "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 = float32(talentInfo.Income) data.Withdrawed = float32(talentInfo.Withdrawed) data.Canwithdraw = float32(talentInfo.Canwithdraw) data.Withdrawing = float32(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 } else { data.ReceiverName = "暂未绑定物流地址" data.PhoneNumber = "暂未绑定物流地址" data.DetailAddr = "暂未绑定物流地址" } db2 := GetReadDB(ctx) var talentBankInfo *gorm_model.YounggeeTalentBank err = db2.Debug().Model(gorm_model.YounggeeTalentBank{}).Where("talent_id = ?", talentId). First(&talentBankInfo).Error if err != nil { if err == gorm.ErrRecordNotFound { return nil, nil } else { return nil, err } } db3 := GetReadDB(ctx) var infoBank *gorm_model.InfoBank db3.Debug().Model(gorm_model.InfoBank{}).Where("id = ?", talentBankInfo.BankID).First(&infoBank) db4 := GetReadDB(ctx) var infoRegion *gorm_model.InfoRegion db4.Debug().Model(gorm_model.InfoRegion{}).Where("self_code = ?", talentBankInfo.BankOpenAddress).First(&infoRegion) provinceCode := conv.MustString(talentBankInfo.BankOpenAddress, "")[0:2] + "0000" var province *gorm_model.InfoRegion db4.Debug().Model(gorm_model.InfoRegion{}).Where("self_code = ?", conv.MustInt(provinceCode, 0)).First(&province) cityCode := conv.MustString(talentBankInfo.BankOpenAddress, "")[0:4] + "00" var city *gorm_model.InfoRegion db4.Debug().Model(gorm_model.InfoRegion{}).Where("self_code = ?", conv.MustInt(cityCode, 0)).First(&city) data.Bank = infoBank.Name data.BankOpenAddress = province.RegionName + city.RegionName + infoRegion.RegionName data.BankCardNumber = talentBankInfo.BankCardNumber data.Name = talentBankInfo.Name data.AliPayNumber = talentBankInfo.AlipayNumber data.AliPayRealName = talentBankInfo.AlipayRealName return data, err } func GetTaskRecord(ctx context.Context, talentId string) (*http_model.GetTaskRecordResponse, error) { db := GetReadDB(ctx) var taskInfos []*gorm_model.YoungeeTaskInfo // 根据 talent_id 进行筛选 db = db.Debug().Model(gorm_model.YoungeeTaskInfo{}).Where("talent_id = ?", talentId) // 查询总数 var total int64 if err := db.Count(&total).Error; err != nil { logrus.WithContext(ctx).Errorf("[GetTaskRecord] error query mysql total, err:%+v", err) return nil, err } err := db.Order("update_at desc").Find(&taskInfos).Error if err != nil { if err == gorm.ErrRecordNotFound { return nil, nil } else { return nil, err } } projectIdMap := map[int]gorm_model.ProjectInfo{} for _, taskInfo := range taskInfos { if _, ok := projectIdMap[taskInfo.ProjectId]; !ok { db1 := GetReadDB(ctx) projectInfo := gorm_model.ProjectInfo{} db1.Where("project_id = ?", taskInfo.ProjectId).First(&projectInfo) projectIdMap[taskInfo.ProjectId] = projectInfo } } var taskRecordDatas []*http_model.TaskRecordData for _, taskInfo := range taskInfos { updateAt := conv.MustString(taskInfo.UpdateAt, "") updateAt = updateAt[0:19] taskRecordData := http_model.TaskRecordData{ ProjectId: conv.MustString(taskInfo.ProjectId, ""), ProjectName: projectIdMap[taskInfo.ProjectId].ProjectName, ProjectType: consts.GetProjectType(projectIdMap[taskInfo.ProjectId].ProjectType), ProjectPlatform: consts.GetProjectPlatform(projectIdMap[taskInfo.ProjectId].ProjectPlatform), TaskId: conv.MustString(taskInfo.TaskId, ""), TaskStage: consts.GetTaskStage(taskInfo.TaskStage), UpdatedAt: updateAt, } taskRecordDatas = append(taskRecordDatas, &taskRecordData) } taskRecordResponse := new(http_model.GetTaskRecordResponse) taskRecordResponse.TaskRecordData = taskRecordDatas taskRecordResponse.Total = conv.MustString(total, "") return taskRecordResponse, nil }