yuleduiPay/service/pay.go

88 lines
2.3 KiB
Go

package service
import (
"errors"
"strconv"
"time"
"yuleduiPay/repo"
"yuleduiPay/service/po"
"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 Pay struct {
payOrderRepo repo.PayOrder
}
func (t *Pay) PayQrCode(r *ghttp.Request) {
req := vo.PayQrCodeReq{}
err := r.Parse(&req)
if err != nil {
r.Response.Writeln(err)
return
}
g.Log().Line().Printf(nil, "%+v", req)
//获取订单信息
//创建订单记录
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
payOrder.Created = time.Now()
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" //默认人民币 //订单备注
mMap["seller_id"] = 0 //????
mMap["seller_name"] = "商户名称" //???
mMap["timeout_express"] = "1h" //设置未付款交易的超时时间,一个小时
mMap["sub_openid"] = payOrder.OpenId //微信OpenId
mMap["is_minipg"] = "1" //微信小程序支付:1
appId,err = g.Cfg().Get(ctx, "weixin.appId")
if err != nil {
r.SetError(err)
return
}
mMap["appid"] =
err = errors.New("cuowu!!!!!")
r.SetError(err)
return
/*
resp := vo.PayQrCodeResp{}
resp.Code = 0
resp.Message = "success"
r.Response.WriteJson(resp)
*/
}