PHP_OS, 'environment' => $_SERVER[ 'SERVER_SOFTWARE' ], 'php_v' => PHP_VERSION, 'version' => config('version') ]; } /** * 获取域名配置 */ public function getUrl() { return (new CoreSysConfigService())->getSceneDomain(); } /** * 获取系统信息 * @return array */ public function getSystemInfo() { $server = []; $server[] = [ "name" => get_lang('dict_setting.server_system'), "server" => PHP_OS ]; $server[] = [ "name" => get_lang('dict_setting.server_setting'), "server" => PHP_SAPI ]; $server[] = [ "name" => get_lang('dict_setting.php_version'), "server" => PHP_VERSION]; //环境权限 $system_variables = []; //pdo $pdo = extension_loaded('pdo') && extension_loaded('pdo_mysql'); $system_variables[] = [ "name" => "pdo", "need" => get_lang('dict_setting.php_authority_ask'), "status" => $pdo ]; //curl $curl = extension_loaded('curl') && function_exists('curl_init'); $system_variables[] = [ "name" => "curl", "need" => get_lang('dict_setting.php_authority_ask'), "status" => $curl ]; //openssl $openssl = extension_loaded('openssl'); $system_variables[] = [ "name" => "openssl", "need" => get_lang('dict_setting.php_authority_ask'), "status" => $openssl ]; //gd $gd = extension_loaded('gd'); $system_variables[] = [ "name" => "GD库", "need" => get_lang('dict_setting.php_authority_ask'), "status" => $gd ]; //fileinfo $fileinfo = extension_loaded('fileinfo'); $system_variables[] = [ "name" => "fileinfo", "need" => get_lang('dict_setting.php_authority_ask'), "status" => $fileinfo ]; //目录权限 $root_path = str_replace("\\", DIRECTORY_SEPARATOR, dirname(__FILE__, 5)); $root_path = str_replace("../", DIRECTORY_SEPARATOR, $root_path); $dirs_list = [ [ "path" => $root_path . DIRECTORY_SEPARATOR . 'runtime' . DIRECTORY_SEPARATOR, "need" => get_lang('dict_setting.file_authority_ask'), "path_name" => "/runtime", "name" => "runtime" ], [ "path" => $root_path . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR, "need" => get_lang('dict_setting.file_authority_ask'), "path_name" => "/public/upload", "name" => "upload" ], ]; //目录 可读 可写检测 foreach ($dirs_list as $k => $v) { $is_readable = is_readable($v[ "path" ]); $is_write = is_write($v[ "path" ]); if ($is_readable && $is_write) { $dirs_list[ $k ][ "status" ] = true; } else { $dirs_list[ $k ][ "status" ] = false; } } $system_variables = array_merge($system_variables, $dirs_list); //获取环境版本 $server_version = []; $row = (array) Db::query("select VERSION() as verson"); $server_version[] = [ "name" => get_lang('dict_setting.php_version'), "demand" => get_lang('dict_setting.php_ask'), "server" => PHP_VERSION]; $server_version[] = [ "name" => get_lang('dict_setting.mysql_version'), "demand" => get_lang('dict_setting.mysql_ask'), "server" => $row[ 0 ][ 'verson' ] ]; // 进程 $process[] = [ "name" => "php think queue:listen", "need" => get_lang('dict_setting.php_authority_ask'), "status" => ( new SystemService() )->checkJob() ]; return [ "server" => $server, "dirs_list" => $dirs_list, 'system_variables' => $system_variables, 'server_version' => $server_version, 'process' => $process ]; } /** * 清理缓存 */ public function schemaCache() { if (is_dir(dirname($_SERVER[ 'DOCUMENT_ROOT' ]) . '/runtime/schema')) { rmdirs(dirname($_SERVER[ 'DOCUMENT_ROOT' ]) . '/runtime/schema'); } return 'CLEAR_MYSQL_CACHE_SUCCESS'; } /** *校验消息队列是否正常运行 * @return bool */ public function checkJob() { $secret = uniqid('', true); $file = root_path('runtime') . $secret . '.job'; try { CheckJob::dispatch([ 'file' => $file ]); } catch ( Throwable $e) { return false; } // $timeout = 0; // while($timeout < 5){ // if (file_exists($file)) { // @unlink($file); // return true; // } // $timeout++; // sleep(1); // } sleep(5); if (file_exists($file)) { @unlink($file); return true; } return false; } /** * 校验计划任务是否正常运行 * @return bool */ public function checkSchedule() { $file = root_path('runtime') . '.schedule'; if (file_exists($file)) { $time = file_get_contents($file); if (!empty($time) && abs($time - time()) < 90) { return true; } } return false; } public function get_yjpz_config(){ $config = new SysConfig(); $data = $config->where(['config_key' => 'priceRules'])->value("value"); return $data; } public function yjpz_config(array $data){ $config = new SysConfig(); $config->where(['config_key' => 'priceRules'])->update([ 'value' => json_encode($data['priceRules']) ]); return true; } public function xsyj_config(array $data){ $config = new SysConfig(); $config->where(['config_key' => 'XSYJ'])->update([ 'value' => json_encode($data['stages']) ]); $config->where(['config_key' => 'XSPJ'])->update([ 'value' => json_encode($data['form']) ]); $config->where(['config_key' => 'course_type'])->update([ 'value' => json_encode($data['course_type']) ]); return true; } public function get_xsyj_config(){ $dict = new \app\model\dict\Dict(); $config = new SysConfig(); $data = $config->where(['config_key' => 'XSYJ'])->value("value"); $form = $config->where(['config_key' => 'XSPJ'])->value("value"); $course_type = $config->where(['config_key' => 'course_type'])->value("value"); // $course_type = json_decode($course_type, true); $dict_course_type = $dict->where(['key' => 'course_type'])->value("dictionary"); $dict_course_type = json_decode($dict_course_type, true); foreach ($dict_course_type as $k => $v) { foreach ($course_type as $k1 => $v1) { if($v['value'] == $v1['value']){ $dict_course_type[$k]['num'] = $v1['num'] ?? 0; } } if(!isset($dict_course_type[$k]['num'])){ $dict_course_type[$k]['num'] = 0; } } return ['data' => $data,'form' => $form,'course_type' => $dict_course_type]; } public function jlyj_config(array $data){ $config = new SysConfig(); $config->where(['config_key' => 'JLYJ'])->update([ 'value' => json_encode($data) ]); return true; } public function get_jlyj_config(){ $config = new SysConfig(); $data = $config->where(['config_key' => 'JLYJ'])->value("value"); return $data; } public function home1(array $arr){ $campus = new Campus(); $personnel = new Personnel(); $customerResources = new CustomerResources(); $student = new Student(); $data = []; $data['campus_count'] = $campus->count(); $data['personnel_count'] = $personnel->count(); $data['customerResources_count'] = $customerResources->count(); $data['customerResources_day_count'] = $customerResources->whereTime('created_at', 'yesterday')->count(); $data['student_count'] = $student->count(); $data['student_day_count'] = $student->whereTime('created_at', 'yesterday')->count(); if ($arr['date'] == 'week') { $start_date = date('Y-m-d', strtotime('-6 days')); $end_date = date('Y-m-d',strtotime('+1 days')); } elseif ($arr['date'] == 'month') { $start_date = date('Y-m-01'); $end_date = date('Y-m-d'); } elseif ($arr['date'] == 'year') { $start_date = date('Y-01-01'); $end_date = date('Y-m-d'); } else { $start_date = date('Y-m-d', strtotime('-6 days')); $end_date = date('Y-m-d',strtotime('+1 days')); } $stat_data = $customerResources ->where([ ['create_date', '>=', $start_date], ['create_date', '<=', $end_date] ]) ->field('create_date, COUNT(*) as count') ->group('create_date') ->select()->toArray(); $stat_data = !empty($stat_data) ? array_column($stat_data, 'count', 'create_date') : []; $day = ceil((strtotime($end_date) - strtotime($start_date)) / 86400); $value = []; $time = []; for ($i = 0; $i < $day; $i++) { $date = date('Y-m-d', strtotime($start_date) + $i * 86400); $time[] = $date; $value[] = isset($stat_data[ $date ]) ? $stat_data[ $date ] : 0; } $data['customer'][ 'value' ] = $value; $data['customer'][ 'time' ] = $time; $y = date('Y'); $m = date('m'); $campus = new Campus(); $campusPersonnelRole = new CampusPersonRole(); $order = new OrderTable(); $studentCourses = new StudentCourses(); $campus_list = $campus->select()->toArray(); $table = [ 'table_1' => [], 'table_1_total' => 0, 'table_2' => [], 'table_2_total' => 0, ]; //年年度业绩完成情况 $total_task = 0; $total_complete = 0; //年年度月卡续费完成情况 $m_total_task = 0; $m_total_complete = 0; foreach ($campus_list as $key => $item) { $task = $campusPersonnelRole->where(['campus_id' => $item['id']])->sum("task_num"); $complete = $order->alias("a") ->join(['school_customer_resources' => 'b'], 'a.resource_id = b.id', 'left') ->where(['b.campus' => $item['id'], 'order_status' => 'paid']) ->count(); $rate = $complete > 0 ? round($task / $complete, 2) : 0; $table['table_1'][] = [ "序号" => $key + 1, "校区" => $item['campus_name'], "任务" => $task, "完成" => $complete, "完成率" => $rate.'%', ]; $total_task += $task; $total_complete += $complete; $m_task = $studentCourses ->alias("a") ->join(['school_student' => 'b'],'a.student_id = b.id','left') ->where([ ['b.campus_id', '=',$item['id']], ['a.end_date','<',date("Y-m-d")] ]) ->count(); $m_complete = $order->alias("a") ->join(['school_customer_resources' => 'b'], 'a.resource_id = b.id', 'left') ->where(['b.campus' => $item['id'], 'order_status' => 'paid','order_type' => '2']) ->count(); $m_rate = $m_complete > 0 ? round($m_task / $m_complete, 2) : 0; $m_total_task += $m_task; $m_total_complete += $m_complete; $table['table_2'][] = [ "序号" => $key + 1, "校区" => $item['campus_name'], "到期" => $m_task, "续费" => $m_complete, "续费率" => $m_rate.'%', ]; } $table['table_1_total'] = $total_complete > 0 ? round($total_task / $total_complete, 2) : '0'; $table['table_2_total'] = $m_total_complete > 0 ? round($m_total_task / $m_total_complete, 2) : '0'; return $data; } public function home(array $arr){ $personnel_summary = new PersonnelSummary(); $campus = new Campus(); $campusPersonnelRole = new CampusPersonRole(); $order = new OrderTable(); $studentCourses = new StudentCourses(); $campus_list = $campus->where(['campus_status' => 1])->field("id,campus_name")->select()->toArray(); foreach ($campus_list as &$item) { $item['year_task_num'] = 0; //任务数量 $item['year_complete_num'] = 0; //完成数量 $item['year_expire_num'] = 0; //到期数量 $item['year_renew_num'] = 0; //续费数量 $item['year_resource_num'] = 0; //分配的资源数量 $item['year_visit_num'] = 0; //分配的资源数量 $item['year_complete'] = 0; //完成率 $item['month_task_num'] = 0; //任务数量 $item['month_complete_num'] = 0; //完成数量 $item['month_expire_num'] = 0; //到期数量 $item['month_renew_num'] = 0; //续费数量 $item['month_resource_num'] = 0; //分配的资源数量 $item['month_visit_num'] = 0; //分配的资源数量 $item['month_complete'] = 0; //完成率 $item['month_zy_complete_num'] = 0; //资源完成数量 $item['month_zy_complete'] = 0; //资源完成率 $item['visit_num_rate'] = 0; //到访率 $list = $personnel_summary ->alias("a") ->join(['school_campus_person_role' => 'b'], 'a.campus_person_role_id = b.id', 'left') ->where(['a.role_type' => 1,'b.campus_id' => $item['id']]) ->field("a.*") ->select(); foreach ($list as $val) { $date = explode('-', $val['task_date']); if($date[0] == date("Y")) { $item['year_task_num'] += $val['task_num']; $item['year_complete_num'] += $val['complete_num']; $item['year_expire_num'] += $val['expire_num']; $item['year_renew_num'] += $val['renew_num']; $item['year_resource_num'] += $val['resource_num']; $item['year_visit_num'] += $val['visit_num']; if($date[1] == date("m")){ $item['month_task_num'] += $val['task_num']; $item['month_complete_num'] += $val['complete_num']; $item['month_expire_num'] += $val['expire_num']; $item['month_renew_num'] += $val['renew_num']; $item['month_resource_num'] += $val['resource_num']; $item['month_visit_num'] += $val['visit_num']; $complete = $order->alias("a") ->join(['school_customer_resources' => 'b'], 'a.resource_id = b.id', 'left') ->where(['b.campus' => $item['id'], 'order_status' => 'paid','order_type' => 1]) ->count(); $item['month_zy_complete_num'] += $complete; } } } $item['complete'] = $item['year_complete_num'] > 0 ? round($item['year_complete_num'] / $item['year_task_num'], 2) : 0; $item['xf_complete'] = $item['year_renew_num'] > 0 ? round($item['year_renew_num'] / $item['year_expire_num'], 2) : 0; $item['month_complete'] = $item['month_complete_num'] > 0 ? round($item['month_complete_num'] / $item['month_task_num'], 2) : 0; $item['month_xf_complete'] = $item['month_renew_num'] > 0 ? round($item['month_renew_num'] / $item['month_expire_num'], 2) : 0; $item['ls_month_xf_complete'] = $item['month_expire_num'] > 0 ? round(($item['month_expire_num'] - $item['month_renew_num']) / $item['month_expire_num'], 2) : 0; $item['month_zy_complete'] = ($item['month_zy_complete_num'] > 0 and $item['month_task_num'] > 0) ? round($item['month_zy_complete_num'] / $item['month_task_num'], 2) : 0; $item['visit_num_rate'] = $item['month_visit_num'] > 0 ? round($item['month_visit_num'] / $item['month_resource_num'], 2) : 0; } //年度合计 $total_task = array_sum(array_column($campus_list, 'year_task_num')); $total_complete = array_sum(array_column($campus_list, 'year_complete_num')); $complete_rate = $total_complete > 0 ? round($total_complete / $total_task, 2) : 0; $total_expire = array_sum(array_column($campus_list, 'year_expire_num')); $total_renew = array_sum(array_column($campus_list, 'year_renew_num')); $xf_complete_rate = $total_renew > 0 ? round($total_renew / $total_expire, 2) : 0; //月度合计 $month_total_task = array_sum(array_column($campus_list, 'month_task_num')); $month_total_complete = array_sum(array_column($campus_list, 'month_complete_num')); $month_complete_rate = $month_total_complete > 0 ? round($month_total_complete / $month_total_task, 2) : 0; $month_total_expire = array_sum(array_column($campus_list, 'month_expire_num')); $month_total_renew = array_sum(array_column($campus_list, 'month_renew_num')); $month_xf_complete_rate = $month_total_renew > 0 ? round($month_total_renew / $month_total_expire, 2) : 0; $ls_month_xf_complete_rate = $month_total_expire > 0 ? round(($month_total_expire - $month_total_renew) / $month_total_expire, 2) : 0; //资源合计 $zy_total_task = array_sum(array_column($campus_list, 'month_task_num')); $zy_total_complete = array_sum(array_column($campus_list, 'month_zy_complete_num')); $zy_complete_rate = $zy_total_complete > 0 ? round($zy_total_complete / $zy_total_task, 2) : 0; $zy_month_visit_num = array_sum(array_column($campus_list, 'month_visit_num')); $zy_month_resource_num = array_sum(array_column($campus_list, 'month_resource_num')); $zy_visit_complete_rate = $zy_month_visit_num > 0 ? round($zy_month_visit_num / $zy_month_resource_num, 2) : 0; //月度个人业绩情况 $personnel_summary_list = $personnel_summary ->alias("a") ->join(['school_campus_person_role' => 'b'], 'a.campus_person_role_id = b.id', 'left') ->join(['school_personnel' => 'c'], 'c.id = b.person_id', 'left') ->where(['a.role_type' => 1,'a.task_date' => date("Y-m")]) ->field("a.*,c.name") ->select(); $year = date('Y'); foreach ($personnel_summary_list as &$row) { $row['year_complete_num'] = $personnel_summary ->where(['campus_person_role_id' => $row['campus_person_role_id']]) ->where('task_date', 'like', "$year-%") ->sum("complete_num"); $row['xf_complete'] = $row['renew_num'] > 0 ? round($row['renew_num'] / $row['expire_num'], 2) : 0; $row['ls_xf_complete'] = $row['expire_num'] > 0 ? round(($row['expire_num'] - $row['renew_num']) / $row['expire_num'], 2) : 0; } $wx_summary_list = $personnel_summary_list->toArray(); usort($wx_summary_list, function($a, $b) { return $b['complete_num'] <=> $a['complete_num']; }); $xf_summary_list = $personnel_summary_list->toArray(); usort($xf_summary_list, function($a, $b) { return $b['renew_num'] <=> $a['renew_num']; }); $jl_personnel_summary_list = $personnel_summary ->alias("a") ->join(['school_campus_person_role' => 'b'], 'a.campus_person_role_id = b.id', 'left') ->join(['school_personnel' => 'c'], 'c.id = b.person_id', 'left') ->where(['a.role_type' => 2,'a.task_date' => date("Y-m")]) ->field("a.*,c.name") ->select(); $year = date('Y'); foreach ($jl_personnel_summary_list as &$row) { $row['year_complete_num'] = $personnel_summary ->where(['campus_person_role_id' => $row['campus_person_role_id']]) ->where('task_date', 'like', "$year-%") ->sum("complete_num"); $row['xf_complete'] = $row['renew_num'] > 0 ? round($row['renew_num'] / $row['expire_num'], 2) : 0; $row['ls_xf_complete'] = $row['expire_num'] > 0 ? round(($row['expire_num'] - $row['renew_num']) / $row['expire_num'], 2) : 0; } $xf_jl_summary_list = $jl_personnel_summary_list->toArray(); usort($xf_summary_list, function($a, $b) { return $b['renew_num'] <=> $a['renew_num']; }); return [ 'year' => date("Y"), 'month' => date("m"), 'campus_list' => $campus_list, 'complete_rate' => $complete_rate, 'xf_complete_rate' => $xf_complete_rate, 'month_complete_rate' => $month_complete_rate, 'month_xf_complete_rate' => $month_xf_complete_rate, 'ls_month_xf_complete_rate' => $ls_month_xf_complete_rate, 'wx_summary_list' => $wx_summary_list, 'xf_summary_list' => $xf_summary_list, 'xf_jl_summary_list' => $xf_jl_summary_list, 'zy_complete_rate' => $zy_complete_rate, 'zy_visit_complete_rate' => $zy_visit_complete_rate ]; } public function scsjtj(array $row){ $customerResources = new CustomerResources(); $campus_person_role = new CampusPersonRole(); $communication_records = new CommunicationRecords(); $market_performance = new MarketPerformance(); $per = new Personnel(); $data['zysl'] = $customerResources->count(); $data['ygt'] = 0; $data['wgt'] = 0; $list = $customerResources->select(); foreach ($list as $k => $v) { if($communication_records->where(['resource_id' => $v['id']])->find()){ $data['ygt']++; }else{ $data['wgt']++; } } $data['scry'] = $campus_person_role->where(['dept_id' => 1])->count(); $start = date('Y-m-01'); $end = date('Y-m-t'); $data['yhs'] = $market_performance->whereBetween('performance_date', [$start, $end])->Sum("performance_amount"); $data['barData'] = []; $where = []; $c_where = []; if(!empty($row['dateRange'])){ $where[] = ['performance_date','>=',$row['dateRange'][0]]; $where[] = ['performance_date','<=',$row['dateRange'][1]]; $c_where[] = ['create_date','>=',$row['dateRange'][0]]; $c_where[] = ['create_date','<=',$row['dateRange'][1]]; } $sc_list = $campus_person_role->where(['dept_id' => 1])->select()->toArray(); foreach ($sc_list as $k => $v) { $data['barData'][] = [ 'name' => $per->where(['id' => $v['person_id']])->value('name'), 'value' => $market_performance->where(['personnel_id' => $v['person_id']])->where($where)->Sum("performance_amount") ]; } $arr = [0=>'未知',1=>'线上',2=>'地推',3=>'转介绍',4=>'活动',5=>'内部员工']; $data['pieData'] = []; foreach ($arr as $k => $v) { $data['pieData'][] = [ 'name' => $v, 'value' => $customerResources->where(['source_channel' => $k])->where($c_where)->count() ]; } return $data; } public function person_all(){ $Personnel = new Personnel(); return $Personnel->select()->toArray(); } public function role_all(){ $sysRole = new SysRole(); return $sysRole->select()->toArray(); } public function departments_all(){ $departments = new Departments(); return $departments->select()->toArray(); } //数据汇总表 public function personnel_summary(){ $campus_person_role = new CampusPersonRole(); $personnel_summary = new PersonnelSummary(); $role = [5,6]; $campus_person_role_list = $campus_person_role->where([ ['role_id','in',$role] ])->select(); $insertArr = []; foreach ($campus_person_role_list as $k => $v) { $insertArr[] = [ 'task_date' => date("Y-m"), 'campus_person_role_id' => $v['id'], 'role_type' => $v['role_id'] == 6 ? 1 : 2, ]; } $personnel_summary->insertAll($insertArr); return true; } }