init
This commit is contained in:
@ -3,7 +3,6 @@ package api
|
||||
import (
|
||||
account2 "SciencesServer/app/api/enterprise/controller/account"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -12,7 +11,7 @@ type Account struct{}
|
||||
type (
|
||||
accountLoginForm struct {
|
||||
Mode int `json:"mode" form:"mode" binding:"required"`
|
||||
Mobile string `json:"mobile" form:"mobile"`
|
||||
Account string `json:"account" form:"account"`
|
||||
Captcha string `json:"captcha" form:"captcha"`
|
||||
Password string `json:"password" form:"password"`
|
||||
}
|
||||
@ -37,11 +36,11 @@ func (a *Account) Login(c *gin.Context) {
|
||||
Captcha: struct {
|
||||
Mobile string
|
||||
Captcha string
|
||||
}{Mobile: form.Mobile, Captcha: form.Captcha},
|
||||
}{Mobile: form.Account, Captcha: form.Captcha},
|
||||
Password: struct {
|
||||
Mobile string
|
||||
Account string
|
||||
Password string
|
||||
}{Mobile: form.Mobile, Password: form.Password},
|
||||
}{Account: form.Account, Password: form.Password},
|
||||
})
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
@ -60,18 +59,20 @@ func (a *Account) Register(c *gin.Context) {
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *Account) BindMobile(c *gin.Context) {
|
||||
func (*Account) Authorize(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (*Account) BindMobile(c *gin.Context) {
|
||||
//account.NewOther()().BindMobile()
|
||||
}
|
||||
|
||||
func (a *Account) Logout(c *gin.Context) {
|
||||
handle := api.GetSession()(c)
|
||||
func (*Account) Logout(c *gin.Context) {
|
||||
// 因跳过中间键,故只能自己去获取token用户信息
|
||||
//token := c.GetHeader(config.APIRequestToken)
|
||||
|
||||
session := new(service.SessionEnterprise)
|
||||
//session, _ := service.NewAuthToken(token).Auth()
|
||||
|
||||
if handle != nil {
|
||||
session = handle.(*service.SessionEnterprise)
|
||||
}
|
||||
err := account2.NewLogout()(session).Launch()
|
||||
err := account2.NewLogout()(nil).Launch()
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ type (
|
||||
Mobile, Captcha string
|
||||
}
|
||||
Password struct {
|
||||
Mobile, Password string
|
||||
Account, Password string
|
||||
}
|
||||
Platform struct {
|
||||
OpenID string
|
||||
@ -88,13 +88,13 @@ RETURNS:
|
||||
|
||||
// loginForPassword 密码登陆
|
||||
func loginForPassword(params *LoginParams, local string) (*InstanceLoginParams, error) {
|
||||
if !utils.ValidateMobile(params.Password.Mobile) {
|
||||
if !utils.ValidateMobile(params.Password.Account) {
|
||||
return nil, errors.New("手机号码格式异常")
|
||||
}
|
||||
mUserInstance := model3.NewUserInstance()
|
||||
|
||||
isExist, err := model2.FirstField(mUserInstance.UserInstance, []string{"id", "uuid", "mobile", "password", "salt", "status"},
|
||||
model2.NewWhere("mobile", params.Password.Mobile), model2.NewWhere("local", local))
|
||||
model2.NewWhere("mobile", params.Password.Account), model2.NewWhere("local", local))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -13,7 +13,7 @@ type Logout struct {
|
||||
type LogoutHandle func(enterprise *service.SessionEnterprise) *Logout
|
||||
|
||||
func (c *Logout) Launch() error {
|
||||
if c.UID > 0 {
|
||||
if c.SessionEnterprise != nil && c.UID > 0 {
|
||||
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
|
||||
}
|
||||
return nil
|
||||
|
@ -62,6 +62,7 @@ func (c *Register) Launch(params *RegisterParams) (*InstanceLoginReturn, error)
|
||||
return nil, errors.New("当前手机号码已注册")
|
||||
}
|
||||
mUserInstance.Local.Local = c.local
|
||||
mUserInstance.Source = model2.UserInstanceSourceForLocal
|
||||
mUserInstance.Password = utils.GetRandomString(12)
|
||||
mUserInstance.Mobile = params.Mobile
|
||||
mUserInstance.Password = params.Password
|
||||
|
@ -24,7 +24,7 @@ type (
|
||||
|
||||
// Expert 专家数据
|
||||
func (m *UserManage) Expert(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*UserManageForExpert, error) {
|
||||
query := orm.GetDB().Table(m.TableName()+" AS m").
|
||||
db := orm.GetDB().Table(m.TableName()+" AS m").
|
||||
Select(strings.Join([]string{"m.id", "m.name", "u.mobile", "m.identity_info"}, ",")).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON m.uid = u.uuid", model.NewUserInstance().TableName())).
|
||||
Where("m.is_deleted = ?", model.DeleteStatusForNot).
|
||||
@ -34,13 +34,13 @@ func (m *UserManage) Expert(page, pageSize int, count *int64, where ...*model.Mo
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
query = query.Where(v.Condition, v.Value)
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
if err := query.Count(count).Error; err != nil {
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := query.Order("m.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
if err := db.Order("m.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
|
@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"SciencesServer/app/api/manage/controller"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/config"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@ -77,13 +78,11 @@ func (a *Account) Login(c *gin.Context) {
|
||||
* }
|
||||
*/
|
||||
func (a *Account) Logout(c *gin.Context) {
|
||||
handle := getSession()(c)
|
||||
// 因跳过中间键,故只能自己去获取token用户信息
|
||||
token := c.GetHeader(config.APIRequestToken)
|
||||
|
||||
session := new(service.Session)
|
||||
session, _ := service.NewAuthToken(token).Auth()
|
||||
|
||||
if handle != nil {
|
||||
session = handle.(*service.Session)
|
||||
}
|
||||
err := controller.NewAccount()(session).Logout()
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/manage/controller/manage"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -11,7 +13,26 @@ func (*Manage) Company(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (*Manage) CompanyExamine(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (*Manage) Expert(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
Status int `json:"status" form:"status"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := manage.NewInstance()(api.GetSession()(c).(*service.Session), api.GetLocal()(c).(string)).
|
||||
Expert(form.Name, form.Status, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)
|
||||
}
|
||||
|
||||
func (*Manage) ExpertExamine(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
@ -27,9 +48,13 @@ func (*Menu) Examine(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
Identity int `json:"identity" form:"identity" binding:"required"`
|
||||
Status int `json:"status" form:"status" binding:"required"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := manage.NewExamine()(api.GetSession()(c).(*service.Session), api.GetLocal()(c).(string)).
|
||||
Launch(form.Convert(), form.Identity, form.Status)
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
@ -57,7 +57,9 @@ func (c *Account) Login(account, password, captchaKey, captchaValue, equipment,
|
||||
|
||||
// Logout 退出请求
|
||||
func (c *Account) Logout() error {
|
||||
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
|
||||
if c.Session != nil && c.UID > 0 {
|
||||
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,10 @@ type ExamineManageInfo struct {
|
||||
|
||||
// examineHandle 审核处理
|
||||
var examineHandle = map[int]func(uint64) (*ExamineManageInfo, error){
|
||||
config.TenantUserIdentityForCompany: examineCompany,
|
||||
config.TenantUserIdentityForExpert: examineExpert,
|
||||
config.TenantUserIdentityForCompany: examineCompany,
|
||||
config.TenantUserIdentityForExpert: examineExpert,
|
||||
config.TenantUserIdentityForResearch: examineResearch,
|
||||
config.TenantUserIdentityForLaboratory: examineLaboratory,
|
||||
}
|
||||
|
||||
func checkManage(IModel model2.IModel, id uint64) error {
|
||||
@ -56,7 +58,7 @@ func examineCompany(id uint64) (*ExamineManageInfo, error) {
|
||||
return &ExamineManageInfo{
|
||||
IModel: mManageCompany.ManageCompany, UID: mManageCompany.UID,
|
||||
IdentityInfo: &model2.UserIdentityForCompany{
|
||||
Industry: mManageCompany.Industry, Keyword: mManageCompany.Keyword,
|
||||
Industry: mManageCompany.Industry, Keyword: mManageCompany.Keyword, CreatedAt: time.Now(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@ -75,6 +77,45 @@ func examineExpert(id uint64) (*ExamineManageInfo, error) {
|
||||
IModel: mManageExpert.ManageExpert, UID: mManageExpert.UID,
|
||||
IdentityInfo: &model2.UserIdentityForExpert{
|
||||
Industry: mManageExpert.Industry, Keyword: mManageExpert.Keyword, Research: mManageExpert.Research,
|
||||
CreatedAt: time.Now(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func examineResearch(id uint64) (*ExamineManageInfo, error) {
|
||||
mManageResearch := model.NewManageResearch()
|
||||
|
||||
err := checkManage(mManageResearch.ManageResearch, id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if mManageResearch.Status != model2.ExamineStatusForOngoing {
|
||||
return nil, errors.New("当前入住信息已审核")
|
||||
}
|
||||
return &ExamineManageInfo{
|
||||
IModel: mManageResearch.ManageResearch, UID: mManageResearch.UID,
|
||||
IdentityInfo: &model2.UserIdentityForResearch{
|
||||
Name: mManageResearch.Name, Industry: mManageResearch.Industry, Keyword: mManageResearch.Keyword,
|
||||
Research: mManageResearch.Research, CreatedAt: time.Now(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func examineLaboratory(id uint64) (*ExamineManageInfo, error) {
|
||||
mManageLaboratory := model.NewManageLaboratory()
|
||||
|
||||
err := checkManage(mManageLaboratory.ManageLaboratory, id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if mManageLaboratory.Status != model2.ExamineStatusForOngoing {
|
||||
return nil, errors.New("当前入住信息已审核")
|
||||
}
|
||||
return &ExamineManageInfo{
|
||||
IModel: mManageLaboratory.ManageLaboratory, UID: mManageLaboratory.UID,
|
||||
IdentityInfo: &model2.UserIdentityForLaboratory{
|
||||
Name: mManageLaboratory.Name, Industry: mManageLaboratory.Industry, Keyword: mManageLaboratory.Keyword,
|
||||
Research: mManageLaboratory.Research, CreatedAt: time.Now(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@ -96,7 +137,6 @@ func (c *Examine) Launch(id uint64, identity, status int) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Updates(data.IModel, map[string]interface{}{
|
||||
"status": status, "updated_at": time.Now(),
|
||||
|
@ -1,14 +1,91 @@
|
||||
package manage
|
||||
|
||||
import "SciencesServer/app/service"
|
||||
import (
|
||||
"SciencesServer/app/api/manage/controller"
|
||||
"SciencesServer/app/api/manage/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Instance struct {
|
||||
*service.Session
|
||||
gorm.Model
|
||||
local string
|
||||
}
|
||||
|
||||
type InstanceHandle func(session *service.Session, local string) *Instance
|
||||
|
||||
type (
|
||||
// InstanceForExpert 专家信息
|
||||
InstanceForExpert struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Industry []string `json:"industry"`
|
||||
ResearchName string `json:"research_name"`
|
||||
LaboratoryName string `json:"laboratory_name"`
|
||||
Address string `json:"address"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Instance) Company(name string, status int, page, pageSize int) {
|
||||
mManageCompany := model.NewManageCompany()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if name != "" {
|
||||
where = append(where, model2.NewWhereLike("name", name))
|
||||
}
|
||||
|
||||
var count int64
|
||||
|
||||
mManageCompany.Companys(page, pageSize, &count)
|
||||
}
|
||||
|
||||
// Expert 专家信息
|
||||
func (c *Instance) Expert(name string, status int, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mManageExpert := model.NewManageExpert()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if name != "" {
|
||||
where = append(where, model2.NewWhereLike("name", name))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mManageExpert.Experts(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*InstanceForExpert, 0)
|
||||
|
||||
for _, v := range out {
|
||||
industry := make([]string, 0)
|
||||
|
||||
for _, v := range strings.Split(v.Industry, ";") {
|
||||
industry = append(industry, config.GetIndustryInfo(v, "-"))
|
||||
}
|
||||
// 研究机构,实验室
|
||||
researchName := v.LaboratoryName
|
||||
laboratoryName := ""
|
||||
|
||||
if v.LaboratoryName != "" {
|
||||
researchName = v.ResearchName
|
||||
laboratoryName = v.LaboratoryName
|
||||
}
|
||||
list = append(list, &InstanceForExpert{ID: v.GetEncodeID(), Name: v.Name, Industry: industry,
|
||||
ResearchName: researchName, LaboratoryName: laboratoryName,
|
||||
Address: v.FormatBasic(), CreatedAt: v.CreatedAt,
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(session *service.Session, local string) *Instance {
|
||||
return &Instance{
|
||||
|
@ -1,11 +1,17 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
)
|
||||
|
||||
type ManageCompany struct {
|
||||
*model.ManageCompany
|
||||
}
|
||||
|
||||
func (m *ManageCompany) Companys(page, pageSize int, count *int64, where ...*model.ModelWhere) {
|
||||
|
||||
}
|
||||
|
||||
func NewManageCompany() *ManageCompany {
|
||||
return &ManageCompany{}
|
||||
}
|
||||
|
@ -1,11 +1,50 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ManageExpert struct {
|
||||
*model.ManageExpert
|
||||
}
|
||||
|
||||
type ManageExpertInfo struct {
|
||||
*model.ManageExpert
|
||||
Name string `json:"name"`
|
||||
ResearchName string `json:"research_name"`
|
||||
LaboratoryName string `json:"laboratory_name"`
|
||||
}
|
||||
|
||||
// Experts 专家信息
|
||||
func (m *ManageExpert) Experts(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageExpertInfo, error) {
|
||||
mUserInstance := model.NewUserInstance()
|
||||
mSysTenant := model.NewSysTenant()
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS e").
|
||||
Select("e.*", "u.name", "l.name AS laboratory_name", "r.name AS research_name").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON e.uid = u.uuid", mUserInstance.TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS l ON e.tenant_id = l.id", mSysTenant.TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON l.parent_id = r.id", mSysTenant.TableName())).
|
||||
Where("")
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*ManageExpertInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("e.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewManageExpert() *ManageExpert {
|
||||
return &ManageExpert{model.NewManageExpert()}
|
||||
}
|
||||
|
Reference in New Issue
Block a user