feat(user):增加企业用户开户功能。

This commit is contained in:
徐涛 2022-08-13 17:37:04 +08:00
parent 5197d9d74e
commit 64d63e7f20
2 changed files with 48 additions and 1 deletions

View File

@ -34,6 +34,7 @@ func InitializeUserController(router *gin.Engine) {
UserController.Router.PUT("/account/enabled/state", security.OPSAuthorize, UserController.SwitchUserEnabling)
UserController.Router.POST("/account", security.OPSAuthorize, UserController.CreateOPSAndManagementAccount)
UserController.Router.GET("/account/:uid", security.MustAuthenticated, UserController.GetUserDetail)
UserController.Router.POST("/enterprise", security.OPSAuthorize, UserController.CreateEnterpriseAccount)
}
type LoginFormData struct {
@ -256,3 +257,49 @@ func (_UserController) GetUserDetail(c *gin.Context) {
}
result.Json(http.StatusOK, http.StatusOK, "用户详细信息已获取到。", gin.H{"user": userDetail})
}
type EnterpriseCreationFormData struct {
Username string `json:"username" form:"username"`
Name string `json:"name" form:"name"`
Region *string `json:"region" form:"region"`
Address *string `json:"address" form:"address"`
Contact *string `json:"contact" form:"contact"`
Phone *string `json:"phone" form:"phone"`
UnitServiceFee *string `json:"unitServiceFee" form:"unitServiceFee"`
}
func (_UserController) CreateEnterpriseAccount(c *gin.Context) {
result := response.NewResult(c)
creationForm := new(EnterpriseCreationFormData)
c.BindJSON(creationForm)
exists, err := service.UserService.IsUsernameExists(creationForm.Username)
if exists {
result.Error(http.StatusConflict, "指定的用户名已经被使用了。")
return
}
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
newUser := new(model.User)
newUser.Username = creationForm.Username
newUser.Type = 0
newUser.Enabled = true
newUserDetail := new(model.UserDetail)
newUserDetail.Name = &creationForm.Name
newUserDetail.Contact = creationForm.Contact
newUserDetail.Phone = creationForm.Phone
newUserDetail.UnitServiceFee, err = decimal.NewFromString(*creationForm.UnitServiceFee)
if err != nil {
result.Error(http.StatusBadRequest, "用户月服务费无法解析。")
return
}
newUserDetail.ServiceExpiration = time.Now()
verifyCode, err := service.UserService.CreateUser(newUser, newUserDetail)
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
result.Json(http.StatusOK, http.StatusOK, "用户已经成功创建。", gin.H{"verify": verifyCode})
}

View File

@ -9,7 +9,7 @@ import (
type UserDetail struct {
CreatedAndModifiedWithUser `xorm:"extends"`
DeletedWithUser `xorm:"extends"`
Id string `xorm:"varchar(120) pk not null -" json:"-"`
Id string `xorm:"varchar(120) pk not null" json:"-"`
Name *string `xorm:"varchar(100)" json:"name"`
Abbr *string `xorm:"varchar(50)" json:"abbr"`
Region *string `xorm:"varchar(10)" json:"region"`