a.corp.Id,

This commit is contained in:
jiangyong27 2025-01-08 12:59:56 +08:00
parent 1718a4665d
commit c566fcd3f1
6 changed files with 37 additions and 12 deletions

View File

@ -50,10 +50,11 @@ func (d *ApprovalCheckinDao) Get(id int64) (*model.ApprovalCheckin, error) {
return &u, nil return &u, nil
} }
func (d *ApprovalCheckinDao) GetBySpNo(spNo string) (*model.ApprovalCheckin, error) { func (d *ApprovalCheckinDao) GetBySpNo(corpId int64, spNo string) (*model.ApprovalCheckin, error) {
var u model.ApprovalCheckin var u model.ApprovalCheckin
tx := GetDB().Table(d.TableName()) tx := GetDB().Table(d.TableName())
tx = tx.Where("sp_no = ?", spNo) tx = tx.Where("sp_no = ?", spNo)
tx = tx.Where("corp_id = ?", corpId)
res := tx.First(&u) res := tx.First(&u)
if res.Error == gorm.ErrRecordNotFound { if res.Error == gorm.ErrRecordNotFound {
return nil, nil return nil, nil

View File

@ -50,10 +50,11 @@ func (d *ApprovalPaymentDao) Get(id int64) (*model.ApprovalPayment, error) {
return &u, nil return &u, nil
} }
func (d *ApprovalPaymentDao) GetBySpNo(spNo string) (*model.ApprovalPayment, error) { func (d *ApprovalPaymentDao) GetBySpNo(corpId int64, spNo string) (*model.ApprovalPayment, error) {
var u model.ApprovalPayment var u model.ApprovalPayment
tx := GetDB().Table(d.TableName()) tx := GetDB().Table(d.TableName())
tx = tx.Where("sp_no = ?", spNo) tx = tx.Where("sp_no = ?", spNo)
tx = tx.Where("corp_id = ?", corpId)
res := tx.First(&u) res := tx.First(&u)
if res.Error == gorm.ErrRecordNotFound { if res.Error == gorm.ErrRecordNotFound {
return nil, nil return nil, nil

View File

@ -50,10 +50,11 @@ func (d *ApprovalRefundDao) Get(id int64) (*model.ApprovalRefund, error) {
return &u, nil return &u, nil
} }
func (d *ApprovalRefundDao) GetBySpNo(spNo string) (*model.ApprovalRefund, error) { func (d *ApprovalRefundDao) GetBySpNo(corpId int64, spNo string) (*model.ApprovalRefund, error) {
var u model.ApprovalRefund var u model.ApprovalRefund
tx := GetDB().Table(d.TableName()) tx := GetDB().Table(d.TableName())
tx = tx.Where("sp_no = ?", spNo) tx = tx.Where("sp_no = ?", spNo)
tx = tx.Where("corp_id = ?", corpId)
res := tx.First(&u) res := tx.First(&u)
if res.Error == gorm.ErrRecordNotFound { if res.Error == gorm.ErrRecordNotFound {
return nil, nil return nil, nil

View File

@ -50,10 +50,11 @@ func (d *ApprovalVacationDao) Get(id int64) (*model.ApprovalVacation, error) {
return &u, nil return &u, nil
} }
func (d *ApprovalVacationDao) GetBySpNo(spNo string) (*model.ApprovalVacation, error) { func (d *ApprovalVacationDao) GetBySpNo(corpId int64, spNo string) (*model.ApprovalVacation, error) {
var u model.ApprovalVacation var u model.ApprovalVacation
tx := GetDB().Table(d.TableName()) tx := GetDB().Table(d.TableName())
tx = tx.Where("sp_no = ?", spNo) tx = tx.Where("sp_no = ?", spNo)
tx = tx.Where("corp_id = ?", corpId)
res := tx.First(&u) res := tx.First(&u)
if res.Error == gorm.ErrRecordNotFound { if res.Error == gorm.ErrRecordNotFound {
return nil, nil return nil, nil

View File

@ -102,7 +102,7 @@ func (a *Approve) handlePayment(detail *qyweixin.ApproveDetail, spStatus int) {
newData.CorpId = a.corp.Id newData.CorpId = a.corp.Id
dbDao := dao.NewApprovalPaymentDao() dbDao := dao.NewApprovalPaymentDao()
old, err := dbDao.GetBySpNo(detail.SpNo) old, err := dbDao.GetBySpNo(a.corp.Id, detail.SpNo)
if err != nil { if err != nil {
log.Errorf("db error :%s", err.Error()) log.Errorf("db error :%s", err.Error())
return return
@ -135,7 +135,7 @@ func (a *Approve) handleVacation(detail *qyweixin.ApproveDetail, spStatus int) {
newData.CorpId = a.corp.Id newData.CorpId = a.corp.Id
dbDao := dao.NewApprovalVacationDao() dbDao := dao.NewApprovalVacationDao()
old, err := dbDao.GetBySpNo(detail.SpNo) old, err := dbDao.GetBySpNo(a.corp.Id, detail.SpNo)
if err != nil { if err != nil {
log.Errorf("db error :%s", err.Error()) log.Errorf("db error :%s", err.Error())
return return
@ -168,7 +168,7 @@ func (a *Approve) handleCheckin(detail *qyweixin.ApproveDetail, spStatus int) {
newData.CorpId = a.corp.Id newData.CorpId = a.corp.Id
dbDao := dao.NewApprovalCheckinDao() dbDao := dao.NewApprovalCheckinDao()
old, err := dbDao.GetBySpNo(detail.SpNo) old, err := dbDao.GetBySpNo(a.corp.Id, detail.SpNo)
if err != nil { if err != nil {
log.Errorf("db error :%s", err.Error()) log.Errorf("db error :%s", err.Error())
return return
@ -256,7 +256,7 @@ func (a *Approve) handleRefund(detail *qyweixin.ApproveDetail, spStatus int) {
newData.CorpId = a.corp.Id newData.CorpId = a.corp.Id
dbDao := dao.NewApprovalRefundDao() dbDao := dao.NewApprovalRefundDao()
old, err := dbDao.GetBySpNo(detail.SpNo) old, err := dbDao.GetBySpNo(a.corp.Id, detail.SpNo)
if err != nil { if err != nil {
log.Errorf("db error :%s", err.Error()) log.Errorf("db error :%s", err.Error())
return return

View File

@ -61,18 +61,39 @@ func (s *Approval) Sync(month, tp string) {
} else if tp == model.ApprovalTypeVacation { } else if tp == model.ApprovalTypeVacation {
s.saveVacation(detail) s.saveVacation(detail)
} else if tp == model.ApprovalTypePayment { } else if tp == model.ApprovalTypePayment {
s.savePayment(detail)
} }
} }
return return
} }
func (s *Approval) savePayment(detail *qyweixin.ApproveDetail) {
dbDao := dao.NewApprovalPaymentDao()
newData := new(model.ApprovalPayment)
newData.From(detail)
old, err := dbDao.GetBySpNo(s.corp.Id, detail.SpNo)
if err != nil {
log.Errorf("db error :%s", err.Error())
return
}
if old == nil {
_, err = dbDao.Create(newData)
} else {
newData.Id = old.Id
newData.CreateTime = old.CreateTime
err = dbDao.Update(newData)
}
if err != nil {
log.Errorf("db error :%s", err.Error())
}
}
func (s *Approval) saveCheckin(detail *qyweixin.ApproveDetail) { func (s *Approval) saveCheckin(detail *qyweixin.ApproveDetail) {
dbDao := dao.NewApprovalCheckinDao() dbDao := dao.NewApprovalCheckinDao()
newData := new(model.ApprovalCheckin) newData := new(model.ApprovalCheckin)
newData.From(detail) newData.From(detail)
old, err := dbDao.GetBySpNo(detail.SpNo) old, err := dbDao.GetBySpNo(s.corp.Id, detail.SpNo)
if err != nil { if err != nil {
log.Errorf("db error :%s", err.Error()) log.Errorf("db error :%s", err.Error())
return return
@ -93,7 +114,7 @@ func (s *Approval) saveRefund(detail *qyweixin.ApproveDetail) {
dbDao := dao.NewApprovalRefundDao() dbDao := dao.NewApprovalRefundDao()
newData := new(model.ApprovalRefund) newData := new(model.ApprovalRefund)
newData.From(detail) newData.From(detail)
old, err := dbDao.GetBySpNo(detail.SpNo) old, err := dbDao.GetBySpNo(s.corp.Id, detail.SpNo)
if err != nil { if err != nil {
log.Errorf("db error :%s", err.Error()) log.Errorf("db error :%s", err.Error())
return return
@ -111,7 +132,7 @@ func (s *Approval) saveVacation(detail *qyweixin.ApproveDetail) {
dbDao := dao.NewApprovalVacationDao() dbDao := dao.NewApprovalVacationDao()
newData := new(model.ApprovalVacation) newData := new(model.ApprovalVacation)
newData.From(detail) newData.From(detail)
old, err := dbDao.GetBySpNo(detail.SpNo) old, err := dbDao.GetBySpNo(s.corp.Id, detail.SpNo)
if err != nil { if err != nil {
log.Errorf("db error :%s", err.Error()) log.Errorf("db error :%s", err.Error())
return return