1
This commit is contained in:
@@ -1,95 +0,0 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
// JXMsg 京西消息结构体
|
||||
type JXMsg struct {
|
||||
SendType string `json:"sendType"` //消息发送方 jx-商家;mt-美团;elm-饿了么
|
||||
Data interface{} `json:"data"` //美团/饿了么 单聊消息
|
||||
}
|
||||
|
||||
var (
|
||||
rdb = api.Cacher
|
||||
)
|
||||
|
||||
const (
|
||||
SendTypeJx = "jx" //消息发送方jx标识符
|
||||
ExpireTimeDay = 24 * time.Hour //redis一天过期时间
|
||||
)
|
||||
|
||||
// GetUserList 查询门店-用户消息列表(与当前商铺聊天的所有用户) appid:vendorStoreID:10/11(mt/elm)
|
||||
func GetUserList(keys []string) (retVal []interface{}) {
|
||||
if len(keys) == 0 {
|
||||
return nil
|
||||
}
|
||||
for _, v := range keys {
|
||||
if value := rdb.Get(v); value != nil {
|
||||
retVal = append(retVal, value)
|
||||
}
|
||||
}
|
||||
if len(retVal) > 0 {
|
||||
return retVal
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetOneUserDetail 获取当前用户(单个)所有聊天记录 appID:vendorStoreID:10:userID
|
||||
func GetOneUserDetail(msgID string) (retVal interface{}) {
|
||||
if retVal = rdb.Get(msgID); retVal != nil {
|
||||
return retVal
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetMessageDetail 存储门店用户聊天detail 门店发送
|
||||
func SetMessageDetail(data interface{}, vendorID string) error {
|
||||
if vendorID == model.IMVendorIDMT {
|
||||
param := JXMsg{
|
||||
SendType: SendTypeJx,
|
||||
Data: data,
|
||||
}
|
||||
//生成与美团消息id
|
||||
req := data.(mtwmapi.SingleChat)
|
||||
key := GenMtMsgDetailID(req.AppPoiCode, req.AppID, req.OpenUserID)
|
||||
//存储
|
||||
paramM, _ := json.Marshal(param)
|
||||
err := rdb.RPush(key, string(paramM))
|
||||
ok, err := rdb.ExpireResult(key, ExpireTimeDay)
|
||||
if err != nil || !ok {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if vendorID == model.IMVendorIDELM {
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//1 美团
|
||||
|
||||
// GenMtMsgDetailID 生成查询详细聊天记录ID
|
||||
func GenMtMsgDetailID(vendorStoreID string, appID, userID int) string {
|
||||
temp := utils.Int2Str(appID) + ":" + vendorStoreID + ":10:" + utils.Int2Str(userID)
|
||||
return temp
|
||||
}
|
||||
|
||||
// SetMessageRead 平台方设置消息已读(不使用)
|
||||
//func SetMessageRead(msgID, vendorStoreID, vendorID string) (err error) {
|
||||
// if vendorID == model.IMVendorIDMT {
|
||||
// err = api.MtwmAPI.MsgRead(vendorStoreID, msgID, vendorID)
|
||||
//
|
||||
// }
|
||||
// if vendorID == model.IMVendorIDELM {
|
||||
//
|
||||
// }
|
||||
// return nil
|
||||
//}
|
||||
Reference in New Issue
Block a user