diff --git a/app/enterprise/api/user.go b/app/enterprise/api/user.go index 7b059a9..e0e8b76 100644 --- a/app/enterprise/api/user.go +++ b/app/enterprise/api/user.go @@ -10,6 +10,28 @@ import ( type User struct{} +type ( + // userSettledForm 入驻平台参数 + userSettledForm struct { + api.IDStringForm + api.ImageForm + Name string `json:"name" form:"name"` + Code string `json:"code" form:"code"` + config.Area + Introduce string `json:"introduce" form:"introduce"` + Industry uint64 `json:"industry" form:"industry"` + Keywords []string `json:"keywords" form:"keywords"` + } + // userBankForm 银行平台信息参数 + userBankForm struct { + Name string `json:"name" form:"name" binding:"required"` + IDCard string `json:"id_card" form:"id_card" binding:"required"` + BackCard string `json:"back_card" form:"back_card" binding:"required"` + BackName string `json:"back_name" form:"back_name" binding:"required"` + Captcha string `json:"captcha" form:"captcha" binding:"required"` + } +) + func (a *User) Info(c *gin.Context) { data := user.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise)).Info() api.APISuccess(data) @@ -20,20 +42,9 @@ func (a *User) Detail(c *gin.Context) { api.APIResponse(err, data)(c) } -type SettledBasic struct { - api.IDStringForm - api.ImageForm - Name string `json:"name" form:"name"` - Code string `json:"code" form:"code"` - config.Area - Introduce string `json:"introduce" form:"introduce"` - Industry uint64 `json:"industry" form:"industry"` - Keywords []string `json:"keywords" form:"keywords"` -} - func (a *Tenant) SettledCompany(c *gin.Context) { form := &struct { - SettledBasic + userSettledForm }{} if err := api.Bind(form)(c); err != nil { api.APIFailure(err.(error))(c) @@ -48,7 +59,7 @@ func (a *Tenant) SettledCompany(c *gin.Context) { func (a *Tenant) SettledExpert(c *gin.Context) { form := &struct { - SettledBasic + userSettledForm config.IdentityForExpert }{} if err := api.Bind(form)(c); err != nil { @@ -63,7 +74,7 @@ func (a *Tenant) SettledExpert(c *gin.Context) { func (a *Tenant) SettledResearch(c *gin.Context) { form := &struct { - SettledBasic + userSettledForm config.IdentityForResearch }{} if err := api.Bind(form)(c); err != nil { @@ -79,7 +90,7 @@ func (a *Tenant) SettledResearch(c *gin.Context) { func (a *Tenant) SettledLaboratory(c *gin.Context) { form := &struct { - SettledBasic + userSettledForm config.IdentityForLaboratory }{} if err := api.Bind(form)(c); err != nil { @@ -104,3 +115,35 @@ func (a *User) SwitchIdentity(c *gin.Context) { err := user.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise)).SwitchIdentity(form.Identity) api.APIResponse(err)(c) } + +func (a *User) Back(c *gin.Context) { + data, err := user.NewBack()(api.GetSession()(c).(*service.SessionEnterprise)).List() + api.APIResponse(err, data) +} + +func (a *User) BackBind(c *gin.Context) { + form := new(userBankForm) + + if err := api.Bind(form)(c); err != nil { + api.APIFailure(err.(error))(c) + return + } + err := user.NewBack()(api.GetSession()(c).(*service.SessionEnterprise)).Bind(&user.BackParams{ + Name: form.Name, + IDCard: form.IDCard, + BackCard: form.BackCard, + BackName: form.BackName, + }, form.Captcha) + api.APIResponse(err) +} + +func (a *User) BackUnbind(c *gin.Context) { + form := new(api.IDStringForm) + + if err := api.Bind(form)(c); err != nil { + api.APIFailure(err.(error))(c) + return + } + err := user.NewBack()(api.GetSession()(c).(*service.SessionEnterprise)).Unbind(form.Convert()) + api.APIResponse(err) +} diff --git a/app/enterprise/controller/user/bank.go b/app/enterprise/controller/user/bank.go index 8c8a86d..a027fb8 100644 --- a/app/enterprise/controller/user/bank.go +++ b/app/enterprise/controller/user/bank.go @@ -3,6 +3,7 @@ package user import ( model2 "SciencesServer/app/common/model" "SciencesServer/app/enterprise/model" + "SciencesServer/app/handle" "SciencesServer/app/service" "SciencesServer/utils" "errors" @@ -58,7 +59,16 @@ func (c *Back) List() ([]*BackInfo, error) { } // Bind 绑定 -func (c *Back) Bind(params *BackParams) error { +func (c *Back) Bind(params *BackParams, captcha string) error { + pass, err := handle.NewCaptcha().Validate(&handle.CaptchaSms{ + Mobile: c.Mobile, Captcha: captcha, + }) + if err != nil { + return err + } else if !pass { + return errors.New("验证码错误或已过期") + } + if !params.checkIDCard() { return errors.New("身份证号信息错误") } @@ -69,9 +79,7 @@ func (c *Back) Bind(params *BackParams) error { var count int64 - err := model2.Count(mUserManageBack.UserManageBank, &count, model2.NewWhere("back_card", params.BackCard)) - - if err != nil { + if err = model2.Count(mUserManageBack.UserManageBank, &count, model2.NewWhere("back_card", params.BackCard)); err != nil { return err } else if count > 0 { return errors.New("当前银行卡已被注册")