diff --git a/routers/admin/v1/employee.go b/routers/admin/v1/employee.go index c1b3cbe..87f7549 100644 --- a/routers/admin/v1/employee.go +++ b/routers/admin/v1/employee.go @@ -156,5 +156,51 @@ func AddEmployee(c *gin.Context) { // @Success 200 {string} json "{"code": 200, "data":{}, "msg":"ok"}" // @Router /admin/v1/employees/{id} [put] func EditEmployee(c *gin.Context) { + id := com.StrTo(c.Param("id")).MustInt() + username := c.PostForm("username") + password := c.PostForm("password") + department := c.PostForm("department") + position := c.PostForm("position") + state := com.StrTo(c.PostForm("state")).MustInt() + + valid := validation.Validation{} + valid.Min(id,1, "id").Message("必须是有效的员工id") + valid.Range(state, 0, 1, "state").Message("状态只允许0或1") + + data := make(map[string]interface{}) + code := e.InvalidParams + + if ! valid.HasErrors() { + if models.ExistEmployeeByID(id) { + code = e.SUCCESS + if username != "" { + data["username"] = username + } + if password != "" { + data["password"] = password + } + if department != "" { + data["department"] = department + } + if position != "" { + data["position"] = position + } + if state >= 0 { + data["state"] = state + } + } else { + code = e.ErrorNotExistEmployee + } + } + + if code == 200 { + models.EditEmployee(id, data) + } + + c.JSON(http.StatusOK, gin.H{ + "code" : code, + "msg" : e.GetMsg(code), + "data": data, + }) } \ No newline at end of file