zhangqian
2024-04-07 a0d098663f4e5f099fcefa3ca2f4b544a76152c9
location表增加仓库id字段
3个文件已修改
37 ■■■■ 已修改文件
controllers/location.go 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/location.go 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/warehouse.go 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/location.go
@@ -24,7 +24,7 @@
func (slf LocationController) AddLocation(c *gin.Context) {
    var params models.Location
    if err := c.BindJSON(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误:"+err.Error())
        return
    }
    if err := slf.CheckLocation(params); err != nil {
@@ -39,6 +39,19 @@
            return
        }
        params.JointName = first.JointName + "/" + params.Name
        if first.WarehouseId != 0 {
            params.WarehouseId = first.Id
        } else {
            //根据仓库缩写查询仓库
            houseCode := strings.Split(first.JointName, "/")[0]
            warehouse, err := models.NewWarehouseSearch().SetCode(houseCode).First()
            if err != nil {
                util.ResponseFormat(c, code.RequestParamError, err)
                return
            }
            params.WarehouseId = warehouse.Id
        }
    } else {
        params.JointName = params.Name
    }
models/location.go
@@ -27,6 +27,8 @@
        NextCount            string                        `json:"nextCount" gorm:"type:varchar(255);comment:下次盘点"`       //下次盘点
        JointName            string                        `json:"jointName" gorm:"type:varchar(255);comment:拼接名称"`       //拼接名称
        Children             []*Location                   `json:"children" gorm:"-"`
        WarehouseId          int                           `json:"warehouseId" gorm:"type:int;not null;default:0;comment:仓库ID"` //仓库ID
        Warehouse            Warehouse                     `json:"warehouse" gorm:"foreignKey:WarehouseId"`                     //仓库
    }
    LocationSearch struct {
@@ -164,6 +166,10 @@
        db = db.Where("is_scrap_location = ?", slf.IsScrapLocation)
    }
    if slf.Preload {
        db = db.Preload("Warehouse")
    }
    return db
}
models/warehouse.go
@@ -12,14 +12,14 @@
    Warehouse struct {
        WmsModel
        Id                     int          `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Name                   string       `json:"name" gorm:"index;type:varchar(255);not null;comment:仓库名称"`                                 //仓库名称
        Active                 bool         `json:"active" gorm:"type:tinyint(1);not null;comment:是否激活"`                                       //是否启用,传true就行
        Code                   string       `json:"code" binding:"required,min=1,max=5"  gorm:"index;type:varchar(255);not null;comment:仓库编码"` //仓库编码
        PartnerID              int          `json:"partnerId"  gorm:"type:int;not null;comment:合作伙伴id"`                                        //合作伙伴id
        BuyToResupply          bool         `json:"buyToResupply" gorm:"type:tinyint(1);not null;comment:是否购买补给"`                              //是否购买补给,已购买产品能够发送到此仓库
        ResupplyWhIdsStr       string       `json:"-" gorm:"column:resupply_wh_ids;type:varchar(255);not null;comment:补给来源仓库ID"`               //补给来源仓库ID
        ResupplyWhIds          []string     `json:"resupplyWhIds" gorm:"-"`                                                                    //补给来源仓库ID
        ResupplyWh             []*Warehouse `json:"resupplyWh" gorm:"-"`                                                                       //补给来源仓库
        Name                   string       `json:"name" gorm:"index;type:varchar(255);not null;comment:仓库名称"`                   //仓库名称
        Active                 bool         `json:"active" gorm:"type:tinyint(1);not null;comment:是否激活"`                         //是否启用,传true就行
        Code                   string       `json:"code" gorm:"index;type:varchar(255);not null;comment:仓库编码"`                   //仓库编码
        PartnerID              int          `json:"partnerId"  gorm:"type:int;not null;comment:合作伙伴id"`                          //合作伙伴id
        BuyToResupply          bool         `json:"buyToResupply" gorm:"type:tinyint(1);not null;comment:是否购买补给"`                //是否购买补给,已购买产品能够发送到此仓库
        ResupplyWhIdsStr       string       `json:"-" gorm:"column:resupply_wh_ids;type:varchar(255);not null;comment:补给来源仓库ID"` //补给来源仓库ID
        ResupplyWhIds          []string     `json:"resupplyWhIds" gorm:"-"`                                                      //补给来源仓库ID
        ResupplyWh             []*Warehouse `json:"resupplyWh" gorm:"-"`                                                         //补给来源仓库
        CompanyId              int          `json:"companyId" gorm:"type:int;not null;comment:公司id"`
        Company                Company      `json:"company" gorm:"foreignKey:CompanyId"`
        Address                string       `json:"address" gorm:"type:varchar(512);comment:地址"`         //地址