智慧食堂
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

hdl_demo.go 6.2 KiB

il y a 1 an
il y a 9 mois
il y a 1 an
il y a 1 an
il y a 9 mois
il y a 1 an
il y a 1 an
il y a 8 mois
il y a 1 an
il y a 1 an
il y a 8 mois
il y a 1 an
il y a 1 an
il y a 8 mois
il y a 9 mois
il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
il y a 10 mois
il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
il y a 9 mois
il y a 8 mois
il y a 9 mois
il y a 8 mois
il y a 9 mois
il y a 8 mois
il y a 9 mois
il y a 8 mois
il y a 9 mois
il y a 8 mois
il y a 9 mois
il y a 1 an
il y a 1 an
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 m []model.CentralKitchenForSchoolUserWithDay
  24. eg := db.Db
  25. if err1 := eg.Where("state = 3").Asc("id").Find(&m); err1 != nil {
  26. e.OutErr(c, e.ERR, err1.Error())
  27. return
  28. }
  29. now := time.Now()
  30. var records []int
  31. for _, v := range m {
  32. mm := new(model.CentralKitchenForSchoolUserRefundDay)
  33. has, err := db.Db.Where("records_id =? and state = 1", v.Id).Get(mm)
  34. if err != nil {
  35. fmt.Println(err)
  36. return
  37. }
  38. if has == false {
  39. centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{}
  40. centralKitchenForSchoolUserRefundDayDb.Set(0)
  41. _, err = centralKitchenForSchoolUserRefundDayDb.CentralKitchenForSchoolUserRefundDayInsert(&model.CentralKitchenForSchoolUserRefundDay{
  42. OutTradeNo: v.OrdNo,
  43. OutRequestNo: "",
  44. Uid: v.Uid,
  45. IdentityId: v.IdentityId,
  46. RecordsId: v.Id,
  47. State: enum.CentralKitchenForSchoolUserRefundDayStateForAuditing,
  48. Amount: v.Amount,
  49. Memo: "fill",
  50. CreateAt: now.Format("2006-01-02 15:04:05"),
  51. UpdateAt: now.Format("2006-01-02 15:04:05"),
  52. })
  53. records = append(records, v.Id)
  54. }
  55. }
  56. e.OutSuc(c, records, nil)
  57. return
  58. var req md.CentralKitchenForSchoolOrderRefundAuditReq
  59. err := c.ShouldBindJSON(&req)
  60. if err != nil {
  61. err = validate.HandleValidateErr(err)
  62. err1 := err.(e.E)
  63. e.OutErr(c, err1.Code, err1.Error())
  64. return
  65. }
  66. err1 := svc.CentralKitchenForSchoolOrderRefundAudit(c, req)
  67. if err1 != nil {
  68. fmt.Println(err1.Error())
  69. e.OutErr(c, e.ERR, err1.Error())
  70. return
  71. }
  72. e.OutSuc(c, "success", nil)
  73. return
  74. sysCfgDb := db.SysCfgDb{}
  75. sysCfgDb.Set()
  76. sysCfg := sysCfgDb.SysCfgFindWithDb(enum.OpenAlipayAppid, enum.OpenAlipayAppPrivateKey, enum.OpenAlipayPublicKey)
  77. //调用支付宝进行退款
  78. err6, _ := svc2.CurlAlipayTradeRefund(md2.CurlAlipayTradeRefundReq{
  79. Config: struct {
  80. PayAliAppId string `json:"pay_ali_app_id" label:"支付宝开放平台-第三方应用-appid"`
  81. PayAliPrivateKey string `json:"pay_ali_private_key" label:"支付宝开放平台-第三方应用-接口加签-应用私钥"`
  82. PayAliPublicKey string `json:"pay_ali_public_key" label:"支付宝开放平台-第三方应用-接口加签-支付宝公钥"`
  83. }{
  84. PayAliAppId: sysCfg[enum.OpenAlipayAppid],
  85. PayAliPrivateKey: sysCfg[enum.OpenAlipayAppPrivateKey],
  86. PayAliPublicKey: sysCfg[enum.OpenAlipayPublicKey],
  87. },
  88. OutTradeNo: "800169659125681442",
  89. RefundAmount: "180.00",
  90. RefundReason: "央厨订餐退款",
  91. OutRequestNo: "r_800169659125681442_1705546121",
  92. AppAuthToken: "202308BB8ef30019cd8d4a40a3853192c397dX35",
  93. })
  94. if err6 != nil {
  95. fmt.Println(err6.Error())
  96. }
  97. return
  98. qrcodeWithBatchRecordsDb := db.AdminDb{}
  99. qrcodeWithBatchRecordsDb.Set()
  100. data, _, err := qrcodeWithBatchRecordsDb.GetAdminRolePermission(1001)
  101. if err != nil {
  102. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  103. return
  104. }
  105. e.OutSuc(c, data, nil)
  106. go GoOnExecuting()
  107. return
  108. }
  109. func DemoV1(c *gin.Context) {
  110. var outRequestNo = c.Query("out_request_no")
  111. var outTradeNo = c.Query("out_no")
  112. centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{}
  113. centralKitchenForSchoolUserRefundDayDb.Set(0)
  114. var m []model.CentralKitchenForSchoolUserRefundDay
  115. if err := centralKitchenForSchoolUserRefundDayDb.Db.Where("out_request_no =?", outRequestNo).Desc("id").Find(&m); err != nil {
  116. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  117. return
  118. }
  119. centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{}
  120. centralKitchenForSchoolPackageOrd.Set(outTradeNo)
  121. ord, _ := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrd()
  122. var dealReturnOrdMapForWx = map[string]struct {
  123. OutRequestNo string `json:"out_request_no"`
  124. Amount float64 `json:"amount"`
  125. Total string `json:"total"`
  126. WxMchId string `json:"wx_mch_id"`
  127. }{}
  128. companyWithWxpayInfoDb := db.CompanyWithWxpayInfoDb{}
  129. companyWithWxpayInfoDb.Set()
  130. wxMchId, _ := companyWithWxpayInfoDb.GetCompanyWithWxpayInfoByEnterprise(ord.EnterpriseId)
  131. for _, v := range m {
  132. dealReturnOrdMapForWx[ord.OutTradeNo] = struct {
  133. OutRequestNo string `json:"out_request_no"`
  134. Amount float64 `json:"amount"`
  135. Total string `json:"total"`
  136. WxMchId string `json:"wx_mch_id"`
  137. }(struct {
  138. OutRequestNo string
  139. Amount float64
  140. Total string
  141. WxMchId string
  142. }{OutRequestNo: outRequestNo, Amount: dealReturnOrdMapForWx[v.OutTradeNo].Amount + utils.StrToFloat64(v.Amount), Total: ord.TotalPrice, WxMchId: wxMchId})
  143. }
  144. client, err1 := svc3.NewWxPayClient(c) //初始化微信连接
  145. if err1 != nil {
  146. e.OutErr(c, e.ERR, err1.Error())
  147. return
  148. }
  149. sysCfgDb := db.SysCfgDb{}
  150. sysCfgDb.Set()
  151. sysCfg := sysCfgDb.SysCfgFindWithDb(enum.JsapiPayAppAutToken, enum.OpenAlipayAppid, enum.OpenAlipayAppPrivateKey, enum.OpenAlipayPublicKey, enum.WxJsapiRefundPayNotifyUrl)
  152. wxSvc := refunddomestic.RefundsApiService{Client: client}
  153. for k, v := range dealReturnOrdMapForWx {
  154. resp, _, err6 := wxSvc.Create(c,
  155. refunddomestic.CreateRequest{
  156. SubMchid: core.String(v.WxMchId),
  157. OutTradeNo: core.String(k),
  158. OutRefundNo: core.String(v.OutRequestNo),
  159. Reason: core.String("央厨订餐退款"),
  160. NotifyUrl: core.String(sysCfg[enum.WxJsapiRefundPayNotifyUrl]),
  161. Amount: &refunddomestic.AmountReq{
  162. Currency: core.String("CNY"),
  163. Refund: core.Int64(int64(math.Round(v.Amount * 100))),
  164. Total: core.Int64(int64(math.Round(utils.StrToFloat64(v.Total) * 100))),
  165. },
  166. },
  167. )
  168. fmt.Println(">>>>wxRefund<<<<", resp)
  169. if err6 != nil {
  170. fmt.Println(err6)
  171. e.OutErr(c, e.ERR, err6.Error())
  172. return
  173. }
  174. }
  175. e.OutSuc(c, dealReturnOrdMapForWx, nil)
  176. return
  177. }
  178. func GoOnExecuting() {
  179. for i := 0; i < 20; i++ {
  180. time.Sleep(1 * time.Second)
  181. fmt.Println(i)
  182. }
  183. }