54 lines
921 B
Go
54 lines
921 B
Go
package monitor
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/golang-module/carbon/v2"
|
|
"samba/pkg/log"
|
|
"samba/pkg/task"
|
|
"samba/pkg/xtime"
|
|
"samba/util/model"
|
|
"time"
|
|
)
|
|
|
|
// PayMonitor 支付异常检测
|
|
type PayMonitor struct {
|
|
*Ding
|
|
lastCount int64
|
|
lastTime carbon.Carbon
|
|
}
|
|
|
|
func (p *PayMonitor) Init(t *task.Task) {
|
|
t.Ticker(30 * time.Minute)
|
|
}
|
|
|
|
func (p *PayMonitor) Name() string {
|
|
return "支付异常检测"
|
|
}
|
|
|
|
func (p *PayMonitor) Do(*task.Task) {
|
|
count, err := model.NewPaymentInfoOp().Count()
|
|
if err != nil {
|
|
log.Error(err.Error())
|
|
return
|
|
}
|
|
|
|
if count > p.lastCount {
|
|
// 订单数增加
|
|
p.lastCount = count
|
|
p.lastTime = xtime.Now()
|
|
return
|
|
}
|
|
|
|
// 订单数不变
|
|
dur := p.lastTime.DiffInDuration(xtime.Now())
|
|
if dur < 3*time.Hour {
|
|
return
|
|
}
|
|
|
|
err = p.Ding.SendMessageText(fmt.Sprintf("支付异常!%.2f小时内没有新订单", dur.Hours()))
|
|
if err != nil {
|
|
log.Error(err.Error())
|
|
return
|
|
}
|
|
}
|