companyFavoriteRepository.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\CompanyFavorite;
  4. use Prettus\Repository\Eloquent\BaseRepository;
  5. use Prettus\Repository\Criteria\RequestCriteria;
  6. /**
  7. * Class MemberRepositoryEloquent.
  8. *
  9. * @package namespace App\Repositories;
  10. */
  11. class companyFavoriteRepository extends BaseRepository
  12. {
  13. /**
  14. * Specify Model class name
  15. *
  16. * @return string
  17. */
  18. public function model()
  19. {
  20. return CompanyFavorite::class;
  21. }
  22. /**
  23. * Boot up the repository, pushing criteria
  24. */
  25. public function boot()
  26. {
  27. $this->pushCriteria(app(RequestCriteria::class));
  28. }
  29. public function getAttentionsMe($uid, $settr)
  30. {
  31. if ($settr) {
  32. $res= $this->model->with(['resumes','companys'])->whereHas('resumes', function ($query) use ($uid) {
  33. $query->whereIn('id', $uid);
  34. })->whereHas('companys')->where($settr)->orderBy('id', 'desc')->paginate(5);
  35. } else {
  36. $res= $this->model->with(['resumes','companys'])->whereHas('resumes', function ($query) use ($uid) {
  37. $query->whereIn('id', $uid);
  38. })->whereHas('companys')->orderBy('id', 'desc')->paginate(5);
  39. }
  40. return $res;
  41. }
  42. public function delAttention($id)
  43. {
  44. return $this->model->whereIn('id', $id)->delete();
  45. }
  46. public function getAttentionByResume($resume_id)
  47. {
  48. return $this->model->where('resume_id', $resume_id)->count();
  49. }
  50. /**
  51. * 企业收藏的简历
  52. * @param $where
  53. * @param $page
  54. * @return mixed
  55. */
  56. public function favorityList($where, $map, $id, $page)
  57. {
  58. return $this->model->when($map, function ($query) use ($map) {
  59. $query->whereHas('resumes', function ($querys) use ($map) {
  60. $querys->where($map);
  61. });
  62. })->where($where)->where('company_id', $id)->orderBy('created_at', 'desc')->paginate($page, ['*']);
  63. // return $this->model->with(['resumes'=>function ($query) use ($map) {
  64. // $query->where($map);
  65. // }])->where($where)->whereHas('resumes')->where('company_id', $id)->orderBy('created_at', 'desc')->paginate($page, ['*']);
  66. }
  67. /**删除企业收藏的简历
  68. * @param $ids
  69. * @return mixed
  70. * @param $company_id
  71. */
  72. public function favoritesResumeDel($ids,$company_id)
  73. {
  74. return $this->model->whereIn('id', $ids)->where("company_id",$company_id)->delete();
  75. }
  76. public function findFavorite($resume_id, $company_id)
  77. {
  78. $where['resume_id'] = $resume_id;
  79. $where['company_id'] = $company_id;
  80. return $this->model->where($where)->first();
  81. }
  82. public function cancelFavor($where)
  83. {
  84. return $this->model->where($where)->delete();
  85. }
  86. public function getFavoritesResumes($where)
  87. {
  88. return $this->model->where($where)->get();
  89. }
  90. public function insertData($data)
  91. {
  92. return $this->model->insert($data);
  93. }
  94. }