互动
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.

49 lines
2.2 KiB

package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
)
const CustomerGoodsTableName = TableNamePrefix + "customer_goods"
type CustomerGoods struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
IsDelete bool `json:"is_delete" xorm:"not null default 0 comment('是否删除') TINYINT(1)"`
CreatedAt time.Time `json:"created_at" xorm:"created comment('创建时间') TIMESTAMP"`
UpdatedAt time.Time `json:"updated_at" xorm:"updated comment('更新时间') TIMESTAMP"`
ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
GoodsPicUrl string `json:"goods_pic_url" xorm:"not null default '' comment('商品图片') VARCHAR(255)"`
IsForceAdded int `json:"is_force_added" xorm:"not null default 0 comment('是否强制上架0不强制1强制') TINYINT(1)"`
FixedField string `json:"fixed_field" xorm:"not null default '' comment('固定不可改字段,|分隔') VARCHAR(255)"`
Stock int `json:"stock" xorm:"not null default 0 comment('库存-1的时候无上限') INT(18)"`
Name string `json:"name" xorm:"not null default '' comment('商品名称') VARCHAR(255)"`
Price float64 `json:"price" xorm:"not null default 0.00 comment('商品单价')"`
Desc string `json:"desc" xorm:"not null default '' comment('商品介绍') VARCHAR(255)"`
//// 无关变量
GoodType int `json:"good_type" xorm:"-"`
Postage float64 `json:"postage" xorm:"-"`
Qrcode string `json:"qrcode,omitempty" xorm:"-"`
}
func (t *CustomerGoods) TableName() string {
return CustomerGoodsTableName
}
func (t *CustomerGoods) Alias(name string) string {
return AliasTableName(t, name)
}
func GetGoodsByActivityId(activityId, areaId int64) ([]*CustomerGoods, error) {
goods := make([]*CustomerGoods, 0)
err := core.GetXormAuto().Where("is_delete=0 and activity_id=? and area_id=?", activityId, areaId).
Asc("created_at").Find(&goods)
return goods, err
}
func (t *CustomerGoods) IncrStockById(id, num interface{}) (int64, error) {
return core.GetXormAuto().ID(id).Incr("stock", num).Cols("stock").Update(t)
}