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.

119 lines
3.7 KiB

package goods
import (
"recook/internal/v2/lib/db"
"github.com/golangkit/formatime"
"github.com/jinzhu/gorm"
)
const (
GysGoodsDetailPhotoTypeDetail = 0
GysGoodsDetailPhotoTypeInspection = 1
GysGoodsDetailPhotoTypeOther = 2
)
type GysGoodsDetailPhotoModel struct {
db.BaseModel
Id uint `gorm:"column:id;primary_key" json:"id"`
GoodsId uint `json:"goodsId"`
Url string `json:"url"`
Name string `json:"name"`
OrderNo int `json:"orderNo"`
Width int `json:"width"`
Height int `json:"height"`
Type int `json:"type"`
ExpireTime formatime.Second `json:"expireTime"`
GroupID uint `json:"groupID"`
}
func (r *GysGoodsDetailPhotoModel) TableName() string {
return "gys_goods_detail_photo"
}
type GysGoodsDetailPhotoTempModel struct {
GysGoodsDetailPhotoModel
}
func (r *GysGoodsDetailPhotoTempModel) TableName() string {
return "gys_goods_detail_photo_temp"
}
type GysGoodsPhotoGroupModel struct {
db.BaseModel
ID uint `gorm:"column:id;primary_key" json:"id"`
GoodsId uint `json:"goodsId"`
Type int `json:"type"`
ExpireTime formatime.Second `json:"expireTime"`
Title string `json:"name"`
}
func (r *GysGoodsPhotoGroupModel) TableName() string {
return "gys_goods_photo_group"
}
//通过goodsId来获取
func (r *GysGoodsPhotoGroupModel) FindByGoodsId(id uint) (rest []GysGoodsPhotoGroupModel) {
r.GetDb().Model(&GysGoodsPhotoGroupModel{}).Where("goods_id=?", id).Find(&rest)
return
}
type GysGoodsPhotoGroupTempModel struct {
GysGoodsPhotoGroupModel
}
func (r *GysGoodsPhotoGroupTempModel) TableName() string {
return "gys_goods_photo_group_temp"
}
func (r *GysGoodsDetailPhotoModel) Create(data *GysGoodsDetailPhotoModel) {
r.GetDb().Create(data)
}
func (r *GysGoodsDetailPhotoModel) CreateAll(datas *[]GysGoodsDetailPhotoModel) int64 {
valueStr := ""
values := []interface{}{}
for _, item := range *datas {
valueStr += ",(?,?,?,?,?,?,?)"
values = append(values, item.GoodsId, item.Url, item.Name, item.Type, item.OrderNo, item.Width, item.Height)
}
if len(values) > 0 {
return r.GetDb().Exec("insert into gys_goods_detail_photo(goods_id,url,name,`type`,order_no,width,height) values "+valueStr[1:], values...).RowsAffected
}
return 0
}
func (r *GysGoodsDetailPhotoModel) DeleteByGoodsId(goodsId uint) int64 {
return r.GetDb().Delete(&GysGoodsDetailPhotoModel{}, "goods_id = ?", goodsId).RowsAffected
}
func (r *GysGoodsDetailPhotoModel) GetByGoodsId(goodsId uint) (result []GysGoodsDetailPhotoModel) {
if goodsId < 0 {
return []GysGoodsDetailPhotoModel{}
}
r.GetDb().Model(&GysGoodsDetailPhotoModel{}).Find(&result, "goods_id = ?", goodsId)
return
}
// @Style sql
func (r *GysGoodsDetailPhotoModel) GetByGoodsIdSql(goodsId uint, detailType int, selectStr string, args ...interface{}) (result *gorm.SqlExpr) {
return r.GetDb().Model(&GysGoodsDetailPhotoModel{}).Select(selectStr, args...).Where("goods_id = ? and `type` = ?", goodsId, detailType).SubQuery()
}
// @Style sql
func (r *GysGoodsDetailPhotoModel) UpdateById(id uint, data *GysGoodsDetailPhotoModel) error {
return r.GetDb().Model(&GysGoodsDetailPhotoModel{}).Where("id = ?", id).Update(data).Error
}
//通过goodsId来获取质检表详情
func (r *GysGoodsDetailPhotoModel) SearchByGoodsId(id uint) (rest []GysGoodsDetailPhotoModel) {
r.GetDb().Model(&GysGoodsDetailPhotoModel{}).Where("goods_id=?", id).Find(&rest)
return
}
//通过group_id来获取数组
func (r *GysGoodsDetailPhotoModel) FindByGroupId(groupId uint) (rest []GysGoodsDetailPhotoModel) {
r.GetDb().Model(&GysGoodsDetailPhotoModel{}).Where("group_id=?", groupId).Find(&rest)
return
}