feat:完善项目
This commit is contained in:
@ -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 {
|
||||
|
Reference in New Issue
Block a user