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 RefundTypeApi struct{} // Add // @Tags 退款方式管理 // @Summary 添加退款方式 // @Produce application/json // @Param object body request.AddRefundType true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/refundType/add [post] func (s *RefundTypeApi) Add(c *gin.Context) { var params request.AddRefundType ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } errCode := service.NewRefundTypeService().AddRefundType(¶ms.RefundType) 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/refundType/delete/{id} [delete] func (s *RefundTypeApi) Delete(c *gin.Context) { ctx, ok := contextx.NewContext(c, nil) if !ok { return } id, _ := strconv.Atoi(c.Param("id")) errCode := service.NewRefundTypeService().DeleteRefundType(id) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // Update // @Tags 退款方式管理 // @Summary 更新退款方式 // @Produce application/json // @Param object body request.UpdateRefundType true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/refundType/update [put] func (s *RefundTypeApi) Update(c *gin.Context) { var params request.UpdateRefundType ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } if params.Id == 0 { ctx.Fail(ecode.ParamsErr) } params.RefundType.Id = params.Id errCode := service.NewRefundTypeService().UpdateRefundType(¶ms.RefundType) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // List // @Tags 退款方式管理 // @Summary 获取退款方式列表 // @Produce application/json // @Param object query request.GetRefundTypeList true "参数" // @Success 200 {object} response.ListResponse{data=[]model.RefundType} // @Router /api/refundType/list [get] func (s *RefundTypeApi) List(c *gin.Context) { var params request.GetRefundTypeList ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } RefundType, total, errCode := service.NewRefundTypeService().GetRefundTypeList() if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.OkWithDetailed(response.ListResponse{ Data: RefundType, Count: total, }) }