2024-11-05 08:32:10 +08:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strconv"
|
|
|
|
"yuleduiPay/repo"
|
|
|
|
"yuleduiPay/service/po"
|
|
|
|
"yuleduiPay/service/vo"
|
|
|
|
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
|
|
"github.com/gogf/gf/v2/net/ghttp"
|
2024-11-05 09:49:02 +08:00
|
|
|
"github.com/gogf/gf/v2/os/gtime"
|
2024-11-05 08:32:10 +08:00
|
|
|
"github.com/gogf/gf/v2/util/guid"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Pay struct {
|
|
|
|
payOrderRepo repo.PayOrder
|
2024-11-05 09:49:02 +08:00
|
|
|
shopRepo repo.Shop
|
2024-11-05 08:32:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Pay) PayQrCode(r *ghttp.Request) {
|
|
|
|
req := vo.PayQrCodeReq{}
|
|
|
|
err := r.Parse(&req)
|
|
|
|
if err != nil {
|
2024-11-05 09:49:02 +08:00
|
|
|
r.SetError(err)
|
2024-11-05 08:32:10 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
g.Log().Line().Printf(nil, "%+v", req)
|
|
|
|
//获取订单信息
|
2024-11-05 09:49:02 +08:00
|
|
|
shop, err := t.shopRepo.GetShopById(req.ShopId)
|
|
|
|
if err != nil {
|
|
|
|
r.SetError(err)
|
|
|
|
return
|
|
|
|
}
|
2024-11-05 08:32:10 +08:00
|
|
|
//创建订单记录
|
|
|
|
payOrder := po.PayOrder{}
|
|
|
|
payOrder.OrderId = guid.S()
|
|
|
|
payOrder.Price, err = strconv.ParseFloat(req.Price, 64)
|
|
|
|
if err != nil {
|
|
|
|
r.SetError(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
payOrder.Amount, err = strconv.ParseFloat(req.Amount, 64)
|
|
|
|
if err != nil {
|
|
|
|
r.SetError(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
payOrder.Bean, err = strconv.ParseFloat(req.Bean, 64)
|
|
|
|
if err != nil {
|
|
|
|
r.SetError(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
payOrder.OpenId = req.OpenId
|
|
|
|
payOrder.Mobile = req.Mobile
|
|
|
|
payOrder.ShopId = req.ShopId
|
2024-11-05 09:49:02 +08:00
|
|
|
payOrder.Created = gtime.Now()
|
2024-11-05 08:32:10 +08:00
|
|
|
payOrder.Updated = payOrder.Created
|
|
|
|
|
|
|
|
err = t.payOrderRepo.CreatePayOrder(&payOrder)
|
|
|
|
if err != nil {
|
|
|
|
r.SetError(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
//调用银盛的微信小程序接口(银盛接口)
|
|
|
|
mMap := g.Map{}
|
|
|
|
mMap["orderId"] = payOrder.OpenId //订单编号
|
|
|
|
mMap["shopdate"] = payOrder.Created.Format("20060102") //商户系统的交易发生日期格式
|
|
|
|
mMap["subject"] = "余乐兑小程序订单" //订单备注
|
|
|
|
mMap["total_amount"] = payOrder.Amount //该笔订单的资金总额????????
|
|
|
|
mMap["currency"] = "CNY" //默认人民币 //订单备注
|
2024-11-05 09:49:02 +08:00
|
|
|
mMap["seller_id"] = shop.AccountNumber //商户ID
|
|
|
|
mMap["seller_name"] = shop.ShopName //店铺名称
|
2024-11-05 08:32:10 +08:00
|
|
|
mMap["timeout_express"] = "1h" //设置未付款交易的超时时间,一个小时
|
|
|
|
mMap["sub_openid"] = payOrder.OpenId //微信OpenId
|
|
|
|
mMap["is_minipg"] = "1" //微信小程序支付:1
|
2024-11-05 09:49:02 +08:00
|
|
|
appId, err := g.Cfg().Get(nil, "weixin.appId")
|
2024-11-05 08:32:10 +08:00
|
|
|
if err != nil {
|
|
|
|
r.SetError(err)
|
|
|
|
return
|
|
|
|
}
|
2024-11-05 09:49:02 +08:00
|
|
|
mMap["appid"] = appId
|
2024-11-05 08:32:10 +08:00
|
|
|
|
|
|
|
err = errors.New("cuowu!!!!!")
|
|
|
|
r.SetError(err)
|
|
|
|
return
|
|
|
|
/*
|
|
|
|
resp := vo.PayQrCodeResp{}
|
|
|
|
resp.Code = 0
|
|
|
|
resp.Message = "success"
|
|
|
|
r.Response.WriteJson(resp)
|
|
|
|
*/
|
|
|
|
}
|