commit
75fd8d7d23
1482 changed files with 283283 additions and 0 deletions
@ -0,0 +1,18 @@ |
|||||
|
APP_DEBUG = true |
||||
|
|
||||
|
[APP] |
||||
|
DEFAULT_TIMEZONE = Asia/Shanghai |
||||
|
|
||||
|
[DATABASE] |
||||
|
TYPE = mysql |
||||
|
HOSTNAME = 127.0.0.1 |
||||
|
DATABASE = www.test.com |
||||
|
USERNAME = root |
||||
|
PASSWORD =123456 |
||||
|
HOSTPORT = 3306 |
||||
|
CHARSET = utf8mb4 |
||||
|
DEBUG = true |
||||
|
PREFIX = tp_ |
||||
|
|
||||
|
[LANG] |
||||
|
default_lang = zh-cn |
||||
@ -0,0 +1,4 @@ |
|||||
|
/.idea |
||||
|
/.vscode |
||||
|
*.log |
||||
|
/runtime |
||||
@ -0,0 +1 @@ |
|||||
|
|
||||
@ -0,0 +1,42 @@ |
|||||
|
sudo: false |
||||
|
|
||||
|
language: php |
||||
|
|
||||
|
branches: |
||||
|
only: |
||||
|
- stable |
||||
|
|
||||
|
cache: |
||||
|
directories: |
||||
|
- $HOME/.composer/cache |
||||
|
|
||||
|
before_install: |
||||
|
- composer self-update |
||||
|
|
||||
|
install: |
||||
|
- composer install --no-dev --no-interaction --ignore-platform-reqs |
||||
|
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Core.zip . |
||||
|
- composer require --update-no-dev --no-interaction "topthink/think-image:^1.0" |
||||
|
- composer require --update-no-dev --no-interaction "topthink/think-migration:^1.0" |
||||
|
- composer require --update-no-dev --no-interaction "topthink/think-captcha:^1.0" |
||||
|
- composer require --update-no-dev --no-interaction "topthink/think-mongo:^1.0" |
||||
|
- composer require --update-no-dev --no-interaction "topthink/think-worker:^1.0" |
||||
|
- composer require --update-no-dev --no-interaction "topthink/think-helper:^1.0" |
||||
|
- composer require --update-no-dev --no-interaction "topthink/think-queue:^1.0" |
||||
|
- composer require --update-no-dev --no-interaction "topthink/think-angular:^1.0" |
||||
|
- composer require --dev --update-no-dev --no-interaction "topthink/think-testing:^1.0" |
||||
|
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Full.zip . |
||||
|
|
||||
|
script: |
||||
|
- php think unit |
||||
|
|
||||
|
deploy: |
||||
|
provider: releases |
||||
|
api_key: |
||||
|
secure: TSF6bnl2JYN72UQOORAJYL+CqIryP2gHVKt6grfveQ7d9rleAEoxlq6PWxbvTI4jZ5nrPpUcBUpWIJHNgVcs+bzLFtyh5THaLqm39uCgBbrW7M8rI26L8sBh/6nsdtGgdeQrO/cLu31QoTzbwuz1WfAVoCdCkOSZeXyT/CclH99qV6RYyQYqaD2wpRjrhA5O4fSsEkiPVuk0GaOogFlrQHx+C+lHnf6pa1KxEoN1A0UxxVfGX6K4y5g4WQDO5zT4bLeubkWOXK0G51XSvACDOZVIyLdjApaOFTwamPcD3S1tfvuxRWWvsCD5ljFvb2kSmx5BIBNwN80MzuBmrGIC27XLGOxyMerwKxB6DskNUO9PflKHDPI61DRq0FTy1fv70SFMSiAtUv9aJRT41NQh9iJJ0vC8dl+xcxrWIjU1GG6+l/ZcRqVx9V1VuGQsLKndGhja7SQ+X1slHl76fRq223sMOql7MFCd0vvvxVQ2V39CcFKao/LB1aPH3VhODDEyxwx6aXoTznvC/QPepgWsHOWQzKj9ftsgDbsNiyFlXL4cu8DWUty6rQy8zT2b4O8b1xjcwSUCsy+auEjBamzQkMJFNlZAIUrukL/NbUhQU37TAbwsFyz7X0E/u/VMle/nBCNAzgkMwAUjiHM6FqrKKBRWFbPrSIixjfjkCnrMEPw= |
||||
|
file: |
||||
|
- ThinkPHP_Core.zip |
||||
|
- ThinkPHP_Full.zip |
||||
|
skip_cleanup: true |
||||
|
on: |
||||
|
tags: true |
||||
@ -0,0 +1,26 @@ |
|||||
|
<!doctype html> |
||||
|
<html> |
||||
|
<head> |
||||
|
<meta charset="utf-8"> |
||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> |
||||
|
<title>404</title> |
||||
|
<style> |
||||
|
body{ |
||||
|
background-color:#444; |
||||
|
font-size:14px; |
||||
|
} |
||||
|
h3{ |
||||
|
font-size:60px; |
||||
|
color:#eee; |
||||
|
text-align:center; |
||||
|
padding-top:30px; |
||||
|
font-weight:normal; |
||||
|
} |
||||
|
</style> |
||||
|
</head> |
||||
|
|
||||
|
<body> |
||||
|
<h3>404,您请求的文件不存在!</h3> |
||||
|
</body> |
||||
|
</html> |
||||
@ -0,0 +1,3 @@ |
|||||
|
# www.yaoli.com |
||||
|
|
||||
|
yaoli.com |
||||
@ -0,0 +1 @@ |
|||||
|
deny from all |
||||
@ -0,0 +1,22 @@ |
|||||
|
<?php |
||||
|
declare (strict_types = 1); |
||||
|
|
||||
|
namespace app; |
||||
|
|
||||
|
use think\Service; |
||||
|
|
||||
|
/** |
||||
|
* 应用服务类 |
||||
|
*/ |
||||
|
class AppService extends Service |
||||
|
{ |
||||
|
public function register() |
||||
|
{ |
||||
|
// 服务注册 |
||||
|
} |
||||
|
|
||||
|
public function boot() |
||||
|
{ |
||||
|
// 服务启动 |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,58 @@ |
|||||
|
<?php |
||||
|
namespace app; |
||||
|
|
||||
|
use think\db\exception\DataNotFoundException; |
||||
|
use think\db\exception\ModelNotFoundException; |
||||
|
use think\exception\Handle; |
||||
|
use think\exception\HttpException; |
||||
|
use think\exception\HttpResponseException; |
||||
|
use think\exception\ValidateException; |
||||
|
use think\Response; |
||||
|
use Throwable; |
||||
|
|
||||
|
/** |
||||
|
* 应用异常处理类 |
||||
|
*/ |
||||
|
class ExceptionHandle extends Handle |
||||
|
{ |
||||
|
/** |
||||
|
* 不需要记录信息(日志)的异常类列表 |
||||
|
* @var array |
||||
|
*/ |
||||
|
protected $ignoreReport = [ |
||||
|
HttpException::class, |
||||
|
HttpResponseException::class, |
||||
|
ModelNotFoundException::class, |
||||
|
DataNotFoundException::class, |
||||
|
ValidateException::class, |
||||
|
]; |
||||
|
|
||||
|
/** |
||||
|
* 记录异常信息(包括日志或者其它方式记录) |
||||
|
* |
||||
|
* @access public |
||||
|
* @param Throwable $exception |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function report(Throwable $exception): void |
||||
|
{ |
||||
|
// 使用内置的方式记录异常日志 |
||||
|
parent::report($exception); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Render an exception into an HTTP response. |
||||
|
* |
||||
|
* @access public |
||||
|
* @param \think\Request $request |
||||
|
* @param Throwable $e |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function render($request, Throwable $e): Response |
||||
|
{ |
||||
|
// 添加自定义异常处理机制 |
||||
|
|
||||
|
// 其他错误交给系统处理 |
||||
|
return parent::render($request, $e); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
<?php |
||||
|
namespace app; |
||||
|
|
||||
|
// 应用请求对象类 |
||||
|
class Request extends \think\Request |
||||
|
{ |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
{ |
||||
|
"name": "捕梦者", |
||||
|
"version": "6.0.0", |
||||
|
"description": "api接口", |
||||
|
"title": "捕梦者 V6 API接口", |
||||
|
"url": "http://tp6.com/api", |
||||
|
"header": { |
||||
|
"title": "捕梦者", |
||||
|
"filename": "" |
||||
|
}, |
||||
|
"template": { |
||||
|
"withCompare": true, |
||||
|
"withGenerator": false |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ] |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved. |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: liu21st <liu21st@gmail.com> |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 应用设置 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
return [ |
||||
|
// 默认分页显示数量 |
||||
|
'page_size' => 10, |
||||
|
]; |
||||
@ -0,0 +1,99 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | api基础控制器 |
||||
|
|
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
declare (strict_types = 1); |
||||
|
|
||||
|
namespace app\api\controller; |
||||
|
|
||||
|
use think\App; |
||||
|
use think\facade\Config; |
||||
|
use think\facade\Request; |
||||
|
use think\Response; |
||||
|
use think\Validate; |
||||
|
use think\exception\HttpResponseException; |
||||
|
|
||||
|
/** |
||||
|
* 控制器基础类 |
||||
|
*/ |
||||
|
abstract class Base |
||||
|
{ |
||||
|
/** |
||||
|
* Request实例 |
||||
|
* @var \think\Request |
||||
|
*/ |
||||
|
protected $request; |
||||
|
|
||||
|
/** |
||||
|
* 应用实例 |
||||
|
* @var \think\App |
||||
|
*/ |
||||
|
protected $app; |
||||
|
|
||||
|
/** |
||||
|
* 是否批量验证 |
||||
|
* @var bool |
||||
|
*/ |
||||
|
protected $batchValidate = false; |
||||
|
|
||||
|
/** |
||||
|
* 控制器中间件 |
||||
|
* @var array |
||||
|
*/ |
||||
|
protected $middleware = []; |
||||
|
|
||||
|
/** |
||||
|
* 分页数量 |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $pageSize = ''; |
||||
|
|
||||
|
/** |
||||
|
* 构造方法 |
||||
|
* @access public |
||||
|
* @param App $app 应用对象 |
||||
|
*/ |
||||
|
public function __construct(App $app) |
||||
|
{ |
||||
|
$this->app = $app; |
||||
|
$this->request = $this->app->request; |
||||
|
|
||||
|
// 控制器初始化 |
||||
|
$this->initialize(); |
||||
|
} |
||||
|
|
||||
|
// 初始化 |
||||
|
protected function initialize() |
||||
|
{ |
||||
|
//每页显示数据量 |
||||
|
$this->pageSize = Request::param('page_size', Config::get('app.page_size')); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 返回封装后的API数据到客户端 |
||||
|
* @param mixed $data 要返回的数据 |
||||
|
* @param integer $code 返回的code |
||||
|
* @param mixed $msg 提示信息 |
||||
|
* @param string $type 返回数据格式 |
||||
|
* @param array $header 发送的Header信息 |
||||
|
* @return Response |
||||
|
*/ |
||||
|
protected function result($data, int $code = 0, $msg = '', string $type = '', array $header = []): Response |
||||
|
{ |
||||
|
$result = [ |
||||
|
'code' => $code, |
||||
|
'msg' => $msg, |
||||
|
'time' => time(), |
||||
|
'data' => $data, |
||||
|
]; |
||||
|
|
||||
|
$type = $type ?: 'json'; |
||||
|
$response = Response::create($result, $type)->header($header); |
||||
|
|
||||
|
throw new HttpResponseException($response); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,405 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 上传控制器 |
||||
|
|
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\api\controller; |
||||
|
|
||||
|
use function GuzzleHttp\Psr7\str; |
||||
|
use think\App; |
||||
|
use think\facade\Env; |
||||
|
use think\facade\Request; |
||||
|
use think\Response; |
||||
|
|
||||
|
class Upload extends Base |
||||
|
{ |
||||
|
|
||||
|
// 上传方式 [chunk 大文件分片上传, tp 沿用TP上传] |
||||
|
private $uploadType = ""; |
||||
|
|
||||
|
// 上传验证规则 |
||||
|
protected $uploadValidate = []; |
||||
|
|
||||
|
// 构造方法 |
||||
|
public function __construct(App $app) |
||||
|
{ |
||||
|
parent::__construct($app); |
||||
|
// 默认上传方式 |
||||
|
$this->uploadType = "chunk"; |
||||
|
|
||||
|
// 验证规则 |
||||
|
$this->uploadValidate = [ |
||||
|
'file' => $this->uploadVal() |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
// 上传文件 |
||||
|
public function index() |
||||
|
{ |
||||
|
if (Request::param('from') == 'ckeditor') { |
||||
|
// 获取上传文件表单字段名 |
||||
|
$fileKey = array_keys(request()->file()); |
||||
|
$path = []; |
||||
|
for ($i = 0; $i < count($fileKey); $i++) { |
||||
|
// 获取表单上传文件并执行上传操作 |
||||
|
$uploadFile = $this->uploadFile($fileKey[$i]); |
||||
|
if ($uploadFile['code'] == 1) { |
||||
|
$path[] = $uploadFile['url']; |
||||
|
} else { |
||||
|
$path = []; |
||||
|
$error = $uploadFile['msg']; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if ($path) { |
||||
|
$result['uploaded'] = true; |
||||
|
// 分辨是否截图上传,截图上传只能上传一个,非截图上传可以上传多个 |
||||
|
if (Request::param('responseType') == 'json') { |
||||
|
$result["url"] = $path[0]; |
||||
|
} else { |
||||
|
$result["url"] = $path; |
||||
|
} |
||||
|
return json_encode($result); |
||||
|
} else { |
||||
|
// 上传失败 |
||||
|
$result['uploaded'] = false; |
||||
|
$result['url'] = ''; |
||||
|
$result['message'] = $error; |
||||
|
return json_encode($result, true); |
||||
|
} |
||||
|
} else { |
||||
|
if ($this->uploadType == 'tp') { |
||||
|
// webupload [file是webloader固定写入的隐藏文本名称] |
||||
|
return json($this->uploadFile('file')); |
||||
|
} else { |
||||
|
return json($this->bigUpload()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 上传验证 |
||||
|
private function uploadVal() |
||||
|
{ |
||||
|
$file = []; |
||||
|
if (Request::param('upload_type') == 'file') { |
||||
|
// 文件限制 |
||||
|
if (config('config.upload_file_ext')) { |
||||
|
$file['fileExt'] = config('config.upload_file_ext'); |
||||
|
} else { |
||||
|
$file['fileExt'] = 'rar,zip,avi,rmvb,3gp,flv,mp3,mp4,txt,doc,xls,ppt,pdf,xls,docx,xlsx,doc,pptx'; |
||||
|
} |
||||
|
// 限制文件大小(单位b) |
||||
|
if (config('config.upload_file_size')) { |
||||
|
$file['fileSize'] = config('config.upload_file_size') * 1024; |
||||
|
} |
||||
|
} else { |
||||
|
// 图片限制 |
||||
|
if (config('config.upload_image_ext')) { |
||||
|
$file['fileExt'] = config('config.upload_image_ext'); |
||||
|
} else { |
||||
|
$file['fileExt'] = 'jpg,png,gif,jpeg'; |
||||
|
} |
||||
|
// 限制图片大小(单位b) |
||||
|
if (config('config.upload_image_size')) { |
||||
|
$file['fileSize'] = config('config.upload_image_size') * 1024; |
||||
|
} |
||||
|
} |
||||
|
return $file; |
||||
|
} |
||||
|
|
||||
|
// tp上传文件 |
||||
|
private function uploadFile(string $fileName) |
||||
|
{ |
||||
|
$file = request()->file($fileName); |
||||
|
try { |
||||
|
validate($this->uploadValidate) |
||||
|
->check(['file' => $file]); |
||||
|
$savename = \think\facade\Filesystem::disk('public')->putFile('uploads', $file); |
||||
|
// windows系统中路径反斜杠处理 |
||||
|
$savename = str_replace('\\', '/', $savename); |
||||
|
return [ |
||||
|
'code' => 1, |
||||
|
'msg' => '上传成功', |
||||
|
'url' => '/' . $savename |
||||
|
]; |
||||
|
} catch (\Exception $e) { // think\exception\ValidateException 取消验证异常捕获 |
||||
|
return [ |
||||
|
'code' => 0, |
||||
|
'msg' => 'ERROR:' . $e->getMessage(), |
||||
|
'url' => '' |
||||
|
]; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 大文件切片上传 |
||||
|
private function bigUpload() |
||||
|
{ |
||||
|
$host = $_SERVER['HTTP_ORIGIN']; |
||||
|
$host = str_replace('http://','',$host); |
||||
|
$host = str_replace('https://','',$host); |
||||
|
|
||||
|
$root_path = dirname(root_path()); |
||||
|
|
||||
|
if($host == ''){ |
||||
|
$host = 'default'; |
||||
|
} |
||||
|
$host_ori = $host; |
||||
|
$host = md5($host); |
||||
|
// 验证 |
||||
|
$file = request()->file('file'); |
||||
|
try { |
||||
|
validate($this->uploadValidate) |
||||
|
->check(['file' => $file]); |
||||
|
} catch (\Exception $e) { // think\exception\ValidateException 取消验证异常捕获 |
||||
|
return [ |
||||
|
'code' => 0, |
||||
|
'msg' => 'ERROR:' . $e->getMessage(), |
||||
|
'url' => '' |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
// Make sure file is not cached (as it happens for example on iOS devices) |
||||
|
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); |
||||
|
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
||||
|
header("Cache-Control: no-store, no-cache, must-revalidate"); |
||||
|
header("Cache-Control: post-check=0, pre-check=0", false); |
||||
|
header("Pragma: no-cache"); |
||||
|
|
||||
|
// 跨域支持 |
||||
|
// header("Access-Control-Allow-Origin: *"); |
||||
|
// other CORS headers if any... |
||||
|
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { |
||||
|
exit; // finish preflight CORS requests here |
||||
|
} |
||||
|
|
||||
|
if (!empty($_REQUEST['debug'])) { |
||||
|
$random = rand(0, intval($_REQUEST['debug'])); |
||||
|
if ($random === 0) { |
||||
|
header("HTTP/1.0 500 Internal Server Error"); |
||||
|
exit; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 页面执行时间不限制 |
||||
|
@set_time_limit(5 * 60); |
||||
|
|
||||
|
// Uncomment this one to fake upload time |
||||
|
// usleep(5000); |
||||
|
|
||||
|
// Settings |
||||
|
// $targetDir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload"; |
||||
|
// 设置临时上传目录 |
||||
|
$targetDir = 'uploads' . DIRECTORY_SEPARATOR . 'temp'; |
||||
|
$y = date('Y'); |
||||
|
$m = date('m'); |
||||
|
$d = date('d'); |
||||
|
// 设置上传目录 |
||||
|
$uploadDir = $root_path.DIRECTORY_SEPARATOR. 'static.ahbmz.com' . DIRECTORY_SEPARATOR .$host . DIRECTORY_SEPARATOR . $y.DIRECTORY_SEPARATOR .$m .DIRECTORY_SEPARATOR .$d ; |
||||
|
$returnDir = config('config.static_image_url').$host . DIRECTORY_SEPARATOR . $y.DIRECTORY_SEPARATOR . $m.DIRECTORY_SEPARATOR . $d; |
||||
|
// 上传完后清空临时目录 |
||||
|
$cleanupTargetDir = true; |
||||
|
// 临时文件期限 |
||||
|
$maxFileAge = 5 * 3600; |
||||
|
|
||||
|
// 创建临时目录 |
||||
|
if (!file_exists($targetDir)) { |
||||
|
@mkdir($targetDir); |
||||
|
} |
||||
|
|
||||
|
// 创建上传目录 |
||||
|
if (!file_exists($uploadDir)) { |
||||
|
@mkdir($uploadDir,0777,true); |
||||
|
} |
||||
|
|
||||
|
// 获取上传文件名称 |
||||
|
if (isset($_REQUEST["name"])) { |
||||
|
$fileName = $_REQUEST["name"]; |
||||
|
} elseif (!empty($_FILES)) { |
||||
|
$fileName = $_FILES["file"]["name"]; |
||||
|
} else { |
||||
|
$fileName = uniqid("file_"); |
||||
|
} |
||||
|
|
||||
|
$size = 0; |
||||
|
if(!empty($_FILES)){ |
||||
|
$size = $_FILES["file"]["size"]; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
$oldName = $fileName; |
||||
|
$fileName = iconv('UTF-8','gb2312',$fileName); |
||||
|
|
||||
|
// 临时上传完整目录信息 |
||||
|
$filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName; |
||||
|
|
||||
|
// 定义命名规则 |
||||
|
$pathInfo = pathinfo($fileName); |
||||
|
// md5 |
||||
|
$fileName = md5(time() . $pathInfo['basename']) . '.' . $pathInfo['extension']; |
||||
|
|
||||
|
// 正式上传完整目录信息 |
||||
|
$uploadPath = $uploadDir . DIRECTORY_SEPARATOR . $fileName; |
||||
|
$returnPath = $returnDir.DIRECTORY_SEPARATOR . $fileName; |
||||
|
|
||||
|
// Chunking might be enabled |
||||
|
$chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0; |
||||
|
$chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 1; |
||||
|
|
||||
|
// 清空临时目录 |
||||
|
if ($cleanupTargetDir) { |
||||
|
if (!is_dir($targetDir) || !$dir = opendir($targetDir)) { |
||||
|
return [ |
||||
|
'code' => 0, |
||||
|
'msg' => 'Failed to open temp directory.', |
||||
|
'url' => '' |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
while (($file = readdir($dir)) !== false) { |
||||
|
$tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file; |
||||
|
|
||||
|
// 如果临时文件是当前文件,则转到下一个 |
||||
|
if ($tmpfilePath == "{$filePath}_{$chunk}.part" || $tmpfilePath == "{$filePath}_{$chunk}.parttmp") { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
// 如果临时文件早于最大使用期限并且不是当前文件,则将其删除 |
||||
|
if (preg_match('/\.(part|parttmp)$/', $file) && (@filemtime($tmpfilePath) < time() - $maxFileAge)) { |
||||
|
@unlink($tmpfilePath); |
||||
|
} |
||||
|
} |
||||
|
closedir($dir); |
||||
|
} |
||||
|
|
||||
|
// 打开临时文件 |
||||
|
if (!$out = @fopen("{$filePath}_{$chunk}.parttmp", "wb")) { |
||||
|
return [ |
||||
|
'code' => 0, |
||||
|
'msg' => 'Failed to open output stream.', |
||||
|
'url' => '' |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
if (!empty($_FILES)) { |
||||
|
if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) { |
||||
|
return [ |
||||
|
'code' => 0, |
||||
|
'msg' => 'Failed to move uploaded file.', |
||||
|
'url' => '' |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
// 读取二进制输入流并将其附加到临时文件 |
||||
|
if (!$in = @fopen($_FILES["file"]["tmp_name"], "rb")) { |
||||
|
return [ |
||||
|
'code' => 0, |
||||
|
'msg' => 'Failed to open input stream.', |
||||
|
'url' => '' |
||||
|
]; |
||||
|
} |
||||
|
} else { |
||||
|
if (!$in = @fopen("php://input", "rb")) { |
||||
|
return [ |
||||
|
'code' => 0, |
||||
|
'msg' => 'Failed to open input stream.', |
||||
|
'url' => '' |
||||
|
]; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
while ($buff = fread($in, 4096)) { |
||||
|
fwrite($out, $buff); |
||||
|
} |
||||
|
|
||||
|
@fclose($out); |
||||
|
@fclose($in); |
||||
|
|
||||
|
rename("{$filePath}_{$chunk}.parttmp", "{$filePath}_{$chunk}.part"); |
||||
|
|
||||
|
$index = 0; |
||||
|
$done = true; |
||||
|
for ($index = 0; $index < $chunks; $index++) { |
||||
|
if (!file_exists("{$filePath}_{$index}.part")) { |
||||
|
$done = false; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
if ($done) { |
||||
|
if (!$out = @fopen($uploadPath, "wb")) { |
||||
|
return [ |
||||
|
'code' => 0, |
||||
|
'msg' => 'Failed to open output stream.', |
||||
|
'url' => '' |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
if (flock($out, LOCK_EX)) { |
||||
|
for ($index = 0; $index < $chunks; $index++) { |
||||
|
if (!$in = @fopen("{$filePath}_{$index}.part", "rb")) { |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
while ($buff = fread($in, 4096)) { |
||||
|
fwrite($out, $buff); |
||||
|
} |
||||
|
|
||||
|
@fclose($in); |
||||
|
@unlink("{$filePath}_{$index}.part"); |
||||
|
} |
||||
|
|
||||
|
flock($out, LOCK_UN); |
||||
|
} |
||||
|
@fclose($out); |
||||
|
|
||||
|
// 输出 |
||||
|
// windows系统中路径反斜杠处理 |
||||
|
$uploadPath = str_replace('\\', '/', $uploadPath); |
||||
|
$returnPath = str_replace('\\', '/', $returnPath); |
||||
|
|
||||
|
//将数据上传到数据库中 |
||||
|
$data = [ |
||||
|
'name' => $fileName, |
||||
|
'host' => $host_ori, |
||||
|
'y' => $y, |
||||
|
'm' => $m, |
||||
|
'd' => $d, |
||||
|
'url' => $returnPath, |
||||
|
'date' => $m.$d, |
||||
|
'type' => $pathInfo['extension'], |
||||
|
'size' => $size |
||||
|
]; |
||||
|
//curl(config('config.log_image_url'),$data); |
||||
|
$header = [ |
||||
|
'Token:'.request()->header('token'), |
||||
|
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36' |
||||
|
]; |
||||
|
curl(config('config.log_image_url'),$data,$header); |
||||
|
|
||||
|
|
||||
|
return [ |
||||
|
'code' => 0, |
||||
|
'msg' => '上传成功,请到对应文件夹查看', |
||||
|
'url' => $returnPath, |
||||
|
]; |
||||
|
|
||||
|
// return $response; |
||||
|
|
||||
|
/*$response = [ |
||||
|
'success'=>true, |
||||
|
'oldName'=>$oldName, |
||||
|
'filePaht'=>$uploadPath, |
||||
|
'fileSize'=>$data['size'], |
||||
|
'fileSuffixes'=>$pathInfo['extension'], |
||||
|
'file_id'=>$data['id'], |
||||
|
]; |
||||
|
|
||||
|
die(json_encode($response));*/ |
||||
|
} |
||||
|
|
||||
|
// Return Success JSON-RPC response |
||||
|
die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,43 @@ |
|||||
|
<?php |
||||
|
declare (strict_types=1); |
||||
|
|
||||
|
namespace app\middleware; |
||||
|
|
||||
|
use think\App; |
||||
|
|
||||
|
class AllowCrossDomain |
||||
|
{ |
||||
|
|
||||
|
protected $app; |
||||
|
|
||||
|
public function __construct(App $app) |
||||
|
{ |
||||
|
$this->app = $app; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 处理请求 |
||||
|
* |
||||
|
* @param \think\Request $request |
||||
|
* @param \Closure $next |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle($request, \Closure $next) |
||||
|
{ |
||||
|
|
||||
|
/** @var Response $response */ |
||||
|
$response = $next($request); |
||||
|
|
||||
|
// 支持跨域请求的host数组['a.cn', 'b.cn'] |
||||
|
$corsHost = ['api.ahbmz.com', 'cms.ahbmz.com','www.yaoli.com']; |
||||
|
|
||||
|
if (!empty($corsHost) && is_array($corsHost) && in_array($request->host(), $corsHost)) { |
||||
|
$response->header([ |
||||
|
'Access-Control-Allow-Origin' => '*', |
||||
|
'Access-Control-Allow-Methods' => 'GET, POST, PATCH, PUT, DELETE', |
||||
|
'Access-Control-Allow-Headers' => 'Authorization, Content-Type, If-Match,token, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With', |
||||
|
]); |
||||
|
} |
||||
|
return $response; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,81 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | Api中间件 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | QQ: 407593529 |
||||
|
* '::::::::::::' | DATETIME: 2019/07/18 |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\api\middleware; |
||||
|
|
||||
|
use app\api\service\JwtAuth; |
||||
|
|
||||
|
use think\facade\Request; |
||||
|
use think\Response; |
||||
|
use think\exception\HttpResponseException; |
||||
|
|
||||
|
class Api |
||||
|
{ |
||||
|
public function handle($request, \Closure $next) |
||||
|
{ |
||||
|
$token = Request::header('token'); |
||||
|
if ($token) { |
||||
|
if (count(explode('.', $token)) <> 3) { |
||||
|
$this->result([], 0, 'token格式错误'); |
||||
|
} |
||||
|
$jwtAuth = JwtAuth::getInstance(); |
||||
|
$jwtAuth->setToken($token); |
||||
|
if ($jwtAuth->validate() && $jwtAuth->verify()) { |
||||
|
return $next($request); |
||||
|
} else { |
||||
|
$this->result([], 0, 'token已过期'); |
||||
|
} |
||||
|
} else { |
||||
|
$this->result([], 0, 'token不能为空'); |
||||
|
} |
||||
|
|
||||
|
return $next($request); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 返回封装后的API数据到客户端 |
||||
|
* @param mixed $data 要返回的数据 |
||||
|
* @param integer $code 返回的code |
||||
|
* @param mixed $msg 提示信息 |
||||
|
* @param string $type 返回数据格式 |
||||
|
* @param array $header 发送的Header信息 |
||||
|
* @return Response |
||||
|
*/ |
||||
|
protected function result($data, int $code = 0, $msg = '', string $type = '', array $header = []): Response |
||||
|
{ |
||||
|
$result = [ |
||||
|
'code' => $code, |
||||
|
'msg' => $msg, |
||||
|
'time' => time(), |
||||
|
'data' => $data, |
||||
|
]; |
||||
|
|
||||
|
$type = $type ?: 'json'; |
||||
|
$response = Response::create($result, $type)->header($header); |
||||
|
|
||||
|
throw new HttpResponseException($response); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,130 @@ |
|||||
|
<?php |
||||
|
namespace app\api\service; |
||||
|
|
||||
|
use Lcobucci\JWT\Builder; |
||||
|
use Lcobucci\JWT\Parser; |
||||
|
use Lcobucci\JWT\Signer\Hmac\Sha256; |
||||
|
use Lcobucci\JWT\ValidationData; |
||||
|
|
||||
|
/** |
||||
|
* 单例 一次请求中所有出现jwt的地方都是一个用户 |
||||
|
* Class JwtAuth |
||||
|
* @package app\api\service |
||||
|
*/ |
||||
|
class JwtAuth |
||||
|
{ |
||||
|
// jwt token |
||||
|
private $token; |
||||
|
|
||||
|
// jwt 过期时间 |
||||
|
private $expTime = 3600; |
||||
|
|
||||
|
// claim iss |
||||
|
private $iss = 'api.zhangyun.com'; |
||||
|
|
||||
|
// claim aud |
||||
|
private $aud = 'zhangyun_app'; |
||||
|
|
||||
|
// claim uid |
||||
|
private $uid; |
||||
|
|
||||
|
// secrect |
||||
|
private $secrect = '1faASDF3'; |
||||
|
|
||||
|
// decode token |
||||
|
private $decodeToken; |
||||
|
|
||||
|
// 单例模式JwtAuth句柄 |
||||
|
private static $instance; |
||||
|
|
||||
|
// 获取JwtAuth的句柄 |
||||
|
public static function getInstance() |
||||
|
{ |
||||
|
if (is_null(self::$instance)) { |
||||
|
self::$instance = new self(); |
||||
|
} |
||||
|
return self::$instance; |
||||
|
} |
||||
|
|
||||
|
// 私有化构造函数 |
||||
|
private function __construct() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
// 私有化clone函数 |
||||
|
private function __clone() |
||||
|
{ |
||||
|
// TODO: Implement __clone() method. |
||||
|
} |
||||
|
|
||||
|
// 获取token |
||||
|
public function getToken() |
||||
|
{ |
||||
|
return (string)$this->token; |
||||
|
} |
||||
|
|
||||
|
// 设置token |
||||
|
public function setToken($token) |
||||
|
{ |
||||
|
$this->token = $token; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
// 设置uid |
||||
|
public function setUid($uid) |
||||
|
{ |
||||
|
$this->uid = $uid; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
// 获取uid |
||||
|
public function getUid() |
||||
|
{ |
||||
|
return $this->uid; |
||||
|
} |
||||
|
|
||||
|
// 编码jwt token |
||||
|
public function encode() |
||||
|
{ |
||||
|
$time = time(); |
||||
|
$this->token = (new Builder())->setHeader('alg', 'HS256') |
||||
|
->setIssuer($this->iss) |
||||
|
->setAudience($this->aud) |
||||
|
->setIssuedAt($time) |
||||
|
->setExpiration($time + $this->expTime) |
||||
|
->set('uid', $this->uid) |
||||
|
->sign(new Sha256(), $this->secrect) |
||||
|
->getToken(); |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
public function decode() |
||||
|
{ |
||||
|
if (!$this->decodeToken) { |
||||
|
$this->decodeToken = (new Parser())->parse((string)$this->token); // Parses from a string |
||||
|
$this->uid = $this->decodeToken->getClaim('uid'); |
||||
|
} |
||||
|
return $this->decodeToken; |
||||
|
} |
||||
|
|
||||
|
// validate |
||||
|
public function validate() |
||||
|
{ |
||||
|
$data = new ValidationData(); // It will use the current time to validate (iat, nbf and exp) |
||||
|
$data->setIssuer($this->iss); |
||||
|
$data->setAudience($this->aud); |
||||
|
$data->setId($this->uid); |
||||
|
|
||||
|
return $this->decode()->validate($data); |
||||
|
} |
||||
|
|
||||
|
// verify token |
||||
|
public function verify() |
||||
|
{ |
||||
|
$signer = new Sha256(); |
||||
|
return $this->decode()->verify($signer, $this->secrect); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,717 @@ |
|||||
|
<?php |
||||
|
// 应用公共文件 |
||||
|
|
||||
|
|
||||
|
//curl统一请求方法 |
||||
|
function curl($url, $data = array(), $http = array(), $method = "POST") |
||||
|
{ |
||||
|
$api_start_time = microtime(true); |
||||
|
$opts = array( |
||||
|
CURLOPT_TIMEOUT => 300, |
||||
|
CURLOPT_RETURNTRANSFER => 1, |
||||
|
CURLOPT_SSL_VERIFYPEER => FALSE, |
||||
|
CURLOPT_SSL_VERIFYHOST => FALSE, |
||||
|
CURLOPT_HTTPHEADER => $http, |
||||
|
CURLOPT_URL => $url, |
||||
|
CURLOPT_CUSTOMREQUEST => $method, |
||||
|
CURLOPT_POSTFIELDS => http_build_query($data) |
||||
|
); |
||||
|
|
||||
|
$curl = curl_init(); |
||||
|
curl_setopt_array($curl, $opts); |
||||
|
$return = curl_exec($curl); |
||||
|
return json_decode($return, TRUE); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// 获取列表链接地址 |
||||
|
function getUrl($v) |
||||
|
{ |
||||
|
// 判断是否外部链接 |
||||
|
if (trim($v['url']) == '') { |
||||
|
// 判断是否跳转到下级栏目 |
||||
|
if ($v['is_next'] == 1) { |
||||
|
$is_next = \app\common\model\Cate::where('parent_id', $v['id']) |
||||
|
->order('sort asc,id desc') |
||||
|
->find(); |
||||
|
if ($is_next) { |
||||
|
$v['url'] = getUrl($is_next); |
||||
|
} |
||||
|
} else { |
||||
|
if ($v['cate_folder']) { |
||||
|
$v['url'] = (string)url($v['cate_folder'] . '/index'); |
||||
|
} else { |
||||
|
$moduleName = \app\common\model\Module::where('id', $v['module_id']) |
||||
|
->value('model_name'); |
||||
|
$v['url'] = (string)url($moduleName . '/index', ['cate' => $v['id']]); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return $v['url']; |
||||
|
} |
||||
|
|
||||
|
// 获取详情URL |
||||
|
function getShowUrl($v) |
||||
|
{ |
||||
|
if ($v) { |
||||
|
if (isset($v['url']) && !empty($v['url'])) { |
||||
|
return $v['url']; |
||||
|
} |
||||
|
$cate = \app\common\model\Cate::field('id,cate_folder,module_id') |
||||
|
->where('id', $v['cate_id']) |
||||
|
->find(); |
||||
|
if ($cate['cate_folder']) { |
||||
|
$url = url($cate['cate_folder'] . '/info', ['id' => $v['id']]); |
||||
|
} else { |
||||
|
$moduleName = \app\common\model\Module::where('id', $cate['module_id']) |
||||
|
->value('model_name'); |
||||
|
$url = url($moduleName . '/info', ['cate' => $cate['id'], 'id' => $v['id']]); |
||||
|
} |
||||
|
} |
||||
|
return $url; |
||||
|
} |
||||
|
|
||||
|
/*** |
||||
|
* 处理数据(把列表中需要处理的字段转换成数组和对应的值,用于自定义标签文件中) |
||||
|
* @param $list 列表 |
||||
|
* @param $moduleid 模型ID |
||||
|
* @return array |
||||
|
*/ |
||||
|
function changeFields($list, $moduleid) |
||||
|
{ |
||||
|
$info = []; |
||||
|
foreach ($list as $k => $v) { |
||||
|
$url = getShowUrl($v); |
||||
|
$list[$k] = changeField($v, $moduleid); |
||||
|
$info[$k] = $list[$k];//定义中间变量防止报错 |
||||
|
$info[$k]['url'] = $url; |
||||
|
} |
||||
|
return $info; |
||||
|
} |
||||
|
|
||||
|
/*** |
||||
|
* 处理数据(用于详情页中数据转换) |
||||
|
* @param $info 内容详情 |
||||
|
* @param $moduleid 模型ID |
||||
|
* @return array |
||||
|
*/ |
||||
|
function changefield($info, $moduleId) |
||||
|
{ |
||||
|
$fields = \app\common\model\Field::where('module_id', '=', $moduleId) |
||||
|
->select(); |
||||
|
foreach ($fields as $k => $v) { |
||||
|
$field = $v['field']; |
||||
|
if ($info[$field]) { |
||||
|
switch ($v['type']) { |
||||
|
case 'textarea'://多行文本 |
||||
|
break; |
||||
|
case 'editor'://编辑器 |
||||
|
$info[$field] = $info[$field]; |
||||
|
break; |
||||
|
case 'select'://下拉列表 |
||||
|
break; |
||||
|
case 'radio'://单选按钮 |
||||
|
break; |
||||
|
case 'checkbox'://复选框 |
||||
|
$info[$field] = explode(',', $info[$field]); |
||||
|
break; |
||||
|
case 'images'://多张图片 |
||||
|
$info[$field] = json_decode($info[$field], true); |
||||
|
break; |
||||
|
case 'tag'://TAG标签 |
||||
|
if (!empty($info[$field])) { |
||||
|
$tags = explode(',', $info[$field]); |
||||
|
foreach ($tags as $k => $tag) { |
||||
|
$tags[$k] = [ |
||||
|
'name' => $tag, |
||||
|
'url' => \think\facade\Route::buildUrl('index/tag', ['module' => $moduleId, 't' => $tag])->__toString(), |
||||
|
]; |
||||
|
} |
||||
|
$info[$field] = $tags; |
||||
|
} |
||||
|
default: |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
return $info; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 邮件发送 |
||||
|
* @param $to 接收人 |
||||
|
* @param string $subject 邮件标题 |
||||
|
* @param string $content 邮件内容(html模板渲染后的内容) |
||||
|
* @throws Exception |
||||
|
* @throws phpmailerException |
||||
|
*/ |
||||
|
function send_email($to, $subject = '', $content = '') |
||||
|
{ |
||||
|
$mail = new PHPMailer\PHPMailer\PHPMailer(); |
||||
|
$arr = \think\facade\Db::name('config') |
||||
|
->where('inc_type', 'smtp') |
||||
|
->select(); |
||||
|
$config = convert_arr_kv($arr, 'name', 'value'); |
||||
|
|
||||
|
$mail->CharSet = 'UTF-8'; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码 |
||||
|
$mail->isSMTP(); |
||||
|
$mail->SMTPDebug = 0; |
||||
|
//调试输出格式 |
||||
|
//$mail->Debugoutput = 'html'; |
||||
|
//smtp服务器 |
||||
|
$mail->Host = $config['smtp_server']; |
||||
|
//端口 - likely to be 25, 465 or 587 |
||||
|
$mail->Port = $config['smtp_port']; |
||||
|
|
||||
|
if ($mail->Port == '465') { |
||||
|
$mail->SMTPSecure = 'ssl'; |
||||
|
}// 使用安全协议 |
||||
|
//Whether to use SMTP authentication |
||||
|
$mail->SMTPAuth = true; |
||||
|
//发送邮箱 |
||||
|
$mail->Username = $config['smtp_user']; |
||||
|
//密码 |
||||
|
$mail->Password = $config['smtp_pwd']; |
||||
|
//Set who the message is to be sent from |
||||
|
$mail->setFrom($config['smtp_user'], $config['email_id']); |
||||
|
//回复地址 |
||||
|
//$mail->addReplyTo('replyto@example.com', 'First Last'); |
||||
|
//接收邮件方 |
||||
|
if (is_array($to)) { |
||||
|
foreach ($to as $v) { |
||||
|
$mail->addAddress($v); |
||||
|
} |
||||
|
} else { |
||||
|
$mail->addAddress($to); |
||||
|
} |
||||
|
|
||||
|
$mail->isHTML(true);// send as HTML |
||||
|
//标题 |
||||
|
$mail->Subject = $subject; |
||||
|
//HTML内容转换 |
||||
|
$mail->msgHTML($content); |
||||
|
return $mail->send(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 验证输入的邮件地址是否合法 |
||||
|
* @param $user_email 邮箱 |
||||
|
* @return bool |
||||
|
*/ |
||||
|
function is_email($user_email) |
||||
|
{ |
||||
|
$chars = "/^([a-z0-9+_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,6}\$/i"; |
||||
|
if (strpos($user_email, '@') !== false && strpos($user_email, '.') !== false) { |
||||
|
if (preg_match($chars, $user_email)) { |
||||
|
return true; |
||||
|
} else { |
||||
|
return false; |
||||
|
} |
||||
|
} else { |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 验证输入的手机号码是否合法 |
||||
|
* @param $mobile_phone 手机号 |
||||
|
* @return bool |
||||
|
*/ |
||||
|
function is_mobile_phone($mobile_phone) |
||||
|
{ |
||||
|
$chars = "/^13[0-9]{1}[0-9]{8}$|15[0-9]{1}[0-9]{8}$|18[0-9]{1}[0-9]{8}$|17[0-9]{1}[0-9]{8}$/"; |
||||
|
if (preg_match($chars, $mobile_phone)) { |
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 过滤数组元素前后空格 (支持多维数组) |
||||
|
* @param $array 要过滤的数组 |
||||
|
* @return array|string |
||||
|
*/ |
||||
|
function trim_array_element($array) |
||||
|
{ |
||||
|
if (!is_array($array)) |
||||
|
return trim($array); |
||||
|
return array_map('trim_array_element', $array); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 将数据库中查出的列表以指定的 值作为数组的键名,并以另一个值作为键值 |
||||
|
* @param $arr |
||||
|
* @param $key_name |
||||
|
* @return array |
||||
|
*/ |
||||
|
function convert_arr_kv($arr, $key_name, $value) |
||||
|
{ |
||||
|
$arr2 = array(); |
||||
|
foreach ($arr as $key => $val) { |
||||
|
$arr2[$val[$key_name]] = $val[$value]; |
||||
|
} |
||||
|
return $arr2; |
||||
|
} |
||||
|
|
||||
|
function string2array($info) |
||||
|
{ |
||||
|
if ($info == '') return array(); |
||||
|
eval("\$r = $info;"); |
||||
|
return $r; |
||||
|
} |
||||
|
|
||||
|
function array2string($info) |
||||
|
{ |
||||
|
//删除空格,某些情况下字段的设置会出现换行和空格的情况 |
||||
|
if (is_array($info)) { |
||||
|
if (array_key_exists('options', $info)) { |
||||
|
$info['options'] = trim($info['options']); |
||||
|
} |
||||
|
} |
||||
|
if ($info == '') return ''; |
||||
|
if (!is_array($info)) { |
||||
|
//删除反斜杠 |
||||
|
$string = stripslashes($info); |
||||
|
} |
||||
|
foreach ($info as $key => $val) { |
||||
|
$string[$key] = stripslashes($val); |
||||
|
} |
||||
|
$setup = var_export($string, TRUE); |
||||
|
return $setup; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 文本域中换行标签输出 |
||||
|
* @param $info 内容 |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
function textareaBr($info) |
||||
|
{ |
||||
|
$info = str_replace("\r\n", "<br />", $info); |
||||
|
$info = str_replace("\n", "<br />", $info); |
||||
|
$info = str_replace("\r", "<br />", $info); |
||||
|
return $info; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 无限分类-栏目 |
||||
|
* @param $cate |
||||
|
* @param string $lefthtml |
||||
|
* @param int $pid |
||||
|
* @param int $lvl |
||||
|
* @return array |
||||
|
*/ |
||||
|
function tree_cate($cate, $leftHtml = '|— ', $pid = 0, $lvl = 0) |
||||
|
{ |
||||
|
$arr = array(); |
||||
|
foreach ($cate as $v) { |
||||
|
if ($v['parent_id'] == $pid) { |
||||
|
$v['lvl'] = $lvl + 1; |
||||
|
$v['left_html'] = str_repeat($leftHtml, $lvl); |
||||
|
$v['l_cate_name'] = $v['left_html'] . $v['cate_name']; |
||||
|
$arr[] = $v; |
||||
|
$arr = array_merge($arr, tree_cate($cate, $leftHtml, $v['id'], $lvl + 1)); |
||||
|
} |
||||
|
} |
||||
|
return $arr; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 组合多维数组 |
||||
|
* @param $cate |
||||
|
* @param string $name |
||||
|
* @param int $pid |
||||
|
* @return array |
||||
|
*/ |
||||
|
function unlimitedForLayer($cate, $name = 'sub', $pid = 0) |
||||
|
{ |
||||
|
$arr = array(); |
||||
|
foreach ($cate as $v) { |
||||
|
if ($v['parent_id'] == $pid) { |
||||
|
$v[$name] = unlimitedForLayer($cate, $name, $v['id']); |
||||
|
$v['url'] = getUrl($v); |
||||
|
$arr[] = $v; |
||||
|
} |
||||
|
} |
||||
|
return $arr; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 传递一个父级分类ID返回当前子分类 |
||||
|
* @param $cate |
||||
|
* @param $pid |
||||
|
* @return array |
||||
|
*/ |
||||
|
function getChildsOn($cate, $pid) |
||||
|
{ |
||||
|
$arr = array(); |
||||
|
foreach ($cate as $v) { |
||||
|
if ($v['parent_id'] == $pid) { |
||||
|
$v['sub'] = getChilds($cate, $v['id']); |
||||
|
$v['url'] = getUrl($v); |
||||
|
$arr[] = $v; |
||||
|
} |
||||
|
} |
||||
|
return $arr; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 传递一个父级分类ID返回所有子分类 |
||||
|
* @param $cate |
||||
|
* @param $pid |
||||
|
* @return array |
||||
|
*/ |
||||
|
function getChilds($cate, $pid) |
||||
|
{ |
||||
|
$arr = array(); |
||||
|
foreach ($cate as $v) { |
||||
|
if ($v['parentid'] == $pid) { |
||||
|
$v['url'] = getUrl($v); |
||||
|
$arr[] = $v; |
||||
|
$arr = array_merge($arr, getChilds($cate, $v['id'])); |
||||
|
} |
||||
|
} |
||||
|
return $arr; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 传递一个父级分类ID返回所有子分类ID |
||||
|
* @param $cate |
||||
|
* @param $pid |
||||
|
* @return array |
||||
|
*/ |
||||
|
function getChildsId($cate, $pid) |
||||
|
{ |
||||
|
$arr = []; |
||||
|
foreach ($cate as $v) { |
||||
|
if ($v['parent_id'] == $pid) { |
||||
|
$arr[] = $v; |
||||
|
$arr = array_merge($arr, getChildsId($cate, $v['id'])); |
||||
|
} |
||||
|
} |
||||
|
return $arr; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 格式化分类数组为字符串 |
||||
|
* @param $ids |
||||
|
* @param string $pid |
||||
|
* @return string |
||||
|
*/ |
||||
|
function getChildsIdStr($ids, $pid = '') |
||||
|
{ |
||||
|
$result = ''; |
||||
|
foreach ($ids as $k => $v) { |
||||
|
$result .= $v['id'] . ','; |
||||
|
} |
||||
|
if ($pid) { |
||||
|
$result = $pid . ',' . $result; |
||||
|
} |
||||
|
$result = rtrim($result, ','); |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 传递一个子分类ID返回所有的父级分类[前台栏目] |
||||
|
* @param $cate |
||||
|
* @param $id |
||||
|
* @return array |
||||
|
*/ |
||||
|
function getParents($cate, $id) |
||||
|
{ |
||||
|
$arr = array(); |
||||
|
foreach ($cate as $v) { |
||||
|
if ($v['id'] == $id) { |
||||
|
$arr[] = $v; |
||||
|
$arr = array_merge(getParents($cate, $v['parent_id']), $arr); |
||||
|
} |
||||
|
} |
||||
|
return $arr; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取文件目录列表 |
||||
|
* @param string $pathname 路径 |
||||
|
* @param integer $fileFlag 文件列表 0所有文件列表,1只读文件夹,2是只读文件(不包含文件夹) |
||||
|
* @param string $pathname 路径 |
||||
|
* @return array |
||||
|
*/ |
||||
|
function get_file_folder_List($pathname, $fileFlag = 0, $pattern = '*') |
||||
|
{ |
||||
|
$fileArray = array(); |
||||
|
$pathname = rtrim($pathname, '/') . '/'; |
||||
|
$list = glob($pathname . $pattern); |
||||
|
foreach ($list as $i => $file) { |
||||
|
switch ($fileFlag) { |
||||
|
case 0: |
||||
|
$fileArray[] = basename($file); |
||||
|
break; |
||||
|
case 1: |
||||
|
if (is_dir($file)) { |
||||
|
$fileArray[] = basename($file); |
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
case 2: |
||||
|
if (is_file($file)) { |
||||
|
$fileArray[] = basename($file); |
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
default: |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (empty($fileArray)) $fileArray = NULL; |
||||
|
return $fileArray; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取所有模版 |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
function getTemplate() |
||||
|
{ |
||||
|
// 查找所有系统设置表数据 |
||||
|
$system = \app\common\model\System::find(1); |
||||
|
|
||||
|
$path = './template/' . $system['template'] . '/index/' . $system['html'] . '/'; |
||||
|
$tpl['list'] = get_file_folder_List($path, 2, '*_list*'); |
||||
|
$tpl['show'] = get_file_folder_List($path, 2, '*_show*'); |
||||
|
return $tpl; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 传递一个父级分类ID返回所有子分类 |
||||
|
* @param $cate |
||||
|
* @param $pid |
||||
|
* @return array |
||||
|
*/ |
||||
|
function getChildsRule($rules, $pid) |
||||
|
{ |
||||
|
$arr = []; |
||||
|
foreach ($rules as $v) { |
||||
|
if ($v['pid'] == $pid) { |
||||
|
$arr[] = $v; |
||||
|
$arr = array_merge($arr, getChildsRule($rules, $v['id'])); |
||||
|
} |
||||
|
} |
||||
|
return $arr; |
||||
|
} |
||||
|
|
||||
|
/*** |
||||
|
* 对象转数组 |
||||
|
* @param $object |
||||
|
* @return array |
||||
|
*/ |
||||
|
function object2array($object) |
||||
|
{ |
||||
|
$array = array(); |
||||
|
if (is_object($object)) { |
||||
|
foreach ($object as $key => $value) { |
||||
|
$array[$key] = $value; |
||||
|
} |
||||
|
} else { |
||||
|
$array = $object; |
||||
|
} |
||||
|
return $array; |
||||
|
} |
||||
|
|
||||
|
/*** |
||||
|
* 获取当前栏目ID |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
function getCateId() |
||||
|
{ |
||||
|
if (\think\facade\Request::has('cate')) { |
||||
|
$result = (int)\think\facade\Request::param('cate'); |
||||
|
} else { |
||||
|
$result = \app\common\model\Cate::where('cate_folder', '=', \think\facade\Request::controller()) |
||||
|
->value('id'); |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 改变前台字典数据标签取得的数据 |
||||
|
* @param array $list |
||||
|
* @return array |
||||
|
*/ |
||||
|
function changeDict(array $list, string $field, string $all="全部") |
||||
|
{ |
||||
|
$get = \think\facade\Request::except(['page'], 'get'); |
||||
|
foreach ($list as $k => $v) { |
||||
|
$url = $get; |
||||
|
$url[$field] = $v['dict_value']; |
||||
|
$list[$k]['url'] = (string)url(\think\facade\Request::controller() . '/' . \think\facade\Request::action(), $url); |
||||
|
$param = \think\facade\Request::param('', '', 'htmlspecialchars'); |
||||
|
// 高亮显示 |
||||
|
$list[$k]['current'] = 0; |
||||
|
if (!empty($param)) { |
||||
|
foreach ($param as $kk => $vv) { |
||||
|
if ($kk == $field) { |
||||
|
if (strpos($vv, '|') !== false) { |
||||
|
// 多选 |
||||
|
$paramArr = explode("|", $vv); |
||||
|
foreach ($paramArr as $kkk => $vvv) { |
||||
|
if ($vvv == $v['dict_value']) { |
||||
|
$list[$k]['current'] = 1; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} else { |
||||
|
// 单选 |
||||
|
if ($vv == $v['dict_value']) { |
||||
|
$list[$k]['current'] = 1; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$list[$k]['param'] = $param; |
||||
|
} |
||||
|
|
||||
|
// 添加[全部]字段在第一位 |
||||
|
if (isset($get[$field])) { |
||||
|
unset($get[$field]); |
||||
|
} else { |
||||
|
$hover = 1; |
||||
|
} |
||||
|
$url = (string)url(\think\facade\Request::controller() . '/' . \think\facade\Request::action(), $get); |
||||
|
|
||||
|
$all = [ |
||||
|
'dict_label' => $all, |
||||
|
'dict_value' => 0, |
||||
|
'url' => $url, |
||||
|
'current' => $hover ?? 0, |
||||
|
]; |
||||
|
array_unshift($list, $all); |
||||
|
|
||||
|
return $list; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 改变模版标签中分类字段传递 |
||||
|
* @param string $field 需要分类查询的字段,通过,分割或|分割 |
||||
|
* @return string |
||||
|
*/ |
||||
|
function getSearchField(string $field) |
||||
|
{ |
||||
|
$sql = ''; |
||||
|
if ($field) { |
||||
|
$field = str_replace('|', ',', $field); |
||||
|
$fieldArr = explode(',', $field); |
||||
|
foreach ($fieldArr as $k => $v) { |
||||
|
if (!empty($v)) { |
||||
|
// 查询浏览器参数是否包含此参数 |
||||
|
if (\think\facade\Request::has($v, 'get')) { |
||||
|
$str = \think\facade\Request::get($v, '', 'htmlspecialchars'); |
||||
|
if (strpos($str, '|') !== false) { |
||||
|
$sql = ' AND ('; |
||||
|
$strArr = explode("|", $str); |
||||
|
foreach ($strArr as &$strAr) { |
||||
|
// 检测是否存在 |
||||
|
$dictCount = \app\common\model\Dictionary::where('dict_value', $strAr)->count(); |
||||
|
if ($dictCount) { |
||||
|
$sql .= ' FIND_IN_SET(\'' . $strAr . '\', ' . $v . ') OR'; |
||||
|
} |
||||
|
} |
||||
|
// 去除最后一个or |
||||
|
$sql = substr($sql, 0, strlen($sql) - 2); |
||||
|
$sql .= ') '; |
||||
|
} else { |
||||
|
// 检测是否存在 |
||||
|
$dictCount = \app\common\model\Dictionary::where('dict_value', $str)->count(); |
||||
|
if ($dictCount) { |
||||
|
$sql .= ' AND FIND_IN_SET(\'' . $str . '\', ' . $v . ') '; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return $sql; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 无限分类-权限 |
||||
|
* @param $cate 栏目 |
||||
|
* @param string $lefthtml 分隔符 |
||||
|
* @param int $pid 父ID |
||||
|
* @param int $lvl 层级 |
||||
|
* @return array |
||||
|
*/ |
||||
|
function tree($cate , $lefthtml = '|— ' , $pid = 0 , $lvl = 0 ){ |
||||
|
$arr = array(); |
||||
|
foreach ($cate as $v){ |
||||
|
if ($v['pid'] == $pid) { |
||||
|
$v['lvl'] = $lvl + 1; |
||||
|
$v['lefthtml'] = str_repeat($lefthtml,$lvl); |
||||
|
$v['ltitle'] = $v['lefthtml'].$v['title']; |
||||
|
$arr[] = $v; |
||||
|
$arr = array_merge($arr, tree($cate, $lefthtml, $v['id'], $lvl+1)); |
||||
|
} |
||||
|
} |
||||
|
return $arr; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 无限分类-权限 |
||||
|
* @param $cate 栏目 |
||||
|
* @param string $lefthtml 分隔符 |
||||
|
* @param int $pid 父ID |
||||
|
* @param int $lvl 层级 |
||||
|
* @return array |
||||
|
*/ |
||||
|
function tree_three($cate , $lefthtml = '|— ' , $pid = 0 , $lvl = 0 ){ |
||||
|
$arr = array(); |
||||
|
foreach ($cate as $v){ |
||||
|
$keys = array_keys($v); |
||||
|
if (end($v) == $pid) { |
||||
|
$v['lvl'] = $lvl + 1; |
||||
|
$v['lefthtml'] = str_repeat($lefthtml,$lvl); |
||||
|
$v[$keys[1]] = $v['lefthtml'] . $v[$keys[1]]; |
||||
|
$arr[] = $v; |
||||
|
$arr = array_merge($arr, tree_three($cate, $lefthtml, $v[$keys[0]], $lvl+1)); |
||||
|
} |
||||
|
} |
||||
|
return $arr; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 字符串截取,支持中文和其他编码 |
||||
|
* |
||||
|
* @param string $str 需要转换的字符串 |
||||
|
* @param string $start 开始位置 |
||||
|
* @param string $length 截取长度 |
||||
|
* @param string $charset 编码格式 |
||||
|
* @param string $suffix 截断字符串后缀 |
||||
|
* @return string |
||||
|
*/ |
||||
|
function cut_str($str, $start = 0, $length, $suffix = "", $charset = "utf-8") |
||||
|
{ |
||||
|
if (function_exists("mb_substr")) { |
||||
|
if (mb_strlen($str, 'UTF-8') <= $length) { |
||||
|
$suffix = ''; |
||||
|
} |
||||
|
return mb_substr($str, $start, $length, $charset) . $suffix; |
||||
|
} elseif (function_exists('iconv_substr')) { |
||||
|
if (mb_strlen($str, 'UTF-8') <= $length) { |
||||
|
$suffix = ''; |
||||
|
} |
||||
|
return iconv_substr($str, $start, $length, $charset) . $suffix; |
||||
|
} |
||||
|
$re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/"; |
||||
|
$re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/"; |
||||
|
$re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/"; |
||||
|
$re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/"; |
||||
|
preg_match_all($re[$charset], $str, $match); |
||||
|
$slice = join("", array_slice($match[0], $start, $length)); |
||||
|
if (mb_strlen($str, 'UTF-8') <= $length) { |
||||
|
$suffix = ''; |
||||
|
} |
||||
|
return $slice . $suffix; |
||||
|
} |
||||
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,602 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 表格快速构造器 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | QQ: 407593529 |
||||
|
* '::::::::::::' | DATETIME: 2019/08/05 |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\builder; |
||||
|
|
||||
|
use think\facade\Request; |
||||
|
use think\facade\View; |
||||
|
|
||||
|
class TableBuilder |
||||
|
{ |
||||
|
/** |
||||
|
* @var array 列名 |
||||
|
*/ |
||||
|
private $_field_name = []; |
||||
|
|
||||
|
/** |
||||
|
* @var string 模板路径(默认使用系统内置路径,无需设置) |
||||
|
*/ |
||||
|
private $_template = ''; |
||||
|
|
||||
|
/** |
||||
|
* @var array 模板变量 |
||||
|
*/ |
||||
|
private $_vars = [ |
||||
|
'page_title' => '', // 页面标题 |
||||
|
'page_tips' => '', // 页面提示 |
||||
|
'page_tips_top' => '', // 页面提示[top] |
||||
|
'page_tips_search' => '', // 页面提示[search] |
||||
|
'page_tips_bottom' => '', // 页面提示[bottom] |
||||
|
'tips_type' => '', // 页面提示类型 |
||||
|
'extra_js' => '', // 额外JS代码 |
||||
|
'extra_css' => '', // 额外CSS代码 |
||||
|
'extra_html' => '', // 额外HTML代码 |
||||
|
'columns' => [], // 表格列集合 |
||||
|
'right_buttons' => [], // 表格右侧按钮 |
||||
|
'top_buttons' => [], // 顶部栏按钮组[toolbar] |
||||
|
'unique_id' => 'id', // 表格主键名称,(默认为id,如表主键不为id必须设置主键) |
||||
|
'data_url' => '', // 表格数据源 |
||||
|
'add_url' => '', // 默认的新增地址 |
||||
|
'edit_url' => '', // 默认的修改地址 |
||||
|
'del_url' => '', // 默认的删除地址 |
||||
|
'export_url' => '', // 默认的导出地址 |
||||
|
'sort_url' => '', // 默认的排序地址 |
||||
|
'search' => [], // 搜索参数 |
||||
|
'pagination' => 'true', // 是否进行分页 |
||||
|
'empty_tips' => '暂无数据', // 空数据提示信息[待完善] |
||||
|
'hide_checkbox' => false, // 是否隐藏第一列多选[待完善] |
||||
|
|
||||
|
]; |
||||
|
|
||||
|
/** |
||||
|
* @var 单例模式句柄 |
||||
|
*/ |
||||
|
private static $instance; |
||||
|
|
||||
|
/** |
||||
|
* 获取句柄 |
||||
|
* @return FormBuilder |
||||
|
*/ |
||||
|
public static function getInstance() |
||||
|
{ |
||||
|
if (is_null(self::$instance)) { |
||||
|
self::$instance = new self(); |
||||
|
} |
||||
|
return self::$instance; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 私有化构造函数 |
||||
|
*/ |
||||
|
private function __construct() |
||||
|
{ |
||||
|
// 初始化 |
||||
|
$this->initialize(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 初始化 |
||||
|
*/ |
||||
|
protected function initialize() |
||||
|
{ |
||||
|
// 设置默认模版 |
||||
|
$this->_template = 'table_builder/layout'; |
||||
|
|
||||
|
// 设置默认URL |
||||
|
$this->_vars['data_url'] = Request::baseUrl() . '?getList=1'; |
||||
|
$this->_vars['add_url'] = url('add'); |
||||
|
$this->_vars['edit_url'] = url('edit', ['id' => '__id__']); |
||||
|
$this->_vars['del_url'] = url('del'); |
||||
|
$this->_vars['export_url'] = url('export'); |
||||
|
$this->_vars['sort_url'] = url('sort'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 私有化clone函数 |
||||
|
*/ |
||||
|
private function __clone() |
||||
|
{ |
||||
|
// TODO: Implement __clone() method. |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 渲染模版 |
||||
|
* @param string $template 模板文件名或者内容 |
||||
|
* @param bool $renderContent 是否渲染内容 |
||||
|
* @return string |
||||
|
* @throws \Exception |
||||
|
*/ |
||||
|
public function fetch(string $template = '') |
||||
|
{ |
||||
|
// 单独设置模板 |
||||
|
if ($template != '') { |
||||
|
$this->_template = $template; |
||||
|
} |
||||
|
View::assign($this->_vars); |
||||
|
return View::fetch($this->_template); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置表格主键 |
||||
|
* @param string $key 主键名称 |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function setUniqueId($key = '') |
||||
|
{ |
||||
|
if ($key != '') { |
||||
|
$this->_vars['unique_id'] = $key; |
||||
|
} |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置页面标题 |
||||
|
* @param string $title 页面标题 |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function setPageTitle($title = '') |
||||
|
{ |
||||
|
if ($title != '') { |
||||
|
$this->_vars['page_title'] = trim($title); |
||||
|
} |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置表单页提示信息 |
||||
|
* @param string $tips 提示信息 |
||||
|
* @param string $type 提示类型:danger,info,warning,success |
||||
|
* @param string $pos 提示位置:top,search,bottom |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function setPageTips($tips = '', $type = 'info', $pos = 'top') |
||||
|
{ |
||||
|
if ($tips != '') { |
||||
|
$this->_vars['page_tips_' . $pos] = $tips; |
||||
|
$this->_vars['tips_type'] = trim($type) ?? 'info'; |
||||
|
} |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置额外JS代码 |
||||
|
* @param string $extra_js 额外JS代码 |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function setExtraJs($extra_js = '') |
||||
|
{ |
||||
|
if ($extra_js != '') { |
||||
|
$this->_vars['extra_js'] = $extra_js; |
||||
|
} |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置额外CSS代码 |
||||
|
* @param string $extra_css 额外CSS代码 |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function setExtraCss($extra_css = '') |
||||
|
{ |
||||
|
if ($extra_css != '') { |
||||
|
$this->_vars['extra_css'] = $extra_css; |
||||
|
} |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置额外HTML代码 |
||||
|
* @param string $extra_html 额外HTML代码 |
||||
|
* @param string $pos 位置 [top和bottom] |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function setExtraHtml($extra_html = '', $pos = '') |
||||
|
{ |
||||
|
if ($extra_html != '') { |
||||
|
$pos != '' && $pos = '_' . $pos; |
||||
|
$this->_vars['extra_html' . $pos] = $extra_html; |
||||
|
} |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加一列 |
||||
|
* @param string $name 字段名称 |
||||
|
* @param string $title 字段别名 |
||||
|
* @param string $type 单元格类型 |
||||
|
* @param string $default 默认值 |
||||
|
* @param string $param 额外参数 |
||||
|
* @param string $class css类名 |
||||
|
* @param string $sortable 是否排序 |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function addColumn($name = '', $title = '', $type = '', $default = '', $param = '', $class = '', $sortable = 'false') |
||||
|
{ |
||||
|
$column = [ |
||||
|
'name' => $name, |
||||
|
'title' => $title, |
||||
|
'type' => $type, |
||||
|
'default' => $default, |
||||
|
'param' => $param, |
||||
|
'class' => $class, |
||||
|
'sortable'=> $sortable, |
||||
|
]; |
||||
|
|
||||
|
$this->_vars['columns'][] = $column; |
||||
|
$this->_field_name[$name] = $title; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 一次性添加多列 |
||||
|
* @param array $columns 数据列 |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function addColumns($columns = []) |
||||
|
{ |
||||
|
if (!empty($columns)) { |
||||
|
foreach ($columns as $column) { |
||||
|
call_user_func_array([$this, 'addColumn'], $column); |
||||
|
} |
||||
|
} |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置是否显示分页 |
||||
|
* @param string $value 是否显示分页 true|false |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function setPagination($value = '') |
||||
|
{ |
||||
|
if ($value != '') { |
||||
|
$this->_vars['pagination'] = $value; |
||||
|
} |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 隐藏第一列多选框(默认显示,多选列多用于批量删除等操作) |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function hideCheckbox() |
||||
|
{ |
||||
|
$this->_vars['hide_checkbox'] = true; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加一个右侧按钮 |
||||
|
* @param string $type 按钮类型:edit/delete/default |
||||
|
* @param array $attribute 按钮属性 |
||||
|
* @param array $extra 扩展参数(待用) |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function addRightButton($type = '', $attribute = []) |
||||
|
{ |
||||
|
switch ($type) { |
||||
|
// 预览按钮 |
||||
|
case 'preview': |
||||
|
// 默认属性 |
||||
|
$btn_attribute = [ |
||||
|
'type' => 'preview', |
||||
|
'title' => '预览', |
||||
|
'icon' => 'fa fa-eye', |
||||
|
'class' => 'btn btn-success btn-xs', |
||||
|
'href' => url('index/preview', ['module' => Request::controller(), 'id' => '__id__']), |
||||
|
'target' => '_blank' |
||||
|
]; |
||||
|
break; |
||||
|
// 编辑按钮 |
||||
|
case 'edit': |
||||
|
// 默认属性 |
||||
|
$btn_attribute = [ |
||||
|
'type' => 'edit', |
||||
|
'title' => '编辑', |
||||
|
'icon' => 'fa fa-edit', |
||||
|
'class' => 'btn btn-primary btn-xs', |
||||
|
]; |
||||
|
break; |
||||
|
|
||||
|
// 删除按钮(不可恢复) |
||||
|
case 'delete': |
||||
|
// 默认属性 |
||||
|
$btn_attribute = [ |
||||
|
'type' => 'delete', |
||||
|
'title' => '删除', |
||||
|
'icon' => 'fa fa-trash-o', |
||||
|
'class' => 'btn btn-danger btn-xs confirm', |
||||
|
]; |
||||
|
break; |
||||
|
|
||||
|
// 自定义按钮 |
||||
|
default: |
||||
|
// 默认属性 |
||||
|
$btn_attribute = [ |
||||
|
'title' => '自定义按钮', |
||||
|
'icon' => 'fa fa-smile-o', |
||||
|
'class' => 'btn btn-flat btn-default btn-xs', |
||||
|
'href' => 'javascript:void(0);' |
||||
|
]; |
||||
|
break; |
||||
|
} |
||||
|
// 合并自定义属性 |
||||
|
if ($attribute && is_array($attribute)) { |
||||
|
$btn_attribute = array_merge($btn_attribute, $attribute); |
||||
|
} |
||||
|
|
||||
|
$this->_vars['right_buttons'][] = $btn_attribute; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加多个右侧按钮 |
||||
|
* @param array|string $buttons 按钮类型 |
||||
|
* 例如: |
||||
|
* $builder->addRightButtons('edit'); |
||||
|
* $builder->addRightButtons('edit,delete'); |
||||
|
* $builder->addRightButtons(['edit', 'delete']); |
||||
|
* $builder->addRightButtons(['edit' => ['title' => '查看'], 'delete']); |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function addRightButtons($buttons = []) |
||||
|
{ |
||||
|
if (!empty($buttons)) { |
||||
|
$buttons = is_array($buttons) ? $buttons : explode(',', $buttons); |
||||
|
foreach ($buttons as $key => $value) { |
||||
|
if (is_numeric($key)) { |
||||
|
$this->addRightButton($value); |
||||
|
} else { |
||||
|
$this->addRightButton(trim($key), $value); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置表格URL |
||||
|
* @param string $url url地址 |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function setDataUrl($url = '') |
||||
|
{ |
||||
|
if ($url != '') { |
||||
|
$this->_vars['data_url'] = $url; |
||||
|
} |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置表格默认的新增地址 |
||||
|
* @param string $url url地址 |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function setAddUrl($url = '') |
||||
|
{ |
||||
|
if ($url != '') { |
||||
|
$this->_vars['add_url'] = $url; |
||||
|
} |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置表格默认的修改地址 |
||||
|
* @param string $url url地址 |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function setEditUrl($url = '') |
||||
|
{ |
||||
|
if ($url != '') { |
||||
|
$this->_vars['edit_url'] = $url; |
||||
|
} |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置表格默认的删除地址 |
||||
|
* @param string $url url地址 |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function setDelUrl($url = '') |
||||
|
{ |
||||
|
if ($url != '') { |
||||
|
$this->_vars['del_url'] = $url; |
||||
|
} |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置表格默认的导出地址 |
||||
|
* @param string $url url地址 |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function setExportUrl($url = '') |
||||
|
{ |
||||
|
if ($url != '') { |
||||
|
$this->_vars['export_url'] = $url; |
||||
|
} |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置表格默认的更改排序地址 |
||||
|
* @param string $url url地址 |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function setSortUrl($url = '') |
||||
|
{ |
||||
|
if ($url != '') { |
||||
|
$this->_vars['sort_url'] = $url; |
||||
|
} |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置搜索参数 |
||||
|
* @param array $items |
||||
|
* @return $this |
||||
|
* 第一个参数:类型 |
||||
|
* 第二个参数:字段名称 |
||||
|
* 第三个参数:字段别名 |
||||
|
* 第四个参数:匹配方式(默认为“=”,也可以是“<>,>,>=,<,<=,LIKE”等等) |
||||
|
* 第五个参数:默认值 |
||||
|
* 第六个参数:额外参数(不同类型,用途不同) |
||||
|
*/ |
||||
|
public function setSearch($items = []) |
||||
|
{ |
||||
|
if (!empty($items)) { |
||||
|
foreach ($items as &$item) { |
||||
|
$item['type'] = $item[0]; // 字段类型 |
||||
|
$item['name'] = $item[1]; // 字段名称 |
||||
|
$item['title'] = $item[2]; // 字段别名 |
||||
|
$item['option'] = isset($item[3]) ? $item[3] : '='; // 匹配方式 |
||||
|
$item['default'] = isset($item[4]) ? $item[4] : ''; // 默认值 |
||||
|
$item['param'] = isset($item[5]) ? $item[5] : []; // 额外参数 |
||||
|
} |
||||
|
$this->_vars['search'] = $items; |
||||
|
} |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加一个顶部按钮[目前只能新窗口打开,暂时不考虑弹出层] |
||||
|
* @param string $type 按钮类型:add/edit/del/export/build/default |
||||
|
* @param array $attribute 按钮属性 |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function addTopButton($type = '', $attribute = []) |
||||
|
{ |
||||
|
switch ($type) { |
||||
|
|
||||
|
// 新增按钮 |
||||
|
case 'add': |
||||
|
// 默认属性 |
||||
|
$btn_attribute = [ |
||||
|
'title' => '新增', |
||||
|
'icon' => 'fa fa-plus', |
||||
|
'class' => 'btn btn-success', |
||||
|
'href' => '', |
||||
|
'onclick' => '$.operate.add()', |
||||
|
]; |
||||
|
break; |
||||
|
|
||||
|
// 修改按钮 |
||||
|
case 'edit': |
||||
|
// 默认属性 |
||||
|
$btn_attribute = [ |
||||
|
'title' => '修改', |
||||
|
'icon' => 'fa fa-edit', |
||||
|
'class' => 'btn btn-primary single disabled', |
||||
|
'href' => '', |
||||
|
'onclick' => '$.operate.edit()', |
||||
|
]; |
||||
|
break; |
||||
|
|
||||
|
// 删除按钮 |
||||
|
case 'del': |
||||
|
// 默认属性 |
||||
|
$btn_attribute = [ |
||||
|
'title' => '删除', |
||||
|
'icon' => 'fa fa-remove', |
||||
|
'class' => 'btn btn-danger multiple disabled', |
||||
|
'href' => '', |
||||
|
'onclick' => '$.operate.removeAll()' |
||||
|
]; |
||||
|
break; |
||||
|
|
||||
|
// 导出按钮 |
||||
|
case 'export': |
||||
|
// 默认属性 |
||||
|
$btn_attribute = [ |
||||
|
'title' => '导出', |
||||
|
'icon' => 'fa fa-download', |
||||
|
'class' => 'btn btn-warning', |
||||
|
'href' => '', |
||||
|
'onclick' => '$.table.export()' |
||||
|
]; |
||||
|
break; |
||||
|
|
||||
|
// 生成按钮 |
||||
|
case 'build': |
||||
|
// 默认属性 |
||||
|
$btn_attribute = [ |
||||
|
'title' => '代码生成', |
||||
|
'icon' => 'fa fa-file-code-o', |
||||
|
'class' => 'btn btn-info single disabled', |
||||
|
'href' => '', |
||||
|
'onclick' => '$.operate.build(\'\', \''.url('module/build').'\')' |
||||
|
]; |
||||
|
break; |
||||
|
|
||||
|
// 自定义按钮 |
||||
|
default: |
||||
|
// 默认属性 |
||||
|
$btn_attribute = [ |
||||
|
'title' => '自定义', |
||||
|
'icon' => 'fa fa-lightbulb-o', |
||||
|
'class' => 'btn btn-default', |
||||
|
'href' => '', |
||||
|
'onclick' => '' |
||||
|
]; |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
// 合并自定义属性 |
||||
|
if ($attribute && is_array($attribute)) { |
||||
|
$btn_attribute = array_merge($btn_attribute, $attribute); |
||||
|
} |
||||
|
$this->_vars['top_buttons'][] = $btn_attribute; |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 一次性添加多个顶部按钮 |
||||
|
* @param array|string $buttons 按钮组 |
||||
|
* 例如: |
||||
|
* addTopButtons('add') |
||||
|
* addTopButtons('add, edit, del') |
||||
|
* addTopButtons(['add', 'del']) |
||||
|
* addTopButtons(['add' => ['title' => '增加'], 'del']) |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function addTopButtons($buttons = []) |
||||
|
{ |
||||
|
if (!empty($buttons)) { |
||||
|
$buttons = is_array($buttons) ? $buttons : explode(',', $buttons); |
||||
|
foreach ($buttons as $key => $value) { |
||||
|
if (is_numeric($key)) { |
||||
|
// key为数字则直接添加一个按钮 |
||||
|
$this->addTopButton($value); |
||||
|
} else { |
||||
|
// key不为数字则需设置属性,去除前后空格 |
||||
|
$this->addTopButton(trim($key), $value); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return $this; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,198 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | {$comment}控制器 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: {$author} |
||||
|
* ::::::::::: | EMAIL: {$email} |
||||
|
* ..:::::::::::' | DATETIME: {$dateTime} |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\admin\controller; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入表格和表单构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
use app\common\builder\FormBuilder; |
||||
|
use app\common\builder\TableBuilder; |
||||
|
|
||||
|
class {$modelName} extends Base |
||||
|
{ |
||||
|
// 验证器 |
||||
|
protected $validate = '{$validate}'; |
||||
|
|
||||
|
// 当前主表 |
||||
|
protected $tableName = '{$tableName}'; |
||||
|
|
||||
|
// 当前主模型 |
||||
|
protected $modelName = '{$modelName}'; |
||||
|
|
||||
|
// 列表 |
||||
|
public function index(){ |
||||
|
// 获取主键 |
||||
|
$pk = MakeBuilder::getPrimarykey($this->tableName); |
||||
|
// 获取列表数据 |
||||
|
$coloumns = MakeBuilder::getListColumns($this->tableName); |
||||
|
// 获取搜索数据 |
||||
|
$search = MakeBuilder::getListSearch($this->tableName); |
||||
|
// 获取当前模块信息 |
||||
|
$model = '\app\common\model\\' . $this->modelName; |
||||
|
$module = \app\common\model\Module::where('table_name', $this->tableName)->find(); |
||||
|
// 搜索 |
||||
|
if (Request::param('getList') == 1) { |
||||
|
$where = MakeBuilder::getListWhere($this->tableName); |
||||
|
$orderByColumn = Request::param('orderByColumn') ?? $pk; |
||||
|
$isAsc = Request::param('isAsc') ?? 'desc'; |
||||
|
return $model::getList($where, $this->pageSize, [$orderByColumn => $isAsc]); |
||||
|
} |
||||
|
// 检测单页模式 |
||||
|
$isSingle = MakeBuilder::checkSingle($this->modelName); |
||||
|
if ($isSingle) { |
||||
|
return $this->jump($isSingle); |
||||
|
} |
||||
|
// 构建页面 |
||||
|
return TableBuilder::getInstance() |
||||
|
->setUniqueId($pk) // 设置主键 |
||||
|
->addColumns($coloumns) // 添加列表字段数据 |
||||
|
->setSearch($search) // 添加头部搜索 |
||||
|
->addColumn('right_button', '操作', 'btn') // 启用右侧操作列 |
||||
|
->addRightButtons($module->right_button) // 设置右侧操作列 |
||||
|
->addTopButtons($module->top_button) // 设置顶部按钮组 |
||||
|
{$setAddUrl}->fetch(); |
||||
|
} |
||||
|
|
||||
|
// 添加 |
||||
|
public function add() |
||||
|
{ |
||||
|
// 获取字段信息 |
||||
|
$coloumns = MakeBuilder::getAddColumns($this->tableName); |
||||
|
// 获取分组后的字段信息 |
||||
|
$groups = MakeBuilder::getgetAddGroups($this->modelName, $this->tableName, $coloumns); |
||||
|
// 构建页面 |
||||
|
$builder = FormBuilder::getInstance(); |
||||
|
{$showAll} |
||||
|
$groups ? $builder->addGroup($groups) : $builder->addFormItems($coloumns); |
||||
|
return $builder->fetch(); |
||||
|
} |
||||
|
|
||||
|
// 添加保存 |
||||
|
public function addPost() |
||||
|
{ |
||||
|
if (Request::isPost()) { |
||||
|
$data = MakeBuilder::changeFormData(Request::except(['file'], 'post'), $this->tableName); |
||||
|
$result = $this->validate($data, $this->validate); |
||||
|
if (true !== $result) { |
||||
|
// 验证失败 输出错误信息 |
||||
|
$this->error($result); |
||||
|
} else { |
||||
|
$model = '\app\common\model\\' . $this->modelName; |
||||
|
$result = $model::addPost($data); |
||||
|
if ($result['error']) { |
||||
|
$this->error($result['msg']); |
||||
|
} else { |
||||
|
$this->success($result['msg'], 'index'); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 修改 |
||||
|
public function edit(string $id) |
||||
|
{ |
||||
|
$model = '\app\common\model\\' . $this->modelName; |
||||
|
$info = $model::edit($id)->toArray(); |
||||
|
// 获取字段信息 |
||||
|
$coloumns = MakeBuilder::getAddColumns($this->tableName, $info); |
||||
|
// 获取分组后的字段信息 |
||||
|
$groups = MakeBuilder::getgetAddGroups($this->modelName, $this->tableName, $coloumns); |
||||
|
|
||||
|
// 构建页面 |
||||
|
$builder = FormBuilder::getInstance(); |
||||
|
{$showAll}$groups ? $builder->addGroup($groups) : $builder->addFormItems($coloumns); |
||||
|
return $builder->fetch(); |
||||
|
} |
||||
|
|
||||
|
// 修改保存 |
||||
|
public function editPost() |
||||
|
{ |
||||
|
if (Request::isPost()) { |
||||
|
$data = MakeBuilder::changeFormData(Request::except(['file'], 'post'), $this->tableName); |
||||
|
$result = $this->validate($data, $this->validate); |
||||
|
if (true !== $result) { |
||||
|
// 验证失败 输出错误信息 |
||||
|
$this->error($result); |
||||
|
} else { |
||||
|
$model = '\app\common\model\\' . $this->modelName; |
||||
|
$result = $model::editPost($data); |
||||
|
if ($result['error']) { |
||||
|
$this->error($result['msg']); |
||||
|
} else { |
||||
|
$this->success($result['msg'], 'index'); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 删除 |
||||
|
public function del(string $id) |
||||
|
{ |
||||
|
if (Request::isPost()) { |
||||
|
if (strpos($id, ',') !== false) { |
||||
|
return $this->selectDel($id); |
||||
|
} |
||||
|
$model = '\app\common\model\\' . $this->modelName; |
||||
|
return $model::del($id); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 批量删除 |
||||
|
public function selectDel(string $id){ |
||||
|
if (Request::isPost()) { |
||||
|
$model = '\app\common\model\\' . $this->modelName; |
||||
|
return $model::selectDel($id); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 排序 |
||||
|
public function sort() |
||||
|
{ |
||||
|
if (Request::isPost()) { |
||||
|
$data = Request::post(); |
||||
|
$model = '\app\common\model\\' . $this->modelName; |
||||
|
return $model::sort($data); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 状态变更 |
||||
|
public function state(string $id) |
||||
|
{ |
||||
|
if (Request::isPost()) { |
||||
|
$model = '\app\common\model\\' . $this->modelName; |
||||
|
return $model::state($id); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 导出 |
||||
|
public function export() |
||||
|
{ |
||||
|
\app\common\model\Base::export($this->tableName, $this->modelName); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,70 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | {$comment}模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: {$author} |
||||
|
* ::::::::::: | EMAIL: {$email} |
||||
|
* ..:::::::::::' | DATETIME: {$dateTime} |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class {$modelName} extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
{$moduleTable} |
||||
|
{$relations} |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
{$listInfo} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, '{$modelName}'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
{$listInfo} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, '{$modelName}'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | {$comment}验证器 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: {$author} |
||||
|
* ::::::::::: | EMAIL: {$email} |
||||
|
* ..:::::::::::' | DATETIME: {$dateTime} |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\admin\validate; |
||||
|
|
||||
|
use think\Validate; |
||||
|
|
||||
|
class {$modelName} extends Validate |
||||
|
{ |
||||
|
{$rules} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
<?php |
||||
|
namespace app\common\facade; |
||||
|
|
||||
|
use think\Facade; |
||||
|
|
||||
|
class Cms extends Facade |
||||
|
{ |
||||
|
protected static function getFacadeClass() |
||||
|
{ |
||||
|
return 'app\common\service\Cms'; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
<?php |
||||
|
namespace app\common\facade; |
||||
|
|
||||
|
use think\Facade; |
||||
|
|
||||
|
class MakeBuilder extends Facade |
||||
|
{ |
||||
|
protected static function getFacadeClass() |
||||
|
{ |
||||
|
return 'app\common\builder\MakeBuilder'; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
<?php |
||||
|
namespace app\common\facade; |
||||
|
|
||||
|
use think\Facade; |
||||
|
|
||||
|
class User extends Facade |
||||
|
{ |
||||
|
protected static function getFacadeClass() |
||||
|
{ |
||||
|
return 'app\common\service\User'; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 广告管理模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/07/10 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class Ad extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
|
||||
|
public function adType() |
||||
|
{ |
||||
|
return $this->belongsTo('AdType', 'type_id'); |
||||
|
} |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['type_id']) { |
||||
|
$v['type_id'] = $v->adType->getData('name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Ad'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['type_id']) { |
||||
|
$v['type_id'] = $v->adType->getData('name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Ad'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,70 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 广告分组模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/07/10 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class AdType extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
|
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'AdType'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
|
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'AdType'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,164 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 管理员列表模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/03/08 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Db; |
||||
|
use think\facade\Event; |
||||
|
use think\facade\Request; |
||||
|
use think\facade\Session; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class Admin extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
$auth = new \Auth(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
$title = ''; |
||||
|
$groups = $auth->getGroups($v->id); |
||||
|
foreach ($groups as $group) { |
||||
|
$title .= $group['title'] . ','; |
||||
|
} |
||||
|
$title = rtrim($title, ','); |
||||
|
$list[$k]['group_name'] = $title; |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Admin'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
|
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Admin'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 管理员登录校验 |
||||
|
* @return array|\think\response\Json |
||||
|
* @throws \think\Exception |
||||
|
*/ |
||||
|
public static function checkLogin() |
||||
|
{ |
||||
|
// 查找所有系统设置表数据 |
||||
|
$system = \app\common\model\System::find(1); |
||||
|
|
||||
|
$username = Request::param("username"); |
||||
|
$password = Request::param("password"); |
||||
|
$open_code = $system['code']; |
||||
|
if ($open_code) { |
||||
|
$code = Request::param("vercode"); |
||||
|
if (!captcha_check($code)) { |
||||
|
$data = ['error' => '1', 'msg' => '验证码错误']; |
||||
|
return json($data); |
||||
|
} |
||||
|
} |
||||
|
$result = self::where(['username' => $username, 'password' => md5($password)])->find(); |
||||
|
|
||||
|
if (empty($result)) { |
||||
|
$data = ['error' => '1', 'msg' => '帐号或密码错误']; |
||||
|
return json($data); |
||||
|
} else { |
||||
|
$check = Request::checkToken('__token__'); |
||||
|
if (false === $check) { |
||||
|
$data = ['error' => '2', 'msg' => '验证有误']; |
||||
|
return json($data); |
||||
|
} |
||||
|
if ($result['status'] == 1) { |
||||
|
$uid = $result['id']; |
||||
|
// 更新登录IP和登录时间 |
||||
|
self::where('id', '=', $result['id']) |
||||
|
->update(['login_time' => time(), 'login_ip' => Request::ip()]); |
||||
|
|
||||
|
// 查找规则 |
||||
|
$rules = Db::name('auth_group_access') |
||||
|
->alias('a') |
||||
|
->leftJoin('auth_group ag', 'a.group_id = ag.id') |
||||
|
->field('a.group_id,ag.rules,ag.title') |
||||
|
->where('uid', $uid) |
||||
|
->find(); |
||||
|
// 查询所有不验证的方法并放入规则中 |
||||
|
$authOpen = AuthRule::where('auth_open', '=', '0') |
||||
|
->select(); |
||||
|
$authRole = AuthRule::select(); |
||||
|
$authOpens = []; |
||||
|
foreach ($authOpen as $k => $v) { |
||||
|
$authOpens[] = $v['id']; |
||||
|
// 查询所有下级权限 |
||||
|
$ids = getChildsRule($authRole, $v['id']); |
||||
|
foreach ($ids as $kk => $vv) { |
||||
|
$authOpens[] = $vv['id']; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$authOpensStr = !empty($authOpens) ? implode(",", $authOpens) : ''; |
||||
|
$rules['rules'] = $rules['rules'] . $authOpensStr; |
||||
|
|
||||
|
// 重新查询要赋值的数据[原因是toArray必须保证find的数据不为空,为空就报错] |
||||
|
$result = self::where(['username' => $username, 'password' => md5($password)])->find(); |
||||
|
Session::set('admin', [ |
||||
|
'id' => $result['id'], |
||||
|
'username' => $result['username'], |
||||
|
'login_time' => date('Y-m-d H:i:s', $result['login_time']), |
||||
|
'login_ip' => $result['login_ip'], |
||||
|
'nickname' => $result['nickname'], |
||||
|
'image' => $result['image'], |
||||
|
]); |
||||
|
Session::set('admin.group_id' , $rules['group_id']); |
||||
|
Session::set('admin.rules' , explode(',', $rules['rules'])); |
||||
|
Session::set('admin.title' , $rules['title']); |
||||
|
|
||||
|
// 触发登录成功事件 |
||||
|
Event::trigger('AdminLogin', $result); |
||||
|
|
||||
|
$data = ['error' => '0', 'href' => url('Index/index')->__toString(), 'msg' => '登录成功']; |
||||
|
return json($data); |
||||
|
} else { |
||||
|
return json(['error' => 1, 'msg' => '用户已被禁用!']); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,145 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 管理员日志模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/03/08 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
use think\facade\Session; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class AdminLog extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
public function admin() |
||||
|
{ |
||||
|
return $this->belongsTo('Admin', 'admin_id'); |
||||
|
} |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['admin_id']) { |
||||
|
$v['admin_id'] = $v->admin->getData('username'); |
||||
|
} |
||||
|
// 截取部分user_agent |
||||
|
$userAgent = explode('(', $v['user_agent']); |
||||
|
$v['user_agent'] = $userAgent[0]; |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'AdminLog'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['admin_id']) { |
||||
|
$v['admin_id'] = $v->admin->getData('username'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'AdminLog'); |
||||
|
} |
||||
|
|
||||
|
// 管理员日志记录 |
||||
|
public static function record() |
||||
|
{ |
||||
|
// 入库信息 |
||||
|
$adminId = Session::get('admin.id',0); |
||||
|
$url = Request::url(); |
||||
|
$title = ''; |
||||
|
$content = Request::except(['s','_pjax']); //s 变量为系统内置的变量,_pjax为js的变量,无记录的必要 |
||||
|
$ip = Request::ip(); |
||||
|
$userAgent = Request::server('HTTP_USER_AGENT'); |
||||
|
|
||||
|
// 标题处理 |
||||
|
$auth = new \Auth(); |
||||
|
$titleArr = $auth->getBreadCrumb(); |
||||
|
if (is_array($titleArr)) { |
||||
|
foreach ($titleArr as $k => $v) { |
||||
|
$title = '[' . $v['title'] . '] -> ' . $title; |
||||
|
} |
||||
|
$title = substr($title, 0, strlen($title) - 4); |
||||
|
} |
||||
|
|
||||
|
// 内容处理(过长的内容和涉及密码的内容不进行记录) |
||||
|
if ($content) { |
||||
|
foreach ($content as $k => $v) { |
||||
|
if (is_string($v) && strlen($v) > 200 || stripos($k, 'password') !== false) { |
||||
|
unset($content[$k]); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 登录处理 |
||||
|
if (strpos($url, 'Login/checkLogin') !== false) { |
||||
|
$title = '[登录成功]'; |
||||
|
$content = ''; |
||||
|
} |
||||
|
|
||||
|
// 插入数据 |
||||
|
if (!empty($title)) { |
||||
|
// 查询管理员上一条数据 |
||||
|
$result = self::where('admin_id', '=', $adminId) |
||||
|
->order('id', 'desc') |
||||
|
->find(); |
||||
|
if ($result) { |
||||
|
if ($result->url != $url) { |
||||
|
self::create([ |
||||
|
'title' => $title ? $title : '', |
||||
|
'content' => !is_scalar($content) ? json_encode($content) : $content, |
||||
|
'url' => $url, |
||||
|
'admin_id' => $adminId, |
||||
|
'user_agent' => $userAgent, |
||||
|
'ip' => $ip |
||||
|
]); |
||||
|
} |
||||
|
} else { |
||||
|
self::create([ |
||||
|
'title' => $title ? $title : '', |
||||
|
'content' => !is_scalar($content) ? json_encode($content) : $content, |
||||
|
'url' => $url, |
||||
|
'admin_id' => $adminId, |
||||
|
'user_agent' => $userAgent, |
||||
|
'ip' => $ip |
||||
|
]); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 文章模块模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/07/10 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class Article extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
|
||||
|
public function cate() |
||||
|
{ |
||||
|
return $this->belongsTo('Cate', 'cate_id'); |
||||
|
} |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['cate_id']) { |
||||
|
$v['cate_id'] = $v->cate->getData('cate_name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Article'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['cate_id']) { |
||||
|
$v['cate_id'] = $v->cate->getData('cate_name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Article'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,67 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 角色组管理模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/02/02 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class AuthGroup extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
|
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'AuthGroup'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
|
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'AuthGroup'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
<?php |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
class AuthGroupAccess extends Base |
||||
|
{ |
||||
|
// 开启自动写入时间戳字段 |
||||
|
protected $autoWriteTimestamp = true; |
||||
|
} |
||||
@ -0,0 +1,90 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 菜单规则模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/03/08 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class AuthRule extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select() |
||||
|
->toArray(); |
||||
|
$list = tree($list); |
||||
|
foreach ($list as $k => $v) { |
||||
|
$list[$k]['title'] = $v['ltitle']; |
||||
|
$list[$k]['icon'] = $v['icon'] ? "<i class=\"{$v['icon']}\"></i>" : ''; |
||||
|
} |
||||
|
|
||||
|
// 渲染输出 |
||||
|
$result = [ |
||||
|
'total' => count($list), |
||||
|
'per_page' => 10000, |
||||
|
'current_page' => 1, |
||||
|
'last_page' => 1, |
||||
|
'data' => $list, |
||||
|
]; |
||||
|
return MakeBuilder::changeTableData($result, 'AuthRule'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
|
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'AuthRule'); |
||||
|
} |
||||
|
|
||||
|
// 获取父ID选项信息 |
||||
|
public static function getPidOptions($order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::order($order) |
||||
|
->select() |
||||
|
->toArray(); |
||||
|
$list = tree($list); |
||||
|
$result = []; |
||||
|
foreach ($list as $k => $v) { |
||||
|
$result[$v['id']] = $v['ltitle']; |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,153 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 公共模型基类 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | QQ: 407593529 |
||||
|
* '::::::::::::' | DATETIME: 2019/04/02 |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
use think\Model; |
||||
|
|
||||
|
// 引入导出的命名空间 |
||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
||||
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx; |
||||
|
|
||||
|
class Base extends Model |
||||
|
{ |
||||
|
// 开启自动写入时间戳字段 |
||||
|
protected $autoWriteTimestamp = true; |
||||
|
|
||||
|
// 通用修改数据 |
||||
|
public static function edit($id){ |
||||
|
$info = self::find($id); |
||||
|
return $info; |
||||
|
} |
||||
|
|
||||
|
// 通用修改保存 |
||||
|
public static function editPost($data) |
||||
|
{ |
||||
|
if ($data) { |
||||
|
foreach ($data as $k => $v) { |
||||
|
if ($v && is_array($v)) { |
||||
|
$data[$k] = implode(',', $v); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$result = self::update($data); |
||||
|
if ($result) { |
||||
|
return ['error' => 0, 'msg' => '修改成功']; |
||||
|
} else { |
||||
|
return ['error' => 1, 'msg' => '修改失败']; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 通用添加保存 |
||||
|
public static function addPost($data){ |
||||
|
if ($data) { |
||||
|
foreach ($data as $k => $v) { |
||||
|
if ($v && is_array($v)) { |
||||
|
$data[$k] = implode(',', $v); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$result = self::create($data); |
||||
|
if ($result) { |
||||
|
return ['error' => 0, 'msg' => '添加成功']; |
||||
|
} else { |
||||
|
return ['error' => 1, 'msg' => '添加失败']; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 删除 |
||||
|
public static function del($id){ |
||||
|
self::destroy($id); |
||||
|
return json(['error'=>0,'msg'=>'删除成功!']); |
||||
|
} |
||||
|
|
||||
|
// 批量删除 |
||||
|
public static function selectDel($id){ |
||||
|
if ($id) { |
||||
|
$ids = explode(',',$id); |
||||
|
self::destroy($ids); |
||||
|
return json(['error'=>0, 'msg'=>'删除成功!']); |
||||
|
}else{ |
||||
|
return ['error' => 1, 'msg' => '删除失败']; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 排序修改 |
||||
|
public static function sort($data) |
||||
|
{ |
||||
|
$info = self::find($data['id']); |
||||
|
if ($info->sort != $data['sort']) { |
||||
|
$info->sort = $data['sort']; |
||||
|
$info->save(); |
||||
|
return json(['error' => 0, 'msg' => '修改成功!']); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 状态修改 |
||||
|
public static function state($id){ |
||||
|
$info = self::find($id); |
||||
|
$info-> status = $info['status'] == 1 ? 0 : 1; |
||||
|
$info -> save(); |
||||
|
return json(['error'=>0, 'msg'=>'修改成功!']); |
||||
|
} |
||||
|
|
||||
|
// 导出 |
||||
|
public static function export($tableNam, $moduleName){ |
||||
|
// 获取主键 |
||||
|
$pk = \app\common\facade\MakeBuilder::getPrimarykey($tableNam); |
||||
|
// 获取列表数据 |
||||
|
$coloumns = \app\common\facade\MakeBuilder::getListColumns($tableNam); |
||||
|
// 搜索 |
||||
|
$where = \app\common\facade\MakeBuilder::getListWhere($tableNam); |
||||
|
$orderByColumn = \think\facade\Request::param('orderByColumn') ?? $pk; |
||||
|
$isAsc = \think\facade\Request::param('isAsc') ?? 'desc'; |
||||
|
$model = '\app\common\model\\' . $moduleName; |
||||
|
// 获取要导出的数据 |
||||
|
$list = $model::getExport($where, [$orderByColumn => $isAsc]); |
||||
|
// 初始化表头数组 |
||||
|
$str = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']; |
||||
|
$spreadsheet = new Spreadsheet(); |
||||
|
$sheet = $spreadsheet->getActiveSheet(); |
||||
|
foreach ($coloumns as $k => $v) { |
||||
|
$sheet->setCellValue($str[$k] . '1', $v['1']); |
||||
|
} |
||||
|
foreach ($list as $key => $value) { |
||||
|
foreach ($coloumns as $k => $v) { |
||||
|
// 修正字典数据 |
||||
|
if (isset($v[4]) && is_array($v[4]) && !empty($v[4])) { |
||||
|
$value[$v['0']] = $v[4][$value[$v['0']]]; |
||||
|
} |
||||
|
$sheet->setCellValue($str[$k].($key+2),$value[$v['0']]); |
||||
|
} |
||||
|
} |
||||
|
$moduleName = \app\common\model\Module::where('table_name', $tableNam)->value('module_name'); |
||||
|
header('Content-Type: application/vnd.ms-excel'); |
||||
|
header('Content-Disposition: attachment;filename="' . $moduleName . '导出' . '.xlsx"'); |
||||
|
header('Cache-Control: max-age=0'); |
||||
|
$writer = new Xlsx($spreadsheet); |
||||
|
$writer->save('php://output'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,98 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 栏目管理模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/03/08 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class Cate extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
public function module() |
||||
|
{ |
||||
|
return $this->belongsTo('Module', 'module_id'); |
||||
|
} |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['module_id']) { |
||||
|
$v['module_id'] = $v->module->getData('module_name'); |
||||
|
} |
||||
|
} |
||||
|
$list = tree_cate($list->toArray()); |
||||
|
// 重设栏目名称 |
||||
|
foreach($list as &$ls){ |
||||
|
$ls['cate_name'] = $ls['l_cate_name']; |
||||
|
} |
||||
|
// 渲染输出 |
||||
|
$result = [ |
||||
|
'total' => count($list), |
||||
|
'per_page' => 10000, |
||||
|
'current_page' => 1, |
||||
|
'last_page' => 1, |
||||
|
'data' => $list, |
||||
|
]; |
||||
|
return MakeBuilder::changeTableData($result, 'Cate'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['module_id']) { |
||||
|
$v['module_id'] = $v->module->getData('module_name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Cate'); |
||||
|
} |
||||
|
|
||||
|
// 获取父ID选项信息 |
||||
|
public static function getPidOptions($order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::order($order) |
||||
|
->select() |
||||
|
->toArray(); |
||||
|
$list = tree_cate($list); |
||||
|
$result = []; |
||||
|
foreach ($list as $k => $v) { |
||||
|
$result[$v['id']] = $v['l_cate_name']; |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 公共配置文件模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | QQ: 407593529 |
||||
|
* '::::::::::::' | DATETIME: 2019/03/04 |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
class Config extends Base |
||||
|
{ |
||||
|
//不需要使用自动时间戳 |
||||
|
protected $autoWriteTimestamp = false; |
||||
|
|
||||
|
// 定义时间戳字段名 |
||||
|
//protected $createTime = 'create_time'; |
||||
|
//protected $updateTime = 'update_time'; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,70 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 碎片管理模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/07/10 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class Debris extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
|
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Debris'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
|
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Debris'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 字典数据模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/07/10 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class Dictionary extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
|
||||
|
public function dictionaryType() |
||||
|
{ |
||||
|
return $this->belongsTo('DictionaryType', 'dict_type'); |
||||
|
} |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['dict_type']) { |
||||
|
$v['dict_type'] = $v->dictionaryType->getData('dict_name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Dictionary'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['dict_type']) { |
||||
|
$v['dict_type'] = $v->dictionaryType->getData('dict_name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Dictionary'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,70 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 字典类型模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/07/10 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class DictionaryType extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
|
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'DictionaryType'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
|
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'DictionaryType'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 下载模块模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/07/10 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class Download extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
|
||||
|
public function cate() |
||||
|
{ |
||||
|
return $this->belongsTo('Cate', 'cate_id'); |
||||
|
} |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['cate_id']) { |
||||
|
$v['cate_id'] = $v->cate->getData('cate_name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Download'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['cate_id']) { |
||||
|
$v['cate_id'] = $v->cate->getData('cate_name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Download'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,92 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 模型字段模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/03/08 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
class Field extends Base |
||||
|
{ |
||||
|
// 开启自动写入时间戳字段 |
||||
|
protected $autoWriteTimestamp = false; |
||||
|
|
||||
|
// 一对一获取所属模块 |
||||
|
public function Module() |
||||
|
{ |
||||
|
return $this->belongsTo('Module', 'module_id'); |
||||
|
} |
||||
|
|
||||
|
// 一对一获取所属字典 |
||||
|
public function DictionaryType() |
||||
|
{ |
||||
|
return $this->belongsTo('DictionaryType', 'dict_code'); |
||||
|
} |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
$list[$k]['module_id'] = $v->Module->getData('module_name'); |
||||
|
if ($list[$k]['dict_code']) { |
||||
|
$list[$k]['dict_code'] = $v->DictionaryType->getData('dict_name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Field'); |
||||
|
} |
||||
|
|
||||
|
// 获取模型对应的字段信息 |
||||
|
public static function getFieldList($moduleId, $order = ['sort' => 'asc', 'id' => 'asc']) |
||||
|
{ |
||||
|
$list = self::where('module_id', $moduleId) |
||||
|
->order($order) |
||||
|
->select() |
||||
|
->toArray(); |
||||
|
// 格式化setup 字段 |
||||
|
$result = array(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if (!empty($v['setup'])) { |
||||
|
$list[$k]['setup'] = string2array($v['setup']); |
||||
|
if (array_key_exists('options', $list[$k]['setup'])) { |
||||
|
$list[$k]['setup']['options'] = explode("\n", $list[$k]['setup']['options']); |
||||
|
foreach ($list[$k]['setup']['options'] as $kk => $vv) { |
||||
|
$list[$k]['setup']['options'][$kk] = trim_array_element(explode("|", $list[$k]['setup']['options'][$kk])); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$result[$v['field']] = $list[$k]; |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 字段分组模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/07/10 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class FieldGroup extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
|
||||
|
public function module() |
||||
|
{ |
||||
|
return $this->belongsTo('Module', 'module_id'); |
||||
|
} |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['module_id']) { |
||||
|
$v['module_id'] = $v->module->getData('module_name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'FieldGroup'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['module_id']) { |
||||
|
$v['module_id'] = $v->module->getData('module_name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'FieldGroup'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,70 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 友情链接模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/07/10 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class Link extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
|
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Link'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
|
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Link'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 留言模块模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/07/10 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class Message extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
|
||||
|
public function cate() |
||||
|
{ |
||||
|
return $this->belongsTo('Cate', 'cate_id'); |
||||
|
} |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['cate_id']) { |
||||
|
$v['cate_id'] = $v->cate->getData('cate_name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Message'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['cate_id']) { |
||||
|
$v['cate_id'] = $v->cate->getData('cate_name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Message'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,263 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 模块列表模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/03/08 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Config; |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class Module extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]) |
||||
|
->toArray(); |
||||
|
// 获取不可选中的信息 |
||||
|
$unMakeModule = MakeBuilder::unMakeModule(); |
||||
|
foreach ($list['data'] as $k => $v) { |
||||
|
if (in_array($v['model_name'], $unMakeModule)) { |
||||
|
$list['data'][$k]['checkbox_disabled'] = '1'; |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Module'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
return $list; |
||||
|
} |
||||
|
|
||||
|
// 添加模块时创建表,并初始化主键字段、添加时间、修改时间等字段 |
||||
|
public static function makeModule(string $tableName, int $tableType = 2) |
||||
|
{ |
||||
|
// 获取模块信息 |
||||
|
$module = self::where('table_name', $tableName)->find(); |
||||
|
// 获取表前缀 |
||||
|
$tableName = \think\facade\Config::get('database.connections.mysql.prefix') . $tableName; |
||||
|
// 取得所有表名称 |
||||
|
$tables = \think\facade\Db::getTables(); |
||||
|
// 已有表则不再创建 |
||||
|
if (in_array($tableName, $tables)) { |
||||
|
return '表已存在,请先手动删除[' . $tableName.']'; |
||||
|
} else { |
||||
|
$sqlStr = '`id` int(8) unsigned NOT NULL AUTO_INCREMENT, |
||||
|
`create_time` int(11) NOT NULL, |
||||
|
`update_time` int(11) NOT NULL,'; |
||||
|
// 自动添加排序字段 |
||||
|
if ($module->is_sort) { |
||||
|
$sqlStr .= '`sort` mediumint(8) DEFAULT \'50\' COMMENT \'排序\','; |
||||
|
} |
||||
|
// 自动添加状态字段 |
||||
|
if ($module->is_status) { |
||||
|
$sqlStr .= '`status` tinyint(1) DEFAULT NULL COMMENT \'状态\','; |
||||
|
} |
||||
|
// 添加CMS模块时自动增加[栏目ID、点击数、关键词、描述、模板、跳转地址]字段 |
||||
|
if ($tableType == 1 && Config::get('builder.add_cate_id')) { |
||||
|
$sqlStr .= '`cate_id` int(8) unsigned NOT NULL DEFAULT \'0\' COMMENT \'栏目\','; |
||||
|
$sqlStr .= '`hits` int(8) unsigned NOT NULL DEFAULT \'0\' COMMENT \'点击次数\','; |
||||
|
$sqlStr .= '`keywords` varchar(255) NOT NULL DEFAULT \'\' COMMENT \'关键词\','; |
||||
|
$sqlStr .= '`description` varchar(255) NOT NULL DEFAULT \'\' COMMENT \'描述\','; |
||||
|
$sqlStr .= '`template` varchar(30) NOT NULL DEFAULT \'\' COMMENT \'模板\','; |
||||
|
$sqlStr .= '`url` varchar(255) NOT NULL DEFAULT \'\' COMMENT \'跳转地址\','; |
||||
|
} |
||||
|
|
||||
|
$sql = "CREATE TABLE `{$tableName}` ( |
||||
|
{$sqlStr} |
||||
|
PRIMARY KEY (`id`) |
||||
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='{$module->table_comment}'"; |
||||
|
\think\facade\Db::execute($sql); |
||||
|
// 插入表记录 |
||||
|
$data = [ |
||||
|
['module_id' => $module->id, 'field' => 'id', 'name' => '编号', 'type' => 'hidden', 'is_list' => '1', 'status' => '1', 'sort' => '1', 'remark' => '自增ID', 'setup' => "array ('default' => '0','extra_attr' => '','extra_class' => '','step' => '1','fieldtype' => 'int','group' => '')"], |
||||
|
['module_id' => $module->id, 'field' => 'create_time', 'name' => '添加时间', 'maxlength' => '11', 'type' => 'datetime', 'is_list' => '1', 'search_type' => '=', 'status' => '1', 'sort' => '50', 'remark' => '添加时间', 'setup' => "array ('default' => '0', 'format' => 'yyyy-mm-dd hh:ii:ss', 'extra_attr' => '', 'extra_class' => '', 'placeholder' => '', 'fieldtype' => 'int',)"], |
||||
|
['module_id' => $module->id, 'field' => 'update_time', 'name' => '更新时间', 'maxlength' => '11', 'type' => 'datetime', 'is_list' => '1', 'search_type' => '=', 'status' => '1', 'sort' => '50', 'remark' => '更新时间', 'setup' => "array ('default' => '0', 'format' => 'yyyy-mm-dd hh:ii:ss', 'extra_attr' => '', 'extra_class' => '', 'placeholder' => '', 'fieldtype' => 'int',)"], |
||||
|
]; |
||||
|
// 自动添加排序字段 |
||||
|
if ($module->is_sort) { |
||||
|
$data[] = ['module_id' => $module->id, 'field' => 'sort', 'name' => '排序', 'required' => '1', 'maxlength' => '8', 'type' => 'number', 'is_add' => '1', 'is_edit' => '1', 'is_list' => '1', 'is_sort' => '1', 'search_type' => '=', 'status' => '1', 'sort' => '49', 'remark' => '', 'setup' => "array ('default' => '50', 'extra_attr' => '', 'extra_class' => '', 'step' => '1', 'fieldtype' => 'int',)"]; |
||||
|
} |
||||
|
// 自动添加状态字段 |
||||
|
if ($module->is_status) { |
||||
|
$data[] = ['module_id' => $module->id, 'field' => 'status', 'name' => '状态', 'required' => '1', 'maxlength' => '1', 'type' => 'radio', 'data_source' => '1', 'dict_code' => '1', 'is_add' => '1', 'is_edit' => '1', 'is_list' => '1', 'is_search' => '1', 'is_sort' => '0', 'search_type' => '=', 'status' => '1', 'sort' => '48', 'remark' => '', 'setup' => "array ('default' => '1', 'extra_attr' => '', 'extra_class' => '', 'fieldtype' => 'tinyint',)"]; |
||||
|
} |
||||
|
|
||||
|
// 添加CMS模块时自动增加[栏目ID、点击数、关键词、描述、模板、跳转地址]字段 |
||||
|
if ($tableType == 1 && Config::get('builder.add_cate_id')) { |
||||
|
$data[] = [ |
||||
|
'module_id' => $module->id, |
||||
|
'field' => 'cate_id', |
||||
|
'name' => '栏目', |
||||
|
'required' => '1', |
||||
|
'maxlength' => '0', |
||||
|
'type' => 'select', |
||||
|
'data_source' => '2', |
||||
|
'relation_model' => 'Cate', |
||||
|
'relation_field' => 'cate_name', |
||||
|
'is_add' => '1', |
||||
|
'is_edit' => '1', |
||||
|
'is_list' => '1', |
||||
|
'is_search' => '1', |
||||
|
'is_sort' => '0', |
||||
|
'search_type' => '=', |
||||
|
'status' => '1', |
||||
|
'sort' => '2', |
||||
|
'remark' => '栏目', |
||||
|
'setup' => "array ('default' => '0', 'extra_attr' => '', 'extra_class' => '', 'fieldtype' => 'tinyint',)" |
||||
|
]; |
||||
|
$data[] = [ |
||||
|
'module_id' => $module->id, |
||||
|
'field' => 'hits', |
||||
|
'name' => '点击次数', |
||||
|
'required' => '0', |
||||
|
'maxlength' => '0', |
||||
|
'type' => 'number', |
||||
|
'data_source' => '0', |
||||
|
'relation_model' => '', |
||||
|
'relation_field' => '', |
||||
|
'is_add' => '1', |
||||
|
'is_edit' => '1', |
||||
|
'is_list' => '1', |
||||
|
'is_search' => '0', |
||||
|
'is_sort' => '1', |
||||
|
'search_type' => '=', |
||||
|
'status' => '1', |
||||
|
'sort' => '43', |
||||
|
'remark' => '点击次数', |
||||
|
'setup' => "array ('default' => '0', 'extra_attr' => '', 'extra_class' => '', 'step' => '1', 'fieldtype' => 'int', )" |
||||
|
]; |
||||
|
$data[] = [ |
||||
|
'module_id' => $module->id, |
||||
|
'field' => 'keywords', |
||||
|
'name' => '关键词', |
||||
|
'required' => '0', |
||||
|
'maxlength' => '0', |
||||
|
'type' => 'text', |
||||
|
'data_source' => '0', |
||||
|
'relation_model' => '', |
||||
|
'relation_field' => '', |
||||
|
'is_add' => '1', |
||||
|
'is_edit' => '1', |
||||
|
'is_list' => '0', |
||||
|
'is_search' => '0', |
||||
|
'is_sort' => '0', |
||||
|
'search_type' => '=', |
||||
|
'status' => '1', |
||||
|
'sort' => '44', |
||||
|
'remark' => '关键词', |
||||
|
'setup' => "array ( 'default' => '', 'extra_attr' => '', 'extra_class' => '', 'placeholder' => '', 'fieldtype' => 'varchar', 'group' => '', )" |
||||
|
]; |
||||
|
$data[] = [ |
||||
|
'module_id' => $module->id, |
||||
|
'field' => 'description', |
||||
|
'name' => '描述', |
||||
|
'required' => '0', |
||||
|
'maxlength' => '255', |
||||
|
'type' => 'textarea', |
||||
|
'data_source' => '0', |
||||
|
'relation_model' => '', |
||||
|
'relation_field' => '', |
||||
|
'is_add' => '1', |
||||
|
'is_edit' => '1', |
||||
|
'is_list' => '0', |
||||
|
'is_search' => '0', |
||||
|
'is_sort' => '0', |
||||
|
'search_type' => '=', |
||||
|
'status' => '1', |
||||
|
'sort' => '45', |
||||
|
'remark' => '描述', |
||||
|
'setup' => "array ( 'default' => '', 'extra_attr' => '', 'extra_class' => '', 'placeholder' => '', 'fieldtype' => 'varchar', )" |
||||
|
]; |
||||
|
$data[] = [ |
||||
|
'module_id' => $module->id, |
||||
|
'field' => 'template', |
||||
|
'name' => '模板', |
||||
|
'tips' => '单独设置此条记录的模板,如:article_show.html 或 article_show', |
||||
|
'required' => '0', |
||||
|
'maxlength' => '30', |
||||
|
'type' => 'text', |
||||
|
'data_source' => '0', |
||||
|
'relation_model' => '', |
||||
|
'relation_field' => '', |
||||
|
'is_add' => '1', |
||||
|
'is_edit' => '1', |
||||
|
'is_list' => '0', |
||||
|
'is_search' => '0', |
||||
|
'is_sort' => '0', |
||||
|
'search_type' => '=', |
||||
|
'status' => '1', |
||||
|
'sort' => '46', |
||||
|
'remark' => '模板', |
||||
|
'setup' => "array ( 'default' => '', 'extra_attr' => '', 'extra_class' => '', 'placeholder' => '', 'fieldtype' => 'varchar', 'group' => '', )" |
||||
|
]; |
||||
|
$data[] = [ |
||||
|
'module_id' => $module->id, |
||||
|
'field' => 'url', |
||||
|
'name' => '跳转地址', |
||||
|
'tips' => '如需直接跳转,请填写完整的网站地址或相对地址', |
||||
|
'required' => '0', |
||||
|
'maxlength' => '0', |
||||
|
'type' => 'text', |
||||
|
'data_source' => '0', |
||||
|
'relation_model' => '', |
||||
|
'relation_field' => '', |
||||
|
'is_add' => '1', |
||||
|
'is_edit' => '1', |
||||
|
'is_list' => '0', |
||||
|
'is_search' => '0', |
||||
|
'is_sort' => '0', |
||||
|
'search_type' => '=', |
||||
|
'status' => '1', |
||||
|
'sort' => '47', |
||||
|
'remark' => '跳转地址', |
||||
|
'setup' => "array ( 'default' => '', 'extra_attr' => '', 'extra_class' => '', 'placeholder' => '', 'fieldtype' => 'varchar', 'group' => '', |
||||
|
)" |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
$fild = new Field(); |
||||
|
$fild->saveAll($data); |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 单页模块模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/07/10 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class Page extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
|
||||
|
public function cate() |
||||
|
{ |
||||
|
return $this->belongsTo('Cate', 'cate_id'); |
||||
|
} |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['cate_id']) { |
||||
|
$v['cate_id'] = $v->cate->getData('cate_name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Page'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['cate_id']) { |
||||
|
$v['cate_id'] = $v->cate->getData('cate_name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Page'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,84 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 图片模块模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/07/10 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class Picture extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
|
||||
|
public function cate() |
||||
|
{ |
||||
|
return $this->belongsTo('Cate', 'cate_id'); |
||||
|
}public function article() |
||||
|
{ |
||||
|
return $this->belongsTo('Article', 'guanlian'); |
||||
|
} |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['cate_id']) { |
||||
|
$v['cate_id'] = $v->cate->getData('cate_name'); |
||||
|
}if ($list[$k]['guanlian']) { |
||||
|
$v['guanlian'] = $v->article->getData('title'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Picture'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['cate_id']) { |
||||
|
$v['cate_id'] = $v->cate->getData('cate_name'); |
||||
|
}if ($list[$k]['guanlian']) { |
||||
|
$v['guanlian'] = $v->article->getData('title'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Picture'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 产品模块模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/07/10 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class Product extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
|
||||
|
public function cate() |
||||
|
{ |
||||
|
return $this->belongsTo('Cate', 'cate_id'); |
||||
|
} |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['cate_id']) { |
||||
|
$v['cate_id'] = $v->cate->getData('cate_name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Product'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['cate_id']) { |
||||
|
$v['cate_id'] = $v->cate->getData('cate_name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Product'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,70 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 系统设置模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/07/10 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class System extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
|
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'System'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
|
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'System'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,53 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 系统设置分组模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | QQ: 407593529 |
||||
|
* '::::::::::::' | DATETIME: 2019/05/15 |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
use think\facade\Request; |
||||
|
|
||||
|
class SystemGroup extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
// 一对多获取系统设置 |
||||
|
public function systems() |
||||
|
{ |
||||
|
return $this->hasMany('System', 'group_id'); |
||||
|
} |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id'=>'desc']){ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
return $list; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 团队模块模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/07/10 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class Team extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
|
||||
|
public function cate() |
||||
|
{ |
||||
|
return $this->belongsTo('Cate', 'cate_id'); |
||||
|
} |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['cate_id']) { |
||||
|
$v['cate_id'] = $v->cate->getData('cate_name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Team'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['cate_id']) { |
||||
|
$v['cate_id'] = $v->cate->getData('cate_name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Team'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 会员管理模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/07/10 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class Users extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
|
||||
|
public function usersType() |
||||
|
{ |
||||
|
return $this->belongsTo('UsersType', 'type_id'); |
||||
|
} |
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['type_id']) { |
||||
|
$v['type_id'] = $v->usersType->getData('name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Users'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
if ($list[$k]['type_id']) { |
||||
|
$v['type_id'] = $v->usersType->getData('name'); |
||||
|
} |
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'Users'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,70 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 会员分组模型 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2020/07/10 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\model; |
||||
|
|
||||
|
// 引入框架内置类 |
||||
|
use think\facade\Request; |
||||
|
|
||||
|
// 引入构建器 |
||||
|
use app\common\facade\MakeBuilder; |
||||
|
|
||||
|
class UsersType extends Base |
||||
|
{ |
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = 'create_time'; |
||||
|
protected $updateTime = 'update_time'; |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
// 获取列表 |
||||
|
public static function getList($where = array(), $pageSize, $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->paginate([ |
||||
|
'query' => Request::get(), |
||||
|
'list_rows' => $pageSize, |
||||
|
]); |
||||
|
foreach ($list as $k => $v) { |
||||
|
|
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'UsersType'); |
||||
|
} |
||||
|
|
||||
|
// 导出列表 |
||||
|
public static function getExport($where = array(), $order = ['sort', 'id' => 'desc']) |
||||
|
{ |
||||
|
$list = self::where($where) |
||||
|
->order($order) |
||||
|
->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
|
||||
|
} |
||||
|
return MakeBuilder::changeTableData($list, 'UsersType'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,253 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | CMS前台相关业务处理 |
||||
|
|
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\service; |
||||
|
|
||||
|
use app\common\facade\MakeBuilder; |
||||
|
use app\common\model\Cate; |
||||
|
use think\facade\Config; |
||||
|
use think\facade\Db; |
||||
|
|
||||
|
class Cms |
||||
|
{ |
||||
|
/** |
||||
|
* 获取栏目信息 |
||||
|
* @param string $cateId 栏目id |
||||
|
* @return array|null|\think\Model |
||||
|
*/ |
||||
|
public function getCateInfo(string $cateId) |
||||
|
{ |
||||
|
$cate = Cate::where('id', '=', $cateId)->find(); |
||||
|
// 设置顶级栏目,当顶级栏目不存在的时候顶级栏目为本身 |
||||
|
if ($cate) { |
||||
|
$cate->topid = $cate['parent_id'] ? $cate['parent_id'] : $cate['id']; |
||||
|
} |
||||
|
return $cate; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 更新内容的点击数 |
||||
|
* @param string $id 内容id |
||||
|
* @param string $tableName 表名称(含前缀) |
||||
|
* @return bool |
||||
|
*/ |
||||
|
public function addHits(string $id, string $tableName) |
||||
|
{ |
||||
|
// 判断当前表是否存在hits字段 |
||||
|
if ($this->_iset_field(Config::get('database.connections.mysql.prefix') . $tableName, 'hits')) { |
||||
|
Db::name($tableName) |
||||
|
->where('id', $id) |
||||
|
->inc('hits') |
||||
|
->update(); |
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取内容的详细信息 |
||||
|
* @param string $id |
||||
|
* @param string $tableName |
||||
|
*/ |
||||
|
public function getInfo(string $id, string $tableName) |
||||
|
{ |
||||
|
$modelName = $this->getModelName($tableName); |
||||
|
if (empty($modelName)) { |
||||
|
return false; |
||||
|
} |
||||
|
$model = '\app\common\model\\' . $modelName; |
||||
|
$info = $model::edit($id)->toArray(); |
||||
|
// 获取字段信息 |
||||
|
$info = $this->changeInfo($tableName, $info); |
||||
|
return $info; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取内容页面TDK |
||||
|
* @param $info 内容 |
||||
|
* @param $cate 栏目 |
||||
|
* @param $system 系统 |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function getInfoTdk($info, $cate, $system) |
||||
|
{ |
||||
|
$result = []; |
||||
|
$result['title'] = $cate['cate_name'] ?: $cate['catname']; // 标题 |
||||
|
$result['keywords'] = $info['keywords'] ?: ($cate['keywords'] ?: $system['key']); // 关键词 |
||||
|
$result['description'] = $info['description'] ? $info['description'] : ($cate['description'] ?: $system['des']); // 描述 |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取内容页面模版 |
||||
|
* @param $info 内容 |
||||
|
* @param $cate 栏目 |
||||
|
* @param $tableName 表名称 |
||||
|
* @return mixed|string |
||||
|
*/ |
||||
|
public function getInfoView($info, $cate, string $tableName) |
||||
|
{ |
||||
|
return $info['template'] ? str_replace('.html', '', $info['template']) : |
||||
|
($cate['template_show'] ? str_replace('.html', '', $cate['template_show']) : $tableName . '_show'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取列表页面TDK |
||||
|
* @param $info 内容 |
||||
|
* @param $cate 栏目 |
||||
|
* @param $system 系统 |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function getListTdk($cate, $system) |
||||
|
{ |
||||
|
$result = []; |
||||
|
$result['title'] = $cate['title'] ?: $cate['cate_name']; // 标题 |
||||
|
$result['keywords'] = $cate['keywords'] ?: $system['key']; // 关键词 |
||||
|
$result['description'] = $cate['description'] ?: $system['des']; // 描述 |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取列表页面模版 |
||||
|
* @param $info 内容 |
||||
|
* @param $cate 栏目 |
||||
|
* @param $tableName 表名称 |
||||
|
* @return mixed|string |
||||
|
*/ |
||||
|
public function getListView($cate, string $tableName) |
||||
|
{ |
||||
|
return $cate['template_list'] ? str_replace('.html', '', $cate['template_list']) : $tableName . '_list'; |
||||
|
} |
||||
|
|
||||
|
// =================================================== |
||||
|
|
||||
|
/** |
||||
|
* 判断表中是否存在所选字段 |
||||
|
* @param $table 表全称 |
||||
|
* @param $field 字段名称 |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
private function _iset_field($table, $field) |
||||
|
{ |
||||
|
$fields = Db::getTableFields($table); |
||||
|
if (array_search($field, $fields) === false) { |
||||
|
return false; |
||||
|
} else { |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据表名称查询模型名称 |
||||
|
* @param string $tableName [表名称,不含前缀] |
||||
|
* @return mixed|string |
||||
|
*/ |
||||
|
private function getModelName(string $tableName) |
||||
|
{ |
||||
|
$module = \app\common\model\Module::where('table_name', $tableName)->find(); |
||||
|
if ($module) { |
||||
|
return $module->model_name; |
||||
|
} else { |
||||
|
// 查询不到模块信息,直接尝试转换[需遵循ThinkPHP命名规范] |
||||
|
$tableName = explode('_', $tableName); |
||||
|
$result = ''; |
||||
|
foreach ($tableName as $k => $v) { |
||||
|
$result .= ucfirst($v); |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据表名称查询模型ID |
||||
|
* @param string $tableName [表名称,不含前缀] |
||||
|
* @return mixed|string |
||||
|
*/ |
||||
|
private function getModelId(string $tableName) |
||||
|
{ |
||||
|
$module = \app\common\model\Module::where('table_name', $tableName)->find(); |
||||
|
if ($module) { |
||||
|
return $module->id; |
||||
|
} else { |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 格式化详情页面的内容输出 |
||||
|
* @param string $tableName |
||||
|
* @param array $info |
||||
|
* @return array |
||||
|
*/ |
||||
|
private function changeInfo(string $tableName, array $info) |
||||
|
{ |
||||
|
$fields = MakeBuilder::getFields($tableName); |
||||
|
foreach ($fields as &$field) { |
||||
|
// select等需要获取数据的字段 |
||||
|
$options = MakeBuilder::getFieldOptions($field); |
||||
|
|
||||
|
// 添加到返回数组中,注意form构建器和table构建器的不一致 |
||||
|
if ($field['type'] == 'text') { |
||||
|
// 忽略 |
||||
|
} elseif ($field['type'] == 'textarea' || $field['type'] == 'password') { |
||||
|
// 忽略 |
||||
|
} elseif ($field['type'] == 'radio' || $field['type'] == 'checkbox') { |
||||
|
$info[$field['field']] = $this->changeOptionsValue($options, $info[$field['field']], false); |
||||
|
} elseif ($field['type'] == 'select' || $field['type'] == 'select2') { |
||||
|
if ($field['field'] !== 'cate_id') { |
||||
|
$info[$field['field']] = $this->changeOptionsValue($options, $info[$field['field']], false); |
||||
|
} |
||||
|
} elseif ($field['type'] == 'number') { |
||||
|
} elseif ($field['type'] == 'hidden') { |
||||
|
} elseif ($field['type'] == 'date' || $field['type'] == 'time' || $field['type'] == 'datetime') { |
||||
|
|
||||
|
} elseif ($field['type'] == 'daterange') { |
||||
|
} elseif ($field['type'] == 'tag') { |
||||
|
if (!empty($info[$field['field']])) { |
||||
|
$tags = explode(',', $info[$field['field']]); |
||||
|
foreach ($tags as $k => $tag) { |
||||
|
$tags[$k] = [ |
||||
|
'name' => $tag, |
||||
|
'url' => \think\facade\Route::buildUrl('index/tag', ['module' => $this->getModelId($tableName), 't' => $tag])->__toString(), |
||||
|
]; |
||||
|
} |
||||
|
$info[$field['field']] = $tags; |
||||
|
} |
||||
|
} elseif ($field['type'] == 'images' || $field['type'] == 'files') { |
||||
|
$info[$field['field']] = json_decode($info[$field['field']], true); |
||||
|
} elseif ($field['type'] == 'editor') { |
||||
|
|
||||
|
} elseif ($field['type'] == 'color') { |
||||
|
|
||||
|
} |
||||
|
// Button |
||||
|
} |
||||
|
return $info; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 改变内容中有选项的值为可用数组 |
||||
|
* @param array $options 选项 |
||||
|
* @param string $value 当前值 |
||||
|
* @param bool $type 返回类型(true array/false string) |
||||
|
* @return array/string |
||||
|
*/ |
||||
|
private function changeOptionsValue(array $options = [], string $value = '', bool $type = true) |
||||
|
{ |
||||
|
$result = []; |
||||
|
if ($value) { |
||||
|
$value = explode(',', $value); |
||||
|
foreach ($value as $k => $v) { |
||||
|
$result[] = $options[$v]; |
||||
|
} |
||||
|
} |
||||
|
if ($type == false) { |
||||
|
$result = implode(" ", $result); |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,229 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | CMS前台会员相关业务处理 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | DATETIME: 2019/03/28 |
||||
|
* '::::::::::::' |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\service; |
||||
|
|
||||
|
use think\facade\Request; |
||||
|
use think\facade\Session; |
||||
|
|
||||
|
class User |
||||
|
{ |
||||
|
/** |
||||
|
* 获取用户信息 |
||||
|
* @param int $userId 用户ID |
||||
|
* @return array|null|\think\Model |
||||
|
*/ |
||||
|
public function getUser(int $userId) |
||||
|
{ |
||||
|
$user = \app\common\model\Users::find($userId); |
||||
|
if ($user) { |
||||
|
$user->type_name = $user->UsersType['name']; |
||||
|
} |
||||
|
return $user; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 登录校验 |
||||
|
* @param string $username 用户名或邮箱 |
||||
|
* @param string $password 密码 |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function login(string $username, string $password) |
||||
|
{ |
||||
|
$user = \app\common\model\Users::where('email|mobile',$username) |
||||
|
->where('password',md5($password)) |
||||
|
->find(); |
||||
|
if (empty($user)) { |
||||
|
return [ |
||||
|
'error' => 1, |
||||
|
'msg' => '帐号或密码错误', |
||||
|
]; |
||||
|
} else { |
||||
|
if ($user['status'] == 1) { |
||||
|
Session::set('user',[ |
||||
|
'id' =>$user['id'], |
||||
|
'email' => $user['email'], |
||||
|
'type_id' => $user['type_id'], |
||||
|
'status' => $user['status'], |
||||
|
]); |
||||
|
// 更新信息 |
||||
|
$user->last_login_time = time(); |
||||
|
$user->last_login_ip = Request::ip(); |
||||
|
$user->save(); |
||||
|
return [ |
||||
|
'error' => 0, |
||||
|
'msg' => '登录成功', |
||||
|
]; |
||||
|
} else { |
||||
|
return [ |
||||
|
'error' => 1, |
||||
|
'msg' => '用户已被禁用', |
||||
|
]; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 注册用户 |
||||
|
* @param string $username 邮箱 |
||||
|
* @param string $password 密码 |
||||
|
* @param string $password2 确认密码 |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function register(string $username, string $password, string $password2) |
||||
|
{ |
||||
|
// 密码长度不能低于6位 |
||||
|
if (strlen($password) < 6) { |
||||
|
return [ |
||||
|
'error' => 1, |
||||
|
'msg' => '密码长度不能低于6位', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
// 邮箱合法性判断 |
||||
|
if (!is_email($username)) { |
||||
|
return [ |
||||
|
'error' => 1, |
||||
|
'msg' => '邮箱格式错误', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
// 确认密码 |
||||
|
if ($password != $password2) { |
||||
|
return [ |
||||
|
'error' => 1, |
||||
|
'msg' => '两次密码输入不一致', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
// 防止重复 |
||||
|
$count = \app\common\model\Users::where('email|mobile','=',$username)->count(); |
||||
|
if ($count) { |
||||
|
return [ |
||||
|
'error' => 1, |
||||
|
'msg' => '邮箱已被注册', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
// 注册 |
||||
|
$data = []; |
||||
|
$data['email'] = $username; |
||||
|
$data['password'] = md5($password); |
||||
|
$data['last_login_time'] = $data['create_time'] = time(); |
||||
|
$data['create_ip'] = $data['last_login_ip'] = Request::ip(); |
||||
|
$data['status'] = 1; |
||||
|
$data['type_id'] = 1; |
||||
|
$data['sex'] = Request::post('sex') ? Request::post('sex') : 0; |
||||
|
$user = \app\common\model\Users::create($data); |
||||
|
if ($user->id) { |
||||
|
return [ |
||||
|
'error' => 0, |
||||
|
'msg' => '注册成功', |
||||
|
]; |
||||
|
} else { |
||||
|
return [ |
||||
|
'error' => 1, |
||||
|
'msg' => '注册失败', |
||||
|
]; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 修改密码 |
||||
|
* @param int $userId 用户ID |
||||
|
* @param string $oldPassword 原密码 |
||||
|
* @param string $newPassword 新密码 |
||||
|
* @param string $confirmPassword 确认密码 |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function changePassword(int $userId, string $oldPassword, string $newPassword, string $confirmPassword) |
||||
|
{ |
||||
|
// 密码长度不能低于6位 |
||||
|
if (strlen($newPassword)<6) { |
||||
|
return [ |
||||
|
'error' => 1, |
||||
|
'msg' => '密码长度不能低于6位', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
// 校验原密码 |
||||
|
$user = \app\common\model\Users::where('id', $userId) |
||||
|
->where('password', md5(trim($oldPassword))) |
||||
|
->find(); |
||||
|
if (!$user) { |
||||
|
return [ |
||||
|
'error' => 1, |
||||
|
'msg' => '原密码输入有误', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
// 确认密码 |
||||
|
if ($newPassword != $confirmPassword) { |
||||
|
return [ |
||||
|
'error' => 1, |
||||
|
'msg' => '两次输入的密码不一致', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
// 更改密码 |
||||
|
$user->password = md5($newPassword); |
||||
|
$user->save(); |
||||
|
return [ |
||||
|
'error' => 0, |
||||
|
'msg' => '密码修改成功', |
||||
|
]; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 修改用户信息 |
||||
|
* @param int $userId |
||||
|
*/ |
||||
|
public function changeInfo(int $userId) |
||||
|
{ |
||||
|
$data = [ |
||||
|
'sex' => Request::param('sex'), |
||||
|
'qq' => Request::param('qq'), |
||||
|
'mobile' => Request::param('mobile'), |
||||
|
]; |
||||
|
// 手机唯一性校验 |
||||
|
if ($data['mobile']) { |
||||
|
$count = \app\common\model\Users::where('mobile', $data['mobile']) |
||||
|
->where('id', '<>', $userId) |
||||
|
->find(); |
||||
|
if ($count) { |
||||
|
return [ |
||||
|
'error' => 1, |
||||
|
'msg' => '手机号已存在', |
||||
|
]; |
||||
|
} |
||||
|
} |
||||
|
\app\common\model\Users::update($data, ['id' => $userId]); |
||||
|
return [ |
||||
|
'error' => 0, |
||||
|
'msg' => '修改成功', |
||||
|
]; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,392 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* | 自定义标签 |
||||
|
* +---------------------------------------------------------------------- |
||||
|
* .::::. |
||||
|
* .::::::::. | AUTHOR: siyu |
||||
|
* ::::::::::: | EMAIL: 407593529@qq.com |
||||
|
* ..:::::::::::' | QQ: 407593529 |
||||
|
* '::::::::::::' | DATETIME: 2019/03/28 |
||||
|
* .:::::::::: |
||||
|
* '::::::::::::::.. |
||||
|
* ..::::::::::::. |
||||
|
* ``:::::::::::::::: |
||||
|
* ::::``:::::::::' .:::. |
||||
|
* ::::' ':::::' .::::::::. |
||||
|
* .::::' :::: .:::::::'::::. |
||||
|
* .:::' ::::: .:::::::::' ':::::. |
||||
|
* .::' :::::.:::::::::' ':::::. |
||||
|
* .::' ::::::::::::::' ``::::. |
||||
|
* ...::: ::::::::::::' ``::. |
||||
|
* ```` ':. ':::::::::' ::::.. |
||||
|
* '.:::::' ':'````.. |
||||
|
* +---------------------------------------------------------------------- |
||||
|
*/ |
||||
|
namespace app\common\taglib; |
||||
|
|
||||
|
use think\template\TagLib; |
||||
|
|
||||
|
class Tp extends TagLib { |
||||
|
|
||||
|
protected $tags = array( |
||||
|
// 标签定义: attr 属性列表 close 是否闭合(0 或者1 默认1) alias 标签别名 level 嵌套层次 |
||||
|
'close' => ['attr' => 'time,format', 'close' => 0], // 闭合标签,默认为不闭合 |
||||
|
'open' => ['attr' => 'name,type', 'close' => 1], |
||||
|
'nav' => ['attr' => 'id,limit,name', 'close' => 1], // 通用导航信息 |
||||
|
'cate' => ['attr' => 'id,type,anchor','close' => 0], // 通用栏目信息 |
||||
|
'position' => ['attr' => 'name','close' => 1], // 通用位置信息 |
||||
|
'link' => ['attr' => 'name','close' => 1], // 获取友情链接 |
||||
|
'ad' => ['attr' => 'name,id','close' => 1], // 获取广告信息 |
||||
|
'debris' => ['attr' => 'name,type','close' => 0], // 获取碎片信息 |
||||
|
'list' => ['attr' => 'id,name,pagesize,where,search,limit,order','close' => 1], // 通用列表 |
||||
|
'search' => ['attr' => 'search,table,name,pagesize,where,order','close' => 1], // 通用搜索 |
||||
|
'tag' => ['attr' => 'name,pagesize,order','close' => 1], // 通用标签 |
||||
|
'prev' => ['attr' => 'len','close' => 0], // 上一篇 |
||||
|
'next' => ['attr' => 'len','close' => 0], // 下一篇 |
||||
|
'dict' => ['attr' => 'name,dict_type,field,all','close' => 1], // 获取字典类型 |
||||
|
); |
||||
|
|
||||
|
// 这是一个闭合标签的简单演示 |
||||
|
public function tagClose($tag) |
||||
|
{ |
||||
|
$format = empty($tag['format']) ? 'Y-m-d H:i:s' : $tag['format']; |
||||
|
$time = empty($tag['time']) ? time() : $tag['time']; |
||||
|
$parse = '<?php '; |
||||
|
$parse .= 'echo date("' . $format . '",' . $time . ');'; |
||||
|
$parse .= ' ?>'; |
||||
|
return $parse; |
||||
|
} |
||||
|
|
||||
|
// 这是一个非闭合标签的简单演示 |
||||
|
public function tagOpen($tag, $content) |
||||
|
{ |
||||
|
$type = empty($tag['type']) ? 0 : 1; // 这个type目的是为了区分类型,一般来源是数据库 |
||||
|
$name = $tag['name']; // name是必填项,这里不做判断了 |
||||
|
$parse = '<?php '; |
||||
|
$parse .= '$test_arr=[[1,3,5,7,9],[2,4,6,8,10]];'; // 这里是模拟数据 |
||||
|
$parse .= '$__LIST__ = $test_arr[' . $type . '];'; |
||||
|
$parse .= ' ?>'; |
||||
|
$parse .= '{volist name="__LIST__" id="' . $name . '"}'; |
||||
|
$parse .= $content; |
||||
|
$parse .= '{/volist}'; |
||||
|
return $parse; |
||||
|
} |
||||
|
|
||||
|
// 通用导航信息 |
||||
|
Public function tagNav($tag, $content) |
||||
|
{ |
||||
|
$tag['limit'] = $tag['limit'] ?? '0'; |
||||
|
$tag['id'] = $tag['id'] ?? ''; |
||||
|
$name = $tag['name'] ?? 'nav'; |
||||
|
if (!empty($tag['id'])) { |
||||
|
$cateStr = '$__CATE__ = \app\common\model\Cate::where(\'is_menu\',1)->order(\'sort ASC,id DESC\')->select();'; |
||||
|
$cateStr .= '$__LIST__ = getChildsOn($__CATE__,' . $tag['id'] . ');'; |
||||
|
} else { |
||||
|
$cateStr = '$__CATE__ = \app\common\model\Cate::where(\'is_menu\',1)->order(\'sort ASC,id DESC\')->select();'; |
||||
|
$cateStr .= '$__LIST__ = unlimitedForLayer($__CATE__);'; |
||||
|
} |
||||
|
// 提取前N条数据,因为sql的LIMIT避免不了子栏目的问题 |
||||
|
if (!empty($tag['limit'])) { |
||||
|
$cateStr .= '$__LIST__ = array_slice($__LIST__, 0,' . $tag['limit'] . ');'; |
||||
|
} |
||||
|
$parse = '<?php '; |
||||
|
$parse .= $cateStr; |
||||
|
$parse .= ' ?>'; |
||||
|
$parse .= '{volist name="__LIST__" id="' . $name . '"}'; |
||||
|
$parse .= $content; |
||||
|
$parse .= '{/volist}'; |
||||
|
return $parse; |
||||
|
} |
||||
|
|
||||
|
// 通用栏目信息 |
||||
|
Public function tagCate($tag) |
||||
|
{ |
||||
|
$id = $tag['id'] ?? getCateId(); |
||||
|
$type = $tag['type'] ?? 'cate_name'; |
||||
|
$anchor = $tag['anchor'] ?? ''; |
||||
|
|
||||
|
$str = '<?php '; |
||||
|
$str .= '$__CATE__ = \app\common\model\Cate::where("id",' . $id . ')->find();'; |
||||
|
$str .= 'if ($__CATE__) { '; |
||||
|
$str .= '$__CATE__->url = getUrl($__CATE__->toArray());'; |
||||
|
$str .= ' |
||||
|
if (!empty(\'' . $anchor . '\')) { |
||||
|
$__CATE__->url = $__CATE__->url . \'' . $anchor . '\'; |
||||
|
}'; |
||||
|
$str .= 'echo $__CATE__[\'' . $type . '\'];'; |
||||
|
$str .= '}'; |
||||
|
$str .= '?>'; |
||||
|
return $str; |
||||
|
} |
||||
|
|
||||
|
// 通用位置信息 |
||||
|
Public function tagPosition($tag, $content) |
||||
|
{ |
||||
|
$name = $tag['name'] ? $tag['name'] : 'position'; |
||||
|
$parse = '<?php '; |
||||
|
$parse .= '$__CATE__ = \app\common\model\Cate::select();'; |
||||
|
$parse .= '$__CATEID__ = getCateId();'; |
||||
|
$parse .= '$__LIST__ = getParents($__CATE__,$__CATEID__);'; |
||||
|
$parse .= ' ?>'; |
||||
|
$parse .= '{volist name="__LIST__" id="' . $name . '"}'; |
||||
|
$parse .= '<?php $' . $name . '[\'url\']=getUrl( $' . $name . '); ?>'; |
||||
|
$parse .= $content; |
||||
|
$parse .= '{/volist}'; |
||||
|
return $parse; |
||||
|
} |
||||
|
|
||||
|
// 获取友情链接 |
||||
|
Public function tagLink($tag, $content) |
||||
|
{ |
||||
|
$name = $tag['name'] ? $tag['name'] : 'link'; |
||||
|
$parse = '<?php '; |
||||
|
$parse .= '$__LIST__ = \app\common\model\Link::where(\'status\',1)->order(\'sort asc,id desc\')->select();'; |
||||
|
$parse .= ' ?>'; |
||||
|
$parse .= '{volist name="__LIST__" id="' . $name . '"}'; |
||||
|
$parse .= $content; |
||||
|
$parse .= '{/volist}'; |
||||
|
return $parse; |
||||
|
} |
||||
|
|
||||
|
// 获取广告信息 |
||||
|
Public function tagAd($tag, $content) |
||||
|
{ |
||||
|
$name = $tag['name'] ?? 'ad'; |
||||
|
$id = $tag['id'] ?? ''; |
||||
|
$parse = '<?php '; |
||||
|
$parse .= ' |
||||
|
$__WHERE__ = []; |
||||
|
$__WHERE__[] = [\'status\', \'=\', 1]; |
||||
|
if (!empty(\'' . $id . '\')) { |
||||
|
$__WHERE__[] = [\'type_id\', \'=\', ' . $id . ']; |
||||
|
}'; |
||||
|
$parse .= ' |
||||
|
$__LIST__ = \app\common\model\Ad::where($__WHERE__)->order(\'sort asc,id desc\')->select();'; |
||||
|
$parse .= ' ?>'; |
||||
|
$parse .= '{volist name="__LIST__" id="' . $name . '"}'; |
||||
|
$parse .= $content; |
||||
|
$parse .= '{/volist}'; |
||||
|
return $parse; |
||||
|
} |
||||
|
|
||||
|
// 通用碎片信息 |
||||
|
Public function tagDebris($tag) |
||||
|
{ |
||||
|
$name = $tag['name'] ?? ''; |
||||
|
$type = $tag['type'] ?? ''; |
||||
|
$str = '<?php '; |
||||
|
$str .= 'echo \app\common\model\Debris::where("name",\'' . $name . '\')->where("status", 1)->value("' . $type . '");'; |
||||
|
$str .= '?>'; |
||||
|
return $str; |
||||
|
} |
||||
|
|
||||
|
// 通用列表 |
||||
|
Public function tagList($tag, $content) |
||||
|
{ |
||||
|
$id = $tag['id'] ?? '0'; // 可以为空 |
||||
|
$name = $tag['name'] ?? "list"; // 不可为空 |
||||
|
$order = $tag['order'] ?? 'sort ASC,id DESC'; // 排序 |
||||
|
$limit = $tag['limit'] ?? '0'; // 多少条数据,传递时不再进行分页 |
||||
|
$search = $tag['search'] ?? ''; // 分类筛选字段,通过,或|传递多个 |
||||
|
|
||||
|
$where = isset($tag['where']) ? $tag['where'] . ' AND status = 1 ' : ' status = 1 '; // 查询条件 |
||||
|
$pageSize = $tag['pagesize'] ?? config('app.page_size'); // 每页数量 |
||||
|
$parse = '<?php '; |
||||
|
$parse .= ' |
||||
|
$list = []; |
||||
|
$__CATEID__ = '.$id.' ? '.$id.' : getCateId(); |
||||
|
$__CATE__ = \app\common\model\Cate::find($__CATEID__); |
||||
|
$__SEARCH__ = getSearchField(\'' . $search . '\'); |
||||
|
// 查询子分类,列表要包含子分类内容 |
||||
|
$__ALLCATE__ = \app\common\model\Cate::field(\'id,parent_id\')->select()->toArray(); |
||||
|
$__IDS__ = getChildsIdStr(getChildsId($__ALLCATE__,$__CATEID__),$__CATEID__); |
||||
|
// 表名称为空时(id不存在)直接返回空数组 |
||||
|
if ($__CATE__ && !empty($__CATE__->module->getData(\'table_name\'))) { |
||||
|
$__MODEL__ = \'\app\common\model\\\\\' . $__CATE__->module->getData(\'model_name\'); |
||||
|
// 当传递limit时,不再进行分页 |
||||
|
if(' . $limit . ' != 0){ |
||||
|
$__LIST__ = $__MODEL__::where("' . $where . '" . $__SEARCH__) |
||||
|
->where(\'cate_id\', \'in\', $__IDS__) |
||||
|
->field($__CATE__->module->getData(\'list_fields\')) |
||||
|
->order(\'' . $order . '\') |
||||
|
->limit(\'' . $limit . '\') |
||||
|
->select(); |
||||
|
$page = \'\'; |
||||
|
}else{ |
||||
|
$__PAGESIZE__ = empty($__CATE__[\'page_size\'])?' . $pageSize . ':$__CATE__->page_size; |
||||
|
$__LIST__ = $__MODEL__::where("' . $where . '" . $__SEARCH__) |
||||
|
->where(\'cate_id\', \'in\', $__IDS__) |
||||
|
->field($__CATE__->module->getData(\'list_fields\')) |
||||
|
->order(\'' . $order . '\') |
||||
|
->paginate([ |
||||
|
\'query\' => request()->param(), |
||||
|
\'list_rows\' => $__PAGESIZE__, |
||||
|
]); |
||||
|
$page = $__LIST__->render(); |
||||
|
} |
||||
|
// 处理数据(把列表中需要处理的字段转换成数组和对应的值) |
||||
|
$__LIST__ = changeFields($__LIST__, $__CATE__->module_id); |
||||
|
}else{ |
||||
|
$__LIST__ = []; |
||||
|
} |
||||
|
'; |
||||
|
$parse .= ' ?>'; |
||||
|
$parse .= '{volist name="__LIST__" id="' . $name . '"}'; |
||||
|
$parse .= $content; |
||||
|
$parse .= '{/volist}'; |
||||
|
return $parse; |
||||
|
} |
||||
|
|
||||
|
// 通用搜索 |
||||
|
Public function tagSearch($tag, $content) |
||||
|
{ |
||||
|
$search = $tag['search'] ?? ""; // 关键字 |
||||
|
$table = $tag['table'] ?? "article"; // 表名称 |
||||
|
$name = $tag['name'] ?? "list"; // 不可为空 |
||||
|
$order = $tag['order'] ?? 'sort ASC,id DESC'; // 排序 |
||||
|
$where = isset($tag['where']) ? $tag['where'] . ' AND status = 1 ' : 'status = 1'; // 查询条件 |
||||
|
$pagesize = $tag['pagesize'] ?? config('app.page_size'); // 分页条数 |
||||
|
|
||||
|
$parse = '<?php '; |
||||
|
$parse .= ' |
||||
|
$__MODULE__ = \app\common\model\Module::where("table_name","' . strtolower($table) . '")->find(); |
||||
|
$__MODEL__ = \'\app\common\model\\\\\' . $__MODULE__->model_name; |
||||
|
|
||||
|
$__LIST__ = $__MODEL__::where("' . $where . '") |
||||
|
->where("title", "like", "%' . $search . '%") |
||||
|
->order("' . $order . '") |
||||
|
->paginate([ |
||||
|
\'query\' => request()->param(), |
||||
|
\'list_rows\' => "' . $pagesize . '", |
||||
|
]); |
||||
|
$page = $__LIST__->render(); |
||||
|
|
||||
|
//处理数据(把列表中需要处理的字段转换成数组和对应的值) |
||||
|
$__LIST__ = changeFields($__LIST__,$__MODULE__->id); |
||||
|
'; |
||||
|
$parse .= ' ?>'; |
||||
|
$parse .= '{volist name="__LIST__" id="' . $name . '"}'; |
||||
|
$parse .= $content; |
||||
|
$parse .= '{/volist}'; |
||||
|
return $parse; |
||||
|
} |
||||
|
|
||||
|
// 通用TAG标签 |
||||
|
Public function tagTag($tag, $content) |
||||
|
{ |
||||
|
$name = $tag['name'] ?? "list"; //不可为空 |
||||
|
$order = $tag['order'] ?? 'sort ASC,id DESC'; //排序 |
||||
|
$pagesize = $tag['pagesize'] ?? config('app.page_size'); //分页条数 |
||||
|
|
||||
|
$parse = '<?php '; |
||||
|
$parse .= ' |
||||
|
// 获取模型ID |
||||
|
$__MODULEID__ = request()->param(\'module\'); |
||||
|
// 获取搜索词 |
||||
|
$__T__ = request()->param(\'t\'); |
||||
|
// 查询模型 |
||||
|
$__MODULE__ = \app\common\model\Module::find($__MODULEID__); |
||||
|
// 查询tag字段名称 |
||||
|
$__TAGFIELD__ = \app\common\model\Field::where(\'module_id\', $__MODULEID__) |
||||
|
->where(\'type\', \'tag\') |
||||
|
->value(\'field\'); |
||||
|
// 当前模型 |
||||
|
$__MODEL__ = \'\app\common\model\\\\\' . $__MODULE__->model_name; |
||||
|
$__LIST__ = $__MODEL__::where($__TAGFIELD__, "find in set", $__T__) |
||||
|
->order("' . $order . '") |
||||
|
->paginate("' . $pagesize . '"); |
||||
|
$page = $__LIST__->render(); |
||||
|
|
||||
|
// 处理数据(把列表中需要处理的字段转换成数组和对应的值) |
||||
|
$__LIST__ = changeFields($__LIST__,$__MODULEID__); |
||||
|
'; |
||||
|
$parse .= ' ?>'; |
||||
|
$parse .= '{volist name="__LIST__" id="' . $name . '"}'; |
||||
|
$parse .= $content; |
||||
|
$parse .= '{/volist}'; |
||||
|
return $parse; |
||||
|
} |
||||
|
|
||||
|
// 详情上一篇 |
||||
|
Public function tagPrev($tag) |
||||
|
{ |
||||
|
$len = $tag['len'] ?: '500'; |
||||
|
$str = '<?php '; |
||||
|
$str .= ' |
||||
|
$__CATEID__ = getCateId(); |
||||
|
$__CATE__ = \app\common\model\Cate::find($__CATEID__); |
||||
|
$__MODEL__ = \'\app\common\model\\\\\' . $__CATE__->module->getData(\'model_name\'); |
||||
|
$__PREV__ = $__MODEL__::where(\'cate_id\',$__CATEID__) |
||||
|
->where(\'id\',\'<\',input(\'id\')) |
||||
|
->where(\'status\',\'=\',1) |
||||
|
->field(\'id,cate_id,title\') |
||||
|
->order(\'sort ASC,id DESC\') |
||||
|
->find(); |
||||
|
if($__PREV__){ |
||||
|
//处理字数 |
||||
|
if(' . $len . '<>500){ |
||||
|
$__PREV__[\'title\'] = mb_substr($__PREV__[\'title\'],0,' . $len . '); |
||||
|
} |
||||
|
//处理上一篇中的URL |
||||
|
$__PREV__[\'url\'] = getShowUrl($__PREV__); |
||||
|
$__PREV__ = "<a class=\"prev\" title=\" ".$__PREV__[\'title\']." \" href=\" ".$__PREV__[\'url\']." \">".$__PREV__[\'title\']."</a>"; |
||||
|
}else{ |
||||
|
$__PREV__ = "<a class=\"prev_no\" href=\"javascript:;\">暂无数据</a>"; |
||||
|
} |
||||
|
echo $__PREV__; |
||||
|
'; |
||||
|
$str .= '?>'; |
||||
|
return $str; |
||||
|
} |
||||
|
|
||||
|
// 详情下一篇 |
||||
|
Public function tagNext($tag) |
||||
|
{ |
||||
|
$len = $tag['len'] ?: '500'; |
||||
|
$str = '<?php '; |
||||
|
$str .= ' |
||||
|
$__CATEID__ = getCateId(); |
||||
|
$__CATE__ = \app\common\model\Cate::find($__CATEID__); |
||||
|
$__MODEL__ = \'\app\common\model\\\\\' . $__CATE__->module->getData(\'model_name\'); |
||||
|
$__PREV__ = $__MODEL__::where(\'cate_id\',$__CATEID__) |
||||
|
->where(\'id\',\'>\',input(\'id\')) |
||||
|
->where(\'status\',\'=\',1) |
||||
|
->field(\'id,cate_id,title\') |
||||
|
->order(\'sort ASC,id DESC\') |
||||
|
->find(); |
||||
|
if($__PREV__){ |
||||
|
//处理字数 |
||||
|
if(' . $len . '<>500){ |
||||
|
$__PREV__[\'title\'] = mb_substr($__PREV__[\'title\'],0,' . $len . '); |
||||
|
} |
||||
|
//处理上一篇中的URL |
||||
|
$__PREV__[\'url\'] = getShowUrl($__PREV__); |
||||
|
$__PREV__ = "<a class=\"prev\" title=\" ".$__PREV__[\'title\']." \" href=\" ".$__PREV__[\'url\']." \">".$__PREV__[\'title\']."</a>"; |
||||
|
}else{ |
||||
|
$__PREV__ = "<a class=\"prev_no\" href=\"javascript:;\">暂无数据</a>"; |
||||
|
} |
||||
|
echo $__PREV__; |
||||
|
'; |
||||
|
$str .= '?>'; |
||||
|
return $str; |
||||
|
} |
||||
|
|
||||
|
// 字典类型 |
||||
|
Public function tagDict($tag, $content) |
||||
|
{ |
||||
|
$name = $tag['name'] ?? 'dictionary'; |
||||
|
$dictType = $tag['dict_type'] ?? 0; |
||||
|
$field = $tag['field'] ?? 'type'; |
||||
|
$all = $tag['all'] ?? '全部'; |
||||
|
$parse = '<?php '; |
||||
|
$parse .= '$__DICTS__ = \app\common\model\Dictionary::where(\'status\',1)->where(\'dict_type\',' . $dictType . ')->order(\'sort ASC,id desc\')->select()->toArray(); |
||||
|
$__DICTS__ = changeDict($__DICTS__, \'' . $field . '\', \'' . $all . '\'); |
||||
|
'; |
||||
|
$parse .= ' ?>'; |
||||
|
$parse .= '{volist name="__DICTS__" id="' . $name . '"}'; |
||||
|
$parse .= $content; |
||||
|
$parse .= '{/volist}'; |
||||
|
return $parse; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,59 @@ |
|||||
|
{__NOLAYOUT__}<!DOCTYPE html> |
||||
|
<html> |
||||
|
<head> |
||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||
|
<title>跳转提示</title> |
||||
|
<style type="text/css"> |
||||
|
*{box-sizing:border-box;margin:0;padding:0;font-family:Lantinghei SC,Open Sans,Arial,Hiragino Sans GB,Microsoft YaHei,"微软雅黑",STHeiti,WenQuanYi Micro Hei,SimSun,sans-serif;-webkit-font-smoothing:antialiased} |
||||
|
body{padding:70px 0;background:#edf1f4;font-weight:400;font-size:1pc;-webkit-text-size-adjust:none;color:#333} |
||||
|
a{outline:0;color:#3498db;text-decoration:none;cursor:pointer} |
||||
|
.system-message{margin:20px 5%;padding:40px 20px;background:#fff;box-shadow:1px 1px 1px hsla(0,0%,39%,.1);text-align:center} |
||||
|
.system-message h1{margin:0;margin-bottom:9pt;color:#444;font-weight:400;font-size:40px} |
||||
|
.system-message .jump,.system-message .image{margin:20px 0;padding:0;padding:10px 0;font-weight:400} |
||||
|
.system-message .jump{font-size:14px} |
||||
|
.system-message .jump a{color:#333} |
||||
|
.system-message p{font-size:9pt;line-height:20px} |
||||
|
.system-message .btn{display:inline-block;margin-right:10px;width:138px;height:2pc;border:1px solid #44a0e8;border-radius:30px;color:#44a0e8;text-align:center;font-size:1pc;line-height:2pc;margin-bottom:5px;} |
||||
|
.success .btn{border-color:#69bf4e;color:#69bf4e} |
||||
|
.error .btn{border-color:#ff8992;color:#ff8992} |
||||
|
.info .btn{border-color:#3498db;color:#3498db} |
||||
|
.copyright p{width:100%;color:#919191;text-align:center;font-size:10px} |
||||
|
.system-message .btn-grey{border-color:#bbb;color:#bbb} |
||||
|
.clearfix:after{clear:both;display:block;visibility:hidden;height:0;content:"."} |
||||
|
@media (max-width:768px){body {padding:20px 0;}} |
||||
|
@media (max-width:480px){.system-message h1{font-size:30px;}} |
||||
|
</style> |
||||
|
</head> |
||||
|
<body> |
||||
|
<?php |
||||
|
$codeText = $code == 1 ? 'success' : ($code == 0 ? 'error' : 'info'); |
||||
|
?> |
||||
|
<div class="system-message {$codeText}"> |
||||
|
<div class="image"> |
||||
|
<img src="/static/common/images/{$codeText}.svg" alt="" width="150" /> |
||||
|
</div> |
||||
|
<h1><?php echo(strip_tags($msg));?></h1> |
||||
|
<p class="jump"> |
||||
|
页面将在 <span id="wait"><?php echo($wait);?></span> 秒后自动跳转 |
||||
|
</p> |
||||
|
<p class="clearfix"> |
||||
|
<a href="#" onClick="javascript :history.back(-1);" class="btn btn-grey">返回上一页</a> |
||||
|
<a id="href" href="{$url}" class="btn btn-primary">立即跳转</a> |
||||
|
</p> |
||||
|
</div> |
||||
|
<script type="text/javascript"> |
||||
|
(function(){ |
||||
|
var wait = document.getElementById('wait'), |
||||
|
href = document.getElementById('href').href; |
||||
|
var interval = setInterval(function(){ |
||||
|
var time = --wait.innerHTML; |
||||
|
if(time <= 0) { |
||||
|
location.href = href; |
||||
|
clearInterval(interval); |
||||
|
}; |
||||
|
}, 1000); |
||||
|
})(); |
||||
|
</script> |
||||
|
</body> |
||||
|
</html> |
||||
@ -0,0 +1,17 @@ |
|||||
|
<?php |
||||
|
// 事件定义文件 |
||||
|
return [ |
||||
|
'bind' => [ |
||||
|
], |
||||
|
|
||||
|
'listen' => [ |
||||
|
'AppInit' => [], |
||||
|
'HttpRun' => [], |
||||
|
'HttpEnd' => [], |
||||
|
'LogLevel' => [], |
||||
|
'LogWrite' => [], |
||||
|
], |
||||
|
|
||||
|
'subscribe' => [ |
||||
|
], |
||||
|
]; |
||||
@ -0,0 +1,15 @@ |
|||||
|
<?php |
||||
|
// 全局中间件定义文件 |
||||
|
return [ |
||||
|
// 全局请求缓存 |
||||
|
// \think\middleware\CheckRequestCache::class, |
||||
|
// 多语言加载 |
||||
|
// \think\middleware\LoadLangPack::class, |
||||
|
// Session初始化 |
||||
|
[ |
||||
|
\think\middleware\AllowCrossDomain::class, |
||||
|
[ |
||||
|
['Access-Control-Allow-Headers' => '*'] |
||||
|
] |
||||
|
] |
||||
|
]; |
||||
@ -0,0 +1,9 @@ |
|||||
|
<?php |
||||
|
use app\ExceptionHandle; |
||||
|
use app\Request; |
||||
|
|
||||
|
// 容器Provider定义文件 |
||||
|
return [ |
||||
|
'think\Request' => Request::class, |
||||
|
'think\exception\Handle' => ExceptionHandle::class, |
||||
|
]; |
||||
@ -0,0 +1,9 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use app\AppService; |
||||
|
|
||||
|
// 系统服务定义文件 |
||||
|
// 服务在完成全局初始化之后执行 |
||||
|
return [ |
||||
|
AppService::class, |
||||
|
]; |
||||
@ -0,0 +1,26 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ] |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved. |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: liu21st <liu21st@gmail.com> |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
/** |
||||
|
* php think build 自动生成应用的目录结构的定义示例 |
||||
|
*/ |
||||
|
return [ |
||||
|
// 需要自动创建的文件 |
||||
|
'__file__' => [], |
||||
|
// 需要自动创建的目录 |
||||
|
'__dir__' => ['controller', 'model', 'view'], |
||||
|
// 需要自动创建的控制器 |
||||
|
'controller' => ['Index'], |
||||
|
// 需要自动创建的模型 |
||||
|
'model' => ['User'], |
||||
|
// 需要自动创建的模板 |
||||
|
'view' => ['index/index'], |
||||
|
]; |
||||
@ -0,0 +1,52 @@ |
|||||
|
{ |
||||
|
"name": "topthink/think", |
||||
|
"description": "the new thinkphp framework", |
||||
|
"type": "project", |
||||
|
"keywords": [ |
||||
|
"framework", |
||||
|
"thinkphp", |
||||
|
"ORM" |
||||
|
], |
||||
|
"homepage": "http://thinkphp.cn/", |
||||
|
"license": "Apache-2.0", |
||||
|
"authors": [ |
||||
|
{ |
||||
|
"name": "liu21st", |
||||
|
"email": "liu21st@gmail.com" |
||||
|
} |
||||
|
], |
||||
|
"require": { |
||||
|
"php": ">=7.1.0", |
||||
|
"topthink/framework": "6.0.*", |
||||
|
"topthink/think-orm": "2.0.*", |
||||
|
"topthink/think-view": "^1.0", |
||||
|
"phpmailer/phpmailer": "^6.0", |
||||
|
"phpoffice/phpspreadsheet": "^1.8", |
||||
|
"tp5er/tp5-databackup": "^1.0", |
||||
|
"topthink/think-captcha": "^3.0", |
||||
|
"lcobucci/jwt": "^3.3", |
||||
|
"topthink/think-multi-app": "^1.0", |
||||
|
"zzstudio/think-addons": "^2.0", |
||||
|
"alibabacloud/client": "^1.5" |
||||
|
}, |
||||
|
"require-dev": { |
||||
|
"symfony/var-dumper": "^4.2" |
||||
|
}, |
||||
|
"autoload": { |
||||
|
"psr-4": { |
||||
|
"app\\": "app" |
||||
|
}, |
||||
|
"psr-0": { |
||||
|
"": "extend/" |
||||
|
} |
||||
|
}, |
||||
|
"config": { |
||||
|
"preferred-install": "dist" |
||||
|
}, |
||||
|
"scripts": { |
||||
|
"post-autoload-dump": [ |
||||
|
"@php think service:discover", |
||||
|
"@php think vendor:publish" |
||||
|
] |
||||
|
} |
||||
|
} |
||||
File diff suppressed because it is too large
@ -0,0 +1,23 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | thinkphp6 Addons [ WE CAN DO IT JUST THINK IT ] |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Copyright (c) 2016 http://www.zzstudio.net All rights reserved. |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Byron Sampson <xiaobo.sun@qq.com> |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
return [ |
||||
|
// 是否自动读取取插件钩子配置信息 |
||||
|
'autoload' => true, |
||||
|
// 当关闭自动获取配置时需要手动配置hooks信息 |
||||
|
'hooks' => [ |
||||
|
// 可以定义多个钩子 |
||||
|
'testhook' => 'test' // 键为钩子名称,用于在业务中自定义钩子处理,值为实现该钩子的插件, |
||||
|
// 多个插件可以用数组也可以用逗号分割 |
||||
|
], |
||||
|
'route' => [], |
||||
|
'service' => [], |
||||
|
]; |
||||
@ -0,0 +1,32 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 应用设置 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
return [ |
||||
|
// 应用地址 |
||||
|
'app_host' => env('app.host', ''), |
||||
|
// 应用的命名空间 |
||||
|
'app_namespace' => '', |
||||
|
// 是否启用路由 |
||||
|
'with_route' => true, |
||||
|
// 默认应用 |
||||
|
'default_app' => 'index', |
||||
|
// 默认时区 |
||||
|
'default_timezone' => 'Asia/Shanghai', |
||||
|
|
||||
|
// 应用映射(自动多应用模式有效) |
||||
|
'app_map' => [], |
||||
|
// 域名绑定(自动多应用模式有效) |
||||
|
'domain_bind' => [], |
||||
|
// 禁止URL访问的应用列表(自动多应用模式有效) |
||||
|
'deny_app_list' => [], |
||||
|
|
||||
|
// 异常页面的模板文件 |
||||
|
'exception_tmpl' => app()->getThinkPath() . 'tpl/think_exception.tpl', |
||||
|
|
||||
|
// 错误显示信息,非调试模式有效 |
||||
|
'error_message' => '页面错误!请稍后再试~', |
||||
|
// 显示错误信息 |
||||
|
'show_error_msg' => false, |
||||
|
]; |
||||
@ -0,0 +1,29 @@ |
|||||
|
<?php |
||||
|
|
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 缓存设置 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
return [ |
||||
|
// 默认缓存驱动 |
||||
|
'default' => env('cache.driver', 'file'), |
||||
|
|
||||
|
// 缓存连接方式配置 |
||||
|
'stores' => [ |
||||
|
'file' => [ |
||||
|
// 驱动方式 |
||||
|
'type' => 'File', |
||||
|
// 缓存保存目录 |
||||
|
'path' => '', |
||||
|
// 缓存前缀 |
||||
|
'prefix' => '', |
||||
|
// 缓存有效期 0表示永久缓存 |
||||
|
'expire' => 0, |
||||
|
// 缓存标签前缀 |
||||
|
'tag_prefix' => 'tag:', |
||||
|
// 序列化机制 例如 ['serialize', 'unserialize'] |
||||
|
'serialize' => [], |
||||
|
], |
||||
|
// 更多的缓存连接 |
||||
|
], |
||||
|
]; |
||||
@ -0,0 +1,39 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Captcha配置文件 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
return [ |
||||
|
//验证码位数 |
||||
|
'length' => 5, |
||||
|
// 验证码字符集合 |
||||
|
'codeSet' => '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY', |
||||
|
// 验证码过期时间 |
||||
|
'expire' => 1800, |
||||
|
// 是否使用中文验证码 |
||||
|
'useZh' => false, |
||||
|
// 是否使用算术验证码 |
||||
|
'math' => false, |
||||
|
// 是否使用背景图 |
||||
|
'useImgBg' => false, |
||||
|
//验证码字符大小 |
||||
|
'fontSize' => 25, |
||||
|
// 是否使用混淆曲线 |
||||
|
'useCurve' => true, |
||||
|
//是否添加杂点 |
||||
|
'useNoise' => true, |
||||
|
// 验证码字体 不设置则随机 |
||||
|
'fontttf' => '', |
||||
|
//背景颜色 |
||||
|
'bg' => [243, 251, 254], |
||||
|
// 验证码图片高度 |
||||
|
'imageH' => 0, |
||||
|
// 验证码图片宽度 |
||||
|
'imageW' => 0, |
||||
|
|
||||
|
// 添加额外的验证码设置 |
||||
|
// verify => [ |
||||
|
// 'length'=>4, |
||||
|
// ... |
||||
|
//], |
||||
|
]; |
||||
@ -0,0 +1,13 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 应用设置 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
return [ |
||||
|
'static_image_url' => 'http://static.ahbmz.com/', |
||||
|
'upload_file_ext' => 'jpg,png,gif,jpeg,pdf,rar,zip,avi,rmvb,3gp,flv,mp3,mp4,txt,doc,xls,ppt,pdf,xls,docx,xlsx,doc,pptx', |
||||
|
// 'upload_file_size' => '100000', |
||||
|
'upload_image_ext' => 'jpg,png,gif,jpeg', |
||||
|
'log_image_url' => 'http://api.cms.ahbmz.com/api/UploadLog/add', |
||||
|
// 'upload_image_size' => '10', |
||||
|
]; |
||||
@ -0,0 +1,9 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 控制台配置 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
return [ |
||||
|
// 指令定义 |
||||
|
'commands' => [ |
||||
|
], |
||||
|
]; |
||||
@ -0,0 +1,18 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Cookie设置 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
return [ |
||||
|
// cookie 保存时间 |
||||
|
'expire' => 0, |
||||
|
// cookie 保存路径 |
||||
|
'path' => '/', |
||||
|
// cookie 有效域名 |
||||
|
'domain' => '', |
||||
|
// cookie 启用安全传输 |
||||
|
'secure' => false, |
||||
|
// httponly设置 |
||||
|
'httponly' => false, |
||||
|
// 是否使用 setcookie |
||||
|
'setcookie' => true, |
||||
|
]; |
||||
@ -0,0 +1,62 @@ |
|||||
|
<?php |
||||
|
|
||||
|
return [ |
||||
|
// 默认使用的数据库连接配置 |
||||
|
'default' => env('database.driver', 'mysql'), |
||||
|
|
||||
|
// 自定义时间查询规则 |
||||
|
'time_query_rule' => [], |
||||
|
|
||||
|
// 自动写入时间戳字段 |
||||
|
// true为自动识别类型 false关闭 |
||||
|
// 字符串则明确指定时间字段类型 支持 int timestamp datetime date |
||||
|
'auto_timestamp' => true, |
||||
|
|
||||
|
// 时间字段取出后的默认时间格式 |
||||
|
'datetime_format' => 'Y-m-d H:i:s', |
||||
|
|
||||
|
// 数据库连接配置信息 |
||||
|
'connections' => [ |
||||
|
'mysql' => [ |
||||
|
// 数据库类型 |
||||
|
'type' => env('database.type', 'mysql'), |
||||
|
// 服务器地址 |
||||
|
'hostname' => env('database.hostname', '127.0.0.1'), |
||||
|
// 数据库名 |
||||
|
'database' => env('database.database', 'www.yutian.com'), |
||||
|
// 用户名 |
||||
|
'username' => env('database.username', 'root'), |
||||
|
// 密码 |
||||
|
'password' => env('database.password', '123456'), |
||||
|
// 端口 |
||||
|
'hostport' => env('database.hostport', '3306'), |
||||
|
// 数据库连接参数 |
||||
|
'params' => [], |
||||
|
// 数据库编码默认采用utf8 |
||||
|
'charset' => env('database.charset', 'utf8'), |
||||
|
// 数据库表前缀 |
||||
|
'prefix' => env('database.prefix', ''), |
||||
|
|
||||
|
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) |
||||
|
'deploy' => 0, |
||||
|
// 数据库读写是否分离 主从式有效 |
||||
|
'rw_separate' => false, |
||||
|
// 读写分离后 主服务器数量 |
||||
|
'master_num' => 1, |
||||
|
// 指定从服务器序号 |
||||
|
'slave_no' => '', |
||||
|
// 是否严格检查字段是否存在 |
||||
|
'fields_strict' => true, |
||||
|
// 是否需要断线重连 |
||||
|
'break_reconnect' => false, |
||||
|
// 监听SQL |
||||
|
'trigger_sql' => env('app_debug', true), |
||||
|
// 开启字段缓存 |
||||
|
'fields_cache' => false, |
||||
|
// 字段缓存路径 |
||||
|
'schema_cache_path' => app()->getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR, |
||||
|
], |
||||
|
|
||||
|
// 更多的数据库配置信息 |
||||
|
], |
||||
|
]; |
||||
@ -0,0 +1,24 @@ |
|||||
|
<?php |
||||
|
|
||||
|
return [ |
||||
|
// 默认磁盘 |
||||
|
'default' => env('filesystem.driver', 'local'), |
||||
|
// 磁盘列表 |
||||
|
'disks' => [ |
||||
|
'local' => [ |
||||
|
'type' => 'local', |
||||
|
'root' => app()->getRuntimePath() . 'storage', |
||||
|
], |
||||
|
'public' => [ |
||||
|
// 磁盘类型 |
||||
|
'type' => 'local', |
||||
|
// 磁盘路径 |
||||
|
'root' => app()->getRootPath() . 'public/storage', |
||||
|
// 磁盘路径对应的外部URL路径 |
||||
|
'url' => '/storage', |
||||
|
// 可见性 |
||||
|
'visibility' => 'public', |
||||
|
], |
||||
|
// 更多的磁盘配置信息 |
||||
|
], |
||||
|
]; |
||||
@ -0,0 +1,25 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 多语言设置 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
return [ |
||||
|
// 默认语言 |
||||
|
'default_lang' => env('lang.default_lang', 'zh-cn'), |
||||
|
// 允许的语言列表 |
||||
|
'allow_lang_list' => [], |
||||
|
// 多语言自动侦测变量名 |
||||
|
'detect_var' => 'lang', |
||||
|
// 是否使用Cookie记录 |
||||
|
'use_cookie' => true, |
||||
|
// 多语言cookie变量 |
||||
|
'cookie_var' => 'think_lang', |
||||
|
// 扩展语言包 |
||||
|
'extend_list' => [], |
||||
|
// Accept-Language转义为对应语言包名称 |
||||
|
'accept_language' => [ |
||||
|
'zh-hans-cn' => 'zh-cn', |
||||
|
], |
||||
|
// 是否支持语言分组 |
||||
|
'allow_group' => false, |
||||
|
]; |
||||
@ -0,0 +1,45 @@ |
|||||
|
<?php |
||||
|
|
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 日志设置 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
return [ |
||||
|
// 默认日志记录通道 |
||||
|
'default' => env('log.channel', 'file'), |
||||
|
// 日志记录级别 |
||||
|
'level' => [], |
||||
|
// 日志类型记录的通道 ['error'=>'email',...] |
||||
|
'type_channel' => [], |
||||
|
// 关闭全局日志写入 |
||||
|
'close' => false, |
||||
|
// 全局日志处理 支持闭包 |
||||
|
'processor' => null, |
||||
|
|
||||
|
// 日志通道列表 |
||||
|
'channels' => [ |
||||
|
'file' => [ |
||||
|
// 日志记录方式 |
||||
|
'type' => 'File', |
||||
|
// 日志保存目录 |
||||
|
'path' => '', |
||||
|
// 单文件日志写入 |
||||
|
'single' => false, |
||||
|
// 独立日志级别 |
||||
|
'apart_level' => [], |
||||
|
// 最大日志文件数量 |
||||
|
'max_files' => 0, |
||||
|
// 使用JSON格式记录 |
||||
|
'json' => false, |
||||
|
// 日志处理 |
||||
|
'processor' => null, |
||||
|
// 关闭通道日志写入 |
||||
|
'close' => false, |
||||
|
// 日志输出格式化 |
||||
|
'format' => '[%s][%s] %s', |
||||
|
// 是否实时写入 |
||||
|
'realtime_write' => false, |
||||
|
], |
||||
|
// 其它日志通道配置 |
||||
|
], |
||||
|
|
||||
|
]; |
||||
@ -0,0 +1,8 @@ |
|||||
|
<?php |
||||
|
// 中间件配置 |
||||
|
return [ |
||||
|
// 别名或分组 |
||||
|
'alias' => [], |
||||
|
// 优先级设置,此数组中的中间件会按照数组中的顺序优先执行 |
||||
|
'priority' => [], |
||||
|
]; |
||||
@ -0,0 +1,45 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 路由设置 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
return [ |
||||
|
// pathinfo分隔符 |
||||
|
'pathinfo_depr' => '/', |
||||
|
// URL伪静态后缀 |
||||
|
'url_html_suffix' => 'html', |
||||
|
// URL普通方式参数 用于自动生成 |
||||
|
'url_common_param' => true, |
||||
|
// 是否开启路由延迟解析 |
||||
|
'url_lazy_route' => false, |
||||
|
// 是否强制使用路由 |
||||
|
'url_route_must' => false, |
||||
|
// 合并路由规则 |
||||
|
'route_rule_merge' => false, |
||||
|
// 路由是否完全匹配 |
||||
|
'route_complete_match' => false, |
||||
|
// 访问控制器层名称 |
||||
|
'controller_layer' => 'controller', |
||||
|
// 空控制器名 |
||||
|
'empty_controller' => 'Error', |
||||
|
// 是否使用控制器后缀 |
||||
|
'controller_suffix' => false, |
||||
|
// 默认的路由变量规则 |
||||
|
'default_route_pattern' => '[\w\.]+', |
||||
|
// 是否开启请求缓存 true自动缓存 支持设置请求缓存规则 |
||||
|
'request_cache_key' => false, |
||||
|
// 请求缓存有效期 |
||||
|
'request_cache_expire' => null, |
||||
|
// 全局请求缓存排除规则 |
||||
|
'request_cache_except' => [], |
||||
|
// 默认控制器名 |
||||
|
'default_controller' => 'Index', |
||||
|
// 默认操作名 |
||||
|
'default_action' => 'index', |
||||
|
// 操作方法后缀 |
||||
|
'action_suffix' => '', |
||||
|
// 默认JSONP格式返回的处理方法 |
||||
|
'default_jsonp_handler' => 'jsonpReturn', |
||||
|
// 默认JSONP处理方法 |
||||
|
'var_jsonp_handler' => 'callback', |
||||
|
]; |
||||
@ -0,0 +1,19 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 会话设置 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
return [ |
||||
|
// session name |
||||
|
'name' => 'PHPSESSID', |
||||
|
// SESSION_ID的提交变量,解决flash上传跨域 |
||||
|
'var_session_id' => '', |
||||
|
// 驱动方式 支持file cache |
||||
|
'type' => 'file', |
||||
|
// 存储连接标识 当type使用cache的时候有效 |
||||
|
'store' => null, |
||||
|
// 过期时间 |
||||
|
'expire' => 1440, |
||||
|
// 前缀 |
||||
|
'prefix' => '', |
||||
|
]; |
||||
@ -0,0 +1,10 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Trace设置 开启调试模式后有效 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
return [ |
||||
|
// 内置Html和Console两种方式 支持扩展 |
||||
|
'type' => 'Html', |
||||
|
// 读取的日志通道名 |
||||
|
'channel' => '', |
||||
|
]; |
||||
@ -0,0 +1,25 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 模板设置 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
return [ |
||||
|
// 模板引擎类型使用Think |
||||
|
'type' => 'Think', |
||||
|
// 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法 |
||||
|
'auto_rule' => 1, |
||||
|
// 模板目录名 |
||||
|
'view_dir_name' => 'view', |
||||
|
// 模板后缀 |
||||
|
'view_suffix' => 'html', |
||||
|
// 模板文件名分隔符 |
||||
|
'view_depr' => DIRECTORY_SEPARATOR, |
||||
|
// 模板引擎普通标签开始标记 |
||||
|
'tpl_begin' => '{', |
||||
|
// 模板引擎普通标签结束标记 |
||||
|
'tpl_end' => '}', |
||||
|
// 标签库标签开始标记 |
||||
|
'taglib_begin' => '{', |
||||
|
// 标签库标签结束标记 |
||||
|
'taglib_end' => '}', |
||||
|
]; |
||||
@ -0,0 +1,268 @@ |
|||||
|
<?php |
||||
|
use think\facade\Request; |
||||
|
use think\facade\Session; |
||||
|
use think\facade\Db; |
||||
|
use think\facade\Config; |
||||
|
/** |
||||
|
* 权限认证类 |
||||
|
* 功能特性: |
||||
|
* 1,是对规则进行认证,不是对节点进行认证。用户可以把节点当作规则名称实现对节点进行认证。 |
||||
|
* $auth = new Auth(); |
||||
|
* $auth->check('规则名称', '用户id'); |
||||
|
* |
||||
|
* 2,可以同时对多条规则进行认证,并设置多条规则的关系(or或者and) |
||||
|
* $auth = new Auth(); |
||||
|
* $auth->check('规则1,规则2', '用户id', 'and'); |
||||
|
* 第三个参数为and时表示,用户需要同时具有规则1和规则2的权限。 当第三个参数为or时,表示用户值需要具备其中一个条件即可。默认为or |
||||
|
* 3,一个用户可以属于多个用户组(think_auth_group_access表 定义了用户所属用户组)。我们需要设置每个用户组拥有哪些规则(think_auth_group 定义了用户组权限) |
||||
|
* |
||||
|
* 4,支持规则表达式。 |
||||
|
* 在 think_auth_rule 表中定义一条规则时,如果type为1, condition字段就可以定义规则表达式。 如定义{score}>5 and {score}<100 表示用户的分数在5-100之间时这条规则才会通过。 |
||||
|
*/ |
||||
|
// 数据库 |
||||
|
/* |
||||
|
-- ---------------------------- |
||||
|
-- think_auth_rule,规则表, |
||||
|
-- id:主键,name:规则唯一标识, title:规则中文名称 status 状态:为1正常,为0禁用,condition:规则表达式,为空表示存在就验证,不为空表示按照条件验证 |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `think_auth_rule`; |
||||
|
CREATE TABLE `think_auth_rule` ( |
||||
|
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, |
||||
|
`name` char(80) NOT NULL DEFAULT '', |
||||
|
`title` char(20) NOT NULL DEFAULT '', |
||||
|
`type` tinyint(1) NOT NULL DEFAULT '1', |
||||
|
`status` tinyint(1) NOT NULL DEFAULT '1', |
||||
|
`condition` char(100) NOT NULL DEFAULT '', # 规则附件条件,满足附加条件的规则,才认为是有效的规则 |
||||
|
PRIMARY KEY (`id`), |
||||
|
UNIQUE KEY `name` (`name`) |
||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8; |
||||
|
-- ---------------------------- |
||||
|
-- think_auth_group 用户组表, |
||||
|
-- id:主键, title:用户组中文名称, rules:用户组拥有的规则id, 多个规则","隔开,status 状态:为1正常,为0禁用 |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `think_auth_group`; |
||||
|
CREATE TABLE `think_auth_group` ( |
||||
|
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, |
||||
|
`title` char(100) NOT NULL DEFAULT '', |
||||
|
`status` tinyint(1) NOT NULL DEFAULT '1', |
||||
|
`rules` char(80) NOT NULL DEFAULT '', |
||||
|
PRIMARY KEY (`id`) |
||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8; |
||||
|
-- ---------------------------- |
||||
|
-- think_auth_group_access 用户组明细表 |
||||
|
-- uid:用户id,group_id:用户组id |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `think_auth_group_access`; |
||||
|
CREATE TABLE `think_auth_group_access` ( |
||||
|
`uid` mediumint(8) unsigned NOT NULL, |
||||
|
`group_id` mediumint(8) unsigned NOT NULL, |
||||
|
UNIQUE KEY `uid_group_id` (`uid`,`group_id`), |
||||
|
KEY `uid` (`uid`), |
||||
|
KEY `group_id` (`group_id`) |
||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8; |
||||
|
*/ |
||||
|
class Auth |
||||
|
{ |
||||
|
protected $_config = [ |
||||
|
'auth_on' => true, // 认证开关 |
||||
|
'auth_type' => 1, // 认证方式,1为实时认证;2为登录认证。 |
||||
|
'auth_group' => 'auth_group', // 用户组数据表名 |
||||
|
'auth_group_access' => 'auth_group_access', // 用户-用户组关系表 |
||||
|
'auth_rule' => 'auth_rule', // 权限规则表 |
||||
|
'auth_user' => 'admin', // 用户信息表 |
||||
|
'auth_user_id_field'=> 'id', // 用户表ID字段名 |
||||
|
]; |
||||
|
protected $BreadCrumb = []; |
||||
|
public function __construct() |
||||
|
{ |
||||
|
if (Config::get('app.auth')) { |
||||
|
$this->_config = array_merge($this->_config, Config::get('app.auth')); |
||||
|
} |
||||
|
} |
||||
|
/** |
||||
|
* 检查权限 |
||||
|
* @param string|array $name 需要验证的规则列表,支持逗号分隔的权限规则或索引数组 |
||||
|
* @param integer $uid 认证用户ID |
||||
|
* @param string $relation 如果为 'or' 表示满足任一条规则即通过验证;如果为 'and' 则表示需满足所有规则才能通过验证 |
||||
|
* @param string $mode 执行check的模式 |
||||
|
* @param integer $type 规则类型 |
||||
|
* @return boolean 通过验证返回true;失败返回false |
||||
|
*/ |
||||
|
public function check($name, $uid, $relation = 'or', $mode = 'url', $type = 1) |
||||
|
{ |
||||
|
if (!$this->_config['auth_on']) { |
||||
|
return true; |
||||
|
} |
||||
|
$authList = $this->getAuthList($uid, $type); |
||||
|
if (is_string($name)) { |
||||
|
$name = strtolower($name); |
||||
|
if (strpos($name, ',') !== false) { |
||||
|
$name = explode(',', $name); |
||||
|
} else { |
||||
|
$name = [$name]; |
||||
|
} |
||||
|
} |
||||
|
$list = []; |
||||
|
if ($mode === 'url') { |
||||
|
$REQUEST = unserialize(strtolower(serialize($_REQUEST))); |
||||
|
} |
||||
|
foreach ($authList as $auth) { |
||||
|
|
||||
|
$query = preg_replace('/^.+\?/U', '', $auth); |
||||
|
if ($mode === 'url' && $query != $auth) { |
||||
|
parse_str($query, $param); // 解析规则中的param |
||||
|
$intersect = array_intersect_assoc($REQUEST, $param); |
||||
|
$auth = preg_replace('/\?.*$/U', '', $auth); |
||||
|
if (in_array($auth, $name) && $intersect == $param) { |
||||
|
$list[] = $auth; |
||||
|
} |
||||
|
} elseif (in_array($auth, $name)) { |
||||
|
$list[] = $auth; |
||||
|
} |
||||
|
} |
||||
|
if ($relation === 'or' && !empty($list)) { |
||||
|
return true; |
||||
|
} |
||||
|
$diff = array_diff($name, $list); |
||||
|
if ($relation === 'and' && empty($diff)) { |
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据用户ID获取用户组,返回值为数组 |
||||
|
* @param integer $uid 用户ID |
||||
|
* @return array 用户所属用户组 ['uid'=>'用户ID', 'group_id'=>'用户组ID', 'title'=>'用户组名', 'rules'=>'用户组拥有的规则ID,多个用英文,隔开'] |
||||
|
*/ |
||||
|
public function getGroups($uid) |
||||
|
{ |
||||
|
static $groups = []; |
||||
|
if (isset($groups[$uid])) { |
||||
|
return $groups[$uid]; |
||||
|
} |
||||
|
$user_groups = Db::name($this->_config['auth_group_access']) |
||||
|
->alias('a') |
||||
|
->where('a.uid', $uid) |
||||
|
->where('g.status', 1) |
||||
|
->join($this->_config['auth_group'].' g', "a.group_id = g.id") |
||||
|
->field('uid,group_id,title,rules') |
||||
|
->select(); |
||||
|
$groups[$uid] = $user_groups ?: []; |
||||
|
return $groups[$uid]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获得权限列表 |
||||
|
* @param integer $uid 用户ID |
||||
|
* @param integer $type 规则类型 |
||||
|
* @return array 权限列表 |
||||
|
*/ |
||||
|
protected function getAuthList($uid, $type) |
||||
|
{ |
||||
|
static $_authList = []; |
||||
|
$t = implode(',', (array)$type); |
||||
|
if (isset($_authList[$uid.$t])) { |
||||
|
return $_authList[$uid.$t]; |
||||
|
} |
||||
|
if ($this->_config['auth_type'] == 2 && Session::has('_AUTH_LIST_'.$uid.$t)) { |
||||
|
return Session::get('_AUTH_LIST_'.$uid.$t); |
||||
|
} |
||||
|
// 读取用户所属用户组 |
||||
|
$groups = $this->getGroups($uid); |
||||
|
$ids = []; // 保存用户所属用户组设置的所有权限规则ID |
||||
|
foreach ($groups as $g) { |
||||
|
$ids = array_merge($ids, explode(',', trim($g['rules'], ','))); |
||||
|
} |
||||
|
$ids = array_unique($ids); |
||||
|
if (empty($ids)) { |
||||
|
$_authList[$uid.$t] = []; |
||||
|
return []; |
||||
|
} |
||||
|
$map = [ |
||||
|
['id', 'in', $ids], |
||||
|
['type', '=', $type], |
||||
|
['auth_open', '=', 1] |
||||
|
]; |
||||
|
// 读取用户组所有权限规则 |
||||
|
$rules = Db::name($this->_config['auth_rule'])->where($map)->field('condition,name')->select(); |
||||
|
// 循环规则,判断结果。 |
||||
|
$authList = []; |
||||
|
foreach ($rules as $rule) { |
||||
|
if (!empty($rule['condition'])) { // 根据condition进行验证 |
||||
|
$user = $this->getUserInfo($uid); // 获取用户信息,一维数组 |
||||
|
$command = preg_replace('/\{(\w*?)\}/', '$user[\'\\1\']', $rule['condition']); |
||||
|
// dump($command); // debug |
||||
|
@(eval('$condition=('.$command.');')); |
||||
|
if ($condition) { |
||||
|
$authList[] = strtolower($rule['name']); |
||||
|
} |
||||
|
} else { |
||||
|
// 只要存在就记录 |
||||
|
$authList[] = strtolower($rule['name']); |
||||
|
} |
||||
|
} |
||||
|
$_authList[$uid.$t] = $authList; |
||||
|
if ($this->_config['auth_type'] == 2) { |
||||
|
Session::set('_AUTH_LIST_'.$uid.$t, $authList); |
||||
|
} |
||||
|
return array_unique($authList); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获得用户资料,根据自己的情况读取数据库 |
||||
|
*/ |
||||
|
protected function getUserInfo($uid) { |
||||
|
static $userinfo = []; |
||||
|
if (!isset($userinfo[$uid])) { |
||||
|
$userinfo[$uid] = Db::name($this->_config['auth_user'])->where((string)$this->_config['auth_user_id_field'], $uid)->find(); |
||||
|
} |
||||
|
return $userinfo[$uid]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获得面包导航 |
||||
|
* @param string $path |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function getBreadCrumb($route = '') |
||||
|
{ |
||||
|
//当前URL |
||||
|
$route = $route ? $route : Request::controller() . '/' . lcfirst(Request::action()); |
||||
|
|
||||
|
//查找名称 |
||||
|
$data = Db::name('auth_rule')->where('name', '=', $route)->find(); |
||||
|
|
||||
|
$result = []; |
||||
|
if ($data) { |
||||
|
$result[] = [ |
||||
|
'url' => $data['name'], |
||||
|
'title' => $data['title'], |
||||
|
'icon' => $data['icon'], |
||||
|
]; |
||||
|
//查找是否有上级别 |
||||
|
if ($data['pid']) { |
||||
|
//查询上级url |
||||
|
$route = Db::name('auth_rule')->where('id', '=', $data['pid'])->find(); |
||||
|
$crumb = $this->getBreadCrumb($route['name']); |
||||
|
foreach ($crumb as $k => $v) { |
||||
|
$result[] = [ |
||||
|
'url' => $crumb[$k]['url'], |
||||
|
'title' => $crumb[$k]['title'], |
||||
|
'icon' => $crumb[$k]['icon'] |
||||
|
]; |
||||
|
} |
||||
|
} |
||||
|
} else { |
||||
|
//不存在的记录 |
||||
|
if ($route == 'Index/index') { |
||||
|
$result[] = [ |
||||
|
'url' => 'Index/index', |
||||
|
'title' => '控制台', |
||||
|
'icon' => 'fa fa-dashboard', |
||||
|
]; |
||||
|
} |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
<!doctype html> |
||||
|
<html> |
||||
|
<head> |
||||
|
<meta charset="utf-8"> |
||||
|
<title>恭喜,站点创建成功!</title> |
||||
|
<style> |
||||
|
.container { |
||||
|
width: 60%; |
||||
|
margin: 10% auto 0; |
||||
|
background-color: #f0f0f0; |
||||
|
padding: 2% 5%; |
||||
|
border-radius: 10px |
||||
|
} |
||||
|
|
||||
|
ul { |
||||
|
padding-left: 20px; |
||||
|
} |
||||
|
|
||||
|
ul li { |
||||
|
line-height: 2.3 |
||||
|
} |
||||
|
|
||||
|
a { |
||||
|
color: #20a53a |
||||
|
} |
||||
|
</style> |
||||
|
</head> |
||||
|
<body> |
||||
|
<div class="container"> |
||||
|
<h1>恭喜, 站点创建成功!</h1> |
||||
|
<h3>这是默认index.html,本页面由系统自动生成</h3> |
||||
|
<ul> |
||||
|
<li>本页面在FTP根目录下的index.html</li> |
||||
|
<li>您可以修改、删除或覆盖本页面</li> |
||||
|
<li>FTP相关信息,请到“面板系统后台 > FTP” 查看</li> |
||||
|
</ul> |
||||
|
</div> |
||||
|
</body> |
||||
|
</html> |
||||
@ -0,0 +1,10 @@ |
|||||
|
<IfModule mod_rewrite.c> |
||||
|
Options +FollowSymlinks -Multiviews |
||||
|
RewriteEngine On |
||||
|
|
||||
|
RewriteCond %{REQUEST_FILENAME} !-d |
||||
|
RewriteCond %{REQUEST_FILENAME} !-f |
||||
|
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1] |
||||
|
</IfModule> |
||||
|
|
||||
|
|
||||
|
After Width: | Height: | Size: 15 KiB |
@ -0,0 +1,29 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ] |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Copyright (c) 2006-2019 http://thinkphp.cn All rights reserved. |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: liu21st <liu21st@gmail.com> |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
// [ 应用入口文件 ] |
||||
|
namespace think; |
||||
|
|
||||
|
if (version_compare(PHP_VERSION, '7.1.0', '<')) { |
||||
|
echo '请升级您的PHP版本,要求:PHP >= 7.1.0,当前版本为 ' . PHP_VERSION; |
||||
|
exit; |
||||
|
} |
||||
|
|
||||
|
require __DIR__ . '/../vendor/autoload.php'; |
||||
|
|
||||
|
// 执行HTTP应用并响应 |
||||
|
$http = (new App())->http; |
||||
|
|
||||
|
$response = $http->run(); |
||||
|
|
||||
|
$response->send(); |
||||
|
|
||||
|
$http->end($response); |
||||
@ -0,0 +1,17 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ] |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved. |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: liu21st <liu21st@gmail.com> |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// $Id$ |
||||
|
|
||||
|
if (is_file($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SCRIPT_NAME"])) { |
||||
|
return false; |
||||
|
} else { |
||||
|
require __DIR__ . "/index.php"; |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
#!/usr/bin/env php |
||||
|
<?php |
||||
|
namespace think; |
||||
|
|
||||
|
// 命令行入口文件 |
||||
|
// 加载基础文件 |
||||
|
require __DIR__ . '/vendor/autoload.php'; |
||||
|
|
||||
|
// 应用初始化 |
||||
|
(new App())->console->run(); |
||||
@ -0,0 +1,21 @@ |
|||||
|
# The MIT License (MIT) |
||||
|
|
||||
|
Copyright (c) 2016-2019 Riku Särkinen |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
of this software and associated documentation files (the "Software"), to deal |
||||
|
in the Software without restriction, including without limitation the rights |
||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
copies of the Software, and to permit persons to whom the Software is |
||||
|
furnished to do so, subject to the following conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice shall be included in all |
||||
|
copies or substantial portions of the Software. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
|
SOFTWARE. |
||||
@ -0,0 +1,29 @@ |
|||||
|
{ |
||||
|
"name": "adbario/php-dot-notation", |
||||
|
"description": "PHP dot notation access to arrays", |
||||
|
"keywords": ["dotnotation", "arrayaccess"], |
||||
|
"homepage": "https://github.com/adbario/php-dot-notation", |
||||
|
"license": "MIT", |
||||
|
"authors": [ |
||||
|
{ |
||||
|
"name": "Riku Särkinen", |
||||
|
"email": "riku@adbar.io" |
||||
|
} |
||||
|
], |
||||
|
"require": { |
||||
|
"php": ">=5.5", |
||||
|
"ext-json": "*" |
||||
|
}, |
||||
|
"require-dev": { |
||||
|
"phpunit/phpunit": "^4.0|^5.0|^6.0", |
||||
|
"squizlabs/php_codesniffer": "^3.0" |
||||
|
}, |
||||
|
"autoload": { |
||||
|
"files": [ |
||||
|
"src/helpers.php" |
||||
|
], |
||||
|
"psr-4": { |
||||
|
"Adbar\\": "src" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,601 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* Dot - PHP dot notation access to arrays |
||||
|
* |
||||
|
* @author Riku Särkinen <riku@adbar.io> |
||||
|
* @link https://github.com/adbario/php-dot-notation |
||||
|
* @license https://github.com/adbario/php-dot-notation/blob/2.x/LICENSE.md (MIT License) |
||||
|
*/ |
||||
|
namespace Adbar; |
||||
|
|
||||
|
use Countable; |
||||
|
use ArrayAccess; |
||||
|
use ArrayIterator; |
||||
|
use JsonSerializable; |
||||
|
use IteratorAggregate; |
||||
|
|
||||
|
/** |
||||
|
* Dot |
||||
|
* |
||||
|
* This class provides a dot notation access and helper functions for |
||||
|
* working with arrays of data. Inspired by Laravel Collection. |
||||
|
*/ |
||||
|
class Dot implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable |
||||
|
{ |
||||
|
/** |
||||
|
* The stored items |
||||
|
* |
||||
|
* @var array |
||||
|
*/ |
||||
|
protected $items = []; |
||||
|
|
||||
|
/** |
||||
|
* Create a new Dot instance |
||||
|
* |
||||
|
* @param mixed $items |
||||
|
*/ |
||||
|
public function __construct($items = []) |
||||
|
{ |
||||
|
$this->items = $this->getArrayItems($items); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set a given key / value pair or pairs |
||||
|
* if the key doesn't exist already |
||||
|
* |
||||
|
* @param array|int|string $keys |
||||
|
* @param mixed $value |
||||
|
*/ |
||||
|
public function add($keys, $value = null) |
||||
|
{ |
||||
|
if (is_array($keys)) { |
||||
|
foreach ($keys as $key => $value) { |
||||
|
$this->add($key, $value); |
||||
|
} |
||||
|
} elseif (is_null($this->get($keys))) { |
||||
|
$this->set($keys, $value); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Return all the stored items |
||||
|
* |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function all() |
||||
|
{ |
||||
|
return $this->items; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Delete the contents of a given key or keys |
||||
|
* |
||||
|
* @param array|int|string|null $keys |
||||
|
*/ |
||||
|
public function clear($keys = null) |
||||
|
{ |
||||
|
if (is_null($keys)) { |
||||
|
$this->items = []; |
||||
|
|
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
$keys = (array) $keys; |
||||
|
|
||||
|
foreach ($keys as $key) { |
||||
|
$this->set($key, []); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Delete the given key or keys |
||||
|
* |
||||
|
* @param array|int|string $keys |
||||
|
*/ |
||||
|
public function delete($keys) |
||||
|
{ |
||||
|
$keys = (array) $keys; |
||||
|
|
||||
|
foreach ($keys as $key) { |
||||
|
if ($this->exists($this->items, $key)) { |
||||
|
unset($this->items[$key]); |
||||
|
|
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
$items = &$this->items; |
||||
|
$segments = explode('.', $key); |
||||
|
$lastSegment = array_pop($segments); |
||||
|
|
||||
|
foreach ($segments as $segment) { |
||||
|
if (!isset($items[$segment]) || !is_array($items[$segment])) { |
||||
|
continue 2; |
||||
|
} |
||||
|
|
||||
|
$items = &$items[$segment]; |
||||
|
} |
||||
|
|
||||
|
unset($items[$lastSegment]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Checks if the given key exists in the provided array. |
||||
|
* |
||||
|
* @param array $array Array to validate |
||||
|
* @param int|string $key The key to look for |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function exists($array, $key) |
||||
|
{ |
||||
|
return array_key_exists($key, $array); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Flatten an array with the given character as a key delimiter |
||||
|
* |
||||
|
* @param string $delimiter |
||||
|
* @param array|null $items |
||||
|
* @param string $prepend |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function flatten($delimiter = '.', $items = null, $prepend = '') |
||||
|
{ |
||||
|
$flatten = []; |
||||
|
|
||||
|
if (is_null($items)) { |
||||
|
$items = $this->items; |
||||
|
} |
||||
|
|
||||
|
foreach ($items as $key => $value) { |
||||
|
if (is_array($value) && !empty($value)) { |
||||
|
$flatten = array_merge( |
||||
|
$flatten, |
||||
|
$this->flatten($delimiter, $value, $prepend.$key.$delimiter) |
||||
|
); |
||||
|
} else { |
||||
|
$flatten[$prepend.$key] = $value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $flatten; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Return the value of a given key |
||||
|
* |
||||
|
* @param int|string|null $key |
||||
|
* @param mixed $default |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function get($key = null, $default = null) |
||||
|
{ |
||||
|
if (is_null($key)) { |
||||
|
return $this->items; |
||||
|
} |
||||
|
|
||||
|
if ($this->exists($this->items, $key)) { |
||||
|
return $this->items[$key]; |
||||
|
} |
||||
|
|
||||
|
if (strpos($key, '.') === false) { |
||||
|
return $default; |
||||
|
} |
||||
|
|
||||
|
$items = $this->items; |
||||
|
|
||||
|
foreach (explode('.', $key) as $segment) { |
||||
|
if (!is_array($items) || !$this->exists($items, $segment)) { |
||||
|
return $default; |
||||
|
} |
||||
|
|
||||
|
$items = &$items[$segment]; |
||||
|
} |
||||
|
|
||||
|
return $items; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Return the given items as an array |
||||
|
* |
||||
|
* @param mixed $items |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function getArrayItems($items) |
||||
|
{ |
||||
|
if (is_array($items)) { |
||||
|
return $items; |
||||
|
} elseif ($items instanceof self) { |
||||
|
return $items->all(); |
||||
|
} |
||||
|
|
||||
|
return (array) $items; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Check if a given key or keys exists |
||||
|
* |
||||
|
* @param array|int|string $keys |
||||
|
* @return bool |
||||
|
*/ |
||||
|
public function has($keys) |
||||
|
{ |
||||
|
$keys = (array) $keys; |
||||
|
|
||||
|
if (!$this->items || $keys === []) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
foreach ($keys as $key) { |
||||
|
$items = $this->items; |
||||
|
|
||||
|
if ($this->exists($items, $key)) { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
foreach (explode('.', $key) as $segment) { |
||||
|
if (!is_array($items) || !$this->exists($items, $segment)) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
$items = $items[$segment]; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Check if a given key or keys are empty |
||||
|
* |
||||
|
* @param array|int|string|null $keys |
||||
|
* @return bool |
||||
|
*/ |
||||
|
public function isEmpty($keys = null) |
||||
|
{ |
||||
|
if (is_null($keys)) { |
||||
|
return empty($this->items); |
||||
|
} |
||||
|
|
||||
|
$keys = (array) $keys; |
||||
|
|
||||
|
foreach ($keys as $key) { |
||||
|
if (!empty($this->get($key))) { |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Merge a given array or a Dot object with the given key |
||||
|
* or with the whole Dot object |
||||
|
* |
||||
|
* @param array|string|self $key |
||||
|
* @param array|self $value |
||||
|
*/ |
||||
|
public function merge($key, $value = []) |
||||
|
{ |
||||
|
if (is_array($key)) { |
||||
|
$this->items = array_merge($this->items, $key); |
||||
|
} elseif (is_string($key)) { |
||||
|
$items = (array) $this->get($key); |
||||
|
$value = array_merge($items, $this->getArrayItems($value)); |
||||
|
|
||||
|
$this->set($key, $value); |
||||
|
} elseif ($key instanceof self) { |
||||
|
$this->items = array_merge($this->items, $key->all()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Recursively merge a given array or a Dot object with the given key |
||||
|
* or with the whole Dot object. |
||||
|
* |
||||
|
* Duplicate keys are converted to arrays. |
||||
|
* |
||||
|
* @param array|string|self $key |
||||
|
* @param array|self $value |
||||
|
*/ |
||||
|
public function mergeRecursive($key, $value = []) |
||||
|
{ |
||||
|
if (is_array($key)) { |
||||
|
$this->items = array_merge_recursive($this->items, $key); |
||||
|
} elseif (is_string($key)) { |
||||
|
$items = (array) $this->get($key); |
||||
|
$value = array_merge_recursive($items, $this->getArrayItems($value)); |
||||
|
|
||||
|
$this->set($key, $value); |
||||
|
} elseif ($key instanceof self) { |
||||
|
$this->items = array_merge_recursive($this->items, $key->all()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Recursively merge a given array or a Dot object with the given key |
||||
|
* or with the whole Dot object. |
||||
|
* |
||||
|
* Instead of converting duplicate keys to arrays, the value from |
||||
|
* given array will replace the value in Dot object. |
||||
|
* |
||||
|
* @param array|string|self $key |
||||
|
* @param array|self $value |
||||
|
*/ |
||||
|
public function mergeRecursiveDistinct($key, $value = []) |
||||
|
{ |
||||
|
if (is_array($key)) { |
||||
|
$this->items = $this->arrayMergeRecursiveDistinct($this->items, $key); |
||||
|
} elseif (is_string($key)) { |
||||
|
$items = (array) $this->get($key); |
||||
|
$value = $this->arrayMergeRecursiveDistinct($items, $this->getArrayItems($value)); |
||||
|
|
||||
|
$this->set($key, $value); |
||||
|
} elseif ($key instanceof self) { |
||||
|
$this->items = $this->arrayMergeRecursiveDistinct($this->items, $key->all()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Merges two arrays recursively. In contrast to array_merge_recursive, |
||||
|
* duplicate keys are not converted to arrays but rather overwrite the |
||||
|
* value in the first array with the duplicate value in the second array. |
||||
|
* |
||||
|
* @param array $array1 Initial array to merge |
||||
|
* @param array $array2 Array to recursively merge |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function arrayMergeRecursiveDistinct(array $array1, array $array2) |
||||
|
{ |
||||
|
$merged = &$array1; |
||||
|
|
||||
|
foreach ($array2 as $key => $value) { |
||||
|
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) { |
||||
|
$merged[$key] = $this->arrayMergeRecursiveDistinct($merged[$key], $value); |
||||
|
} else { |
||||
|
$merged[$key] = $value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $merged; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Return the value of a given key and |
||||
|
* delete the key |
||||
|
* |
||||
|
* @param int|string|null $key |
||||
|
* @param mixed $default |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function pull($key = null, $default = null) |
||||
|
{ |
||||
|
if (is_null($key)) { |
||||
|
$value = $this->all(); |
||||
|
$this->clear(); |
||||
|
|
||||
|
return $value; |
||||
|
} |
||||
|
|
||||
|
$value = $this->get($key, $default); |
||||
|
$this->delete($key); |
||||
|
|
||||
|
return $value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Push a given value to the end of the array |
||||
|
* in a given key |
||||
|
* |
||||
|
* @param mixed $key |
||||
|
* @param mixed $value |
||||
|
*/ |
||||
|
public function push($key, $value = null) |
||||
|
{ |
||||
|
if (is_null($value)) { |
||||
|
$this->items[] = $key; |
||||
|
|
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
$items = $this->get($key); |
||||
|
|
||||
|
if (is_array($items) || is_null($items)) { |
||||
|
$items[] = $value; |
||||
|
$this->set($key, $items); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Replace all values or values within the given key |
||||
|
* with an array or Dot object |
||||
|
* |
||||
|
* @param array|string|self $key |
||||
|
* @param array|self $value |
||||
|
*/ |
||||
|
public function replace($key, $value = []) |
||||
|
{ |
||||
|
if (is_array($key)) { |
||||
|
$this->items = array_replace($this->items, $key); |
||||
|
} elseif (is_string($key)) { |
||||
|
$items = (array) $this->get($key); |
||||
|
$value = array_replace($items, $this->getArrayItems($value)); |
||||
|
|
||||
|
$this->set($key, $value); |
||||
|
} elseif ($key instanceof self) { |
||||
|
$this->items = array_replace($this->items, $key->all()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set a given key / value pair or pairs |
||||
|
* |
||||
|
* @param array|int|string $keys |
||||
|
* @param mixed $value |
||||
|
*/ |
||||
|
public function set($keys, $value = null) |
||||
|
{ |
||||
|
if (is_array($keys)) { |
||||
|
foreach ($keys as $key => $value) { |
||||
|
$this->set($key, $value); |
||||
|
} |
||||
|
|
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
$items = &$this->items; |
||||
|
|
||||
|
foreach (explode('.', $keys) as $key) { |
||||
|
if (!isset($items[$key]) || !is_array($items[$key])) { |
||||
|
$items[$key] = []; |
||||
|
} |
||||
|
|
||||
|
$items = &$items[$key]; |
||||
|
} |
||||
|
|
||||
|
$items = $value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Replace all items with a given array |
||||
|
* |
||||
|
* @param mixed $items |
||||
|
*/ |
||||
|
public function setArray($items) |
||||
|
{ |
||||
|
$this->items = $this->getArrayItems($items); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Replace all items with a given array as a reference |
||||
|
* |
||||
|
* @param array $items |
||||
|
*/ |
||||
|
public function setReference(array &$items) |
||||
|
{ |
||||
|
$this->items = &$items; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Return the value of a given key or all the values as JSON |
||||
|
* |
||||
|
* @param mixed $key |
||||
|
* @param int $options |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function toJson($key = null, $options = 0) |
||||
|
{ |
||||
|
if (is_string($key)) { |
||||
|
return json_encode($this->get($key), $options); |
||||
|
} |
||||
|
|
||||
|
$options = $key === null ? 0 : $key; |
||||
|
|
||||
|
return json_encode($this->items, $options); |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* -------------------------------------------------------------- |
||||
|
* ArrayAccess interface |
||||
|
* -------------------------------------------------------------- |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* Check if a given key exists |
||||
|
* |
||||
|
* @param int|string $key |
||||
|
* @return bool |
||||
|
*/ |
||||
|
public function offsetExists($key) |
||||
|
{ |
||||
|
return $this->has($key); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Return the value of a given key |
||||
|
* |
||||
|
* @param int|string $key |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function offsetGet($key) |
||||
|
{ |
||||
|
return $this->get($key); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Set a given value to the given key |
||||
|
* |
||||
|
* @param int|string|null $key |
||||
|
* @param mixed $value |
||||
|
*/ |
||||
|
public function offsetSet($key, $value) |
||||
|
{ |
||||
|
if (is_null($key)) { |
||||
|
$this->items[] = $value; |
||||
|
|
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
$this->set($key, $value); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Delete the given key |
||||
|
* |
||||
|
* @param int|string $key |
||||
|
*/ |
||||
|
public function offsetUnset($key) |
||||
|
{ |
||||
|
$this->delete($key); |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* -------------------------------------------------------------- |
||||
|
* Countable interface |
||||
|
* -------------------------------------------------------------- |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* Return the number of items in a given key |
||||
|
* |
||||
|
* @param int|string|null $key |
||||
|
* @return int |
||||
|
*/ |
||||
|
public function count($key = null) |
||||
|
{ |
||||
|
return count($this->get($key)); |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* -------------------------------------------------------------- |
||||
|
* IteratorAggregate interface |
||||
|
* -------------------------------------------------------------- |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* Get an iterator for the stored items |
||||
|
* |
||||
|
* @return \ArrayIterator |
||||
|
*/ |
||||
|
public function getIterator() |
||||
|
{ |
||||
|
return new ArrayIterator($this->items); |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* -------------------------------------------------------------- |
||||
|
* JsonSerializable interface |
||||
|
* -------------------------------------------------------------- |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* Return items for JSON serialization |
||||
|
* |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function jsonSerialize() |
||||
|
{ |
||||
|
return $this->items; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* Dot - PHP dot notation access to arrays |
||||
|
* |
||||
|
* @author Riku Särkinen <riku@adbar.io> |
||||
|
* @link https://github.com/adbario/php-dot-notation |
||||
|
* @license https://github.com/adbario/php-dot-notation/blob/2.x/LICENSE.md (MIT License) |
||||
|
*/ |
||||
|
|
||||
|
use Adbar\Dot; |
||||
|
|
||||
|
if (! function_exists('dot')) { |
||||
|
/** |
||||
|
* Create a new Dot object with the given items |
||||
|
* |
||||
|
* @param mixed $items |
||||
|
* @return \Adbar\Dot |
||||
|
*/ |
||||
|
function dot($items) |
||||
|
{ |
||||
|
return new Dot($items); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,288 @@ |
|||||
|
# CHANGELOG |
||||
|
|
||||
|
## 1.5.25 - 2020-07-04 |
||||
|
- Fixed ROA signature. |
||||
|
- Deprecated `LogFormatter`. |
||||
|
|
||||
|
## 1.5.24 - 2020-06-04 |
||||
|
- Fixed Resolve Host. |
||||
|
|
||||
|
## 1.5.23 - 2020-05-22 |
||||
|
- Optimized global product support. |
||||
|
|
||||
|
## 1.5.22 - 2020-05-12 |
||||
|
- Updated Endpoints. |
||||
|
|
||||
|
## 1.5.21 - 2020-02-26 |
||||
|
- Improved Nonce. |
||||
|
- Updated Endpoints. |
||||
|
|
||||
|
## 1.5.20 - 2019-12-30 |
||||
|
- Improved Docs. |
||||
|
- Updated Endpoints. |
||||
|
|
||||
|
## 1.5.19 - 2019-12-17 |
||||
|
- Updated Endpoints. |
||||
|
|
||||
|
## 1.5.18 - 2019-10-11 |
||||
|
- Updated Request link. |
||||
|
- Updated Endpoints data. |
||||
|
|
||||
|
## 1.5.17 - 2019-09-15 |
||||
|
- Improved Host Finder. |
||||
|
- Updated Endpoints Data. |
||||
|
|
||||
|
## 1.5.16 - 2019-08-21 |
||||
|
- Updated Endpoints Data. |
||||
|
|
||||
|
## 1.5.15 - 2019-08-14 |
||||
|
- Improved Client. |
||||
|
|
||||
|
|
||||
|
## 1.5.14 - 2019-07-25 |
||||
|
- Improved Credential Filter. |
||||
|
|
||||
|
|
||||
|
## 1.5.13 - 2019-07-18 |
||||
|
- Improved API Resolver. |
||||
|
|
||||
|
|
||||
|
## 1.5.12 - 2019-06-20 |
||||
|
- Fixed Signature for ROA. |
||||
|
|
||||
|
|
||||
|
## 1.5.11 - 2019-06-14 |
||||
|
- Added endpoint rules. |
||||
|
|
||||
|
|
||||
|
## 1.5.10 - 2019-06-13 |
||||
|
- Improved `Resovler`. |
||||
|
- Updated `endpoints`. |
||||
|
|
||||
|
|
||||
|
## 1.5.9 - 2019-06-04 |
||||
|
- Improved `UUID`. |
||||
|
|
||||
|
|
||||
|
## 1.5.8 - 2019-05-30 |
||||
|
- Improved `Arrays`. |
||||
|
|
||||
|
|
||||
|
## 1.5.7 - 2019-05-29 |
||||
|
- Improved `uuid`. |
||||
|
|
||||
|
|
||||
|
## 1.5.6 - 2019-05-29 |
||||
|
- Fixed `uuid` version lock. |
||||
|
|
||||
|
|
||||
|
## 1.5.5 - 2019-05-23 |
||||
|
- Improved `Signature`. |
||||
|
|
||||
|
|
||||
|
## 1.5.4 - 2019-05-22 |
||||
|
- Updated `Endpoints`. |
||||
|
- Fixed `Content-Type` in header. |
||||
|
|
||||
|
|
||||
|
## 1.5.3 - 2019-05-13 |
||||
|
- Improved `Endpoint` tips. |
||||
|
- Improved `Endpoints` for `STS`. |
||||
|
|
||||
|
|
||||
|
## 1.5.2 - 2019-05-10 |
||||
|
- Improved `Result` object. |
||||
|
|
||||
|
|
||||
|
## 1.5.1 - 2019-05-09 |
||||
|
- Supported `Resolver` for Third-party dependencies. |
||||
|
|
||||
|
|
||||
|
## 1.5.0 - 2019-05-07 |
||||
|
- Improved `Resolver` for products. |
||||
|
|
||||
|
|
||||
|
## 1.4.0 - 2019-05-06 |
||||
|
- Support `Retry` and `Asynchronous` for Request. |
||||
|
|
||||
|
|
||||
|
## 1.3.1 - 2019-04-30 |
||||
|
- Allow timeouts to be set in microseconds. |
||||
|
|
||||
|
|
||||
|
## 1.3.0 - 2019-04-18 |
||||
|
- Improved parameters methods. |
||||
|
- Optimized the logic for body encode. |
||||
|
|
||||
|
|
||||
|
## 1.2.1 - 2019-04-11 |
||||
|
- Improve exception code and message for `Region ID`. |
||||
|
|
||||
|
|
||||
|
## 1.2.0 - 2019-04-11 |
||||
|
- Improve exception message for `Region ID`. |
||||
|
|
||||
|
|
||||
|
## 1.1.1 - 2019-04-02 |
||||
|
- Added endpoints for `batchcomputenew`, `privatelink`. |
||||
|
- Improve Region ID tips. |
||||
|
|
||||
|
|
||||
|
## 1.1.0 - 2019-04-01 |
||||
|
- Updated `composer.json`. |
||||
|
|
||||
|
|
||||
|
## 1.0.27 - 2019-03-31 |
||||
|
- Support `Policy` for `ramRoleArnClient`. |
||||
|
|
||||
|
|
||||
|
## 1.0.26 - 2019-03-27 |
||||
|
- Support `pid`, `cost`, `start_time` for Log. |
||||
|
|
||||
|
|
||||
|
## 1.0.25 - 2019-03-27 |
||||
|
- Updated default log format. |
||||
|
- Add endpoints for `dbs`. |
||||
|
|
||||
|
|
||||
|
## 1.0.24 - 2019-03-26 |
||||
|
- Support Log. |
||||
|
|
||||
|
|
||||
|
## 1.0.23 - 2019-03-23 |
||||
|
- Remove SVG. |
||||
|
|
||||
|
|
||||
|
## 1.0.22 - 2019-03-20 |
||||
|
- Add endpoint `cn-hangzhou` for `idaas` . |
||||
|
|
||||
|
|
||||
|
## 1.0.21 - 2019-03-19 |
||||
|
- Installing by Using the ZIP file. |
||||
|
- Update Docs. |
||||
|
|
||||
|
|
||||
|
## 1.0.20 - 2019-03-13 |
||||
|
- Improve Tests. |
||||
|
- Update Docs. |
||||
|
|
||||
|
|
||||
|
## 1.0.19 - 2019-03-12 |
||||
|
- Add SSL Verify Option `verify()`. |
||||
|
|
||||
|
|
||||
|
## 1.0.18 - 2019-03-11 |
||||
|
- Add endpoints for `acr`. |
||||
|
- Add endpoints for `faas`. |
||||
|
- Add endpoints for `ehs`. |
||||
|
- SSL certificates are not validated by default. |
||||
|
|
||||
|
|
||||
|
## 1.0.17 - 2019-03-08 |
||||
|
- Support Mock for Test. |
||||
|
|
||||
|
|
||||
|
## 1.0.16 - 2019-03-07 |
||||
|
- Support Credential Provider Chain. |
||||
|
- Support `CCC`. |
||||
|
- Add `ap-south-1` for `cas`. |
||||
|
- Add `ap-southeast-1` for `waf`. |
||||
|
- Update Docs. |
||||
|
|
||||
|
|
||||
|
## 1.0.15 - 2019-02-27 |
||||
|
- Add endpoints for `Chatbot`. |
||||
|
- Change endpoints for `drdspost` and `drdspre`. |
||||
|
|
||||
|
|
||||
|
## 1.0.14 - 2019-02-21 |
||||
|
- Enable debug mode by set environment variable `DEBUG=sdk`. |
||||
|
|
||||
|
|
||||
|
## 1.0.13 - 2019-02-18 |
||||
|
- Support Release Script `composer release`. |
||||
|
- Add endpoints for apigateway in `drdspre` in `cn-qingdao`. |
||||
|
- Add endpoints for apigateway in `drdspre` in `cn-beijing`. |
||||
|
- Add endpoints for apigateway in `drdspre` in `cn-hangzhou`. |
||||
|
- Add endpoints for apigateway in `drdspre` in `cn-shanghai`. |
||||
|
- Add endpoints for apigateway in `drdspre` in `cn-shenzhen`. |
||||
|
- Add endpoints for apigateway in `drdspre` in `cn-hongkong`. |
||||
|
- Add endpoints for apigateway in `drdspost` in `ap-southeast-1`. |
||||
|
- Add endpoints for apigateway in `drdspost` in `cn-shanghai`. |
||||
|
- Add endpoints for apigateway in `drdspost` in `cn-hongkong`. |
||||
|
- Add endpoints for apigateway in `vod` in `ap-southeast-1`. |
||||
|
- Add endpoints for apigateway in `vod` in `eu-central-1`. |
||||
|
|
||||
|
|
||||
|
## 1.0.12 - 2019-02-16 |
||||
|
- Support `open_basedir`. |
||||
|
|
||||
|
|
||||
|
## 1.0.11 - 2019-02-13 |
||||
|
- Improve User Agent. |
||||
|
|
||||
|
|
||||
|
## 1.0.10 - 2019-02-12 |
||||
|
- `userAgentAppend` is renamed to `appendUserAgent`. |
||||
|
|
||||
|
|
||||
|
## 1.0.9 - 2019-02-12 |
||||
|
- `userAgent` is renamed to `userAgentAppend`. |
||||
|
|
||||
|
|
||||
|
## 1.0.8 - 2019-02-11 |
||||
|
- `userAgent` - Support DIY User Agent. |
||||
|
- Add endpoints for apigateway in Zhangjiakou. |
||||
|
- Add endpoints for apigateway in Hu He Hao Te. |
||||
|
- Add endpoints for vod in Hu He Hao Te. |
||||
|
- Add endpoints for hsm in Zhangjiakou. |
||||
|
- Add endpoints for luban in Germany. |
||||
|
- Add endpoints for linkwan in Hangzhou. |
||||
|
- Add endpoints for drdspost in Singapore. |
||||
|
|
||||
|
|
||||
|
## 1.0.7 - 2019-01-28 |
||||
|
- Add endpoints for gpdb in Tokyo. |
||||
|
- Add endpoints for elasticsearch in Beijing. |
||||
|
|
||||
|
|
||||
|
## 1.0.6 - 2019-01-23 |
||||
|
- Add endpoints for dysmsapi in Singapore. |
||||
|
- Add endpoints for dybaseapi. |
||||
|
- Add endpoints for dyiotapi. |
||||
|
- Add endpoints for dycdpapi. |
||||
|
- Add endpoints for dyplsapi. |
||||
|
- Add endpoints for dypnsapi. |
||||
|
- Add endpoints for dyvmsapi. |
||||
|
- Add endpoints for snsuapi. |
||||
|
|
||||
|
|
||||
|
## 1.0.5 - 2019-01-21 |
||||
|
- Add endpoints for ApiGateway in Silicon Valley, Virginia. |
||||
|
- Add endpoints for Image Search in Shanghai. |
||||
|
|
||||
|
|
||||
|
## 1.0.4 - 2019-01-17 |
||||
|
- Support fixer all. |
||||
|
- Add Endpoints. |
||||
|
|
||||
|
|
||||
|
## 1.0.3 - 2019-01-15 |
||||
|
- Update Endpoints. |
||||
|
- Update README.md. |
||||
|
- Update Return Result Message. |
||||
|
|
||||
|
|
||||
|
## 1.0.2 - 2019-01-15 |
||||
|
- Optimize the documentation. |
||||
|
- Adjust the CI configuration. |
||||
|
|
||||
|
|
||||
|
## 1.0.1 - 2019-01-09 |
||||
|
- Distinguish credential error. |
||||
|
- Add endpoints for NLS. |
||||
|
- Add not found product tip. |
||||
|
|
||||
|
|
||||
|
## 1.0.0 - 2019-01-07 |
||||
|
- Initial release of the Alibaba Cloud Client for PHP Version 1.0.0 on Packagist See <https://github.com/aliyun/openapi-sdk-php-client> for more information. |
||||
@ -0,0 +1,30 @@ |
|||||
|
# Contributing to the Alibaba Cloud Client for PHP |
||||
|
|
||||
|
We work hard to provide a high-quality and useful SDK for Alibaba Cloud, and |
||||
|
we greatly value feedback and contributions from our community. Please submit |
||||
|
your [issues][issues] or [pull requests][pull-requests] through GitHub. |
||||
|
|
||||
|
## Tips |
||||
|
|
||||
|
- The SDK is released under the [Apache license][license]. Any code you submit |
||||
|
will be released under that license. For substantial contributions, we may |
||||
|
ask you to sign a [Alibaba Documentation Corporate Contributor License |
||||
|
Agreement (CLA)][cla]. |
||||
|
- We follow all of the relevant PSR recommendations from the [PHP Framework |
||||
|
Interop Group][php-fig]. Please submit code that follows these standards. |
||||
|
The [PHP CS Fixer][cs-fixer] tool can be helpful for formatting your code. |
||||
|
Your can use `composer fixer` to fix code. |
||||
|
- We maintain a high percentage of code coverage in our unit tests. If you make |
||||
|
changes to the code, please add, update, and/or remove tests as appropriate. |
||||
|
- If your code does not conform to the PSR standards, does not include adequate |
||||
|
tests, or does not contain a changelog document, we may ask you to update |
||||
|
your pull requests before we accept them. We also reserve the right to deny |
||||
|
any pull requests that do not align with our standards or goals. |
||||
|
|
||||
|
[issues]: https://github.com/aliyun/openapi-sdk-php-client/issues |
||||
|
[pull-requests]: https://github.com/aliyun/openapi-sdk-php-client/pulls |
||||
|
[license]: http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
[cla]: https://alibaba-cla-2018.oss-cn-beijing.aliyuncs.com/Alibaba_Documentation_Open_Source_Corporate_CLA.pdf |
||||
|
[php-fig]: http://php-fig.org |
||||
|
[cs-fixer]: http://cs.sensiolabs.org/ |
||||
|
[docs-readme]: https://github.com/aliyun/openapi-sdk-php-client/blob/master/README.md |
||||
@ -0,0 +1,13 @@ |
|||||
|
Copyright (c) 2009-present, Alibaba Cloud All rights reserved. |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
@ -0,0 +1,88 @@ |
|||||
|
# Alibaba Cloud Client for PHP |
||||
|
|
||||
|
<https://www.alibabacloud.com/> |
||||
|
|
||||
|
Copyright (c) 2009-present, Alibaba Cloud All rights reserved. |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"). |
||||
|
You may not use this file except in compliance with the License. |
||||
|
A copy of the License is located at |
||||
|
|
||||
|
<http://www.apache.org/licenses/LICENSE-2.0> |
||||
|
|
||||
|
or in the "license" file accompanying this file. This file is distributed |
||||
|
on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
||||
|
express or implied. See the License for the specific language governing |
||||
|
permissions and limitations under the License. |
||||
|
|
||||
|
# Guzzle |
||||
|
|
||||
|
<https://github.com/guzzle/guzzle> |
||||
|
|
||||
|
Copyright (c) 2011-2018 Michael Dowling, https://github.com/mtdowling <mtdowling@gmail.com> |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
of this software and associated documentation files (the "Software"), to deal |
||||
|
in the Software without restriction, including without limitation the rights |
||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
copies of the Software, and to permit persons to whom the Software is |
||||
|
furnished to do so, subject to the following conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice shall be included in |
||||
|
all copies or substantial portions of the Software. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
THE SOFTWARE. |
||||
|
|
||||
|
# jmespath.php |
||||
|
|
||||
|
<https://github.com/mtdowling/jmespath.php> |
||||
|
|
||||
|
Copyright (c) 2014 Michael Dowling, https://github.com/mtdowling |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
of this software and associated documentation files (the "Software"), to deal |
||||
|
in the Software without restriction, including without limitation the rights |
||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
copies of the Software, and to permit persons to whom the Software is |
||||
|
furnished to do so, subject to the following conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice shall be included in |
||||
|
all copies or substantial portions of the Software. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
THE SOFTWARE. |
||||
|
|
||||
|
# Dot |
||||
|
|
||||
|
<https://github.com/adbario/php-dot-notation> |
||||
|
|
||||
|
Copyright (c) 2016-2019 Riku Särkinen |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
of this software and associated documentation files (the "Software"), to deal |
||||
|
in the Software without restriction, including without limitation the rights |
||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
copies of the Software, and to permit persons to whom the Software is |
||||
|
furnished to do so, subject to the following conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice shall be included in all |
||||
|
copies or substantial portions of the Software. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
|
SOFTWARE. |
||||
@ -0,0 +1,166 @@ |
|||||
|
[English](/README.md) | 简体中文 |
||||
|
|
||||
|
|
||||
|
# Alibaba Cloud Client for PHP |
||||
|
[](https://packagist.org/packages/alibabacloud/client) |
||||
|
[](https://packagist.org/packages/alibabacloud/client) |
||||
|
[](https://packagist.org/packages/alibabacloud/client) |
||||
|
[](https://packagist.org/packages/alibabacloud/client) |
||||
|
[](https://codecov.io/gh/aliyun/openapi-sdk-php-client) |
||||
|
[](https://travis-ci.org/aliyun/openapi-sdk-php-client) |
||||
|
[](https://ci.appveyor.com/project/aliyun/openapi-sdk-php-client/branch/master) |
||||
|
|
||||
|
|
||||
|
 |
||||
|
|
||||
|
|
||||
|
Alibaba Cloud Client for PHP 是帮助 PHP 开发者管理凭据、发送请求的客户端工具,[Alibaba Cloud SDK for PHP][SDK] 由本工具提供底层支持。 |
||||
|
|
||||
|
|
||||
|
## 在线示例 |
||||
|
[API Explorer](https://api.aliyun.com) 提供在线调用阿里云产品,并动态生成 SDK 代码和快速检索接口等能力,能显著降低使用云 API 的难度。 |
||||
|
|
||||
|
|
||||
|
## 先决条件 |
||||
|
您的系统需要满足[先决条件](/docs/zh-CN/0-Prerequisites.md),包括 PHP> = 5.5。 我们强烈建议使用cURL扩展,并使用TLS后端编译cURL 7.16.2+。 |
||||
|
|
||||
|
|
||||
|
## 安装依赖 |
||||
|
如果已在系统上[全局安装 Composer](https://getcomposer.org/doc/00-intro.md#globally),请直接在项目目录中运行以下内容来安装 Alibaba Cloud Client for PHP 作为依赖项: |
||||
|
``` |
||||
|
composer require alibabacloud/client |
||||
|
``` |
||||
|
> 一些用户可能由于网络问题无法安装,可以使用[阿里云 Composer 全量镜像](https://developer.aliyun.com/composer)。 |
||||
|
|
||||
|
请看[安装](/docs/zh-CN/1-Installation.md)有关通过 Composer 和其他方式安装的详细信息。 |
||||
|
|
||||
|
|
||||
|
## 快速使用 |
||||
|
在您开始之前,您需要注册阿里云帐户并获取您的[凭证](https://usercenter.console.aliyun.com/#/manage/ak)。 |
||||
|
|
||||
|
```php |
||||
|
<?php |
||||
|
|
||||
|
use AlibabaCloud\Client\AlibabaCloud; |
||||
|
|
||||
|
AlibabaCloud::accessKeyClient('accessKeyId', 'accessKeySecret')->asDefaultClient(); |
||||
|
``` |
||||
|
|
||||
|
|
||||
|
## 请求 |
||||
|
> 请求风格分为 `ROA` 和 `RPC`,不同产品风格不同,使用前,请参考产品文档。推荐使用 [Alibaba Cloud SDK for PHP][SDK] ,细节已被封装,无需关心风格。 |
||||
|
|
||||
|
|
||||
|
### ROA 请求 |
||||
|
```php |
||||
|
<?php |
||||
|
|
||||
|
use AlibabaCloud\Client\AlibabaCloud; |
||||
|
use AlibabaCloud\Client\Exception\ClientException; |
||||
|
use AlibabaCloud\Client\Exception\ServerException; |
||||
|
|
||||
|
try { |
||||
|
$result = AlibabaCloud::roa() |
||||
|
->regionId('cn-hangzhou') // 指定请求的区域,不指定则使用客户端区域、默认区域 |
||||
|
->product('CS') // 指定产品 |
||||
|
->version('2015-12-15') // 指定产品版本 |
||||
|
->action('DescribeClusterServices') // 指定产品接口 |
||||
|
->serviceCode('cs') // 设置 ServiceCode 以备寻址,非必须 |
||||
|
->endpointType('openAPI') // 设置类型,非必须 |
||||
|
->method('GET') // 指定请求方式 |
||||
|
->host('cs.aliyun.com') // 指定域名则不会寻址,如认证方式为 Bearer Token 的服务则需要指定 |
||||
|
->pathPattern('/clusters/[ClusterId]/services') // 指定ROA风格路径规则 |
||||
|
->withClusterId('123456') // 为路径中参数赋值,方法名:with + 参数 |
||||
|
->request(); // 发起请求并返回结果对象,请求需要放在设置的最后面 |
||||
|
|
||||
|
print_r($result->toArray()); |
||||
|
|
||||
|
} catch (ClientException $exception) { |
||||
|
print_r($exception->getErrorMessage()); |
||||
|
} catch (ServerException $exception) { |
||||
|
print_r($exception->getErrorMessage()); |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
### RPC 请求 |
||||
|
```php |
||||
|
<?php |
||||
|
|
||||
|
use AlibabaCloud\Client\AlibabaCloud; |
||||
|
use AlibabaCloud\Client\Exception\ClientException; |
||||
|
use AlibabaCloud\Client\Exception\ServerException; |
||||
|
|
||||
|
try { |
||||
|
$result = AlibabaCloud::rpc() |
||||
|
->product('Cdn') |
||||
|
->version('2014-11-11') |
||||
|
->action('DescribeCdnService') |
||||
|
->method('POST') |
||||
|
->request(); |
||||
|
|
||||
|
print_r($result->toArray()); |
||||
|
|
||||
|
} catch (ClientException $exception) { |
||||
|
print_r($exception->getErrorMessage()); |
||||
|
} catch (ServerException $exception) { |
||||
|
print_r($exception->getErrorMessage()); |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
|
||||
|
## 文档 |
||||
|
* [先决条件](/docs/zh-CN/0-Prerequisites.md) |
||||
|
* [安装](/docs/zh-CN/1-Installation.md) |
||||
|
* [客户端和凭证](/docs/zh-CN/2-Client.md) |
||||
|
* [请求](/docs/zh-CN/3-Request.md) |
||||
|
* [结果](/docs/zh-CN/4-Result.md) |
||||
|
* [区域](/docs/zh-CN/5-Region.md) |
||||
|
* [域名](/docs/zh-CN/6-Host.md) |
||||
|
* [SSL 验证](/docs/zh-CN/7-Verify.md) |
||||
|
* [调试](/docs/zh-CN/8-Debug.md) |
||||
|
* [日志](/docs/zh-CN/9-Log.md) |
||||
|
* [测试](/docs/zh-CN/10-Test.md) |
||||
|
|
||||
|
|
||||
|
## 问题 |
||||
|
[提交 Issue](https://github.com/aliyun/openapi-sdk-php-client/issues/new/choose),不符合指南的问题可能会立即关闭。 |
||||
|
|
||||
|
|
||||
|
## 发行说明 |
||||
|
每个版本的详细更改记录在[发行说明](/CHANGELOG.md)中。 |
||||
|
|
||||
|
|
||||
|
## 贡献 |
||||
|
提交 Pull Request 之前请阅读[贡献指南](/CONTRIBUTING.md)。 |
||||
|
|
||||
|
|
||||
|
## 相关 |
||||
|
* [阿里云服务 Regions & Endpoints][endpoints] |
||||
|
* [OpenAPI Explorer][open-api] |
||||
|
* [Packagist][packagist] |
||||
|
* [Composer][composer] |
||||
|
* [Guzzle中文文档][guzzle-docs] |
||||
|
* [最新源码][latest-release] |
||||
|
|
||||
|
|
||||
|
## 许可证 |
||||
|
[Apache-2.0](/LICENSE.md) |
||||
|
|
||||
|
Copyright (c) 2009-present, Alibaba Cloud All rights reserved. |
||||
|
|
||||
|
|
||||
|
[SDK]: https://github.com/aliyun/openapi-sdk-php |
||||
|
[open-api]: https://api.aliyun.com |
||||
|
[latest-release]: https://github.com/aliyun/openapi-sdk-php-client |
||||
|
[guzzle-docs]: https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html |
||||
|
[composer]: https://getcomposer.org |
||||
|
[packagist]: https://packagist.org/packages/alibabacloud/sdk |
||||
|
[home]: https://home.console.aliyun.com |
||||
|
[aliyun]: https://www.aliyun.com |
||||
|
[regions]: https://help.aliyun.com/document_detail/40654.html |
||||
|
[endpoints]: https://developer.aliyun.com/endpoints |
||||
|
[cURL]: http://php.net/manual/zh/book.curl.php |
||||
|
[OPCache]: http://php.net/manual/zh/book.opcache.php |
||||
|
[xdebug]: http://xdebug.org |
||||
|
[OpenSSL]: http://php.net/manual/zh/book.openssl.php |
||||
|
[client]: https://github.com/aliyun/openapi-sdk-php-client |
||||
@ -0,0 +1,167 @@ |
|||||
|
English | [简体中文](/README-zh-CN.md) |
||||
|
|
||||
|
|
||||
|
# Alibaba Cloud Client for PHP |
||||
|
[](https://packagist.org/packages/alibabacloud/client) |
||||
|
[](https://packagist.org/packages/alibabacloud/client) |
||||
|
[](https://packagist.org/packages/alibabacloud/client) |
||||
|
[](https://packagist.org/packages/alibabacloud/client) |
||||
|
[](https://codecov.io/gh/aliyun/openapi-sdk-php-client) |
||||
|
[](https://travis-ci.org/aliyun/openapi-sdk-php-client) |
||||
|
[](https://ci.appveyor.com/project/aliyun/openapi-sdk-php-client/branch/master) |
||||
|
|
||||
|
|
||||
|
 |
||||
|
|
||||
|
|
||||
|
Alibaba Cloud Client for PHP is a client tool that helps PHP developers manage credentials and send requests, [Alibaba Cloud SDK for PHP][SDK] dependency on this tool. |
||||
|
|
||||
|
|
||||
|
## Online Demo |
||||
|
[API Explorer](https://api.aliyun.com) provides the ability to call the cloud product OpenAPI online, and dynamically generate SDK Example code and quick retrieval interface, which can significantly reduce the difficulty of using the cloud API. |
||||
|
|
||||
|
|
||||
|
## Prerequisites |
||||
|
Your system will need to meet the [Prerequisites](/docs/en-US/0-Prerequisites.md), including having PHP >= 5.5. We highly recommend having it compiled with the cURL extension and cURL 7.16.2+. |
||||
|
|
||||
|
|
||||
|
## Installation |
||||
|
If Composer is already [installed globally on your system](https://getcomposer.org/doc/00-intro.md#globally), run the following in the base directory of your project to install Alibaba Cloud Client for PHP as a dependency: |
||||
|
``` |
||||
|
composer require alibabacloud/client |
||||
|
``` |
||||
|
> Some users may not be able to install due to network problems, you can try to switch the Composer mirror. |
||||
|
|
||||
|
Please see the [Installation](/docs/en-US/1-Installation.md) for more detailed information about installing the Alibaba Cloud Client for PHP through Composer and other means. |
||||
|
|
||||
|
|
||||
|
## Quick Examples |
||||
|
Before you begin, you need to sign up for an Alibaba Cloud account and retrieve your [Credentials](https://usercenter.console.aliyun.com/#/manage/ak). |
||||
|
|
||||
|
### Create Client |
||||
|
```php |
||||
|
<?php |
||||
|
|
||||
|
use AlibabaCloud\Client\AlibabaCloud; |
||||
|
|
||||
|
AlibabaCloud::accessKeyClient('accessKeyId', 'accessKeySecret')->asDefaultClient(); |
||||
|
``` |
||||
|
|
||||
|
|
||||
|
## Request |
||||
|
> Request styles are divided into `ROA` and `RPC`. Different product styles are different. Please refer to the product documentation before using. It is recommended to use [Alibaba cloud SDK for PHP][SDK], the details have been encapsulated, and you do not need to care about the style. |
||||
|
|
||||
|
|
||||
|
### ROA Request |
||||
|
```php |
||||
|
<?php |
||||
|
|
||||
|
use AlibabaCloud\Client\AlibabaCloud; |
||||
|
use AlibabaCloud\Client\Exception\ClientException; |
||||
|
use AlibabaCloud\Client\Exception\ServerException; |
||||
|
|
||||
|
try { |
||||
|
$result = AlibabaCloud::roa() |
||||
|
->regionId('cn-hangzhou') // Specify the requested regionId, if not specified, use the client regionId, then default regionId |
||||
|
->product('CS') // Specify product |
||||
|
->version('2015-12-15') // Specify product version |
||||
|
->action('DescribeClusterServices') // Specify product interface |
||||
|
->serviceCode('cs') // Set ServiceCode for addressing, optional |
||||
|
->endpointType('openAPI') // Set type, optional |
||||
|
->method('GET') // Set request method |
||||
|
->host('cs.aliyun.com') // Location Service will not be enabled if the host is specified. For example, service with a Certification type-Bearer Token should be specified |
||||
|
->pathPattern('/clusters/[ClusterId]/services') // Specify path rule with ROA-style |
||||
|
->withClusterId('123456') // Assign values to parameters in the path. Method: with + Parameter |
||||
|
->request(); // Make a request and return to result object. The request is to be placed at the end of the setting |
||||
|
|
||||
|
print_r($result->toArray()); |
||||
|
|
||||
|
} catch (ClientException $exception) { |
||||
|
print_r($exception->getErrorMessage()); |
||||
|
} catch (ServerException $exception) { |
||||
|
print_r($exception->getErrorMessage()); |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
### RPC Request |
||||
|
```php |
||||
|
<?php |
||||
|
|
||||
|
use AlibabaCloud\Client\AlibabaCloud; |
||||
|
use AlibabaCloud\Client\Exception\ClientException; |
||||
|
use AlibabaCloud\Client\Exception\ServerException; |
||||
|
|
||||
|
try { |
||||
|
$result = AlibabaCloud::rpc() |
||||
|
->product('Cdn') |
||||
|
->version('2014-11-11') |
||||
|
->action('DescribeCdnService') |
||||
|
->method('POST') |
||||
|
->request(); |
||||
|
|
||||
|
print_r($result->toArray()); |
||||
|
|
||||
|
} catch (ClientException $exception) { |
||||
|
print_r($exception->getErrorMessage()); |
||||
|
} catch (ServerException $exception) { |
||||
|
print_r($exception->getErrorMessage()); |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
|
||||
|
## Documentation |
||||
|
* [Prerequisites](/docs/en-US/0-Prerequisites.md) |
||||
|
* [Installation](/docs/en-US/1-Installation.md) |
||||
|
* [Client & Credentials](/docs/en-US/2-Client.md) |
||||
|
* [Request](/docs/en-US/3-Request.md) |
||||
|
* [Result](/docs/en-US/4-Result.md) |
||||
|
* [Region](/docs/en-US/5-Region.md) |
||||
|
* [Host](/docs/en-US/6-Host.md) |
||||
|
* [SSL Verify](/docs/en-US/7-Verify.md) |
||||
|
* [Debug](/docs/en-US/8-Debug.md) |
||||
|
* [Log](/docs/en-US/9-Log.md) |
||||
|
* [Test](/docs/en-US/10-Test.md) |
||||
|
|
||||
|
|
||||
|
## Issues |
||||
|
[Opening an Issue](https://github.com/aliyun/openapi-sdk-php-client/issues/new/choose), Issues not conforming to the guidelines may be closed immediately. |
||||
|
|
||||
|
|
||||
|
## Changelog |
||||
|
Detailed changes for each release are documented in the [release notes](/CHANGELOG.md). |
||||
|
|
||||
|
|
||||
|
## Contribution |
||||
|
Please make sure to read the [Contributing Guide](/CONTRIBUTING.md) before making a pull request. |
||||
|
|
||||
|
|
||||
|
## References |
||||
|
* [Alibaba Cloud Regions & Endpoints][endpoints] |
||||
|
* [OpenAPI Explorer][open-api] |
||||
|
* [Packagist][packagist] |
||||
|
* [Composer][composer] |
||||
|
* [Guzzle Documentation][guzzle-docs] |
||||
|
* [Latest Release][latest-release] |
||||
|
|
||||
|
|
||||
|
## License |
||||
|
[Apache-2.0](/LICENSE.md) |
||||
|
|
||||
|
Copyright (c) 2009-present, Alibaba Cloud All rights reserved. |
||||
|
|
||||
|
|
||||
|
[SDK]: https://github.com/aliyun/openapi-sdk-php |
||||
|
[open-api]: https://api.alibabacloud.com |
||||
|
[latest-release]: https://github.com/aliyun/openapi-sdk-php-client |
||||
|
[guzzle-docs]: http://docs.guzzlephp.org/en/stable/request-options.html |
||||
|
[composer]: https://getcomposer.org |
||||
|
[packagist]: https://packagist.org/packages/alibabacloud/sdk |
||||
|
[home]: https://home.console.aliyun.com |
||||
|
[alibabacloud]: https://www.alibabacloud.com |
||||
|
[regions]: https://www.alibabacloud.com/help/doc-detail/40654.html |
||||
|
[endpoints]: https://developer.aliyun.com/endpoints |
||||
|
[cURL]: http://php.net/manual/en/book.curl.php |
||||
|
[OPCache]: http://php.net/manual/en/book.opcache.php |
||||
|
[xdebug]: http://xdebug.org |
||||
|
[OpenSSL]: http://php.net/manual/en/book.openssl.php |
||||
|
[client]: https://github.com/aliyun/openapi-sdk-php-client |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue