package v1 import ( "aps_crm/model/request" "aps_crm/model/response" "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" "aps_crm/service" "github.com/gin-gonic/gin" "strconv" ) type PaymentTypeApi struct{} // Add // @Tags 支付方式管理 // @Summary 添加支付方式 // @Produce application/json // @Param object body request.AddPaymentType true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/paymentType/add [post] func (s *PaymentTypeApi) Add(c *gin.Context) { var params request.AddPaymentType ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } errCode := service.NewPaymentTypeService().AddPaymentType(¶ms.PaymentType) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // Delete // @Tags 支付方式管理 // @Summary 删除支付方式 // @Produce application/json // @Param id path int true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/paymentType/delete/{id} [delete] func (s *PaymentTypeApi) Delete(c *gin.Context) { ctx, ok := contextx.NewContext(c, nil) if !ok { return } id, _ := strconv.Atoi(c.Param("id")) errCode := service.NewPaymentTypeService().DeletePaymentType(id) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // Update // @Tags 支付方式管理 // @Summary 更新支付方式 // @Produce application/json // @Param object body request.UpdatePaymentType true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/paymentType/update [put] func (s *PaymentTypeApi) Update(c *gin.Context) { var params request.UpdatePaymentType ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } if params.Id == 0 { ctx.Fail(ecode.ParamsErr) } params.PaymentType.Id = params.Id errCode := service.NewPaymentTypeService().UpdatePaymentType(¶ms.PaymentType) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // List // @Tags 支付方式管理 // @Summary 获取支付方式列表 // @Produce application/json // @Param object query request.GetPaymentTypeList true "参数" // @Success 200 {object} response.ListResponse{data=[]model.PaymentType} // @Router /api/paymentType/list [get] func (s *PaymentTypeApi) List(c *gin.Context) { var params request.GetPaymentTypeList ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } paymentType, total, errCode := service.NewPaymentTypeService().GetPaymentTypeList() if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.OkWithDetailed(response.ListResponse{ Data: paymentType, Count: total, }) }