133 lines
3.5 KiB
Go
133 lines
3.5 KiB
Go
package api
|
|
|
|
import (
|
|
"ArmedPolice/app/common/model"
|
|
"ArmedPolice/app/controller/manage"
|
|
"ArmedPolice/app/service"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Supplier struct{}
|
|
|
|
type (
|
|
// supplierForm 参数信息
|
|
supplierForm struct {
|
|
Name string `json:"name" form:"name" binding:"required"`
|
|
Mobile string `json:"mobile" form:"mobile" binding:"required"`
|
|
Address string `json:"address" form:"address"`
|
|
Remark string `json:"remark" form:"remark"`
|
|
}
|
|
)
|
|
|
|
func (*Supplier) Material(c *gin.Context) {
|
|
form := &struct {
|
|
Name string `json:"name" form:"name"`
|
|
Mobile string `json:"mobile" form:"mobile"`
|
|
PageForm
|
|
}{}
|
|
if err := bind(form)(c); err != nil {
|
|
APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewSupplier()(getSession()(c).(*service.Session)).
|
|
List(form.Name, form.Mobile, model.ManageSupplierKindForMaterial, form.Page, form.PageSize)
|
|
APIResponse(err, data)
|
|
}
|
|
|
|
func (*Supplier) MaterialAdd(c *gin.Context) {
|
|
form := new(supplierForm)
|
|
|
|
if err := bind(form)(c); err != nil {
|
|
APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
|
|
Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
|
|
Kind: model.ManageSupplierKindForMaterial,
|
|
})
|
|
APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Supplier) MaterialEdit(c *gin.Context) {
|
|
form := &struct {
|
|
IDStringForm
|
|
supplierForm
|
|
}{}
|
|
if err := bind(form)(c); err != nil {
|
|
APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
|
|
ID: form.Convert(), Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
|
|
Kind: model.ManageSupplierKindForMaterial,
|
|
})
|
|
APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Supplier) MaterialDelete(c *gin.Context) {
|
|
form := new(IDStringForm)
|
|
|
|
if err := bind(form)(c); err != nil {
|
|
APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Delete(form.Convert())
|
|
APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Supplier) Repair(c *gin.Context) {
|
|
form := &struct {
|
|
Name string `json:"name" form:"name"`
|
|
Mobile string `json:"mobile" form:"mobile"`
|
|
PageForm
|
|
}{}
|
|
if err := bind(form)(c); err != nil {
|
|
APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := manage.NewSupplier()(getSession()(c).(*service.Session)).
|
|
List(form.Name, form.Mobile, model.ManageSupplierKindForRepair, form.Page, form.PageSize)
|
|
APIResponse(err, data)
|
|
}
|
|
|
|
func (*Supplier) RepairAdd(c *gin.Context) {
|
|
form := new(supplierForm)
|
|
|
|
if err := bind(form)(c); err != nil {
|
|
APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
|
|
Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
|
|
Kind: model.ManageSupplierKindForRepair,
|
|
})
|
|
APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Supplier) RepairEdit(c *gin.Context) {
|
|
form := &struct {
|
|
IDStringForm
|
|
supplierForm
|
|
}{}
|
|
if err := bind(form)(c); err != nil {
|
|
APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
|
|
ID: form.Convert(), Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
|
|
Kind: model.ManageSupplierKindForRepair,
|
|
})
|
|
APIResponse(err)(c)
|
|
}
|
|
|
|
func (*Supplier) RepairDelete(c *gin.Context) {
|
|
form := new(IDStringForm)
|
|
|
|
if err := bind(form)(c); err != nil {
|
|
APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Delete(form.Convert())
|
|
APIResponse(err)(c)
|
|
}
|