|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- package hdl
-
- import (
- "applet/app/admin/lib/validate"
- "applet/app/admin/md"
- svc "applet/app/admin/svc/order"
- md2 "applet/app/customer/md"
- svc2 "applet/app/customer/svc"
- "applet/app/db"
- "applet/app/db/model"
- "applet/app/e"
- "applet/app/enum"
- svc3 "applet/app/svc"
- "applet/app/utils"
- "fmt"
- "github.com/gin-gonic/gin"
- "github.com/wechatpay-apiv3/wechatpay-go/core"
- "github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
- "math"
- "time"
- )
-
- // Demo 测试
- func Demo(c *gin.Context) {
- var req md.CentralKitchenForSchoolOrderRefundAuditReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- err1 := svc.CentralKitchenForSchoolOrderRefundAudit(c, req)
- if err1 != nil {
- fmt.Println(err1.Error())
- e.OutErr(c, e.ERR, err1.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- return
- sysCfgDb := db.SysCfgDb{}
- sysCfgDb.Set()
- sysCfg := sysCfgDb.SysCfgFindWithDb(enum.OpenAlipayAppid, enum.OpenAlipayAppPrivateKey, enum.OpenAlipayPublicKey)
-
- //调用支付宝进行退款
- err6, _ := svc2.CurlAlipayTradeRefund(md2.CurlAlipayTradeRefundReq{
- Config: struct {
- PayAliAppId string `json:"pay_ali_app_id" label:"支付宝开放平台-第三方应用-appid"`
- PayAliPrivateKey string `json:"pay_ali_private_key" label:"支付宝开放平台-第三方应用-接口加签-应用私钥"`
- PayAliPublicKey string `json:"pay_ali_public_key" label:"支付宝开放平台-第三方应用-接口加签-支付宝公钥"`
- }{
- PayAliAppId: sysCfg[enum.OpenAlipayAppid],
- PayAliPrivateKey: sysCfg[enum.OpenAlipayAppPrivateKey],
- PayAliPublicKey: sysCfg[enum.OpenAlipayPublicKey],
- },
- OutTradeNo: "800169659125681442",
- RefundAmount: "180.00",
- RefundReason: "央厨订餐退款",
- OutRequestNo: "r_800169659125681442_1705546121",
- AppAuthToken: "202308BB8ef30019cd8d4a40a3853192c397dX35",
- })
- if err6 != nil {
- fmt.Println(err6.Error())
- }
- return
- qrcodeWithBatchRecordsDb := db.AdminDb{}
- qrcodeWithBatchRecordsDb.Set()
- data, _, err := qrcodeWithBatchRecordsDb.GetAdminRolePermission(1001)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, data, nil)
- go GoOnExecuting()
- return
- }
-
- func DemoV1(c *gin.Context) {
- var outRequestNo = c.Query("out_request_no")
- var outTradeNo = c.Query("out_no")
- centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{}
- centralKitchenForSchoolUserRefundDayDb.Set(0)
- var m []model.CentralKitchenForSchoolUserRefundDay
- if err := centralKitchenForSchoolUserRefundDayDb.Db.Where("out_request_no =?", outRequestNo).Desc("id").Find(&m); err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{}
- centralKitchenForSchoolPackageOrd.Set(outTradeNo)
- ord, _ := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrd()
-
- var dealReturnOrdMapForWx = map[string]struct {
- OutRequestNo string `json:"out_request_no"`
- Amount float64 `json:"amount"`
- Total string `json:"total"`
- WxMchId string `json:"wx_mch_id"`
- }{}
- companyWithWxpayInfoDb := db.CompanyWithWxpayInfoDb{}
- companyWithWxpayInfoDb.Set()
- wxMchId, _ := companyWithWxpayInfoDb.GetCompanyWithWxpayInfoByEnterprise(ord.EnterpriseId)
-
- for _, v := range m {
- dealReturnOrdMapForWx[ord.OutTradeNo] = struct {
- OutRequestNo string `json:"out_request_no"`
- Amount float64 `json:"amount"`
- Total string `json:"total"`
- WxMchId string `json:"wx_mch_id"`
- }(struct {
- OutRequestNo string
- Amount float64
- Total string
- WxMchId string
- }{OutRequestNo: outRequestNo, Amount: dealReturnOrdMapForWx[v.OutTradeNo].Amount + utils.StrToFloat64(v.Amount), Total: ord.TotalPrice, WxMchId: wxMchId})
- }
- client, err1 := svc3.NewWxPayClient(c) //初始化微信连接
- if err1 != nil {
- e.OutErr(c, e.ERR, err1.Error())
- return
- }
-
- sysCfgDb := db.SysCfgDb{}
- sysCfgDb.Set()
- sysCfg := sysCfgDb.SysCfgFindWithDb(enum.JsapiPayAppAutToken, enum.OpenAlipayAppid, enum.OpenAlipayAppPrivateKey, enum.OpenAlipayPublicKey, enum.WxJsapiRefundPayNotifyUrl)
- wxSvc := refunddomestic.RefundsApiService{Client: client}
- for k, v := range dealReturnOrdMapForWx {
- resp, _, err6 := wxSvc.Create(c,
- refunddomestic.CreateRequest{
- SubMchid: core.String(v.WxMchId),
- OutTradeNo: core.String(k),
- OutRefundNo: core.String(v.OutRequestNo),
- Reason: core.String("央厨订餐退款"),
- NotifyUrl: core.String(sysCfg[enum.WxJsapiRefundPayNotifyUrl]),
- Amount: &refunddomestic.AmountReq{
- Currency: core.String("CNY"),
- Refund: core.Int64(int64(math.Round(v.Amount * 100))),
- Total: core.Int64(int64(math.Round(utils.StrToFloat64(v.Total) * 100))),
- },
- },
- )
- fmt.Println(">>>>wxRefund<<<<", resp)
- if err6 != nil {
- fmt.Println(err6)
- e.OutErr(c, e.ERR, err6.Error())
- return
- }
- }
- e.OutSuc(c, dealReturnOrdMapForWx, nil)
- return
- }
-
- func GoOnExecuting() {
- for i := 0; i < 20; i++ {
- time.Sleep(1 * time.Second)
- fmt.Println(i)
- }
- }
|