feat:优化项目结构
This commit is contained in:
@ -1,8 +1,11 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
account2 "SciencesServer/app/api/enterprise/controller/account"
|
||||
"SciencesServer/app/api/enterprise/controller/account"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/config"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -32,7 +35,7 @@ func (a *Account) Login(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := account2.NewLogin()(api.GetLocal()(c).(string)).Launch(account2.LoginMode(form.Mode), &account2.LoginParams{
|
||||
data, err := account.NewLogin()(api.GetLocal()(c).(string)).Launch(account.LoginMode(form.Mode), &account.LoginParams{
|
||||
Captcha: struct {
|
||||
Mobile string
|
||||
Captcha string
|
||||
@ -52,7 +55,7 @@ func (a *Account) Register(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := account2.NewRegister()(api.GetLocal()(c).(string)).Launch(&account2.RegisterParams{
|
||||
data, err := account.NewRegister()(api.GetLocal()(c).(string)).Launch(&account.RegisterParams{
|
||||
Name: form.Name, Mobile: form.Mobile, Captcha: form.Captcha,
|
||||
Password: form.Password, RepeatPass: form.RepeatPass, Identity: form.Identity,
|
||||
})
|
||||
@ -63,16 +66,14 @@ func (*Account) Authorize(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (*Account) BindMobile(c *gin.Context) {
|
||||
//account.NewOther()().BindMobile()
|
||||
}
|
||||
|
||||
func (*Account) Logout(c *gin.Context) {
|
||||
// 因跳过中间键,故只能自己去获取token用户信息
|
||||
//token := c.GetHeader(config.APIRequestToken)
|
||||
token := c.GetHeader(config.APIRequestToken)
|
||||
|
||||
//session, _ := service.NewAuthToken(token).Auth()
|
||||
_session := session.NewEnterprise()
|
||||
|
||||
err := account2.NewLogout()(nil).Launch()
|
||||
_ = service.NewAuthToken(token).Auth(_session)
|
||||
|
||||
err := account.NewLogout()(_session).Launch()
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package api
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/controller/identity"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -19,7 +19,7 @@ func (*Identity) Expert(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := identity.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
data, err := identity.NewInstance()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Expert(form.Name, form.Mobile, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
technology2 "SciencesServer/app/api/enterprise/controller/technology"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/basic/config"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
config2 "SciencesServer/config"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strings"
|
||||
@ -110,7 +110,7 @@ func (a *Technology) Instance(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology2.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
data, err := technology2.NewInstance()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
List(form.Status, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
@ -122,7 +122,7 @@ func (a *Technology) InstanceAdd(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewInstance()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&technology2.InstanceParams{
|
||||
PatentID: form.PatentID, Territory: form.Territory, Title: form.Title, Company: form.Company,
|
||||
Images: form.FilterImageURL(), ProveImages: form.FilterProveImages(), Introduce: form.Introduce, Purpose: form.Purpose,
|
||||
@ -141,7 +141,7 @@ func (a *Technology) InstanceEdit(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewInstance()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&technology2.InstanceParams{
|
||||
ID: form.Convert(),
|
||||
PatentID: form.PatentID, Territory: form.Territory, Title: form.Title, Company: form.Company,
|
||||
@ -161,7 +161,7 @@ func (a *Technology) InstanceShelf(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewInstance()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Shelf(form.Convert(), form.Status)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
@ -173,7 +173,7 @@ func (a *Technology) InstanceDelete(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewInstance()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
@ -187,7 +187,7 @@ func (a *Technology) Paper(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology2.NewPaper()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
data, err := technology2.NewPaper()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
List(form.Title, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
@ -199,7 +199,7 @@ func (a *Technology) PaperAdd(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewPaper()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewPaper()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&technology2.PaperParams{
|
||||
Title: form.Title, Ext: form.Ext, Author: form.Author, PublishAt: form.PublishAt,
|
||||
Keyword: form.Keyword, Tags: form.Tags, Remark: form.Remark,
|
||||
@ -216,7 +216,7 @@ func (a *Technology) PaperEdit(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewPaper()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewPaper()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&technology2.PaperParams{
|
||||
ID: form.Convert(), Title: form.Title, Ext: form.Ext, Author: form.Author, PublishAt: form.PublishAt,
|
||||
Keyword: form.Keyword, Tags: form.Tags, Remark: form.Remark,
|
||||
@ -231,7 +231,7 @@ func (a *Technology) PaperDelete(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewPaper()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewPaper()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
@ -245,7 +245,7 @@ func (a *Technology) Patent(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology2.NewPatent()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
data, err := technology2.NewPatent()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
List(form.Title, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
@ -257,7 +257,7 @@ func (a *Technology) PatentDetail(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology2.NewPatent()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
data, err := technology2.NewPatent()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Detail(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
@ -269,7 +269,7 @@ func (a *Technology) PatentAdd(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewPatent()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewPatent()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&technology2.PatentParams{
|
||||
Title: form.Title, IPCCode: form.IPCCode, CPCCode: form.CPCCode, ApplyCode: form.ApplyCode,
|
||||
ApplyName: form.ApplyName, ApplyAddress: form.ApplyAddress, ApplyZipCode: form.ApplyZipCode,
|
||||
@ -288,7 +288,7 @@ func (a *Technology) PatentEdit(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewPatent()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewPatent()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&technology2.PatentParams{
|
||||
ID: form.Convert(), Title: form.Title, IPCCode: form.IPCCode, CPCCode: form.CPCCode,
|
||||
ApplyCode: form.ApplyCode, ApplyName: form.ApplyName, ApplyAddress: form.ApplyAddress,
|
||||
@ -305,7 +305,7 @@ func (a *Technology) PatentDelete(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewPatent()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewPatent()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
@ -319,7 +319,7 @@ func (a *Technology) Demand(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology2.NewDemand()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
data, err := technology2.NewDemand()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
List(form.Status, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
@ -331,7 +331,7 @@ func (a *Technology) DemandDetail(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology2.NewDemand()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
data, err := technology2.NewDemand()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Detail(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
@ -343,7 +343,7 @@ func (a *Technology) DemandAdd(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewDemand()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewDemand()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&technology2.DemandParams{
|
||||
Title: form.Title, Introduce: form.Introduce, Name: form.Name, Mobile: form.Mobile, Deadline: form.Deadline,
|
||||
Industry: form.Industry, Kinds: form.Kinds, Area: form.Area, Budget: form.Budget, BudgetMode: form.BudgetMode,
|
||||
@ -365,7 +365,7 @@ func (a *Technology) DemandEdit(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewDemand()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewDemand()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&technology2.DemandParams{
|
||||
ID: form.Convert(), Title: form.Title, Introduce: form.Introduce, Name: form.Name, Mobile: form.Mobile, Deadline: form.Deadline,
|
||||
Industry: form.Industry, Kinds: form.Kinds, Area: form.Area, Budget: form.Budget, BudgetMode: form.BudgetMode,
|
||||
@ -385,7 +385,7 @@ func (a *Technology) DemandDelete(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewDemand()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewDemand()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
@ -399,7 +399,7 @@ func (a *Technology) Topic(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology2.NewTopic()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
data, err := technology2.NewTopic()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
List(form.Status, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
@ -411,7 +411,7 @@ func (a *Technology) TopicDetail(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology2.NewTopic()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
data, err := technology2.NewTopic()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Detail(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
@ -423,7 +423,7 @@ func (a *Technology) TopicAdd(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewTopic()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewTopic()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&technology2.TopicParams{Title: form.Title, Emcee: form.Emcee, Mechanism: form.Mechanism, Code: form.Code,
|
||||
BeginAt: form.BeginAt, FinishAt: form.FinishAt, Amount: form.Amount, Source: form.Source, Kind: form.Kind,
|
||||
Keywords: form.Keywords})
|
||||
@ -439,7 +439,7 @@ func (a *Technology) TopicEdit(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewTopic()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewTopic()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&technology2.TopicParams{ID: form.Convert(), Title: form.Title, Emcee: form.Emcee, Mechanism: form.Mechanism,
|
||||
Code: form.Code, BeginAt: form.BeginAt, FinishAt: form.FinishAt, Amount: form.Amount, Source: form.Source,
|
||||
Kind: form.Kind, Keywords: form.Keywords})
|
||||
@ -453,7 +453,7 @@ func (a *Technology) TopicDelete(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewTopic()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewTopic()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
@ -467,7 +467,7 @@ func (a *Technology) Equipment(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology2.NewEquipment()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
data, err := technology2.NewEquipment()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
List(form.Title, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
@ -479,7 +479,7 @@ func (a *Technology) EquipmentAdd(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewEquipment()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewEquipment()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&technology2.EquipmentParams{Title: form.Title, Research: form.Research, Describe: form.Describe})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
@ -493,7 +493,7 @@ func (a *Technology) EquipmentEdit(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewEquipment()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewEquipment()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&technology2.EquipmentParams{ID: form.Convert(), Title: form.Title, Research: form.Research, Describe: form.Describe})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
@ -505,7 +505,7 @@ func (a *Technology) EquipmentDelete(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewEquipment()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)).
|
||||
err := technology2.NewEquipment()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
user2 "SciencesServer/app/api/enterprise/controller/user"
|
||||
"SciencesServer/app/api/enterprise/controller/user"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/basic/config"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -32,17 +32,30 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (a *User) Info(c *gin.Context) {
|
||||
data := user2.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise)).Info()
|
||||
func (*User) Info(c *gin.Context) {
|
||||
data := user.NewInstance()(api.GetSession()(c).(*session.Enterprise)).Info()
|
||||
api.APISuccess(data)
|
||||
}
|
||||
|
||||
func (a *User) Detail(c *gin.Context) {
|
||||
data, err := user2.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise)).Detail()
|
||||
func (*User) Detail(c *gin.Context) {
|
||||
data, err := user.NewInstance()(api.GetSession()(c).(*session.Enterprise)).Detail()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *User) SettledCompany(c *gin.Context) {
|
||||
func (*User) BindMobile(c *gin.Context) {
|
||||
form := &struct {
|
||||
Mobile string `json:"mobile" form:"mobile" binding:"required"`
|
||||
Captcha string `json:"captcha" form:"captcha" binding:"required"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user.NewInstance()(api.GetSession()(c).(*session.Enterprise)).BindMobile(form.Mobile, form.Captcha)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*User) SettledCompany(c *gin.Context) {
|
||||
form := &struct {
|
||||
userSettledForm
|
||||
}{}
|
||||
@ -50,14 +63,14 @@ func (a *User) SettledCompany(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user2.NewSettled()(api.GetSession()(c).(*service.SessionEnterprise)).Company(&user2.SettledParams{
|
||||
err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Company(&user.SettledParams{
|
||||
ID: form.Convert(), Image: form.FilterImageURL(), Name: form.Name, Code: form.Code,
|
||||
Area: form.Area, Introduce: form.Introduce, Industry: form.Industry, Keywords: form.Keywords,
|
||||
}, nil)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *User) SettledExpert(c *gin.Context) {
|
||||
func (*User) SettledExpert(c *gin.Context) {
|
||||
form := &struct {
|
||||
userSettledForm
|
||||
config.IdentityForExpert
|
||||
@ -66,14 +79,14 @@ func (a *User) SettledExpert(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user2.NewSettled()(api.GetSession()(c).(*service.SessionEnterprise)).Expert(&user2.SettledParams{
|
||||
err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Expert(&user.SettledParams{
|
||||
ID: form.Convert(), Area: form.Area, Introduce: form.Introduce, Industry: form.Industry,
|
||||
Keywords: form.Keywords,
|
||||
}, &form.IdentityForExpert)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *User) SettledResearch(c *gin.Context) {
|
||||
func (*User) SettledResearch(c *gin.Context) {
|
||||
form := &struct {
|
||||
userSettledForm
|
||||
config.IdentityForResearch
|
||||
@ -82,14 +95,14 @@ func (a *User) SettledResearch(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user2.NewSettled()(api.GetSession()(c).(*service.SessionEnterprise)).Research(&user2.SettledParams{
|
||||
err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Research(&user.SettledParams{
|
||||
ID: form.Convert(), Image: form.FilterImageURL(), Name: form.Name, Code: form.Code,
|
||||
Area: form.Area, Introduce: form.Introduce, Industry: form.Industry, Keywords: form.Keywords,
|
||||
}, &form.IdentityForResearch)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *User) SettledLaboratory(c *gin.Context) {
|
||||
func (*User) SettledLaboratory(c *gin.Context) {
|
||||
form := &struct {
|
||||
userSettledForm
|
||||
config.IdentityForLaboratory
|
||||
@ -98,14 +111,14 @@ func (a *User) SettledLaboratory(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user2.NewSettled()(api.GetSession()(c).(*service.SessionEnterprise)).Laboratory(&user2.SettledParams{
|
||||
err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Laboratory(&user.SettledParams{
|
||||
ID: form.Convert(), Image: form.FilterImageURL(), Name: form.Name, Code: form.Code,
|
||||
Area: form.Area, Introduce: form.Introduce, Industry: form.Industry, Keywords: form.Keywords,
|
||||
}, &form.IdentityForLaboratory)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *User) SwitchIdentity(c *gin.Context) {
|
||||
func (*User) SwitchIdentity(c *gin.Context) {
|
||||
form := &struct {
|
||||
Identity int `json:"identity" form:"identity" binding:"required"`
|
||||
}{}
|
||||
@ -113,38 +126,35 @@ func (a *User) SwitchIdentity(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user2.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise)).SwitchIdentity(form.Identity)
|
||||
err := user.NewInstance()(api.GetSession()(c).(*session.Enterprise)).SwitchIdentity(form.Identity)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *User) Back(c *gin.Context) {
|
||||
data, err := user2.NewBank()(api.GetSession()(c).(*service.SessionEnterprise)).List()
|
||||
func (*User) Back(c *gin.Context) {
|
||||
data, err := user.NewBank()(api.GetSession()(c).(*session.Enterprise)).List()
|
||||
api.APIResponse(err, data)
|
||||
}
|
||||
|
||||
func (a *User) BackBind(c *gin.Context) {
|
||||
func (*User) BackBind(c *gin.Context) {
|
||||
form := new(userBankForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user2.NewBank()(api.GetSession()(c).(*service.SessionEnterprise)).Bind(&user2.BankParams{
|
||||
Name: form.Name,
|
||||
IDCard: form.IDCard,
|
||||
BankCard: form.BackCard,
|
||||
BankName: form.BackName,
|
||||
err := user.NewBank()(api.GetSession()(c).(*session.Enterprise)).Bind(&user.BankParams{
|
||||
Name: form.Name, IDCard: form.IDCard, BankCard: form.BackCard, BankName: form.BackName,
|
||||
}, form.Captcha)
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
||||
func (a *User) BackUnbind(c *gin.Context) {
|
||||
func (*User) BackUnbind(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user2.NewBank()(api.GetSession()(c).(*service.SessionEnterprise)).Unbind(form.Convert())
|
||||
err := user.NewBank()(api.GetSession()(c).(*session.Enterprise)).Unbind(form.Convert())
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
@ -2,25 +2,26 @@ package account
|
||||
|
||||
import (
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/utils"
|
||||
)
|
||||
|
||||
type Logout struct {
|
||||
*service.SessionEnterprise
|
||||
*session.Enterprise
|
||||
}
|
||||
|
||||
type LogoutHandle func(enterprise *service.SessionEnterprise) *Logout
|
||||
type LogoutHandle func(session *session.Enterprise) *Logout
|
||||
|
||||
func (c *Logout) Launch() error {
|
||||
if c.SessionEnterprise != nil && c.UID > 0 {
|
||||
if c.Enterprise != nil && c.UID > 0 {
|
||||
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewLogout() LogoutHandle {
|
||||
return func(enterprise *service.SessionEnterprise) *Logout {
|
||||
return &Logout{enterprise}
|
||||
return func(session *session.Enterprise) *Logout {
|
||||
return &Logout{Enterprise: session}
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"SciencesServer/app/handle"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Other struct{}
|
||||
|
||||
type OtherHandle func() *Other
|
||||
|
||||
// BindMobile 绑定手机号码
|
||||
func (c *Other) BindMobile(token, mobile, captcha string) (interface{}, error) {
|
||||
if !utils.ValidateMobile(mobile) {
|
||||
return nil, errors.New("手机号码格式异常")
|
||||
}
|
||||
pass, err := handle.NewCaptcha().Validate(&handle.CaptchaSms{
|
||||
Mobile: mobile, Captcha: captcha,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !pass {
|
||||
return nil, errors.New("验证码错误或已过期")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func NewOther() OtherHandle {
|
||||
return func() *Other {
|
||||
return &Other{}
|
||||
}
|
||||
}
|
@ -5,16 +5,16 @@ import (
|
||||
"SciencesServer/app/api/manage/controller"
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Instance struct {
|
||||
*service.SessionEnterprise
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type InstanceHandle func(enterprise *service.SessionEnterprise, local string) *Instance
|
||||
type InstanceHandle func(session *session.Enterprise, local string) *Instance
|
||||
|
||||
type (
|
||||
// InstanceForExpert 专家信息
|
||||
@ -64,10 +64,10 @@ func (c *Instance) Expert(name, mobile string, page, pageSize int) (*controller.
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(enterprise *service.SessionEnterprise, local string) *Instance {
|
||||
return func(session *session.Enterprise, local string) *Instance {
|
||||
return &Instance{
|
||||
SessionEnterprise: enterprise,
|
||||
local: local,
|
||||
Enterprise: session,
|
||||
local: local,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"SciencesServer/app/api/manage/controller"
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"time"
|
||||
@ -13,11 +13,11 @@ import (
|
||||
|
||||
// Demand 技术需求管理
|
||||
type Demand struct {
|
||||
*service.SessionEnterprise
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type DemandHandle func(enterprise *service.SessionEnterprise, local string) *Demand
|
||||
type DemandHandle func(session *session.Enterprise, local string) *Demand
|
||||
|
||||
type (
|
||||
// DemandInfo 需求信息
|
||||
@ -182,7 +182,7 @@ func (c *Demand) Delete(id uint64) error {
|
||||
}
|
||||
|
||||
func NewDemand() DemandHandle {
|
||||
return func(enterprise *service.SessionEnterprise, local string) *Demand {
|
||||
return &Demand{SessionEnterprise: enterprise, local: local}
|
||||
return func(session *session.Enterprise, local string) *Demand {
|
||||
return &Demand{Enterprise: session, local: local}
|
||||
}
|
||||
}
|
||||
|
@ -4,16 +4,16 @@ import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/api/manage/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Equipment struct {
|
||||
*service.SessionEnterprise
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type EquipmentHandle func(enterprise *service.SessionEnterprise, local string) *Equipment
|
||||
type EquipmentHandle func(session *session.Enterprise, local string) *Equipment
|
||||
|
||||
type EquipmentParams struct {
|
||||
ID uint64
|
||||
@ -102,10 +102,10 @@ func (c *Equipment) Delete(id uint64) error {
|
||||
}
|
||||
|
||||
func NewEquipment() EquipmentHandle {
|
||||
return func(enterprise *service.SessionEnterprise, local string) *Equipment {
|
||||
return func(session *session.Enterprise, local string) *Equipment {
|
||||
return &Equipment{
|
||||
SessionEnterprise: enterprise,
|
||||
local: local,
|
||||
Enterprise: session,
|
||||
local: local,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,18 +4,18 @@ import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/api/manage/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Instance 技术管理
|
||||
type Instance struct {
|
||||
*service.SessionEnterprise
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type InstanceHandle func(enterprise *service.SessionEnterprise, local string) *Instance
|
||||
type InstanceHandle func(session *session.Enterprise, local string) *Instance
|
||||
|
||||
type (
|
||||
// InstanceInfo 详细信息
|
||||
@ -157,7 +157,7 @@ func (c *Instance) Delete(id uint64) error {
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(enterprise *service.SessionEnterprise, local string) *Instance {
|
||||
return &Instance{SessionEnterprise: enterprise, local: local}
|
||||
return func(session *session.Enterprise, local string) *Instance {
|
||||
return &Instance{Enterprise: session, local: local}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/api/manage/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"time"
|
||||
@ -12,11 +12,11 @@ import (
|
||||
|
||||
// Paper 论文管理
|
||||
type Paper struct {
|
||||
*service.SessionEnterprise
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type PaperHandle func(enterprise *service.SessionEnterprise, local string) *Paper
|
||||
type PaperHandle func(session *session.Enterprise, local string) *Paper
|
||||
|
||||
type (
|
||||
PaperInfo struct {
|
||||
@ -113,7 +113,7 @@ func (c *Paper) Delete(id uint64) error {
|
||||
}
|
||||
|
||||
func NewPaper() PaperHandle {
|
||||
return func(enterprise *service.SessionEnterprise, local string) *Paper {
|
||||
return &Paper{SessionEnterprise: enterprise, local: local}
|
||||
return func(session *session.Enterprise, local string) *Paper {
|
||||
return &Paper{Enterprise: session, local: local}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/api/manage/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"time"
|
||||
@ -12,11 +12,11 @@ import (
|
||||
|
||||
// Patent 专利管理
|
||||
type Patent struct {
|
||||
*service.SessionEnterprise
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type PatentHandle func(enterprise *service.SessionEnterprise, local string) *Patent
|
||||
type PatentHandle func(session *session.Enterprise, local string) *Patent
|
||||
|
||||
type (
|
||||
// PatentInfo 专利信息
|
||||
@ -148,7 +148,7 @@ func (c *Patent) Delete(id uint64) error {
|
||||
}
|
||||
|
||||
func NewPatent() PatentHandle {
|
||||
return func(enterprise *service.SessionEnterprise, local string) *Patent {
|
||||
return &Patent{SessionEnterprise: enterprise, local: local}
|
||||
return func(session *session.Enterprise, local string) *Patent {
|
||||
return &Patent{Enterprise: session, local: local}
|
||||
}
|
||||
}
|
||||
|
@ -4,18 +4,18 @@ import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/api/manage/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Topic struct {
|
||||
*service.SessionEnterprise
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type TopicHandle func(enterprise *service.SessionEnterprise, local string) *Topic
|
||||
type TopicHandle func(session *session.Enterprise, local string) *Topic
|
||||
|
||||
type (
|
||||
// TopicInfo 课题信息
|
||||
@ -146,10 +146,10 @@ func (c *Topic) Delete(id uint64) error {
|
||||
}
|
||||
|
||||
func NewTopic() TopicHandle {
|
||||
return func(enterprise *service.SessionEnterprise, local string) *Topic {
|
||||
return func(session *session.Enterprise, local string) *Topic {
|
||||
return &Topic{
|
||||
SessionEnterprise: enterprise,
|
||||
local: local,
|
||||
Enterprise: session,
|
||||
local: local,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,16 +4,16 @@ import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/handle"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Bank struct {
|
||||
*service.SessionEnterprise
|
||||
*session.Enterprise
|
||||
}
|
||||
|
||||
type BankHandle func(enterprise *service.SessionEnterprise) *Bank
|
||||
type BankHandle func(session *session.Enterprise) *Bank
|
||||
|
||||
type (
|
||||
// BankInfo 银行卡信息
|
||||
@ -116,7 +116,7 @@ func (c *Bank) Unbind(id uint64) error {
|
||||
}
|
||||
|
||||
func NewBank() BankHandle {
|
||||
return func(enterprise *service.SessionEnterprise) *Bank {
|
||||
return &Bank{enterprise}
|
||||
return func(session *session.Enterprise) *Bank {
|
||||
return &Bank{Enterprise: session}
|
||||
}
|
||||
}
|
||||
|
@ -4,17 +4,20 @@ import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/handle"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
config2 "SciencesServer/config"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Instance struct{ *service.SessionEnterprise }
|
||||
type Instance struct{ *session.Enterprise }
|
||||
|
||||
type InstanceHandle func(enterprise *service.SessionEnterprise) *Instance
|
||||
type InstanceHandle func(session *session.Enterprise) *Instance
|
||||
|
||||
type (
|
||||
// InstanceInfo 基本信息
|
||||
@ -58,6 +61,36 @@ func (c *Instance) Detail() (*InstanceDetailInfo, error) {
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// BindMobile 绑定手机号码
|
||||
func (c *Instance) BindMobile(mobile, captcha string) error {
|
||||
if !utils.ValidateMobile(mobile) {
|
||||
return errors.New("操作错误,手机号码格式异常")
|
||||
}
|
||||
// 查询用户手机号码是否绑定
|
||||
mUserInstance := model.NewUserInstance()
|
||||
|
||||
if _, err := model2.FirstField(mUserInstance.UserInstance, []string{"id", "uuid", "mobile"}, model2.NewWhere("uuid", c.UID)); err != nil {
|
||||
return err
|
||||
}
|
||||
if mUserInstance.Mobile == mobile {
|
||||
return nil
|
||||
}
|
||||
pass, err := handle.NewCaptcha().Validate(&handle.CaptchaSms{
|
||||
Mobile: mobile, Captcha: captcha,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !pass {
|
||||
return errors.New("操作错误,验证码错误或已过期")
|
||||
}
|
||||
if err := model2.Updates(mUserInstance.UserInstance, map[string]interface{}{
|
||||
"mobile": mobile, "updated_at": time.Now(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SwitchIdentity 切换身份
|
||||
func (c *Instance) SwitchIdentity(identity int) error {
|
||||
if _, has := config.TenantUserIdentityData[identity]; !has {
|
||||
@ -96,12 +129,12 @@ func (c *Instance) SwitchIdentity(identity int) error {
|
||||
c.ManageUID = mUserManage.UUID
|
||||
}
|
||||
c.SelectIdentity = identity
|
||||
service.Publish(config2.EventForAccountLoginProduce, config2.RedisKeyForAccount, c.UIDToString(), c.SessionEnterprise)
|
||||
service.Publish(config2.EventForAccountLoginProduce, config2.RedisKeyForAccount, c.UIDToString(), c.Enterprise)
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(enterprise *service.SessionEnterprise) *Instance {
|
||||
return &Instance{SessionEnterprise: enterprise}
|
||||
return func(session *session.Enterprise) *Instance {
|
||||
return &Instance{Enterprise: session}
|
||||
}
|
||||
}
|
||||
|
@ -4,15 +4,15 @@ import (
|
||||
model3 "SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Settled 入驻
|
||||
type Settled struct{ *service.SessionEnterprise }
|
||||
type Settled struct{ *session.Enterprise }
|
||||
|
||||
type SettledHandle func(enterprise *service.SessionEnterprise) *Settled
|
||||
type SettledHandle func(session *session.Enterprise) *Settled
|
||||
|
||||
type SettledParams struct {
|
||||
ID uint64
|
||||
@ -185,7 +185,7 @@ func (c *Settled) Agent() {
|
||||
}
|
||||
|
||||
func NewSettled() SettledHandle {
|
||||
return func(enterprise *service.SessionEnterprise) *Settled {
|
||||
return &Settled{enterprise}
|
||||
return func(session *session.Enterprise) *Settled {
|
||||
return &Settled{Enterprise: session}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"SciencesServer/app/api/manage/controller"
|
||||
"SciencesServer/app/service"
|
||||
session "SciencesServer/app/session"
|
||||
"SciencesServer/config"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -81,8 +82,10 @@ func (a *Account) Logout(c *gin.Context) {
|
||||
// 因跳过中间键,故只能自己去获取token用户信息
|
||||
token := c.GetHeader(config.APIRequestToken)
|
||||
|
||||
session, _ := service.NewAuthToken(token).Auth()
|
||||
_session := session.NewManage()
|
||||
|
||||
err := controller.NewAccount()(session).Logout()
|
||||
_ = service.NewAuthToken(token).Auth(_session)
|
||||
|
||||
err := controller.NewAccount()(_session).Logout()
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
@ -4,14 +4,15 @@ import (
|
||||
model3 "SciencesServer/app/api/manage/model"
|
||||
"SciencesServer/app/handle"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Account struct{ *Platform }
|
||||
type Account struct{ *session.Manage }
|
||||
|
||||
type AccountHandle func(session *service.Session) *Account
|
||||
type AccountHandle func(session *session.Manage) *Account
|
||||
|
||||
type (
|
||||
AccountLoginResponse struct {
|
||||
@ -39,32 +40,32 @@ func (c *Account) Login(account, password, captchaKey, captchaValue, equipment,
|
||||
if !mSysUser.ValidatePassword(password) {
|
||||
return nil, errors.New("密码错误")
|
||||
}
|
||||
session := service.NewSession()
|
||||
session.UID = mSysUser.UUID
|
||||
session.Name = mSysUser.Name
|
||||
session.Mobile = mSysUser.Mobile
|
||||
session.IsAdmin = mSysUser.IsAdminUser()
|
||||
_session := service.NewSession()
|
||||
_session.UID = mSysUser.UUID
|
||||
_session.Name = mSysUser.Name
|
||||
_session.Mobile = mSysUser.Mobile
|
||||
_session.IsAdmin = mSysUser.IsAdminUser()
|
||||
|
||||
uid := mSysUser.UUIDString()
|
||||
|
||||
session.Token = utils.JWTEncrypt(config.SettingInfo.TokenEffectTime, map[string]interface{}{config.TokenForUID: uid})
|
||||
_session.Token = utils.JWTEncrypt(config.SettingInfo.TokenEffectTime, map[string]interface{}{config.TokenForUID: uid})
|
||||
|
||||
service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccount, uid, session)
|
||||
service.Publish(config.EventForAccountLoginProduce, session.TenantID, session.UID, equipment, ip)
|
||||
service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccount, uid, _session)
|
||||
service.Publish(config.EventForAccountLoginProduce, _session.TenantID, _session.UID, equipment, ip)
|
||||
|
||||
return &AccountLoginResponse{Token: session.Token, EffectTime: config.SettingInfo.TokenEffectTime}, nil
|
||||
return &AccountLoginResponse{Token: _session.Token, EffectTime: config.SettingInfo.TokenEffectTime}, nil
|
||||
}
|
||||
|
||||
// Logout 退出请求
|
||||
func (c *Account) Logout() error {
|
||||
if c.Session != nil && c.UID > 0 {
|
||||
if c.Manage != nil && c.UID > 0 {
|
||||
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewAccount() AccountHandle {
|
||||
return func(session *service.Session) *Account {
|
||||
return &Account{Platform: &Platform{Session: session}}
|
||||
return func(session *session.Manage) *Account {
|
||||
return &Account{Manage: session}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
type Platform struct{ *service.Session }
|
||||
|
||||
func (c *Platform) Format() string {
|
||||
return c.TenantKey
|
||||
return ""
|
||||
}
|
||||
|
||||
// ReturnPages 分页数据
|
||||
|
@ -4,8 +4,6 @@ import (
|
||||
"SciencesServer/app/api/manage/controller"
|
||||
model3 "SciencesServer/app/api/manage/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/logger"
|
||||
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
@ -59,16 +57,16 @@ func (c *Role) Bind(uid uint64, roleIDs []uint64) error {
|
||||
return err
|
||||
}
|
||||
go utils.TryCatch(func() {
|
||||
permission := service.NewPermission(obj)(c.TenantKey, utils.UintToString(uid))
|
||||
|
||||
if _, err = permission.DeleteRolesForUser(false); err != nil {
|
||||
logger.ErrorF("删除用户【%d】角色权限错误:%v", uid, err)
|
||||
return
|
||||
}
|
||||
if _, err = permission.AddRoleForUser(); err != nil {
|
||||
logger.ErrorF("添加用户【%d】角色权限错误:%v", uid, err)
|
||||
return
|
||||
}
|
||||
//permission := service.NewPermission(obj)(c.TenantKey, utils.UintToString(uid))
|
||||
//
|
||||
//if _, err = permission.DeleteRolesForUser(false); err != nil {
|
||||
// logger.ErrorF("删除用户【%d】角色权限错误:%v", uid, err)
|
||||
// return
|
||||
//}
|
||||
//if _, err = permission.AddRoleForUser(); err != nil {
|
||||
// logger.ErrorF("添加用户【%d】角色权限错误:%v", uid, err)
|
||||
// return
|
||||
//}
|
||||
})
|
||||
return nil
|
||||
})
|
||||
|
9
app/logic/isession.go
Normal file
9
app/logic/isession.go
Normal file
@ -0,0 +1,9 @@
|
||||
package logic
|
||||
|
||||
type ISession interface {
|
||||
SetToken(key string)
|
||||
GetToken() string
|
||||
|
||||
MarshalBinary() ([]byte, error)
|
||||
UnmarshalBinary(data []byte) error
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"SciencesServer/app/logic"
|
||||
"SciencesServer/config"
|
||||
cache2 "SciencesServer/serve/cache"
|
||||
"SciencesServer/utils"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
@ -13,31 +15,32 @@ type AuthToken struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
func (this *AuthToken) Auth() (*Session, error) {
|
||||
func (this *AuthToken) Auth(session logic.ISession) error {
|
||||
tokenInfo := utils.JWTDecrypt(this.Token)
|
||||
|
||||
if tokenInfo == nil || len(tokenInfo) <= 0 {
|
||||
return nil, errors.New("Token无效")
|
||||
return errors.New("登陆错误,Token无效")
|
||||
}
|
||||
expTimestamp := utils.StringToInt64(fmt.Sprintf("%v", tokenInfo["exp"]))
|
||||
expTime := time.Unix(expTimestamp, 0)
|
||||
ok := expTime.After(time.Now())
|
||||
|
||||
if !ok {
|
||||
return nil, errors.New("Token过期")
|
||||
return errors.New("登陆错误,Token过期")
|
||||
}
|
||||
cache, _ := cache2.Cache.HGet(config.RedisKeyForAccount, fmt.Sprintf("%v", tokenInfo[config.TokenForUID]))
|
||||
|
||||
if cache == "" {
|
||||
return nil, errors.New("用户未登录或已退出")
|
||||
return errors.New("登陆错误,用户未登录或已退出")
|
||||
}
|
||||
session := new(Session)
|
||||
_ = session.UnmarshalBinary([]byte(cache))
|
||||
|
||||
if !config.SettingInfo.MultipleLogin && session.Token != this.Token {
|
||||
return nil, errors.New("登录失效,已在其他地方登录!")
|
||||
if err := json.Unmarshal([]byte(cache), session); err != nil {
|
||||
return err
|
||||
}
|
||||
return session, nil
|
||||
if !config.SettingInfo.MultipleLogin && session.GetToken() != this.Token {
|
||||
return errors.New("登陆错误,已在其他地方登录!")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewAuthToken(token string) *AuthToken {
|
||||
|
@ -6,13 +6,12 @@ import (
|
||||
)
|
||||
|
||||
type Session struct {
|
||||
UID uint64 `json:"uid"` // 唯一标识ID
|
||||
Token string `json:"token"` // token
|
||||
Name string `json:"name"` // 名称
|
||||
Mobile string `json:"mobile"` // 手机号码
|
||||
IsAdmin bool `json:"is_admin"` // 是否超管
|
||||
TenantID uint64 `json:"tenant_id"` // 租户ID
|
||||
TenantKey string `json:"tenant_key"` // 租户标识,用来区别分库管理
|
||||
Token string `json:"token"` // token
|
||||
UID uint64 `json:"uid"` // 唯一标识ID
|
||||
TenantID uint64 `json:"tenant_id"` // 租户ID
|
||||
Name string `json:"name"` // 名称
|
||||
Mobile string `json:"mobile"` // 手机号码
|
||||
IsAdmin bool `json:"is_admin"` // 是否超管
|
||||
}
|
||||
|
||||
func (this *Session) MarshalBinary() ([]byte, error) {
|
||||
|
42
app/session/enterprise.go
Normal file
42
app/session/enterprise.go
Normal file
@ -0,0 +1,42 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"SciencesServer/utils"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// Enterprise 企业用户
|
||||
type Enterprise struct {
|
||||
Token string `json:"token"` // token
|
||||
UID uint64 `json:"uid"` // 唯一标识ID
|
||||
TenantID uint64 `json:"tenant_id"` // 租户ID
|
||||
ManageUID uint64 `json:"manage_uid"` // 管理平台用户唯一ID
|
||||
Name string `json:"name"` // 名称
|
||||
Mobile string `json:"mobile"` // 手机号码
|
||||
Identity int `json:"identity"` // 总身份信息
|
||||
SelectIdentity int `json:"select_identity"` // 选中身份信息
|
||||
}
|
||||
|
||||
func (this *Enterprise) SetToken(token string) {
|
||||
this.Token = token
|
||||
}
|
||||
|
||||
func (this *Enterprise) GetToken() string {
|
||||
return this.GetToken()
|
||||
}
|
||||
|
||||
func (this *Enterprise) UIDToString() string {
|
||||
return utils.UintToString(this.UID)
|
||||
}
|
||||
|
||||
func (this *Enterprise) MarshalBinary() ([]byte, error) {
|
||||
return json.Marshal(this)
|
||||
}
|
||||
|
||||
func (this *Enterprise) UnmarshalBinary(data []byte) error {
|
||||
return utils.FromJSONBytes(data, this)
|
||||
}
|
||||
|
||||
func NewEnterprise() *Enterprise {
|
||||
return &Enterprise{}
|
||||
}
|
36
app/session/manage.go
Normal file
36
app/session/manage.go
Normal file
@ -0,0 +1,36 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"SciencesServer/utils"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type Manage struct {
|
||||
UID uint64 `json:"uid"` // 唯一标识ID
|
||||
Token string `json:"token"` // token
|
||||
Name string `json:"name"` // 名称
|
||||
Mobile string `json:"mobile"` // 手机号码
|
||||
IsAdmin bool `json:"is_admin"` // 是否超管
|
||||
TenantID uint64 `json:"tenant_id"` // 租户ID
|
||||
TenantKey string `json:"tenant_key"` // 租户标识,用来区别分库管理
|
||||
}
|
||||
|
||||
func (this *Manage) SetToken(token string) {
|
||||
this.Token = token
|
||||
}
|
||||
|
||||
func (this *Manage) GetToken() string {
|
||||
return this.GetToken()
|
||||
}
|
||||
|
||||
func (this *Manage) MarshalBinary() ([]byte, error) {
|
||||
return json.Marshal(this)
|
||||
}
|
||||
|
||||
func (this *Manage) UnmarshalBinary(data []byte) error {
|
||||
return utils.FromJSONBytes(data, this)
|
||||
}
|
||||
|
||||
func NewManage() *Manage {
|
||||
return &Manage{}
|
||||
}
|
Reference in New Issue
Block a user