|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package test
-
- import (
- "applet/app/db"
- "applet/app/e"
- enum2 "applet/app/enum"
- svc3 "applet/app/svc"
- "applet/app/utils"
- "github.com/gin-gonic/gin"
- "github.com/wechatpay-apiv3/wechatpay-go/core"
- "github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
- "math"
- "time"
- )
-
- func WxRefundsTest(c *gin.Context) {
- outTradeNo := c.DefaultQuery("out_trade_no", "")
- refund := c.DefaultQuery("refund", "")
- centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{}
- centralKitchenForSchoolPackageOrd.Set(outTradeNo)
- ord, err := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrd()
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if ord == nil {
- e.OutErr(c, e.ERR_NO_DATA, "未查询到对应订单记录")
- return
- }
- sysCfgDb := db.SysCfgDb{}
- sysCfgDb.Set()
- sysCfg := sysCfgDb.SysCfgFindWithDb(enum2.WxMchId, enum2.WxJsapiRefundPayNotifyUrl)
- client, err := svc3.NewWxPayClient(c)
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
- wxSvc := refunddomestic.RefundsApiService{Client: client}
- outRequestNoSuffix := "_" + utils.Int64ToStr(time.Now().Unix())
- outRequestNo := "r_" + ord.OutTradeNo + outRequestNoSuffix
-
- resp, result, err := wxSvc.Create(c,
- refunddomestic.CreateRequest{
- SubMchid: core.String(sysCfg[enum2.WxMchId]),
- OutTradeNo: core.String(ord.OutTradeNo),
- OutRefundNo: core.String(outRequestNo),
- Reason: core.String("央厨订餐退款"),
- NotifyUrl: core.String(sysCfg[enum2.WxJsapiRefundPayNotifyUrl]),
- Amount: &refunddomestic.AmountReq{
- Currency: core.String("CNY"),
- Refund: core.Int64(utils.StrToInt64(refund)),
- Total: core.Int64(int64(math.Round(utils.StrToFloat64(ord.TotalPrice) * 100))),
- },
- },
- )
- if err != nil {
- // 处理错误
- println("call Create err:%s", err)
- } else {
- // 处理返回结果
- println("status=%d resp=%s", result.Response.StatusCode, resp)
- }
-
- e.OutSuc(c, map[string]interface{}{
- "resp": resp,
- "result": result,
- }, nil)
- return
- }
|