| | |
| | | |
| | | // CreateProduct 创建Product记录 |
| | | // Author [piexlmax](https://github.com/piexlmax) |
| | | func (pService *ProductService) CreateProduct(p *test.Product) (err error) { |
| | | func (pService *ProductService) CreateProduct(p []*test.Product) (err error) { |
| | | err = global.GVA_DB.Create(p).Error |
| | | return err |
| | | } |
| | |
| | | // UpdateProduct 更新Product记录 |
| | | // Author [piexlmax](https://github.com/piexlmax) |
| | | func (pService *ProductService) UpdateProduct(p test.Product) (err error) { |
| | | err = global.GVA_DB.Save(&p).Error |
| | | err = global.GVA_DB.Updates(&p).Error |
| | | return err |
| | | } |
| | | |
| | |
| | | db = db.Where("supplier_id = ?", info.SupplierId) |
| | | } |
| | | |
| | | if info.MaximumStock != 0 { |
| | | db = db.Where("maximum_stock = ?", info.MaximumStock) |
| | | } |
| | | |
| | | if info.MinimumStock != 0 { |
| | | db = db.Where("minimum_stock = ?", info.MinimumStock) |
| | | } |
| | | |
| | | if info.PurchasePrice != 0 { |
| | | db = db.Where("purchase_price = ?", info.PurchasePrice) |
| | | } |
| | | |
| | | if info.Specifications != "" { |
| | | db = db.Where("specifications LIKE ?", "%"+info.Specifications+"%") |
| | | } |
| | | |
| | | if info.ModelNumber != "" { |
| | | db = db.Where("model_number LIKE ?", "%"+info.ModelNumber+"%") |
| | | } |
| | | |
| | | if info.ProductType != "" { |
| | | db = db.Where("product_type LIKE ?", "%"+info.ProductType+"%") |
| | | } |
| | | |
| | | if info.SupplierNumber != "" { |
| | | db = db.Joins("Supplier").Where("Supplier.number LIKE ?", "%"+info.SupplierNumber+"%") |
| | | } |
| | | |
| | | err = db.Count(&total).Error |
| | | if err != nil { |
| | | return |
| | |
| | | err = db.Limit(limit).Offset(offset).Preload("Supplier").Find(&ps).Error |
| | | return ps, total, err |
| | | } |
| | | |
| | | // GetProducts 根据ids获取Product记录 |
| | | func (pService *ProductService) GetProducts(ids []uint) (p []*test.Product, m map[uint]*test.Product, err error) { |
| | | err = global.GVA_DB.Where("id in ?", ids).Find(&p).Error |
| | | if err != nil { |
| | | return |
| | | } |
| | | m = make(map[uint]*test.Product, len(p)) |
| | | for _, product := range p { |
| | | m[product.ID] = product |
| | | } |
| | | return |
| | | } |