feat:完善项目

This commit is contained in:
henry
2021-11-03 17:55:27 +08:00
parent 62c2dda714
commit af976f83c1
14 changed files with 376 additions and 27 deletions

View File

@ -3,6 +3,7 @@ package model
import (
"ArmedPolice/app/common/model"
"ArmedPolice/serve/orm"
"fmt"
)
type ManageMaterial struct {
@ -10,11 +11,30 @@ type ManageMaterial struct {
}
type ManageMaterialInfo struct {
Title string `json:"title"`
*model.ManageMaterial
SupplierName string `json:"supplier_name"`
}
func (m *ManageMaterial) Materials() {
orm.GetDB().Table(m.TableName() + " AS m").Select("")
func (m *ManageMaterial) Materials(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageMaterialInfo, error) {
db := orm.GetDB().Table(m.TableName()+" AS m").
Select("m.*", "s.name AS supplier_name").
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON m.supplier_id = s.id", model.NewManageSupplier().TableName()))
if len(where) > 0 {
for _, wo := range where {
db = db.Where(wo.Condition, wo.Value)
}
}
out := make([]*ManageMaterialInfo, 0)
if err := db.Order("p.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
return nil, err
}
if err := db.Count(count).Error; err != nil {
return nil, err
}
return out, nil
}
func NewManageMaterial() *ManageMaterial {