package v1
|
|
import (
|
"aps_crm/model"
|
"aps_crm/model/request"
|
"aps_crm/model/response"
|
"aps_crm/pkg/contextx"
|
"aps_crm/pkg/ecode"
|
"github.com/gin-gonic/gin"
|
"strconv"
|
)
|
|
type SaleTypeApi struct{}
|
|
// Add
|
//
|
// @Tags SaleType
|
// @Summary 添加销售类型
|
// @Produce application/json
|
// @Param object body request.AddSaleType true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/saleType/add [post]
|
func (s *SaleTypeApi) Add(c *gin.Context) {
|
var params request.AddSaleType
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
|
saleType := new(model.SaleType)
|
saleType.Name = params.Name
|
|
errCode := saleTypeService.AddSaleType(saleType)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// Delete
|
//
|
// @Tags SaleType
|
// @Summary 删除销售类型
|
// @Produce application/json
|
// @Param id path int true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/saleType/delete/{id} [delete]
|
func (s *SaleTypeApi) Delete(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
errCode := saleTypeService.DeleteSaleType(id)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// Update
|
//
|
// @Tags SaleType
|
// @Summary 更新销售类型
|
// @Produce application/json
|
// @Param object body request.UpdateSaleTypes true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/saleType/update [put]
|
func (s *SaleTypeApi) Update(c *gin.Context) {
|
var params request.UpdateSaleTypes
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
|
errCode := saleTypeService.UpdateSaleType(params.SaleTypes)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// List
|
//
|
// @Tags SaleType
|
// @Summary 获取销售类型列表
|
// @Produce application/json
|
// @Success 200 {object} contextx.Response{data=response.SaleTypeResponse}
|
// @Router /api/saleType/list [get]
|
func (s *SaleTypeApi) List(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
saleTypes, errCode := saleTypeService.GetSaleTypeList()
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.OkWithDetailed(response.SaleTypeResponse{
|
List: saleTypes,
|
})
|
}
|