JobsRepository.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wuzhenke
  5. * Date: 2018/11/6
  6. * Time: 13:18
  7. */
  8. namespace App\Repositories;
  9. use App\Models\Jobs;
  10. use App\Models\JobsContact;
  11. use App\Models\Company;
  12. use App\Models\Category;
  13. use Prettus\Repository\Criteria\RequestCriteria;
  14. use Prettus\Repository\Eloquent\BaseRepository;
  15. use Illuminate\Support\Facades\DB;
  16. class JobsRepository extends BaseRepository
  17. {
  18. /*protected $company;
  19. protected $jobs;*/
  20. /**
  21. * JobsRepository constructor.
  22. */
  23. /*public function __construct(Jobs $jobs, Company $company)
  24. {
  25. $this->company = $company;
  26. $this->jobs = $jobs;
  27. }*/
  28. /**
  29. * Specify Model class name
  30. *
  31. * @return string
  32. */
  33. public function model()
  34. {
  35. return Jobs::class;
  36. }
  37. /**
  38. * Boot up the repository, pushing criteria
  39. */
  40. public function boot()
  41. {
  42. $this->pushCriteria(app(RequestCriteria::class));
  43. }
  44. public function getFires($job_id)
  45. {
  46. return $this->model->where(['id'=>$job_id])->first();
  47. }
  48. public static function countAuditJobsNum()
  49. {
  50. $where['company_id'] = auth('web-company')->user()->id;
  51. $map = [];
  52. if (config('aix.companyset.comset.show_set.jobs_display') == 1) {
  53. $where['audit'] = 1;
  54. } else {
  55. $map[] = ['id','>',0];
  56. }
  57. return Jobs::where($where)->where($map)->count();
  58. }
  59. public function getJobsList($where,$limit = 10)
  60. {
  61. return $this->model->where($where)->paginate($limit);
  62. }
  63. /**
  64. * 根据企业ID获取职位
  65. * @param $company_id
  66. * @return mixed
  67. */
  68. public function getJobsByUid($company_id)
  69. {
  70. return $this->findWhere(['company_id'=>$company_id]);
  71. }
  72. /**
  73. * 根据职位ID获取职位信息
  74. * @param $id
  75. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Model[]|null
  76. */
  77. public function getJobsById($id)
  78. {
  79. return $this->model->with('jobsContact')->with('subsites')->find($id);
  80. }
  81. public function jobsSelect($uid)
  82. {
  83. return $this->model->where('company_id', $uid)->orderBy('created_at', 'asc')->get();
  84. }
  85. public function modifyData($ids, $data)
  86. {
  87. return $this->model->whereIn('id', $ids)->update($data);
  88. }
  89. public function modifyCom($comidArr, $data)
  90. {
  91. return $this->model->whereIn('id', $comidArr)->update($data);
  92. }
  93. /**
  94. * 更新map数据
  95. * @param $id
  96. * @param $data
  97. * @return mixed
  98. */
  99. public function updateMap($id, $data)
  100. {
  101. return $this->model->where('company_id', $id)->update($data);
  102. }
  103. public function updateSubsite($jidArr, $subsite_id)
  104. {
  105. return $this->model->whereIn('id', $jidArr)->update(['subsite_id'=>$subsite_id]);
  106. }
  107. /**
  108. * 职位管理列表
  109. * @param $page
  110. * @param $where
  111. * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
  112. */
  113. public function list($page, $where, $orwhere)
  114. {
  115. return $this->model->with(['promotion'])->where($where)->where(function ($query) use ($orwhere) {
  116. if ($orwhere) {
  117. if (isset($orwhere[3])) {
  118. $query->orWhere('display', $orwhere[0])->orWhere('valid', $orwhere[1])->orWhere('audit', "=", 3);
  119. } else {
  120. $query->orWhere('display', $orwhere[0])->orWhere('valid', $orwhere[1])->orWhere('audit', "<>", $orwhere[2]);
  121. }
  122. }
  123. })->orderByRaw('display asc,audit asc,refresh_time desc')->paginate($page, ['*']);
  124. }
  125. /**
  126. * 某企业发布职位数
  127. * @return mixed
  128. */
  129. public function jobsTotal($where)
  130. {
  131. return $this->model->where($where)->count();
  132. }
  133. /**
  134. * 我是否有这个职位
  135. * @return mixed
  136. * @param $user
  137. * @param $ids
  138. */
  139. public function jobsHas($user,$ids)
  140. {
  141. if (is_string($ids)){
  142. $ids=explode(",",$ids);
  143. }
  144. return $this->model->whereIn("id",$ids)->where('company_id',$user->id)->count();
  145. }
  146. public function jobAuditTotal($where, $audit)
  147. {
  148. return $this->model->where($where)->whereIn('audit',$audit)->count();
  149. }
  150. public function getComJobs($where, $field = '*')
  151. {
  152. return $this->model->select($field)->where($where)->get()->toArray();
  153. }
  154. /**
  155. * 添加职位
  156. * @param $jobData
  157. * @return mixed
  158. */
  159. public function store($jobData)
  160. {
  161. return $this->model->create($jobData);
  162. }
  163. /**
  164. * 关闭职位
  165. * @param $ids
  166. * @return mixed
  167. */
  168. public function closeJobs($ids)
  169. {
  170. return $this->model->whereIn('id', $ids)->update(['display'=>2,'valid'=>0]);
  171. }
  172. /**恢复职位
  173. * @param $ids
  174. * @return mixed
  175. */
  176. public function showJobs($ids, $data)
  177. {
  178. return $this->model->whereIn('id', $ids)->update($data);
  179. }
  180. /**
  181. * 删除职位
  182. * @param $ids
  183. * @return mixed
  184. */
  185. public function delJobs($ids)
  186. {
  187. return $this->model->whereIn('id', $ids)->delete();
  188. }
  189. public function getJobs($id)
  190. {
  191. return $this->model->with('jobsContact')->whereIn('id', $id)->get();
  192. }
  193. public function jobsRefresh($job_id)
  194. {
  195. return $this->update(['refresh_time'=>time()], $job_id);
  196. }
  197. public function findJobsName($jid)
  198. {
  199. return $this->model->whereIn('id', $jid)->select('id', 'jobs_name')->get()->toArray();
  200. }
  201. public function applyJobs($where, $id)
  202. {
  203. return $this->model->where($where)->where('company_id', $id)->select(['id','jobs_name'])->get()->toArray();
  204. }
  205. /**
  206. * 查找职位
  207. * @param $map
  208. * @return mixed
  209. */
  210. public function jobsList($map)
  211. {
  212. return $this->model->select(['id', 'jobs_name'])->where($map)->get();
  213. }
  214. /**
  215. * 获取职位
  216. * @param $where
  217. * @return mixed
  218. */
  219. public function getInfo($where)
  220. {
  221. return $this->model->where($where)->first();
  222. }
  223. //增加点击量
  224. public function incrementData($where, $num, $filed)
  225. {
  226. $model = $this->model->where($where)->first();
  227. $model->click = $model->$filed + $num;
  228. $model->timestamps = false;
  229. return $model->save();
  230. }
  231. //根据条件获取职位列表
  232. public function getOtherJobs($where, $limit = '')
  233. {
  234. // $rst = $this->model->whereHas('subsites', function ($query) { $query->where('subsite_id', get_subsite_id());})->where($where)->orderBy('stime', 'DESC')->orderBy('refresh_time', 'DESC');
  235. $rst = $this->model->where($where)->orderBy('stime', 'DESC')->orderBy('refresh_time', 'DESC');
  236. if ($limit) {
  237. return $rst->paginate($limit);
  238. }else{
  239. return $rst->get();
  240. }
  241. }
  242. public function getCompanyOtherJobs($where,$page=1,$pageSize=6,$category_id=[])
  243. {
  244. $offset = ($page - 1) * $pageSize;
  245. return $this->model->whereHas('subsites', function ($query) {
  246. $query->where('subsite_id', get_subsite_id());
  247. })->where(function ($query) use($where,$category_id){
  248. if($category_id){
  249. $query->whereIn('category',$category_id);
  250. }
  251. $query->where($where);
  252. })->orderBy('stime', 'DESC')->orderBy('refresh_time', 'DESC')->offset($offset)->limit($pageSize)->get();
  253. }
  254. public function getOtherJobsCount($where, $limit = '')
  255. {
  256. $rst = $this->model->where($where)->orderBy('stime', 'DESC')->orderBy('refresh_time', 'DESC');
  257. if ($limit) {
  258. return $rst->paginate($limit);
  259. } else {
  260. return $rst->get();
  261. }
  262. }
  263. //获取符合条件的职位数量
  264. public function getJobsCount($where)
  265. {
  266. return $this->model->whereHas('subsites', function ($query) { $query->where('subsite_id', get_subsite_id());})->where($where)->count();
  267. }
  268. /**
  269. * 获取单条职位(在招的)
  270. * @param $data 条件
  271. * @return bool返回值 如果有返回职位数组,否则返回 false
  272. */
  273. public function getAuditJobsOne($data)
  274. {
  275. $val = $this->model->where($data)->first();
  276. if (!$val) {
  277. return false;
  278. }
  279. $val->contact= JobsContact::where('job_id', $val->id)->first();
  280. $val->deadline_days=($val->deadline-time())>0?"距到期时间还有<strong style=\"color:#FF0000\">".sub_day($val->deadline, time())."</strong>":"<span style=\"color:#FF6600\">目前已过期</span>";
  281. return $val;
  282. }
  283. public function recommendJobs($intenionArrTwo, $intenionArrThree, $page=1, $where, $pageSize=12)
  284. {
  285. $offset = ($page - 1) * $pageSize;
  286. return $this->model->whereIn('audit', $where)->where('display', 1)->where('valid', 1)->where(function ($query) use ($intenionArrTwo, $intenionArrThree) {
  287. $query->whereIn('category', $intenionArrTwo)->orWhereIn('subclass', $intenionArrThree);
  288. })->offset($offset)->limit($pageSize)->get();
  289. }
  290. public function nearbyJobs($lng, $lat, $page=1, $where, $pageSize=12)
  291. {
  292. $offset = ($page - 1) * $pageSize;
  293. return $this->model->whereBetween('map_x', $lng)->whereBetween('map_y', $lat)->whereIn('audit', $where)->where('display', 1)->where('valid', 1)->offset($offset)->limit($pageSize)->get();
  294. }
  295. public function new_jobs($data, $page=1, $where, $pageSize=12)
  296. {
  297. $offset = ($page - 1) * $pageSize;
  298. return $this->model->where('refresh_time', '>', $data)->whereIn('audit', $where)->where('display', 1)->where('valid', 1)->offset($offset)->limit($pageSize)->get();
  299. }
  300. /**
  301. * 获取已关闭/未关闭的职位.
  302. */
  303. public function getDisplayJobs($id, $display)
  304. {
  305. return $this->model->whereIn('id', $id)->where('display', $display)->get()->toArray();
  306. }
  307. public function getLastJobsCount($where)
  308. {
  309. 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();
  310. }
  311. public function getNextJobsCount($where)
  312. {
  313. 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();
  314. }
  315. public function getJobCount($where)
  316. {
  317. return $this->model->where($where)->count();
  318. }
  319. //获取用户中心用于匹配推荐简历的职位
  320. public function getMatchJob($where, $whereNotIn = array(), $order_by = array())
  321. {
  322. $rst = $this->model->where($where);
  323. if ($whereNotIn) {
  324. $rst->whereNotIn(key($whereNotIn), $whereNotIn[key($whereNotIn)]);
  325. }
  326. if (is_array($order_by)) {
  327. foreach ($order_by as $k => $v) {
  328. $rst->orderBy($k, $v);
  329. }
  330. } else {
  331. $rst->orderBy('stime', 'DESC')->orderBy('refresh_time', 'DESC');
  332. }
  333. return $rst->first();
  334. }
  335. //获取有招聘职位的知名企业
  336. public function getJobCompanies($where, $order, $limit = '')
  337. {
  338. $rst = $this->model->whereHas('subsites', function ($query) { $query->where('subsite_id', get_subsite_id());})->select(DB::raw('distinct company_id,count(id) as jobs_num'))->where($where);
  339. if ($order && is_array($order)) {
  340. foreach ($order as $k => $v) {
  341. $rst->orderBy($k, $v);
  342. }
  343. }
  344. $rst->groupBy('company_id');
  345. if ($limit) {
  346. $rst->limit($limit);
  347. }
  348. return $rst->get();
  349. }
  350. public function getCompanyJobs($where = array(), $where_in = array(), $order = array(), $limit = '')
  351. {
  352. $rst = $this->model->with('company')->where($where);
  353. if ($where_in) {
  354. foreach ($where_in as $k => $v) {
  355. $rst->whereIn($k, $v);
  356. }
  357. }
  358. if ($order && is_array($order)) {
  359. foreach ($order as $k => $v) {
  360. $rst->orderBy($k, $v);
  361. }
  362. }
  363. if ($limit) {
  364. $rst->limit($limit);
  365. }
  366. return $rst->get();
  367. }
  368. public function fliterJobs($where = array(), $where_in = array(), $order = array())
  369. {
  370. $rst = $this->model->where($where);
  371. if ($where_in) {
  372. foreach ($where_in as $k => $v) {
  373. $rst->whereIn($k, $v);
  374. }
  375. }
  376. if ($order && is_array($order)) {
  377. foreach ($order as $k => $v) {
  378. $rst->orderBy($k, $v);
  379. }
  380. }
  381. return $rst->get();
  382. }
  383. public function autoRefreshJobs($ids)
  384. {
  385. return $this->model->whereIn('id', $ids)->update(['refresh_time'=>time()]);
  386. }
  387. public function getName($id)
  388. {
  389. return $this->model->where('id', $id)->value('jobs_name');
  390. }
  391. public function getJobNumGroup($where, $company_where, $group_by)
  392. {
  393. return $this->model->select(DB::raw('count(id),DATE(created_at)'))
  394. ->where($where)
  395. ->when($company_where, function ($query) use ($company_where) {
  396. $query->whereHas('company', function ($query) use ($company_where) {
  397. $query->where($company_where);
  398. });
  399. })
  400. ->groupBy($group_by)
  401. ->get();
  402. }
  403. public function getNumsByGroup($where, $company_where, $fields, $group_by = '', $order_by = '', $whereIn = [])
  404. {
  405. $rst = $this->model->select(DB::raw($fields))->where($where)->when($company_where, function ($query) use ($company_where) {
  406. $query->whereHas('company', function ($query) use ($company_where) {
  407. $query->where($company_where);
  408. });
  409. });
  410. if ($whereIn) {
  411. foreach ($whereIn as $k => $v) {
  412. $rst->whereIn($k, $v);
  413. }
  414. }
  415. if ($group_by) {
  416. if (is_array($group_by)) {
  417. foreach ($group_by as $k => $v) {
  418. $rst->groupBy($v);
  419. }
  420. } else {
  421. $rst->groupBy($group_by);
  422. }
  423. }
  424. if ($order_by) {
  425. $rst->orderByRaw($order_by);
  426. }
  427. return $rst->get();
  428. }
  429. public function getJobNumByTradeGroup($where, $fields, $group_by, $order_by = '', $limit = '')
  430. {
  431. $rst = DB::table(Jobs::getTableName().' as j')->select(DB::raw($fields))
  432. ->leftjoin(Company::getTableName().' as c', 'c.id', '=', 'j.company_id')
  433. ->where($where)
  434. ->whereRaw('j.deleted_at is null and c.deleted_at is null')
  435. ->groupBy($group_by);
  436. if ($order_by) {
  437. $rst->orderByRaw($order_by);
  438. }
  439. if ($limit) {
  440. $rst->offset(0)->limit($limit);
  441. };
  442. return $rst->get();
  443. }
  444. public function getAvgWageByGroup($where, $company_where, $fields, $group_by, $order_by, $limit)
  445. {
  446. $rst = $this->model->select(DB::raw($fields))->where($where)->when($company_where, function ($query) use ($company_where) {
  447. $query->whereHas('company', function ($query) use ($company_where) {
  448. $query->where($company_where);
  449. });
  450. });
  451. if ($group_by) {
  452. $rst->groupBy($group_by);
  453. }
  454. if ($order_by) {
  455. $rst->orderByRaw($order_by);
  456. }
  457. if ($limit) {
  458. $rst->offset(0)->limit($limit);
  459. }
  460. return $rst->get();
  461. }
  462. public function getJobIndustryAmount($where, $company_where, $industry_ids)
  463. {
  464. $rst = $this->model->where($where)->when($company_where, function ($query) use ($company_where, $industry_ids) {
  465. $query->whereHas('company', function ($query) use ($company_where, $industry_ids) {
  466. $query->where($company_where);
  467. if ($industry_ids) {
  468. $query->whereIn('industry', $industry_ids);
  469. }
  470. });
  471. });
  472. return $rst->sum('amount');
  473. }
  474. public function getIndustryAmount($where, $company_where, $trades)
  475. {
  476. $rst = $this->model->where($where)->when($company_where, function ($query) use ($company_where, $trades) {
  477. $query->whereHas('company', function ($query) use ($company_where, $trades) {
  478. $query->where($company_where);
  479. if ($trades) {
  480. $query->whereIn('trade', $trades);
  481. }
  482. });
  483. });
  484. return $rst->sum('amount');
  485. }
  486. public function getJobAmountByNature($where, $job_where, $company_where)
  487. {
  488. $rst = DB::table(Jobs::getTableName().' as j')->selectRaw('sum(j.amount) as num, p.nature')
  489. ->leftjoin(Company::getTableName().' as p', 'p.id', '=', 'j.company_id')
  490. ->leftjoin(Category::getTableName().' as c', 'c.id', '=', 'p.nature')
  491. ->where($job_where)
  492. ->where($company_where)
  493. ->whereRaw($where)
  494. ->groupBy('p.nature')
  495. ->orderByRaw('p.nature asc')
  496. ->get();
  497. return $rst;
  498. }
  499. public function getJobAmountByEconomy($where, $job_where, $company_where, $nature_ids)
  500. {
  501. $rst = DB::table(Jobs::getTableName().' as j')
  502. ->selectRaw('IFNULL(sum(j.amount),0) as num, p.economy')
  503. ->leftjoin(Company::getTableName().' as p', 'p.id', '=', 'j.company_id')
  504. ->leftjoin(Category::getTableName().' as c', 'c.id', '=', 'p.economy')
  505. ->where($job_where)
  506. ->where($company_where)
  507. ->whereRaw($where)
  508. ->whereIn('p.nature', $nature_ids)
  509. ->groupBy('p.economy')
  510. ->orderByRaw('p.economy asc')
  511. ->get();
  512. return $rst;
  513. }
  514. public function getJobAmountByEconomyGroup($where, $job_where, $company_where, $fields = 'IFNULL(sum(j.amount),0) as num, p.economy', $group = [], $order = '')
  515. {
  516. $rst = DB::table(Jobs::getTableName().' as j')
  517. ->selectRaw($fields)
  518. ->leftjoin(Company::getTableName().' as p', 'p.id', '=', 'j.company_id')
  519. ->where($job_where)
  520. ->where($company_where);
  521. if ($where) {
  522. $rst->whereRaw($where);
  523. }
  524. if ($group) {
  525. foreach ($group as $k => $v) {
  526. $rst->groupBy($v);
  527. }
  528. }
  529. if ($order) {
  530. $rst->orderByRaw('p.economy asc');
  531. }
  532. $res = $rst->get();
  533. return $res;
  534. }
  535. public function getJobTypeAmount($job_where, $company_where, $types)
  536. {
  537. return $this->model->where($job_where)->when($company_where, function ($query) use ($company_where) {
  538. $query->whereHas('company', function ($query) use ($company_where) {
  539. $query->where($company_where);
  540. });
  541. })->when($types, function ($query) use ($types) {
  542. $query->whereIn('category', $types);
  543. })->sum('amount');
  544. }
  545. public function getJobAmountByType($job_where, $company_where, $whereRaw)
  546. {
  547. return $this->model->where($job_where)->when($company_where, function ($query) use ($company_where) {
  548. $query->whereHas('company', function ($query) use ($company_where) {
  549. $query->where($company_where);
  550. });
  551. })->when($whereRaw, function ($query) use ($whereRaw) {
  552. $query->whereRaw($whereRaw);
  553. })->get();
  554. }
  555. public function getJobAmountByAge($where, $job_where, $company_where, $fields, $group_by = '', $order_by = '')
  556. {
  557. $rst = $this->model->select(DB::raw($fields))->where($job_where)->when($where, function ($query) use ($where) {
  558. $query->whereRaw($where);
  559. })->when($company_where, function ($query) use ($company_where) {
  560. $query->whereHas('company', function ($query) use ($company_where) {
  561. $query->where($company_where);
  562. });
  563. });
  564. if ($group_by) {
  565. $rst->groupBy($group_by);
  566. }
  567. if ($order_by) {
  568. $rst->orderByRaw($order_by);
  569. }
  570. return $rst->get();
  571. }
  572. public function getJobAmountByAges($age_data, $age_text, $ages, $where, $job_where, $company_where, $fields, $group_by = '', $order_by = '')
  573. {
  574. $rst = $this->model->select(DB::raw($fields))->where($job_where)->when($where, function ($query) use ($where) {
  575. $query->whereRaw($where);
  576. })->when($company_where, function ($query) use ($company_where) {
  577. $query->whereHas('company', function ($query) use ($company_where) {
  578. $query->where($company_where);
  579. });
  580. });
  581. if ($group_by) {
  582. $rst->groupBy($group_by);
  583. }
  584. if ($order_by) {
  585. $rst->orderByRaw($order_by);
  586. }
  587. $res = $rst->chunk(500, function ($lave_rst) use (&$age_data, $age_text, $ages) {
  588. if ($lave_rst->isNotEmpty()) {
  589. //处理每条数据所属年龄段
  590. foreach ($lave_rst as $key => $val) {
  591. if ($val->num > 0) {
  592. $j_min_age = $val['min_age'];
  593. $j_max_age = $val['max_age'];
  594. $relative_age_arr = [];
  595. foreach ($ages as $k => $v) {
  596. $min_age = $v['min_age'];
  597. $max_age = $v['max_age'];
  598. if ($j_min_age && $j_max_age) {
  599. if ($j_min_age <= $max_age && $j_max_age>=$min_age) {
  600. $relative_age_arr[] = $age_text[$k];
  601. }
  602. }
  603. }
  604. if ($relative_age_arr) {
  605. //将职位招聘人数平均分配给符合的年龄段,剩余的给第一个符合的年龄段
  606. $lave_quotient = intval(floor($val->num/count($relative_age_arr)));
  607. $lave_remainder = $val->num % count($relative_age_arr);
  608. foreach ($relative_age_arr as $n => $r) {
  609. $age_data[$r] = (int)$age_data[$r] + $lave_quotient;
  610. }
  611. $age_data[$relative_age_arr[0]] = (int)$age_data[$relative_age_arr[0]] + $lave_remainder;
  612. }
  613. }
  614. }
  615. }
  616. });
  617. return $age_data;
  618. }
  619. public function getCrmJobs($where, $where_in = [], $order_by = [], $fileds = '', $offset = '', $limit = '')
  620. {
  621. if ($fileds) {
  622. $rst = $this->model->select(DB::raw($fileds))->where($where);
  623. } else {
  624. $rst = $this->model->where($where);
  625. }
  626. if ($where_in) {
  627. foreach ($where_in as $k => $v) {
  628. $rst->whereIn($k, $v);
  629. }
  630. }
  631. if ($order_by) {
  632. if (is_array($order_by)) {
  633. foreach ($order_by as $k => $v) {
  634. $rst->orderBy($k, $v);
  635. }
  636. } else {
  637. $rst->orderByRaw($order_by);
  638. }
  639. }
  640. if ($offset !='' && $limit!='') {
  641. $rst->offset($offset)->limit($limit);
  642. };
  643. return $rst->get();
  644. }
  645. public function getCrmJobCount($where, $where_in)
  646. {
  647. $rst = $this->model->where($where);
  648. if ($where_in) {
  649. foreach ($where_in as $k => $v) {
  650. $rst->whereIn($k, $v);
  651. }
  652. }
  653. return $rst->count();
  654. }
  655. public function getCrmInfo($where)
  656. {
  657. return $this->model->with(['company','jobsContact'])->where($where)->first();
  658. }
  659. public function getJobNum($where, $company_where)
  660. {
  661. $rst = $this->model->where($where)->when($company_where, function ($query) use ($company_where) {
  662. $query->whereHas('company', function ($query) use ($company_where) {
  663. $query->where($company_where);
  664. });
  665. })->count();
  666. return $rst;
  667. }
  668. public function AdminFind($where,$select){
  669. return $this->model->where($where)->select($select)->first()->toArray();
  670. }
  671. public function getPluck($where,$column)
  672. {
  673. return $this->model->where($where)->pluck($column);
  674. }
  675. }