Browse Source

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	app/common.php
master
wanghongjun 3 years ago
parent
commit
d37d054fe3
  1. 110
      app/BaseController.php
  2. 102
      app/common.php
  3. 3
      app/controller/Index.php
  4. 3
      composer.json
  5. 96
      composer.lock
  6. 6
      config/view.php
  7. BIN
      doc/HIK接口.docx
  8. 0
      view/index/index.html

110
app/BaseController.php

@ -6,6 +6,9 @@ namespace app;
use think\App;
use think\exception\ValidateException;
use think\Validate;
use think\facade\View;
use think\facade\Config;
use think\facade\Request;
/**
* 控制器基础类
@ -36,6 +39,33 @@ abstract class BaseController
*/
protected $middleware = [];
/* @var array $admin 商家登录信息 */
protected $admin;
/* @var string $route 当前控制器名称 */
protected $controller = '';
/* @var string $route 当前方法名称 */
protected $action = '';
/* @var string $route 当前路由uri */
protected $routeUri = '';
/* @var string $route 当前路由:分组名称 */
protected $group = '';
/* @var array $allowAllAction 登录验证白名单 */
protected $allowAllAction = [
// 登录页面
'passport/login',
];
/* @var array $notLayoutAction 无需全局layout */
protected $notLayoutAction = [
// 登录页面
'passport/login',
];
/**
* 构造方法
* @access public
@ -48,6 +78,28 @@ abstract class BaseController
// 控制器初始化
$this->initialize();
// 全局layout
$this->layout();
}
/**
* 全局layout模板输出
* @throws \Exception
*/
private function layout()
{
// 验证当前请求是否在白名单
if (!in_array($this->routeUri, $this->notLayoutAction)) {
// 输出到view
View::assign([
'base_url' => base_url(), // 当前域名
'admin_url' => url('/admin'), // 后台模块url
'group' => $this->group,
'menus' => $this->menus(), // 后台菜单
'admin' => $this->admin, // 商家登录信息
'request' => Request::instance() // Request对象
]);
}
}
// 初始化
@ -91,4 +143,62 @@ abstract class BaseController
return $v->failException(true)->check($data);
}
/**
* 解析当前路由参数 (分组名称、控制器名称、方法名)
*/
protected function getRouteinfo()
{
// 控制器名称
$this->controller = toUnderScore($this->request->controller());
// 方法名称
$this->action = $this->request->action();
// 控制器分组 (用于定义所属模块)
$groupstr = strstr($this->controller, '.', true);
$this->group = $groupstr !== false ? $groupstr : $this->controller;
// 当前uri
$this->routeUri = $this->controller . '/' . $this->action;
}
/**
* 后台菜单配置
* @return array
*/
private function menus()
{
foreach ($data = Config::get('menus') as $group => $first) {
$data[$group]['active'] = $group === $this->group;
// 遍历:二级菜单
if (isset($first['submenu'])) {
foreach ($first['submenu'] as $secondKey => $second) {
// 二级菜单所有uri
$secondUris = isset($second['uris']) ? $second['uris'] : [$second['index']];
// 二级菜单:active
!isset($data[$group]['submenu'][$secondKey]['active'])
&& $data[$group]['submenu'][$secondKey]['active'] = in_array($this->routeUri, $secondUris);
}
}
}
return $data;
}
/**
* 验证登录状态
* @return bool
*/
private function checkLogin()
{
// 验证当前请求是否在白名单
if (in_array($this->routeUri, $this->allowAllAction)) {
return true;
}
// 验证登录状态
if (empty($this->admin)
|| (int)$this->admin['is_login'] !== 1
) {
$this->redirect('passport/login');
return false;
}
return true;
}
}

102
app/common.php

@ -1,6 +1,6 @@
<?php
// 应用公共文件
use think\facade\Request;
/**
* 模拟GET请求 HTTPS的页面
* @param string $url 请求地址
@ -125,93 +125,17 @@ function post2($url, array $data = [])
return $result;
}
function getStartAndEndDatetime($period) {
switch ($period) {
case 'today':
$startDatetime = strtotime('today');
$endDatetime = strtotime('tomorrow - 1 second');
break;
case 'this_week':
$startDatetime = strtotime('this week');
$endDatetime = strtotime('next week - 1 second');
break;
case 'this_month':
$startDatetime = strtotime('first day of this month');
$endDatetime = strtotime('first day of next month - 1 second');
break;
case 'this_year':
$startDatetime = strtotime('first day of January this year');
$endDatetime = strtotime('first day of January next year - 1 second');
break;
default:
return null;
}
$startDatetimeStr = date('Y-m-d H:i:s', $startDatetime);
$endDatetimeStr = date('Y-m-d H:i:s', $endDatetime);
return [
'start_datetime' => $startDatetimeStr,
'end_datetime' => $endDatetimeStr
];
}
function getTargetDate($granularity = 'all') {
$data = [];
if ($granularity === 'day' || $granularity === 'all') {
$date = $granularity !== 'all' ? $granularity : 'day';
$data[$date] = [
'start_time' => strtotime('today'),
'end_time' => strtotime('tomorrow - 1 second'),
];
}
if ($granularity === 'week' || $granularity === 'all') {
$date = $granularity !== 'all' ? $granularity : 'week';
$data[$date] = [
'start_time' => strtotime('this week midnight'),
'end_time' => strtotime('next week midnight - 1 second'),
];
}
if ($granularity === 'month' || $granularity === 'all') {
$date = $granularity !== 'all' ? $granularity : 'month';
$data[$date] = [
'start_time' => strtotime(date('Y-m-01 00:00:00')),
'end_time' => strtotime(date('Y-m-t 23:59:59')),
];
}
if ($granularity === 'year' || $granularity === 'all') {
$date = $granularity !== 'all' ? $granularity : 'year';
$data[$date] = [
'start_time' => strtotime('first day of January this year'),
'end_time' => strtotime('first day of January next year - 1 second'),
];
}
foreach ($data as &$val) {
$val['c_start_time'] = date("c",$val['start_time']);
$val['c_end_time'] = date("c",$val['end_time']);
$val['start_time'] = date("Y-m-d H:i:s",$val['start_time']);
$val['end_time'] = date("Y-m-d H:i:s",$val['end_time']);
}
return $data;
}
function formatNumber($number) {
if ($number < 10000) {
return number_format($number);
} else if ($number < 100000000) {
if ($number % 10000 == 0) {
return number_format($number / 10000) . '万';
} else {
return number_format($number);
}
} else {
if ($number % 100000000 == 0) {
return number_format($number / 100000000) . '亿';
} else {
return number_format($number);
}
/**
* 获取当前域名及根路径
* @return string
*/
function base_url()
{
static $baseUrl = '';
if (empty($baseUrl)) {
$request = Request::instance();
$subDir = str_replace('\\', '/', dirname($request->server('PHP_SELF')));
$baseUrl = $request->scheme() . '://' . $request->host() . $subDir . ($subDir === '/' ? '' : '/');
}
return $baseUrl;
}

3
app/controller/Index.php

@ -2,12 +2,13 @@
namespace app\controller;
use app\BaseController;
use think\facade\View;
class Index extends BaseController
{
public function index()
{
return phpinfo();
return view("index");
//return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V' . \think\facade\App::version() . '<br/><span style="font-size:30px;">14载初心不改 - 你值得信赖的PHP框架</span></p><span style="font-size:25px;">[ V6.0 版本由 <a href="https://www.yisu.com/" target="yisu">亿速云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ee9b1aa918103c4fc"></think>';
}

3
composer.json

@ -22,7 +22,8 @@
"require": {
"php": ">=7.1.0",
"topthink/framework": "^6.0.0",
"topthink/think-orm": "^2.0"
"topthink/think-orm": "^2.0",
"topthink/think-view": "^1.0"
},
"require-dev": {
"symfony/var-dumper": "^4.2",

96
composer.lock

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "74a749574e0f40df27b0061a71e2b878",
"content-hash": "3b129548bb372dfb395fcb114b7f7071",
"packages": [
{
"name": "league/flysystem",
@ -562,6 +562,100 @@
"source": "https://github.com/top-think/think-orm/tree/v2.0.61"
},
"time": "2023-04-20T14:27:51+00:00"
},
{
"name": "topthink/think-template",
"version": "v2.0.9",
"source": {
"type": "git",
"url": "https://github.com/top-think/think-template.git",
"reference": "6d25642ae0e306166742fd7073dc7a159e18073c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/think-template/zipball/6d25642ae0e306166742fd7073dc7a159e18073c",
"reference": "6d25642ae0e306166742fd7073dc7a159e18073c",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=7.1.0",
"psr/simple-cache": "^1.0"
},
"type": "library",
"autoload": {
"psr-4": {
"think\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "liu21st",
"email": "liu21st@gmail.com"
}
],
"description": "the php template engine",
"support": {
"issues": "https://github.com/top-think/think-template/issues",
"source": "https://github.com/top-think/think-template/tree/v2.0.9"
},
"time": "2023-02-14T10:50:39+00:00"
},
{
"name": "topthink/think-view",
"version": "v1.0.14",
"source": {
"type": "git",
"url": "https://github.com/top-think/think-view.git",
"reference": "edce0ae2c9551ab65f9e94a222604b0dead3576d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/think-view/zipball/edce0ae2c9551ab65f9e94a222604b0dead3576d",
"reference": "edce0ae2c9551ab65f9e94a222604b0dead3576d",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=7.1.0",
"topthink/think-template": "^2.0"
},
"type": "library",
"autoload": {
"psr-4": {
"think\\view\\driver\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "liu21st",
"email": "liu21st@gmail.com"
}
],
"description": "thinkphp template driver",
"support": {
"issues": "https://github.com/top-think/think-view/issues",
"source": "https://github.com/top-think/think-view/tree/v1.0.14"
},
"time": "2019-11-06T11:40:13+00:00"
}
],
"packages-dev": [

6
config/view.php

@ -11,7 +11,7 @@ return [
// 模板目录名
'view_dir_name' => 'view',
// 模板后缀
'view_suffix' => 'html',
'view_suffix' => 'php',
// 模板文件名分隔符
'view_depr' => DIRECTORY_SEPARATOR,
// 模板引擎普通标签开始标记
@ -22,4 +22,8 @@ return [
'taglib_begin' => '{',
// 标签库标签结束标记
'taglib_end' => '}',
// layout 设置
'layout_on' => true,
'layout_name' => 'layouts/layout',
'layout_item' => '{__CONTENT__}'
];

BIN
doc/HIK接口.docx

Binary file not shown.

0
view/index/index.html

Loading…
Cancel
Save