DengBiao пре 1 година
родитељ
комит
c2f2e3ff66
5 измењених фајлова са 185 додато и 27 уклоњено
  1. +30
    -1
      app/db/db_dou_shen_im_group.go
  2. +16
    -0
      app/db/gim/model/group.go
  3. +25
    -0
      app/db/model/regional_agent_user.go
  4. +77
    -17
      consume/dou_shen_user_register_for_my_my_recommender.go
  5. +37
    -9
      consume/dou_shen_user_register_for_operation_center.go

+ 30
- 1
app/db/db_dou_shen_im_group.go Прегледај датотеку

@@ -108,6 +108,36 @@ func DouShenImGroupGetOneByParamsForFans(Db *xorm.Engine, kind int, uid int64) (
return &m, nil
}

func DouShenImGroupFindByParamsByKind(Db *xorm.Engine, kind int, params map[string]interface{}) (*[]model.DouShenImGroup, error) {
var m []model.DouShenImGroup
if params["value"] == nil {
return nil, errors.New("参数有误")
}
if params["key"] == nil {
//查询全部数据
err := Db.Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return &m, nil
} else {
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice {
//指定In查询
if err := Db.In(utils.AnyToString(params["key"]), params["value"]).And("kind =?", kind).Find(&m); err != nil {
return nil, logx.Warn(err)
}
return &m, nil
} else {
var query = fmt.Sprintf("%s =?", params["key"])
err := Db.Where(query, params["value"]).And("kind =?", kind).Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return &m, nil
}
}
}

// DouShenImGroupFindByParams 通过传入的参数查询数据(多条)
func DouShenImGroupFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.DouShenImGroup, error) {
var m []model.DouShenImGroup
@@ -136,6 +166,5 @@ func DouShenImGroupFindByParams(Db *xorm.Engine, params map[string]interface{})
}
return &m, nil
}

}
}

+ 16
- 0
app/db/gim/model/group.go Прегледај датотеку

@@ -0,0 +1,16 @@
package model

import "time"

type Group struct {
Id int64 // 群组id
Name string // 组名
AvatarUrl string // 头像
Introduction string // 群简介
UserNum int32 // 群组人数
IsAllMemberBanned int32 // 是否全员禁言(1:是 2:否)
MasterId int64 // 站长id
Extra string // 附加字段
CreateTime time.Time // 创建时间
UpdateTime time.Time // 更新时间
}

+ 25
- 0
app/db/model/regional_agent_user.go Прегледај датотеку

@@ -0,0 +1,25 @@
package model

import (
"time"
)

type RegionalAgentUser struct {
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"`
SchemeId int `json:"scheme_id" xorm:"not null comment('方案id') INT(11)"`
Uid int `json:"uid" xorm:"not null comment('参与区域代理的用户id') index(mgbgu_uid_ord_id_group_id_index) INT(11)"`
RegionId int `json:"region_id" xorm:"not null comment('区域id') index(mgbgu_uid_ord_id_group_id_index) INT(11)"`
IsFailure int `json:"is_failure" xorm:"not null default 0 comment('是否已失效:0否 1是') TINYINT(1)"`
FailureTime int `json:"failure_time" xorm:"not null comment('剩下失效时间(单位:月)0代表永久') INT(11)"`
ProvinceId int64 `json:"province_id" xorm:"comment('省级区域id') BIGINT(20)"`
CityId int64 `json:"city_id" xorm:"comment('市级区域id') BIGINT(20)"`
DistrictId int64 `json:"district_id" xorm:"comment('区/县级id') BIGINT(20)"`
SiteId int64 `json:"site_id" xorm:"comment('网点id') BIGINT(20)"`
RegionalName string `json:"regional_name" xorm:"not null comment('地区名:(例如:广东省;广东省-珠海市;广东省-珠海市-香洲区;广东省-珠海市-香洲区-港湾一号)') VARCHAR(255)"`
Level int `json:"level" xorm:"not null default 0 comment('等级(1:省级;2:市级;3:区/县 级;4:网点)') TINYINT(1)"`
CreateTime time.Time `json:"create_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') index(mgbgu_uid_ord_id_group_id_index) TIMESTAMP"`
UpdateTime time.Time `json:"update_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"`
DeletedTime time.Time `json:"deleted_time" xorm:"comment('删除时间') TIMESTAMP"`
DateType int `json:"date_type" xorm:"not null comment('1:包月,2:包季,3:包年,4:永久') TINYINT(1)"`
AutoRenewal int `json:"auto_renewal" xorm:"not null comment('是否自动续费0否 1是') TINYINT(1)"`
}

+ 77
- 17
consume/dou_shen_user_register_for_my_my_recommender.go Прегледај датотеку

@@ -5,6 +5,7 @@ import (
"applet/app/db"
db2 "applet/app/db/gim"
"applet/app/db/gim/model"
model2 "applet/app/db/model"
utils2 "applet/app/utils"
"applet/app/utils/logx"
utils "applet/app/utils/rpc"
@@ -110,30 +111,89 @@ func handleDouShenUserRegisterConsumeForMyRecommender(msgData []byte) error {
}

//2、查找是否有群
fansGroup, err := db.DouShenImGroupGetOneByParamsForFans(db.Db, 3, msg.RecommenderUid)
var fansGroup *model2.DouShenImGroup
fansGroups, err := db.DouShenImGroupFindByParamsByKind(db.Db, 3, map[string]interface{}{
"key": "uid",
"value": msg.RecommenderUid,
})
if err != nil {
return err
}
if fansGroup == nil {
return errors.New("当前推荐人暂未拥有粉丝群,请联系管理员!!!")
} else {
userGroup, err2 := db2.GroupUserGetOneByParams(db.ImDb, 1, map[string]interface{}{
for _, group := range *fansGroups {
//统计当前群有多少人
userGroups, err := db2.GroupUserFindByParams(db.ImDb, map[string]interface{}{
"key": "group_id",
"value": fansGroup.GroupId,
"value": group.GroupId,
})
if err2 != nil {
return err2
if err != nil {
return err
}
if userGroup == nil {
return errors.New("当前推荐人群暂未设置群主,请联系管理员!!!")
if len(*userGroups) < 500 {
fansGroup = &group
}
//加入群
_, err = utils.GetLogicExtClient(cfg.ImLogicRpc.URL, cfg.ImLogicRpc.PORT).AddGroupMembers(
utils.GetCtx("", strconv.FormatInt(userGroup.UserId, 10), "", msg.MasterId),
&pb.AddGroupMembersReq{
GroupId: int64(fansGroup.GroupId),
UserIds: []int64{gimUser.Id},
})
}

if fansGroup == nil {
recommenderUser, err := db.UserFindByID(db.DBs[msg.MasterId], msg.RecommenderUid)
if err != nil {
return err
}
recommenderGimUser, err := db2.UserGetOneByParams(db.ImDb, msg.MasterId, map[string]interface{}{
"key": "phone_number",
"value": recommenderUser.Phone,
})
groupName := "我的粉丝【" + utils2.AnyToString(len(*fansGroups)+1) + "】群"
//3、创建群
resp, err := utils.GetLogicExtClient(cfg.ImLogicRpc.URL, cfg.ImLogicRpc.PORT).CreateGroup(utils.GetCtx("", strconv.FormatInt(recommenderGimUser.Id, 10), "0", msg.MasterId), &pb.CreateGroupReq{
Name: groupName,
AvatarUrl: "",
//Introduction: "官方群",
Introduction: "",
Extra: "",
MemberIds: []int64{},
})
if err != nil {
return err
}

//插入 dou_shen_im_group 记录
now := time.Now()
_, err = db.DouShenImGroupInsert(db.Db, &model2.DouShenImGroup{
Kind: 1,
Uid: int(msg.RecommenderUid),
GroupId: int(resp.GroupId),
IsFull: 0,
Name: groupName,
CreateTime: now,
UpdateTime: now,
})
if err != nil {
return err
}
fansGroup, err = db.DouShenImGroupGetOneByParams(db.Db, 2, map[string]interface{}{
"group_id": resp.GroupId,
})
if err != nil {
return err
}
}
userGroup, err2 := db2.GroupUserGetOneByParams(db.ImDb, 1, map[string]interface{}{
"key": "group_id",
"value": fansGroup.GroupId,
})
if err2 != nil {
return err2
}
if userGroup == nil {
return errors.New("当前推荐人群暂未设置群主,请联系管理员!!!")
}

//加入群
_, err = utils.GetLogicExtClient(cfg.ImLogicRpc.URL, cfg.ImLogicRpc.PORT).AddGroupMembers(
utils.GetCtx("", strconv.FormatInt(userGroup.UserId, 10), "", msg.MasterId),
&pb.AddGroupMembersReq{
GroupId: int64(fansGroup.GroupId),
UserIds: []int64{gimUser.Id},
})
return nil
}

+ 37
- 9
consume/dou_shen_user_register_for_operation_center.go Прегледај датотеку

@@ -111,10 +111,29 @@ func handleDouShenUserRegisterConsumeForOperationCenter(msgData []byte) error {
}

//2、查找是否有群
OperationGroup, err := db.DouShenImGroupGetOneByParamsForFans(db.Db, 2, msg.OperationCenterUid)
//OperationGroup, err := db.DouShenImGroupGetOneByParamsForFans(db.Db, 2, msg.OperationCenterUid)
var OperationGroup *model2.DouShenImGroup
operationGroups, err := db.DouShenImGroupFindByParamsByKind(db.Db, 2, map[string]interface{}{
"key": "uid",
"value": msg.OperationCenterUid,
})
if err != nil {
return err
}
for _, group := range *operationGroups {
//统计当前群有多少人
userGroups, err := db2.GroupUserFindByParams(db.ImDb, map[string]interface{}{
"key": "group_id",
"value": group.GroupId,
})
if err != nil {
return err
}
if len(*userGroups) < 500 {
OperationGroup = &group
}
}

if OperationGroup == nil {
//创建运营中心群
operationCenterUser, err := db.UserFindByID(db.DBs[msg.MasterId], msg.OperationCenterUid)
@@ -128,10 +147,21 @@ func handleDouShenUserRegisterConsumeForOperationCenter(msgData []byte) error {
if operationCenterGimUser == nil {
return errors.New("运营中心用户暂未注册im系统")
}
groupName := "抖省(" + utils2.AnyToString(msg.OperationCenterUid) + ")运营中心【1】群"
if operationCenterUser.Nickname != "" {
groupName = "抖省(" + utils2.AnyToString(operationCenterUser.Nickname) + ")运营中心【1】群"
var m model2.RegionalAgentUser
_, err = db.DBs[msg.MasterId].Where("uid =?", msg.OperationCenterUid).Get(&m)
if err != nil {
panic(err)
}
regionalAgentRegion, err := db.RegionalAgentRegionGetOneByParams(db.DBs[msg.MasterId], map[string]interface{}{
"key": "id",
"value": m.RegionId,
})
if err != nil {
panic(err)
}

groupName := "抖省" + regionalAgentRegion.Name + "运营中心【" + utils2.AnyToString(len(*operationGroups)) + "】群"

resp, err := utils.GetLogicExtClient(cfg.ImLogicRpc.URL, cfg.ImLogicRpc.PORT).CreateGroup(utils.GetCtx("", utils2.Int64ToStr(operationCenterGimUser.Id), "", msg.MasterId), &pb.CreateGroupReq{
Name: groupName,
AvatarUrl: "",
@@ -157,14 +187,12 @@ func handleDouShenUserRegisterConsumeForOperationCenter(msgData []byte) error {
if err != nil {
return err
}
OperationGroup, err = db.DouShenImGroupGetOneByParamsForFans(db.Db, 2, msg.OperationCenterUid)
OperationGroup, err = db.DouShenImGroupGetOneByParams(db.Db, 2, map[string]interface{}{
"group_id": resp.GroupId,
})
if err != nil {
return err
}
if OperationGroup == nil {
utils2.FilePutContents("douShenUserRegisterConsumeForOperationCenter_not_found", utils2.SerializeStr(msg))
return errors.New("当前城市合伙人暂未拥有运营中心群,请联系管理员!!!")
}
}
userGroup, err2 := db2.GroupUserGetOneByParams(db.ImDb, 1, map[string]interface{}{
"key": "group_id",


Loading…
Откажи
Сачувај