package controllers import ( "github.com/gin-gonic/gin" "silkserver/controllers/request" "silkserver/extend/code" "silkserver/extend/util" "silkserver/middleware" "silkserver/models" "silkserver/pkg/timex" "strconv" "time" ) type SalaryPlanController struct { } // SaveSalaryPlan // // @Tags 员工薪资/薪酬方案 // @Summary 保存薪酬方案 // @Produce application/json // @Param object body models.SaveSalaryPlan true "参数" // @Param Authorization header string true "token" // @Success 200 {object} util.Response "成功" // @Router /api-jl/v1/salary/saveSalaryPlan [post] func (slf SalaryPlanController) SaveSalaryPlan(c *gin.Context) { var params models.SalaryPlan err := c.BindJSON(¶ms) if err != nil { util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") return } if params.ID > 0 { //更新 err = models.NewSalaryPlanSearch().Save(¶ms) if err != nil { util.ResponseFormat(c, code.RequestParamError, "保存失败") return } } else { //新建 info := middleware.GetUserInfo(c) params.AddPeople = info.NickName params.CreateTime = timex.TimeToString2(time.Now()) err = models.NewSalaryPlanSearch().Create(¶ms) if err != nil { util.ResponseFormat(c, code.RequestParamError, "保存失败") return } } util.ResponseFormat(c, code.Success, "保存成功") } // GetSalaryPlanList // // @Tags 员工薪资/薪酬方案 // @Summary 获取薪酬方案列表 // @Produce application/json // @Param object body request.GetSalaryPlanList true "参数" // @Param Authorization header string true "token" // @Success 200 {object} util.ResponseList{data=[]models.SalaryPlan} "成功" // @Router /api-jl/v1/salary/getSalaryPlanList [post] func (slf SalaryPlanController) GetSalaryPlanList(c *gin.Context) { var params request.GetSalaryPlanList err := c.BindJSON(¶ms) if err != nil { util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") return } find, total, err := models.NewSalaryPlanSearch().SetPage(params.Page, params.PageSize).Find() if err != nil { util.ResponseFormat(c, code.RequestParamError, "查找失败") return } util.ResponseFormatList(c, code.Success, find, total) } // DeleteSalaryPlanInfo // // @Tags 员工薪资/薪酬方案 // @Summary 删除薪酬方案 // @Produce application/json // @Param number path string true "id" // @Param Authorization header string true "token" // @Success 200 {object} util.Response "成功" // @Router /api-jl/v1/salary/deleteSalaryPlanInfo/{id} [delete] func (slf SalaryPlanController) DeleteSalaryPlanInfo(c *gin.Context) { id := c.Param("id") if id == "" { util.ResponseFormat(c, code.RequestParamError, "无效的id") return } atoi, _ := strconv.Atoi(id) if atoi == 0 { util.ResponseFormat(c, code.RequestParamError, "无效的id") return } err := models.NewSalaryPlanSearch().SetId(atoi).Delete() if err != nil { util.ResponseFormat(c, code.RequestParamError, "删除失败") return } util.ResponseFormat(c, code.Success, "删除成功") }