@@ -15,24 +15,23 @@ import (
15
15
"looklook/app/order/model"
16
16
"looklook/app/usercenter/cmd/rpc/usercenter"
17
17
usercenterModel "looklook/app/usercenter/model"
18
- "looklook/common /globalkey"
19
- "looklook/common /tool"
20
- "looklook/common /wxminisub"
21
- "looklook/common /xerr"
18
+ "looklook/pkg /globalkey"
19
+ "looklook/pkg /tool"
20
+ "looklook/pkg /wxminisub"
21
+ "looklook/pkg /xerr"
22
22
"time"
23
23
)
24
24
25
25
var ErrPaySuccessNotifyFail = xerr .NewErrMsg ("pay success notify user fail" )
26
26
27
-
28
27
// PaySuccessNotifyUserHandler pay success notify user
29
28
type PaySuccessNotifyUserHandler struct {
30
29
svcCtx * svc.ServiceContext
31
30
}
32
31
33
32
func NewPaySuccessNotifyUserHandler (svcCtx * svc.ServiceContext ) * PaySuccessNotifyUserHandler {
34
33
return & PaySuccessNotifyUserHandler {
35
- svcCtx :svcCtx ,
34
+ svcCtx : svcCtx ,
36
35
}
37
36
}
38
37
@@ -49,56 +48,54 @@ func (l *PaySuccessNotifyUserHandler) ProcessTask(ctx context.Context, t *asynq.
49
48
AuthType : usercenterModel .UserAuthTypeSmallWX ,
50
49
})
51
50
if err != nil {
52
- return errors .Wrapf (ErrPaySuccessNotifyFail ,"pay success notify user fail, rpc get user err:%v , orderSn:%s , userId:%d" ,err ,p .Order .Sn ,p .Order .UserId )
51
+ return errors .Wrapf (ErrPaySuccessNotifyFail , "pay success notify user fail, rpc get user err:%v , orderSn:%s , userId:%d" , err , p .Order .Sn , p .Order .UserId )
53
52
}
54
53
if usercenterResp .UserAuth == nil || len (usercenterResp .UserAuth .AuthKey ) == 0 {
55
- return errors .Wrapf (ErrPaySuccessNotifyFail ,"pay success notify user , user no exists err:%v , orderSn:%s , userId:%d" ,err ,p .Order .Sn ,p .Order .UserId )
54
+ return errors .Wrapf (ErrPaySuccessNotifyFail , "pay success notify user , user no exists err:%v , orderSn:%s , userId:%d" , err , p .Order .Sn , p .Order .UserId )
56
55
}
57
56
openId := usercenterResp .UserAuth .AuthKey
58
57
59
-
60
58
// 2、send notify
61
- msgs := l .getData (ctx ,p .Order ,openId )
62
- for _ , msg := range msgs {
63
- l .SendWxMini (ctx ,msg )
59
+ msgs := l .getData (ctx , p .Order , openId )
60
+ for _ , msg := range msgs {
61
+ l .SendWxMini (ctx , msg )
64
62
}
65
63
66
64
return nil
67
65
}
68
66
69
67
// get send data
70
- func (l * PaySuccessNotifyUserHandler ) getData (_ context.Context ,order * model.HomestayOrder ,openId string )[]* subscribe.Message {
68
+ func (l * PaySuccessNotifyUserHandler ) getData (_ context.Context , order * model.HomestayOrder , openId string ) []* subscribe.Message {
71
69
72
70
return []* subscribe.Message {
73
71
{
74
- ToUser : openId ,
72
+ ToUser : openId ,
75
73
TemplateID : wxminisub .OrderPaySuccessTemplateID ,
76
74
Data : map [string ]* subscribe.DataItem {
77
75
"character_string6" : {Value : order .Sn },
78
76
"thing1" : {Value : order .Title },
79
- "amount2" : {Value :fmt .Sprintf ("%.2f" , tool .Fen2Yuan (order .OrderTotalPrice ))},
80
- "time4" : {Value :carbon .CreateFromTimestamp (order .LiveStartDate .Unix ()).Format (globalkey .DateTimeFormatTplStandardDate )},
81
- "time5" : {Value :carbon .CreateFromTimestamp (order .LiveEndDate .Unix ()).Format (globalkey .DateTimeFormatTplStandardDate )},
77
+ "amount2" : {Value : fmt .Sprintf ("%.2f" , tool .Fen2Yuan (order .OrderTotalPrice ))},
78
+ "time4" : {Value : carbon .CreateFromTimestamp (order .LiveStartDate .Unix ()).Format (globalkey .DateTimeFormatTplStandardDate )},
79
+ "time5" : {Value : carbon .CreateFromTimestamp (order .LiveEndDate .Unix ()).Format (globalkey .DateTimeFormatTplStandardDate )},
82
80
},
83
81
},
84
82
{
85
- ToUser : openId ,
83
+ ToUser : openId ,
86
84
TemplateID : wxminisub .OrderPaySuccessLiveKnowTemplateID ,
87
85
Data : map [string ]* subscribe.DataItem {
88
- "date2" : {Value :carbon .CreateFromTimestamp (order .LiveStartDate .Unix ()).Format (globalkey .DateTimeFormatTplStandardDate )},
89
- "date3" : {Value :carbon .CreateFromTimestamp (order .LiveEndDate .Unix ()).Format (globalkey .DateTimeFormatTplStandardDate )} ,
90
- "character_string4" : {Value :order .TradeCode } ,
91
- "thing1" : {Value :"请不要将验证码告知商家以外人员,以防上当" } ,
86
+ "date2" : {Value : carbon .CreateFromTimestamp (order .LiveStartDate .Unix ()).Format (globalkey .DateTimeFormatTplStandardDate )},
87
+ "date3" : {Value : carbon .CreateFromTimestamp (order .LiveEndDate .Unix ()).Format (globalkey .DateTimeFormatTplStandardDate )},
88
+ "character_string4" : {Value : order .TradeCode },
89
+ "thing1" : {Value : "请不要将验证码告知商家以外人员,以防上当" },
92
90
},
93
91
},
94
92
}
95
93
}
96
94
97
-
98
95
// SendWxMini send to wechat mini
99
- func (l * PaySuccessNotifyUserHandler ) SendWxMini (ctx context.Context ,msg * subscribe.Message ) {
96
+ func (l * PaySuccessNotifyUserHandler ) SendWxMini (ctx context.Context , msg * subscribe.Message ) {
100
97
101
- if l .svcCtx .Config .Mode != service .ProMode {
98
+ if l .svcCtx .Config .Mode != service .ProMode {
102
99
msg .MiniprogramState = "developer"
103
100
} else {
104
101
msg .MiniprogramState = "formal"
@@ -114,7 +111,7 @@ func (l *PaySuccessNotifyUserHandler) SendWxMini(ctx context.Context,msg *subscr
114
111
err := l .svcCtx .MiniProgram .GetSubscribe ().Send (msg )
115
112
if err != nil {
116
113
if retryNum > maxRetryNum {
117
- logx .WithContext (ctx ).Errorf ("Payment successful send wechat mini subscription message failed retryNum : %d , err:%v, msg : %+v " , retryNum ,err , msg )
114
+ logx .WithContext (ctx ).Errorf ("Payment successful send wechat mini subscription message failed retryNum : %d , err:%v, msg : %+v " , retryNum , err , msg )
118
115
return
119
116
}
120
117
retryNum ++
0 commit comments