智慧食堂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package test
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. enum2 "applet/app/enum"
  6. svc3 "applet/app/svc"
  7. "applet/app/utils"
  8. "github.com/gin-gonic/gin"
  9. "github.com/wechatpay-apiv3/wechatpay-go/core"
  10. "github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
  11. "math"
  12. "time"
  13. )
  14. func WxRefundsTest(c *gin.Context) {
  15. outTradeNo := c.DefaultQuery("out_trade_no", "")
  16. refund := c.DefaultQuery("refund", "")
  17. centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{}
  18. centralKitchenForSchoolPackageOrd.Set(outTradeNo)
  19. ord, err := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrd()
  20. if err != nil {
  21. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  22. return
  23. }
  24. if ord == nil {
  25. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应订单记录")
  26. return
  27. }
  28. sysCfgDb := db.SysCfgDb{}
  29. sysCfgDb.Set()
  30. sysCfg := sysCfgDb.SysCfgFindWithDb(enum2.WxMchId, enum2.WxJsapiRefundPayNotifyUrl)
  31. client, err := svc3.NewWxPayClient(c)
  32. if err != nil {
  33. e.OutErr(c, e.ERR, err.Error())
  34. return
  35. }
  36. wxSvc := refunddomestic.RefundsApiService{Client: client}
  37. outRequestNoSuffix := "_" + utils.Int64ToStr(time.Now().Unix())
  38. outRequestNo := "r_" + ord.OutTradeNo + outRequestNoSuffix
  39. resp, result, err := wxSvc.Create(c,
  40. refunddomestic.CreateRequest{
  41. SubMchid: core.String(sysCfg[enum2.WxMchId]),
  42. OutTradeNo: core.String(ord.OutTradeNo),
  43. OutRefundNo: core.String(outRequestNo),
  44. Reason: core.String("央厨订餐退款"),
  45. NotifyUrl: core.String(sysCfg[enum2.WxJsapiRefundPayNotifyUrl]),
  46. Amount: &refunddomestic.AmountReq{
  47. Currency: core.String("CNY"),
  48. Refund: core.Int64(utils.StrToInt64(refund)),
  49. Total: core.Int64(int64(math.Round(utils.StrToFloat64(ord.TotalPrice) * 100))),
  50. },
  51. },
  52. )
  53. if err != nil {
  54. // 处理错误
  55. println("call Create err:%s", err)
  56. } else {
  57. // 处理返回结果
  58. println("status=%d resp=%s", result.Response.StatusCode, resp)
  59. }
  60. e.OutSuc(c, map[string]interface{}{
  61. "resp": resp,
  62. "result": result,
  63. }, nil)
  64. return
  65. }