package controllers import ( "encoding/json" "eta/eta_forum_hub/models" "eta/eta_forum_hub/models/system" "eta/eta_forum_hub/services" "eta/eta_forum_hub/utils" ) type AdminController struct { BaseAuthController } // Save // @Title 新增或者编辑系统用户 // @Description 新增系统用户接口 // @Param request body system.SysuserAddReq true "type json string" // @Success 200 新增成功 // @router /save [post] func (this *AdminController) Save() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req system.AddAdminReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.AdminName == "" { br.Msg = "请输入用户名" br.IsSendEmail = false return } if req.BusinessCode == "" { br.Msg = "请输入商户编码" br.IsSendEmail = false return } err, isSendEmail := services.AddOrUpdateAdmin(&req) if err != nil { br.Msg = "新增或者更新用户失败" br.ErrMsg = "新增或者更新用户失败, Err:" + err.Error() br.IsSendEmail = isSendEmail return } br.Ret = 200 br.Success = true br.Msg = "新增成功" } // Delete // @Title 删除系统用户 // @Description 删除系统用户接口 // @Param request body system.AdminDeleteReq true "type json string" // @Success 200 删除成功 // @router /delete [post] func (this *AdminController) Delete() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req system.AdminDeleteReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.AdminName == "" { br.Msg = "请选择用户" return } if req.BusinessCode == "" { br.Msg = "请选择商户" return } adminInfo, err := system.GetAdminByAdminNameAndBusinessCode(req.AdminName, req.BusinessCode) if err != nil { if err.Error() == utils.ErrNoRow() { br.Msg = "用户不存在" return } br.Msg = "获取用户信息失败" br.ErrMsg = "获取用户信息失败,Err:" + err.Error() return } err = system.DeleteSysuser(adminInfo.AdminId) if err != nil { br.Msg = "删除失败" br.ErrMsg = "删除失败,Err:" + err.Error() return } br.Ret = 200 br.Success = true br.Msg = "删除成功" }