diff --git a/common/dao/approval_checkin.go b/common/dao/approval_checkin.go index a81f939..b0fc3b1 100644 --- a/common/dao/approval_checkin.go +++ b/common/dao/approval_checkin.go @@ -50,10 +50,11 @@ func (d *ApprovalCheckinDao) Get(id int64) (*model.ApprovalCheckin, error) { 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 tx := GetDB().Table(d.TableName()) tx = tx.Where("sp_no = ?", spNo) + tx = tx.Where("corp_id = ?", corpId) res := tx.First(&u) if res.Error == gorm.ErrRecordNotFound { return nil, nil diff --git a/common/dao/approval_payment.go b/common/dao/approval_payment.go index ba09954..869b69d 100644 --- a/common/dao/approval_payment.go +++ b/common/dao/approval_payment.go @@ -50,10 +50,11 @@ func (d *ApprovalPaymentDao) Get(id int64) (*model.ApprovalPayment, error) { 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 tx := GetDB().Table(d.TableName()) tx = tx.Where("sp_no = ?", spNo) + tx = tx.Where("corp_id = ?", corpId) res := tx.First(&u) if res.Error == gorm.ErrRecordNotFound { return nil, nil diff --git a/common/dao/approval_refund.go b/common/dao/approval_refund.go index 779836b..d898407 100644 --- a/common/dao/approval_refund.go +++ b/common/dao/approval_refund.go @@ -50,10 +50,11 @@ func (d *ApprovalRefundDao) Get(id int64) (*model.ApprovalRefund, error) { 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 tx := GetDB().Table(d.TableName()) tx = tx.Where("sp_no = ?", spNo) + tx = tx.Where("corp_id = ?", corpId) res := tx.First(&u) if res.Error == gorm.ErrRecordNotFound { return nil, nil diff --git a/common/dao/approval_vacation.go b/common/dao/approval_vacation.go index 910b4e6..8f3648a 100644 --- a/common/dao/approval_vacation.go +++ b/common/dao/approval_vacation.go @@ -50,10 +50,11 @@ func (d *ApprovalVacationDao) Get(id int64) (*model.ApprovalVacation, error) { 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 tx := GetDB().Table(d.TableName()) tx = tx.Where("sp_no = ?", spNo) + tx = tx.Where("corp_id = ?", corpId) res := tx.First(&u) if res.Error == gorm.ErrRecordNotFound { return nil, nil diff --git a/server/service/qyweixin_approve.go b/server/service/qyweixin_approve.go index 8564354..2effb09 100644 --- a/server/service/qyweixin_approve.go +++ b/server/service/qyweixin_approve.go @@ -102,7 +102,7 @@ func (a *Approve) handlePayment(detail *qyweixin.ApproveDetail, spStatus int) { newData.CorpId = a.corp.Id dbDao := dao.NewApprovalPaymentDao() - old, err := dbDao.GetBySpNo(detail.SpNo) + old, err := dbDao.GetBySpNo(a.corp.Id, detail.SpNo) if err != nil { log.Errorf("db error :%s", err.Error()) return @@ -135,7 +135,7 @@ func (a *Approve) handleVacation(detail *qyweixin.ApproveDetail, spStatus int) { newData.CorpId = a.corp.Id dbDao := dao.NewApprovalVacationDao() - old, err := dbDao.GetBySpNo(detail.SpNo) + old, err := dbDao.GetBySpNo(a.corp.Id, detail.SpNo) if err != nil { log.Errorf("db error :%s", err.Error()) return @@ -168,7 +168,7 @@ func (a *Approve) handleCheckin(detail *qyweixin.ApproveDetail, spStatus int) { newData.CorpId = a.corp.Id dbDao := dao.NewApprovalCheckinDao() - old, err := dbDao.GetBySpNo(detail.SpNo) + old, err := dbDao.GetBySpNo(a.corp.Id, detail.SpNo) if err != nil { log.Errorf("db error :%s", err.Error()) return @@ -256,7 +256,7 @@ func (a *Approve) handleRefund(detail *qyweixin.ApproveDetail, spStatus int) { newData.CorpId = a.corp.Id dbDao := dao.NewApprovalRefundDao() - old, err := dbDao.GetBySpNo(detail.SpNo) + old, err := dbDao.GetBySpNo(a.corp.Id, detail.SpNo) if err != nil { log.Errorf("db error :%s", err.Error()) return diff --git a/worker/approval.go b/worker/approval.go index c919dd2..ab88a02 100644 --- a/worker/approval.go +++ b/worker/approval.go @@ -61,18 +61,39 @@ func (s *Approval) Sync(month, tp string) { } else if tp == model.ApprovalTypeVacation { s.saveVacation(detail) } else if tp == model.ApprovalTypePayment { - + s.savePayment(detail) } } 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) { dbDao := dao.NewApprovalCheckinDao() newData := new(model.ApprovalCheckin) newData.From(detail) - old, err := dbDao.GetBySpNo(detail.SpNo) + old, err := dbDao.GetBySpNo(s.corp.Id, detail.SpNo) if err != nil { log.Errorf("db error :%s", err.Error()) return @@ -93,7 +114,7 @@ func (s *Approval) saveRefund(detail *qyweixin.ApproveDetail) { dbDao := dao.NewApprovalRefundDao() newData := new(model.ApprovalRefund) newData.From(detail) - old, err := dbDao.GetBySpNo(detail.SpNo) + old, err := dbDao.GetBySpNo(s.corp.Id, detail.SpNo) if err != nil { log.Errorf("db error :%s", err.Error()) return @@ -111,7 +132,7 @@ func (s *Approval) saveVacation(detail *qyweixin.ApproveDetail) { dbDao := dao.NewApprovalVacationDao() newData := new(model.ApprovalVacation) newData.From(detail) - old, err := dbDao.GetBySpNo(detail.SpNo) + old, err := dbDao.GetBySpNo(s.corp.Id, detail.SpNo) if err != nil { log.Errorf("db error :%s", err.Error()) return