paymenter
This commit is contained in:
parent
b63564f917
commit
c89880e13f
|
@ -0,0 +1,78 @@
|
||||||
|
package dao
|
||||||
|
|
||||||
|
import (
|
||||||
|
"enterprise/common/model"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ApprovalPaymentDao struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewApprovalPaymentDao() *ApprovalPaymentDao {
|
||||||
|
return &ApprovalPaymentDao{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *ApprovalPaymentDao) TableName() string {
|
||||||
|
return "approval_payment"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *ApprovalPaymentDao) Create(o *model.ApprovalPayment) (int64, error) {
|
||||||
|
o.CreateTime = time.Now().Unix()
|
||||||
|
res := GetDB().Table(d.TableName()).Create(o)
|
||||||
|
return o.Id, res.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *ApprovalPaymentDao) Update(o *model.ApprovalPayment) error {
|
||||||
|
o.UpdateTime = time.Now().Unix()
|
||||||
|
tx := GetDB().Table(d.TableName())
|
||||||
|
res := tx.Save(o)
|
||||||
|
return res.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *ApprovalPaymentDao) Delete(id int64) error {
|
||||||
|
res := GetDB().Table(d.TableName()).Delete(&model.ApprovalPayment{}, id)
|
||||||
|
return res.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *ApprovalPaymentDao) Get(id int64) (*model.ApprovalPayment, error) {
|
||||||
|
var u model.ApprovalPayment
|
||||||
|
tx := GetDB().Table(d.TableName())
|
||||||
|
tx = tx.Where("id = ?", id)
|
||||||
|
res := tx.First(&u)
|
||||||
|
if res.Error == gorm.ErrRecordNotFound {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if res.Error != nil {
|
||||||
|
return nil, res.Error
|
||||||
|
}
|
||||||
|
return &u, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *ApprovalPaymentDao) GetBySpNo(spNo string) (*model.ApprovalPayment, error) {
|
||||||
|
var u model.ApprovalPayment
|
||||||
|
tx := GetDB().Table(d.TableName())
|
||||||
|
tx = tx.Where("sp_no = ?", spNo)
|
||||||
|
res := tx.First(&u)
|
||||||
|
if res.Error == gorm.ErrRecordNotFound {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if res.Error != nil {
|
||||||
|
return nil, res.Error
|
||||||
|
}
|
||||||
|
return &u, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *ApprovalPaymentDao) GetByUsername(username, month string) ([]*model.ApprovalPayment, error) {
|
||||||
|
var u []*model.ApprovalPayment
|
||||||
|
tx := GetDB().Table(d.TableName())
|
||||||
|
tx = tx.Where("month = ?", month)
|
||||||
|
tx = tx.Where("username = ?", username)
|
||||||
|
res := tx.Find(&u)
|
||||||
|
if res.Error != nil {
|
||||||
|
return nil, res.Error
|
||||||
|
}
|
||||||
|
return u, nil
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/smbrave/goutil"
|
||||||
|
"github.com/spf13/cast"
|
||||||
|
"gitlab.batiao8.com/open/gosdk/qyweixin"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ApprovalPayment struct {
|
||||||
|
Id int64
|
||||||
|
Username string
|
||||||
|
Month string
|
||||||
|
SpNo string
|
||||||
|
ApplyTime string
|
||||||
|
CreateTime int64
|
||||||
|
UpdateTime int64
|
||||||
|
|
||||||
|
PaymentType string
|
||||||
|
PaymentDate string
|
||||||
|
PaymentAmount float64
|
||||||
|
PaymentRemark string
|
||||||
|
PaymentPayer string
|
||||||
|
PaymentPayee string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApprovalPayment) From(d *qyweixin.ApproveDetail) {
|
||||||
|
a.SpNo = d.SpNo
|
||||||
|
a.Username = d.GetUserid()
|
||||||
|
a.ApplyTime = goutil.TimeToDateTime(d.ApplyTime)
|
||||||
|
|
||||||
|
paymentTime := cast.ToInt64(d.GetValue("付款日期"))
|
||||||
|
a.Month = time.Unix(paymentTime, 0).Format("200601")
|
||||||
|
|
||||||
|
a.PaymentType = d.GetValue("付款类型")
|
||||||
|
a.PaymentPayer = d.GetValue("付款主体")
|
||||||
|
a.PaymentDate = goutil.TimeToDateTime(paymentTime)
|
||||||
|
a.PaymentAmount = cast.ToFloat64(d.GetValue("付款金额"))
|
||||||
|
a.PaymentRemark = d.GetValue("备注说明")
|
||||||
|
|
||||||
|
account := d.GetValue("收款账户")
|
||||||
|
accountFields := strings.Split(account, ",")
|
||||||
|
if len(accountFields) >= 3 {
|
||||||
|
a.PaymentPayee = accountFields[1]
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ var (
|
||||||
ApprovalTpIdCheckin = "C4UCJS891Afmu1rE1Ws6cvph7YHqebWtt7KRFqh8c"
|
ApprovalTpIdCheckin = "C4UCJS891Afmu1rE1Ws6cvph7YHqebWtt7KRFqh8c"
|
||||||
ApprovalTpIdRefund = "C4UE6NT3ZE7XzER9TBk2ynHEeqA11NE2GGCuBq5yH"
|
ApprovalTpIdRefund = "C4UE6NT3ZE7XzER9TBk2ynHEeqA11NE2GGCuBq5yH"
|
||||||
ApprovalTpIdVacation = "3WLJF6naF5jhnXvwisuPmE85wVMYcy1S1ZvYibkw"
|
ApprovalTpIdVacation = "3WLJF6naF5jhnXvwisuPmE85wVMYcy1S1ZvYibkw"
|
||||||
|
ApprovalTpIdPayment = "C4WqcQBRQZoB5d15uKtjwuG6k32mc7ykJYuLF1ois"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ApprovalRefund struct {
|
type ApprovalRefund struct {
|
||||||
|
|
8
go.mod
8
go.mod
|
@ -13,14 +13,14 @@ require (
|
||||||
github.com/mitchellh/mapstructure v1.5.0
|
github.com/mitchellh/mapstructure v1.5.0
|
||||||
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
|
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
|
||||||
github.com/sirupsen/logrus v1.9.3
|
github.com/sirupsen/logrus v1.9.3
|
||||||
github.com/smbrave/goutil v0.0.0-20240105134047-64fe0dfafba2
|
github.com/smbrave/goutil v0.0.0-20240307100306-1a2edd79979d
|
||||||
github.com/spf13/cast v1.6.0
|
github.com/spf13/cast v1.6.0
|
||||||
github.com/spf13/viper v1.16.0
|
github.com/spf13/viper v1.16.0
|
||||||
github.com/wechatpay-apiv3/wechatpay-go v0.2.18
|
github.com/wechatpay-apiv3/wechatpay-go v0.2.18
|
||||||
github.com/xuri/excelize/v2 v2.8.0
|
github.com/xuri/excelize/v2 v2.8.0
|
||||||
golang.org/x/crypto v0.18.0
|
golang.org/x/crypto v0.18.0
|
||||||
gorm.io/driver/mysql v1.5.1
|
gorm.io/driver/mysql v1.5.1
|
||||||
gorm.io/gorm v1.25.5
|
gorm.io/gorm v1.25.7
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
@ -69,13 +69,13 @@ require (
|
||||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||||
github.com/xuri/efp v0.0.0-20230802181842-ad255f2331ca // indirect
|
github.com/xuri/efp v0.0.0-20230802181842-ad255f2331ca // indirect
|
||||||
github.com/xuri/nfp v0.0.0-20230819163627-dc951e3ffe1a // indirect
|
github.com/xuri/nfp v0.0.0-20230819163627-dc951e3ffe1a // indirect
|
||||||
gitlab.batiao8.com/open/gosdk v0.0.0-20240124083400-940a627adef3 // indirect
|
gitlab.batiao8.com/open/gosdk v0.0.0-20240309120421-dc8eede4b7ca // indirect
|
||||||
go.uber.org/atomic v1.9.0 // indirect
|
go.uber.org/atomic v1.9.0 // indirect
|
||||||
go.uber.org/multierr v1.8.0 // indirect
|
go.uber.org/multierr v1.8.0 // indirect
|
||||||
go.uber.org/zap v1.21.0 // indirect
|
go.uber.org/zap v1.21.0 // indirect
|
||||||
golang.org/x/arch v0.7.0 // indirect
|
golang.org/x/arch v0.7.0 // indirect
|
||||||
golang.org/x/net v0.20.0 // indirect
|
golang.org/x/net v0.20.0 // indirect
|
||||||
golang.org/x/sys v0.16.0 // indirect
|
golang.org/x/sys v0.18.0 // indirect
|
||||||
golang.org/x/text v0.14.0 // indirect
|
golang.org/x/text v0.14.0 // indirect
|
||||||
google.golang.org/protobuf v1.32.0 // indirect
|
google.golang.org/protobuf v1.32.0 // indirect
|
||||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
|
|
|
@ -68,12 +68,40 @@ func (a *Approve) handleApprovalChange(msg *message.MixMessage) {
|
||||||
log.Errorf("get spn detail error :%s", err.Error())
|
log.Errorf("get spn detail error :%s", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Infof("spno: %s detail: %s", spNo, goutil.EncodeJSON(detail))
|
||||||
if templateId == model.ApprovalTpIdRefund {
|
if templateId == model.ApprovalTpIdRefund {
|
||||||
a.handleRefund(detail)
|
a.handleRefund(detail)
|
||||||
} else if templateId == model.ApprovalTpIdVacation {
|
} else if templateId == model.ApprovalTpIdVacation {
|
||||||
a.handleVacation(detail)
|
a.handleVacation(detail)
|
||||||
} else if templateId == model.ApprovalTpIdCheckin {
|
} else if templateId == model.ApprovalTpIdCheckin {
|
||||||
a.handleCheckin(detail)
|
a.handleCheckin(detail)
|
||||||
|
} else if templateId == model.ApprovalTpIdPayment {
|
||||||
|
a.handlePayment(detail)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Approve) handlePayment(detail *qyweixin.ApproveDetail) {
|
||||||
|
newData := new(model.ApprovalPayment)
|
||||||
|
newData.From(detail)
|
||||||
|
dbDao := dao.NewApprovalPaymentDao()
|
||||||
|
|
||||||
|
old, err := dbDao.GetBySpNo(detail.SpNo)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("db error :%s", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if old != nil {
|
||||||
|
newData.Id = old.Id
|
||||||
|
newData.CreateTime = old.CreateTime
|
||||||
|
err = dbDao.Update(newData)
|
||||||
|
} else {
|
||||||
|
_, err = dbDao.Create(newData)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("db error :%s", err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,6 +152,7 @@ func (a *Approve) handleCheckin(detail *qyweixin.ApproveDetail) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Approve) handleRefund(detail *qyweixin.ApproveDetail) {
|
func (a *Approve) handleRefund(detail *qyweixin.ApproveDetail) {
|
||||||
newData := new(model.ApprovalRefund)
|
newData := new(model.ApprovalRefund)
|
||||||
newData.From(detail)
|
newData.From(detail)
|
||||||
|
|
Loading…
Reference in New Issue