35 lines
963 B
Go
35 lines
963 B
Go
package order
|
|
|
|
import (
|
|
"log"
|
|
|
|
"hfb_sys/backend/internal/model"
|
|
)
|
|
|
|
func (r *Repository) prepareRefund(order *model.RentalOrder, amountCent int64, bizType string, remark string) (*refundAction, error) {
|
|
if amountCent <= 0 {
|
|
return nil, nil
|
|
}
|
|
if r.refundFunc == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
order.RefundStatus = refundStatusPending
|
|
order.RefundAmountCent = amountCent
|
|
order.RefundedAt = nil
|
|
return &refundAction{
|
|
OrderID: order.ID,
|
|
RefundAmountCent: amountCent,
|
|
BizType: bizType,
|
|
Remark: remark,
|
|
}, nil
|
|
}
|
|
|
|
func (r *Repository) startRefundBestEffort(action *refundAction) {
|
|
if action == nil || r.refundFunc == nil {
|
|
return
|
|
}
|
|
if _, err := r.refundFunc(action.OrderID, action.RefundAmountCent, action.BizType, action.Remark); err != nil {
|
|
log.Printf("[order] start refund failed order_id=%d biz_type=%s amount_cent=%d err=%v", action.OrderID, action.BizType, action.RefundAmountCent, err)
|
|
}
|
|
}
|