apply.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package dao
  2. import (
  3. "go-common/app/admin/ep/melloi/model"
  4. )
  5. // QueryApply query apply list
  6. func (d *Dao) QueryApply(apply *model.Apply, pn, ps int32) (qar *model.QueryApplyResponse, err error) {
  7. qar = &model.QueryApplyResponse{}
  8. err = d.DB.Table(model.Apply{}.TableName()).Where(model.Apply{
  9. ID: apply.ID, From: apply.From, To: apply.To, Status: apply.Status, Active: model.ApplyValid}).
  10. Count(&qar.TotalSize).Offset((pn - 1) * ps).Limit(ps).Order("id desc").Find(&qar.ApplyList).Error
  11. qar.PageSize = ps
  12. qar.PageNum = pn
  13. return
  14. }
  15. // QueryUserApplyList query user apply list
  16. func (d *Dao) QueryUserApplyList(userName string) (applyList []*model.Apply, err error) {
  17. applyList = []*model.Apply{}
  18. err = d.DB.Table(model.Apply{}.TableName()).Where("`from`=?", userName).
  19. Where("`active`=?", 1).Where("`status`=?", model.ApplyValid).Find(&applyList).Error
  20. return
  21. }
  22. //QueryApplyByID query apply by id
  23. func (d *Dao) QueryApplyByID(id int64) (apply *model.Apply, err error) {
  24. apply = &model.Apply{}
  25. err = d.DB.Table(model.Apply{}.TableName()).Where("id = ?", id).First(apply).Error
  26. return
  27. }
  28. //AddApply add apply
  29. func (d *Dao) AddApply(apply *model.Apply) error {
  30. return d.DB.Model(&model.Apply{}).Create(apply).Error
  31. }
  32. // UpdateApply update apply info
  33. func (d *Dao) UpdateApply(apply *model.Apply) error {
  34. return d.DB.Model(&model.Apply{}).Updates(apply).Where("ID=?", apply.ID).Error
  35. }
  36. // DeleteApply delete apply info
  37. func (d *Dao) DeleteApply(id int64) error {
  38. return d.DB.Model(&model.Apply{}).Where("ID=?", id).Update("active", model.ApplyInvalid).Error
  39. }