智慧食堂
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

158 linhas
5.0 KiB

  1. package hdl
  2. import (
  3. "applet/app/admin/lib/validate"
  4. "applet/app/admin/md"
  5. svc "applet/app/admin/svc/order"
  6. md2 "applet/app/customer/md"
  7. svc2 "applet/app/customer/svc"
  8. "applet/app/db"
  9. "applet/app/db/model"
  10. "applet/app/e"
  11. "applet/app/enum"
  12. svc3 "applet/app/svc"
  13. "applet/app/utils"
  14. "fmt"
  15. "github.com/gin-gonic/gin"
  16. "github.com/wechatpay-apiv3/wechatpay-go/core"
  17. "github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
  18. "math"
  19. "time"
  20. )
  21. // Demo 测试
  22. func Demo(c *gin.Context) {
  23. var req md.CentralKitchenForSchoolOrderRefundAuditReq
  24. err := c.ShouldBindJSON(&req)
  25. if err != nil {
  26. err = validate.HandleValidateErr(err)
  27. err1 := err.(e.E)
  28. e.OutErr(c, err1.Code, err1.Error())
  29. return
  30. }
  31. err1 := svc.CentralKitchenForSchoolOrderRefundAudit(c, req)
  32. if err1 != nil {
  33. fmt.Println(err1.Error())
  34. e.OutErr(c, e.ERR, err1.Error())
  35. return
  36. }
  37. e.OutSuc(c, "success", nil)
  38. return
  39. sysCfgDb := db.SysCfgDb{}
  40. sysCfgDb.Set()
  41. sysCfg := sysCfgDb.SysCfgFindWithDb(enum.OpenAlipayAppid, enum.OpenAlipayAppPrivateKey, enum.OpenAlipayPublicKey)
  42. //调用支付宝进行退款
  43. err6, _ := svc2.CurlAlipayTradeRefund(md2.CurlAlipayTradeRefundReq{
  44. Config: struct {
  45. PayAliAppId string `json:"pay_ali_app_id" label:"支付宝开放平台-第三方应用-appid"`
  46. PayAliPrivateKey string `json:"pay_ali_private_key" label:"支付宝开放平台-第三方应用-接口加签-应用私钥"`
  47. PayAliPublicKey string `json:"pay_ali_public_key" label:"支付宝开放平台-第三方应用-接口加签-支付宝公钥"`
  48. }{
  49. PayAliAppId: sysCfg[enum.OpenAlipayAppid],
  50. PayAliPrivateKey: sysCfg[enum.OpenAlipayAppPrivateKey],
  51. PayAliPublicKey: sysCfg[enum.OpenAlipayPublicKey],
  52. },
  53. OutTradeNo: "800169659125681442",
  54. RefundAmount: "180.00",
  55. RefundReason: "央厨订餐退款",
  56. OutRequestNo: "r_800169659125681442_1705546121",
  57. AppAuthToken: "202308BB8ef30019cd8d4a40a3853192c397dX35",
  58. })
  59. if err6 != nil {
  60. fmt.Println(err6.Error())
  61. }
  62. return
  63. qrcodeWithBatchRecordsDb := db.AdminDb{}
  64. qrcodeWithBatchRecordsDb.Set()
  65. data, _, err := qrcodeWithBatchRecordsDb.GetAdminRolePermission(1001)
  66. if err != nil {
  67. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  68. return
  69. }
  70. e.OutSuc(c, data, nil)
  71. go GoOnExecuting()
  72. return
  73. }
  74. func DemoV1(c *gin.Context) {
  75. var outRequestNo = c.Query("out_request_no")
  76. var outTradeNo = c.Query("out_no")
  77. centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{}
  78. centralKitchenForSchoolUserRefundDayDb.Set(0)
  79. var m []model.CentralKitchenForSchoolUserRefundDay
  80. if err := centralKitchenForSchoolUserRefundDayDb.Db.Where("out_request_no =?", outRequestNo).Desc("id").Find(&m); err != nil {
  81. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  82. return
  83. }
  84. centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{}
  85. centralKitchenForSchoolPackageOrd.Set(outTradeNo)
  86. ord, _ := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrd()
  87. var dealReturnOrdMapForWx = map[string]struct {
  88. OutRequestNo string `json:"out_request_no"`
  89. Amount float64 `json:"amount"`
  90. Total string `json:"total"`
  91. WxMchId string `json:"wx_mch_id"`
  92. }{}
  93. companyWithWxpayInfoDb := db.CompanyWithWxpayInfoDb{}
  94. companyWithWxpayInfoDb.Set()
  95. wxMchId, _ := companyWithWxpayInfoDb.GetCompanyWithWxpayInfoByEnterprise(ord.EnterpriseId)
  96. for _, v := range m {
  97. dealReturnOrdMapForWx[ord.OutTradeNo] = struct {
  98. OutRequestNo string `json:"out_request_no"`
  99. Amount float64 `json:"amount"`
  100. Total string `json:"total"`
  101. WxMchId string `json:"wx_mch_id"`
  102. }(struct {
  103. OutRequestNo string
  104. Amount float64
  105. Total string
  106. WxMchId string
  107. }{OutRequestNo: outRequestNo, Amount: dealReturnOrdMapForWx[v.OutTradeNo].Amount + utils.StrToFloat64(v.Amount), Total: ord.TotalPrice, WxMchId: wxMchId})
  108. }
  109. client, err1 := svc3.NewWxPayClient(c) //初始化微信连接
  110. if err1 != nil {
  111. e.OutErr(c, e.ERR, err1.Error())
  112. return
  113. }
  114. sysCfgDb := db.SysCfgDb{}
  115. sysCfgDb.Set()
  116. sysCfg := sysCfgDb.SysCfgFindWithDb(enum.JsapiPayAppAutToken, enum.OpenAlipayAppid, enum.OpenAlipayAppPrivateKey, enum.OpenAlipayPublicKey, enum.WxJsapiRefundPayNotifyUrl)
  117. wxSvc := refunddomestic.RefundsApiService{Client: client}
  118. for k, v := range dealReturnOrdMapForWx {
  119. resp, _, err6 := wxSvc.Create(c,
  120. refunddomestic.CreateRequest{
  121. SubMchid: core.String(v.WxMchId),
  122. OutTradeNo: core.String(k),
  123. OutRefundNo: core.String(v.OutRequestNo),
  124. Reason: core.String("央厨订餐退款"),
  125. NotifyUrl: core.String(sysCfg[enum.WxJsapiRefundPayNotifyUrl]),
  126. Amount: &refunddomestic.AmountReq{
  127. Currency: core.String("CNY"),
  128. Refund: core.Int64(int64(math.Round(v.Amount * 100))),
  129. Total: core.Int64(int64(math.Round(utils.StrToFloat64(v.Total) * 100))),
  130. },
  131. },
  132. )
  133. fmt.Println(">>>>wxRefund<<<<", resp)
  134. if err6 != nil {
  135. fmt.Println(err6)
  136. e.OutErr(c, e.ERR, err6.Error())
  137. return
  138. }
  139. }
  140. e.OutSuc(c, dealReturnOrdMapForWx, nil)
  141. return
  142. }
  143. func GoOnExecuting() {
  144. for i := 0; i < 20; i++ {
  145. time.Sleep(1 * time.Second)
  146. fmt.Println(i)
  147. }
  148. }