HomeController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Admin\AdminRole;
  5. use App\Models\Appeal;
  6. use App\Models\Category;
  7. use App\Models\PersonalJobsApply;
  8. use App\Models\RefreshLog;
  9. use App\Repositories\AppealRepository;
  10. use App\Repositories\CompanyImgRepository;
  11. use App\Repositories\CompanyRepository;
  12. use App\Repositories\FeedbackRepository;
  13. use App\Repositories\Jobfair\JobfairCompanyRepository;
  14. use App\Repositories\Jobfair\JobfairJobRepository;
  15. use App\Repositories\Jobfairout\JobfairoutCompanyRepository;
  16. use App\Repositories\JobsRepository;
  17. use App\Repositories\MemberInfoRepository;
  18. use App\Repositories\MemberRepository;
  19. use App\Repositories\ReportRepository;
  20. use App\Repositories\ResumeImgRepository;
  21. use App\Repositories\ResumeRepository;
  22. use Encore\Admin\Facades\Admin;
  23. use Encore\Admin\Layout\Content;
  24. use Illuminate\Support\Facades\DB;
  25. class HomeController extends Controller
  26. {
  27. protected $where = [];
  28. public function __construct()
  29. {
  30. if (get_subsite_id() != 0) {
  31. $this->where[] = ['subsite_id', '=', get_subsite_id()];
  32. }
  33. }
  34. public function index(
  35. Content $content,
  36. CompanyRepository $companyRepository,
  37. MemberRepository $memberRepository,
  38. JobsRepository $jobsRepository,
  39. ResumeRepository $resumeRepository,
  40. ResumeImgRepository $resumeImgRepository,
  41. FeedbackRepository $feedbackRepository,
  42. ReportRepository $reportRepository
  43. )
  44. {
  45. $view = 'admin.home.index';
  46. if (Admin::user()->isRole('health')) {
  47. $view = 'admin.home.health';
  48. }
  49. if (Admin::user()->isRole('ic_group')) {
  50. $view = 'admin.home.ic';
  51. }
  52. if (Admin::user()->isRole('health') || Admin::user()->isRole('ic_group')) {
  53. $data = [
  54. 'company' => $this->company($companyRepository, $this->where),
  55. 'jobs' => $this->jobs($jobsRepository, $this->where),
  56. 'needAuthCompany' => $this->needAuthCompany($companyRepository, $this->where),
  57. 'needAuditJobs' => $this->needAuditJobs($jobsRepository, $this->where),
  58. ];
  59. } else {
  60. $data = [
  61. 'company' => $this->company($companyRepository, $this->where),
  62. 'person' => $this->person($memberRepository, $this->where),
  63. 'jobs' => $this->jobs($jobsRepository, $this->where),
  64. 'resume' => $this->resume($resumeRepository, $this->where),
  65. 'needAuthCompany' => $this->needAuthCompany($companyRepository, $this->where),
  66. 'needAuditJobs' => $this->needAuditJobs($jobsRepository, $this->where),
  67. 'needAuditResume' => $this->needAuditResume($resumeRepository, $this->where),
  68. 'needAuditResumeImg' => $this->needAuditResumeImg($resumeImgRepository, $this->where),
  69. 'suggestion' => $this->suggestion($feedbackRepository, $this->where),
  70. 'report' => $this->report($reportRepository, $this->where),
  71. ];
  72. }
  73. return $content
  74. ->header('首页')
  75. ->description('统计列表')
  76. ->body(view($view)->with($data));
  77. }
  78. protected function company($companyRepository, $where)
  79. {
  80. if (Admin::user()->isRole('health')) {
  81. $where[] = ['is_health', '=', 1];
  82. }
  83. if (Admin::user()->isRole('ic_group')) {
  84. $where[] = ['is_ic', '=', 1];
  85. }
  86. return (object)['getCompanyCount' => $companyRepository->getCompanyCount($where), 'getLastCompanyCount' => $companyRepository->getLastCompanyCount($where), 'getNextCompanyCount' => $companyRepository->getNextCompanyCount($where)];
  87. }
  88. protected function person($memberRepository, $where)
  89. {
  90. return (object)['getPersonCount' => $memberRepository->getPersonCount($where), 'getLastPersonCount' => $memberRepository->getLastPersonCount($where), 'getNextPersonCount' => $memberRepository->getNextPersonCount($where)];
  91. }
  92. protected function jobs($jobsRepository, $where)
  93. {
  94. if (Admin::user()->isRole('health')) {
  95. $where[] = ['is_health', '=', 1];
  96. }
  97. if (Admin::user()->isRole('ic_group')) {
  98. $where[] = ['is_ic', '=', 1];
  99. }
  100. return (object)['getJobCount' => $jobsRepository->getJobCount($where), 'getLastJobsCount' => $jobsRepository->getLastJobsCount($where), 'getNextJobsCount' => $jobsRepository->getNextJobsCount($where)];
  101. }
  102. protected function resume($resumeRepository, $where)
  103. {
  104. return (object)['getResumesCount' => $resumeRepository->getResumesCount($where), 'getLastResumeCount' => $resumeRepository->getLastResumeCount($where), 'getNextResumeCount' => $resumeRepository->getNextResumeCount($where)];
  105. }
  106. protected function needAuthCompany($companyRepository, $where)
  107. {
  108. $where[] = ['audit', '=', 2];
  109. if (Admin::user()->isRole('health')) {
  110. $where[] = ['is_health', '=', 1];
  111. }
  112. if (Admin::user()->isRole('ic_group')) {
  113. $where[] = ['is_ic', '=', 1];
  114. }
  115. return (object)['getAuditCount' => $companyRepository->getAuditCount($where)];
  116. }
  117. protected function needAuditJobs($jobsRepository, $where)
  118. {
  119. $where[] = ['audit', '=', 2];
  120. if (Admin::user()->isRole('health')) {
  121. $where[] = ['is_health', '=', 1];
  122. }
  123. if (Admin::user()->isRole('ic_group')) {
  124. $where[] = ['is_ic', '=', 1];
  125. }
  126. return (object)['getJobsCount' => $jobsRepository->getJobCount($where)];
  127. }
  128. protected function needAuditResume($resumeRepository, $where)
  129. {
  130. $where[] = ['audit', '=', 1];
  131. return (object)['getAuditCount' => $resumeRepository->getAuditCount($where)];
  132. }
  133. protected function needAuditResumeImg($resumeImgRepository, $subsite_id)
  134. {
  135. $where[] = ['audit', '=', 1];
  136. return (object)['getAuditCount' => $resumeImgRepository->getAuditCount($where, $subsite_id)];
  137. }
  138. protected function suggestion($feedbackRepository, $where)
  139. {
  140. $where[] = ['audit', '=', 0];
  141. return (object)['getCount' => $feedbackRepository->getCount($where)];
  142. }
  143. protected function report($reportRepository, $where)
  144. {
  145. $where[] = ['audit', '=', 1];
  146. return (object)['getCount' => $reportRepository->getCount($where)];
  147. }
  148. protected function appeal($appealRepository, $where)
  149. {
  150. $where[] = ['status', '=', 0];
  151. return (object)['getCount' => $appealRepository->getCount($where)];
  152. }
  153. protected function jobfairJobs($jobfairJobRepository)
  154. {
  155. $where[] = ['audit', '=', 2];
  156. $where[] = ['type', '=', 1];
  157. return (object)['getCount' => $jobfairJobRepository->getCount($where)];
  158. }
  159. protected function jobfairCompany($jobfairCompanyRepository, $subsite_id)
  160. {
  161. $where[] = ['audit', '=', 2];
  162. return (object)['getCount' => $jobfairCompanyRepository->getCount($where, $subsite_id)];
  163. }
  164. protected function jobfairoutJobs($jobfairJobRepository)
  165. {
  166. $where[] = ['audit', '=', 2];
  167. $where[] = ['type', '=', 2];
  168. return (object)['getCount' => $jobfairJobRepository->getCount($where)];
  169. }
  170. protected function jobfairoutCompany($jobfairoutCompanyRepository, $subsite_id)
  171. {
  172. $where[] = ['audit', '=', 2];
  173. return (object)['getCount' => $jobfairoutCompanyRepository->getCount($where, $subsite_id)];
  174. }
  175. protected function companyImg($companyImgRepository, $subsite_id)
  176. {
  177. return (object)['getCount' => $companyImgRepository->getCount($subsite_id, [0, 2])];
  178. }
  179. protected function memberInfo($memberInfoRepository, $subsite_id)
  180. {
  181. $where[] = ['photo', '=', 1];
  182. $where[] = ['photo_audit', '=', 1];
  183. return (object)['getCount' => $memberInfoRepository->getCount($where, $subsite_id)];
  184. }
  185. protected function register($table, $where)
  186. {
  187. $result = [];
  188. $dayArr = getLastDates(30);
  189. $sql = "deleted_at is null";
  190. if ($where) {
  191. $whereSubsite = $where[0][2] ? $where[0][2] : 0;
  192. $sql .= " and subsite_id=" . $whereSubsite;
  193. }
  194. $realArr = DB::select("select DATE_FORMAT(created_at,'%Y-%m-%d') as days,count(*) as count FROM " . $table . " WHERE " . $sql . " and created_at >= '" . date('Y-m-d H:i:s', strtotime('-30 days')) . "' AND created_at <= '" . date('Y-m-d H:i:s') . "' GROUP BY days");
  195. foreach ($dayArr as $key => $val) {
  196. if (in_array($val, array_column($realArr, 'days'))) {
  197. foreach ($realArr as $key1 => $val1) {
  198. if ($val == $val1->days) {
  199. $result[] = [$val, $val1->count];
  200. break;
  201. }
  202. }
  203. } else {
  204. $result[] = [$val, 0];
  205. }
  206. }
  207. return $result;
  208. }
  209. protected function companyType($where)
  210. {
  211. $sql = "deleted_at is null";
  212. if ($where) {
  213. $whereSubsite = $where[0][2] ? $where[0][2] : 0;
  214. $sql .= " and subsite_id=" . $whereSubsite;
  215. }
  216. $result = [];
  217. $category = Category::where('alias', 'AIX_company_type')->select(['id', 'demand'])->get()->toArray();
  218. $category_name = array_column($category, 'demand');
  219. $company = DB::select("select nature,count(*) as count from companys WHERE " . $sql . " group by nature");
  220. foreach ($category as $key => $val) {
  221. if (in_array($val['id'], array_column($company, 'nature'))) {
  222. foreach ($company as $key1 => $val1) {
  223. if ($val['id'] == $val1->nature) {
  224. $result[] = ['value' => $val1->count, 'name' => $val['demand']];
  225. break;
  226. }
  227. }
  228. } else {
  229. $result[] = ['value' => 0, 'name' => $val['demand']];
  230. }
  231. }
  232. return ['category_name' => $category_name, 'result' => $result];
  233. }
  234. protected function userAction()
  235. {
  236. $result = [];
  237. $dayArr = getLastDates(14);
  238. $jobsRefresh = RefreshLog::when(get_subsite_id() > 0, function ($query) {
  239. $query->whereHas('companys', function ($query) {
  240. $query->where('subsite_id', get_subsite_id());
  241. });
  242. })->where('utype', 1)->where('type', 1006)->where('created_at', '>=', date('Y-m-d H:i:s', strtotime('-14 days')))->where('created_at', '<=', date('Y-m-d H:i:s'))->selectRaw('DATE_FORMAT(created_at,\'%Y-%m-%d\') as days,count(*) as count')->groupBy('days')->get()->toArray();
  243. $jobsApply = PersonalJobsApply::when(get_subsite_id() > 0, function ($query) {
  244. $query->whereHas('resumes', function ($query) {
  245. $query->where('subsite_id', get_subsite_id());
  246. });
  247. })->where('created_at', '>=', date('Y-m-d H:i:s', strtotime('-14 days')))->where('created_at', '<=', date('Y-m-d H:i:s'))->selectRaw('DATE_FORMAT(created_at,\'%Y-%m-%d\') as days,count(*) as count')->groupBy('days')->get()->toArray();
  248. $newArray = ['jobsRefresh' => $jobsRefresh, 'jobsApply' => $jobsApply];
  249. foreach ($dayArr as $key => $val) {
  250. foreach ($newArray as $key2 => $val2) {
  251. if (in_array($val, array_column($val2, 'days'))) {
  252. foreach ($val2 as $key1 => $val1) {
  253. if ($val == $val1['days']) {
  254. $result[$key2][] = $val1['count'];
  255. break;
  256. }
  257. }
  258. } else {
  259. $result[$key2][] = 0;
  260. }
  261. }
  262. }
  263. return ['day' => $dayArr, 'userAction' => $result];
  264. }
  265. public function ajax()
  266. {
  267. $where = $this->where;
  268. $member = $this->register('members', $where);
  269. $company = $this->register('companys', $where);
  270. $companyType = $this->companyType($where);
  271. $userAction = $this->userAction();
  272. return response()->json(['member' => $member, 'company' => $company, 'companyType' => $companyType, 'userAction' => $userAction]);
  273. }
  274. public function menuMessage(
  275. CompanyRepository $companyRepository,
  276. JobsRepository $jobsRepository,
  277. CompanyImgRepository $companyImgRepository,
  278. ResumeRepository $resumeRepository,
  279. ResumeImgRepository $resumeImgRepository,
  280. MemberInfoRepository $memberInfoRepository,
  281. FeedbackRepository $feedbackRepository,
  282. ReportRepository $reportRepository,
  283. AppealRepository $appealRepository,
  284. JobfairJobRepository $jobfairJobRepository,
  285. JobfairCompanyRepository $jobfairCompanyRepository,
  286. JobfairoutCompanyRepository $jobfairoutCompanyRepository
  287. )
  288. {
  289. $needAuthCompany = $this->needAuthCompany($companyRepository, $this->where)->getAuditCount;
  290. $needAuditJobs = $this->needAuditJobs($jobsRepository, $this->where)->getJobsCount;
  291. $companyImg = $this->companyImg($companyImgRepository, $this->where)->getCount;
  292. $needAuditResume = $this->needAuditResume($resumeRepository, $this->where)->getAuditCount;
  293. $needAuditResumeImg = $this->needAuditResumeImg($resumeImgRepository, $this->where)->getAuditCount;
  294. $memberInfo = $this->memberInfo($memberInfoRepository, $this->where)->getCount;
  295. $suggestion = $this->suggestion($feedbackRepository, $this->where)->getCount;
  296. $report = $this->report($reportRepository, $this->where)->getCount;
  297. $appeal = $this->appeal($appealRepository, $this->where)->getCount;
  298. $jobfairJobs = $this->jobfairJobs($jobfairJobRepository)->getCount;
  299. $jobfairCompany = $this->jobfairCompany($jobfairCompanyRepository, $this->where)->getCount;
  300. $jobfairoutJobs = $this->jobfairoutJobs($jobfairJobRepository)->getCount;
  301. $jobfairoutCompany = $this->jobfairoutCompany($jobfairoutCompanyRepository, $this->where)->getCount;
  302. return response()->json([
  303. ["id" => 13, "num" => $needAuthCompany + $needAuditJobs + $companyImg, "has_child" => true],
  304. ["id" => 14, "num" => $needAuthCompany, "has_child" => false],
  305. ["id" => 31, "num" => $needAuditJobs, "has_child" => false],
  306. ["id" => 41, "num" => $companyImg, "has_child" => false],
  307. ["id" => 110, "num" => $needAuditResume + $needAuditResumeImg + $memberInfo, "has_child" => true],
  308. ["id" => 111, "num" => $needAuditResume, "has_child" => false],
  309. ["id" => 112, "num" => $needAuditResumeImg, "has_child" => false],
  310. ["id" => 113, "num" => $memberInfo, "has_child" => false],
  311. ["id" => 19, "num" => $suggestion + $report + $appeal, "has_child" => true],
  312. ["id" => 106, "num" => $suggestion, "has_child" => false],
  313. ["id" => 47, "num" => $report, "has_child" => false],
  314. ["id" => 50, "num" => $appeal, "has_child" => false],
  315. ["id" => 145, "num" => $jobfairJobs + $jobfairCompany, "has_child" => true],
  316. ["id" => 149, "num" => $jobfairJobs, "has_child" => false],
  317. ["id" => 151, "num" => $jobfairCompany, "has_child" => false],
  318. ["id" => 175, "num" => $jobfairoutJobs + $jobfairoutCompany, "has_child" => true],
  319. ["id" => 177, "num" => $jobfairoutJobs, "has_child" => false],
  320. ["id" => 179, "num" => $jobfairoutCompany, "has_child" => false],
  321. ]);
  322. }
  323. }