Browse Source

生成word

master V0.0.3
刘道霖 3 years ago
parent
commit
7f735d1015
  1. 1
      .gitignore
  2. 1
      .htaccess
  3. 32
      app/BaseController.php
  4. 53
      app/controller/ArticleController.php
  5. 1
      app/model/Article.php
  6. 0
      nginx.htaccess
  7. 8
      public/.htaccess
  8. 3
      public/article/关于「男人身体」的事儿,女人最关心的都在这儿.doc
  9. 3
      public/article/关于男生「羞羞」的 7 个小知识.doc
  10. 3
      public/article/可乐杀精?精子的生存状况可真够凶险的.......doc
  11. 3
      public/article/如何帮女友 or 老婆买姨妈巾?.doc
  12. 3
      public/article/害羞的男孩看过来:关于遗精那件小事.doc
  13. 3
      public/article/真相 · 男人一辈子只能射精 6000 次?.doc
  14. 4
      public/article/精液真的有营养吗?.doc
  15. 3
      public/article/胡子会不会越刮越粗?关于胡子的 15 个秘密.doc
  16. 3
      public/article/除了啤酒肚,还有哪些原因让男人肚子变大?.doc
  17. 6
      public/article/骑自行车也会影响生殖能力吗?.doc
  18. 5
      public/nginx.htaccess
  19. 3
      route/app.php

1
.gitignore

@ -3,5 +3,6 @@
/runtime
/public/.well-known
/public/uploads
/h5
*.log
.env

1
.htaccess

@ -1 +0,0 @@

32
app/BaseController.php

@ -91,4 +91,36 @@ abstract class BaseController
return $v->failException(true)->check($data);
}
// 获取数组指定key的value
function getValByKey(string $key, array $arr, $default = false)
{
return array_key_exists($key, $arr) ? $arr[$key] : $default;
}
// 应用公共文件
function ApiException($msg = '请求错误',$errorCode = 20000,$statusCode = 404)
{
// abort($errorCode, $msg,[
// 'statusCode' => $statusCode
// ]);
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Headers:content-type,token');
header('Access-Control-Request-Method:GET,POST,DELETE');
if (strtoupper($_SERVER['REQUEST_METHOD']) == 'OPTIONS') {
exit;
}
throw new \app\lib\exception\BaseException(['code' => $errorCode, 'message' => $msg, 'data' => [
'statusCode' => $statusCode
]]);
}
// 成功返回
function showSuccess($data = '',$msg = 'ok',$code = 200){
return json([ 'msg' => $msg, 'data' => $data,'code'=>$code],$code);
}
function showError($msg = 'error',$code = 201){
return json([ 'msg' => $msg ],$code);
}
}

53
app/controller/ArticleController.php

@ -1,18 +1,53 @@
<?php
class ArticleController
namespace app\controller;
use app\BaseController;
use app\model\Article;
class ArticleController extends BaseController
{
public function sendArticle()
{
$list = Article::field("*")->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');
try {
$list = Article::field("*")->select()->toArray();
foreach($list as $value) {
$uuid = md5(time());
$html = $value['content'];
$this->start();
$wordname = $uuid.'/article/'.$value['title'].".doc";
echo $html;
$this->save($wordname);
}
} catch (\Exception $e) {
dd($e);
}
}
function start()
{
ob_start();
echo '<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">';
}
function save($path)
{
echo "</html>";
$data = ob_get_contents();
ob_end_clean();
$this->wirtefile($path, $data);
}
function wirtefile($fn, $data)
{
$fp = fopen($fn, "wb");
fwrite($fp, $data);
fclose($fp);
}
}

1
app/model/Article.php

@ -1,4 +1,5 @@
<?php
namespace app\model;
use app\model\BaseModel;

0
nginx.htaccess

8
public/.htaccess

@ -1,8 +0,0 @@
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>

3
public/article/关于「男人身体」的事儿,女人最关心的都在这儿.doc
File diff suppressed because it is too large
View File

3
public/article/关于男生「羞羞」的 7 个小知识.doc
File diff suppressed because it is too large
View File

3
public/article/可乐杀精?精子的生存状况可真够凶险的.......doc
File diff suppressed because it is too large
View File

3
public/article/如何帮女友 or 老婆买姨妈巾?.doc
File diff suppressed because it is too large
View File

3
public/article/害羞的男孩看过来:关于遗精那件小事.doc
File diff suppressed because it is too large
View File

3
public/article/真相 · 男人一辈子只能射精 6000 次?.doc
File diff suppressed because it is too large
View File

4
public/article/精液真的有营养吗?.doc
File diff suppressed because it is too large
View File

3
public/article/胡子会不会越刮越粗?关于胡子的 15 个秘密.doc
File diff suppressed because it is too large
View File

3
public/article/除了啤酒肚,还有哪些原因让男人肚子变大?.doc
File diff suppressed because it is too large
View File

6
public/article/骑自行车也会影响生殖能力吗?.doc
File diff suppressed because it is too large
View File

5
public/nginx.htaccess

@ -0,0 +1,5 @@
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}

3
route/app.php

@ -14,4 +14,5 @@ Route::get('think', function () {
return 'hello,ThinkPHP6!';
});
Route::get('hello/:name', 'Article/hello');
Route::get('sendArticle', 'ArticleController/sendArticle');
//Route::get('sendArticle', 'ArticleController/sendArticle');
Loading…
Cancel
Save