ResumeRepository.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\Resume;
  4. use App\Models\MemberInfo;
  5. use App\Models\Member;
  6. use Prettus\Repository\Eloquent\BaseRepository;
  7. use Prettus\Repository\Criteria\RequestCriteria;
  8. use Illuminate\Support\Facades\DB;
  9. /**
  10. * Class MemberRepositoryEloquent.
  11. *
  12. * @package namespace App\Repositories;
  13. */
  14. class ResumeRepository extends BaseRepository
  15. {
  16. /**
  17. * Specify Model class name
  18. *
  19. * @return string
  20. */
  21. public function model()
  22. {
  23. return Resume::class;
  24. }
  25. /**
  26. * Boot up the repository, pushing criteria
  27. */
  28. public function boot()
  29. {
  30. $this->pushCriteria(app(RequestCriteria::class));
  31. }
  32. /**
  33. * @param $uid
  34. * @return mixed
  35. */
  36. public function getPersonInfo($uid)
  37. {
  38. return $this->model->where(['uid'=>$uid,'def'=>1])->first();
  39. }
  40. /**
  41. * 获取所有的简历。
  42. */
  43. public function getAllResume($uid)
  44. {
  45. return $this->model->with('resumeEntrusts')->where(['uid'=>$uid])->get();
  46. }
  47. /**
  48. * 获取审核通过的简历。
  49. */
  50. public function getSuccessResume($uid, $data)
  51. {
  52. return $this->model->where(['uid'=>$uid])->whereIn('audit', $data)->get();
  53. }
  54. public function getSuccessResumeByid($where, $data)
  55. {
  56. return $this->model->where($where)->whereIn('audit', $data)->first();
  57. }
  58. public function getSuccessResumeCount($uid, $data)
  59. {
  60. return $this->model->where(['uid'=>$uid])->whereIn('audit', $data)->count();
  61. }
  62. public function resumeAdd($date)
  63. {
  64. return $this->model->create($date);
  65. }
  66. public function getResumeCount($uid)
  67. {
  68. return $this->model->where('uid', $uid)->count();
  69. }
  70. public function getResumeById($id)
  71. {
  72. return $this->model->with('memberInfos')->find($id);
  73. }
  74. public function getOneResume($where)
  75. {
  76. return $this->model->where($where)->first();
  77. }
  78. public function updateById($data, $id)
  79. {
  80. return $this->update($data, $id);
  81. }
  82. public function getArrayById($id)
  83. {
  84. return $this->model->find($id)->toArray();
  85. }
  86. public function resumeShow($id)
  87. {
  88. return $this->model->with('memberInfos')->with('members')->find($id)->toArray();
  89. }
  90. public function delResume($id)
  91. {
  92. return $this->delete($id);
  93. }
  94. public function attentionMe($data)
  95. {
  96. return $this->model->where($data)->get();
  97. }
  98. public function getResumeMemInfo($id)
  99. {
  100. return $this->model->with('memberInfos')->find($id);
  101. }
  102. public function getResume($id)
  103. {
  104. return $this->model->find($id);
  105. }
  106. public function getResumeList($ids)
  107. {
  108. return $this->model->whereIn('id', $ids)->get();
  109. }
  110. public function findResumeList($uidArr)
  111. {
  112. return $this->model->whereIn('uid', $uidArr)->where('def', 1)->orderByRaw("FIELD(uid,".implode(",", $uidArr).")")->paginate(2);
  113. }
  114. //根据条件获取简历信息
  115. public function getResumes($where)
  116. {
  117. return $this->model->where($where)->get();
  118. }
  119. public function getResumeInfo($where)
  120. {
  121. return $this->model->where($where)->orderBy('def','desc')->first();
  122. }
  123. public function getResumesWithInfo($ids)
  124. {
  125. return $this->model->with('memberInfos')->whereIn('id', $ids)->get();
  126. }
  127. public function getResumeBasic($uid, $id)
  128. {
  129. $id=intval($id);
  130. $uid=intval($uid);
  131. $where['uid']=$uid;
  132. $where['id']=$id;
  133. $info = $this->model->where($where)->first();
  134. if (!$info) {
  135. return false;
  136. }
  137. $info->age=date("Y")-$info->birthdate;
  138. $info->number="N".str_pad($info->id, 7, "0", STR_PAD_LEFT);
  139. $info->lastname=$info->fullname;
  140. return $info;
  141. }
  142. public function updateWord($id, $date)
  143. {
  144. return $this->model->where('id', $id)->update($date);
  145. }
  146. public function updateAllResume($id, $date)
  147. {
  148. return $this->model->whereIn('id', $id)->update($date);
  149. }
  150. public function getLastResumeCount($where)
  151. {
  152. return $this->model->where($where)->where('created_at', '>=', date('Y-m-01 00:00:00', strtotime('-1 month')))->where('created_at', '<=', date("Y-m-d 23:59:59", strtotime(-date('d').'day')))->count();
  153. }
  154. public function getNextResumeCount($where)
  155. {
  156. return $this->model->where($where)->where('created_at', '>=', date('Y-m-01 00:00:00', strtotime(date("Y-m-d"))))->where('created_at', '<=', date('Y-m-d 23:59:59', strtotime(date('Y-m-01', strtotime(date("Y-m-d")))." +1 month -1 day")))->count();
  157. }
  158. public function getResumesCount($where)
  159. {
  160. return $this->model->where($where)->count();
  161. }
  162. public function getAuditCount($where)
  163. {
  164. return $this->model->where($where)->count();
  165. }
  166. //增加点击量
  167. public function incrementData($where, $num, $filed)
  168. {
  169. $model = $this->model->where($where)->first();
  170. $model->click = $model->$filed + $num;
  171. $model->timestamps = false;
  172. return $model->save();
  173. }
  174. public function getMatchResume($where, $whereIn = array(), $where_notIn = array(), $orderby = array())
  175. {
  176. $rst = $this->model->where($where);
  177. if ($whereIn && is_array($whereIn)) {
  178. foreach ($whereIn as $k => $v) {
  179. $rst->whereIn($k, $v);
  180. }
  181. }
  182. if ($where_notIn && is_array($where_notIn)) {
  183. foreach ($where_notIn as $k => $v) {
  184. $rst->whereNotIn($k, $v);
  185. }
  186. }
  187. if ($orderby) {
  188. if (is_array($orderby)) {
  189. foreach ($orderby as $k => $v) {
  190. $rst->orderBy($k, $v);
  191. }
  192. } else {
  193. $rst->orderbyRaw($orderby);
  194. }
  195. }
  196. return $rst->first();
  197. }
  198. public function getResumeNumGroup($where, $group_by)
  199. {
  200. return $this->model->where($where)->select(DB::raw('count(id),DATE(created_at)'))->groupBy($group_by)->get();
  201. }
  202. public function getResumeNum($where, $member_where)
  203. {
  204. $rst = $this->model->where($where)->when($member_where, function ($query) use ($member_where) {
  205. $query->whereHas('members', function ($query) use ($member_where) {
  206. $query->where($member_where);
  207. });
  208. })->count();
  209. return $rst;
  210. }
  211. public function getAvgWageByGroup($where, $member_where, $fields, $group_by, $order_by = '', $limit = '')
  212. {
  213. $rst = $this->model->select(DB::raw($fields))->where($where)->when($member_where, function ($query) use ($member_where) {
  214. $query->whereHas('members', function ($query) use ($member_where) {
  215. $query->where($member_where);
  216. });
  217. });
  218. if ($group_by) {
  219. $rst->groupBy($group_by);
  220. }
  221. if ($order_by) {
  222. $rst->orderByRaw($order_by);
  223. }
  224. if ($limit) {
  225. $rst->offset(0)->limit($limit);
  226. }
  227. return $rst->get();
  228. }
  229. public function getNumByClassGroup($where, $member_where, $fields, $group_by, $limit = '', $order_by = '')
  230. {
  231. $rst = $this->model->withTrashed()->select(DB::raw($fields))->where($where)->when($member_where, function ($query) use ($member_where) {
  232. $query->whereHas('members', function ($query) use ($member_where) {
  233. $query->withTrashed()->where($member_where);
  234. });
  235. });
  236. if ($group_by) {
  237. $rst->groupBy($group_by);
  238. }
  239. if ($order_by) {
  240. $rst->orderByRaw($order_by);
  241. }
  242. if ($limit) {
  243. $rst->offset(0)->limit($limit);
  244. }
  245. return $rst->get();
  246. }
  247. public function getResumeNumByClassGroup($where, $member_where, $fields, $group_by, $order_by = '', $limit = '')
  248. {
  249. $top_arr = [];
  250. $second_arr = [];
  251. $rst = $this->model->select(DB::raw($fields))->where($where)->when($member_where, function ($query) use ($member_where) {
  252. $query->whereHas('members', function ($query) use ($member_where) {
  253. $query->where($member_where);
  254. });
  255. });
  256. if ($order_by) {
  257. $rst->orderByRaw($order_by);
  258. }
  259. $res = $rst->chunk(1000, function ($resumes) use (&$top_arr, &$second_arr) {
  260. foreach ($resumes as $k => $resume) {
  261. //处理期望职位所属分类
  262. $id_arr = explode(",", $resume->intention_jobs_id);
  263. foreach ($id_arr as $k => $v) {
  264. $ids = explode('.', $v);
  265. if (array_has($top_arr, $ids[0])) {
  266. $top_arr[$ids[0]] = $top_arr[$ids[0]]+1;
  267. } else {
  268. $top_arr[$ids[0]] = 1;
  269. }
  270. if (array_has($second_arr, $ids[1])) {
  271. $second_arr[$ids[1]] = $second_arr[$ids[1]]+1;
  272. } else {
  273. $second_arr[$ids[1]] = 1;
  274. }
  275. }
  276. }
  277. });
  278. arsort($top_arr);
  279. arsort($second_arr);
  280. if ($limit) {
  281. $top_arr = array_slice($top_arr, 0, $limit, true);
  282. $second_arr = array_slice($second_arr, 0, $limit, true);
  283. }
  284. return ['topClass'=>$top_arr,'secondClass'=>$second_arr];
  285. }
  286. public function getResumeNumByEducationGroup($where, $resume_where, $member_where, $resume_fields, $group_by, $order_by)
  287. {
  288. $resume_rst = DB::table(Resume::getTableName().' as r')->select(DB::raw($resume_fields))
  289. ->leftjoin(MemberInfo::getTableName().' as mu', 'mu.uid', '=', 'r.uid')
  290. ->leftjoin(Member::getTableName().' as m', 'm.id', '=', 'r.uid')
  291. ->where($resume_where)
  292. ->where($member_where)
  293. ->whereRaw($where)
  294. ->groupBy($group_by)
  295. ->orderByRaw($order_by)
  296. ->get();
  297. return $resume_rst;
  298. }
  299. public function getResumeNumsByAgeGroup($where, $resume_where, $member_where, $info_where, $resume_fields, $group_by, $order_by = '')
  300. {
  301. $resume_rst = DB::table(Resume::getTableName().' as r') //->select(DB::raw($resume_fields))
  302. ->leftjoin(MemberInfo::getTableName().' as mu', 'mu.uid', '=', 'r.uid')
  303. ->leftjoin(Member::getTableName().' as m', 'm.id', '=', 'r.uid')
  304. ->where($resume_where)
  305. ->where($member_where)
  306. ->where($info_where)
  307. ->whereRaw($where);
  308. if ($group_by) {
  309. $resume_rst->groupBy($group_by);
  310. }
  311. if ($order_by) {
  312. $resume_rst->orderByRaw($order_by);
  313. }
  314. $rst = $resume_rst->count();
  315. return $rst;
  316. }
  317. public function clearResumeExpires()
  318. {
  319. return $this->model->where('expires','>',0)->where('expires','<',time())->get()->toArray();
  320. }
  321. public function getCrmResumes($where, $whereIn = [])
  322. {
  323. $rst = $this->model->with(['members:id,username,mobile'])->where($where);
  324. if ($whereIn) {
  325. foreach ($whereIn as $k => $v) {
  326. $rst->whereIn($k, $v);
  327. }
  328. }
  329. return $rst->get();
  330. }
  331. public function getResumeNumByGroup($resume_where, $member_where, $info_where, $resume_fields, $group_by, $order_by = '')
  332. {
  333. $where = 'r.deleted_at is null and mu.deleted_at is null and m.deleted_at is null';
  334. $resume_rst = DB::table(Resume::getTableName().' as r')->select(DB::raw($resume_fields))
  335. ->leftjoin(MemberInfo::getTableName().' as mu', 'mu.uid', '=', 'r.uid')
  336. ->leftjoin(Member::getTableName().' as m', 'm.id', '=', 'r.uid')
  337. ->where($resume_where)
  338. ->where($member_where)
  339. ->where($info_where)
  340. ->whereRaw($where);
  341. if ($group_by) {
  342. $resume_rst->groupBy($group_by);
  343. }
  344. if ($order_by) {
  345. $resume_rst->orderByRaw($order_by);
  346. }
  347. $rst = $resume_rst->get();
  348. return $rst;
  349. }
  350. }