智慧食堂
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.

hdl_demo.go 6.6 KiB

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