Merge branch 'jdshop' of e.coding.net:rosydev/jx-callback into jdshop

This commit is contained in:
邹宗楠
2023-05-15 09:32:07 +08:00
6 changed files with 71 additions and 73 deletions

View File

@@ -3,6 +3,9 @@ package auto_delivery
import (
"crypto/rand"
"encoding/json"
"math/big"
"strings"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
@@ -10,8 +13,6 @@ import (
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals"
"math/big"
"strings"
)
var riderListInfo = make(map[string][]map[string]string, 0)
@@ -138,6 +139,8 @@ func AutoSettingFakeDelivery() {
return
}
}
globals.SugarLogger.Debug("==========%s,%d", riderKey, len(riderListInfo[riderKey]))
globals.SugarLogger.Debug("==========%s", utils.Format4Output(riderListInfo[riderKey], false))
randNumber, _ := rand.Int(rand.Reader, big.NewInt(int64(len(riderListInfo[riderKey]))))
randTime := randNumber.Int64()
if randTime < 0 {

View File

@@ -2,13 +2,14 @@ package misc
import (
"fmt"
"sync"
"time"
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
"git.rosy.net.cn/jx-callback/business/bidding"
"git.rosy.net.cn/jx-callback/business/jxcallback/auto_delivery"
"git.rosy.net.cn/jx-callback/business/jxutils/ddmsg"
"git.rosy.net.cn/jx-callback/business/partner/delivery"
"sync"
"time"
"git.rosy.net.cn/jx-callback/business/partner/purchase/jdshop"
@@ -83,17 +84,17 @@ var (
"7:00:00",
"8:00:00",
"9:00:00",
"10:00:00",
"11:00:00",
"12:00:00",
"13:00:00",
"14:00:00",
"15:00:00",
"16:00:00",
"17:00:00",
"18:00:00",
"19:00:00",
"20:00:00",
//"10:00:00",
//"11:00:00",
//"12:00:00",
//"13:00:00",
//"14:00:00",
//"15:00:00",
//"16:00:00",
//"17:00:00",
//"18:00:00",
//"19:00:00",
//"20:00:00",
}
openRemoteStoreTimeList = []string{
"04:30:00",
@@ -262,11 +263,11 @@ func Init() {
}, 5*time.Second, 10*time.Minute)
// 抖音更新门店商品 ,接口收费暂不使用
if beego.BConfig.RunMode != "jxgy" {
ScheduleTimerFunc("RefreshSyncSkuList", func() {
syncStoreSkuTiktok()
}, []string{"13:00:00"})
}
//if beego.BConfig.RunMode != "jxgy" {
// ScheduleTimerFunc("RefreshSyncSkuList", func() {
// syncStoreSkuTiktok()
// }, []string{"13:00:00"})
//}
//刷新抖音门店token
if beego.BConfig.RunMode != "jxgy" {

View File

@@ -1654,7 +1654,6 @@ func GetStoreBaseByVendorStoreID(vendorStoreID string, vendorID int) (storeDetai
return nil, errors.New("vendorStoreID不能为空")
}
//DefaultTimeValue := utils.Str2Time("1970-01-01 00:00:00")
sql := `SELECT t.* FROM store t WHERE t.id = (SELECT s.store_id FROM store_map s WHERE s.vendor_store_id= ? AND s.vendor_id= ? AND s.deleted_at= '1970-01-01 00:00:00' )`
if err := GetRow(GetDB(), &storeDetail, sql, []interface{}{vendorStoreID, vendorID}); err != nil {
return nil, err

View File

@@ -44,6 +44,7 @@ func SendToVendor(msg []byte) {
return
}
Send(temp, sendData.Data.(map[string]interface{})["app_id"])
return
}
if sendData.VendorID == VendorIDELM {
param := sendData.Data.(ebaiapi.BusinessSendMsgReq)
@@ -53,18 +54,6 @@ func SendToVendor(msg []byte) {
}
}
//if err != nil {
// ClientRender(Fail, FailMsg, map[string]string{
// "errMsg": fmt.Sprintf("%v", err),
// })
// return err
//} else {
// ClientRender(SuccessCode, SuccessMsg, map[string]interface{}{
// "vendorID": sendData.VendorID,
// "msg": "ok",
// })
// return nil
//}
return
}
@@ -92,16 +81,16 @@ func Send(data []byte, appID interface{}) {
for {
_, msg, err := conn.ReadMessage()
temp := string(msg)
res := JsonCommon(HeartSuccessWord)
fmt.Printf("Send %s receive: %s\n", conn.RemoteAddr(), string(msg))
if err != nil {
break
} else if temp == res {
continue
} else {
if temp != HeartSuccessWord {
ReadMsgFromVendor(VendorIDMT, "", msg)
}
ReadMsgFromVendor(VendorIDMT, "", msg)
}
fmt.Printf("%s receive: %s\n", conn.RemoteAddr(), string(msg))
}
return
}
// MtInit 发送心跳
@@ -135,12 +124,15 @@ func MtInit() {
for {
_, msg, err := conn.ReadMessage()
temp := string(msg)
if err != nil || temp != "HB" {
res := JsonCommon(HeartCheckSuccess)
fmt.Printf("MtInit %s receive: %s\n", conn.RemoteAddr(), string(msg))
if err != nil {
break
} else if temp == res {
continue
} else {
ReadMsgFromVendor(VendorIDMT, "", msg)
}
fmt.Printf("%s receive: %s\n", conn.RemoteAddr(), string(msg))
}
}, url.ClientIDMain)
@@ -172,12 +164,13 @@ func MtInit() {
for {
_, msg, err := connSub.ReadMessage()
temp := string(msg)
if err != nil || temp != HeartCheckSuccess {
res := JsonCommon(HeartCheckSuccess)
if err != nil || temp == res {
break
} else {
ReadMsgFromVendor(VendorIDMT, "", msg)
}
fmt.Printf("%s connSub:receive: %s\n", connSub.RemoteAddr(), string(msg))
fmt.Printf("MtInit %s connSub:receive: %s\n", connSub.RemoteAddr(), string(msg))
}
}, url.ClientIDSub)
@@ -220,7 +213,7 @@ func ReadMsgFromClient(vendorID int, elmAppID string, msg interface{}) {
MsgContent: ElmData,
}
userList = &UserMessageList{
VendorID: VendorIDMT,
VendorID: VendorIDELM,
UserID: ElmData.PayLoad.GroupID,
LatestMsg: ElmData.PayLoad.Content,
LatestTime: int(ElmData.PayLoad.CreateTime),
@@ -245,10 +238,10 @@ func ReadMsgFromVendor(vendorID int, elmAppID string, msg []byte) {
return
}
var (
err error
vendorStoreID string
jxMsg = &JXMsg{}
userList = &UserMessageList{}
err error
//vendorStoreID string
jxMsg = &JXMsg{}
userList = &UserMessageList{}
)
if vendorID == VendorIDMT {
var MtSingleChat = mtwmapi.SingleChat{}
@@ -263,7 +256,7 @@ func ReadMsgFromVendor(vendorID int, elmAppID string, msg []byte) {
LatestMsg: MtSingleChat.MsgContent,
LatestTime: MtSingleChat.Cts,
}
vendorStoreID = MtSingleChat.AppPoiCode
//vendorStoreID = MtSingleChat.AppPoiCode
}
if vendorID == VendorIDELM {
var ElmData = ebaiapi.ImMessageSend{}
@@ -273,7 +266,7 @@ func ReadMsgFromVendor(vendorID int, elmAppID string, msg []byte) {
MsgContent: ElmData,
}
userList = &UserMessageList{
VendorID: VendorIDMT,
VendorID: VendorIDELM,
UserID: ElmData.PayLoad.GroupID,
LatestMsg: ElmData.PayLoad.Content,
LatestTime: int(ElmData.PayLoad.CreateTime),
@@ -291,9 +284,13 @@ func ReadMsgFromVendor(vendorID int, elmAppID string, msg []byte) {
//return
}
//3 cid推送新消息
err = PushMsgByCid(vendorStoreID, vendorID)
//err = PushMsgByCid(vendorStoreID, vendorID)
//4 长链接通知给客户端
ToClientChan <- clientInfo{Code: SuccessCode, Msg: fmt.Sprintf("%v", err), Data: jxMsg}
if err != nil {
ToClientChan <- clientInfo{Code: SuccessCode, Msg: fmt.Sprintf("%v", err), Data: jxMsg}
} else {
ToClientChan <- clientInfo{Code: SuccessCode, Msg: SuccessMsg, Data: jxMsg}
}
return
}
@@ -372,11 +369,11 @@ func GetNewAndTrim(key string, flag string) (cnt int, err error) {
func GenMsgDetailID(jxMsg *JXMsg, vendorID int, elmAppID string) (msgID string) {
if vendorID == VendorIDMT {
var d1 = jxMsg.MsgContent.(mtwmapi.SingleChat)
msgID = utils.Int2Str(d1.AppID) + ":" + d1.AppPoiCode + ":10:" + utils.Int2Str(d1.OpenUserID)
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 + ":11:" + d2.PayLoad.GroupID
msgID = elmAppID + ":" + d2.PlatformShopID + ":3:" + d2.PayLoad.GroupID
}
return msgID
}
@@ -385,11 +382,11 @@ func GenMsgDetailID(jxMsg *JXMsg, vendorID int, elmAppID string) (msgID string)
func GenMsgListID(jxMsg *JXMsg, vendorID int, elmAppID string) (msgID string) {
if vendorID == VendorIDMT {
var d1 = jxMsg.MsgContent.(mtwmapi.SingleChat)
msgID = utils.Int2Str(d1.AppID) + ":" + d1.AppPoiCode + ":10"
msgID = utils.Int2Str(d1.AppID) + ":" + d1.AppPoiCode + ":1"
}
if vendorID == VendorIDELM {
var d2 = jxMsg.MsgContent.(ebaiapi.ImMessageSend)
msgID = elmAppID + ":" + d2.PlatformShopID + ":11"
msgID = elmAppID + ":" + d2.PlatformShopID + ":3"
}
return msgID
}

View File

@@ -82,13 +82,8 @@ type commonConf struct {
// SendData 客户端写入参数
type SendData struct {
//ClientId string `json:"clientId" validate:"required"` //链接ID
VendorID int `json:"vendorID"` //消息来源平台ID 10-美团 11-饿了么
VendorID int `json:"vendorID"` //消息来源平台ID 1-美团 3-饿了么
Data interface{} `json:"data"` //发送给平台 美团/饿了么消息结构体
//返回值
//Code int `json:"code"`
//Msg string `json:"msg"`
//SendUserId string `json:"sendUserId"`
}
// JXMsg 京西消息结构体
@@ -153,7 +148,7 @@ var (
CommonSetting = &commonConf{}
GlobalSetting = &global{}
//心跳相关
heartbeatInterval = 60 * time.Second // 心跳间隔
heartbeatInterval = 20 * time.Second // 心跳间隔
HeartCheckMsg = "~#HHHBBB#~" //心跳检测消息
HeartCheckSuccess = "HB" //成功发送返回心跳消息
HeartSuccessWord = "成功" //成功发送返回心跳消息
@@ -345,3 +340,10 @@ func RandString() string {
}
return string(bytes)
}
// JsonCommon json格式化
func JsonCommon(str string) (retVal string) {
temp, _ := json.Marshal(str)
_ = json.Unmarshal(temp, &retVal)
return retVal
}

View File

@@ -90,18 +90,18 @@ func PingTimer() {
if conn.ClientType == ClientTypeJx {
if err := conn.Socket.WriteControl(websocket.PingMessage, []byte{}, time.Now().Add(time.Second)); err != nil {
Manager.DisConnect <- conn
globals.SugarLogger.Debugf("发送心跳失败: %s 总连接数:%d", clientId, Manager.Count())
fmt.Printf("发送心跳失败: %s 总连接数:%d", clientId, Manager.Count())
}
if err := ConnRender(conn.Socket, renderData{ClientId: clientId}); err != nil {
return
}
} else {
if err := conn.Socket.WriteMessage(websocket.TextMessage, []byte(HeartCheckMsg)); err != nil {
fmt.Printf("PingTimer mtHeartBeat err:%v", err)
//对美团重新建立连接
MtInit()
}
}
//globals.SugarLogger.Debugf("发送心跳 clientId=%s,i=%d", clientId, i)
}
}
}()
@@ -114,11 +114,11 @@ func WriteMessage() {
clientInfo := <-ToClientChan
//广播发送通知所有京西客户端
i++
fmt.Printf("WriteMessage clientInfo=%s i=%d", utils.Format4Output(clientInfo, false), i)
fmt.Printf("WriteMessage clientInfo=%s i=%d\n", utils.Format4Output(clientInfo, false), i)
if Manager.AllClient() != nil {
for _, conn := range Manager.AllClient() {
if conn.ClientType == ClientTypeJx { //只发送给京西
globals.SugarLogger.Debugf("WriteMessage conn.ClientId=%s", conn.ClientId)
fmt.Printf("WriteMessage conn.ClientId=%s\n", conn.ClientId)
if err := Render(conn.Socket, clientInfo.MessageId, clientInfo.Code, clientInfo.Msg, clientInfo.Data); err != nil {
Manager.DisConnect <- conn
}
@@ -128,11 +128,6 @@ func WriteMessage() {
globals.SugarLogger.Debugf("无客户端连接,请检查")
return
}
//if conn, err := Manager.GetByClientId(clientInfo.ClientId); err == nil && conn != nil {
// if err := Render(conn.Socket, clientInfo.MessageId, clientInfo.Code, clientInfo.Msg, clientInfo.Data); err != nil {
// Manager.DisConnect <- conn
// }
//}
}
}
@@ -155,8 +150,8 @@ func (c *Client) Read() {
go func() {
for {
messageType, msg, err := c.Socket.ReadMessage()
temp := string(msg)
fmt.Print(temp)
//temp := string(msg)
//fmt.Print(temp)
if err != nil {
if messageType == -1 && websocket.IsCloseError(err, websocket.CloseGoingAway, websocket.CloseNormalClosure, websocket.CloseNoStatusReceived) {
Manager.DisConnect <- c
@@ -165,6 +160,7 @@ func (c *Client) Read() {
return
}
}
fmt.Printf("Client Read:receive: %s\n", string(msg))
SendToVendor(msg)
}
}()