DengBiao 1 anno fa
parent
commit
6510219155
2 ha cambiato i file con 81 aggiunte e 10 eliminazioni
  1. +1
    -1
      app/admin/hdl/hdl_audit_center.go
  2. +80
    -9
      app/admin/svc/order/svc_central_kitchen_for_school_order.go

+ 1
- 1
app/admin/hdl/hdl_audit_center.go Vedi File

@@ -196,7 +196,7 @@ func CentralKitchenForSchoolOrderRefundAudit(c *gin.Context) {
}

go func() {
err1 := svc2.CentralKitchenForSchoolOrderRefundAudit(req)
err1 := svc2.CentralKitchenForSchoolOrderRefundAudit(c, req)
if err1 != nil {
logx.Error(err1)
println("<<<<CentralKitchenForSchoolOrderRefundAudit>>>>>Error:::", err1.Error())


+ 80
- 9
app/admin/svc/order/svc_central_kitchen_for_school_order.go Vedi File

@@ -3,13 +3,21 @@ package svc
import (
"applet/app/admin/md"
svc "applet/app/admin/svc/enterprise_manage"
enum2 "applet/app/customer/enum"
md2 "applet/app/customer/md"
svc2 "applet/app/customer/svc"
"applet/app/db"
model2 "applet/app/db/model"
"applet/app/e"
"applet/app/enum"
svc3 "applet/app/svc"
"applet/app/utils"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
"math"
"time"
)

@@ -153,10 +161,11 @@ func CentralKitchenForSchoolOrderRefundList(req md.CentralKitchenForSchoolOrderR
return
}

func CentralKitchenForSchoolOrderRefundAudit(req md.CentralKitchenForSchoolOrderRefundAuditReq) (err error) {
func CentralKitchenForSchoolOrderRefundAudit(c *gin.Context, req md.CentralKitchenForSchoolOrderRefundAuditReq) (err error) {
sysCfgDb := db.SysCfgDb{}
sysCfgDb.Set()
sysCfg := sysCfgDb.SysCfgFindWithDb(enum.JsapiPayAppAutToken, enum.OpenAlipayAppid, enum.OpenAlipayAppPrivateKey, enum.OpenAlipayPublicKey)
sysCfg := sysCfgDb.SysCfgFindWithDb(enum.JsapiPayAppAutToken, enum.OpenAlipayAppid, enum.OpenAlipayAppPrivateKey, enum.OpenAlipayPublicKey,
enum.WxMchId, enum.WxJsapiRefundPayNotifyUrl)

session := db.Db.NewSession()
defer session.Close()
@@ -166,11 +175,18 @@ func CentralKitchenForSchoolOrderRefundAudit(req md.CentralKitchenForSchoolOrder
centralKitchenForSchoolUserRefundDayDb.Set(0)
centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{}
centralKitchenForSchoolUserWithDayDb.Set(0)
centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{}
var dealReturnOrdMap = map[string]struct {
OutRequestNo string `json:"out_request_no"`
Amount float64 `json:"amount"`
}{}

var dealReturnOrdMapForWx = map[string]struct {
OutRequestNo string `json:"out_request_no"`
Amount float64 `json:"amount"`
Total string `json:"total"`
}{}

outRequestNoSuffix := "_" + utils.Int64ToStr(time.Now().Unix())

for _, v := range req.Ids {
@@ -190,13 +206,38 @@ func CentralKitchenForSchoolOrderRefundAudit(req md.CentralKitchenForSchoolOrder

userWithDay.State = enum.CentralKitchenForSchoolUserWithDayStateForCancel
outRequestNo := "r_" + returnDay.OutTradeNo + outRequestNoSuffix
dealReturnOrdMap[returnDay.OutTradeNo] = struct {
OutRequestNo string `json:"out_request_no"`
Amount float64 `json:"amount"`
}(struct {
OutRequestNo string
Amount float64
}{OutRequestNo: outRequestNo, Amount: dealReturnOrdMap[returnDay.OutTradeNo].Amount + utils.StrToFloat64(returnDay.Amount)})
centralKitchenForSchoolPackageOrd.Set(returnDay.OutTradeNo)
ord, err4 := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrd()
if err4 != nil {
_ = session.Rollback()
return err4
}
if ord == nil {
_ = session.Rollback()
return errors.New("未查询到对应订单记录")
}

if ord.PayWay == enum2.PayWayForAli {
dealReturnOrdMap[returnDay.OutTradeNo] = struct {
OutRequestNo string `json:"out_request_no"`
Amount float64 `json:"amount"`
}(struct {
OutRequestNo string
Amount float64
}{OutRequestNo: outRequestNo, Amount: dealReturnOrdMap[returnDay.OutTradeNo].Amount + utils.StrToFloat64(returnDay.Amount)})
}

if ord.PayWay == enum2.PayWayForWx {
dealReturnOrdMapForWx[returnDay.OutTradeNo] = struct {
OutRequestNo string `json:"out_request_no"`
Amount float64 `json:"amount"`
Total string `json:"total"`
}(struct {
OutRequestNo string
Amount float64
Total string
}{OutRequestNo: outRequestNo, Amount: dealReturnOrdMap[returnDay.OutTradeNo].Amount + utils.StrToFloat64(returnDay.Amount), Total: ord.TotalPrice})
}

returnDay.OutRequestNo = outRequestNo
returnDay.State = enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete
@@ -264,5 +305,35 @@ func CentralKitchenForSchoolOrderRefundAudit(req md.CentralKitchenForSchoolOrder
time.Sleep(200 * time.Millisecond) //TODO::避免频繁调用
}

client, err := svc3.NewWxPayClient(c)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
wxSvc := refunddomestic.RefundsApiService{Client: client}

for k, v := range dealReturnOrdMapForWx {
resp, _, err6 := wxSvc.Create(c,
refunddomestic.CreateRequest{
SubMchid: core.String(sysCfg[enum.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))),
},
},
)
if err6 != nil {
_ = session.Rollback()
return err6
}
fmt.Println(">>>>wxRefund<<<<", resp.Status)
time.Sleep(20 * time.Millisecond) //TODO::避免频繁调用
}

return session.Commit()
}

Caricamento…
Annulla
Salva