71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package service
|
|
|
|
import (
|
|
"strconv"
|
|
"time"
|
|
"yuleduiPay/common"
|
|
"yuleduiPay/repo"
|
|
"yuleduiPay/service/vo"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/net/ghttp"
|
|
"github.com/gogf/gf/v2/util/guid"
|
|
)
|
|
|
|
type YsePay struct {
|
|
payOrderRepo repo.PayOrder
|
|
shopRepo repo.Shop
|
|
}
|
|
|
|
// 银盛 异步通知余乐兑
|
|
func (t *YsePay) NotifyPay(r *ghttp.Request) {
|
|
g.Log().Line().Print(nil, r.Request)
|
|
req := vo.NotifyPayReq{}
|
|
err := r.Parse(&req)
|
|
if err != nil {
|
|
r.SetError(err)
|
|
return
|
|
}
|
|
|
|
payOrder, err := t.payOrderRepo.GetPayOrderByOrderId(req.OutTradeNo) //获取订单
|
|
if err != nil {
|
|
r.SetError(err)
|
|
return
|
|
}
|
|
|
|
updates := g.Map{"ysePayStatus": req.TradeStatus, "updated": time.Now()}
|
|
err = t.payOrderRepo.UpdatePayOrderByOrderId(updates, req.OutTradeNo)
|
|
if err != nil {
|
|
r.SetError(err)
|
|
return
|
|
}
|
|
orderTime, err := time.Parse(common.Layout, req.NotifyTime)
|
|
if err != nil {
|
|
r.SetError(err)
|
|
return
|
|
}
|
|
topic := g.Cfg().MustGet(nil, "MQTT.topic")
|
|
|
|
//将支付结果写入MQTT中
|
|
orderMsg := vo.MQTTOrder{}
|
|
orderMsg.Topic = topic.String()
|
|
orderMsg.MsgId = guid.S()
|
|
orderMsg.OrderId = payOrder.OrderId
|
|
|
|
orderMsg.OrderEndTime = orderTime.Unix()
|
|
orderMsg.Price = strconv.FormatFloat(payOrder.Price, 'f', -1, 64)
|
|
orderMsg.Amount = strconv.FormatFloat(payOrder.Amount, 'f', -1, 64)
|
|
orderMsg.Bean = strconv.FormatFloat(payOrder.Bean, 'f', -1, 64)
|
|
orderMsg.ShopId = payOrder.ShopId
|
|
orderMsg.OpenId = payOrder.OpenId
|
|
orderMsg.Mobile = payOrder.Mobile
|
|
orderMsg.SendTime = time.Now().Unix()
|
|
|
|
err = MQTTService.Publish(&orderMsg)
|
|
if err != nil {
|
|
r.SetError(err)
|
|
}
|
|
return
|
|
|
|
}
|