From be8cfea231baa6989f596a08058078773f624bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E9=81=93=E9=9C=96?= <409729760@qq.com> Date: Wed, 26 Apr 2023 10:30:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .example.env | 1 - app/controller/ArticleController.php | 18 +++ app/controller/Index.php | 17 --- app/model/Article.php | 9 ++ app/model/BaseModel.php | 164 ++++++++++++++++++++++++ composer.json | 3 +- composer.lock | 179 ++++++++++++++++++++++++++- config/database.php | 4 +- route/app.php | 2 +- 9 files changed, 373 insertions(+), 24 deletions(-) delete mode 100644 .example.env create mode 100644 app/controller/ArticleController.php delete mode 100644 app/controller/Index.php create mode 100644 app/model/Article.php create mode 100644 app/model/BaseModel.php diff --git a/.example.env b/.example.env deleted file mode 100644 index c27f74c..0000000 --- a/.example.env +++ /dev/null @@ -1 +0,0 @@ -APP_DEBUG = true [APP] DEFAULT_TIMEZONE = Asia/Shanghai [DATABASE] TYPE = mysql HOSTNAME = 127.0.0.1 DATABASE = test USERNAME = username PASSWORD = password HOSTPORT = 3306 CHARSET = utf8 DEBUG = true [LANG] default_lang = zh-cn \ No newline at end of file diff --git a/app/controller/ArticleController.php b/app/controller/ArticleController.php new file mode 100644 index 0000000..2858a65 --- /dev/null +++ b/app/controller/ArticleController.php @@ -0,0 +1,18 @@ +select()->toArray(); + foreach($list as $value) { + dd(1231); + $content = json_decode(htmlspecialchars_decode($value['content']), true); + $tmp = new \PhpOffice\PhpWord\TemplateProcessor('tmp.docx');//打开模板 + $tmp->setValue('name', '李四');//替换变量name + $tmp->setValue('mobile', '18888888888');//替换变量mobile + $tmp->saveAs('简历.docx'); + } + } +} \ No newline at end of file diff --git a/app/controller/Index.php b/app/controller/Index.php deleted file mode 100644 index 48be096..0000000 --- a/app/controller/Index.php +++ /dev/null @@ -1,17 +0,0 @@ -*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }

:)

ThinkPHP V' . \think\facade\App::version() . '
16载初心不改 - 你值得信赖的PHP框架

[ V6.0 版本由 亿速云 独家赞助发布 ]
'; - } - - public function hello($name = 'ThinkPHP6') - { - return 'hello,' . $name; - } -} diff --git a/app/model/Article.php b/app/model/Article.php new file mode 100644 index 0000000..29d9ce3 --- /dev/null +++ b/app/model/Article.php @@ -0,0 +1,9 @@ +createFields)) { + $M->allowField($M->createFields); + } + } + + // 更新前 + public static function onBeforeUpdate($M){ + // 过滤可更新字段 + if (!empty($M->updateFields)) { + $M->allowField($M->updateFields); + } + } + + // 定义全局的查询范围 + + /** + * 封装简化查询范围(更加语义化,重要) + */ + // 开启状态 + public function scopeStatus($query,$status = 1){ + $query->where('status',$status); + } + + // 搜索器(非常重要) + // 创建时间 + public function searchCreateTimeAttr($query, $value, $data) + { + $query->whereBetweenTime('create_time', $value[0], $value[1]); + } + + // 更新时间 + public function searchUpdateTimeAttr($query, $value, $data) + { + $query->whereBetweenTime('update_time', $value[0], $value[1]); + } + + // 获取器(处理输出字段) + // 常用增删改查方法 + /** + * 1. 修改状态 + * 前提: + * (1) 参数:id和status + * (2) 使用 validate 的isExist + */ + public function _UpdateStatus() + { + $request = request(); + return $request->Model->save([ + 'status'=>$request->param('status') + ]); + } + + // 判断当前用户是否有操作该信息的权限 + public function __checkActionAuth(){ + $request = request(); + if ($request->Model->user_id !== $request->UserModel->id) { + return ApiException('非法操作'); + } + } + + // 获取文件完整url + public function getFileUrl($url='') + { + if (!$url) return; + //return url($url,'',false,true); + return $url; + } + + + // 列表 + public function Mlist(){ + $param = request()->param(); + $limit = intval(getValByKey('limit',$param,10)); + $page = intval(getValByKey('page',$param,1)); + $totalCount = $this->count(); + $list = $this->page($page,$limit)->order([ + 'order'=>'desc', + 'id'=>'desc' + ])->select(); + return [ + 'list'=>$list, + 'totalCount'=>$totalCount + ]; + } + // 创建 + public function Mcreate(){ + return $this->create(request()->param()); + } + // 修改 + public function Mupdate(){ + $param = request()->param(); + return request()->Model->save($param); + } + // 删除 + public function Mdelete(){ + return request()->Model->delete(); + } + + public function MdeleteAll(){ + $param = request()->param('ids'); + // 找到所有数据并删除 + return $this->where('id','in',$param)->delete(); + } + + + //根据token 判断是用户端还是后台 编辑 + public function setAuthorAttr($value,$data) + { + $token=request()->header('token'); + // 获取用户信息 + $user = cms_getUser([ + 'token'=>$token, + 'tag'=>'user' + ]); + if($user['id']){ + if(isset($data['id'])&&$data['id']){ + $this->set('update_user',$data['author']); + }else{ + $this->set('create_user',$data['author']); + } + } else { + if(isset($data['id'])&&$data['id']){ + $this->set('update_author',$data['author']); + }else{ + $this->set('create_author',$data['author']); + } + + } + } + + protected $append = [ + // 'create_author'=>'create_author_text', + // 'create_user'=>'create_user_text', + // 'update_author'=>'update_author_text', + // 'update_user'=>'update_user_text', + ]; + + +} diff --git a/composer.json b/composer.json index cef5f5b..ef3aac3 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,8 @@ "php": ">=7.2.5", "topthink/framework": "^6.1.0", "topthink/think-orm": "^2.0", - "topthink/think-filesystem": "^1.0" + "topthink/think-filesystem": "^1.0", + "phpoffice/phpword": "^1.0" }, "require-dev": { "symfony/var-dumper": "^4.2", diff --git a/composer.lock b/composer.lock index 1367741..b722432 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,70 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "66559480dea8532df6a457e4e313a236", + "content-hash": "3a66a32e287f1334c07eaa62deb888c8", "packages": [ + { + "name": "laminas/laminas-escaper", + "version": "2.12.0", + "source": { + "type": "git", + "url": "https://github.com/laminas/laminas-escaper.git", + "reference": "ee7a4c37bf3d0e8c03635d5bddb5bb3184ead490" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laminas/laminas-escaper/zipball/ee7a4c37bf3d0e8c03635d5bddb5bb3184ead490", + "reference": "ee7a4c37bf3d0e8c03635d5bddb5bb3184ead490", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-mbstring": "*", + "php": "^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0" + }, + "conflict": { + "zendframework/zend-escaper": "*" + }, + "require-dev": { + "infection/infection": "^0.26.6", + "laminas/laminas-coding-standard": "~2.4.0", + "maglnet/composer-require-checker": "^3.8.0", + "phpunit/phpunit": "^9.5.18", + "psalm/plugin-phpunit": "^0.17.0", + "vimeo/psalm": "^4.22.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Laminas\\Escaper\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Securely and safely escape HTML, HTML attributes, JavaScript, CSS, and URLs", + "homepage": "https://laminas.dev", + "keywords": [ + "escaper", + "laminas" + ], + "support": { + "chat": "https://laminas.dev/chat", + "docs": "https://docs.laminas.dev/laminas-escaper/", + "forum": "https://discourse.laminas.dev", + "issues": "https://github.com/laminas/laminas-escaper/issues", + "rss": "https://github.com/laminas/laminas-escaper/releases.atom", + "source": "https://github.com/laminas/laminas-escaper" + }, + "funding": [ + { + "url": "https://funding.communitybridge.org/projects/laminas-project", + "type": "community_bridge" + } + ], + "time": "2022-10-10T10:11:09+00:00" + }, { "name": "league/flysystem", "version": "1.1.10", @@ -207,6 +269,119 @@ ], "time": "2022-04-17T13:12:02+00:00" }, + { + "name": "phpoffice/phpword", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/PHPOffice/PHPWord.git", + "reference": "8521612b39edeec9055d3688ad555342a40857dd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPOffice/PHPWord/zipball/8521612b39edeec9055d3688ad555342a40857dd", + "reference": "8521612b39edeec9055d3688ad555342a40857dd", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-xml": "*", + "laminas/laminas-escaper": ">=2.6", + "php": "^7.1|^8.0" + }, + "require-dev": { + "dompdf/dompdf": "^2.0", + "ext-gd": "*", + "ext-libxml": "*", + "ext-zip": "*", + "mpdf/mpdf": "^8.1", + "php-coveralls/php-coveralls": "^2.5", + "phpmd/phpmd": "^2.13", + "phpunit/phpunit": ">=7.0", + "symfony/process": "^4.4", + "tecnickcom/tcpdf": "^6.5" + }, + "suggest": { + "dompdf/dompdf": "Allows writing PDF", + "ext-gd2": "Allows adding images", + "ext-xmlwriter": "Allows writing OOXML and ODF", + "ext-xsl": "Allows applying XSL style sheet to headers, to main document part, and to footers of an OOXML template", + "ext-zip": "Allows writing OOXML and ODF" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-develop": "0.19-dev" + } + }, + "autoload": { + "psr-4": { + "PhpOffice\\PhpWord\\": "src/PhpWord" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0" + ], + "authors": [ + { + "name": "Mark Baker" + }, + { + "name": "Gabriel Bull", + "email": "me@gabrielbull.com", + "homepage": "http://gabrielbull.com/" + }, + { + "name": "Franck Lefevre", + "homepage": "https://rootslabs.net/blog/" + }, + { + "name": "Ivan Lanin", + "homepage": "http://ivan.lanin.org" + }, + { + "name": "Roman Syroeshko", + "homepage": "http://ru.linkedin.com/pub/roman-syroeshko/34/a53/994/" + }, + { + "name": "Antoine de Troostembergh" + } + ], + "description": "PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)", + "homepage": "https://phpword.readthedocs.io/", + "keywords": [ + "ISO IEC 29500", + "OOXML", + "Office Open XML", + "OpenDocument", + "OpenXML", + "PhpOffice", + "PhpWord", + "Rich Text Format", + "WordprocessingML", + "doc", + "docx", + "html", + "odf", + "odt", + "office", + "pdf", + "php", + "reader", + "rtf", + "template", + "template processor", + "word", + "writer" + ], + "support": { + "issues": "https://github.com/PHPOffice/PHPWord/issues", + "source": "https://github.com/PHPOffice/PHPWord/tree/1.0.0" + }, + "time": "2022-11-15T20:24:50+00:00" + }, { "name": "psr/cache", "version": "1.0.1", @@ -1066,5 +1241,5 @@ "php": ">=7.2.5" }, "platform-dev": [], - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.3.0" } diff --git a/config/database.php b/config/database.php index ba2ae8c..52f942f 100644 --- a/config/database.php +++ b/config/database.php @@ -24,7 +24,7 @@ return [ // 数据库类型 'type' => env('database.type', 'mysql'), // 服务器地址 - 'hostname' => env('database.hostname', '127.0.0.1'), + 'hostname' => env('database.hostname', '101.132.127.165'), // 数据库名 'database' => env('database.database', ''), // 用户名 @@ -32,7 +32,7 @@ return [ // 密码 'password' => env('database.password', ''), // 端口 - 'hostport' => env('database.hostport', '3306'), + 'hostport' => env('database.hostport', '10139'), // 数据库连接参数 'params' => [], // 数据库编码默认采用utf8 diff --git a/route/app.php b/route/app.php index d8e09e3..93db0b5 100644 --- a/route/app.php +++ b/route/app.php @@ -14,4 +14,4 @@ Route::get('think', function () { return 'hello,ThinkPHP6!'; }); -Route::get('hello/:name', 'index/hello'); +Route::get('hello/:name', 'Article/hello');