Merge branch 'jdshop' of e.coding.net:rosydev/jx-callback into jdshop
This commit is contained in:
@@ -10,6 +10,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/client/orm"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
@@ -282,6 +284,10 @@ func SetMessageDetail(req *JXMsg, vendorID int, elmAppID string) error {
|
||||
}
|
||||
//生成京西消息ID detail
|
||||
msgID := GenMsgDetailID(req, vendorID, elmAppID)
|
||||
if len(msgID) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
data, _ := json.Marshal(req)
|
||||
globals.SugarLogger.Debugf("SetMessageDetail data=%s", string(data))
|
||||
err := rdb.RPush(msgID, string(data))
|
||||
@@ -297,6 +303,9 @@ func SetMessageDetail(req *JXMsg, vendorID int, elmAppID string) error {
|
||||
func SetUserList(jxMsg *JXMsg, userList *UserMessageList, vendorID int, elmAppID string) error {
|
||||
//生成msgID
|
||||
msgID := GenMsgListID(jxMsg, vendorID, elmAppID)
|
||||
if len(msgID) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
//获取未读消息条数并删除旧数据
|
||||
cnt, err := GetNewAndTrim(msgID, userList.UserID)
|
||||
@@ -344,26 +353,47 @@ func GetNewAndTrim(key string, flag string) (cnt int, err error) {
|
||||
|
||||
// GenMsgDetailID 生成查询详细聊天记录ID
|
||||
func GenMsgDetailID(jxMsg *JXMsg, vendorID int, elmAppID string) (msgID string) {
|
||||
//globals.SugarLogger.Debugf("GenMsgDetailID test0124 jxMsg=%s", utils.Format4Output(jxMsg, false))
|
||||
if jxMsg == nil {
|
||||
return ""
|
||||
}
|
||||
if vendorID == VendorIDMT {
|
||||
var d1 = jxMsg.MsgContent.(mtwmapi.PushContentReq)
|
||||
msgID = utils.Int2Str(d1.AppID) + ":" + d1.AppPoiCode + ":1:" + utils.Int2Str(d1.OpenUserID)
|
||||
}
|
||||
if vendorID == VendorIDELM {
|
||||
var d2 = jxMsg.MsgContent.(ebaiapi.ImMessageSend)
|
||||
msgID = elmAppID + ":" + d2.PlatformShopID + ":3:" + d2.PayLoad.GroupID
|
||||
var ElmData = ebaiapi.ImMessageSend{}
|
||||
tempMsgContent, _ := json.Marshal(jxMsg.MsgContent)
|
||||
if err := json.Unmarshal(tempMsgContent, &ElmData); err != nil {
|
||||
return ""
|
||||
}
|
||||
//var d2 = jxMsg.MsgContent.(ebaiapi.ImMessageSend)
|
||||
//msgID = elmAppID + ":" + d2.PlatformShopID + ":3:" + d2.PayLoad.GroupID
|
||||
msgID = elmAppID + ":" + ElmData.PlatformShopID + ":3:" + ElmData.PayLoad.GroupID
|
||||
}
|
||||
return msgID
|
||||
}
|
||||
|
||||
// GenMsgListID 生成展示列表时单条数据ID(部分)
|
||||
func GenMsgListID(jxMsg *JXMsg, vendorID int, elmAppID string) (msgID string) {
|
||||
|
||||
//globals.SugarLogger.Debugf("GenMsgListID test0124 jxMsg=%s,vendorID=%d", utils.Format4Output(jxMsg, false), vendorID)
|
||||
if jxMsg == nil {
|
||||
return ""
|
||||
}
|
||||
if vendorID == VendorIDMT {
|
||||
var d1 = jxMsg.MsgContent.(mtwmapi.PushContentReq)
|
||||
msgID = utils.Int2Str(d1.AppID) + ":" + d1.AppPoiCode + ":1"
|
||||
}
|
||||
if vendorID == VendorIDELM {
|
||||
var d2 = jxMsg.MsgContent.(ebaiapi.ImMessageSend)
|
||||
msgID = elmAppID + ":" + d2.PlatformShopID + ":3"
|
||||
var ElmData = ebaiapi.ImMessageSend{}
|
||||
tempMsgContent, _ := json.Marshal(jxMsg.MsgContent)
|
||||
err := json.Unmarshal(tempMsgContent, &ElmData)
|
||||
fmt.Println(err)
|
||||
//var d2 = jxMsg.MsgContent.(ebaiapi.ImMessageSend)
|
||||
//msgID = elmAppID + ":" + d2.PlatformShopID + ":3"
|
||||
msgID = elmAppID + ":" + ElmData.PlatformShopID + ":3"
|
||||
|
||||
}
|
||||
return msgID
|
||||
}
|
||||
@@ -400,6 +430,30 @@ func FilterUserList(val string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// FilterChatDetail 去重
|
||||
func FilterChatDetail(req *JXMsg, vendorID int) {
|
||||
//if vendorID == VendorIDMT {
|
||||
// mt := req.MsgContent.(mtwmapi.PushContentReq)
|
||||
// temp, _ := GetImChatDetail([]UserRelInfo{{
|
||||
// VendorStoreID: mt.AppPoiCode,
|
||||
// VendorID: "1",
|
||||
// AppID: utils.Int2Str(mt.AppID),
|
||||
// UserID: utils.Int2Str(mt.OpenUserID),
|
||||
// }})
|
||||
//
|
||||
//}
|
||||
//
|
||||
//if vendorID == VendorIDELM {
|
||||
// elm := req.MsgContent.(ebaiapi.ImMessageSend)
|
||||
// temp, _ := GetImChatDetail([]UserRelInfo{{
|
||||
// VendorStoreID: elm.PlatformShopID,
|
||||
// VendorID: "3",
|
||||
// AppID: "34665",
|
||||
// UserID: elm.PayLoad.SenderID,
|
||||
// }})
|
||||
//}
|
||||
}
|
||||
|
||||
// GetImChatDetail 获取门店用户聊天详情
|
||||
func GetImChatDetail(req []UserRelInfo) (map[string][]interface{}, error) {
|
||||
retVal := make(map[string][]interface{}, 0)
|
||||
@@ -472,9 +526,9 @@ func CheckAndReply(req *JXMsg, elmAppID string) (err error) {
|
||||
flag = false
|
||||
vendorID int
|
||||
errList errlist.ErrList
|
||||
apply AutoReply
|
||||
apply *AutoReply
|
||||
jxMsg = &JXMsg{}
|
||||
userList = &UserMessageList{}
|
||||
//userList = &UserMessageList{}
|
||||
)
|
||||
if req.SendType == SendTypeMt {
|
||||
vendorID = VendorIDMT
|
||||
@@ -484,7 +538,7 @@ func CheckAndReply(req *JXMsg, elmAppID string) (err error) {
|
||||
flag = GetIfReply(key)
|
||||
//判断flag状态
|
||||
if !flag {
|
||||
apply = AutoReply{
|
||||
apply = &AutoReply{
|
||||
UserID: mt.AppID,
|
||||
MsgID: mt.MsgID,
|
||||
IsApply: true,
|
||||
@@ -514,13 +568,26 @@ func CheckAndReply(req *JXMsg, elmAppID string) (err error) {
|
||||
SendType: SendTypeJx,
|
||||
MsgContent: temp,
|
||||
}
|
||||
userList = &UserMessageList{
|
||||
VendorID: VendorIDMT,
|
||||
UserID: utils.Int2Str(mt.OpenUserID),
|
||||
LatestMsg: mt.MsgContent,
|
||||
LatestTime: mt.Cts,
|
||||
OrderID: "",
|
||||
//userList = &UserMessageList{
|
||||
// VendorID: VendorIDMT,
|
||||
// UserID: utils.Int2Str(mt.OpenUserID),
|
||||
// LatestMsg: mt.MsgContent,
|
||||
// LatestTime: mt.Cts,
|
||||
// OrderID: "",
|
||||
//}
|
||||
|
||||
//1 存储详细聊天记录
|
||||
if err = SetMessageDetail(jxMsg, vendorID, elmAppID); err != nil {
|
||||
errList.AddErr(fmt.Errorf("自动回复:存储详细聊天记录错误:%v", err))
|
||||
}
|
||||
//2 存储展示列表时单条数据
|
||||
//if err = SetUserList(jxMsg, userList, vendorID, elmAppID); err != nil {
|
||||
// errList.AddErr(fmt.Errorf("自动回复:存储STU聊天记录错误:%v", err))
|
||||
//}
|
||||
}
|
||||
//3 记录自动回复状态
|
||||
if err = RecordAutoStatus(key, apply); err != nil {
|
||||
errList.AddErr(fmt.Errorf("自动回复:记录自动回复状态错误:%v", err))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -533,64 +600,75 @@ func CheckAndReply(req *JXMsg, elmAppID string) (err error) {
|
||||
//1 检测是否已自动回复
|
||||
flag = GetIfReply(key)
|
||||
if !flag {
|
||||
apply = AutoReply{
|
||||
apply = &AutoReply{
|
||||
UserID: utils.Str2Int(elm.PayLoad.SenderID),
|
||||
MsgID: utils.Str2Int(elm.PayLoad.MsgID),
|
||||
IsApply: true,
|
||||
Timestamp: elm.PayLoad.CreateTime,
|
||||
}
|
||||
|
||||
temp := &ebaiapi.BusinessSendMsgReq{
|
||||
param := &ebaiapi.BusinessSendMsgReq{
|
||||
PlatformShopId: elm.PlatformShopID,
|
||||
BizType: ebaiapi.IMType,
|
||||
SubBizType: ebaiapi.IMTypeSendMsg,
|
||||
Payload: ebaiapi.BusinessMsgPayload{
|
||||
PayLoad: ebaiapi.BusinessMsgPayload{
|
||||
GroupId: elm.PayLoad.GroupID,
|
||||
MsgId: utils.Int2Str(RandTimeNumber()),
|
||||
ReceiverIds: elm.PayLoad.ReceiverIDs,
|
||||
ContentType: utils.Int2Str(ebaiapi.ContentTypeNormal),
|
||||
},
|
||||
}
|
||||
|
||||
temp := ""
|
||||
if template := GetCustomTemplate(elmAppID, elm.PlatformShopID); len(template) > 0 {
|
||||
temp.Payload.Content = template
|
||||
temp = template
|
||||
} else {
|
||||
temp.Payload.Content, err = GetDefaultTemplate(elmAppID, elm.PlatformShopID, VendorIDELM)
|
||||
temp, err = GetDefaultTemplate(elmAppID, elm.PlatformShopID, VendorIDELM)
|
||||
if err != nil {
|
||||
temp.Payload.Content = LastTemplate
|
||||
temp = LastTemplate
|
||||
}
|
||||
}
|
||||
tempStr, _ := json.Marshal(temp)
|
||||
tempContent := ebaiapi.Content{
|
||||
Text: string(tempStr),
|
||||
//Text: temp,
|
||||
}
|
||||
tempContentStr, _ := json.Marshal(tempContent)
|
||||
param.PayLoad.Content = string(tempContentStr)
|
||||
|
||||
if err = partner.CurAPIManager.GetAPI(model.VendorIDEBAI, elmAppID).(*ebaiapi.API).BusinessSendMsg(temp); err != nil {
|
||||
if err = partner.CurAPIManager.GetAPI(model.VendorIDEBAI, elmAppID).(*ebaiapi.API).BusinessSendMsg(param); err != nil {
|
||||
apply.IsApply = false
|
||||
globals.SugarLogger.Debugf("CheckAndReply mtSend err:%v", err)
|
||||
} else {
|
||||
//t1 := json.Unmarshal(param.Payload.Content)
|
||||
|
||||
jxMsg = &JXMsg{
|
||||
SendType: SendTypeJx,
|
||||
MsgContent: temp,
|
||||
MsgContent: param,
|
||||
}
|
||||
userList = &UserMessageList{
|
||||
VendorID: VendorIDELM,
|
||||
UserID: elm.PayLoad.SenderID,
|
||||
LatestMsg: elm.PayLoad.Content,
|
||||
LatestTime: elm.PayLoad.CreateTime,
|
||||
OrderID: "",
|
||||
//userList = &UserMessageList{
|
||||
// VendorID: VendorIDELM,
|
||||
// UserID: elm.PayLoad.SenderID,
|
||||
// LatestMsg: elm.PayLoad.Content,
|
||||
// LatestTime: elm.PayLoad.CreateTime,
|
||||
// OrderID: "",
|
||||
//}
|
||||
//1 存储详细聊天记录list
|
||||
if err = SetMessageDetail(jxMsg, vendorID, elmAppID); err != nil {
|
||||
errList.AddErr(fmt.Errorf("自动回复:存储详细聊天记录错误:%v", err))
|
||||
}
|
||||
//2 存储展示列表时单条数据
|
||||
//if err = SetUserList(jxMsg, userList, vendorID, elmAppID); err != nil {
|
||||
// errList.AddErr(fmt.Errorf("自动回复:存储STU聊天记录错误:%v", err))
|
||||
//}
|
||||
}
|
||||
//3 记录自动回复状态
|
||||
if err = RecordAutoStatus(key, apply); err != nil {
|
||||
errList.AddErr(fmt.Errorf("自动回复:记录自动回复状态错误:%v", err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//1 存储详细聊天记录list
|
||||
if err = SetMessageDetail(jxMsg, vendorID, elmAppID); err != nil {
|
||||
errList.AddErr(fmt.Errorf("自动回复:存储详细聊天记录错误:%v", err))
|
||||
}
|
||||
//2 存储展示列表时单条数据
|
||||
if err = SetUserList(jxMsg, userList, vendorID, elmAppID); err != nil {
|
||||
errList.AddErr(fmt.Errorf("自动回复:存储STU聊天记录错误:%v", err))
|
||||
}
|
||||
//3 记录自动回复状态
|
||||
if err = RecordAutoStatus(key, apply); err != nil {
|
||||
errList.AddErr(fmt.Errorf("自动回复:记录自动回复状态错误:%v", err))
|
||||
}
|
||||
if errList.GetErrListAsOne() != nil {
|
||||
return fmt.Errorf("CheckAndReply err=%v", errList.GetErrListAsOne())
|
||||
}
|
||||
@@ -613,7 +691,7 @@ func GetIfReply(key string) (flag bool) {
|
||||
}
|
||||
|
||||
// RecordAutoStatus 记录是否已自动回复状态
|
||||
func RecordAutoStatus(key string, apply AutoReply) error {
|
||||
func RecordAutoStatus(key string, apply *AutoReply) error {
|
||||
data, _ := json.Marshal(apply)
|
||||
err := rdb.RPush(key, string(data))
|
||||
ok, err := rdb.ExpireResult(key, ExpireTimeDay)
|
||||
@@ -660,16 +738,17 @@ func GetDefaultTemplate(appID, vendorStoreID string, vendorID int) (string, erro
|
||||
phoneNum = " "
|
||||
t string
|
||||
)
|
||||
store, err := dao.GetStoreDetail2(dao.GetDB(), 0, vendorStoreID, vendorID)
|
||||
if err != nil {
|
||||
store, err := dao.GetStoreDetailByVendorStoreID(dao.GetDB(), vendorStoreID, vendorID, "")
|
||||
if err != nil && err != orm.ErrNoRows {
|
||||
return "", err
|
||||
}
|
||||
if err == orm.ErrNoRows || (len(store.Tel1) == 0 && len(store.Tel2) == 0) {
|
||||
t = BasePhoneNum
|
||||
}
|
||||
if len(store.Tel1) > 0 {
|
||||
t = store.Tel1
|
||||
}
|
||||
if len(store.Tel1) == 0 && len(store.Tel2) == 0 {
|
||||
t = BasePhoneNum
|
||||
}
|
||||
|
||||
phoneNum = t[:3] + "-" + t[3:7] + "-" + t[7:]
|
||||
temp := BaseTemplate + phoneNum
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ func GetMsgCallBackUrl(msgType, appId string) string {
|
||||
|
||||
// OnImMsg im消息回调
|
||||
func OnImMsg(msg *mtwmapi.ImCallbackMsg) (response *mtwmapi.CallbackResponse) {
|
||||
|
||||
//globals.SugarLogger.Debugf("OnImMsg test0124 msg:=%s", utils.Format4Output(msg, false))
|
||||
if str, err := json.Marshal(msg.PushContent); err == nil {
|
||||
err = im.ReadMsgFromVendor(model.VendorIDMTWM, "", str)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user