PersonalJobsApplyRepository.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\Company;
  4. use App\Models\PersonalJobsApply;
  5. use App\Models\Member;
  6. use App\Models\Category;
  7. use App\Models\Jobs;
  8. use Prettus\Repository\Eloquent\BaseRepository;
  9. use Prettus\Repository\Criteria\RequestCriteria;
  10. use Illuminate\Support\Facades\DB;
  11. /**
  12. * Class MemberRepositoryEloquent.
  13. *
  14. * @package namespace App\Repositories;
  15. */
  16. class PersonalJobsApplyRepository extends BaseRepository
  17. {
  18. /**
  19. * Specify Model class name
  20. *
  21. * @return string
  22. */
  23. public function model()
  24. {
  25. return PersonalJobsApply::class;
  26. }
  27. /**
  28. * Boot up the repository, pushing criteria
  29. */
  30. public function boot()
  31. {
  32. $this->pushCriteria(app(RequestCriteria::class));
  33. }
  34. /**
  35. * 获取已申请职位数。
  36. * @param $resume_id
  37. * @param $personal_uid
  38. * @return mixed
  39. */
  40. public function getApplyJobs($personal_uid, $where)
  41. {
  42. return $this->model->with(['resumes','jobs'=>function($query) use ($where) {
  43. $query->whereIn('audit', $where)->where('display', 1)->where('valid', 1);
  44. }])->where(['personal_uid'=>$personal_uid])->whereHas('resumes')->whereHas('jobs')->count();
  45. }
  46. public function getApplyJobsDef($resume_id, $where)
  47. {
  48. return $this->model->with(['resumes','jobs'=>function($query) use ($where) {
  49. $query->whereIn('audit', $where)->where('display', 1)->where('valid', 1);
  50. }])->where(['resume_id'=>$resume_id])->whereHas('resumes')->whereHas('jobs')->count();
  51. }
  52. public function getApplyResume($jobs_id)
  53. {
  54. return $this->model->where(['jobs_id'=>$jobs_id,'is_reply'=>0])->count();
  55. }
  56. /**
  57. * @param $map
  58. * @param $valid 停招职位
  59. * @param $apply_time 投递时间
  60. * @param $page
  61. * @return mixed
  62. */
  63. public function getResume($where, $page)
  64. {
  65. return $this->model->with('jobs')->with('resumes')->where($where)->orderByRaw("FIELD(is_reply,0,1,3,2,4)")->orderBy('id', 'desc')->orderBy('created_at', 'desc')->paginate($page);
  66. }
  67. public function companyLabelResume($id, $data)
  68. {
  69. return $this->update($data, $id);
  70. }
  71. /**
  72. * 近两周收到的简历
  73. * @return mixed
  74. */
  75. public function twoWeeksTotal($id)
  76. {
  77. return $this->model->where('created_at', '>=', date('Y-m-d', time()-86400*14))->where('company_id', '=', $id)->count();
  78. }
  79. /**
  80. * 近两周处理的简历
  81. * @return mixed
  82. */
  83. public function twoWeeksReplyTotal($id)
  84. {
  85. $where = [
  86. ['created_at','>=',date('Y-m-d', time() - 86400*14)],
  87. ['is_reply', '>', 0],
  88. ['personal_look','=',2],
  89. ];
  90. return $this->model->where($where)->where('company_id', '=', $id)->count();
  91. }
  92. /**
  93. * 删除简历申请
  94. * @param $id
  95. * @return mixed
  96. * @param $company_id
  97. */
  98. public function delJobsApply($id,$company_id)
  99. {
  100. return $this->model->whereIn('id', $id)->where("company_id",$company_id)->delete();
  101. }
  102. /**
  103. * 查询单个简历申请
  104. * @param $where
  105. * @return mixed
  106. */
  107. public function getOne($where)
  108. {
  109. return $this->model->where($where)->orderBy('id', 'desc')->first();
  110. }
  111. public function getJobsApply($where)
  112. {
  113. return $this->model->where($where)->orderBy('id', 'desc')->get();
  114. }
  115. /**
  116. * 获取简历ID
  117. * @param $id
  118. * @return mixed
  119. */
  120. public function getResumeId($id)
  121. {
  122. return $this->model->whereIn('id', $id)->select(['resume_id'])->get()->toArray();
  123. }
  124. /**
  125. * 检测是否申请过职位
  126. */
  127. public function checkJobsApply($resume_id, $company_id, $jobs_id = false)
  128. {
  129. $where['resume_id'] = $resume_id;
  130. $where['company_id'] = $company_id;
  131. $jobs_id && $where['jobs_id'] = $jobs_id;
  132. if (!$this->model->where($where)->first()) {
  133. return false;
  134. }
  135. return true;
  136. }
  137. /**
  138. * 获取一条职位申请记录
  139. */
  140. public function findJobsApply($resume_id, $company_id, $jobs_id = false,$id=0)
  141. {
  142. $where['resume_id'] = $resume_id;
  143. $where['company_id'] = $company_id;
  144. if (!empty($id)){
  145. $where['id']=$id;
  146. }
  147. $jobs_id && $where['jobs_id'] = $jobs_id;
  148. return $this->model->where($where)->first();
  149. }
  150. /**
  151. * 修改投递状态和查看状态
  152. * @param $where
  153. * @return mixed
  154. */
  155. public function updateApply($where)
  156. {
  157. return $this->model->where($where)->update(['is_reply'=>3,'personal_look'=>2]);
  158. }
  159. /**简历回收站
  160. * @param $uid
  161. * @param $page
  162. * @return mixed
  163. */
  164. public function recycle($uid, $page)
  165. {
  166. $where = [
  167. 'company_id'=>$uid,
  168. ];
  169. return $this->model->onlyTrashed()->where($where)->paginate($page);
  170. }
  171. /**删除收到的简历
  172. * @param $id
  173. * @return mixed
  174. */
  175. public function destroyJobsApply($id)
  176. {
  177. return $this->model->whereIn('id', $id)->forceDelete();
  178. }
  179. /**清空回收站
  180. * @param $company_id
  181. * @return mixed
  182. */
  183. public function clearRecycle($company_id)
  184. {
  185. return $this->model->where('company_id', $company_id)->forceDelete();
  186. }
  187. public function applyJobs($where, $jobs_id = array())
  188. {
  189. if ($jobs_id) {
  190. return $this->model->where($where)->whereIn('jobs_id', $jobs_id)->orderBy('created_at', 'desc')->get();
  191. } else {
  192. return $this->model->where($where)->orderBy('created_at', 'desc')->get();
  193. }
  194. }
  195. public function checkApplyJobs($where, $jobs_id = array())
  196. {
  197. if ($jobs_id) {
  198. return $this->model->where($where)->whereIn('jobs_id', $jobs_id)->get();
  199. } else {
  200. return $this->model->where($where)->get();
  201. }
  202. }
  203. //获取其它字段包含whereIn条件的字段的申请记录
  204. public function getApplies($where, $whereIn = array())
  205. {
  206. $list = array();
  207. if ($whereIn) {
  208. $rst = $this->model->where($where)->whereIn(key($whereIn), $whereIn[key($whereIn)])->get();
  209. } else {
  210. $rst = $this->model->where($where)->get();
  211. }
  212. if ($rst->toArray()) {
  213. foreach ($rst as $k => $v) {
  214. $list[$v->resume_id] = $v;
  215. }
  216. }
  217. return $list;
  218. }
  219. public function addData($data)
  220. {
  221. return $this->model->create($data);
  222. }
  223. public function setApply($where, $set)
  224. {
  225. return $this->model->where($where)->update($set);
  226. }
  227. /**投递简历数
  228. * @param $where
  229. * @return mixed
  230. */
  231. public function resumesCount($where)
  232. {
  233. return $this->model->where($where)->count();
  234. }
  235. public function getStateArr()
  236. {
  237. return $this->model->getStateArr();
  238. }
  239. public function getResumeApplyGroup($where, $fileds = 'count(p.id) as num,j.category,c.demand', $group_by = 'j.category', $order_by = 'count(p.jobs_id) DESC', $limit = '')
  240. {
  241. $rst = DB::table(PersonalJobsApply::getTableName().' as p')->select(DB::raw($fileds))
  242. ->leftjoin(Member::getTableName().' as m', 'm.id', '=', 'p.personal_uid')
  243. //->leftjoin(Jobs::getTableName().' as j', 'j.id', '=', 'p.jobs_id')
  244. ->leftjoin(Company::getTableName().' as cp', 'cp.id', '=', 'p.company_id')
  245. ->leftjoin(Category::getTableName().' as c', 'c.id', '=', 'cp.trade')
  246. ->where($where)
  247. ->groupBy($group_by)
  248. ->orderByRaw($order_by);
  249. if ($limit) {
  250. $rst->offset(0)->limit($limit);
  251. }
  252. return $rst->get();
  253. }
  254. public function getApplyNumGroup($where, $group_by, $subsite_id)
  255. {
  256. $rst = $this->model->where($where)->select(DB::raw('count(id),DATE(created_at)'))->when($subsite_id!=-1, function($query) use($subsite_id) {
  257. $query->whereHas('members', function ($query) use ($subsite_id) {
  258. $query->where(['subsite_id'=>$subsite_id]);
  259. });
  260. });
  261. if ($group_by) {
  262. $rst->groupBy($group_by);
  263. }
  264. return $rst->get();
  265. }
  266. public function getApplyNum($where, $company_where)
  267. {
  268. return $this->model
  269. ->where($where)
  270. ->when($company_where, function ($query) use ($company_where) {
  271. $query->whereHas('companys', function ($query) use ($company_where) {
  272. $query->where($company_where);
  273. });
  274. })->count();
  275. }
  276. public function getApplyNumByGroup($where, $company_where, $fields, $group_by, $order_by = '')
  277. {
  278. $rst = $this->model->select(DB::raw($fields))->where($where)
  279. ->when($company_where, function ($query) use ($company_where) {
  280. $query->whereHas('companys', function ($query) use ($company_where) {
  281. $query->where($company_where);
  282. });
  283. });
  284. if ($group_by) {
  285. foreach ($group_by as $k => $v) {
  286. $rst->groupBy($v);
  287. }
  288. }
  289. if ($order_by) {
  290. $rst->orderByRaw($order_by);
  291. }
  292. return $rst->get();
  293. }
  294. public function getApplyNumByCompanyGroup($where, $company_where, $fields, $group_by, $order_by = '', $limit = '')
  295. {
  296. $rst = $this->model->with('companys')->select(DB::raw($fields))->where($where)
  297. ->when($company_where, function ($query) use ($company_where) {
  298. $query->whereHas('companys', function ($query) use ($company_where) {
  299. $query->where($company_where);
  300. });
  301. });
  302. if ($group_by) {
  303. foreach ($group_by as $k => $v) {
  304. $rst->groupBy($v);
  305. }
  306. }
  307. if ($order_by) {
  308. $rst->orderByRaw($order_by);
  309. }
  310. if ($limit) {
  311. $rst->offset(0)->limit($limit);
  312. }
  313. return $rst->get();
  314. }
  315. public function getResumeNumBySexGroup($resume_where, $member_where)
  316. {
  317. $rst = $this->model->with(['memberInfos'])->where($resume_where)->when($member_where, function($query) use($member_where) {
  318. $query->whereHas('members', function ($query) use ($member_where) {
  319. $query->where($member_where);
  320. });
  321. })->get();
  322. return $rst;
  323. }
  324. public function getPersonalJobByID($id){
  325. return $this->model->where("id",$id)->first();
  326. }
  327. public function getResumeApplyWithDeleted($where, $member_where)
  328. {
  329. $rst = $this->model
  330. //->withTrashed()
  331. ->where($where)
  332. ->when($member_where, function ($query) use ($member_where) {
  333. $query->whereHas('members', function ($query) use ($member_where) {
  334. //$query->withTrashed()->where($member_where);
  335. $query->where($member_where);
  336. });
  337. })->get();
  338. return $rst;
  339. }
  340. public function getPluck($where,$column)
  341. {
  342. return $this->model->where($where)->pluck($column);
  343. }
  344. }