outtradeno

This commit is contained in:
jiangyong 2025-04-04 13:01:59 +08:00
parent 716e33aeb9
commit 38eed20aeb
7 changed files with 24 additions and 12 deletions

View File

@ -3,6 +3,7 @@ package model
type StaffPayLog struct { type StaffPayLog struct {
Id int64 Id int64
StaffId int64 StaffId int64
OutTradeNo string
PayType string PayType string
Amount int64 Amount int64
Title string Title string

View File

@ -73,6 +73,10 @@ func (s *StaffSalary) GetBillUrl() string {
return billUrl return billUrl
} }
func (s *StaffSalary) GetOutTradeNo() string {
return fmt.Sprintf("SALARY_%d_%s_%d", s.CorpId, s.Month, s.UserId)
}
type StaffSalarySort []*StaffSalary type StaffSalarySort []*StaffSalary
func (s StaffSalarySort) Len() int { func (s StaffSalarySort) Len() int {

View File

@ -51,7 +51,7 @@ func (q *Payment) Pay(ctx *gin.Context) {
session.CheckDBError(err) session.CheckDBError(err)
session.CheckNilError(user, fmt.Sprintf("用户[%s]不存在", req.Username)) session.CheckNilError(user, fmt.Sprintf("用户[%s]不存在", req.Username))
if err = CommonService.NewPay().Pay(corp, user, req.Title, req.PayType, req.Amount); err != nil { if err = CommonService.NewPay().Pay(corp, user, req.Title, req.PayType, req.Amount, ""); err != nil {
panic(config.ErrInternal.New().Append(err)) panic(config.ErrInternal.New().Append(err))
} }
ctx.JSON(http.StatusOK, session.NewRspOk()) ctx.JSON(http.StatusOK, session.NewRspOk())

View File

@ -161,7 +161,7 @@ func (s *StaffSalary) Pay(sess *session.AdminSession, req *api.PaySalaryReq) {
salary.Status = model.StaffSalaryStatusPayed salary.Status = model.StaffSalaryStatusPayed
dao.NewStaffSalaryDao().Update(salary) dao.NewStaffSalaryDao().Update(salary)
if err = CommonService.NewPay().Pay(corp, user, title, req.PayType, int64(salary.GetRealSalary()*100)); err != nil { if err = CommonService.NewPay().Pay(corp, user, title, req.PayType, int64(salary.GetRealSalary()*100), salary.GetOutTradeNo()); err != nil {
panic(config.ErrInternal.New().Append(err)) panic(config.ErrInternal.New().Append(err))
} }
} }

View File

@ -210,7 +210,7 @@ func (s *StaffUser) Pay(sess *session.AdminSession, req *api.StaffPayReq) {
if req.Title == "" { if req.Title == "" {
req.Title = "测试" req.Title = "测试"
} }
if err = CommonService.NewPay().Pay(corp, user, req.Title, req.PayType, cast.ToInt64(req.Amount)); err != nil { if err = CommonService.NewPay().Pay(corp, user, req.Title, req.PayType, cast.ToInt64(req.Amount), ""); err != nil {
panic(config.ErrInternal.New().Append(err)) panic(config.ErrInternal.New().Append(err))
} }
} }

View File

@ -12,8 +12,8 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/smartwalle/alipay/v3" "github.com/smartwalle/alipay/v3"
"github.com/smbrave/goutil" "github.com/smbrave/goutil"
"github.com/spf13/cast"
"strings" "strings"
"time"
) )
type Pay struct { type Pay struct {
@ -23,7 +23,10 @@ func NewPay() *Pay {
return &Pay{} return &Pay{}
} }
func (p *Pay) Pay(corp *model.Corp, user *model.StaffUser, title, payType string, amount int64) error { func (p *Pay) Pay(corp *model.Corp, user *model.StaffUser, title, payType string, amount int64, outTradeNo string) error {
if outTradeNo == "" {
outTradeNo = fmt.Sprintf("%d_%s_%s", corp.Id, time.Now().Format("200601020304"), user.Id)
}
var err error var err error
realPayType := "" realPayType := ""
payee := user.GetPayee() payee := user.GetPayee()
@ -31,10 +34,10 @@ func (p *Pay) Pay(corp *model.Corp, user *model.StaffUser, title, payType string
if payee.AlipayUid == "" { if payee.AlipayUid == "" {
panic("请绑定支付宝账号") panic("请绑定支付宝账号")
} }
err = p.payAlipay(corp, user, title, amount) err = p.payAlipay(corp, user, title, amount, outTradeNo)
realPayType = "alipay" realPayType = "alipay"
} else { } else {
err = p.payWeixin(corp, user, title, amount) err = p.payWeixin(corp, user, title, amount, outTradeNo)
realPayType = "weixin" realPayType = "weixin"
} }
@ -62,13 +65,13 @@ func (p *Pay) Pay(corp *model.Corp, user *model.StaffUser, title, payType string
return nil return nil
} }
func (p *Pay) payAlipay(corp *model.Corp, user *model.StaffUser, title string, amount int64) error { func (p *Pay) payAlipay(corp *model.Corp, user *model.StaffUser, title string, amount int64, outTradeNo string) error {
corpConfig := corp.GetConfig() corpConfig := corp.GetConfig()
userPayee := user.GetPayee() userPayee := user.GetPayee()
cli := config.GetAliPayClient(goutil.If(corpConfig.PayChannel != "", corpConfig.PayChannel, "batiao")) cli := config.GetAliPayClient(goutil.If(corpConfig.PayChannel != "", corpConfig.PayChannel, "batiao"))
var payReq alipay.FundTransUniTransfer var payReq alipay.FundTransUniTransfer
payReq.Remark = title payReq.Remark = title
payReq.OutBizNo = cast.ToString(goutil.GetBigID(0, 0)) payReq.OutBizNo = outTradeNo
payReq.TransAmount = goutil.FormatMoney(amount) payReq.TransAmount = goutil.FormatMoney(amount)
payReq.ProductCode = "TRANS_ACCOUNT_NO_PWD" payReq.ProductCode = "TRANS_ACCOUNT_NO_PWD"
payReq.BizScene = "DIRECT_TRANSFER" payReq.BizScene = "DIRECT_TRANSFER"
@ -89,7 +92,7 @@ func (p *Pay) payAlipay(corp *model.Corp, user *model.StaffUser, title string, a
return nil return nil
} }
func (p *Pay) payWeixin(corp *model.Corp, user *model.StaffUser, title string, amount int64) error { func (p *Pay) payWeixin(corp *model.Corp, user *model.StaffUser, title string, amount int64, outTradeNo string) error {
cfg := corp.GetConfig() cfg := corp.GetConfig()
@ -107,7 +110,7 @@ func (p *Pay) payWeixin(corp *model.Corp, user *model.StaffUser, title string, a
// 支付费用 // 支付费用
var payReq qyweixin.PayReq var payReq qyweixin.PayReq
payReq.BillNo = cast.ToString(goutil.GetBigID(0, 0)) payReq.BillNo = outTradeNo
payReq.Title = title payReq.Title = title
payReq.Openid = openid payReq.Openid = openid
payReq.TotalAmount = amount payReq.TotalAmount = amount

View File

@ -131,7 +131,11 @@ func (s *Staff) PayStaffSalary(corpId int64, month string) {
message = append(message, fmt.Sprintf(`<a href="%s">查看明细</a>`, staffSalary.GetBillUrl())) message = append(message, fmt.Sprintf(`<a href="%s">查看明细</a>`, staffSalary.GetBillUrl()))
if staffUser.Username == "jiangyong" { if staffUser.Username == "jiangyong" {
err = service.NewPay().Pay(corp, staffUser, fmt.Sprintf("[%s]工资", staffSalary.Month), model.StaffSalaryPaymentAlipay, int64(100*staffSalary.GetRealSalary())) err = service.NewPay().Pay(corp, staffUser,
fmt.Sprintf("[%s]工资", staffSalary.Month),
model.StaffSalaryPaymentAlipay,
int64(100*staffSalary.GetRealSalary()),
staffSalary.GetOutTradeNo())
if err == nil { if err == nil {
staffSalary.Status = model.StaffSalaryStatusPayed staffSalary.Status = model.StaffSalaryStatusPayed
message = append(message, "发放成功") message = append(message, "发放成功")