feat:完善信息
This commit is contained in:
122
app/api/enterprise/controller/user/bank.go
Normal file
122
app/api/enterprise/controller/user/bank.go
Normal file
@ -0,0 +1,122 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/handle"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Back struct {
|
||||
*service.SessionEnterprise
|
||||
}
|
||||
|
||||
type BackHandle func(enterprise *service.SessionEnterprise) *Back
|
||||
|
||||
type (
|
||||
// BackInfo 银行卡信息
|
||||
BackInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.UserManageBank
|
||||
}
|
||||
// BackParams 银行卡参数信息
|
||||
BackParams struct {
|
||||
Name, IDCard, BackCard, BackName string
|
||||
}
|
||||
)
|
||||
|
||||
// checkIDCard 验证身份证号
|
||||
func (c *BackParams) checkIDCard() bool {
|
||||
return utils.ValidateIDCard(c.IDCard)
|
||||
}
|
||||
|
||||
// checkBankCard 验证银行卡号
|
||||
func (c *BackParams) checkBankCard() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// List 列表信息
|
||||
func (c *Back) List() ([]*BackInfo, error) {
|
||||
mUserManageBack := model.NewUserManageBank()
|
||||
|
||||
out := make([]*model2.UserManageBank, 0)
|
||||
|
||||
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("uid", c.ManageUID),
|
||||
Order: model2.NewOrder("is_default", model2.OrderModeToDesc),
|
||||
}}
|
||||
if err := model2.Find(mUserManageBack.UserManageBank, &out, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*BackInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &BackInfo{ID: v.GetEncodeID(), UserManageBank: v})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// Bind 绑定
|
||||
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("身份证号信息错误")
|
||||
}
|
||||
if !params.checkBankCard() {
|
||||
return errors.New("银行卡信息错误")
|
||||
}
|
||||
mUserManageBack := model.NewUserManageBank()
|
||||
|
||||
var count int64
|
||||
|
||||
if err = model2.Count(mUserManageBack.UserManageBank, &count, model2.NewWhere("back_card", params.BackCard)); err != nil {
|
||||
return err
|
||||
} else if count > 0 {
|
||||
return errors.New("当前银行卡已被注册")
|
||||
}
|
||||
mUserManageBack.UID = c.ManageUID
|
||||
mUserManageBack.Name = params.Name
|
||||
mUserManageBack.IDCard = params.IDCard
|
||||
mUserManageBack.BankCard = params.BackCard
|
||||
mUserManageBack.BackName = params.BackName
|
||||
|
||||
if err = model2.Count(mUserManageBack.UserManageBank, &count, model2.NewWhere("uid", c.ManageUID)); err != nil {
|
||||
return err
|
||||
} else if count <= 0 {
|
||||
mUserManageBack.IsDefault = model2.UserManageBankDefaultForYes
|
||||
}
|
||||
return model2.Create(mUserManageBack.UserManageBank)
|
||||
}
|
||||
|
||||
// Unbind 解绑,直接删除
|
||||
func (c *Back) Unbind(id uint64) error {
|
||||
mUserManageBack := model.NewUserManageBank()
|
||||
mUserManageBack.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mUserManageBack.UserManageBank, []string{"id", "uid"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,绑定信息不存在")
|
||||
} else if mUserManageBack.UID != c.ManageUID {
|
||||
return errors.New("无权限操作")
|
||||
}
|
||||
return model2.Delete(mUserManageBack)
|
||||
}
|
||||
|
||||
func NewBack() BackHandle {
|
||||
return func(enterprise *service.SessionEnterprise) *Back {
|
||||
return &Back{enterprise}
|
||||
}
|
||||
}
|
107
app/api/enterprise/controller/user/instance.go
Normal file
107
app/api/enterprise/controller/user/instance.go
Normal file
@ -0,0 +1,107 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
config2 "SciencesServer/config"
|
||||
"SciencesServer/serve/orm"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Instance struct{ *service.SessionEnterprise }
|
||||
|
||||
type InstanceHandle func(enterprise *service.SessionEnterprise) *Instance
|
||||
|
||||
type (
|
||||
// InstanceInfo 基本信息
|
||||
InstanceInfo struct {
|
||||
Name string `json:"name"` // 名称
|
||||
Identity int `json:"identity"` // 具体身份
|
||||
SelectIdentity int `json:"select_identity"` // 最后一次选中的身份信息
|
||||
}
|
||||
// InstanceDetailInfo 详细信息
|
||||
InstanceDetailInfo struct {
|
||||
InstanceInfo
|
||||
Email string `json:"email"` // 邮箱
|
||||
Job string `json:"job"` // 职务
|
||||
FixedPhone string `json:"fixed_phone"` // 固定电话
|
||||
}
|
||||
)
|
||||
|
||||
// Info 基本信息
|
||||
func (c *Instance) Info() *InstanceInfo {
|
||||
return &InstanceInfo{Name: c.Name, Identity: c.Identity, SelectIdentity: c.SelectIdentity}
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
func (c *Instance) Detail() (*InstanceDetailInfo, error) {
|
||||
resp := &InstanceDetailInfo{InstanceInfo: InstanceInfo{Name: c.Name, Identity: c.Identity, SelectIdentity: c.SelectIdentity}}
|
||||
|
||||
mUserManage := model.NewUserManage()
|
||||
|
||||
isExist, err := model2.FirstField(mUserManage.UserManage, []string{"id", "tenant_id", "uuid", "name",
|
||||
"email", "job", "fixed_phone", "other"},
|
||||
model2.NewWhere("uid", c.UID), model2.NewWhere("identity", c.SelectIdentity))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if isExist {
|
||||
resp.Name = mUserManage.Name
|
||||
resp.Email = mUserManage.Email
|
||||
resp.Job = mUserManage.Job
|
||||
resp.FixedPhone = mUserManage.FixedPhone
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// SwitchIdentity 切换身份
|
||||
func (c *Instance) SwitchIdentity(identity int) error {
|
||||
if _, has := config.TenantUserIdentityData[identity]; !has {
|
||||
return errors.New("未知的身份信息")
|
||||
}
|
||||
if c.SelectIdentity == identity {
|
||||
return nil
|
||||
}
|
||||
c.TenantID, c.ManageUID = 0, 0
|
||||
// 已存在相应的身份,更新最后
|
||||
if c.Identity&identity > 0 {
|
||||
mUserManage := model.NewUserManage()
|
||||
// 查询用户身份
|
||||
isExist, err := model2.FirstField(mUserManage.UserManage, []string{"id", "tenant_id", "name", "uuid"},
|
||||
model2.NewWhere("uid", c.UID), model2.NewWhere("identity", identity))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
now := time.Now()
|
||||
|
||||
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.UpdatesWhere(mUserManage.UserManage, map[string]interface{}{
|
||||
"selected": model2.UserManageSelectedForNo, "updated_at": now,
|
||||
}, []*model2.ModelWhere{model2.NewWhere("uid", c.ManageUID)}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return model2.Updates(mUserManage.UserManage, map[string]interface{}{
|
||||
"selected": model2.UserManageSelectedForYes, "updated_at": now,
|
||||
}, tx)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
c.TenantID = mUserManage.TenantID
|
||||
c.ManageUID = mUserManage.UUID
|
||||
}
|
||||
c.SelectIdentity = identity
|
||||
service.Publish(config2.EventForAccountLoginProduce, config2.RedisKeyForAccount, c.UIDToString(), c.SessionEnterprise)
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(enterprise *service.SessionEnterprise) *Instance {
|
||||
return &Instance{SessionEnterprise: enterprise}
|
||||
}
|
||||
}
|
191
app/api/enterprise/controller/user/settled.go
Normal file
191
app/api/enterprise/controller/user/settled.go
Normal file
@ -0,0 +1,191 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
model3 "SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Settled 入驻
|
||||
type Settled struct{ *service.SessionEnterprise }
|
||||
|
||||
type SettledHandle func(enterprise *service.SessionEnterprise) *Settled
|
||||
|
||||
type SettledParams struct {
|
||||
ID uint64
|
||||
Image string // logo图片
|
||||
Name string // 名称
|
||||
Code string // 唯一编码
|
||||
config.Area
|
||||
Introduce string
|
||||
Industry uint64 `json:"industry"`
|
||||
Keywords []string `json:"keywords"`
|
||||
}
|
||||
|
||||
// effect 入驻信息有效性
|
||||
func (c *SettledParams) effect(uid uint64, iModel model2.IModel) error {
|
||||
if c.ID <= 0 {
|
||||
var count int64
|
||||
|
||||
if err := model2.Count(iModel, &count, model2.NewWhere("uid", uid)); err != nil {
|
||||
return err
|
||||
} else if count > 0 {
|
||||
return errors.New("无权限操作,当前身份下已含有申请入驻信息")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if isExist, err := model2.FirstField(iModel, []string{"id", "uid", "status"}, model2.NewWhere("id", c.ID)); err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("无权限操作,未知的入驻信息")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// pass 入驻信息通过性
|
||||
func (c *SettledParams) pass(uid, mUID uint64, mStatus model2.ExamineStatusKind) bool {
|
||||
if mUID != uid || mStatus != model2.ExamineStatusForRefuse {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Company 公司企业
|
||||
func (c *Settled) Company(params *SettledParams, other *config.IdentityForCompany) error {
|
||||
mManageCompany := model3.NewManageCompany()
|
||||
|
||||
err := params.effect(c.ManageUID, mManageCompany.ManageCompany)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mManageCompany.Name = params.Name
|
||||
mManageCompany.Code = params.Code
|
||||
mManageCompany.Image = model2.Image{Image: params.Image}
|
||||
mManageCompany.Area = model2.Area{
|
||||
Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
|
||||
}
|
||||
mManageCompany.Industry = params.Industry
|
||||
mManageCompany.SetKeywordAttribute(params.Keywords)
|
||||
mManageCompany.Introduce = params.Introduce
|
||||
|
||||
if mManageCompany.ID <= 0 {
|
||||
mManageCompany.UID = c.ManageUID
|
||||
return model2.Create(mManageCompany.ManageCompany)
|
||||
}
|
||||
if !params.pass(c.ManageUID, mManageCompany.UID, mManageCompany.Status) {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
mManageCompany.Status = model2.ExamineStatusForOngoing
|
||||
return model2.Updates(mManageCompany.ManageCompany, mManageCompany.ManageCompany)
|
||||
}
|
||||
|
||||
// Expert 专家
|
||||
func (c *Settled) Expert(params *SettledParams, other *config.IdentityForExpert) error {
|
||||
mManageExpert := model3.NewManageExpert()
|
||||
|
||||
err := params.effect(c.ManageUID, mManageExpert.ManageExpert)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mManageExpert.TenantID = other.TenantID
|
||||
mManageExpert.Area = model2.Area{
|
||||
Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
|
||||
}
|
||||
mManageExpert.Industry = params.Industry
|
||||
mManageExpert.SetKeywordAttribute(params.Keywords)
|
||||
mManageExpert.Introduce = params.Introduce
|
||||
mManageExpert.Position = utils.AnyToJSON(model2.Position{Longitude: other.Longitude, Latitude: other.Latitude})
|
||||
mManageExpert.School = other.School
|
||||
mManageExpert.Major = other.Major
|
||||
mManageExpert.Job = other.Job
|
||||
mManageExpert.Title = other.Title
|
||||
mManageExpert.WorkAt = utils.DataTimeToDate(other.WorkAt)
|
||||
mManageExpert.Research = utils.AnyToJSON(other.Research)
|
||||
|
||||
if mManageExpert.ID <= 0 {
|
||||
mManageExpert.UID = c.ManageUID
|
||||
return model2.Create(mManageExpert.ManageExpert)
|
||||
}
|
||||
if !params.pass(c.ManageUID, mManageExpert.UID, mManageExpert.Status) {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
mManageExpert.Status = model2.ExamineStatusForOngoing
|
||||
return model2.Updates(mManageExpert.ManageExpert, mManageExpert.ManageExpert)
|
||||
}
|
||||
|
||||
// Research 研究机构
|
||||
func (c *Settled) Research(params *SettledParams, other *config.IdentityForResearch) error {
|
||||
mManageResearch := model3.NewManageResearch()
|
||||
|
||||
err := params.effect(c.ManageUID, mManageResearch.ManageResearch)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mManageResearch.Area = model2.Area{
|
||||
Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
|
||||
}
|
||||
mManageResearch.Industry = params.Industry
|
||||
mManageResearch.SetKeywordAttribute(params.Keywords)
|
||||
mManageResearch.Introduce = params.Introduce
|
||||
mManageResearch.Position = utils.AnyToJSON(model2.Position{Longitude: other.Longitude, Latitude: other.Latitude})
|
||||
mManageResearch.Research = other.Research
|
||||
|
||||
if mManageResearch.ID <= 0 {
|
||||
mManageResearch.UID = c.ManageUID
|
||||
return model2.Create(mManageResearch.ManageResearch)
|
||||
}
|
||||
if !params.pass(c.ManageUID, mManageResearch.UID, mManageResearch.Status) {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
mManageResearch.Status = model2.ExamineStatusForOngoing
|
||||
return model2.Updates(mManageResearch.ManageResearch, mManageResearch.ManageResearch)
|
||||
}
|
||||
|
||||
// Laboratory 实验室
|
||||
func (c *Settled) Laboratory(params *SettledParams, other *config.IdentityForLaboratory) error {
|
||||
mManageLaboratory := model3.NewManageLaboratory()
|
||||
|
||||
err := params.effect(c.ManageUID, mManageLaboratory.ManageLaboratory)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mManageLaboratory.TenantID = other.TenantID
|
||||
mManageLaboratory.Name = params.Name
|
||||
mManageLaboratory.Code = params.Code
|
||||
mManageLaboratory.Area = model2.Area{
|
||||
Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
|
||||
}
|
||||
mManageLaboratory.Industry = params.Industry
|
||||
mManageLaboratory.SetKeywordAttribute(params.Keywords)
|
||||
mManageLaboratory.Introduce = params.Introduce
|
||||
mManageLaboratory.Position = utils.AnyToJSON(model2.Position{Longitude: other.Longitude, Latitude: other.Latitude})
|
||||
mManageLaboratory.Research = utils.AnyToJSON(other.Research)
|
||||
|
||||
if mManageLaboratory.ID <= 0 {
|
||||
mManageLaboratory.UID = c.ManageUID
|
||||
return model2.Create(mManageLaboratory.ManageLaboratory)
|
||||
}
|
||||
if !params.pass(c.ManageUID, mManageLaboratory.UID, mManageLaboratory.Status) {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
mManageLaboratory.Status = model2.ExamineStatusForOngoing
|
||||
return model2.Updates(mManageLaboratory.ManageLaboratory, mManageLaboratory.ManageLaboratory)
|
||||
}
|
||||
|
||||
// Agent 经纪人
|
||||
func (c *Settled) Agent() {
|
||||
|
||||
}
|
||||
|
||||
func NewSettled() SettledHandle {
|
||||
return func(enterprise *service.SessionEnterprise) *Settled {
|
||||
return &Settled{enterprise}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user