소스 검색

add 微信支付 区分收款公司

tmp
DengBiao 10 달 전
부모
커밋
3e7cfacbbb
3개의 변경된 파일81개의 추가작업 그리고 11개의 파일을 삭제
  1. +17
    -9
      app/admin/svc/order/svc_central_kitchen_for_school_order.go
  2. +10
    -2
      app/customer/svc/svc_pay.go
  3. +54
    -0
      app/db/db_company_with_wxpay_info.go

+ 17
- 9
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("央厨订餐退款"),


+ 10
- 2
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)),


+ 54
- 0
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
}

불러오는 중...
취소
저장