Commit 85d1b88d by 李洪

修改用户信息

parent f86d4ced
......@@ -28,7 +28,7 @@ type ImChatRoom struct {
type ImUser struct {
Id int64
Appid string
Accid string
Appkey string
Name string
Mobile string
......
......@@ -115,7 +115,7 @@ type ImUserReply struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Appid string `protobuf:"bytes,2,opt,name=Appid,proto3" json:"Appid,omitempty"`
Accid string `protobuf:"bytes,2,opt,name=Accid,proto3" json:"Accid,omitempty"`
}
func (x *ImUserReply) Reset() {
......@@ -150,9 +150,9 @@ func (*ImUserReply) Descriptor() ([]byte, []int) {
return file_u_proto_im_user_proto_rawDescGZIP(), []int{1}
}
func (x *ImUserReply) GetAppid() string {
func (x *ImUserReply) GetAccid() string {
if x != nil {
return x.Appid
return x.Accid
}
return ""
}
......@@ -164,7 +164,7 @@ type ImUserOutRequest struct {
unknownFields protoimpl.UnknownFields
Common *Common `protobuf:"bytes,1,opt,name=Common,proto3" json:"Common,omitempty"`
Appid string `protobuf:"bytes,2,opt,name=Appid,proto3" json:"Appid,omitempty"`
Accid string `protobuf:"bytes,2,opt,name=Accid,proto3" json:"Accid,omitempty"`
}
func (x *ImUserOutRequest) Reset() {
......@@ -206,9 +206,9 @@ func (x *ImUserOutRequest) GetCommon() *Common {
return nil
}
func (x *ImUserOutRequest) GetAppid() string {
func (x *ImUserOutRequest) GetAccid() string {
if x != nil {
return x.Appid
return x.Accid
}
return ""
}
......@@ -221,7 +221,7 @@ type ImUserSetRequest struct {
Common *Common `protobuf:"bytes,1,opt,name=Common,proto3" json:"Common,omitempty"`
Mute bool `protobuf:"varint,2,opt,name=Mute,proto3" json:"Mute,omitempty"`
Appid string `protobuf:"bytes,3,opt,name=Appid,proto3" json:"Appid,omitempty"`
Accid string `protobuf:"bytes,3,opt,name=Accid,proto3" json:"Accid,omitempty"`
}
func (x *ImUserSetRequest) Reset() {
......@@ -270,9 +270,9 @@ func (x *ImUserSetRequest) GetMute() bool {
return false
}
func (x *ImUserSetRequest) GetAppid() string {
func (x *ImUserSetRequest) GetAccid() string {
if x != nil {
return x.Appid
return x.Accid
}
return ""
}
......@@ -322,7 +322,7 @@ type ImUserOneRequest struct {
unknownFields protoimpl.UnknownFields
Common *Common `protobuf:"bytes,1,opt,name=Common,proto3" json:"Common,omitempty"`
Appid string `protobuf:"bytes,2,opt,name=Appid,proto3" json:"Appid,omitempty"`
Accid string `protobuf:"bytes,2,opt,name=Accid,proto3" json:"Accid,omitempty"`
}
func (x *ImUserOneRequest) Reset() {
......@@ -364,9 +364,9 @@ func (x *ImUserOneRequest) GetCommon() *Common {
return nil
}
func (x *ImUserOneRequest) GetAppid() string {
func (x *ImUserOneRequest) GetAccid() string {
if x != nil {
return x.Appid
return x.Accid
}
return ""
}
......@@ -377,7 +377,7 @@ type ImUserOneReply struct {
unknownFields protoimpl.UnknownFields
Id int64 `protobuf:"varint,1,opt,name=Id,proto3" json:"Id,omitempty"`
Appid string `protobuf:"bytes,2,opt,name=Appid,proto3" json:"Appid,omitempty"`
Accid string `protobuf:"bytes,2,opt,name=Accid,proto3" json:"Accid,omitempty"`
Name string `protobuf:"bytes,3,opt,name=Name,proto3" json:"Name,omitempty"`
Mobile string `protobuf:"bytes,4,opt,name=Mobile,proto3" json:"Mobile,omitempty"`
Disable int64 `protobuf:"varint,5,opt,name=Disable,proto3" json:"Disable,omitempty"`
......@@ -430,9 +430,9 @@ func (x *ImUserOneReply) GetId() int64 {
return 0
}
func (x *ImUserOneReply) GetAppid() string {
func (x *ImUserOneReply) GetAccid() string {
if x != nil {
return x.Appid
return x.Accid
}
return ""
}
......@@ -729,28 +729,28 @@ var file_u_proto_im_user_proto_rawDesc = []byte{
0x09, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x50, 0x6c, 0x61, 0x74, 0x66,
0x72, 0x6f, 0x6d, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x50, 0x6c, 0x61, 0x74, 0x66,
0x72, 0x6f, 0x6d, 0x22, 0x23, 0x0a, 0x0b, 0x49, 0x6d, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x70,
0x6c, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x41, 0x70, 0x70, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
0x09, 0x52, 0x05, 0x41, 0x70, 0x70, 0x69, 0x64, 0x22, 0x4c, 0x0a, 0x10, 0x49, 0x6d, 0x55, 0x73,
0x6c, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x41, 0x63, 0x63, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
0x09, 0x52, 0x05, 0x41, 0x63, 0x63, 0x69, 0x64, 0x22, 0x4c, 0x0a, 0x10, 0x49, 0x6d, 0x55, 0x73,
0x65, 0x72, 0x4f, 0x75, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x06,
0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x70,
0x62, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x52, 0x06, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e,
0x12, 0x14, 0x0a, 0x05, 0x41, 0x70, 0x70, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
0x05, 0x41, 0x70, 0x70, 0x69, 0x64, 0x22, 0x60, 0x0a, 0x10, 0x49, 0x6d, 0x55, 0x73, 0x65, 0x72,
0x12, 0x14, 0x0a, 0x05, 0x41, 0x63, 0x63, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
0x05, 0x41, 0x63, 0x63, 0x69, 0x64, 0x22, 0x60, 0x0a, 0x10, 0x49, 0x6d, 0x55, 0x73, 0x65, 0x72,
0x53, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x06, 0x43, 0x6f,
0x6d, 0x6d, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x70, 0x62, 0x2e,
0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x52, 0x06, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x12, 0x12,
0x0a, 0x04, 0x4d, 0x75, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, 0x4d, 0x75,
0x74, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x41, 0x70, 0x70, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28,
0x09, 0x52, 0x05, 0x41, 0x70, 0x70, 0x69, 0x64, 0x22, 0x10, 0x0a, 0x0e, 0x49, 0x6d, 0x55, 0x73,
0x74, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x41, 0x63, 0x63, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28,
0x09, 0x52, 0x05, 0x41, 0x63, 0x63, 0x69, 0x64, 0x22, 0x10, 0x0a, 0x0e, 0x49, 0x6d, 0x55, 0x73,
0x65, 0x72, 0x53, 0x65, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x4c, 0x0a, 0x10, 0x49, 0x6d,
0x55, 0x73, 0x65, 0x72, 0x4f, 0x6e, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22,
0x0a, 0x06, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a,
0x2e, 0x70, 0x62, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x52, 0x06, 0x43, 0x6f, 0x6d, 0x6d,
0x6f, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x41, 0x70, 0x70, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
0x09, 0x52, 0x05, 0x41, 0x70, 0x70, 0x69, 0x64, 0x22, 0xf2, 0x02, 0x0a, 0x0e, 0x49, 0x6d, 0x55,
0x6f, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x41, 0x63, 0x63, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
0x09, 0x52, 0x05, 0x41, 0x63, 0x63, 0x69, 0x64, 0x22, 0xf2, 0x02, 0x0a, 0x0e, 0x49, 0x6d, 0x55,
0x73, 0x65, 0x72, 0x4f, 0x6e, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x49,
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x41,
0x70, 0x70, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x41, 0x70, 0x70, 0x69,
0x63, 0x63, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x41, 0x63, 0x63, 0x69,
0x64, 0x12, 0x12, 0x0a, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
0x04, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x4d, 0x6f, 0x62, 0x69, 0x6c, 0x65, 0x18,
0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x4d, 0x6f, 0x62, 0x69, 0x6c, 0x65, 0x12, 0x18, 0x0a,
......
......@@ -20,12 +20,12 @@ type ImUser struct {
}
type ImUserSet struct {
Appid string `validate:"required"`
Accid string `validate:"required"`
Mute bool `validate:"required"`
}
type ImUserQ struct {
Appid string `validate:"required"`
Accid string `validate:"required"`
}
//注册
......@@ -53,17 +53,17 @@ func (u *ImUserServer) ImUserRegister(ctx context.Context, in *pb.ImUserRequest)
}
reply = &pb.ImUserReply{}
// 是否已经注册过, 如果已经注册返回用户信息
if c_user, _ := GetImUserByMobile(imUser.Mobile); c_user.Appid != "" {
reply.Appid = c_user.Appid
if c_user, _ := GetImUserByMobile(imUser.Mobile); c_user.Accid != "" {
reply.Accid = c_user.Accid
return
}
// 企业用户注册失败
c_user, err := helper.CreateImUser(imUser.Name, imUser.Mobile)
c_user, err := CreateImUser(imUser.Name, imUser.Mobile)
if err != nil {
return
}
reply.Appid = c_user.Appid
reply.Accid = c_user.Accid
return
}
......@@ -93,7 +93,7 @@ func (u *ImUserServer) ImUserLogin(ctx context.Context, in *pb.ImUserRequest) (r
}
reply = &pb.ImUserReply{}
c_user, _ := GetImUserByMobile(imUser.Mobile)
if c_user.Appid == "" {
if c_user.Accid == "" {
err = errors.New("用户不存在")
return
}
......@@ -102,16 +102,16 @@ func (u *ImUserServer) ImUserLogin(ctx context.Context, in *pb.ImUserRequest) (r
err = errors.New("用户登录时间更新失败")
return
}
reply.Appid = c_user.Appid
reply.Accid = c_user.Accid
return
}
//用户退出
func (u *ImUserServer) ImUserLoginOut(ctx context.Context, in *pb.ImUserOutRequest) (reply *pb.ImUserSetReply, err error) {
imUserOut := &ImUserQ{
Appid: in.GetAppid(),
Accid: in.GetAccid(),
}
if res, _ := SaveLoginOut(imUserOut.Appid); res != 1 {
if res, _ := SaveLoginOut(imUserOut.Accid); res != 1 {
err = errors.New("用户更改登录状态信息失败")
return
}
......@@ -121,26 +121,31 @@ func (u *ImUserServer) ImUserLoginOut(ctx context.Context, in *pb.ImUserOutReque
//用户禁言
func (u *ImUserServer) ImUserForbiddenWords(ctx context.Context, in *pb.ImUserSetRequest) (reply *pb.ImUserSetReply, err error) {
imUserSet := &ImUserSet{
Appid: in.GetAppid(),
Mute: in.GetMute(),
var mute int64 = 0
if in.GetMute() == true {
mute = 1
}
if res, _ := SetImUserMute(imUserSet.Appid, "mute_estoppel", imUserSet.Mute); res != 1 {
m := make(map[string]interface{})
m["mute_estoppel"] = mute
if res, _ := UpdateImUser(in.GetAccid(), m); res != 1 {
err = errors.New("用户禁言失败")
return
}
reply = &pb.ImUserSetReply{}
return
}
//用户禁音视频
func (u *ImUserServer) ImUserForbiddenAV(ctx context.Context, in *pb.ImUserSetRequest) (reply *pb.ImUserSetReply, err error) {
imUserSet := &ImUserSet{
Appid: in.GetAppid(),
Mute: in.GetMute(),
}
if res, _ := SetImUserMute(imUserSet.Appid, "mute_audio_video", imUserSet.Mute); res != 1 {
var mute int64
if in.GetMute() == true {
mute = 1
} else {
mute = 0
}
m := make(map[string]interface{})
m["mute_audio_video"] = mute
if res, _ := UpdateImUser(in.GetAccid(), m); res != 1 {
err = errors.New("用户禁言失败")
return
}
......@@ -152,14 +157,14 @@ func (u *ImUserServer) ImUserForbiddenAV(ctx context.Context, in *pb.ImUserSetRe
//获取用户信息
func (u *ImUserServer) ImUserOne(ctx context.Context, in *pb.ImUserOneRequest) (reply *pb.ImUserOneReply, err error) {
imUserId := &ImUserQ{
Appid: in.GetAppid(),
Accid: in.GetAccid(),
}
// 参数验证是否合法
if err = helper.Valiator(imUserId); err != nil {
return
}
reply = &pb.ImUserOneReply{}
c_user, err := GetImUserByAppid(imUserId.Appid)
c_user, err := GetImUserByAccid(imUserId.Accid)
if err != nil {
return
}
......@@ -170,7 +175,7 @@ func (u *ImUserServer) ImUserOne(ctx context.Context, in *pb.ImUserOneRequest) (
func getImUser(imuser db.ImUser) *pb.ImUserOneReply {
return &pb.ImUserOneReply{
Id: int64(imuser.Id),
Appid: imuser.Appid,
Accid: imuser.Accid,
Name: imuser.Name,
Mobile: imuser.Mobile,
Disable: int64(imuser.Disable),
......
......@@ -17,7 +17,7 @@ const (
u_table_name = "im_user"
)
func createAppid() string {
func createAccid() string {
id := ksuid.New()
h := md5.New()
h.Write([]byte(id.String()))
......@@ -37,9 +37,9 @@ func GetImUserByMobile(mobile string) (db.ImUser, error) {
//im用户注册
func CreateImUser(name string, mobile string) (db.ImUser, error) {
appid := createAppid()
accid := createAccid()
var c_user db.ImUser
c_user.Appid = appid
c_user.Accid = accid
c_user.Name = name
c_user.Mobile = mobile
c_user.Createtime = helper.GetNowTime()
......@@ -66,25 +66,33 @@ func SaveUpdatetime(mobile string, platfrom string) (int64, error) {
}
//用户退出
func SaveLoginOut(appid string) (int64, error) {
func SaveLoginOut(accid string) (int64, error) {
orm_params := make(orm.Params)
orm_params["login_status"] = 0
res, err := db.MysqlClient.QueryTable(u_table_name).Filter("appid", appid).Update(orm_params)
res, err := db.MysqlClient.QueryTable(u_table_name).Filter("accid", accid).Update(orm_params)
if err != nil {
return 0, err
}
return res, nil
}
//用户设置
func SetImUserMute(appid string, field string, mute bool) (int64, error) {
//修改用户信息
func UpdateImUser(accid string, m map[string]interface{}) (int64, error) {
orm_params := make(orm.Params)
if mute == true {
orm_params[field] = 1
} else {
orm_params[field] = 0
}
res, err := db.MysqlClient.QueryTable(u_table_name).Filter("appid", appid).Update(orm_params)
for k, v := range m {
switch v.(type) {
case int:
i_v := v.(int)
orm_params[k] = i_v
case string:
s_v := v.(string)
orm_params[k] = s_v
case int64:
c_v := v.(int64)
orm_params[k] = c_v
}
}
res, err := db.MysqlClient.QueryTable(u_table_name).Filter("accid", accid).Update(orm_params)
if err != nil {
return 0, err
}
......@@ -92,10 +100,10 @@ func SetImUserMute(appid string, field string, mute bool) (int64, error) {
}
//获取用户信息
func GetImUserByAppid(appid string) (db.ImUser, error) {
func GetImUserByAccid(accid string) (db.ImUser, error) {
var c_user db.ImUser
fmt.Println(db.MysqlClient)
err := db.MysqlClient.QueryTable(u_table_name).Filter("appid", appid).One(&c_user)
err := db.MysqlClient.QueryTable(u_table_name).Filter("accid", accid).One(&c_user)
if err != nil {
return c_user, err
}
......
......@@ -14,21 +14,21 @@ message ImUserRequest {
}
message ImUserReply{
string Appid = 2;
string Accid = 2;
}
//用户退出
message ImUserOutRequest {
Common Common = 1;
string Appid = 2;
string Accid = 2;
}
//用户设置禁言,禁音视频
message ImUserSetRequest {
Common Common = 1;
bool Mute = 2;
string Appid = 3;
string Accid = 3;
}
message ImUserSetReply {}
......@@ -36,12 +36,12 @@ message ImUserSetReply {}
//获取单个用户信息
message ImUserOneRequest {
Common Common = 1;
string Appid = 2;
string Accid = 2;
}
message ImUserOneReply {
int64 Id = 1;
string Appid = 2;
string Accid = 2;
string Name = 3;
string Mobile = 4;
int64 Disable = 5;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment