You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
363 lines
12 KiB
363 lines
12 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service\admin\sys;
|
|
|
|
use addon\shop\app\model\ShopStat;
|
|
use app\job\sys\CheckJob;
|
|
use app\model\campus\Campus;
|
|
use app\model\campus_person_role\CampusPersonRole;
|
|
use app\model\communication_records\CommunicationRecords;
|
|
use app\model\customer_resources\CustomerResources;
|
|
use app\model\departments\Departments;
|
|
use app\model\market_performance\MarketPerformance;
|
|
use app\model\personnel\Personnel;
|
|
use app\model\student\Student;
|
|
use app\model\sys\SysConfig;
|
|
use app\model\sys\SysRole;
|
|
use app\service\core\sys\CoreSysConfigService;
|
|
use core\base\BaseAdminService;
|
|
use think\facade\Db;
|
|
use Throwable;
|
|
|
|
/**
|
|
* 系统信息服务层
|
|
* Class SystemService
|
|
* @package app\service\admin\sys
|
|
*/
|
|
class SystemService extends BaseAdminService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* 获取版权信息(网站整体,不按照站点设置)
|
|
* @return array
|
|
*/
|
|
public function getInfo()
|
|
{
|
|
return [
|
|
'os' => 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)
|
|
]);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
public function get_xsyj_config(){
|
|
$config = new SysConfig();
|
|
|
|
$data = $config->where(['config_key' => 'XSYJ'])->value("value");
|
|
|
|
return $data;
|
|
}
|
|
|
|
|
|
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 home(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;
|
|
|
|
return $data;
|
|
}
|
|
|
|
|
|
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();
|
|
}
|
|
|
|
}
|
|
|