feat:完善项目
This commit is contained in:
120
app/controller/manage/supplier.go
Normal file
120
app/controller/manage/supplier.go
Normal file
@ -0,0 +1,120 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
model2 "ArmedPolice/app/common/model"
|
||||
"ArmedPolice/app/controller/basic"
|
||||
"ArmedPolice/app/model"
|
||||
"ArmedPolice/app/service"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Supplier struct{ *service.Session }
|
||||
|
||||
type SupplierHandle func(session *service.Session) *Supplier
|
||||
|
||||
type (
|
||||
// SupplierInfo 基本信息
|
||||
SupplierInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.ManageSupplier
|
||||
}
|
||||
// SupplierParams 参数信息
|
||||
SupplierParams struct {
|
||||
ID uint64
|
||||
Name, Mobile, Address, Remark string
|
||||
Kind model2.ManageSupplierKind
|
||||
}
|
||||
)
|
||||
|
||||
// List 列表信息
|
||||
func (c *Supplier) List(name, mobile string, kind model2.ManageSupplierKind, page, pageSize int) (*basic.PageDataResponse, error) {
|
||||
mManageSupplier := model.NewManageSupplier()
|
||||
|
||||
out := make([]*model2.ManageSupplier, 0)
|
||||
|
||||
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
|
||||
Where: nil,
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
}}
|
||||
if c.TenantID > 0 {
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereLike("tenant_id", c.TenantID),
|
||||
})
|
||||
}
|
||||
if name != "" {
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereLike("name", name),
|
||||
})
|
||||
}
|
||||
if mobile != "" {
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereLike("mobile", mobile),
|
||||
})
|
||||
}
|
||||
if kind > 0 {
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("kind", kind),
|
||||
})
|
||||
}
|
||||
var count int64
|
||||
|
||||
if err := model2.Pages(mManageSupplier.ManageSupplier, &out, page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*SupplierInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &SupplierInfo{
|
||||
ID: v.GetEncodeID(), ManageSupplier: v,
|
||||
})
|
||||
}
|
||||
return &basic.PageDataResponse{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Form 数据处理
|
||||
func (c *Supplier) Form(params *SupplierParams) error {
|
||||
mManageSupplier := model.NewManageSupplier()
|
||||
|
||||
if params.ID > 0 {
|
||||
mManageSupplier.ID = params.ID
|
||||
|
||||
isExist, err := model2.FirstWhere(mManageSupplier.ManageSupplier)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,供应商信息不存在")
|
||||
}
|
||||
}
|
||||
mManageSupplier.Name = params.Name
|
||||
mManageSupplier.Mobile = params.Mobile
|
||||
mManageSupplier.Address = params.Address
|
||||
mManageSupplier.Remark = params.Remark
|
||||
|
||||
if mManageSupplier.ID > 0 {
|
||||
mManageSupplier.UpdatedAt = time.Now()
|
||||
|
||||
return model2.Updates(mManageSupplier.ManageSupplier, mManageSupplier.ManageSupplier)
|
||||
}
|
||||
mManageSupplier.TenantID = c.TenantID
|
||||
mManageSupplier.Kind = params.Kind
|
||||
return model2.Create(mManageSupplier.ManageSupplier)
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Supplier) Delete(id uint64) error {
|
||||
mManageSupplier := model.NewManageSupplier()
|
||||
mManageSupplier.ID = id
|
||||
|
||||
if err := model2.Delete(mManageSupplier.ManageSupplier); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewSupplier() SupplierHandle {
|
||||
return func(session *service.Session) *Supplier {
|
||||
return &Supplier{session}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user