|
|
@@ -6,15 +6,13 @@ import (
|
|
|
|
|
|
type Goods struct {
|
|
|
global.GVA_MODEL
|
|
|
- CommodityId int `json:"commodityId" gorm:"comment:商品id"`
|
|
|
- Commodity Commodity `json:"commodity" gorm:"foreignKey:CommodityId;references:id;"`
|
|
|
- Number int `json:"number" gorm:"comment:数量"`
|
|
|
- WarehouseId int `json:"warehouseId" gorm:"comment:仓库id"`
|
|
|
- Warehouse Warehouse `json:"warehouse" gorm:"foreignKey:WarehouseId;references:id;"`
|
|
|
- StorageAreaId int `json:"storageAreaId" gorm:"comment:库区id"`
|
|
|
- StorageArea StorageArea `json:"storageArea" gorm:"foreignKey:StorageAreaId;references:id;"`
|
|
|
- PlaceId int `json:"placeId" gorm:"comment:库位id"`
|
|
|
- Place Place `json:"place" gorm:"foreignKey:PlaceId;references:id;"`
|
|
|
+ Name string `json:"name" gorm:"comment:名称"`
|
|
|
+ GoodsGenreId int `json:"goodsGenreId" gorm:"comment:类型"`
|
|
|
+ GoodsGenre GoodsGenre `json:"goodsGenre" gorm:"foreignKey:GoodsGenreId;"`
|
|
|
+ Characteristic string `json:"characteristic" gorm:"comment:特性"`
|
|
|
+ Specifications string `json:"specifications" gorm:"comment:规格"`
|
|
|
+ Unit string `json:"unit" gorm:"comment:单位"`
|
|
|
+ Number int `json:"number" gorm:"comment:数量"`
|
|
|
}
|
|
|
|
|
|
func (Goods) TableName() string {
|
|
|
@@ -22,45 +20,38 @@ func (Goods) TableName() string {
|
|
|
}
|
|
|
|
|
|
func QueryAllGoods() (goods []Goods, err error) {
|
|
|
- err = global.GVA_DB.Model(&Goods{}).Preload("Commodity").Preload("Warehouse").Preload("StorageArea").Preload("Place").Find(&goods).Error
|
|
|
+ err = global.GVA_DB.Model(&Goods{}).Find(&goods).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func QueryGoodsList(limit, offset, commodityId, warehouseId, storageAreaId, placeId int) (goods []Goods, total int64, err error) {
|
|
|
+func QueryGoodsList(limit, offset, genre int, name, characteristic, specifications string) (goods []Goods, total int64, err error) {
|
|
|
// 创建db
|
|
|
db := global.GVA_DB.Model(&Goods{}).Debug()
|
|
|
// 如果有条件搜索 下方会自动创建搜索语句
|
|
|
-
|
|
|
- if commodityId != 0 {
|
|
|
- db = db.Where("commodity_id = ?", commodityId)
|
|
|
+ if name != "" {
|
|
|
+ db = db.Where("name LIKE ?", "%"+name+"%")
|
|
|
}
|
|
|
- if warehouseId != 0 {
|
|
|
- db = db.Where("warehouse_id = ?", warehouseId)
|
|
|
+ if characteristic != "" {
|
|
|
+ db = db.Where("characteristic LIKE ?", "%"+characteristic+"%")
|
|
|
}
|
|
|
- if storageAreaId != 0 {
|
|
|
- db = db.Where("storage_area_id = ?", storageAreaId)
|
|
|
+ if specifications != "" {
|
|
|
+ db = db.Where("specifications LIKE ?", "%"+specifications+"%")
|
|
|
}
|
|
|
- if placeId != 0 {
|
|
|
- db = db.Where("place_id = ?", placeId)
|
|
|
+ if genre > 0 {
|
|
|
+ db = db.Where("goods_genre_id = ?", genre)
|
|
|
}
|
|
|
|
|
|
err = db.Count(&total).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- err = db.Order("id desc").Limit(limit).Offset(offset).Preload("Commodity").Preload("Warehouse").Preload("StorageArea").Preload("Place").Find(&goods).Error
|
|
|
+ err = db.Order("id desc").Limit(limit).Offset(offset).Find(&goods).Error
|
|
|
return goods, total, err
|
|
|
}
|
|
|
|
|
|
-func GetInventory(commodityId, warehouseId, storageAreaId, placeId int) (goods Goods, commodity Commodity, place Place) {
|
|
|
- global.GVA_DB.Model(&Goods{}).
|
|
|
- Where("commodity_id = ? AND warehouse_id = ? AND storage_area_id = ? AND place_id = ?",
|
|
|
- commodityId, warehouseId, storageAreaId, placeId).
|
|
|
- First(&goods)
|
|
|
-
|
|
|
- global.GVA_DB.First(&commodity, commodityId)
|
|
|
- global.GVA_DB.First(&place, placeId)
|
|
|
- return
|
|
|
+func QueryGoodsByGenre(genreId int) (goods []Goods, err error) {
|
|
|
+ err = global.GVA_DB.Model(&Goods{}).Where("goods_genre_id = ?", genreId).Find(&goods).Error
|
|
|
+ return goods, err
|
|
|
}
|
|
|
|
|
|
func (g Goods) CreateGoods() error {
|