bugfix:支付
This commit is contained in:
@@ -41,6 +41,12 @@ func (s *AdRewardService) Grant(ctx context.Context, userID int64, request *dto.
|
||||
return nil, errcode.AdRewardInvalid.WithDetails("该激励类型未配置发放数量")
|
||||
}
|
||||
|
||||
// 变更前后取「有效剩余」,仅用于流水展示;权威数值以额度凭证表为准。
|
||||
before := int64(0)
|
||||
if eff, qerr := getEffectiveQuota(ctx, userID, quotaType); qerr == nil {
|
||||
before = eff.Remain
|
||||
}
|
||||
|
||||
grant := &mysqlmodel.QuotaGrant{
|
||||
UserID: userID,
|
||||
QuotaType: quotaType,
|
||||
@@ -50,12 +56,26 @@ func (s *AdRewardService) Grant(ctx context.Context, userID int64, request *dto.
|
||||
ExpireTime: todayEndUnix(), // 当天 23:59:59 到期
|
||||
RefID: request.RefID,
|
||||
}
|
||||
if err := mysqldao.NewQuotaGrantDao().QuotaGrantCreate(ctx, grant); err != nil {
|
||||
if isDuplicateKey(err) {
|
||||
return nil, errcode.AdRewardClaimed
|
||||
}
|
||||
// 流水 order_no 复用广告记录ID(与凭证 ref_id 一致,便于回溯;非空故不影响唯一索引幂等)。
|
||||
flow := &mysqlmodel.QuotaFlowLog{
|
||||
QuotaFlowUUID: genUUID(),
|
||||
UserID: userID,
|
||||
ChangeTarget: QuotaChangeTargetAdjust,
|
||||
ChangeType: QuotaChangeTypeActivity,
|
||||
ChangeNum: amount,
|
||||
OldValue: before,
|
||||
NewValue: before + amount,
|
||||
OrderNo: request.RefID,
|
||||
QuotaType: quotaType,
|
||||
Reason: "广告激励赠送",
|
||||
}
|
||||
created, err := mysqldao.NewQuotaGrantDao().QuotaGrantCreateWithFlow(ctx, grant, flow)
|
||||
if err != nil {
|
||||
return nil, errcode.DatabaseError
|
||||
}
|
||||
if !created {
|
||||
return nil, errcode.AdRewardClaimed // 凭证已存在:重复领取。
|
||||
}
|
||||
|
||||
return &dto.AdRewardGrantResponse{
|
||||
RefID: request.RefID,
|
||||
|
||||
Reference in New Issue
Block a user