This commit is contained in:
邹宗楠
2025-12-18 09:33:16 +08:00
parent aa0e94ac6e
commit 422ff821f1
13 changed files with 69360 additions and 69319 deletions

View File

@@ -32,56 +32,24 @@ func SendVendorV2(data SendData, vendorOrgCode string) (err error) {
switch data.VendorID {
case model.VendorIDMTWM:
dataStr, _ := json.Marshal(data.Data)
temp := string(dataStr)
globals.SugarLogger.Debugf("SendVendorV2 mtwmtemp=%s", temp)
if _, err = partner.CurAPIManager.GetAPI(model.VendorIDMTWM, vendorOrgCode).(*mtwmapi.API).MsgSend(string(dataStr)); err != nil {
return err
}
case model.VendorIDEBAI:
str, _ := json.Marshal(data.Data)
param := &ebaiapi.BusinessSendMsgReq{}
err = json.Unmarshal(str, &param)
globals.SugarLogger.Debugf("SendVendorV2 ebaiparam=%s", utils.Format4Output(param, false))
err = partner.CurAPIManager.GetAPI(model.VendorIDEBAI, vendorOrgCode).(*ebaiapi.API).BusinessSendMsg(param)
if err = json.Unmarshal(str, &param); err == nil {
err = partner.CurAPIManager.GetAPI(model.VendorIDEBAI, vendorOrgCode).(*ebaiapi.API).BusinessSendMsg(param)
}
case model.VendorIDJD:
//uuid := utils.GetUUID()
//autoReplayParam := &jdapi.ContextMsg{
// Id: uuid,
// Lang: "zh_CN",
// Type: "chat_message",
// From: jdapi.ContextFrom{
// Pin: userMsg.From.Pin,
// App: "im.waiter",
// ClientType: "gw",
// },
// To: jdapi.ContextTo{
// Pin: userMsg.To.Pin,
// App: "im.customer",
// },
// Body: jdapi.ContextBody{
// Type: "text",
// Content: temp,
// Chatinfo: jdapi.ContextBodyChatInfo{
// VenderId: jd.VenderId,
// AskAllocateType: "multiChat",
// Sid: userMsg.Body.Chatinfo.Sid,
// Source: fmt.Sprintf("dd_msg_?_%s"?, uuid),
// },
// Template: struct {
// Source string `json:"source"`
// }{
// Source: fmt.Sprintf("dd_msg_?_%s"?, uuid),
// },
// Mt: 60,
// },
// Timestamp: time.Now().UnixNano(),
// ClientTime: time.Now().UnixNano(),
//}
//err = partner.CurAPIManager.GetAPI(model.VendorIDJD, vendorOrgCode).(*jdapi.API).MessagePushService(autoReplayParam)
str, _ := json.Marshal(data.Data)
param := &jdapi.ContextMsg{}
if err = json.Unmarshal(str, &param); err == nil {
err = partner.CurAPIManager.GetAPI(model.VendorIDJD, vendorOrgCode).(*jdapi.API).MessagePushService(param)
}
}
err = ReadMsgFromClient(data.VendorID, vendorOrgCode, data.Data)
err = ReadMsgFromClient(data.VendorID, vendorOrgCode, data.Data, data.StoreId)
if err != nil {
globals.SugarLogger.Debugf("SendVendorV2:%v", err)
}
@@ -172,6 +140,7 @@ func SetPoiIMStatus(param []SetPoiIMStatusReq) error {
}
case model.VendorIDJD:
api := partner.CurAPIManager.GetAPI(model.VendorIDJD, v.VendorOrgCode).(*jdapi.API)
api.ImStatusModify(fmt.Sprintf("%s+%s", v.VendorStoreID, v.VendorOrgCode), 0, true)
// 0忙碌1在线
err := api.ImWaiterStatusModify(1, v.VendorStoreID, v.ImStatus)
errList.AddErr(fmt.Errorf("jd:%v", err))
@@ -181,7 +150,7 @@ func SetPoiIMStatus(param []SetPoiIMStatusReq) error {
}
// ReadMsgFromClient 存储客户端发送的消息
func ReadMsgFromClient(vendorID int, elmAppID string, msg interface{}) error {
func ReadMsgFromClient(vendorID int, elmAppID string, msg interface{}, storeId int) error {
var (
err error
elmTime int
@@ -231,17 +200,61 @@ func ReadMsgFromClient(vendorID int, elmAppID string, msg interface{}) error {
}
case model.VendorIDJD:
var jdData = jdapi.ContextMsg{}
err = json.Unmarshal(data, &jdData)
jxMsg = &JXMsg{
SendType: SendTypeJx,
MsgContent: jdData,
}
userList = &UserMessageList{
VendorID: model.VendorIDJD,
UserID: jdData.From.Pin,
LatestMsg: utils.Interface2String(jdData.Body),
LatestTime: int(time.Now().Unix()),
if err = json.Unmarshal(data, &jdData); err == nil {
store, err := dao.GetStoreDetail(dao.GetDB(), storeId, model.VendorIDJD, elmAppID)
if err != nil {
return err
}
shopInfo := &jdapi.JdParamJsonObj{
StatusId: utils.Int2Str(storeId), // 京西门店ID
BillId: elmAppID, // vendorOrgCode
ExtendJsonData: "",
StoreId: store.VendorStoreID, // 平台门店ID
Timestamp: utils.Time2Str(time.Now()),
}
extendJsonData := &jdapi.UserChatMsg{
Id: jdData.Id,
Lang: jdData.Lang,
Type: jdData.Type,
From: struct {
Pin string `json:"pin"`
App string `json:"app"`
ClientType string `json:"clientType"`
}{
Pin: jdData.From.Pin,
App: jdData.From.App,
ClientType: jdData.From.ClientType,
},
To: struct {
Pin string `json:"pin"`
App string `json:"app"`
ClientType string `json:"clientType"`
}{
Pin: jdData.To.Pin,
App: jdData.To.App,
ClientType: "",
},
Body: jdapi.UserChatMsgBody{
Content: jdData.Body.Content,
Type: jdData.Body.Type,
},
Timestamp: jdData.Timestamp,
ClientTime: jdData.ClientTime,
}
shopInfo.ExtendJsonData = string(utils.MustMarshal(extendJsonData))
jxMsg = &JXMsg{
SendType: SendTypeJx,
MsgContent: jdData,
}
userList = &UserMessageList{
VendorID: model.VendorIDJD,
UserID: jdData.From.Pin,
LatestMsg: utils.Interface2String(jdData.Body),
LatestTime: int(time.Now().Unix()),
}
}
}
//1 存储展示列表时单条数据
@@ -258,7 +271,7 @@ func ReadMsgFromClient(vendorID int, elmAppID string, msg interface{}) error {
return nil
}
// ReadMsgFromVendor 读取数据并存储到redis
// ReadMsgFromVendor 读取数据并存储到redis 回调
func ReadMsgFromVendor(vendorID int, elmAppID string, msg []byte) error {
var (
err error
@@ -315,7 +328,6 @@ func ReadMsgFromVendor(vendorID int, elmAppID string, msg []byte) error {
if err = utils.UnmarshalUseNumber(msg, &risMsg); err != nil {
return err
}
globals.SugarLogger.Debugf("-----rismsg := %s", utils.Format4Output(risMsg, false))
storeDetail, err := dao.GetStoreDetailByVendorStoreID(dao.GetDB(), risMsg.StoreId, model.VendorIDJD, "")
if err != nil {
return err
@@ -332,24 +344,24 @@ func ReadMsgFromVendor(vendorID int, elmAppID string, msg []byte) error {
return err
}
userList = &UserMessageList{
VendorID: model.VendorIDJD,
LatestMsg: risMsg.ExtendJsonData,
MsgFrom: elmAppID,
VendorID: model.VendorIDJD,
MsgFrom: elmAppID,
}
switch elmAppID {
case jdapi.ImCallbackRisMsg:
userList.UserID = systemMsg.From.Pin
userList.LatestTime = int(systemMsg.Timestamp)
userList.LatestMsg = "暂无"
case jdapi.ImCallbackUserMsg:
userList.UserID = userMsg.From.Pin
userList.LatestTime = int(userMsg.Timestamp)
userList.LatestMsg = userMsg.Body.Content
case jdapi.ImCallbackReadMsg:
userList.UserID = readMsg.From.Pin
userList.LatestTime = int(userMsg.Timestamp)
userList.LatestMsg = "暂无"
}
vendorStoreID = risMsg.StoreId
return fmt.Errorf("咱暂不存储")
}
//1 存储详细聊天记录list
@@ -802,6 +814,7 @@ func CheckAndReply(req *JXMsg, elmAppID string) (err error) {
}
}
case SendTypeJd:
// 京东暂时有自动回复功能
//vendorID = model.VendorIDJD
//jd := req.MsgContent.(*jdapi.ChatRisMsgCallback)
////跳过12小时内商家消息自动回复

View File

@@ -29,8 +29,9 @@ var AppSecretByAppID = map[int]string{
// SendData 客户端写入参数
type SendData struct {
VendorID int `json:"vendorID"` //消息来源平台ID 1-美团 3-饿了么
Data interface{} `json:"data"` //发送给平台 美团/饿了么消息结构体
VendorID int `json:"vendorID"` // 消息来源平台ID 1-美团 3-饿了么
StoreId int `json:"storeId"` // 门店ID
Data interface{} `json:"data"` // 发送给平台 美团/饿了么消息结构体
}
// JXMsg 京西消息结构体