Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录
切换导航
L
library
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
stbz
library
Commits
b1658d72
提交
b1658d72
authored
1月 14, 2022
作者:
gukai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新通知系统
上级
4897acaa
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
228 行增加
和
18 行删除
+228
-18
consumer.go
notify/consumer.go
+1
-1
message.go
notify/message.go
+175
-0
model.go
notify/model.go
+51
-0
producer.go
notify/producer.go
+1
-1
upstream.go
upstream/upstream.go
+0
-16
没有找到文件。
n
sq
/consumer.go
→
n
otify
/consumer.go
浏览文件 @
b1658d72
package
n
sq
package
n
otify
import
(
import
(
"github.com/nsqio/go-nsq"
"github.com/nsqio/go-nsq"
...
...
notify/message.go
0 → 100644
浏览文件 @
b1658d72
package
notify
import
(
"encoding/json"
"errors"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gconv"
"gitlab.jxhh.com/stbz/library.git/logs"
"math/rand"
"strconv"
"time"
)
const
(
//通知服务topic
MsgOrderTopic
=
"messageOrder"
MsgGoodsTopic
=
"messageGoods"
//云仓消息topic
MsgCloudTopic
=
"shopApi"
//通知消息系统topic
NotifyTopic
=
"notifyMessage"
//消息类型
ProductExpire
=
101
ProductModify
=
102
ProductPrice
=
103
ProductRepost
=
104
OrderSendgoods
=
201
OrderComfirmReceiveGoods
=
202
OrderSuccess
=
203
OrderCancel
=
204
RefundApply
=
300
RefundAgree
=
301
RefundRefuse
=
302
RefundSuccess
=
303
ImportTags
=
401
ErrMsgParamEmpty
=
"该类型消息对应字段不能为空"
ErrMsgAppIDEmpty
=
"该类型消息appid字段不能为空"
)
var
(
SendMsgType
=
g
.
MapIntStr
{
ProductExpire
:
"goods.undercarriage"
,
ProductModify
:
"goods.alter"
,
ProductPrice
:
"goods.price.alter"
,
ProductRepost
:
"goods.on.sale"
,
OrderSendgoods
:
"order.delivery"
,
OrderComfirmReceiveGoods
:
"order.delivered"
,
OrderSuccess
:
"order.success"
,
OrderCancel
:
"order.cancel"
,
RefundAgree
:
"afterSale.agree"
,
RefundRefuse
:
"afterSale.refuse"
,
RefundSuccess
:
"afterSale.success"
,
}
)
func
(
p
*
NsqProducer
)
msgValidator
(
notifyMessage
*
NotifyMessage
)
(
err
error
)
{
switch
gconv
.
Int
(
notifyMessage
.
Type
)
/
100
%
10
{
case
1
:
var
msgData
*
GoodsMsgData
if
err
=
gconv
.
Struct
(
notifyMessage
.
Data
,
&
msgData
);
err
!=
nil
{
return
}
if
len
(
msgData
.
GoodsIDs
)
==
0
{
err
=
errors
.
New
(
ErrMsgParamEmpty
)
return
}
case
2
:
var
msgData
*
OrderMsgData
if
err
=
gconv
.
Struct
(
notifyMessage
.
Data
,
&
msgData
);
err
!=
nil
{
return
}
if
msgData
.
OrderSn
==
""
||
msgData
.
Sku
==
0
{
err
=
errors
.
New
(
ErrMsgParamEmpty
)
return
}
if
notifyMessage
.
AppID
==
0
{
err
=
errors
.
New
(
ErrMsgAppIDEmpty
)
return
}
case
3
:
var
msgData
*
RefundMsgData
if
err
=
gconv
.
Struct
(
notifyMessage
.
Data
,
&
msgData
);
err
!=
nil
{
return
}
if
msgData
.
OrderSn
==
""
||
msgData
.
Sku
==
0
||
msgData
.
AfterSaleID
==
0
{
err
=
errors
.
New
(
ErrMsgParamEmpty
)
return
}
if
notifyMessage
.
AppID
==
0
{
err
=
errors
.
New
(
ErrMsgAppIDEmpty
)
return
}
case
4
:
var
msgData
*
TagsMsgData
if
err
=
gconv
.
Struct
(
notifyMessage
.
Data
,
&
msgData
);
err
!=
nil
{
return
}
if
msgData
.
Tags
==
""
{
err
=
errors
.
New
(
ErrMsgParamEmpty
)
return
}
if
notifyMessage
.
AppID
==
0
{
err
=
errors
.
New
(
ErrMsgAppIDEmpty
)
return
}
default
:
err
=
errors
.
New
(
ErrMsgAppIDEmpty
)
}
return
}
/*
各服务推送通知到消息系统 20220114 gk
*/
func
(
p
*
NsqProducer
)
NotifyMessage
(
notifyMessage
*
NotifyMessage
)
(
err
error
)
{
err
=
p
.
msgValidator
(
notifyMessage
)
if
logs
.
CheckErr
(
err
,
"NotifyMessage"
){
return
}
r
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
var
randNums
string
for
i
:=
0
;
i
<=
2
;
i
++
{
randNums
+=
strconv
.
Itoa
(
r
.
Intn
(
9
))
}
notifyMessage
.
ID
=
gconv
.
Int
(
gconv
.
String
(
time
.
Now
()
.
UnixNano
()
/
1e6
)
+
randNums
)
jsonBytes
,
_
:=
json
.
Marshal
(
notifyMessage
)
err
=
NsqProducers
.
Publish
(
NotifyTopic
,
string
(
jsonBytes
))
if
!
logs
.
CheckErr
(
err
,
"NotifyMessage"
)
{
logs
.
Info
(
"NotifyMessage"
,
"消息内容:【%v】"
,
string
(
jsonBytes
))
}
return
}
/*
推送通知到服务系统系统 20220114 gk
*****************************************************
*******注意:该方法目前只有message-server使用 ***********
*****************************************************
*/
func
(
p
*
NsqProducer
)
NotifyServer
(
notifyServer
*
NotifyServer
)
(
err
error
)
{
jsonBytes
,
_
:=
json
.
Marshal
(
notifyServer
)
var
pushTopic
string
switch
notifyServer
.
MsgType
/
100
%
10
{
case
1
:
pushTopic
=
MsgGoodsTopic
case
2
:
pushTopic
=
MsgOrderTopic
case
3
:
pushTopic
=
MsgOrderTopic
}
if
pushTopic
==
""
{
return
}
err
=
NsqProducers
.
Publish
(
NotifyTopic
,
string
(
jsonBytes
))
if
!
logs
.
CheckErr
(
err
,
"NotifyServer"
)
{
logs
.
Info
(
"NotifyServer"
,
"消息内容:【%v】"
,
string
(
jsonBytes
))
}
return
}
n
sq
/model.go
→
n
otify
/model.go
浏览文件 @
b1658d72
package
nsq
package
notify
type
CommonReq
struct
{
MsgType
int
`json:"msgType"`
MsgData
string
`json:"msgData"`
Source
int
`json:"source"`
MsgSendTime
int64
`json:"msgSendTime"`
}
type
CommonReply
struct
{
Success
interface
{}
`json:"success"`
Msg
string
`json:"msg"`
Data
interface
{}
`json:"data"`
Code
int
`json:"code"`
}
type
NotifyReqData
struct
{
type
NotifyReqData
struct
{
RealSource
int
`json:"real_source"`
RealSource
int
`json:"real_source"`
...
@@ -30,17 +14,38 @@ type NotifyReq struct {
...
@@ -30,17 +14,38 @@ type NotifyReq struct {
Data
NotifyReqData
`json:"data"`
Data
NotifyReqData
`json:"data"`
}
}
type
NotifyRes
struct
{
//公共message消息
Code
int
`json:"code"`
type
NotifyServer
struct
{
Msg
string
`json:"msg"`
MsgType
int
`json:"msg_type"`
MsgData
interface
{}
`json:"msg_data"`
Source
int
`json:"source"`
MsgSendTime
int64
`json:"msg_send_time"`
}
//通知消息系统
type
NotifyMessage
struct
{
ID
int
`json:"id"`
Type
interface
{}
`json:"type"`
Data
interface
{}
`json:"data"`
URL
string
`json:"url"`
AppID
int
`json:"appID"`
}
}
type
NotifyResNew
struct
{
Msg
string
`json:"message"`
type
GoodsMsgData
struct
{
GoodsIDs
[]
int
`json:"goods_id"`
}
type
OrderMsgData
struct
{
OrderSn
string
`json:"orderSn"`
Sku
uint
`json:"sku"`
}
}
type
NotifyRefund
Data
struct
{
type
RefundMsg
Data
struct
{
Af
sServiceId
string
`json:"afsServic
eId"`
Af
terSaleID
uint
`json:"afterSal
eId"`
State
int
`json:"state
"`
OrderSn
string
`json:"orderSn
"`
AfterSrvStatus
string
`json:"after_srv_status
"`
Sku
uint
`json:"sku
"`
}
}
type
TagsMsgData
struct
{
Tags
string
`json:"tags"`
}
n
sq
/producer.go
→
n
otify
/producer.go
浏览文件 @
b1658d72
package
n
sq
package
n
otify
import
(
import
(
"fmt"
"fmt"
...
...
upstream/upstream.go
浏览文件 @
b1658d72
package
upstream
package
upstream
//推送类型 101 商品下架 102 商品修改 103 价格变更 104 商品上架 201 订单发货 202 确认收货 301 同意售后退款 302 拒绝售后退款 303 售后退款成功',
const
(
ProductExpire
=
101
ProductModify
=
102
ProductPrice
=
103
ProductRepost
=
104
OrderSendgoods
=
201
OrderComfirmReceivegoods
=
202
OrderSuccess
=
203
RefundApply
=
300
RefundAgree
=
301
RefundRefuse
=
302
RefundSuccess
=
303
)
const
(
const
(
Jd
=
2
Jd
=
2
Ali
=
6
Ali
=
6
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论