You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
4.3 KiB
138 lines
4.3 KiB
<?php
|
|
|
|
namespace app\controller;
|
|
|
|
use app\BaseController;
|
|
use app\model\Article;
|
|
use think\facade\Db;
|
|
|
|
class ArticleController extends BaseController
|
|
{
|
|
|
|
public function sendArticle()
|
|
{
|
|
try {
|
|
$list = Article::where('status', 0)->where('publish_status', 2)->field("*")->select()->toArray();
|
|
foreach ($list as $value) {
|
|
$uuid = strtoupper(md5($value['id']));
|
|
|
|
//创建文件夹
|
|
$pathname = 'D:/AAAA_文章/' . $uuid;
|
|
if (!is_dir($pathname)) { //若目录不存在则创建之
|
|
mkdir($pathname, 0777, true);
|
|
}
|
|
|
|
//url图片保存本地
|
|
$this->down_img($pathname, $value['cover']);
|
|
$wordname = $pathname . "/a_文章.doc";
|
|
|
|
//html标签类文章转成word
|
|
$html = $value['content'];
|
|
$this->start();
|
|
echo $html;
|
|
$this->save($wordname);
|
|
|
|
file_put_contents($pathname . '/c_标题.txt', $value['title']);
|
|
file_put_contents($pathname . '/d_账号.txt', $value['account']);
|
|
|
|
Article::where('id',$value['id'])->update(['status' => 1]);
|
|
}
|
|
} catch (\Exception $e) {
|
|
dd($e);
|
|
}
|
|
return json(['msg' => 'success', 'data' => '生成成功!', 'code' => 200], 200);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
function down_img($path,$img_url){
|
|
ob_start();
|
|
readfile($img_url);
|
|
$img=ob_get_contents();
|
|
ob_end_clean();
|
|
$filename = '/b_封面图.jpg';
|
|
$fp2=@fopen($path.$filename,'a');
|
|
fwrite($fp2,$img);
|
|
fclose($fp2);
|
|
unset($img,$url);
|
|
}
|
|
|
|
public function articleList()
|
|
{
|
|
$param = request()->param();
|
|
|
|
$list = Article::where(function ($q) use ($param) {
|
|
if(isset($param['publish_status'])){
|
|
$q->where('publish_status',$param['publish_status']);
|
|
}
|
|
if(isset($param['account'])){
|
|
$q->where('account',$param['account']);
|
|
}
|
|
})
|
|
->paginate([
|
|
'list_rows'=> $param["limit"],
|
|
'page' => $param["page"],
|
|
])->toArray();
|
|
return json(['msg' => 'success', 'data' => $list['data'],'count' => $list['total'], 'code' => 200], 200);
|
|
}
|
|
|
|
public function deleteArticle()
|
|
{
|
|
$param = request()->param();
|
|
$data = Article::where('id',$param['id'])->find();
|
|
if($data['status'] == 1){
|
|
return json(['msg' => 'fail', 'data' => '已发布的文章不能删除', 'code' => 201], 201);
|
|
}
|
|
$data->delete();
|
|
return json(['msg' => 'success', 'data' => '删除成功!', 'code' => 200], 200);
|
|
|
|
}
|
|
|
|
public function editArticle()
|
|
{
|
|
$param = request()->param();
|
|
$data = Article::where('id',$param['id'])->find();
|
|
if(empty($data)){
|
|
return json(['msg' => 'fail', 'data' => '文章不存在', 'code' => 201], 201);
|
|
}
|
|
Article::where('id',$param['id'])->update([
|
|
'account' => $param['account'] ?? $data['account'],
|
|
'title' => $param['title'] ?? $data['title'],
|
|
'cover' => $param['cover'] ?? $data['cover'],
|
|
'des' => $param['des'] ?? $data['des'],
|
|
'content' => $param['content'] ?? $data['content'],
|
|
'publish_status' => $param['publish_status'] ?? $data['publish_status'],
|
|
]);
|
|
return json(['msg' => 'success', 'data' => '编辑成功!', 'code' => 200], 200);
|
|
}
|
|
|
|
public function detailArticle()
|
|
{
|
|
$param = request()->param();
|
|
$data = Article::where('id',$param['id'])->find();
|
|
return json(['msg' => 'success', 'data' => $data, 'code' => 200], 200);
|
|
}
|
|
}
|