Ejemplo n.º 1
0
Archivo: role.go Proyecto: qmdx/GoCMS
//设置状态
func (c Role) SetStatus(role *models.Role) revel.Result {
	var id string = c.Params.Get("id")
	var status string = c.Params.Get("status")

	data := make(map[string]string)

	if len(id) > 0 && len(status) > 0 {
		Id, err := strconv.ParseInt(id, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}

		Status, err := strconv.ParseInt(status, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}

		role.Status = Status

		if role.SetStatus(Id) {
			data["status"] = "1"
			data["message"] = "设置成功!"
			return c.RenderJson(data)
		} else {
			data["status"] = "0"
			data["message"] = "设置失败!"
			return c.RenderJson(data)
		}
	} else {
		data["status"] = "0"
		data["message"] = "设置失败!"
		return c.RenderJson(data)
	}
}
Ejemplo n.º 2
0
//设置状态
func (c Role) SetStatus(role *models.Role) revel.Result {
	var id string = c.Params.Get("id")
	var status string = c.Params.Get("status")

	data := make(map[string]string)

	if len(id) > 0 && len(status) > 0 {
		Id, err := strconv.ParseInt(id, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}

		Status, err := strconv.ParseInt(status, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}

		role.Status = Status

		if role.SetStatus(Id) {

			//******************************************
			//管理员日志
			if UserID, ok := c.Session["UserID"]; ok {
				UserID, err := strconv.ParseInt(UserID, 10, 64)
				if err != nil {
					revel.WARN.Println(err)
				}

				admin := new(models.Admin)
				admin_info := admin.GetById(UserID)

				logs := new(models.Logs)
				if Status == 1 {
					desc := "角色管理|^|设置状态|^|状态:启用"
					logs.Save(admin_info, c.Controller, desc)
				} else {
					desc := "角色管理|^|设置状态|^|状态:锁定"
					logs.Save(admin_info, c.Controller, desc)
				}
			}
			//*****************************************

			data["status"] = "1"
			data["message"] = "设置成功!"
			return c.RenderJson(data)
		} else {
			data["status"] = "0"
			data["message"] = "设置失败!"
			return c.RenderJson(data)
		}
	} else {
		data["status"] = "0"
		data["message"] = "设置失败!"
		return c.RenderJson(data)
	}
}