@@ -0,0 +1,72 @@
|
||||
package daichongser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"91porn-server/common/daichong"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/common/stderr"
|
||||
"91porn-server/models/commod"
|
||||
"91porn-server/models/v/rchgordmod"
|
||||
"91porn-server/web/webg"
|
||||
)
|
||||
|
||||
const (
|
||||
rate_yinse_coin = 10 //金额转换成金币的单位 1元=10音色币
|
||||
rate_yuan_feng = 100 //将元转换为分
|
||||
retries = 7 //通知7次
|
||||
)
|
||||
|
||||
var interval = []int64{0, 60, 5 * 60, 10 * 60, 30 * 60, 60 * 60, 2 * 60 * 60} //通知时间间隔
|
||||
|
||||
// 上分通知 将订单的处理结果通知给代充平台
|
||||
func OrderCallBack(ctx context.Context, req daichong.OrderCallSign) (commod.Resp, stderr.Code) {
|
||||
sign, err := daichong.Convert2Sign(req, webg.Conf.DaiChong.AppSecret)
|
||||
if err != nil {
|
||||
log.ErrorX(ctx, "create sign data wrong", log.Any("warn", err))
|
||||
return commod.Resp{}, stderr.Failure
|
||||
}
|
||||
orderReq := daichong.CommonReq{
|
||||
AppId: webg.Conf.DaiChong.AppID,
|
||||
Data: sign,
|
||||
}
|
||||
resp, err := daichong.OrderCallBack(ctx, orderReq, webg.Conf.DaiChong.Domain)
|
||||
if err != nil {
|
||||
log.ErrorX(ctx, "GetOrderInfo send http wrong", log.Any("warn", err))
|
||||
return resp, stderr.Failure
|
||||
}
|
||||
return resp, resp.Code
|
||||
}
|
||||
|
||||
// 通知第三方回调的结果 按照时间间隔通知
|
||||
func NotifyThirdOrderCallBack(ctx context.Context, oid string, callBackTime int64, orderStatus int) {
|
||||
var cnt = 0
|
||||
selector := rchgordmod.ReplaceEditSelector{}
|
||||
for cnt < retries {
|
||||
order, _ := rchgordmod.FindRechargeOrderByThirdOrderId(oid)
|
||||
if order.NotifyStatus == rchgordmod.Notify_SUCCESS {
|
||||
return
|
||||
}
|
||||
time.Sleep(time.Duration(interval[cnt]) * time.Second)
|
||||
resp, code := OrderCallBack(ctx, daichong.OrderCallSign{
|
||||
OrderId: oid,
|
||||
Time: callBackTime,
|
||||
Status: orderStatus,
|
||||
})
|
||||
if code == stderr.Success {
|
||||
notifySuccess := rchgordmod.Notify_SUCCESS
|
||||
selector.NotifyStatus = ¬ifySuccess
|
||||
_ = rchgordmod.UpdateBaseOnOidAndStatus(nil, oid, order.Status, selector)
|
||||
log.Info("daichong order call back send http request successfully", log.Any("msg", resp.Msg), log.Any("orderstatus", orderStatus),
|
||||
log.Any("orderId", oid),
|
||||
log.Any("time", time.Now().Format(time.RFC3339)))
|
||||
return
|
||||
}
|
||||
notifyFailure := rchgordmod.Notify_FAILURE
|
||||
selector.NotifyStatus = ¬ifyFailure
|
||||
_ = rchgordmod.UpdateBaseOnOidAndStatus(nil, oid, order.Status, selector)
|
||||
log.Warn("daichong order call back send http request failed", log.Any("responseCode", code), log.Any("msg", resp.Msg))
|
||||
cnt++
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user