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