DapingController.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  1. <?php
  2. namespace App\Http\Controllers\Web\Hardware\Tv;
  3. use App\Http\Controllers\Web\WebBaseController;
  4. use App\Models\CategoryJobs;
  5. use App\Models\Company;
  6. use App\Models\Jobs;
  7. use App\Models\Member;
  8. use App\Models\PersonalTalent;
  9. use App\Models\Resume;
  10. use Illuminate\Http\Request;
  11. use Illuminate\Support\Facades\DB;
  12. use Encore\Admin\Facades\Admin;
  13. class DapingController extends WebBaseController
  14. {
  15. public $view_data = null;
  16. public $SUBSITE_ON = null;
  17. public $subsite_id = null;
  18. public $request_method = null;
  19. public $is_ajax = null;
  20. public $province = null;
  21. public $city = null;
  22. public function __construct(Request $request)
  23. {
  24. $this->view_data = null;
  25. $this->SUBSITE_ON = config('aix.SUBSITE_ON');
  26. $this->subsite_id = session('caiqing_susbite_id');
  27. $this->request_method = $request->method();
  28. $this->is_ajax = $request->ajax();
  29. $this->province = config('aix.province');
  30. $this->city = config('aix.city');
  31. }
  32. public function index(Request $request)
  33. {
  34. $news = $this->getNews($request);
  35. $overview = $this->getOverview($request);
  36. $talent = $this->getTalent($request);
  37. $demand = $this->getDemand($request);
  38. $demand2 = $this->getDemand2();
  39. $trend = $this->getTrend($request);
  40. $right_data = $this->get_right_data();
  41. // return $this->view_data;
  42. return view('app.hardware.tv.daping', $this->view_data);
  43. }
  44. //获取新增数据
  45. public function getNews(Request $request)
  46. {
  47. $mon = $request->input('mon', '0');
  48. // $mon = I('request.mon','0','intval');
  49. $where = [];
  50. $where2 = [];
  51. //加入分站条件
  52. if ($this->SUBSITE_ON == true) {
  53. if (!empty($this->subsite_id)) {
  54. $where['subsite_id'] = $this->subsite_id;
  55. $where2['subsite_id'] = $this->subsite_id;
  56. }
  57. }
  58. //php获取今日开始时间戳和结束时间戳
  59. $end_day = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1;
  60. $end_day = date('Y-m-d H:i:s', $end_day);
  61. if (($mon >= 0)) {
  62. if ($mon == '0') { //获取年初到现在的数据
  63. $pre_start = mktime(0, 0, 0, 1, 1, date('Y'));
  64. } elseif ($mon > 0) { //获取距离当前日期$mon个月的数据
  65. $pre_start = strtotime(date('Y-m-d', strtotime("-" . $mon . " month")));
  66. }
  67. } else if ($mon == '-1') { //获取所有数据
  68. $pre_start = null;
  69. $pre_end = null;
  70. }
  71. $pre_start = date('Y-m-d H:i:s', $pre_start);
  72. //获取个人会员注册数
  73. if ($mon >= 0) {
  74. $where_person_add[] = ['created_at', '>=', $pre_start];
  75. $where_person_add[] = ['created_at', '<=', $end_day];
  76. } else {
  77. $where_person_add[] = ['created_at', '<=', $end_day];
  78. }
  79. // $personal_member_num = M("members")->where($where_person_add)->where($where)->count();
  80. $personal_member_num = Member::where($where_person_add)->where($where)->count();
  81. //获取企业会员注册数
  82. if ($mon >= 0) {
  83. $where_company_add[] = ['created_at', '>=', $pre_start];
  84. $where_company_add[] = ['created_at', '<=', $end_day];
  85. } else {
  86. $where_company_add[] = ['created_at', '<=', $end_day];
  87. }
  88. // $company_member_num = M("members")->where($where_company_add)->where($where)->count();
  89. $company_member_num = Company::where($where_company_add)->where($where)->count();
  90. //新增职位
  91. $where_job_add = null;
  92. if ($mon >= 0) {
  93. $where_job_add[] = ['created_at', '>=', $pre_start];
  94. $where_job_add[] = ['created_at', '<=', $end_day];
  95. } else {
  96. $where_job_add[] = ['created_at', '<=', $end_day];
  97. }
  98. // $job_infos = M("jobs")->where($where_job_add)->where($where)->field('COUNT(*) AS job_num ,SUM(amount) as amount_num')->find();
  99. $job_num = Jobs::where($where_job_add)
  100. ->where($where)
  101. ->count();
  102. $amount_num = Jobs::where($where_job_add)
  103. ->where($where)
  104. ->sum('amount');
  105. if ($request->isMethod('post')) {
  106. $return_data = array('company_member_num' => $company_member_num, 'personal_member_num' => $personal_member_num, 'job_info' => $job_infos);
  107. return json_encode($return_data);
  108. } else {
  109. // $this->assign('company_member_num', $company_member_num);
  110. // $this->assign('personal_member_num', $personal_member_num);
  111. // $this->assign('job_num', $job_infos['job_num']);
  112. // $this->assign('amount_num', $job_infos['amount_num'] ? $job_infos['amount_num'] : 0);
  113. $this->view_data['company_member_num'] = $company_member_num;
  114. $this->view_data['personal_member_num'] = $personal_member_num;
  115. if ($job_num) {
  116. $this->view_data['job_num'] = $job_num;
  117. } else {
  118. $this->view_data['job_num'] = 0;
  119. }
  120. if ($amount_num) {
  121. $this->view_data['amount_num'] = $amount_num;
  122. } else {
  123. $this->view_data['amount_num'] = 0;
  124. }
  125. }
  126. }
  127. public function getEdvisiteducations(Request $request)
  128. {
  129. if (config('aix.SUBSITE_ON') == true) {
  130. $subsite_id = session('caiqing_susbite_id');
  131. if ($subsite_id >= 0) {
  132. $where_subsite = " and subsite_id = " . $subsite_id . "";
  133. } else {
  134. $where_subsite = "";
  135. }
  136. } else {
  137. $where_subsite = '';
  138. }
  139. $sql = "SELECT COUNT(*) AS num,b.c_name as c_name from resumes as a join categorys as b on a.education=b.c_id where b.c_alias='AIX_education' $where_subsite GROUP BY a.education order by num desc";
  140. $dataObj = DB::select($sql);
  141. $i = 0;
  142. $edata_str = "";
  143. $edata_pic = "";
  144. if ($request->isMethod('post')) {
  145. $str_arr = array();
  146. $edu_arr = array();
  147. foreach ($dataObj as $key => $value) {
  148. $edu_arr[] = array('value' => intval($value['num']), 'name' => $value['c_name']);
  149. $str_arr[] = $value['c_name'];
  150. }
  151. $data['edu_str'] = $str_arr;
  152. $data['edu_arr'] = $edu_arr;
  153. if ($str_arr && $edu_arr) {
  154. $data['status'] = 1;
  155. } else {
  156. $data['status'] = 0;
  157. }
  158. return json_encode($data);
  159. } else {
  160. foreach ($dataObj as $key => $value) {
  161. if (empty($edata_pic)) {
  162. $edata_pic = "{value:" . intval($value['num']) . ",name:'" . $value['c_name'] . "'}";
  163. } else {
  164. $edata_pic = $edata_pic . "," . "{value:" . intval($value['num']) . ",name:'" . $value['c_name'] . "'}";
  165. }
  166. if (empty($edata_str)) {
  167. $edata_str = "'" . $value['c_name'] . "'";
  168. } else {
  169. $edata_str = $edata_str . ',' . "'" . $value['c_name'] . "'";
  170. }
  171. $i++;
  172. }
  173. // $this->assign('edata_str',$edata_str);
  174. // $this->assign('edata',$edata_pic);
  175. $this->view_data['edata_str'] = $edata_str;
  176. $this->view_data['edata'] = $edata_pic;
  177. }
  178. }
  179. public function getTalent(Request $request)
  180. {
  181. //加入分站条件
  182. if ($this->SUBSITE_ON == true) {
  183. if ($this->subsite_id === false) {
  184. $where = [];
  185. } else {
  186. if (!empty($this->subsite_id)) {
  187. $where[] = ['subsite_id', '=', $this->subsite_id];
  188. }
  189. }
  190. } else {
  191. $where = [];
  192. }
  193. //日期范围
  194. // $mon = I('request.mon', '0', 'intval');
  195. $mon = $request->input('request.mon', '0');
  196. $now_date = date('Y-m-d', time());
  197. if ($mon == 0) {
  198. $start_time = mktime(0, 0, 0, 1, 1, date('Y'));
  199. } else if ($mon > 0) {
  200. $start_time = date('Y-m-d', strtotime("-" . $mon . " month"));
  201. } else {
  202. $start_time = null;
  203. }
  204. $min = date('Y-m-d H:i:s', $start_time);
  205. $max = date('Y-m-d H:i:s', strtotime($now_date) + 60 * 60 * 24 - 1);
  206. // $category = M('category_jobs')->where("parentid=0")->select();
  207. $category = CategoryJobs::where('parent_id', '0')->get();
  208. $minNum = 0;
  209. $minusArr = array(); //职位分类和差异数
  210. foreach ($category as $key => $value) {
  211. if (strstr($value['categoryname'], '其他') === false && strstr($value['categoryname'], '其它') === false) {
  212. $minusArr[$key]['label'] = $value['name'];
  213. if ($min && $max) {
  214. $where[] = ['created_at', '>=', $min];
  215. $where[] = ['created_at', '<=', $max];
  216. } else {
  217. $where[] = ['created_at', '>=', $min];
  218. }
  219. $job_count = Jobs::where($where)
  220. ->where('topclass', '=', $value['id'])
  221. ->sum('amount');
  222. $dataObj = Resume::where($where)
  223. ->pluck('intention_jobs_id');
  224. $num = 0;
  225. foreach ($dataObj as $key1 => $value1) {
  226. $j = explode(",", $value1);
  227. $c = explode(".", $j[0]);
  228. if ($c[0] == $value['id']) {
  229. $num++;
  230. }
  231. }
  232. $resume_jobs = $num;
  233. $minusArr[$key]['value'] = $job_count - $resume_jobs;
  234. if ($minusArr[$key]['value'] < $minNum) {
  235. $minNum = $minusArr[$key]['value'];
  236. }
  237. }
  238. }
  239. $dArr = array();
  240. $item = 0;
  241. foreach ($minusArr as $key => $value) {
  242. $dArr[$item]['label'] = $value['label'];
  243. $dArr[$item]['value'] = $value['value'];
  244. $item++;
  245. }
  246. usort($dArr, function ($a, $b) {
  247. $al = $a['value'];
  248. $bl = $b['value'];
  249. if ($al == $bl)
  250. return 0;
  251. return ($al > $bl) ? -1 : 1;
  252. });
  253. $cate_names = array();
  254. $cate_values = array();
  255. foreach ($dArr as $k => $v) {
  256. $cate_names[] = $v['label'];
  257. $cate_values[] = $v['value'];
  258. }
  259. if ($this->is_ajax || $this->request_method == 'post') {
  260. return json_encode($dArr);
  261. } else {
  262. // $this->assign('category', $category);
  263. // $this->assign("minNum", $minNum);
  264. // $this->assign('data', $dArr);
  265. // $this->assign('cate_names', json_encode($cate_names));
  266. // $this->assign('cate_values', json_encode($cate_values));
  267. $this->view_data['category'] = $category;
  268. $this->view_data['minNum'] = $minNum;
  269. $this->view_data['data'] = $dArr;
  270. $this->view_data['cate_names'] = json_encode($cate_names);
  271. $this->view_data['cate_values'] = json_encode($cate_values);
  272. }
  273. }
  274. /*趋势分析
  275. * 开始时间和结束时间不在同一年时显示12个月的数据
  276. * 逻辑:没间隔一年显示一组数据
  277. */
  278. public function getTrend(Request $request)
  279. {
  280. // $mon = I('request.mon', '0', 'intval');
  281. $mon = $request->input('request.mon', '0');
  282. $now_date = date('Y-m-d', time());
  283. if ($mon == 0) {
  284. $start_time = mktime(0, 0, 0, 1, 1, date('Y'));
  285. } else if ($mon > 0) {
  286. $start_time = date('Y-m-d', strtotime("-" . $mon . " month"));
  287. } else {
  288. $start_time = null;
  289. }
  290. $min = strtotime($start_time);
  291. $max = strtotime($now_date) + 60 * 60 * 24 - 1;
  292. $start_year = date('Y', $min);
  293. $start_month = date('n', $min);
  294. $end_year = date('Y', $max);
  295. $end_month = date('n', $max);
  296. //同一年显示一组数据,不同年显示多条12个的数据
  297. $month_data = array();
  298. $legend_data = array();
  299. $chart_data = array();
  300. if ($start_year == $end_year) {
  301. $date_where = array(
  302. 'start_date' => $min,
  303. 'end_date' => $max,
  304. );
  305. $res = $this->getTrendData($date_where);
  306. $chart_data[] = $res;
  307. $legend_data[] = $start_year . '年求职人数';
  308. //X轴坐标
  309. for ($j = $start_month; $j <= $end_month; $j++) {
  310. $month_data[] = $j . '月';
  311. }
  312. } else {
  313. $y_num = $end_year - $start_year; //间隔年数
  314. for ($i = 0; $i <= $y_num; $i++) {
  315. if ($i == 4) {
  316. break;
  317. }
  318. $start = (string)($end_year - $i) . '-01-01';
  319. $end = (string)($end_year - $i + 1) . '-01-01';
  320. $date_where = array(
  321. 'start_date' => strtotime($start),
  322. 'end_date' => strtotime($end) - 1,
  323. );
  324. $res = $this->getTrendData($date_where);
  325. $chart_data[] = $res;
  326. $legend_data[] = ($end_year - $i) . '年求职人数';
  327. }
  328. $month_data = array('1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月');
  329. }
  330. $chart_data_str = '[';
  331. $chart_data_arr = array();
  332. if ($chart_data) {
  333. foreach ($chart_data as $k => $v) {
  334. $chart_data_arr[] = "{name:'" . $v['name'] . "',type:'" . $v['type'] . "',data:[" . implode(',', $v['data']) . "], symbolSize:'" . $v['symbolSize'] . "',}";
  335. }
  336. }
  337. $chart_data_str .= implode(',', $chart_data_arr) . ']';
  338. if ($this->request_method == 'post' || $this->is_ajax) {
  339. $return_data = array('legend_data' => $legend_data, 'chart_data' => $chart_data, 'month_data' => $month_data);
  340. return json_encode($return_data);
  341. } else {
  342. // $this->assign('legend_data', json_encode($legend_data));
  343. // $this->assign('chart_data', $chart_data_str);
  344. // $this->assign('month_data', json_encode($month_data));
  345. $this->view_data['legend_data'] = $legend_data;
  346. $this->view_data['chart_data'] = $chart_data_str;
  347. $this->view_data['month_data'] = $month_data;
  348. }
  349. }
  350. public function getTrendData($map)
  351. {
  352. $where = [];
  353. $where2 = [];
  354. if ($this->SUBSITE_ON == true) {
  355. if ($this->subsite_id !== false) {
  356. if ($this->subsite_id >= 0) {
  357. $where['subsite_id'] = $this->subsite_id;
  358. $where2['subsite_id'] = $this->subsite_id;
  359. }
  360. }
  361. }
  362. $min_date = $map['start_date'];
  363. $max_date = $map['end_date'];
  364. //只选了一个时间的情况,不做对比
  365. $start_year = date('Y', $min_date);
  366. $end_year = date('Y', $max_date);
  367. $start_month = date('n', $min_date);
  368. $end_month = date('n', $max_date);
  369. $val_data = array();
  370. for ($i = $start_month; $i <= $end_month; $i++) {
  371. $min = strtotime($start_year . '-' . $i);
  372. if ($i == 12) {
  373. $max = strtotime(($end_year + 1) . '-1');
  374. } else {
  375. $max = strtotime($end_year . '-' . ($i + 1));
  376. }
  377. $admin = Admin::user();
  378. if (!empty($admin)) {
  379. if ($admin->role_id == 3) {
  380. $where['district'] = $this->province;
  381. } else if ($admin->role_id == 4) {
  382. $where['sdistrict'] = $this->city;
  383. } else if ($admin->role_id == 5) {
  384. $where['user_id'] = $admin->id;
  385. }
  386. }
  387. // $where['addtime'] = array(array('>=', $min), array('<=', $max), 'and');
  388. $where[] = ['created_at', '>=', $min];
  389. $where[] = ['created_at', '<=', $max];
  390. $resume_count = Resume::where($where)->count();
  391. $val_data[] = $resume_count;
  392. }
  393. $resumeArr = array(
  394. 'name' => $start_year . '年求职人数',
  395. 'type' => 'line',
  396. 'data' => $val_data,
  397. 'symbolSize' => '10',
  398. );
  399. return $resumeArr;
  400. }
  401. public function getDemand(Request $request)
  402. {
  403. // $mon = I('request.mon', '0', 'intval');
  404. //加入分站条件
  405. $where = [];
  406. if ($this->SUBSITE_ON == true) {
  407. if (!empty($this->subsite_id)) {
  408. $where['subsite_id'] = $this->subsite_id;
  409. }
  410. }
  411. $category = CategoryJobs::where('parent_id', '=', '0')->limit(7)->get();
  412. $month_array = ['1' => '一月', '2' => '二月', '3' => '三月', '4' => '四月', '5' => '五月', '6' => '六月', '7' => '七月', '8' => '八月', '9' => '九月', '10' => '十月', '11' => '十一月', '12' => '十二月'];
  413. $prev_date_start = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m") - 1, 1, date("Y")));
  414. $prev_date_end = date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), 0, date("Y")));
  415. $prev_two_date_start = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m") - 2, 1, date("Y")));
  416. $prev_two_date_end = date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), -1, date("Y")));
  417. $prev_two_month_str = $month_array[date('n', strtotime($prev_two_date_start))];
  418. $prev_month_str = $month_array[date('n', strtotime($prev_date_start))];
  419. // $model_jobs = M('jobs', 'qs_', 'DB_PRIMARY');
  420. $data = [];
  421. foreach ($category as $key => $value) {
  422. switch ($key) {
  423. case 0;
  424. $catename = '单位负责人';
  425. break;
  426. case 1;
  427. $catename = '专业技术人员';
  428. break;
  429. case 2;
  430. $catename = '办事人员和有关人员';
  431. break;
  432. case 3;
  433. $catename = '商业和服务业人员';
  434. break;
  435. case 4;
  436. $catename = '农林牧渔水利生产人员';
  437. break;
  438. case 5;
  439. $catename = '生产运输设备操作工';
  440. break;
  441. case 6;
  442. $catename = '其他';
  443. break;
  444. default;
  445. $catename = '未知';
  446. break;
  447. }
  448. $data[] = [
  449. 'catename' => $catename,
  450. 'name' => $value->name,
  451. 'total_jobs' => Jobs::where($where)
  452. ->where('topclass', '=', $value->id)
  453. ->where('created_at', '>=', $prev_date_start)
  454. ->where('created_at', '<=', $prev_date_end)
  455. ->count(),
  456. 'total_resume' => Jobs::where($where)
  457. ->where('created_at', '>=', $prev_two_date_start)
  458. ->where('created_at', '<=', $prev_two_date_end)
  459. ->count(),
  460. ];
  461. }
  462. //计算需求合计
  463. $total_jobs = 0;
  464. foreach ($data as $k => $v) {
  465. $total_jobs += $v['total_jobs'];
  466. }
  467. //计算求职合计
  468. $total_resume = 0;
  469. foreach ($data as $k => $v) {
  470. $total_resume += $v['total_resume'];
  471. }
  472. //格式化图表分类数据
  473. $categories = array();
  474. foreach ($data as $k => $v) {
  475. $categories[] = $v['catename'];
  476. }
  477. //格式化图表需要的数据
  478. $dataValue = array();
  479. $resume_value = array();
  480. $multiple_value = array();
  481. foreach ($data as $k => $v) {
  482. $dataValue[] = $v['total_jobs'];
  483. $resume_value[] = $v['total_resume'];
  484. $total_name[] = $v['name'];
  485. }
  486. if ($this->request_method == 'post' || $this->is_ajax) {
  487. $return_data = array('data_charts' => $dataValue, 'data_charts2' => $resume_value, 'categories' => $categories, 'multiple' => $multiple_value);
  488. return $return_data;
  489. } else {
  490. // $this->assign('data_charts', json_encode($dataValue));
  491. // $this->assign('data_charts2', json_encode($resume_value));
  492. // $this->assign('total_name', json_encode($total_name));
  493. // $this->assign('prev_month_str', json_encode($prev_month_str));
  494. // $this->assign('prev_two_month_str', json_encode($prev_two_month_str));
  495. // $this->assign('multiple', json_encode($multiple_value));
  496. // $this->assign('categories', json_encode($categories));
  497. $this->view_data['data_charts'] = json_encode($dataValue);
  498. $this->view_data['data_charts2'] = json_encode($resume_value);
  499. $this->view_data['total_name'] = json_encode($total_name);
  500. $this->view_data['prev_month_str'] = json_encode($prev_month_str);
  501. $this->view_data['prev_two_month_str'] = json_encode($prev_two_month_str);
  502. $this->view_data['multiple'] = json_encode($multiple_value);
  503. $this->view_data['categories'] = $categories;
  504. }
  505. }
  506. public function getDemand2()
  507. {
  508. // $mon = I('request.mon', '0', 'intval');
  509. //加入分站条件
  510. $where = [];
  511. if ($this->SUBSITE_ON == true) {
  512. if (!empty($this->subsite_id)) {
  513. if ($this->subsite_id >= 0) {
  514. $where['subsite_id'] = $this->subsite_id;
  515. } else {
  516. $where = [];
  517. }
  518. }
  519. }
  520. $month_array = ['1' => '一月', '2' => '二月', '3' => '三月', '4' => '四月', '5' => '五月', '6' => '六月', '7' => '七月', '8' => '八月', '9' => '九月', '10' => '十月', '11' => '十一月', '12' => '十二月'];
  521. $prev_date_start = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m") - 1, 1, date("Y")));
  522. $prev_date_end = date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), 0, date("Y")));
  523. $prev_two_date_start = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m") - 2, 1, date("Y")));
  524. $prev_two_date_end = date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), -1, date("Y")));
  525. $prev_two_month_str2 = $month_array[date('n', strtotime($prev_two_date_start))];
  526. $prev_month_str2 = $month_array[date('n', strtotime($prev_date_start))];
  527. $ids = [
  528. 802 => '第一类人才',
  529. 803 => '第二类人才',
  530. 804 => '第三类人才',
  531. 805 => '第四类人才',
  532. 806 => '第五类人才',
  533. 0 => '不符合人才标准'
  534. ];
  535. foreach ($ids as $key => $value) {
  536. $data[] = [
  537. 'name' => $value,
  538. 'total_jobs' => PersonalTalent::where($where)
  539. ->where("rc_level_id", '=', $key)
  540. ->where('created_at', '>=', $prev_date_start)
  541. ->where('created_at', '<=', $prev_date_end)
  542. ->count(),
  543. 'total_resume' => PersonalTalent::where($where)
  544. ->where("rc_level_id", '=', $key)
  545. ->where('created_at', '>=', $prev_two_date_start)
  546. ->where('created_at', '<=', $prev_two_date_end)
  547. ->count(),
  548. ];
  549. }
  550. //计算需求合计
  551. $total_jobs = 0;
  552. foreach ($data as $k => $v) {
  553. $total_jobs += $v['total_jobs'];
  554. }
  555. //计算求职合计
  556. $total_resume = 0;
  557. foreach ($data as $k => $v) {
  558. $total_resume += $v['total_resume'];
  559. }
  560. //格式化图表分类数据
  561. //格式化图表需要的数据
  562. $dataValue = array();
  563. $resume_value = array();
  564. $multiple_value = array();
  565. foreach ($data as $k => $v) {
  566. $dataValue[] = $v['total_jobs'];
  567. $resume_value[] = $v['total_resume'];
  568. $total_name[] = $v['name'];
  569. }
  570. // var_dump(json_encode($total_name));
  571. // exit();
  572. if ($this->is_ajax || $this->request_method == 'post') {
  573. $return_data = array('data_charts' => $dataValue, 'data_charts2' => $resume_value, 'multiple' => $multiple_value);
  574. return $return_data;
  575. } else {
  576. // $this->assign('data_charts3', json_encode($dataValue));
  577. // $this->assign('data_charts4', json_encode($resume_value));
  578. // $this->assign('total_name2', json_encode($total_name));
  579. // $this->assign('prev_month_str2', json_encode($prev_month_str2));
  580. // $this->assign('prev_two_month_str2', json_encode($prev_two_month_str2));
  581. // $this->assign('multiple', json_encode($multiple_value));
  582. $this->view_data['data_charts3'] = json_encode($dataValue);
  583. $this->view_data['data_charts4'] = json_encode($resume_value);
  584. $this->view_data['total_name2'] = json_encode($total_name);
  585. $this->view_data['prev_month_str2'] = json_encode($prev_month_str2);
  586. $this->view_data['prev_two_month_str2'] = json_encode($prev_two_month_str2);
  587. $this->view_data['multiple'] = json_encode($multiple_value);
  588. }
  589. }
  590. public function getEducations()
  591. {
  592. // $a = [array('value' => 1037, 'name' => "本科"),
  593. // array('value' => 222, 'name' => "大专"),
  594. // array('value' => 70, 'name' => "中专"),
  595. // array('value' => 63, 'name' => "高中"),
  596. // array('value' => 39, 'name' => "初中"),
  597. // array('value' => 35, 'name' => "硕士"),
  598. // array('value' => 17, 'name' => "中技"),
  599. // array('value' => 3, 'name' => "博士"),
  600. // array('value' => 2, 'name' => "博后")];
  601. // $b = ["本科", "大专", "中专", "高中", "初中", "硕士", "中技", "博士", "博后"];
  602. // return ['edu_arr' => $a, 'edu_str' => $b, 'status' => 1];
  603. $where_subsite = '';
  604. if ($this->SUBSITE_ON == true) {
  605. if (!empty($this->subsite_id)) {
  606. $where_subsite = " and subsite_id = " . $this->subsite_id . "";
  607. }
  608. }
  609. $sql = "SELECT COUNT(*) AS num,b.demand as demand from resumes as a join categorys as b on a.education=b.id where b.alias='AIX_education' $where_subsite GROUP BY a.education order by num desc";
  610. $dataObj = DB::select($sql);
  611. $str_arr = array();
  612. $edu_arr = array();
  613. foreach ($dataObj as $key => $value) {
  614. $edu_arr[] = array('value' => intval($value->num), 'name' => $value->demand);
  615. $str_arr[] = $value->demand;
  616. }
  617. $data['edu_str'] = $str_arr;
  618. $data['edu_arr'] = $edu_arr;
  619. if ($str_arr && $edu_arr) {
  620. $data['status'] = 1;
  621. } else {
  622. $data['status'] = 0;
  623. }
  624. return json_encode($data);
  625. }
  626. // 年龄分布
  627. public function get_right_data()
  628. {
  629. //添加筛选条件
  630. $where = [];
  631. if ($this->SUBSITE_ON == true) {
  632. if (!empty($this->subsite_id)) {
  633. $where['subsite_id'] = $this->subsite_id;
  634. }
  635. }
  636. // $model_resume = M('resume', 'qs_', 'DB_PRIMARY');
  637. $now_year = date('Y');
  638. $data = array();
  639. $for_data = array(
  640. ['district_cn' => "晋江市", 'age' => "31-40岁", 'max' => 40, 'min' => 31, 'district' => 568],
  641. ['district_cn' => "泉州市", 'age' => "26-30岁", 'max' => 30, 'min' => 26, 'district' => 573],
  642. ['district_cn' => "石狮市", 'age' => "23-25岁", 'max' => 25, 'min' => 23, 'district' => 570],
  643. ['district_cn' => "福清市", 'age' => "41-50岁", 'max' => 50, 'min' => 41, 'district' => 540],
  644. ['district_cn' => "长乐市", 'age' => "51-60岁", 'max' => 60, 'min' => 51, 'district' => 539],
  645. ['district_cn' => "思明区", 'age' => "18-22岁", 'max' => 22, 'min' => 18, 'district' => 551],
  646. );
  647. foreach ($for_data as $key => $value) {
  648. $data[] = [
  649. 'district_cn' => $value['district_cn'],
  650. 'age' => $value['age'],
  651. 'total_man' => Resume::distinct()->where($where)
  652. ->where('birthdate', '>', $now_year - $value['max'])
  653. ->where('birthdate', '<=', $now_year - $value['min'])
  654. ->where('sex', '=', 1)
  655. ->count(),
  656. 'total_women' => Resume::distinct()->where($where)
  657. ->where('birthdate', '>', $now_year - $value['max'])
  658. ->where('birthdate', '<=', $now_year - $value['min'])
  659. ->where('sex', '=', 2)
  660. ->count(),
  661. 'total_district' => Resume::distinct()->where($where)
  662. ->where('district', 'like', '%' . $value['district'] . '%')
  663. ->where('display', '1')
  664. ->count(),
  665. 'total_district2' => Resume::distinct()->where($where)
  666. ->where('district', 'like', '%' . $value['district'] . '%')
  667. ->where('display', '0')
  668. ->count(),
  669. ];
  670. }
  671. foreach ($data as $k => $v) {
  672. $district_cn[] = $v['district_cn'];
  673. $age[] = $v['age'];
  674. $total_man[] = $v['total_man'];
  675. $total_women[] = $v['total_women'];
  676. $total_district[] = $v['total_district'];
  677. $total_district2[] = $v['total_district2'];
  678. }
  679. // $this->assign('district_cn', json_encode($district_cn));
  680. // $this->assign('age', json_encode($age));
  681. // $this->assign('total_man', json_encode($total_man));
  682. // $this->assign('total_women', json_encode($total_women));
  683. // $this->assign('total_district', json_encode($total_district));
  684. // $this->assign('total_district2', json_encode($total_district2));
  685. $this->view_data['district_cn'] = json_encode($district_cn, true);
  686. $this->view_data['age'] = json_encode($age, true);
  687. $this->view_data['total_man'] = json_encode($total_man);
  688. $this->view_data['total_women'] = json_encode($total_women);
  689. $this->view_data['total_district'] = json_encode($total_district);
  690. $this->view_data['total_district2'] = json_encode($total_district2);
  691. }
  692. public function getCompetition(Request $request)
  693. {
  694. $mon = I('request.mon', '0', 'intval');
  695. $now_date = date('Y-m-d', time());
  696. if ($mon == 0) {
  697. $start_date = mktime(0, 0, 0, 1, 1, date('Y'));
  698. } else if ($mon > 0) {
  699. $start_time = date('Y-m-d', strtotime("-" . $mon . " month"));
  700. } else {
  701. $start_time = null;
  702. }
  703. //日期范围
  704. $min = strtotime($start_time);
  705. $max = strtotime($now_date) + 60 * 60 * 24 - 1;
  706. //添加筛选条件
  707. if (C('SUBSITE_ON') == true) {
  708. if ($this->subsite_id === false) {
  709. $where = [];
  710. } else {
  711. if ($this->subsite_id >= 0) {
  712. $where['subsite_id'] = $this->subsite_id;
  713. } else {
  714. $where['subsite_id'] = array('IN', '0,1,2,3,4,5');
  715. }
  716. }
  717. } else {
  718. $where = [];
  719. }
  720. if ($this->role_id == 3) {
  721. $condition = " and a.district = " . $this->province . "";
  722. } else if ($this->role_id == 4) {
  723. $condition = " and a.sdistrict = " . $this->city . "";
  724. } else if ($this->role_id == 5) {
  725. $condition = " and a.user_id = " . $this->uid . "";
  726. } else {
  727. $condition = "";
  728. }
  729. $tradeData = M('category_jobs')->where("parentid=0")->select();
  730. foreach ($tradeData as $key => $value) {
  731. $cidArr[] = $value['id'];
  732. }
  733. $cidStr = implode(',', $cidArr);
  734. $tradeArr = array();
  735. if ($min && $max) {
  736. $wheresql = " and apply_addtime>" . $min . " and apply_addtime<" . $max . " ";
  737. } else {
  738. $wheresql = " and apply_addtime<" . $max . " ";
  739. }
  740. $obj = M("personal_jobs_apply as p")->field("COUNT(*) AS num,j.category")
  741. ->join("left JOIN qs_jobs AS j ON p.jobs_id=j.id")
  742. ->where("1=1" . $wheresql . $condition)
  743. ->where($where)
  744. ->group("j.category")
  745. ->order("num desc")
  746. //->limit('0,6')
  747. ->select();
  748. $i = 0;
  749. foreach ($obj as $key => $value) {
  750. if ($i == 8) {
  751. break;
  752. }
  753. if ($value['category'] > 0) {
  754. $cat = M('category_jobs')->where("id=" . $value['category'] . "")->find();
  755. $tradeArr[$key]['label'] = $cat['categoryname'];
  756. $tradeArr[$key]['value'] = $value['num'];
  757. $tabledata[$key]['t_name'] = $cat['categoryname'];
  758. $tabledata[$key]['num'] = $value['num'];
  759. $i++;
  760. }
  761. }
  762. $dArr = array();
  763. $cname_arr = array();
  764. $cvale_arr = array();
  765. $item = 0;
  766. foreach ($tradeArr as $key => $value) {
  767. $dArr[$item]['label'] = $value['label'];
  768. $dArr[$item]['value'] = $value['value'];
  769. $item++;
  770. $cname_arr[] = $value['label'];
  771. $cvale_arr[] = $value['value'];
  772. }
  773. if (IS_POST || IS_AJAX) {
  774. echo json_encode($dArr);
  775. } else {
  776. $this->assign('cname_arr', json_encode($cname_arr));
  777. $this->assign('cvale_arr', json_encode($cvale_arr));
  778. }
  779. }
  780. public function getOverview(Request $request)
  781. {
  782. // $mon = I('request.mon', '0', 'intval');
  783. $mon = $request->input('mon', 0);
  784. $now_time = time();
  785. $now_date = date('Y-m-d', $now_time);
  786. if ($mon == 0) {
  787. $start_time = mktime(0, 0, 0, 1, 1, date('Y'));
  788. } else if ($mon > 0) {
  789. $start_time = date('Y-m-d', strtotime("-" . $mon . " month"));
  790. } else {
  791. $start_time = null;
  792. }
  793. //日期范围
  794. $min = date('Y-m-d H:i:s', $start_time);
  795. $max = date('Y-m-d H:i:s', strtotime($now_date) + 60 * 60 * 24 - 1);
  796. //添加筛选条件
  797. //加入分站条件
  798. $wheresql = '';
  799. $wheresql_d = '';
  800. if (!empty($this->subsite_id) and $this->subsite_id >= 0) {
  801. $where['subsite_id'] = $this->subsite_id;
  802. $where2['subsite_id'] = $this->subsite_id;
  803. $wheresql .= " and subsite_id = ?";
  804. $whereVal[] = $this->subsite_id;
  805. }
  806. $admin = Admin::user();
  807. if (!empty($admin)) {
  808. if ($admin->role_id == 3) {
  809. $wheresql .= " and a.district = ?";
  810. $whereVal[] = $this->province;
  811. } else if ($admin->role_id == 4) {
  812. $wheresql .= " and a.sdistrict = ?";
  813. $whereVal[] = $this->city;
  814. } else if ($admin->role_id == 5) {
  815. $wheresql .= " and a.user_id = ?";
  816. $whereVal[] = $admin->id;
  817. }
  818. }
  819. //获取职位大类简历投递前十信息
  820. $data = array();
  821. if ($min && $max) {
  822. $wheresql .= " where a.created_at > ? and a.created_at < ?";
  823. $wheresql_d .= " where d.down_addtime > ? and d.down_addtime < ?";
  824. $whereVal[] = $min;
  825. $whereVal[] = $max;
  826. } else {
  827. $wheresql .= " where a.created_at < ?";
  828. $wheresql_d .= " where d.down_addtime < ? ";
  829. $whereVal[] = $max;
  830. }
  831. $sql = "SELECT COUNT(*) AS num,j.category,c.name FROM personal_jobs_apply AS a INNER JOIN jobs AS j on j.id=a.jobs_id LEFT JOIN category_jobs as c on c.id = j.category $wheresql GROUP BY j.category ORDER BY num desc limit 0,10";
  832. $dataObj = DB::select($sql, $whereVal);
  833. $i = 0;
  834. $c_ids = array();
  835. foreach ($dataObj as $key => $value) {
  836. if ($value->category > 0) {
  837. $data[$i]['order'] = $i + 1;
  838. $data[$i]['t_name'] = $value->name;
  839. $data[$i]['num'] = $value->num;
  840. $data[$i]['category'] = $value->category;
  841. $c_ids[] = $value->category;
  842. $data[$i]['download_num'] = 0;
  843. $i++;
  844. }
  845. }
  846. if ($c_ids) {
  847. $wheresql_d .= ' and j.category in ( ? )';
  848. $whereVal[] = implode(',', $c_ids);
  849. }
  850. $downloads = $this->getDownloadInfo($wheresql_d, $whereVal); //获取简历下载量
  851. foreach ($data as $k => $v) {
  852. if (isset($downloads[$v['category']]) && $downloads[$v['category']]) {
  853. $data[$k]['download_num'] = $downloads[$v->category];
  854. }
  855. }
  856. if ($this->is_ajax || $this->request_method == 'post') {
  857. echo json_encode($data);
  858. } else {
  859. // $this->assign('overviewInfo', $data);
  860. $this->view_data['overviewInfo'] = $data;
  861. }
  862. }
  863. //获取简历下载信息
  864. public function getDownloadInfo($where, $whereVal)
  865. {
  866. $sql = "SELECT COUNT(*) AS num,j.category FROM company_down_resumes as d INNER join jobs AS j on j.company_id = d.company_uid $where GROUP BY j.category ORDER BY num DESC";
  867. $dataObj = DB::select($sql, $whereVal);
  868. $data = array();
  869. foreach ($dataObj as $key => $value) {
  870. $data[$value->category] = $value->num;
  871. }
  872. return $data;
  873. }
  874. }