123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- <?php
- namespace App\Admin\Controllers;
- use App\Http\Controllers\Controller;
- use App\Models\Admin\AdminRole;
- use App\Models\Appeal;
- use App\Models\Category;
- use App\Models\PersonalJobsApply;
- use App\Models\RefreshLog;
- use App\Repositories\AppealRepository;
- use App\Repositories\CompanyImgRepository;
- use App\Repositories\CompanyRepository;
- use App\Repositories\FeedbackRepository;
- use App\Repositories\Jobfair\JobfairCompanyRepository;
- use App\Repositories\Jobfair\JobfairJobRepository;
- use App\Repositories\Jobfairout\JobfairoutCompanyRepository;
- use App\Repositories\JobsRepository;
- use App\Repositories\MemberInfoRepository;
- use App\Repositories\MemberRepository;
- use App\Repositories\ReportRepository;
- use App\Repositories\ResumeImgRepository;
- use App\Repositories\ResumeRepository;
- use Encore\Admin\Facades\Admin;
- use Encore\Admin\Layout\Content;
- use Illuminate\Support\Facades\DB;
- class HomeController extends Controller
- {
- protected $where = [];
- public function __construct()
- {
- if (get_subsite_id()!=0) {
- $this->where[] = array('subsite_id','=',get_subsite_id());
- }
- }
- public function index(
- Content $content,
- CompanyRepository $companyRepository,
- MemberRepository $memberRepository,
- JobsRepository $jobsRepository,
- ResumeRepository $resumeRepository,
- ResumeImgRepository $resumeImgRepository,
- FeedbackRepository $feedbackRepository,
- ReportRepository $reportRepository
- ) {
- return $content
- ->header('首页')
- ->description('统计列表')
- ->body(view('admin.home.index')->with([
- 'company'=>$this->company($companyRepository, $this->where),
- 'person'=>$this->person($memberRepository, $this->where),
- 'jobs'=>$this->jobs($jobsRepository, $this->where),
- 'resume'=>$this->resume($resumeRepository, $this->where),
- 'needAuthCompany'=>$this->needAuthCompany($companyRepository, $this->where),
- 'needAuditJobs'=>$this->needAuditJobs($jobsRepository, $this->where),
- 'needAuditResume'=>$this->needAuditResume($resumeRepository, $this->where),
- 'needAuditResumeImg'=>$this->needAuditResumeImg($resumeImgRepository, $this->where),
- 'suggestion'=>$this->suggestion($feedbackRepository, $this->where),
- 'report'=>$this->report($reportRepository, $this->where),
- ]));
- }
- protected function company($companyRepository, $where)
- {
- return (object)['getCompanyCount'=>$companyRepository->getCompanyCount($where),'getLastCompanyCount'=>$companyRepository->getLastCompanyCount($where),'getNextCompanyCount'=>$companyRepository->getNextCompanyCount($where)];
- }
- protected function person($memberRepository, $where)
- {
- return (object)['getPersonCount'=>$memberRepository->getPersonCount($where),'getLastPersonCount'=>$memberRepository->getLastPersonCount($where),'getNextPersonCount'=>$memberRepository->getNextPersonCount($where)];
- }
- protected function jobs($jobsRepository, $where)
- {
- return (object)['getJobCount'=>$jobsRepository->getJobCount($where),'getLastJobsCount'=>$jobsRepository->getLastJobsCount($where),'getNextJobsCount'=>$jobsRepository->getNextJobsCount($where)];
- }
- protected function resume($resumeRepository, $where)
- {
- return (object)['getResumesCount'=>$resumeRepository->getResumesCount($where),'getLastResumeCount'=>$resumeRepository->getLastResumeCount($where),'getNextResumeCount'=>$resumeRepository->getNextResumeCount($where)];
- }
- protected function needAuthCompany($companyRepository, $where)
- {
- $where[] = ['audit','=',2];
- return (object)['getAuditCount'=>$companyRepository->getAuditCount($where)];
- }
- protected function needAuditJobs($jobsRepository, $where)
- {
- $where[] = ['audit','=',2];
- return (object)['getJobsCount'=>$jobsRepository->getJobCount($where)];
- }
- protected function needAuditResume($resumeRepository, $where)
- {
- $where[] = ['audit','=',1];
- return (object)['getAuditCount'=>$resumeRepository->getAuditCount($where)];
- }
- protected function needAuditResumeImg($resumeImgRepository, $subsite_id)
- {
- $where[] = ['audit','=',1];
- return (object)['getAuditCount'=>$resumeImgRepository->getAuditCount($where, $subsite_id)];
- }
- protected function suggestion($feedbackRepository, $where)
- {
- $where[] = array('audit','=',0);
- return (object)['getCount'=>$feedbackRepository->getCount($where)];
- }
- protected function report($reportRepository, $where)
- {
- $where[] = array('audit','=',1);
- return (object)['getCount'=>$reportRepository->getCount($where)];
- }
- protected function appeal($appealRepository, $where)
- {
- $where[] = array('status','=',0);
- return (object)['getCount'=>$appealRepository->getCount($where)];
- }
- protected function jobfairJobs($jobfairJobRepository)
- {
- $where[] = array('audit','=',2);
- $where[] = array('type','=',1);
- return (object)['getCount'=>$jobfairJobRepository->getCount($where)];
- }
- protected function jobfairCompany($jobfairCompanyRepository, $subsite_id)
- {
- $where[] = array('audit','=',2);
- return (object)['getCount'=>$jobfairCompanyRepository->getCount($where, $subsite_id)];
- }
- protected function jobfairoutJobs($jobfairJobRepository)
- {
- $where[] = array('audit','=',2);
- $where[] = array('type','=',2);
- return (object)['getCount'=>$jobfairJobRepository->getCount($where)];
- }
- protected function jobfairoutCompany($jobfairoutCompanyRepository, $subsite_id)
- {
- $where[] = array('audit','=',2);
- return (object)['getCount'=>$jobfairoutCompanyRepository->getCount($where, $subsite_id)];
- }
- protected function companyImg($companyImgRepository, $subsite_id)
- {
- return (object)['getCount'=>$companyImgRepository->getCount($subsite_id, [0,2])];
- }
- protected function memberInfo($memberInfoRepository, $subsite_id)
- {
- $where[] = array('photo','=',1);
- $where[] = array('photo_audit','=',1);
- return (object)['getCount'=>$memberInfoRepository->getCount($where, $subsite_id)];
- }
- protected function register($table, $where)
- {
- $result = [];
- $dayArr = getLastDates(30);
- $sql = "deleted_at is null";
- if ($where) {
- $whereSubsite = $where[0][2] ? $where[0][2] : 0;
- $sql.=" and subsite_id=".$whereSubsite;
- }
- $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");
- foreach ($dayArr as $key => $val) {
- if (in_array($val, array_column($realArr, 'days'))) {
- foreach ($realArr as $key1 => $val1) {
- if ($val==$val1->days) {
- $result[] = [$val, $val1->count];
- break;
- }
- }
- } else {
- $result[] = [$val, 0];
- }
- }
- return $result;
- }
- protected function companyType($where)
- {
- $sql = "deleted_at is null";
- if ($where) {
- $whereSubsite = $where[0][2] ? $where[0][2] : 0;
- $sql.=" and subsite_id=".$whereSubsite;
- }
- $result = [];
- $category = Category::where('alias', 'AIX_company_type')->select(['id', 'demand'])->get()->toArray();
- $category_name = array_column($category, 'demand');
- $company = DB::select("select nature,count(*) as count from companys WHERE ".$sql." group by nature");
- foreach ($category as $key => $val) {
- if (in_array($val['id'], array_column($company, 'nature'))) {
- foreach ($company as $key1 => $val1) {
- if ($val['id']==$val1->nature) {
- $result[] = ['value'=>$val1->count, 'name'=>$val['demand']];
- break;
- }
- }
- } else {
- $result[] = ['value'=>0, 'name'=>$val['demand']];
- }
- }
- return ['category_name'=>$category_name,'result'=>$result];
- }
- protected function userAction()
- {
- $result = [];
- $dayArr = getLastDates(14);
- $jobsRefresh = RefreshLog::when(get_subsite_id()>0, function ($query) {
- $query->whereHas('companys', function ($query) {
- $query->where('subsite_id', get_subsite_id());
- });
- })->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();
- $jobsApply = PersonalJobsApply::when(get_subsite_id()>0, function ($query) {
- $query->whereHas('resumes', function ($query) {
- $query->where('subsite_id', get_subsite_id());
- });
- })->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();
- $newArray = ['jobsRefresh'=>$jobsRefresh,'jobsApply'=>$jobsApply];
- foreach ($dayArr as $key => $val) {
- foreach ($newArray as $key2 => $val2) {
- if (in_array($val, array_column($val2, 'days'))) {
- foreach ($val2 as $key1 => $val1) {
- if ($val==$val1['days']) {
- $result[$key2][] = $val1['count'];
- break;
- }
- }
- } else {
- $result[$key2][] = 0;
- }
- }
- }
- return ['day'=>$dayArr, 'userAction'=>$result];
- }
- public function ajax()
- {
- $where = $this->where;
- $member = $this->register('members', $where);
- $company = $this->register('companys', $where);
- $companyType = $this->companyType($where);
- $userAction = $this->userAction();
- return response()->json(['member'=>$member,'company'=>$company,'companyType'=>$companyType,'userAction'=>$userAction]);
- }
- public function menuMessage(
- CompanyRepository $companyRepository,
- JobsRepository $jobsRepository,
- CompanyImgRepository $companyImgRepository,
- ResumeRepository $resumeRepository,
- ResumeImgRepository $resumeImgRepository,
- MemberInfoRepository $memberInfoRepository,
- FeedbackRepository $feedbackRepository,
- ReportRepository $reportRepository,
- AppealRepository $appealRepository,
- JobfairJobRepository $jobfairJobRepository,
- JobfairCompanyRepository $jobfairCompanyRepository,
- JobfairoutCompanyRepository $jobfairoutCompanyRepository
- ) {
- if (Admin::user()->isRole(AdminRole::$consultantSlug)) {
- return response()->json([]);
- }
- $needAuthCompany = $this->needAuthCompany($companyRepository, $this->where)->getAuditCount;
- $needAuditJobs = $this->needAuditJobs($jobsRepository, $this->where)->getJobsCount;
- $companyImg =$this->companyImg($companyImgRepository, $this->where)->getCount;
- $needAuditResume = $this->needAuditResume($resumeRepository, $this->where)->getAuditCount;
- $needAuditResumeImg = $this->needAuditResumeImg($resumeImgRepository, $this->where)->getAuditCount;
- $memberInfo = $this->memberInfo($memberInfoRepository, $this->where)->getCount;
- $suggestion = $this->suggestion($feedbackRepository, $this->where)->getCount;
- $report = $this->report($reportRepository, $this->where)->getCount;
- $appeal = $this->appeal($appealRepository, $this->where)->getCount;
- $jobfairJobs = $this->jobfairJobs($jobfairJobRepository)->getCount;
- $jobfairCompany = $this->jobfairCompany($jobfairCompanyRepository, $this->where)->getCount;
- $jobfairoutJobs = $this->jobfairoutJobs($jobfairJobRepository)->getCount;
- $jobfairoutCompany = $this->jobfairoutCompany($jobfairoutCompanyRepository, $this->where)->getCount;
- return response()->json([
- ["id"=>13,"num"=>$needAuthCompany+$needAuditJobs+$companyImg, "has_child"=>true],
- ["id"=>14,"num"=>$needAuthCompany, "has_child"=>false],
- ["id"=>31,"num"=>$needAuditJobs, "has_child"=>false],
- ["id"=>41,"num"=>$companyImg, "has_child"=>false],
- ["id"=>110,"num"=>$needAuditResume+$needAuditResumeImg+$memberInfo, "has_child"=>true],
- ["id"=>111,"num"=>$needAuditResume, "has_child"=>false],
- ["id"=>112,"num"=>$needAuditResumeImg, "has_child"=>false],
- ["id"=>113,"num"=>$memberInfo, "has_child"=>false],
- ["id"=>19,"num"=>$suggestion+$report+$appeal, "has_child"=>true],
- ["id"=>106,"num"=>$suggestion, "has_child"=>false],
- ["id"=>47,"num"=>$report, "has_child"=>false],
- ["id"=>50,"num"=>$appeal, "has_child"=>false],
- ["id"=>145,"num"=>$jobfairJobs+$jobfairCompany, "has_child"=>true],
- ["id"=>149,"num"=>$jobfairJobs, "has_child"=>false],
- ["id"=>151,"num"=>$jobfairCompany, "has_child"=>false],
- ["id"=>175,"num"=>$jobfairoutJobs+$jobfairoutCompany, "has_child"=>true],
- ["id"=>177,"num"=>$jobfairoutJobs, "has_child"=>false],
- ["id"=>179,"num"=>$jobfairoutCompany, "has_child"=>false],
- ]);
- }
- }
|