Screen.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. namespace app\mainapp\controller;
  3. use app\common\model\RensheCode;
  4. use app\mainapp\BaseController;
  5. use app\common\model\Comjobs as ComjobsModel;
  6. use app\common\model\ComjobsCate as ComjobsCateModel;
  7. use app\common\model\User as UserModel;
  8. use app\common\model\Broker as BrokerModel;
  9. use app\common\model\Worker as WorkerModel;
  10. use app\common\model\Train as TrainModel;
  11. use app\common\model\TrainJoin as TrainJoinModel;
  12. class Screen extends BaseController
  13. {
  14. /**
  15. * 大屏数据
  16. */
  17. public function index()
  18. {
  19. $mul_min = 1;
  20. $mul_max = 1;
  21. $res = [];
  22. //街道数据
  23. $comjobs_community = ComjobsModel::field("count(community),community")->group('community')->column('count(community)', 'community');
  24. $community = RensheCode::getList('community')->toArray();
  25. foreach ($community as &$v) {
  26. if (!empty($comjobs_community[$v['code']])) {
  27. $v['count'] = $comjobs_community[$v['code']];
  28. } else {
  29. $v['count'] = 0;
  30. }
  31. unset($v);
  32. }
  33. $community[] = [
  34. 'id' => 0,
  35. 'name' => '其他',
  36. 'code' => '',
  37. 'count' => $comjobs_community[''],
  38. ];
  39. $res['community'] = $community;
  40. //岗位类型
  41. $comjobs_cate = ComjobsModel::field("count(cateid),cateid")->group('cateid')->column('count(cateid)', 'cateid');
  42. $cateids = array_keys($comjobs_cate);
  43. $cate = ComjobsCateModel::where('id', 'in', $cateids)->select()->toArray();
  44. foreach ($cate as &$v) {
  45. $v['count'] = $comjobs_cate[$v['id']];
  46. unset($v);
  47. }
  48. $res['cate'] = $cate;
  49. //岗位数据
  50. $comjobs_map = [];
  51. $comjobs_map[] = ['createtime', '<=', time()];
  52. $comjobs_map[] = ['status', 'in', '3,4'];
  53. $orderby = ['status' => 'asc', 'updatetime' => 'desc', 'id' => 'desc'];
  54. $comjobs = [];
  55. $comjobs_data = ComjobsModel::with(['worker'])->where($comjobs_map)->order($orderby)->limit(30)->select();
  56. foreach ($comjobs_data as $v) {
  57. $comjobs[] = [
  58. 'title' => $v['title'],
  59. 'company' => $v['worker']['title'],
  60. 'salary' => $v['zwagall'],
  61. ];
  62. }
  63. $res['comjobs'] = $comjobs;
  64. //学历
  65. $user_education = UserModel::field("count(education),education")->group('education')->column('count(education)', 'education');
  66. $education_data = ['' => '未知', 1 => '初中及以下', 2 => '高中', 3 => '中技', 4 => '中专', 5 => '大专', 6 => '本科', 7 => '硕士', 8 => '博士'];
  67. $education = [];
  68. foreach ($education_data as $k => $v) {
  69. $item = ['name' => $v];
  70. if (empty($user_education[$k])) {
  71. $item['count'] = 0;
  72. } else {
  73. $item['count'] = $user_education[$k];
  74. }
  75. $education[] = $item;
  76. }
  77. $res['eduction'] = $education;
  78. //注册相关
  79. $user_gender = UserModel::field("count(gender),gender")->group('gender')->column('count(gender)', 'gender');
  80. $res['people_total'] = array_sum($user_gender);
  81. $res['people_man'] = $user_gender[1];
  82. $res['people_woman'] = $user_gender[2];
  83. $res['broker_total'] = BrokerModel::count();
  84. //岗位相关
  85. $res['company_total'] = WorkerModel::where('status', 'in', '4,5')->count();
  86. $res['comjobs_total'] = ComjobsModel::where($comjobs_map)->count();
  87. //培训相关
  88. $res['train'] = TrainModel::count();
  89. $res['train_join'] = TrainJoinModel::count();
  90. //月注册相关
  91. $year = date('Y');
  92. $month_arr = [
  93. strtotime($year . '-01-01'),
  94. strtotime($year . '-02-01'),
  95. strtotime($year . '-03-01'),
  96. strtotime($year . '-04-01'),
  97. strtotime($year . '-05-01'),
  98. strtotime($year . '-06-01'),
  99. strtotime($year . '-07-01'),
  100. strtotime($year . '-08-01'),
  101. strtotime($year . '-09-01'),
  102. strtotime($year . '-10-01'),
  103. strtotime($year . '-11-01'),
  104. strtotime($year . '-12-01'),
  105. ];
  106. $month_name = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
  107. $user_month = [];
  108. foreach ($month_arr as $k => $v) {
  109. if ($k == 11) {
  110. $item = [
  111. 'name' => $month_name[$k],
  112. 'count' => UserModel::where('createtime', 'between', [$v, strtotime(($year + 1) . '-01-01')])->count(),
  113. ];
  114. } else {
  115. $item = [
  116. 'name' => $month_name[$k],
  117. 'count' => UserModel::where('createtime', 'between', [$v, $month_arr[$k + 1]])->count(),
  118. ];
  119. }
  120. $user_month[] = $item;
  121. }
  122. $res['user_month'] = $user_month;
  123. //倍数
  124. if ($mul_min != 1 || $mul_max != 1) {
  125. foreach ($res as $k => $v) {
  126. if (is_array($v)) {
  127. foreach ($v as $k2 => $v2) {
  128. if (!empty($v2['count'])) {
  129. $res[$k][$k2]['count'] *= mt_rand($mul_min, $mul_max);
  130. }
  131. }
  132. } else {
  133. $res[$k] *= mt_rand($mul_min, $mul_max);
  134. }
  135. }
  136. }
  137. page_result(0, "", $res);
  138. }
  139. }