创建聊天组
This commit is contained in:
@@ -11,8 +11,6 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -23,12 +21,6 @@ var (
|
|||||||
regexpToken = regexp.MustCompile(`,"token":".*"`)
|
regexpToken = regexp.MustCompile(`,"token":".*"`)
|
||||||
)
|
)
|
||||||
|
|
||||||
type CheckCookie struct {
|
|
||||||
VendorID int `json:"vendorID"`
|
|
||||||
VendorOrgCode string `json:"vendorOrgCode"`
|
|
||||||
Status string `json:"status"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddOperateEvent(ctx *jxcontext.Context, accessUUID, jsonData string, errCode, errMsg string, useTime int, apiFunctionSpec string) (err error) {
|
func AddOperateEvent(ctx *jxcontext.Context, accessUUID, jsonData string, errCode, errMsg string, useTime int, apiFunctionSpec string) (err error) {
|
||||||
var (
|
var (
|
||||||
apiFunction string
|
apiFunction string
|
||||||
@@ -134,68 +126,45 @@ func GetOperateEvents(ctx *jxcontext.Context, name string, apiFunctions []string
|
|||||||
return pageInfo, err
|
return pageInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCheckVendorCookie(ctx *jxcontext.Context, vendorIDs []int, isAuto bool) (ccList []*CheckCookie, err error) {
|
func CreateMessageGroup(ctx *jxcontext.Context, userID, userID2 string) (err error) {
|
||||||
var (
|
var (
|
||||||
ebaiOrderID = "1577329467196263592"
|
db = dao.GetDB()
|
||||||
ebaiErr = "return not json"
|
groupID int
|
||||||
ebaiErr2 = "系统错误"
|
|
||||||
mtStoreID = "7388603"
|
|
||||||
mtErr = "返回结果格式不正常"
|
|
||||||
jdUpcCode = "6952395700895"
|
|
||||||
jdErr = "请输入用户名"
|
|
||||||
// mtpsErr = "用户未登录"
|
|
||||||
errMsg = ""
|
|
||||||
)
|
)
|
||||||
for _, v := range vendorIDs {
|
if userID2 != "" {
|
||||||
cc := &CheckCookie{}
|
user, err := dao.GetUserByID(db, "user_id", userID2)
|
||||||
var flag = false
|
if err != nil {
|
||||||
switch v {
|
return err
|
||||||
case model.VendorIDEBAI:
|
}
|
||||||
resultMap, err := api.EbaiAPI.GetStoreOrderInfo(ebaiOrderID)
|
if user == nil {
|
||||||
if len(resultMap) < 1 && err != nil {
|
return fmt.Errorf("无法找到要联系的用户!")
|
||||||
if strings.Contains(err.Error(), ebaiErr) || strings.Contains(err.Error(), ebaiErr2) {
|
}
|
||||||
errMsg += fmt.Sprintf(" 饿百账号:[%v]的Cookie无效了!")
|
for {
|
||||||
flag = true
|
groupID = jxutils.GenRand6()
|
||||||
}
|
temp := &model.MessageGroup{
|
||||||
|
GroupID: groupID,
|
||||||
}
|
}
|
||||||
case model.VendorIDMTWM:
|
dao.GetEntity(db, temp, "GroupID")
|
||||||
_, err := api.MtwmAPI.PackagePriceGet(mtStoreID)
|
if temp == nil {
|
||||||
if err != nil {
|
break
|
||||||
if strings.Contains(err.Error(), mtErr) {
|
|
||||||
errMsg += fmt.Sprintf(" 美团账号:[%v]的Cookie无效了!")
|
|
||||||
flag = true
|
|
||||||
}
|
|
||||||
globals.SugarLogger.Debugf("cookieCheck", err)
|
|
||||||
}
|
|
||||||
case model.VendorIDJD:
|
|
||||||
result, err := api.JdAPI.GetJdUpcCodeByName("", jdUpcCode, 1, 5)
|
|
||||||
if len(result) < 1 && err != nil {
|
|
||||||
if strings.Contains(err.Error(), jdErr) {
|
|
||||||
errMsg += fmt.Sprintf(" 京东账号:[%v]的Cookie无效了!")
|
|
||||||
flag = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case model.VendorIDJDShop:
|
|
||||||
_, err := api.JdShopAPI.OrderDetail("124350112427")
|
|
||||||
if err != nil {
|
|
||||||
if strings.Contains(err.Error(), "登录") {
|
|
||||||
errMsg += fmt.Sprintf("京东商城:[%v]的Cookie无效了!")
|
|
||||||
flag = true
|
|
||||||
}
|
|
||||||
globals.SugarLogger.Debugf("cookieCheck", err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cc.VendorID = v
|
messageGroup := &model.MessageGroup{
|
||||||
cc.VendorOrgCode = ""
|
GroupID: groupID,
|
||||||
if flag {
|
UserID: userID,
|
||||||
cc.Status = "无效"
|
Name: user.Name,
|
||||||
} else {
|
Type: model.GroupTypeSingle,
|
||||||
cc.Status = "有效"
|
MaxCount: 2,
|
||||||
}
|
}
|
||||||
ccList = append(ccList, cc)
|
messageGroupMember := &model.MessageGroupMember{
|
||||||
|
GroupID: groupID,
|
||||||
|
MemberUserID: userID2,
|
||||||
|
Type: model.GroupMemberTypeNormal,
|
||||||
|
}
|
||||||
|
dao.WrapAddIDCULDEntity(messageGroup, ctx.GetUserName())
|
||||||
|
dao.WrapAddIDCULDEntity(messageGroupMember, ctx.GetUserName())
|
||||||
|
dao.CreateEntity(db, messageGroup)
|
||||||
|
dao.CreateEntity(db, messageGroupMember)
|
||||||
}
|
}
|
||||||
if isAuto && errMsg != "" {
|
return err
|
||||||
globals.SugarLogger.Warnf("GetCheckVendorCookie:[%v]", errMsg)
|
|
||||||
}
|
|
||||||
return ccList, err
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,6 +171,10 @@ func GetPossibleVendorIDFromVendorOrderID(vendorOrderID string) (vendorID int) {
|
|||||||
return vendorID
|
return vendorID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GenRand6() (num int) {
|
||||||
|
return utils.Str2Int(fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000)))
|
||||||
|
}
|
||||||
|
|
||||||
func GenOrderNo() (orderNo int64) {
|
func GenOrderNo() (orderNo int64) {
|
||||||
var prefix = utils.Str2Int64(time.Now().Format("20060102"))
|
var prefix = utils.Str2Int64(time.Now().Format("20060102"))
|
||||||
const randPartNum = 1000
|
const randPartNum = 1000
|
||||||
@@ -216,6 +220,20 @@ func GenBillID() (billID int64) {
|
|||||||
return billID
|
return billID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GenGroupID() (groupID int64) {
|
||||||
|
const randPartNum = 100
|
||||||
|
groupID = time.Now().Unix() - orderNoBeginTimestamp
|
||||||
|
groupID = groupID * randPartNum
|
||||||
|
md5Bytes := md5.Sum([]byte(utils.GetUUID()))
|
||||||
|
randPart := 0
|
||||||
|
for k, v := range md5Bytes {
|
||||||
|
randPart += int(v) << ((k % 3) * 8)
|
||||||
|
}
|
||||||
|
groupID += int64(randPart % randPartNum)
|
||||||
|
groupID += int64(math.Pow10(int(math.Log10(float64(groupID))) + 1))
|
||||||
|
return groupID
|
||||||
|
}
|
||||||
|
|
||||||
func GenAfsOrderNo() (orderNo int64) {
|
func GenAfsOrderNo() (orderNo int64) {
|
||||||
const prefix = 80
|
const prefix = 80
|
||||||
const randPartNum = 100
|
const randPartNum = 100
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ const (
|
|||||||
MessageStatusSendAllSuccess = 1
|
MessageStatusSendAllSuccess = 1
|
||||||
MessageStatusSendSuccess = 2
|
MessageStatusSendSuccess = 2
|
||||||
MessageStatusSendAllFailed = 3
|
MessageStatusSendAllFailed = 3
|
||||||
|
|
||||||
|
GroupTypeSingle = 1 //单聊
|
||||||
|
GroupTypeMulit = 2 //群聊
|
||||||
|
|
||||||
|
GroupMemberTypeNormal = 1 //普通群员
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -69,6 +74,7 @@ func (*ImMessageRecord) TableIndex() [][]string {
|
|||||||
type MessageGroup struct {
|
type MessageGroup struct {
|
||||||
ModelIDCULD
|
ModelIDCULD
|
||||||
|
|
||||||
|
GroupID int `orm:"column(group_id)" json:"groupID"` //组ID
|
||||||
UserID string `orm:"size(48);column(user_id)" json:"userID"` //创建组的userID
|
UserID string `orm:"size(48);column(user_id)" json:"userID"` //创建组的userID
|
||||||
Name string `json:"name"` //组名
|
Name string `json:"name"` //组名
|
||||||
Type int `json:"type"` //组类型,1为单聊,2为群聊
|
Type int `json:"type"` //组类型,1为单聊,2为群聊
|
||||||
|
|||||||
@@ -185,6 +185,20 @@ func (c *EventController) GetImMessageRecord() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 创建聊天组
|
||||||
|
// @Description 创建聊天组
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param userID formData string true "创建者id"
|
||||||
|
// @Param userID2 formData string false "被拉的id 如果userID2为空就默认为是创建的群聊"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /CreateMessageGroup [post]
|
||||||
|
func (c *EventController) CreateMessageGroup() {
|
||||||
|
c.callCreateMessageGroup(func(params *tEventCreateMessageGroupParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// @Title 加入用户组
|
// @Title 加入用户组
|
||||||
// @Description 加入用户组
|
// @Description 加入用户组
|
||||||
// @Param token header string true "认证token"
|
// @Param token header string true "认证token"
|
||||||
|
|||||||
@@ -133,6 +133,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:EventController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:EventController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "CreateMessageGroup",
|
||||||
|
Router: `/CreateMessageGroup`,
|
||||||
|
AllowHTTPMethods: []string{"post"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Filters: nil,
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:EventController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:EventController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:EventController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:EventController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "GetImMessageRecord",
|
Method: "GetImMessageRecord",
|
||||||
|
|||||||
Reference in New Issue
Block a user