From eeb859beff89d2c52f6ba43fc945c3c3081b40ce Mon Sep 17 00:00:00 2001 From: viletyy Date: Fri, 25 Sep 2020 13:31:20 +0800 Subject: [PATCH] =?UTF-8?q?[ADD]=E6=9B=B4=E6=96=B0=E5=91=98=E5=B7=A5?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/admin/v1/employee.go | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) 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