yuleduiPay/service/ysepayservice.go

71 lines
1.6 KiB
Go
Raw Normal View History

2024-11-05 17:34:58 +08:00
package service
import (
2024-11-06 15:15:45 +08:00
"strconv"
2024-11-05 17:34:58 +08:00
"time"
2024-11-06 15:15:45 +08:00
"yuleduiPay/common"
2024-11-05 17:34:58 +08:00
"yuleduiPay/repo"
"yuleduiPay/service/vo"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
2024-11-06 15:15:45 +08:00
"github.com/gogf/gf/v2/util/guid"
2024-11-05 17:34:58 +08:00
)
type YsePay struct {
payOrderRepo repo.PayOrder
shopRepo repo.Shop
}
// 银盛 异步通知余乐兑
2024-11-08 15:19:11 +08:00
func (t *YsePay) NotifyPay(r *ghttp.Request) {
2024-11-06 15:15:45 +08:00
g.Log().Line().Print(nil, r.Request)
2024-11-05 17:34:58 +08:00
req := vo.NotifyPayReq{}
err := r.Parse(&req)
if err != nil {
r.SetError(err)
return
}
2024-11-06 15:15:45 +08:00
payOrder, err := t.payOrderRepo.GetPayOrderByOrderId(req.OutTradeNo) //获取订单
if err != nil {
r.SetError(err)
return
}
2024-11-05 17:34:58 +08:00
updates := g.Map{"ysePayStatus": req.TradeStatus, "updated": time.Now()}
err = t.payOrderRepo.UpdatePayOrderByOrderId(updates, req.OutTradeNo)
if err != nil {
r.SetError(err)
return
}
2024-11-06 15:15:45 +08:00
orderTime, err := time.Parse(common.Layout, req.NotifyTime)
if err != nil {
r.SetError(err)
return
}
topic := g.Cfg().MustGet(nil, "MQTT.topic")
2024-11-05 17:34:58 +08:00
//将支付结果写入MQTT中
2024-11-06 15:15:45 +08:00
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)
}
2024-11-05 17:34:58 +08:00
return
2024-11-06 15:15:45 +08:00
2024-11-05 17:34:58 +08:00
}