|
@@ -187,6 +187,22 @@ func GetTalentWithdrawPrevalue(ctx context.Context, request http_model.GetTalent
|
|
|
}, err
|
|
|
}
|
|
|
|
|
|
+func GetWithDrawInfo(ctx context.Context, request http_model.GetWithDrawInfoRequest) (*http_model.WithDrawInfoResponse, error) {
|
|
|
+ db := GetReadDB(ctx)
|
|
|
+ var withdrawinfo gorm_model.YounggeeWithdrawRecord
|
|
|
+ fmt.Println(request.Withdrawid)
|
|
|
+ err := db.Model(gorm_model.YounggeeWithdrawRecord{}).Where("withdraw_id = ?", request.Withdrawid).Find(&withdrawinfo).Error
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ res := &http_model.WithDrawInfoResponse{
|
|
|
+ Operator: withdrawinfo.Name,
|
|
|
+ WithdrawAmount: withdrawinfo.WithdrawAmount,
|
|
|
+ AmountPayable: withdrawinfo.AmountPayable,
|
|
|
+ }
|
|
|
+ return res, nil
|
|
|
+}
|
|
|
+
|
|
|
func GetWithdrawValue(ctx context.Context, request http_model.GetWithdrawValueRequest) (*http_model.ALlWithdrawValue, error) {
|
|
|
var withdrawvalue float64
|
|
|
db := GetReadDB(ctx)
|
|
@@ -311,7 +327,7 @@ func RefuseRecharge(ctx context.Context, req http_model.RefuseRechargeRequest) (
|
|
|
db := GetReadDB(ctx)
|
|
|
err := db.Model(gorm_model.YounggeeRechargeRecord{}).Where("recharge_id=?", req.Id).Updates(map[string]interface{}{"status": 3, "refuse_at": time.Now(), "fail_reason": req.FailReason}).Error
|
|
|
if err != nil {
|
|
|
- logrus.WithContext(ctx).Errorf("[Recharge service] call AcceptRecharge error,err:%+v", err)
|
|
|
+ logrus.WithContext(ctx).Errorf("[Recharge service] call RefuseRecharge error,err:%+v", err)
|
|
|
return nil, err
|
|
|
}
|
|
|
res := &http_model.RefuseRechargeData{
|
|
@@ -320,6 +336,41 @@ func RefuseRecharge(ctx context.Context, req http_model.RefuseRechargeRequest) (
|
|
|
return res, nil
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+func GetRechargeInfo(ctx context.Context, req http_model.GetRechargeInfoRequest) (*http_model.RechargeInfoResponse, error) {
|
|
|
+ db := GetReadDB(ctx)
|
|
|
+ var rechargeinfo gorm_model.YounggeeRechargeRecord
|
|
|
+ err := db.Model(gorm_model.YounggeeRechargeRecord{}).Where("recharge_id = ?", req.RechargeId).First(&rechargeinfo).Error
|
|
|
+ if err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[Recharge service] call GetRechargeInfo error,err:%+v", err)
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ var operator string
|
|
|
+ enterprise := gorm_model.Enterprise{}
|
|
|
+ result := db.Where(gorm_model.Enterprise{EnterpriseID: rechargeinfo.EnterpriseID}).First(&enterprise)
|
|
|
+ if result.Error != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[Recharge service] call Enterprise error,err:%+v", err)
|
|
|
+ return nil, result.Error
|
|
|
+ }
|
|
|
+ if rechargeinfo.SubAccountID != 0 {
|
|
|
+ subaccountinfo := gorm_model.YounggeeSubAccount{}
|
|
|
+ userResult := db.Where(gorm_model.YounggeeSubAccount{SubAccountId: rechargeinfo.SubAccountID, SubAccountType: 1}).First(&subaccountinfo)
|
|
|
+ if userResult.Error != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[Recharge service] call YounggeeSubAccount error,err:%+v", err)
|
|
|
+ return nil, userResult.Error
|
|
|
+ }
|
|
|
+ operator = subaccountinfo.SubAccountName
|
|
|
+ } else {
|
|
|
+ operator = enterprise.BusinessName
|
|
|
+ }
|
|
|
+ res := &http_model.RechargeInfoResponse{
|
|
|
+ RechargeAmount: rechargeinfo.RechargeAmount,
|
|
|
+ Operator: operator,
|
|
|
+ MainAccount: enterprise.BusinessName,
|
|
|
+ }
|
|
|
+ return res, nil
|
|
|
+}
|
|
|
+
|
|
|
func GetPreRechargeList(ctx context.Context, req http_model.GetPreRechargeListRequest) (*http_model.PreRechargeListData, error) {
|
|
|
db := GetReadDB(ctx)
|
|
|
|
|
@@ -336,15 +387,9 @@ func GetPreRechargeList(ctx context.Context, req http_model.GetPreRechargeListRe
|
|
|
var prerechargelist []gorm_model.YounggeeRechargeRecord
|
|
|
var total int64
|
|
|
|
|
|
- // 计算总记录数
|
|
|
- err := db.Model(gorm_model.YounggeeRechargeRecord{}).Where("status = ?", req.Status).Count(&total).Error
|
|
|
- if err != nil {
|
|
|
- return &http_model.PreRechargeListData{}, err
|
|
|
- }
|
|
|
-
|
|
|
- // 查询当前页的数据
|
|
|
- err = db.Model(gorm_model.YounggeeRechargeRecord{}).
|
|
|
- Where("status = 1").
|
|
|
+ // 先查询当前页的数据,不考虑 "Others" 筛选条件
|
|
|
+ err := db.Model(gorm_model.YounggeeRechargeRecord{}).
|
|
|
+ Where("status = ?", req.Status).
|
|
|
Offset((page - 1) * pageSize). // 计算偏移量
|
|
|
Limit(pageSize). // 设置每页限制
|
|
|
Find(&prerechargelist).Error
|
|
@@ -352,29 +397,76 @@ func GetPreRechargeList(ctx context.Context, req http_model.GetPreRechargeListRe
|
|
|
return &http_model.PreRechargeListData{}, err
|
|
|
}
|
|
|
|
|
|
- rechargePointers := make([]*http_model.PreRechargeListResponse, 0, len(prerechargelist))
|
|
|
+ // 在查询到的数据上进行筛选 (比如 "Others" 筛选条件)
|
|
|
+ filteredList := make([]gorm_model.YounggeeRechargeRecord, 0)
|
|
|
for _, recharge := range prerechargelist {
|
|
|
- subaccountinfo := gorm_model.YounggeeSubAccount{}
|
|
|
- userResult := db.Where(gorm_model.YounggeeSubAccount{SubAccountId: recharge.SubAccountID, SubAccountType: 1}).First(&subaccountinfo)
|
|
|
- if userResult.Error != nil {
|
|
|
- return nil, userResult.Error
|
|
|
+ var operator string
|
|
|
+ enterprise := gorm_model.Enterprise{}
|
|
|
+ result := db.Where(gorm_model.Enterprise{EnterpriseID: recharge.EnterpriseID}).First(&enterprise)
|
|
|
+ if result.Error != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[Recharge service] call Enterprise error,err:%+v", err)
|
|
|
+ return nil, result.Error
|
|
|
+ }
|
|
|
+ if recharge.SubAccountID != 0 {
|
|
|
+ subaccountinfo := gorm_model.YounggeeSubAccount{}
|
|
|
+ userResult := db.Where(gorm_model.YounggeeSubAccount{SubAccountId: recharge.SubAccountID, SubAccountType: 1}).First(&subaccountinfo)
|
|
|
+ if userResult.Error != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[Recharge service] call YounggeeSubAccount error,err:%+v", err)
|
|
|
+ return nil, userResult.Error
|
|
|
+ }
|
|
|
+ operator = subaccountinfo.SubAccountName
|
|
|
+ } else {
|
|
|
+ operator = enterprise.BusinessName
|
|
|
+ }
|
|
|
+
|
|
|
+ // 进行 "Others" 筛选条件
|
|
|
+ if req.Others != "" {
|
|
|
+ if operator != req.Others && req.Others != recharge.RechargeID {
|
|
|
+ continue
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ // 满足筛选条件的记录添加到 filteredList
|
|
|
+ filteredList = append(filteredList, recharge)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算筛选后的总记录数
|
|
|
+ total = int64(len(filteredList))
|
|
|
+
|
|
|
+ // 构建返回结果
|
|
|
+ rechargePointers := make([]*http_model.PreRechargeListResponse, 0, len(filteredList))
|
|
|
+ for _, recharge := range filteredList {
|
|
|
+ var operator string
|
|
|
enterprise := gorm_model.Enterprise{}
|
|
|
result := db.Where(gorm_model.Enterprise{EnterpriseID: recharge.EnterpriseID}).First(&enterprise)
|
|
|
if result.Error != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[Recharge service] call Enterprise error,err:%+v", err)
|
|
|
return nil, result.Error
|
|
|
}
|
|
|
+ if recharge.SubAccountID != 0 {
|
|
|
+ subaccountinfo := gorm_model.YounggeeSubAccount{}
|
|
|
+ userResult := db.Where(gorm_model.YounggeeSubAccount{SubAccountId: recharge.SubAccountID, SubAccountType: 1}).First(&subaccountinfo)
|
|
|
+ if userResult.Error != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[Recharge service] call YounggeeSubAccount error,err:%+v", err)
|
|
|
+ return nil, userResult.Error
|
|
|
+ }
|
|
|
+ operator = subaccountinfo.SubAccountName
|
|
|
+ } else {
|
|
|
+ operator = enterprise.BusinessName
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建返回响应数据
|
|
|
response := &http_model.PreRechargeListResponse{
|
|
|
ID: recharge.RechargeID,
|
|
|
EnterPrise: enterprise.BusinessName,
|
|
|
- Operator: subaccountinfo.SubAccountName,
|
|
|
+ Operator: operator,
|
|
|
RechargeAmount: recharge.RechargeAmount,
|
|
|
RechargeMethod: recharge.RechargeMethod,
|
|
|
TransferVoucherUrl: recharge.TransferVoucherUrl,
|
|
|
Phone: recharge.Phone,
|
|
|
- CommitAt: recharge.CommitAt,
|
|
|
- ConfirmAt: recharge.ConfirmAt,
|
|
|
- RefuseAt: recharge.RefuseAt,
|
|
|
+ CommitAt: recharge.CommitAt.Format("2006-01-02 15:04:05"),
|
|
|
+ ConfirmAt: recharge.ConfirmAt.Format("2006-01-02 15:04:05"),
|
|
|
+ RefuseAt: recharge.RefuseAt.Format("2006-01-02 15:04:05"),
|
|
|
FailReason: recharge.FailReason,
|
|
|
}
|
|
|
rechargePointers = append(rechargePointers, response)
|
|
@@ -382,37 +474,110 @@ func GetPreRechargeList(ctx context.Context, req http_model.GetPreRechargeListRe
|
|
|
|
|
|
return &http_model.PreRechargeListData{
|
|
|
PreRechargeListinfo: rechargePointers,
|
|
|
- Total: total,
|
|
|
+ Total: total, // 返回筛选后的总记录数
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
-func GetTalentWithdrawList(ctx context.Context, req *http_model.GetTalentWithdrawListRequest) (*http_model.TalentWithdrawListData, error) {
|
|
|
+func GetRechargenums(db *gorm.DB, status int) (int64, error) {
|
|
|
+ query := db.Model(&gorm_model.YounggeeRechargeRecord{}).Where("status = ?", status)
|
|
|
+
|
|
|
+ // 计算总数
|
|
|
+ var total int64
|
|
|
+ if err := query.Count(&total).Error; err != nil {
|
|
|
+ return 0, err
|
|
|
+ }
|
|
|
+ return total, nil
|
|
|
+}
|
|
|
+
|
|
|
+func GetRechargeCount(ctx context.Context) (*http_model.RechargeCountResponse, error) {
|
|
|
db := GetReadDB(ctx)
|
|
|
- page := req.PageNum
|
|
|
- pageSize := req.PageSize
|
|
|
- if page < 1 {
|
|
|
- page = 1
|
|
|
+ pre, _ := GetRechargenums(db, 1)
|
|
|
+ ing, _ := GetRechargenums(db, 2)
|
|
|
+ ed, _ := GetRechargenums(db, 3)
|
|
|
+ res := &http_model.RechargeCountResponse{
|
|
|
+ PreRechargeNums: pre,
|
|
|
+ RechargeNums: ing,
|
|
|
+ FailNums: ed,
|
|
|
}
|
|
|
- if pageSize < 1 {
|
|
|
- pageSize = 10 // 设置默认每页记录数为 10
|
|
|
+ return res, nil
|
|
|
+}
|
|
|
+
|
|
|
+func GetWithdrawnums(db *gorm.DB, status int) (int64, error) {
|
|
|
+ query := db.Model(&gorm_model.YounggeeWithdrawRecord{}).Where("status = ?", status)
|
|
|
+
|
|
|
+ // 计算总数
|
|
|
+ var total int64
|
|
|
+ if err := query.Count(&total).Error; err != nil {
|
|
|
+ return 0, err
|
|
|
}
|
|
|
+ return total, nil
|
|
|
+}
|
|
|
+
|
|
|
+func GetWithdrawCount(ctx context.Context) (*http_model.WithdrawCountResponse, error) {
|
|
|
+ db := GetReadDB(ctx)
|
|
|
+ pre, _ := GetWithdrawnums(db, 1)
|
|
|
+ ing, _ := GetWithdrawnums(db, 2)
|
|
|
+ ed, _ := GetWithdrawnums(db, 3)
|
|
|
+ res := &http_model.WithdrawCountResponse{
|
|
|
+ PreWithdrawNums: pre,
|
|
|
+ WithdrawNums: ing,
|
|
|
+ FailNums: ed,
|
|
|
+ }
|
|
|
+ return res, nil
|
|
|
+}
|
|
|
+
|
|
|
+func GetTalentWithdrawList(ctx context.Context, req *http_model.GetTalentWithdrawListRequest) (*http_model.TalentWithdrawListData, error) {
|
|
|
+ db := GetReadDB(ctx)
|
|
|
+ pageSize := req.PageSize
|
|
|
|
|
|
var withdrawlist []gorm_model.YounggeeWithdrawRecord
|
|
|
var total int64
|
|
|
|
|
|
// 计算总记录数
|
|
|
- err := db.Model(gorm_model.YounggeeWithdrawRecord{}).Where("status = ?", req.Status).Count(&total).Error
|
|
|
- if err != nil {
|
|
|
- return &http_model.TalentWithdrawListData{}, err
|
|
|
+ query := db.Model(gorm_model.YounggeeWithdrawRecord{}).Where("status = ?", req.Status)
|
|
|
+ if req.Others != "" {
|
|
|
+ query = query.Where("withdraw_id LIKE ? OR Name LIKE ?", "%"+req.Others+"%", "%"+req.Others+"%")
|
|
|
+ }
|
|
|
+ // 添加 during 条件(时间范围筛选)
|
|
|
+ if req.During != "" {
|
|
|
+ // 解析 during 参数为时间
|
|
|
+ startTime, err := time.Parse("2006-01-02", req.During)
|
|
|
+ if err != nil {
|
|
|
+ return nil, fmt.Errorf("invalid during format, expected 'YYYY-MM-DD'")
|
|
|
+ }
|
|
|
+ endTime := startTime.Add(24 * time.Hour).Add(-1 * time.Second) // 当天的 23:59:59
|
|
|
+
|
|
|
+ // 添加时间范围条件
|
|
|
+ var timeField string
|
|
|
+ switch req.Status {
|
|
|
+ case 1:
|
|
|
+ timeField = "submit_at"
|
|
|
+ case 2:
|
|
|
+ timeField = "withdraw_at"
|
|
|
+ case 3:
|
|
|
+ timeField = "reject_at"
|
|
|
+ }
|
|
|
+ query = query.Where(
|
|
|
+ fmt.Sprintf("%s BETWEEN ? AND ?", timeField), // 字段名安全拼接
|
|
|
+ startTime,
|
|
|
+ endTime,
|
|
|
+ )
|
|
|
+ }
|
|
|
+ if err := query.Count(&total).Error; err != nil {
|
|
|
+ return nil, err
|
|
|
}
|
|
|
|
|
|
- // 查询当前页的数据
|
|
|
- err = db.Model(gorm_model.YounggeeWithdrawRecord{}).
|
|
|
- Offset((page - 1) * pageSize). // 计算偏移量
|
|
|
- Limit(pageSize). // 设置每页限制
|
|
|
- Find(&withdrawlist).Error
|
|
|
- if err != nil {
|
|
|
- return &http_model.TalentWithdrawListData{}, err
|
|
|
+ // 添加分页逻辑
|
|
|
+ if pageSize == 0 {
|
|
|
+ pageSize = 10
|
|
|
+ }
|
|
|
+ pageNum := req.PageNum
|
|
|
+ if pageNum == 0 {
|
|
|
+ pageNum = 1
|
|
|
+ }
|
|
|
+ offset := (pageNum - 1) * pageSize
|
|
|
+ if err := query.Offset(offset).Limit(pageSize).Find(&withdrawlist).Error; err != nil {
|
|
|
+ return nil, err
|
|
|
}
|
|
|
|
|
|
withdrawPointers := make([]*http_model.TalentWithdrawListResponse, 0, len(withdrawlist))
|
|
@@ -422,9 +587,9 @@ func GetTalentWithdrawList(ctx context.Context, req *http_model.GetTalentWithdra
|
|
|
TalentId: withdraw.TalentID,
|
|
|
WithdrawAmount: withdraw.WithdrawAmount,
|
|
|
ActualAmount: withdraw.AmountPayable,
|
|
|
- ReajectAt: withdraw.RejectAt,
|
|
|
- SubmitAt: withdraw.SubmitAt,
|
|
|
- WithdrawAt: withdraw.WithdrawAt,
|
|
|
+ ReajectAt: withdraw.RejectAt.Format("2006-01-02 15:04:05"),
|
|
|
+ SubmitAt: withdraw.SubmitAt.Format("2006-01-02 15:04:05"),
|
|
|
+ WithdrawAt: withdraw.WithdrawAt.Format("2006-01-02 15:04:05"),
|
|
|
RejectReason: withdraw.RejectReason,
|
|
|
Name: withdraw.Name,
|
|
|
PhoneNumber: withdraw.PhoneNum,
|
|
@@ -439,77 +604,126 @@ func GetTalentWithdrawList(ctx context.Context, req *http_model.GetTalentWithdra
|
|
|
Total: total,
|
|
|
}, nil
|
|
|
}
|
|
|
-func ConfirmWithdrawal(ctx context.Context, withdrawId string) error {
|
|
|
- db := GetReadDB(ctx)
|
|
|
- db2 := GetReadDB(ctx)
|
|
|
- withdrawInfo := gorm_model.YounggeeWithdrawRecord{}
|
|
|
- db = db.Debug().Model(gorm_model.YounggeeWithdrawRecord{}).Where("withdraw_id = ?", withdrawId).Find(&withdrawInfo)
|
|
|
- db2.Debug().Where("withdraw_id = ?", withdrawId).Updates(gorm_model.YounggeeWithdrawRecord{Status: 2, WithdrawAt: time.Now()})
|
|
|
-
|
|
|
- IncomeIdLists := strings.Split(withdrawInfo.IncomeIdList, ",")
|
|
|
- for _, income := range IncomeIdLists {
|
|
|
- var incomeinfo gorm_model.YounggeeTalentIncome
|
|
|
- err := db.Debug().Model(gorm_model.YounggeeTalentIncome{}).
|
|
|
- Where("id = ?", income).
|
|
|
- First(&incomeinfo).Error // 使用 First 而不是 Updates 来查询数据
|
|
|
- if err != nil {
|
|
|
- logrus.WithContext(ctx).Errorf("[finance db] Query YounggeeTalentIncome error, err:%+v", err)
|
|
|
- return err
|
|
|
+
|
|
|
+func ConfirmWithdrawal(ctx context.Context, withdrawIdsStr string) (*http_model.ConfirmWithdrawalResponse, error) {
|
|
|
+ // 分割 withdrawId 列表
|
|
|
+ withdrawIds := strings.Split(withdrawIdsStr, ",")
|
|
|
+ res := http_model.ConfirmWithdrawalResponse{
|
|
|
+ WithdrawId: withdrawIdsStr,
|
|
|
+ }
|
|
|
+ if len(withdrawIds) == 0 {
|
|
|
+ return &res, fmt.Errorf("empty withdrawIds list")
|
|
|
+ }
|
|
|
+
|
|
|
+ db := GetReadDB(ctx) // 使用统一的 DB 实例
|
|
|
+
|
|
|
+ // 开启事务
|
|
|
+ return &res, db.Transaction(func(tx *gorm.DB) error {
|
|
|
+ // 1. 批量更新提现记录状态
|
|
|
+ if err := tx.Model(&gorm_model.YounggeeWithdrawRecord{}).
|
|
|
+ Where("withdraw_id IN (?)", withdrawIds).
|
|
|
+ Updates(map[string]interface{}{
|
|
|
+ "status": 2,
|
|
|
+ "withdraw_at": time.Now(),
|
|
|
+ }).Error; err != nil {
|
|
|
+ return fmt.Errorf("批量更新提现记录失败: %v", err)
|
|
|
}
|
|
|
- err = db.Model(gorm_model.YounggeeTalentIncome{}).Where("id = ?", income).Updates(gorm_model.YounggeeTalentIncome{WithdrawStatus: 1}).Error
|
|
|
- if err != nil {
|
|
|
- logrus.WithContext(ctx).Errorf("[finance db] Updates YounggeeTalentIncome error, err:%+v", err)
|
|
|
- return err
|
|
|
+
|
|
|
+ // 2. 获取所有提现记录的 IncomeIdList(保留重复项)
|
|
|
+ var withdrawRecords []gorm_model.YounggeeWithdrawRecord
|
|
|
+ if err := tx.Where("withdraw_id IN (?)", withdrawIds).
|
|
|
+ Find(&withdrawRecords).Error; err != nil {
|
|
|
+ return fmt.Errorf("查询提现记录失败: %v", err)
|
|
|
}
|
|
|
- switch incomeinfo.Type {
|
|
|
- case 1:
|
|
|
- {
|
|
|
- err = db.Debug().Model(gorm_model.YounggeeSecTaskInfo{}).Where("task_id = ?", incomeinfo.SectaskID).Updates(gorm_model.YounggeeSecTaskInfo{WithdrawStatus: 4}).Error
|
|
|
- if err != nil {
|
|
|
- logrus.WithContext(ctx).Errorf("[finance db] Updates YounggeeSecTaskInfo error, err:%+v", err)
|
|
|
- return err
|
|
|
- }
|
|
|
+
|
|
|
+ // 3. 收集所有 IncomeId(包含重复项)
|
|
|
+ var rawIncomeIds []string
|
|
|
+ talentAmountMap := make(map[string]float64) // talentID -> 总提现金额
|
|
|
+ for _, record := range withdrawRecords {
|
|
|
+ // 按原始顺序保留所有 IncomeId(含重复)
|
|
|
+ ids := strings.Split(record.IncomeIdList, ",")
|
|
|
+ rawIncomeIds = append(rawIncomeIds, ids...)
|
|
|
+ // 累加提现金额
|
|
|
+ talentAmountMap[record.TalentID] += record.WithdrawAmount
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 更新所有 Income 记录状态(含重复项)
|
|
|
+ if len(rawIncomeIds) > 0 {
|
|
|
+ if err := tx.Model(&gorm_model.YounggeeTalentIncome{}).
|
|
|
+ Where("id IN (?)", rawIncomeIds).
|
|
|
+ Update("withdraw_status", 1).Error; err != nil {
|
|
|
+ return fmt.Errorf("更新收入状态失败: %v", err)
|
|
|
}
|
|
|
- case 2:
|
|
|
- {
|
|
|
- err = db.Debug().Model(gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", incomeinfo.TaskID).Updates(gorm_model.YoungeeTaskInfo{WithdrawStatus: 4}).Error
|
|
|
- if err != nil {
|
|
|
- logrus.WithContext(ctx).Errorf("[finance db] Updates YoungeeTaskInfo error, err:%+v", err)
|
|
|
- return err
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 查询所有 Income 记录详情(含重复项)
|
|
|
+ var incomeList []gorm_model.YounggeeTalentIncome
|
|
|
+ if err := tx.Where("id IN (?)", rawIncomeIds).
|
|
|
+ Find(&incomeList).Error; err != nil {
|
|
|
+ return fmt.Errorf("查询收入详情失败: %v", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 6. 按类型收集所有任务ID(含重复项)
|
|
|
+ type TaskRef struct {
|
|
|
+ Type int
|
|
|
+ TaskIDs []string
|
|
|
+ }
|
|
|
+ var taskRefs []TaskRef
|
|
|
+ for _, income := range incomeList {
|
|
|
+ var taskID string
|
|
|
+ switch income.Type {
|
|
|
+ case 1:
|
|
|
+ taskID = income.SectaskID
|
|
|
+ case 2:
|
|
|
+ taskID = income.TaskID
|
|
|
+ case 3:
|
|
|
+ taskID = income.LocalTaskId
|
|
|
+ default:
|
|
|
+ continue
|
|
|
}
|
|
|
- case 3:
|
|
|
- {
|
|
|
- err = db.Debug().Model(gorm_model.YoungeeLocalTaskInfo{}).Where("task_id = ?", incomeinfo.LocalTaskId).Updates(gorm_model.YoungeeLocalTaskInfo{WithdrawStatus: 4}).Error
|
|
|
- if err != nil {
|
|
|
- logrus.WithContext(ctx).Errorf("[finance db] Updates YoungeeLocalTaskInfo error, err:%+v", err)
|
|
|
- return err
|
|
|
- }
|
|
|
+ // 允许重复的 TaskID
|
|
|
+ taskRefs = append(taskRefs, TaskRef{
|
|
|
+ Type: income.Type,
|
|
|
+ TaskIDs: []string{taskID},
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 7. 批量更新任务状态(允许重复更新)
|
|
|
+ for _, ref := range taskRefs {
|
|
|
+ var model interface{}
|
|
|
+ switch ref.Type {
|
|
|
+ case 1:
|
|
|
+ model = &gorm_model.YounggeeSecTaskInfo{}
|
|
|
+ case 2:
|
|
|
+ model = &gorm_model.YoungeeTaskInfo{}
|
|
|
+ case 3:
|
|
|
+ model = &gorm_model.YoungeeLocalTaskInfo{}
|
|
|
+ default:
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if err := tx.Model(model).
|
|
|
+ Where("task_id IN (?)", ref.TaskIDs).
|
|
|
+ Update("withdraw_status", 4).Error; err != nil {
|
|
|
+ return fmt.Errorf("更新任务状态失败: %v", err)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
- //for _, taskId := range taskIdLists {
|
|
|
- // db1 := GetReadDB(ctx)
|
|
|
- // err := db1.Debug().Model(gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Updates(gorm_model.YoungeeTaskInfo{WithdrawStatus: 4}).Error
|
|
|
- // if err != nil {
|
|
|
- // logrus.WithContext(ctx).Errorf("[finance db] Update YoungeeTaskInfo error,err:%+v", err)
|
|
|
- // return err
|
|
|
- // }
|
|
|
- //
|
|
|
- // err = CreateMessageByTaskId(ctx, 6, 1, taskId)
|
|
|
- // if err != nil {
|
|
|
- // logrus.WithContext(ctx).Errorf("[ConfirmWithdrawal] call CreateMessageByTaskId error,err:%+v", err)
|
|
|
- // return err
|
|
|
- // }
|
|
|
- //}
|
|
|
- db3 := GetReadDB(ctx)
|
|
|
- db3.Debug().Model(gorm_model.YoungeeTalentInfo{}).Where("id = ?", withdrawInfo.TalentID).Updates(
|
|
|
- map[string]interface{}{
|
|
|
- "withdrawing": gorm.Expr("withdrawing - ?", withdrawInfo.WithdrawAmount),
|
|
|
- "withdrawed": gorm.Expr("withdrawed + ?", withdrawInfo.WithdrawAmount)})
|
|
|
- return nil
|
|
|
+ // 8. 更新人才账户金额
|
|
|
+ for talentID, amount := range talentAmountMap {
|
|
|
+ if err := tx.Model(&gorm_model.YoungeeTalentInfo{}).
|
|
|
+ Where("id = ?", talentID).
|
|
|
+ Updates(map[string]interface{}{
|
|
|
+ "withdrawing": gorm.Expr("withdrawing - ?", amount),
|
|
|
+ "withdrawed": gorm.Expr("withdrawed + ?", amount),
|
|
|
+ }).Error; err != nil {
|
|
|
+ return fmt.Errorf("更新人才账户失败: %v", err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+ })
|
|
|
}
|
|
|
+
|
|
|
func RefuseTalentWithdrawal(ctx context.Context, req *http_model.RefuseTalentWithdrawalRequest) error {
|
|
|
db := GetReadDB(ctx)
|
|
|
|