diff --git a/common/dao/staff_salary.go b/common/dao/staff_salary.go index e105a5a..7accec4 100644 --- a/common/dao/staff_salary.go +++ b/common/dao/staff_salary.go @@ -68,6 +68,32 @@ func (d *StaffSalaryDao) GetBy(corpId, userId int64, month string) (*model.Staff return &u, nil } +func (d *StaffSalaryDao) QueryByUser(corpId int64, userId int64, month string, status int) ([]*model.StaffSalary, error) { + var u []*model.StaffSalary + tx := GetDB().Table(d.TableName()) + + tx.Where("corp_id = ?", corpId) + tx.Where("user_id = ?", userId) + if month != "" { + tx.Where("month = ?", month) + } + + if status != 0 { + tx.Where("status = ?", status) + } + tx.Order("month DESC") + + res := tx.Find(&u) + if res.Error == gorm.ErrRecordNotFound { + return nil, nil + } + + if res.Error != nil { + return nil, res.Error + } + return u, nil +} + func (d *StaffSalaryDao) QueryAll(corpId int64, month string, status int) ([]*model.StaffSalary, error) { var u []*model.StaffSalary tx := GetDB().Table(d.TableName()) diff --git a/server/controller/staff.go b/server/controller/staff.go index d386a24..dc0dbc6 100644 --- a/server/controller/staff.go +++ b/server/controller/staff.go @@ -84,6 +84,12 @@ func (s *Staff) Delete(ctx *gin.Context) { panic(config.ErrPriv.New()) } + staffSalarys, err := dao.NewStaffSalaryDao().QueryByUser(sess.GetCorpId(), sess.GetAdmin().Id, "", 0) + session.CheckDBError(err) + if len(staffSalarys) > 0 { + panic("有工资单的员工不能删除") + } + id := cast.ToInt64(ctx.Query("id")) session.CheckDBError(dao.NewStaffUserDao().Delete(id)) ctx.JSON(http.StatusOK, session.NewRspOk())