diff --git a/controllers/common/im.go b/controllers/common/im.go index 3736ac2..7a98e1f 100644 --- a/controllers/common/im.go +++ b/controllers/common/im.go @@ -2,6 +2,7 @@ package common import ( "hudongzhuanjia/controllers" + "hudongzhuanjia/models" im_service "hudongzhuanjia/services/im" pay_service "hudongzhuanjia/services/pay" ) @@ -33,3 +34,12 @@ func (t *ImTestCtl) Send() { t.CheckErr(err) t.SUCCESS("成功") } + +type IMCtl struct { + controllers.BaseCtl +} + +func (t *IMCtl) ParseToken() { + token := t.MustGet("token") + models.ParseToken(token) +} diff --git a/hdws/ws/ws.go b/hdws/ws/ws.go index c1d3f54..83931fa 100644 --- a/hdws/ws/ws.go +++ b/hdws/ws/ws.go @@ -20,11 +20,15 @@ func (ws *WsCtl) HandleConnect(s *melody.Session) { } ws.node.rwmux.Lock() defer ws.node.rwmux.Unlock() - roomId := s.Request.URL.Query().Get("activity_id") + query := s.Request.URL.Query() + roomId := query.Get("activity_id") if _, ok := ws.node.rooms[roomId]; !ok { // 创建房间 ws.node.rooms[roomId] = NewRoom(roomId) } + client := NewClient(s, ws.node, roomId) + token := query.Get("token") + LoginMid(client, &Message{Data: map[string]interface{}{"token": token}}) // 登录设置 ws.node.conns[s] = client ws.node.handleMelodyConnect(client) } diff --git a/models/base.go b/models/base.go index 0971b57..c74d61d 100644 --- a/models/base.go +++ b/models/base.go @@ -51,6 +51,13 @@ func ParseToken(token string) (_type string, id int, err error) { return } id = entry.Id + } else if tokens[0] == define.TYPE_GUEST { + customer := &Customer{} + err = customer.GetByToken(tokens[1]) + if err != nil { + return + } + id = customer.Id } else { err = errors.New("token失效") } diff --git a/models/customer.go b/models/customer.go index fae90df..737381e 100644 --- a/models/customer.go +++ b/models/customer.go @@ -12,30 +12,27 @@ const CustomerTN = TableNamePrefix + "customer" //客户表 type Customer struct { Model `xorm:"extends"` - //Id int `json:"id" xorm:"not null pk autoincr comment('主键') INT(11)"` - //IsDelete bool `json:"-" xorm:"not null default(0) comment('软删除') TINYINT(1)"` - //CreatedAt time.Time `json:"-" xorm:"not null created comment('创建时间') DATETIME"` - //UpdatedAt time.Time `json:"-" xorm:"not null updated comment('更新时间') DATETIME"` - Activities []*Activity `json:"activities" xorm:"-" description:"用户创建的主活动"` - Nickname string `json:"nickname" xorm:"not null default('') comment('昵称') VARCHAR(255)"` - Username string `json:"username" xorm:"not null default('') comment('用户名') VARCHAR(255)"` - Password string `json:"-" xorm:"not null default('') comment('密码') VARCHAR(255)"` - Openid string `json:"open_id" xorm:"not null default('') comment('openid') VARCHAR(128)"` - Token string `json:"token" xorm:"not null default('') comment('登陆凭证token') VARCHAR(255)"` - Balance float64 `json:"balance" xorm:"not null default(0.00) comment('余额') DECIMAL(18)"` - SmsCode string `json:"sms_code" xorm:"not null default('') comment('短信验证码') VARCHAR(128)"` - AreaId int `json:"area_id" xorm:"not null default(0) comment('地区id') INT(11)"` // 子账号的地区 - ActivityId int `json:"activity_id" xrom:"not null default(0) comment('主活动id') INT(11)"` - HeadImg string `json:"head_img" xorm:"not null default('') comment('头像') VARCHAR(255)"` - Email string `json:"email" xorm:"not null default('') comment('邮箱') VARCHAR(128)"` - Phone string `json:"phone" xorm:"not null default('') comment('电话号码') VARCHAR(128)"` - QqOpenid string `json:"qq_openid" xorm:"not null default('') comment('qq openid') VARCHAR(255)"` - Tag string `json:"tag" xorm:"-" description:"tag ws过滤信息"` - Pid int `json:"pid" xorm:"not null default(0) comment('上级账号,该值为空时不允许登陆web客户端') INT(11)"` // 可能判断是否为子账号h - IsSpecial int `json:"is_special" xorm:"not null default 0 comment('是否是特殊用户') TINYINT(1)"` - RoleId int `json:"role_id" xorm:"not null default(4) comment('1超级管理员|2平台管理员|3普通管理员|4代理会员|5渠道会员|6普通会员') INT(11)"` - TopId int `json:"top_id" xorm:"not null default(0) comment('角色的上级id') INT(11)"` + Activities []*Activity `json:"activities" xorm:"-" description:"用户创建的主活动"` + Nickname string `json:"nickname" xorm:"not null default('') comment('昵称') VARCHAR(255)"` + Username string `json:"username" xorm:"not null default('') comment('用户名') VARCHAR(255)"` + Password string `json:"-" xorm:"not null default('') comment('密码') VARCHAR(255)"` + Openid string `json:"open_id" xorm:"not null default('') comment('openid') VARCHAR(128)"` + Token string `json:"token" xorm:"not null default('') comment('登陆凭证token') VARCHAR(255)"` + GuestAppToken string `json:"guest_app_token" xorm:"not null default '' comment('登录guest') VARCHAR(255)"` + Balance float64 `json:"balance" xorm:"not null default(0.00) comment('余额') DECIMAL(18)"` + SmsCode string `json:"sms_code" xorm:"not null default('') comment('短信验证码') VARCHAR(128)"` + AreaId int `json:"area_id" xorm:"not null default(0) comment('地区id') INT(11)"` // 子账号的地区 + ActivityId int `json:"activity_id" xrom:"not null default(0) comment('主活动id') INT(11)"` + HeadImg string `json:"head_img" xorm:"not null default('') comment('头像') VARCHAR(255)"` + Email string `json:"email" xorm:"not null default('') comment('邮箱') VARCHAR(128)"` + Phone string `json:"phone" xorm:"not null default('') comment('电话号码') VARCHAR(128)"` + QqOpenid string `json:"qq_openid" xorm:"not null default('') comment('qq openid') VARCHAR(255)"` + Tag string `json:"tag" xorm:"-" description:"tag ws过滤信息"` + Pid int `json:"pid" xorm:"not null default(0) comment('上级账号,该值为空时不允许登陆web客户端') INT(11)"` // 可能判断是否为子账号h + IsSpecial int `json:"is_special" xorm:"not null default 0 comment('是否是特殊用户') TINYINT(1)"` + RoleId int `json:"role_id" xorm:"not null default(4) comment('1超级管理员|2平台管理员|3普通管理员|4代理会员|5渠道会员|6普通会员') INT(11)"` + TopId int `json:"top_id" xorm:"not null default(0) comment('角色的上级id') INT(11)"` } func (t *Customer) TableName() string { @@ -84,3 +81,14 @@ func (t *Customer) GetByToken(token string) error { } return nil } + +func (t *Customer) GetByGuestToken(token string) error { + exist, err := core.GetXormAuto().Where("is_delete=0 and guest_app_token=?", token).Get(t) + if err != nil { + return err + } + if !exist { + return errors.New("customer信息异常") + } + return nil +} diff --git a/models/order_entry_person.go b/models/order_entry_person.go index 0cb95fa..1900c17 100644 --- a/models/order_entry_person.go +++ b/models/order_entry_person.go @@ -9,10 +9,6 @@ const OrderEntryPersonTableName = TableNamePrefix + "order_entry_person" type OrderEntryPerson struct { Model `xorm:"extends"` - //Id int `json:"id" xorm:"pk autoincr BIGINT(20)"` - //IsDelete bool `json:"-" xorm:"not null default(0) comment('软删除') TINYINT(1)"` - //CreatedAt time.Time `json:"-" xorm:"not null created comment('创建时间') DATETIME"` - //UpdatedAt time.Time `json:"-" xorm:"not null updated comment('更新时间') DATETIME"` Name string `json:"name" xorm:"not null default('') comment('名字') VARCHAR(255)"` Account string `json:"account" xorm:"not null default('') comment('账号') VARCHAR(255)"` diff --git a/utils/define/define.go b/utils/define/define.go index 548129e..3fa48e3 100644 --- a/utils/define/define.go +++ b/utils/define/define.go @@ -81,6 +81,7 @@ const ( const ( TYPE_USER = "h5user" TYPE_CUSTOMER = "customer" + TYPE_GUEST = "guest" TYPE_AREAADMIN = "area_admin" TYPE_ENTRYPEOPLE = "entry_people" TYPE_LIVEUSER = "live_user" // 直播