package test
|
|
import (
|
"srm/global"
|
"srm/model/common/request"
|
"srm/model/test"
|
testReq "srm/model/test/request"
|
)
|
|
type SupplierService struct {
|
}
|
|
// CreateSupplier 创建Supplier记录
|
// Author [piexlmax](https://github.com/piexlmax)
|
func (sService *SupplierService) CreateSupplier(s *test.Supplier) (err error) {
|
err = global.GVA_DB.Create(s).Error
|
return err
|
}
|
|
// DeleteSupplier 删除Supplier记录
|
// Author [piexlmax](https://github.com/piexlmax)
|
func (sService *SupplierService) DeleteSupplier(s test.Supplier) (err error) {
|
err = global.GVA_DB.Delete(&s).Error
|
return err
|
}
|
|
// DeleteSupplierByIds 批量删除Supplier记录
|
// Author [piexlmax](https://github.com/piexlmax)
|
func (sService *SupplierService) DeleteSupplierByIds(ids request.IdsReq) (err error) {
|
err = global.GVA_DB.Delete(&[]test.Supplier{}, "id in ?", ids.Ids).Error
|
return err
|
}
|
|
// UpdateSupplier 更新Supplier记录
|
// Author [piexlmax](https://github.com/piexlmax)
|
func (sService *SupplierService) UpdateSupplier(s test.Supplier) (err error) {
|
err = global.GVA_DB.Save(&s).Error
|
return err
|
}
|
|
// GetSupplier 根据id获取Supplier记录
|
// Author [piexlmax](https://github.com/piexlmax)
|
func (sService *SupplierService) GetSupplier(id uint) (s test.Supplier, err error) {
|
err = global.GVA_DB.Where("id = ?", id).First(&s).Error
|
return
|
}
|
|
// GetSupplierInfoList 分页获取Supplier记录
|
// Author [piexlmax](https://github.com/piexlmax)
|
func (sService *SupplierService) GetSupplierInfoList(info testReq.SupplierSearch) (list []test.Supplier, total int64, err error) {
|
limit := info.PageSize
|
offset := info.PageSize * (info.Page - 1)
|
// 创建db
|
db := global.GVA_DB.Model(&test.Supplier{})
|
var ss []test.Supplier
|
// 如果有条件搜索 下方会自动创建搜索语句
|
if info.StartCreatedAt != nil && info.EndCreatedAt != nil {
|
db = db.Where("created_at BETWEEN ? AND ?", info.StartCreatedAt, info.EndCreatedAt)
|
}
|
if info.Name != "" {
|
db = db.Where("name LIKE ?", "%"+info.Name+"%")
|
}
|
err = db.Count(&total).Error
|
if err != nil {
|
return
|
}
|
|
err = db.Limit(limit).Offset(offset).Find(&ss).Error
|
return ss, total, err
|
}
|
|
// ChangeStatus Change supplier status
|
func (sService *SupplierService) ChangeStatus(id uint, status int) (err error) {
|
err = global.GVA_DB.Model(&test.Supplier{}).Where("id = ?", id).Update("status", status).Error
|
return err
|
}
|