delete staff
This commit is contained in:
parent
e1c9d94148
commit
25c9ba1649
|
@ -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())
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue