You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.8 KiB
51 lines
1.8 KiB
package coin
|
|
|
|
import (
|
|
"github.com/golangkit/formatime"
|
|
"github.com/jinzhu/gorm"
|
|
"github.com/shopspring/decimal"
|
|
"recook/internal/model/user"
|
|
"recook/internal/v2/lib/db"
|
|
user2 "recook/internal/v2/model/recook/user"
|
|
)
|
|
|
|
const (
|
|
RecookCoinHistoryTeamCoin = user.TeamTypeForCoinHistory // 团队结算
|
|
RecookCoinHistoryRecommendCoin = user.RecommendTypeForCoinHistory // 每月结算收益
|
|
RecookCoinHistoryRewardCoin = user.RewardTypeForCoinHistory // 每月结算收益
|
|
|
|
RefundTypeForCoinHistory1 = 7 //瑞比退回
|
|
)
|
|
|
|
type RecookCoinHistoryModel struct {
|
|
db.BaseModel
|
|
Id int64 `gorm:"column:id" json:"id"`
|
|
UserId uint `gorm:"column:user_id" json:"userId"`
|
|
CoinType int `gorm:"column:coin_type" json:"coinType"`
|
|
CoinNum decimal.Decimal `gorm:"column:coin_num" json:"coin_num" form:"coin_num"`
|
|
OrderId uint `gorm:"column:order_id" json:"orderId"`
|
|
OrderAmount decimal.Decimal `gorm:"column:order_amount;default:0.00;NOT NULL" json:"orderAmount"` // 订单支付总额
|
|
Remark string `gorm:"column:remark" json:"remark"`
|
|
CreatedAt formatime.Second `gorm:"column:created_at" json:"createdAt"`
|
|
}
|
|
|
|
// TableName sets the insert table name for this struct type
|
|
func (r *RecookCoinHistoryModel) TableName() string {
|
|
return "recook_coin_history"
|
|
}
|
|
|
|
// @Style 添加
|
|
func (r *RecookCoinHistoryModel) Create(data *RecookCoinHistoryModel) {
|
|
r.GetDb().Create(data)
|
|
}
|
|
|
|
func (r *RecookCoinHistoryModel) UpdateWalletAfterCreate(tx *gorm.DB, userId uint) (err error) {
|
|
var userWallet user2.RecookUserWalletModel
|
|
if err = tx.Find(&userWallet, "user_id=?", userId).Error; err != nil {
|
|
return err
|
|
}
|
|
userWallet.Coin = userWallet.Coin.Add(r.CoinNum)
|
|
err = tx.Save(&userWallet).Error
|
|
return
|
|
}
|