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

45 lines
1.9 KiB

5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package models
  2. import (
  3. "git.ouxuan.net/tommy/osmanthuswine/src/core"
  4. )
  5. const CustomerGoodsTableName = TableNamePrefix + "customer_goods"
  6. type CustomerGoods struct {
  7. Model `xorm:"extends"`
  8. ActivityId int `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
  9. AreaId int `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
  10. GoodsPicUrl []interface{} `json:"goods_pic_url" xorm:"json comment('商品图片')"`
  11. IsForceAdded int `json:"is_force_added" xorm:"not null default 0 comment('是否强制上架0不强制1强制') TINYINT(1)"`
  12. FixedField string `json:"fixed_field" xorm:"not null default '' comment('固定不可改字段,|分隔') VARCHAR(255)"`
  13. Stock int `json:"stock" xorm:"not null default 0 comment('库存-1的时候无上限') INT(18)"`
  14. Name string `json:"name" xorm:"not null default '' comment('商品名称') VARCHAR(255)"`
  15. Price float64 `json:"price" xorm:"not null default 0.00 comment('商品单价') DECIMAL(18,2)"`
  16. Desc string `json:"desc" xorm:"not null default '' comment('商品介绍') VARCHAR(255)"`
  17. // 无关变量
  18. GoodType int `json:"good_type" xorm:"-"`
  19. Postage float64 `json:"postage" xorm:"-"`
  20. Qrcode string `json:"qrcode,omitempty" xorm:"-"`
  21. }
  22. func (t *CustomerGoods) TableName() string {
  23. return CustomerGoodsTableName
  24. }
  25. func (t *CustomerGoods) Alias(name string) string {
  26. return Alias(t, name)
  27. }
  28. func GetGoodsByActivityId(activityId, areaId interface{}) ([]*CustomerGoods, error) {
  29. goods := make([]*CustomerGoods, 0)
  30. err := core.GetXormAuto().Where("is_delete=0 and activity_id=? and area_id=?", activityId, areaId).
  31. Asc("created_at").Find(&goods)
  32. return goods, err
  33. }
  34. func (t *CustomerGoods) IncrStockById(id, num interface{}) (int64, error) {
  35. return core.GetXormAuto().ID(id).Incr("stock", num).Cols("stock").Update(t)
  36. }