2be25df7d2
- P04: 修复 Withdrawal.TableName() 返回正确表名 withdrawals
- P03: 新增提现状态常量 (constant/withdrawal.go),消除魔法数字 0/1/2/3;
新增 CommissionTypeWithdrawCancel (338) 和 WithdrawalCancelForbidden 错误码
- P02: 迁移 02123 为 withdrawals 表添加 method/account/qr_code_url 列;
扩展 Withdrawal GORM 模型和 API 类型(CommissionWithdrawRequest、WithdrawalLog);
申请提现时增加收款方式校验逻辑
- P01: 新增用户取消提现接口 POST /v1/public/user/withdrawal_cancel;
仅可取消自己的待审核提现,退还佣金并写佣金日志
- P05: 管理端提现列表新增 method 过滤参数
Co-authored-by: multica-agent <github@multica.ai>
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package common
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/perfect-panel/server/internal/model/log"
|
|
usermodel "github.com/perfect-panel/server/internal/model/user"
|
|
"github.com/perfect-panel/server/pkg/constant"
|
|
"github.com/pkg/errors"
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
)
|
|
|
|
func WriteCommissionLog(tx *gorm.DB, objectID int64, logType uint16, amount int64, orderNo string) error {
|
|
logInfo := log.Commission{
|
|
Type: logType,
|
|
Amount: amount,
|
|
OrderNo: orderNo,
|
|
Timestamp: time.Now().UnixMilli(),
|
|
}
|
|
|
|
content, err := logInfo.Marshal()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return tx.Model(log.SystemLog{}).Create(&log.SystemLog{
|
|
Type: log.TypeCommission.Uint8(),
|
|
Date: time.Now().Format(time.DateOnly),
|
|
ObjectID: objectID,
|
|
Content: string(content),
|
|
CreatedAt: time.Now(),
|
|
}).Error
|
|
}
|
|
|
|
func LoadPendingWithdrawalForUpdate(ctx context.Context, tx *gorm.DB, withdrawalID int64) (*usermodel.Withdrawal, error) {
|
|
var withdrawal usermodel.Withdrawal
|
|
if err := tx.WithContext(ctx).
|
|
Clauses(clause.Locking{Strength: "UPDATE"}).
|
|
Where("id = ?", withdrawalID).
|
|
First(&withdrawal).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
if withdrawal.Status != constant.WithdrawalStatusPending {
|
|
return nil, errors.New("withdrawal status invalid")
|
|
}
|
|
return &withdrawal, nil
|
|
}
|