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.

180 lines
5.0 KiB

package jyy
import (
"recook/internal/model/manage"
"recook/internal/model/user"
"recook/internal/v2/model/recook/goods"
"time"
"github.com/golangkit/formatime"
"github.com/shopspring/decimal"
"gorm.io/gorm"
)
//type Goods struct {
// ID int `json:"id"`
// GoodsID uint `json:"-"`
//}
//
//func (o Goods) TableName() string {
// return "jyy_goods_info"
//}
type Banner struct {
ID int `json:"id"`
GoodsID uint `json:"goods_id" validate:"required"`
Photo string `json:"photo" validate:"required"`
OrderSort int `json:"order_sort"`
Start formatime.Second `json:"start" validate:"required"`
End formatime.Second `json:"end" validate:"required"`
Valid bool `json:"valid" gorm:"-"`
}
func (o Banner) TableName() string {
return "jyy_banner"
}
func (o *Banner) AfterFind(db *gorm.DB) error {
o.Valid = formatime.NewSecondNow().Time.Before(o.End.Time) && formatime.NewSecondNow().Time.After(o.Start.Time)
return nil
}
type Activity struct {
ID uint `json:"id"`
Name string `json:"name" validate:"required"`
Icon string `json:"icon" validate:"required"`
OrderSort int `json:"order_sort"`
Status int `json:"status" validate:"oneof=1 2"`
GoodsList []ActivityGoods `json:"goods_list" gorm:"foreignKey:ActivityID"`
}
func (o Activity) TableName() string {
return "jyy_activity"
}
func (o *Activity) AfterFind(db *gorm.DB) error {
return nil
}
type ActivityGoods struct {
ID uint `json:"-"`
ActivityID uint `json:"-"`
GoodsID uint `json:"goods_id"`
GoodsInfo goods.RecookGoodsInfoModel `json:"-" gorm:"foreignKey:goods_id"`
GoodsName string `json:"goods_name" gorm:"-"`
}
func (o ActivityGoods) TableName() string {
return "jyy_activity_goods"
}
func (o *ActivityGoods) AfterFind(db *gorm.DB) error {
o.GoodsName = o.GoodsInfo.GoodsName
return nil
}
type ShopCartEntry struct {
ID uint `json:"id"`
SkuID uint `json:"sku_id"`
GoodsID uint `json:"goods_id"`
UserID uint `json:"user_id"`
Quantity uint `json:"quantity"`
}
func (o ShopCartEntry) TableName() string {
return "jyy_shop_cart"
}
type Contact struct {
ID uint `json:"-"`
Mobile string `json:"mobile"`
Wechat string `json:"wechat"`
Photo string `json:"photo"`
}
func (o Contact) TableName() string {
return "jyy_contact"
}
type MessageKind int
const (
Profit MessageKind = iota + 1
Order
)
type AppUserMessage struct {
ID int `json:"id"`
UserID int `json:"user_id"`
Message string `json:"message"`
Kind MessageKind `json:"kind"`
IsRead bool `json:"is_read"`
SubID uint64 `json:"sub_id"`
CreatedAt *time.Time `json:"created_at" gorm:"autoCreateTime"`
}
func (o AppUserMessage) TableName() string {
return "recook_user_message_center"
}
type UserWallet struct {
ID int `json:"id"`
Deposit decimal.Decimal `json:"deposit"`
UserID int `json:"user_id"`
CreatedAt *time.Time `json:"created_at" gorm:"autoCreateTime"`
Version int `json:"version"`
}
func (o UserWallet) TableName() string {
return "jyy_user_wallet"
}
type UserWalletRecord struct {
ID int `json:"id"`
WalletID int `json:"-"`
UserID int `json:"-"`
Amount decimal.Decimal `json:"amount"`
CreatedAt *time.Time `json:"created_at" gorm:"autoCreateTime"`
Current decimal.Decimal `json:"current"`
Kind int `json:"kind"`
OrderID uint64 `json:"order_id"`
}
func (o UserWalletRecord) TableName() string {
return "jyy_wallet_record"
}
type UserWalletApply struct {
ID int `json:"id" gorm:"primaryKey;autoIncrement"`
UserID int `json:"-"`
Amount decimal.Decimal `json:"amount"`
Attach string `json:"attach"`
CreatedAt *time.Time `json:"created_at" gorm:"autoCreateTime"`
State int `json:"state"`
CompanyID int `json:"company_id"`
User *user.Information `json:"-" gorm:"foreignKey:UserID"`
Nickname string `json:"nickname,omitempty" gorm:"-"`
Mobile string `json:"mobile,omitempty" gorm:"-"`
Reason string `json:"reason"`
IsCompany bool `json:"is_company" gorm:"-"`
ApplyUserID int `json:"-"`
ApplyUser *manage.UserInfo `json:"-" gorm:"foreigKey:ApplyUserID"`
ApplyUserName string `json:"apply_user_name" gorm:"-"`
ApplyTime *time.Time `json:"apply_time" gorm:"apply_time"`
}
func (o UserWalletApply) TableName() string {
return "jyy_user_wallet_apply"
}
func (o *UserWalletApply) AfterFind(db *gorm.DB) error {
if o.User != nil {
o.Nickname = o.User.Nickname
o.Mobile = o.User.Mobile
}
o.IsCompany = o.CompanyID != 0
if o.ApplyUser != nil {
o.ApplyUserName = o.ApplyUser.Name
}
return nil
}