Files
ArmedPolice/app/api/supplier.go

618 lines
17 KiB
Go
Raw Normal View History

2021-11-02 16:22:07 +08:00
package api
import (
"ArmedPolice/app/common/model"
2021-11-03 10:24:37 +08:00
"ArmedPolice/app/controller/manage"
2021-11-02 16:22:07 +08:00
"ArmedPolice/app/service"
"github.com/gin-gonic/gin"
)
2021-11-09 14:42:16 +08:00
/**
* @apiDefine Supplier 供应商管理
*/
2021-11-02 16:22:07 +08:00
type Supplier struct{}
type (
// supplierForm 参数信息
supplierForm struct {
2021-11-09 14:42:16 +08:00
Name string `json:"name" form:"name" binding:"required"`
Contacts string `json:"contacts" form:"contacts" binding:"required"`
Mobile string `json:"mobile" form:"mobile" binding:"required"`
Address string `json:"address" form:"address"`
Remark string `json:"remark" form:"remark"`
2021-11-02 16:22:07 +08:00
}
)
2021-11-10 15:09:31 +08:00
/**
* @api {post} /api/v1/supplier/select 供应商Select
* @apiVersion 1.0.0
* @apiName SupplierSelect
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} kind 类型101制造商102材料合作商103维修合作商
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {String} data.id ID
* @apiSuccess (200) {String} data.name 名称
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": [
* {
* "id": "EgmJ4Ga7LQ",
* "name": "测试的",
* }
* ]
* }
*/
func (*Supplier) Select(c *gin.Context) {
form := &struct {
Kind int `json:"kind" form:"kind" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := manage.NewSupplier()(getSession()(c).(*service.Session)).Select(form.Kind)
APIResponse(err, data)(c)
}
2021-11-09 14:42:16 +08:00
/**
* @api {post} /api/v1/supplier/material 器材信息
* @apiVersion 1.0.0
* @apiName SupplierMaterial
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} [name="''"] 名称
* @apiParam {String} [mobile="''"] 联系方式
* @apiParam {Number} current 当前页
* @apiParam {Number} page_size 页展示数
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {Object} data.data 具体信息
* @apiSuccess (200) {String} data.data.id ID
* @apiSuccess (200) {String} data.data.kind 类型101制造商102材料合作商103维修合作商
* @apiSuccess (200) {String} data.data.name 名称
* @apiSuccess (200) {String} data.data.mobile 联系方式
* @apiSuccess (200) {String} data.data.contacts 联系人
* @apiSuccess (200) {String} data.data.address 联系地址
* @apiSuccess (200) {String} data.data.remark 备注信息
* @apiSuccess (200) {Time} data.data.created_at 创建时间
* @apiSuccess (200) {Time} data.data.updated_at 更新时间
* @apiSuccess (200) {Number} data.count 总数
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": {
* "data": [
* {
* "id": "EgmJ4Ga7LQ",
* "kind": 102,
* "name": "测试的",
* "mobile": "",
* "contacts": "",
* "address": "",
* "remark": "",
* "created_at": "2021-11-09T13:39:19+08:00",
* "updated_at": "2021-11-09T13:52:39+08:00"
* }
* ],
* "count": 1
* }
* }
*/
2021-11-02 16:22:07 +08:00
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
}
2021-11-03 10:24:37 +08:00
data, err := manage.NewSupplier()(getSession()(c).(*service.Session)).
2021-11-02 16:22:07 +08:00
List(form.Name, form.Mobile, model.ManageSupplierKindForMaterial, form.Page, form.PageSize)
2021-11-09 14:42:16 +08:00
APIResponse(err, data)(c)
2021-11-02 16:22:07 +08:00
}
2021-11-09 14:42:16 +08:00
/**
* @api {post} /api/v1/supplier/material/add 器材信息添加
* @apiVersion 1.0.0
* @apiName SupplierMaterialAdd
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} name 名称
* @apiParam {String} contacts 联系人
* @apiParam {String} mobile 联系方式
* @apiParam {String} [address="''"] 联系地址
* @apiParam {String} [remark="''"] 联系备注
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
2021-11-02 16:22:07 +08:00
func (*Supplier) MaterialAdd(c *gin.Context) {
form := new(supplierForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
2021-11-03 10:24:37 +08:00
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
2021-11-09 16:32:36 +08:00
Name: form.Name, Mobile: form.Mobile, Contacts: form.Contacts, Address: form.Address, Remark: form.Remark,
2021-11-02 16:22:07 +08:00
Kind: model.ManageSupplierKindForMaterial,
})
2021-11-04 16:16:57 +08:00
APIResponse(err)(c)
2021-11-02 16:22:07 +08:00
}
2021-11-09 14:42:16 +08:00
/**
* @api {post} /api/v1/supplier/material/edit 器材信息修改
* @apiVersion 1.0.0
* @apiName SupplierMaterialEdit
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} id ID
* @apiParam {String} name 名称
* @apiParam {String} contacts 联系人
* @apiParam {String} mobile 联系方式
* @apiParam {String} [address="''"] 联系地址
* @apiParam {String} [remark="''"] 联系备注
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
2021-11-02 16:22:07 +08:00
func (*Supplier) MaterialEdit(c *gin.Context) {
form := &struct {
IDStringForm
supplierForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
2021-11-03 10:24:37 +08:00
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
2021-11-09 16:32:36 +08:00
ID: form.Convert(), Name: form.Name, Contacts: form.Contacts, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
2021-11-02 16:22:07 +08:00
Kind: model.ManageSupplierKindForMaterial,
})
2021-11-04 16:16:57 +08:00
APIResponse(err)(c)
2021-11-02 16:22:07 +08:00
}
2021-11-09 14:42:16 +08:00
/**
* @api {post} /api/v1/supplier/material/delete 器材信息删除
* @apiVersion 1.0.0
* @apiName SupplierMaterialDelete
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} id ID
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
2021-11-02 16:22:07 +08:00
func (*Supplier) MaterialDelete(c *gin.Context) {
form := new(IDStringForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
2021-11-03 10:24:37 +08:00
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Delete(form.Convert())
2021-11-04 16:16:57 +08:00
APIResponse(err)(c)
2021-11-02 16:22:07 +08:00
}
2021-11-09 14:42:16 +08:00
/**
* @api {post} /api/v1/supplier/repair 修理厂信息
* @apiVersion 1.0.0
* @apiName SupplierRepair
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} [name="''"] 名称
* @apiParam {String} [mobile="''"] 联系方式
* @apiParam {Number} current 当前页
* @apiParam {Number} page_size 页展示数
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {Object} data.data 具体信息
* @apiSuccess (200) {String} data.data.id ID
* @apiSuccess (200) {String} data.data.kind 类型101制造商102材料合作商103维修合作商
* @apiSuccess (200) {String} data.data.name 名称
* @apiSuccess (200) {String} data.data.mobile 联系方式
* @apiSuccess (200) {String} data.data.contacts 联系人
* @apiSuccess (200) {String} data.data.address 联系地址
* @apiSuccess (200) {String} data.data.remark 备注信息
* @apiSuccess (200) {Time} data.data.created_at 创建时间
* @apiSuccess (200) {Time} data.data.updated_at 更新时间
* @apiSuccess (200) {Number} data.count 总数
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": {
* "data": [
* {
* "id": "EgmJ4Ga7LQ",
* "kind": 102,
* "name": "测试的",
* "mobile": "",
* "contacts": "",
* "address": "",
* "remark": "",
* "created_at": "2021-11-09T13:39:19+08:00",
* "updated_at": "2021-11-09T13:52:39+08:00"
* }
* ],
* "count": 1
* }
* }
*/
2021-11-02 16:22:07 +08:00
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
}
2021-11-03 10:24:37 +08:00
data, err := manage.NewSupplier()(getSession()(c).(*service.Session)).
2021-11-02 16:22:07 +08:00
List(form.Name, form.Mobile, model.ManageSupplierKindForRepair, form.Page, form.PageSize)
2021-11-09 16:32:36 +08:00
APIResponse(err, data)(c)
2021-11-02 16:22:07 +08:00
}
2021-11-09 14:42:16 +08:00
/**
* @api {post} /api/v1/supplier/repair/add 修理厂信息添加
* @apiVersion 1.0.0
* @apiName SupplierRepairAdd
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} name 名称
* @apiParam {String} contacts 联系人
* @apiParam {String} mobile 联系方式
* @apiParam {String} [address="''"] 联系地址
* @apiParam {String} [remark="''"] 联系备注
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
2021-11-02 16:22:07 +08:00
func (*Supplier) RepairAdd(c *gin.Context) {
form := new(supplierForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
2021-11-03 10:24:37 +08:00
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
2021-11-09 16:32:36 +08:00
Name: form.Name, Mobile: form.Mobile, Contacts: form.Contacts, Address: form.Address, Remark: form.Remark,
2021-11-02 16:22:07 +08:00
Kind: model.ManageSupplierKindForRepair,
})
2021-11-04 16:16:57 +08:00
APIResponse(err)(c)
2021-11-02 16:22:07 +08:00
}
2021-11-09 14:42:16 +08:00
/**
* @api {post} /api/v1/supplier/repair/edit 修理厂信息修改
* @apiVersion 1.0.0
* @apiName SupplierRepairEdit
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} id ID
* @apiParam {String} name 名称
* @apiParam {String} contacts 联系人
* @apiParam {String} mobile 联系方式
* @apiParam {String} [address="''"] 联系地址
* @apiParam {String} [remark="''"] 联系备注
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
2021-11-02 16:22:07 +08:00
func (*Supplier) RepairEdit(c *gin.Context) {
form := &struct {
IDStringForm
supplierForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
2021-11-03 10:24:37 +08:00
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
2021-11-09 16:32:36 +08:00
ID: form.Convert(), Name: form.Name, Contacts: form.Contacts, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
2021-11-02 16:22:07 +08:00
Kind: model.ManageSupplierKindForRepair,
})
2021-11-04 16:16:57 +08:00
APIResponse(err)(c)
2021-11-02 16:22:07 +08:00
}
2021-11-09 14:42:16 +08:00
/**
* @api {post} /api/v1/supplier/repair/delete 修理厂信息删除
* @apiVersion 1.0.0
* @apiName SupplierRepairDelete
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} id ID
* @apiParam {String} name 名称
* @apiParam {String} contacts 联系人
* @apiParam {String} mobile 联系方式
* @apiParam {String} [address="''"] 联系地址
* @apiParam {String} [remark="''"] 联系备注
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
2021-11-02 16:22:07 +08:00
func (*Supplier) RepairDelete(c *gin.Context) {
form := new(IDStringForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
2021-11-03 10:24:37 +08:00
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Delete(form.Convert())
2021-11-04 16:16:57 +08:00
APIResponse(err)(c)
2021-11-02 16:22:07 +08:00
}
2021-11-09 14:42:16 +08:00
/**
* @api {post} /api/v1/supplier/manufacturer 制造商信息
* @apiVersion 1.0.0
* @apiName SupplierManufacturer
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} [name="''"] 名称
* @apiParam {String} [mobile="''"] 联系方式
* @apiParam {Number} current 当前页
* @apiParam {Number} page_size 页展示数
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {Object} data.data 具体信息
* @apiSuccess (200) {String} data.data.id ID
* @apiSuccess (200) {String} data.data.kind 类型101制造商102材料合作商103维修合作商
* @apiSuccess (200) {String} data.data.name 名称
* @apiSuccess (200) {String} data.data.mobile 联系方式
* @apiSuccess (200) {String} data.data.contacts 联系人
* @apiSuccess (200) {String} data.data.address 联系地址
* @apiSuccess (200) {String} data.data.remark 备注信息
* @apiSuccess (200) {Time} data.data.created_at 创建时间
* @apiSuccess (200) {Time} data.data.updated_at 更新时间
* @apiSuccess (200) {Number} data.count 总数
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": {
* "data": [
* {
* "id": "EgmJ4Ga7LQ",
* "kind": 102,
* "name": "测试的",
* "mobile": "",
* "contacts": "",
* "address": "",
* "remark": "",
* "created_at": "2021-11-09T13:39:19+08:00",
* "updated_at": "2021-11-09T13:52:39+08:00"
* }
* ],
* "count": 1
* }
* }
*/
func (*Supplier) Manufacturer(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.ManageSupplierKindForManufacturer, form.Page, form.PageSize)
APIResponse(err, data)(c)
}
/**
* @api {post} /api/v1/supplier/manufacturer/add 制造商信息添加
* @apiVersion 1.0.0
* @apiName SupplierManufacturerAdd
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} name 名称
* @apiParam {String} contacts 联系人
* @apiParam {String} mobile 联系方式
* @apiParam {String} [address="''"] 联系地址
* @apiParam {String} [remark="''"] 联系备注
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (*Supplier) ManufacturerAdd(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{
2021-11-09 16:32:36 +08:00
Name: form.Name, Mobile: form.Mobile, Contacts: form.Contacts, Address: form.Address, Remark: form.Remark,
2021-11-09 14:42:16 +08:00
Kind: model.ManageSupplierKindForManufacturer,
})
APIResponse(err)(c)
}
/**
* @api {post} /api/v1/supplier/manufacturer/edit 制造商信息修改
* @apiVersion 1.0.0
* @apiName SupplierManufacturerEdit
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} id ID
* @apiParam {String} name 名称
* @apiParam {String} contacts 联系人
* @apiParam {String} mobile 联系方式
* @apiParam {String} [address="''"] 联系地址
* @apiParam {String} [remark="''"] 联系备注
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (*Supplier) ManufacturerEdit(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{
2021-11-09 16:32:36 +08:00
ID: form.Convert(), Name: form.Name, Contacts: form.Contacts, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
2021-11-09 14:42:16 +08:00
Kind: model.ManageSupplierKindForManufacturer,
})
APIResponse(err)(c)
}
/**
* @api {post} /api/v1/supplier/manufacturer/delete 制造商信息删除
* @apiVersion 1.0.0
* @apiName SupplierManufacturerDelete
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} id ID
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (*Supplier) ManufacturerDelete(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)
}