|
|
|
@ -2,11 +2,13 @@ package recook
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
|
"github.com/shopspring/decimal"
|
|
|
|
|
"recook/internal/v2/logic/pay"
|
|
|
|
|
"recook/internal/v2/model/jyy"
|
|
|
|
|
"recook/internal/v2/model/recook/after"
|
|
|
|
|
user2 "recook/internal/v2/model/recook/user"
|
|
|
|
|
|
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
|
"github.com/shopspring/decimal"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func Refund(tx *gorm.DB, asGoods *after.RecookAfterSalesGoodsModel) error {
|
|
|
|
@ -39,3 +41,29 @@ func Refund(tx *gorm.DB, asGoods *after.RecookAfterSalesGoodsModel) error {
|
|
|
|
|
|
|
|
|
|
return pay.SyncRefundSuccessCallback(tx, asGoods)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func RefundDeposit(tx *gorm.DB, asGoods *after.RecookAfterSalesGoodsModel) error {
|
|
|
|
|
var wallet jyy.UserWallet
|
|
|
|
|
tx.First(&wallet, "user_id = ?", asGoods.UserId)
|
|
|
|
|
|
|
|
|
|
if asGoods.RefundAmount.GreaterThan(decimal.NewFromFloat(0.0)) {
|
|
|
|
|
if err := tx.Model(&wallet).Updates(map[string]interface{}{
|
|
|
|
|
"balance": wallet.Deposit.Add(asGoods.RefundAmount),
|
|
|
|
|
"version": wallet.Version + 1,
|
|
|
|
|
}).Error; err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := tx.Create(&jyy.UserWalletRecord{
|
|
|
|
|
WalletID: wallet.ID,
|
|
|
|
|
UserID: int(asGoods.UserId),
|
|
|
|
|
Amount: asGoods.RefundAmount,
|
|
|
|
|
Current: wallet.Deposit,
|
|
|
|
|
Kind: 2,
|
|
|
|
|
}).Error; err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pay.SyncRefundSuccessCallback(tx, asGoods)
|
|
|
|
|
}
|
|
|
|
|