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.

53 lines
1.9 KiB

package user
import (
"fmt"
"github.com/astaxie/beego"
"github.com/golangkit/formatime"
"github.com/jinzhu/gorm"
"github.com/shopspring/decimal"
)
type CoinHistory struct {
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"`
}
const (
ShareTypeForCoinHistory = 1 // 分享收益 应该不存在了, 实际是根据用户来的 与RoleTypeForCoinHistory等价
RoleTypeForCoinHistory = 1 // "分享收益" 用户的第一笔订单的收益
TeamTypeForCoinHistory = 2 // 每月结算收益
SelfShoppingTypeForCoinHistory = 3 // 自购收益
TransferTypeForCoinHistory = 4 // 转出
PurchasedTypeForCoinHistory = 5 // 消费抵扣
RefundTypeForCoinHistory = 6 // 退款返还
RefundTypeForCoinHistory1 = 7 //瑞比退回
RecommendTypeForCoinHistory = 8 // 每月结算收益
RewardTypeForCoinHistory = 9 // 每月结算收益
)
// TableName sets the insert table name for this struct type
func (c *CoinHistory) TableName() string {
return "recook_coin_history"
}
func (c *CoinHistory) UpdateWalletAfterCreate(tx *gorm.DB, userId uint) (err error) {
var userWallet Wallet
if err := tx.Find(&userWallet, "user_id=?", userId).Error; err != nil {
return err
}
beego.Info(userWallet.Coin, c.CoinNum)
userWallet.Coin = userWallet.Coin.Add(c.CoinNum)
beego.Info(userWallet.Coin)
err = tx.Save(&userWallet).Error
fmt.Println(userWallet)
return
}