|
@@ -1,18 +1,18 @@
|
|
|
package controller
|
|
|
|
|
|
import (
|
|
|
- "Ic_ouath/app/e"
|
|
|
- "Ic_ouath/app/service"
|
|
|
- "Ic_ouath/app/service/imp"
|
|
|
- "Ic_ouath/global"
|
|
|
- "Ic_ouath/models"
|
|
|
- "Ic_ouath/page"
|
|
|
- "Ic_ouath/simple_zap"
|
|
|
- "Ic_ouath/utils"
|
|
|
- "context"
|
|
|
- "github.com/astaxie/beego/validation"
|
|
|
- "github.com/gin-gonic/gin"
|
|
|
- "github.com/go-playground/validator/v10"
|
|
|
+ "Ic_ouath/app/e"
|
|
|
+ "Ic_ouath/app/service"
|
|
|
+ "Ic_ouath/app/service/imp"
|
|
|
+ "Ic_ouath/global"
|
|
|
+ "Ic_ouath/models"
|
|
|
+ "Ic_ouath/page"
|
|
|
+ "Ic_ouath/simple_zap"
|
|
|
+ "Ic_ouath/utils"
|
|
|
+ "context"
|
|
|
+ "github.com/astaxie/beego/validation"
|
|
|
+ "github.com/gin-gonic/gin"
|
|
|
+ "github.com/go-playground/validator/v10"
|
|
|
)
|
|
|
|
|
|
var users service.User = &imp.User{}
|
|
@@ -26,14 +26,14 @@ var users service.User = &imp.User{}
|
|
|
// @Accept application/json
|
|
|
// @Router /user [post]
|
|
|
func PhoneRegist(c *gin.Context) {
|
|
|
- var userRegist models.UserRegist
|
|
|
- err := c.ShouldBindJSON(&userRegist)
|
|
|
- if err != nil {
|
|
|
- e.ResponseError(c, e.JSONParsingFailed)
|
|
|
- return
|
|
|
- }
|
|
|
- rescode := users.PhoneRegist(userRegist)
|
|
|
- e.ResponseError(c, rescode)
|
|
|
+ var userRegist models.UserRegist
|
|
|
+ err := c.ShouldBindJSON(&userRegist)
|
|
|
+ if err != nil {
|
|
|
+ e.ResponseError(c, e.JSONParsingFailed)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rescode := users.PhoneRegist(userRegist)
|
|
|
+ e.ResponseError(c, rescode)
|
|
|
}
|
|
|
|
|
|
// SendCode 发送验证码
|
|
@@ -45,21 +45,21 @@ func PhoneRegist(c *gin.Context) {
|
|
|
// @Accept application/json
|
|
|
// @Router /sendcode [post]
|
|
|
func SendCode(c *gin.Context) {
|
|
|
- phone := c.PostForm("phone")
|
|
|
- utils.SendModel(phone)
|
|
|
- v := validation.Validation{}
|
|
|
- v.Mobile(phone, "phone")
|
|
|
- v.Required(phone, "phone")
|
|
|
- if v.HasErrors() {
|
|
|
- e.ResponseWithMsg(c, e.ThePhoneNumberIsWrong, "手机号码格式不正确")
|
|
|
- } else {
|
|
|
- rescode := utils.SendModel(phone)
|
|
|
- if rescode != e.SUCCESS {
|
|
|
- e.ResponseWithMsg(c, rescode, rescode.GetMsg())
|
|
|
- } else {
|
|
|
- e.ResponseSuccess(c, "发送成功")
|
|
|
- }
|
|
|
- }
|
|
|
+ phone := c.PostForm("phone")
|
|
|
+ utils.SendModel(phone)
|
|
|
+ v := validation.Validation{}
|
|
|
+ v.Mobile(phone, "phone")
|
|
|
+ v.Required(phone, "phone")
|
|
|
+ if v.HasErrors() {
|
|
|
+ e.ResponseWithMsg(c, e.ThePhoneNumberIsWrong, "手机号码格式不正确")
|
|
|
+ } else {
|
|
|
+ rescode := utils.SendModel(phone)
|
|
|
+ if rescode != e.SUCCESS {
|
|
|
+ e.ResponseWithMsg(c, rescode, rescode.GetMsg())
|
|
|
+ } else {
|
|
|
+ e.ResponseSuccess(c, "发送成功")
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Login 账号登录
|
|
@@ -71,19 +71,19 @@ func SendCode(c *gin.Context) {
|
|
|
// @Accept application/json
|
|
|
// @Router /user [post]
|
|
|
func Login(c *gin.Context) {
|
|
|
- var userRegist models.UserRegist
|
|
|
- err := c.ShouldBindJSON(&userRegist)
|
|
|
- if err != nil {
|
|
|
- e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
|
|
|
- return
|
|
|
- } else {
|
|
|
- login, rescode := users.Login(userRegist)
|
|
|
- if rescode == e.SUCCESS {
|
|
|
- e.ResponseSuccess(c, login)
|
|
|
- } else {
|
|
|
- e.ResponseWithMsg(c, rescode, rescode.GetMsg())
|
|
|
- }
|
|
|
- }
|
|
|
+ var userRegist models.UserRegist
|
|
|
+ err := c.ShouldBindJSON(&userRegist)
|
|
|
+ if err != nil {
|
|
|
+ e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ login, rescode := users.Login(userRegist)
|
|
|
+ if rescode == e.SUCCESS {
|
|
|
+ e.ResponseSuccess(c, login)
|
|
|
+ } else {
|
|
|
+ e.ResponseWithMsg(c, rescode, rescode.GetMsg())
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// CodeLogin 验证码登录
|
|
@@ -95,31 +95,31 @@ func Login(c *gin.Context) {
|
|
|
// @Accept application/json
|
|
|
// @Router /codelogin [post]
|
|
|
func CodeLogin(c *gin.Context) {
|
|
|
- var userRegist models.UserRegist
|
|
|
- err := c.ShouldBindJSON(&userRegist)
|
|
|
- if err != nil {
|
|
|
- e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
|
|
|
- simple_zap.WithCtx(context.Background()).Sugar().Warn(err, e.JSONParsingFailed.GetMsg())
|
|
|
- return
|
|
|
- }
|
|
|
- login, rescode := users.CodeLogin(userRegist)
|
|
|
- if rescode == e.SUCCESS {
|
|
|
- e.ResponseSuccess(c, login)
|
|
|
- } else {
|
|
|
- e.ResponseWithMsg(c, rescode, rescode.GetMsg())
|
|
|
- simple_zap.WithCtx(context.Background()).Sugar().Warn(err, rescode.GetMsg())
|
|
|
- }
|
|
|
+ var userRegist models.UserRegist
|
|
|
+ err := c.ShouldBindJSON(&userRegist)
|
|
|
+ if err != nil {
|
|
|
+ e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
|
|
|
+ simple_zap.WithCtx(context.Background()).Sugar().Warn(err, e.JSONParsingFailed.GetMsg())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ login, rescode := users.CodeLogin(userRegist)
|
|
|
+ if rescode == e.SUCCESS {
|
|
|
+ e.ResponseSuccess(c, login)
|
|
|
+ } else {
|
|
|
+ e.ResponseWithMsg(c, rescode, rescode.GetMsg())
|
|
|
+ simple_zap.WithCtx(context.Background()).Sugar().Warn(err, rescode.GetMsg())
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// GetUserAll 获取所有用户
|
|
|
|
|
|
func GetUserAll(c *gin.Context) {
|
|
|
- user, rescode := users.GetUserAll()
|
|
|
- if rescode == e.SUCCESS {
|
|
|
- e.ResponseSuccess(c, user)
|
|
|
- } else {
|
|
|
- e.ResponseWithMsg(c, rescode, rescode.GetMsg())
|
|
|
- }
|
|
|
+ user, rescode := users.GetUserAll()
|
|
|
+ if rescode == e.SUCCESS {
|
|
|
+ e.ResponseSuccess(c, user)
|
|
|
+ } else {
|
|
|
+ e.ResponseWithMsg(c, rescode, rescode.GetMsg())
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// GetUserAlls 获取所有用户
|
|
@@ -131,20 +131,20 @@ func GetUserAll(c *gin.Context) {
|
|
|
// @Accept application/json
|
|
|
// @Router /admin/getalluser [post]
|
|
|
func GetUserAlls(c *gin.Context) {
|
|
|
- var pages page.PageParams
|
|
|
- err := c.ShouldBindJSON(&pages)
|
|
|
- if err != nil {
|
|
|
- e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
|
|
|
- simple_zap.WithCtx(context.Background()).Sugar().Warn(err, e.JSONParsingFailed.GetMsg())
|
|
|
- return
|
|
|
- }
|
|
|
- result, total, err := page.Paginate(global.DBLink, pages, models.User{})
|
|
|
- if err != nil {
|
|
|
- e.ResponseWithMsg(c, e.PaginationFailed, e.PaginationFailed.GetMsg())
|
|
|
- simple_zap.WithCtx(context.Background()).Sugar().Warn(err, e.PaginationFailed.GetMsg())
|
|
|
- return
|
|
|
- }
|
|
|
- e.ResPonsePage(c, result, total, pages)
|
|
|
+ var pages page.PageParams
|
|
|
+ err := c.ShouldBindJSON(&pages)
|
|
|
+ if err != nil {
|
|
|
+ e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
|
|
|
+ simple_zap.WithCtx(context.Background()).Sugar().Warn(err, e.JSONParsingFailed.GetMsg())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ result, total, err := page.Paginate(global.DBLink, pages, models.User{})
|
|
|
+ if err != nil {
|
|
|
+ e.ResponseWithMsg(c, e.PaginationFailed, e.PaginationFailed.GetMsg())
|
|
|
+ simple_zap.WithCtx(context.Background()).Sugar().Warn(err, e.PaginationFailed.GetMsg())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ e.ResPonsePage(c, result, total, pages)
|
|
|
}
|
|
|
|
|
|
// UpdateUserById 修改用户信息
|
|
@@ -156,22 +156,22 @@ func GetUserAlls(c *gin.Context) {
|
|
|
// @Accept application/json
|
|
|
// @Router /admin/user [post]
|
|
|
func UpdateUserById(c *gin.Context) {
|
|
|
- var userVo models.UserVo
|
|
|
- userId := c.MustGet("user_id")
|
|
|
- err := c.ShouldBindJSON(&userVo)
|
|
|
- if err != nil {
|
|
|
- e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
|
|
|
- simple_zap.WithCtx(context.Background()).Sugar().Warn(err, e.JSONParsingFailed.GetMsg())
|
|
|
- return
|
|
|
- }
|
|
|
- recode := users.UpdateUser(userId, userVo)
|
|
|
- if recode == e.SUCCESS {
|
|
|
- e.ResponseSuccess(c, "修改成功")
|
|
|
- } else {
|
|
|
- e.ResponseWithMsg(c, recode, recode.GetMsg())
|
|
|
- simple_zap.WithCtx(context.Background()).Sugar().Info(err, recode.GetMsg())
|
|
|
+ var userVo models.UserVo
|
|
|
+ userId := c.MustGet("user_id")
|
|
|
+ err := c.ShouldBindJSON(&userVo)
|
|
|
+ if err != nil {
|
|
|
+ e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
|
|
|
+ simple_zap.WithCtx(context.Background()).Sugar().Warn(err, e.JSONParsingFailed.GetMsg())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ recode := users.UpdateUser(userId, userVo)
|
|
|
+ if recode == e.SUCCESS {
|
|
|
+ e.ResponseSuccess(c, "修改成功")
|
|
|
+ } else {
|
|
|
+ e.ResponseWithMsg(c, recode, recode.GetMsg())
|
|
|
+ simple_zap.WithCtx(context.Background()).Sugar().Info(err, recode.GetMsg())
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// DeleteUserById 删除用户信息
|
|
@@ -183,14 +183,14 @@ func UpdateUserById(c *gin.Context) {
|
|
|
// @Accept application/json
|
|
|
// @Router /admin/user [delete]
|
|
|
func DeleteUserById(c *gin.Context) {
|
|
|
- ids := c.QueryArray("ids")
|
|
|
- recode := users.DeleteUser(ids)
|
|
|
- if recode == e.SUCCESS {
|
|
|
- e.ResponseSuccess(c, "删除成功")
|
|
|
- } else {
|
|
|
- e.ResponseWithMsg(c, recode, recode.GetMsg())
|
|
|
- simple_zap.WithCtx(context.Background()).Sugar().Info(recode.GetMsg())
|
|
|
- }
|
|
|
+ ids := c.QueryArray("ids")
|
|
|
+ recode := users.DeleteUser(ids)
|
|
|
+ if recode == e.SUCCESS {
|
|
|
+ e.ResponseSuccess(c, "删除成功")
|
|
|
+ } else {
|
|
|
+ e.ResponseWithMsg(c, recode, recode.GetMsg())
|
|
|
+ simple_zap.WithCtx(context.Background()).Sugar().Info(recode.GetMsg())
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -203,23 +203,23 @@ func DeleteUserById(c *gin.Context) {
|
|
|
// @Accept application/json
|
|
|
// @Router /user [post]
|
|
|
func UpdatePassword(c *gin.Context) {
|
|
|
- var userRegist models.UserUpdate
|
|
|
- err := c.ShouldBindJSON(&userRegist)
|
|
|
- if err != nil {
|
|
|
- e.ResponseError(c, e.JSONParsingFailed)
|
|
|
- return
|
|
|
- }
|
|
|
- validate := validator.New()
|
|
|
- err = validate.Struct(userRegist)
|
|
|
- if err != nil {
|
|
|
- e.ResponseWithMsg(c, e.ERROR, err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- rescode := users.UpdatePassword(userRegist)
|
|
|
- if rescode == e.SUCCESS {
|
|
|
- e.ResponseSuccess(c, nil)
|
|
|
- return
|
|
|
- } else {
|
|
|
- e.ResponseWithMsg(c, rescode, rescode.GetMsg())
|
|
|
- }
|
|
|
+ var userRegist models.UserUpdate
|
|
|
+ err := c.ShouldBindJSON(&userRegist)
|
|
|
+ if err != nil {
|
|
|
+ e.ResponseError(c, e.JSONParsingFailed)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ validate := validator.New()
|
|
|
+ err = validate.Struct(userRegist)
|
|
|
+ if err != nil {
|
|
|
+ e.ResponseWithMsg(c, e.ERROR, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rescode := users.UpdatePassword(userRegist)
|
|
|
+ if rescode == e.SUCCESS {
|
|
|
+ e.ResponseSuccess(c, nil)
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ e.ResponseWithMsg(c, rescode, rescode.GetMsg())
|
|
|
+ }
|
|
|
}
|