From 3e7cfacbbb5668853e254c6d27e534b2afeeb6f8 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Wed, 3 Jan 2024 14:02:14 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98=20?= =?UTF-8?q?=E5=8C=BA=E5=88=86=E6=94=B6=E6=AC=BE=E5=85=AC=E5=8F=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../svc_central_kitchen_for_school_order.go | 26 +++++---- app/customer/svc/svc_pay.go | 12 ++++- app/db/db_company_with_wxpay_info.go | 54 +++++++++++++++++++ 3 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 app/db/db_company_with_wxpay_info.go diff --git a/app/admin/svc/order/svc_central_kitchen_for_school_order.go b/app/admin/svc/order/svc_central_kitchen_for_school_order.go index a60119f..b2adc0b 100644 --- a/app/admin/svc/order/svc_central_kitchen_for_school_order.go +++ b/app/admin/svc/order/svc_central_kitchen_for_school_order.go @@ -163,8 +163,7 @@ func CentralKitchenForSchoolOrderRefundList(req md.CentralKitchenForSchoolOrderR 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, - enum.WxMchId, enum.WxJsapiRefundPayNotifyUrl) + sysCfg := sysCfgDb.SysCfgFindWithDb(enum.JsapiPayAppAutToken, enum.OpenAlipayAppid, enum.OpenAlipayAppPrivateKey, enum.OpenAlipayPublicKey, enum.WxJsapiRefundPayNotifyUrl) session := db.Db.NewSession() defer session.Close() @@ -184,10 +183,14 @@ func CentralKitchenForSchoolOrderRefundAudit(c *gin.Context, req md.CentralKitch OutRequestNo string `json:"out_request_no"` Amount float64 `json:"amount"` Total string `json:"total"` + WxMchId string `json:"wx_mch_id"` }{} outRequestNoSuffix := "_" + utils.Int64ToStr(time.Now().Unix()) + companyWithWxpayInfoDb := db.CompanyWithWxpayInfoDb{} + companyWithWxpayInfoDb.Set() + for _, v := range req.Ids { //1、更新状态 if req.State == 1 { @@ -227,15 +230,25 @@ func CentralKitchenForSchoolOrderRefundAudit(c *gin.Context, req md.CentralKitch } if ord.PayWay == enum2.PayWayForWx { + var wxMchId = dealReturnOrdMapForWx[returnDay.OutTradeNo].WxMchId + if wxMchId == "" { + wxMchId, err4 = companyWithWxpayInfoDb.GetCompanyWithWxpayInfoByEnterprise(ord.EnterpriseId) + if err4 != nil { + _ = session.Rollback() + return err4 + } + } dealReturnOrdMapForWx[returnDay.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 - }{OutRequestNo: outRequestNo, Amount: dealReturnOrdMapForWx[returnDay.OutTradeNo].Amount + utils.StrToFloat64(returnDay.Amount), Total: ord.TotalPrice}) + WxMchId string + }{OutRequestNo: outRequestNo, Amount: dealReturnOrdMapForWx[returnDay.OutTradeNo].Amount + utils.StrToFloat64(returnDay.Amount), Total: ord.TotalPrice, WxMchId: wxMchId}) } returnDay.OutRequestNo = outRequestNo @@ -265,11 +278,6 @@ func CentralKitchenForSchoolOrderRefundAudit(c *gin.Context, req md.CentralKitch return } } - //else { - // returnDay.State = enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject - // userWithDay.State = enum.CentralKitchenForSchoolUserWithDayStateForWait - //} - } //调用支付宝进行退款 @@ -308,7 +316,7 @@ func CentralKitchenForSchoolOrderRefundAudit(c *gin.Context, req md.CentralKitch for k, v := range dealReturnOrdMapForWx { resp, _, err6 := wxSvc.Create(c, refunddomestic.CreateRequest{ - SubMchid: core.String(sysCfg[enum.WxMchId]), + SubMchid: core.String(v.WxMchId), OutTradeNo: core.String(k), OutRefundNo: core.String(v.OutRequestNo), Reason: core.String("央厨订餐退款"), diff --git a/app/customer/svc/svc_pay.go b/app/customer/svc/svc_pay.go index 48fa19f..c741902 100644 --- a/app/customer/svc/svc_pay.go +++ b/app/customer/svc/svc_pay.go @@ -204,14 +204,22 @@ func BuyPackageForWx(c *gin.Context, req md.BuyPackageReq) (outTradeNo, total st return } wxSvc := jsapi.JsapiApiService{Client: client} - sysCfg := sysCfgDb.SysCfgFindWithDb(enum2.WxAppletAppId, enum2.WxSpAppId, enum2.WxSpMchId, enum2.WxAppletAppId, enum2.WxMchId, enum2.WxJsapiPayNotifyUrl) + + companyWithWxpayInfoDb := db.CompanyWithWxpayInfoDb{} + companyWithWxpayInfoDb.Set() + wxMchId, err := companyWithWxpayInfoDb.GetCompanyWithWxpayInfoByEnterprise(req.EnterpriseId) + if err != nil { + return "", "", nil, err + } + + sysCfg := sysCfgDb.SysCfgFindWithDb(enum2.WxAppletAppId, enum2.WxSpAppId, enum2.WxSpMchId, enum2.WxAppletAppId, enum2.WxJsapiPayNotifyUrl) fmt.Println(int64(math.Round(totalPrice * 100))) result, _, err := wxSvc.Prepay(c, jsapi.PrepayRequest{ SpAppid: core.String(sysCfg[enum2.WxSpAppId]), SpMchid: core.String(sysCfg[enum2.WxSpMchId]), SubAppid: core.String(sysCfg[enum2.WxAppletAppId]), - SubMchid: core.String(sysCfg[enum2.WxMchId]), + SubMchid: core.String(wxMchId), Description: core.String("购买食堂套餐"), OutTradeNo: core.String(outTradeNo), TimeExpire: core.Time(time.Now().Add(30 * time.Minute)), diff --git a/app/db/db_company_with_wxpay_info.go b/app/db/db_company_with_wxpay_info.go new file mode 100644 index 0000000..c239e85 --- /dev/null +++ b/app/db/db_company_with_wxpay_info.go @@ -0,0 +1,54 @@ +package db + +import ( + "applet/app/db/model" + "applet/app/utils/logx" + "errors" + "xorm.io/xorm" +) + +type CompanyWithWxpayInfoDb struct { + Db *xorm.Engine `json:"db"` +} + +func (companyWithWxpayInfoDb *CompanyWithWxpayInfoDb) Set() { // set方法 + companyWithWxpayInfoDb.Db = Db +} + +func (companyWithWxpayInfoDb *CompanyWithWxpayInfoDb) GetCompanyWithWxpayInfo(companyId int) (m *model.CompanyWithWxpayInfo, err error) { + m = new(model.CompanyWithWxpayInfo) + has, err := companyWithWxpayInfoDb.Db.Where("company_id =?", companyId).Get(m) + if err != nil { + return nil, logx.Error(err) + } + if has == false { + return nil, nil + } + return m, nil +} + +type EnterpriseWithCompanyWithWxpayInfo struct { + model.Enterprise `xorm:"extends"` + model.Company `xorm:"extends"` + model.CompanyWithWxpayInfo `xorm:"extends"` +} + +func (EnterpriseWithCompanyWithWxpayInfo) TableName() string { + return "enterprise" +} + +func (companyWithWxpayInfoDb *CompanyWithWxpayInfoDb) GetCompanyWithWxpayInfoByEnterprise(enterpriseId int) (wxMchId string, err error) { + var m *EnterpriseWithCompanyWithWxpayInfo + get, err := companyWithWxpayInfoDb.Db.Where("enterprise.id = ?", enterpriseId). + Join("LEFT", "company", "enterprise.company_id = company.id"). + Join("LEFT", "company_with_wxpay_info", "company.id = company_with_wxpay_info.company_id"). + Get(&m) + if err != nil { + return "", err + } + if !get { + return "", errors.New("未查询到相应记录") + } + wxMchId = m.CompanyWithWxpayInfo.WxMchId + return +}