huwhois 5 ماه پیش
والد
کامیت
e34e08f141

+ 1 - 16
app/command/FileConsole.php

@@ -71,7 +71,7 @@ class FileConsole extends Command
     }
 
     /**
-     * 建立文件管理目录索引(递归遍历目录)
+     * 图片添加水印
      */
     public function markwater($dir, $savepath = 'test/cpw', $watermark = "test/watermark2.png")
     {
@@ -135,19 +135,4 @@ class FileConsole extends Command
             }
         }
     }
-
-    /**
-     * 清除无效目录索引
-     */
-    public function clear($dir = '')
-    {
-        $list = FileManager::select();
-        
-        foreach ($list as $value) {
-            $file = app()->getRootPath() . 'public/' . $value->filepath;
-            if (!is_file($file)) {
-                FileManager::destroy($value->fileid);
-            }
-        }
-    }
 }

+ 0 - 64
app/command/MakeController.php

@@ -1,64 +0,0 @@
-<?php
-
-declare (strict_types = 1);
-
-namespace app\common\command;
-
-// 引入框架内置类
-use think\console\Input;
-use think\console\Output;
-use think\console\input\Argument;
-use think\console\input\Option;
-use think\console\Command;
-
-use app\facade\ControllerUtils;
-
-class MakeController extends Command
-{
-    protected $type = "Model";
-
-    protected function configure()
-    {
-        $this->setName('makecontroller')
-            ->addArgument('name', Argument::OPTIONAL, "console name")
-            ->setDescription('Create a new model class');
-    }
-
-    protected function execute(Input $input, Output $output)
-    {
-        $name = trim($input->getArgument('name'));
-
-        $classname = $this->getClassName($name);
-
-        try {
-            ControllerUtils::makeModel($classname);
-            $output->writeln('<info>' . $this->type . ':' . $classname . ' created successfully.</info>');
-        } catch (\Exception $e) {
-            $output->writeln('<error>' . $e->getMessage() . '</error>');
-        }
-    }
-
-    protected function getClassName($name)
-    {
-        if (strpos($name, '\\') !== false) {
-            return $name;
-        }
-
-        if (strpos($name, '@')) {
-            [$app, $name] = explode('@', $name);
-        } else {
-            $app = '';
-        }
-
-        if (strpos($name, '/') !== false) {
-            $name = str_replace('/', '\\', $name);
-        }
-
-        return $this->getNamespace($app) . '\\' . $name;
-    }
-
-    protected function getNamespace(string $app): string
-    {
-        return 'app' . ($app ? '\\' . $app : '') . '\\controller';
-    }
-}

+ 0 - 64
app/command/MakeModel.php

@@ -1,64 +0,0 @@
-<?php
-
-declare (strict_types = 1);
-
-namespace app\common\command;
-
-// 引入框架内置类
-use think\console\Input;
-use think\console\Output;
-use think\console\input\Argument;
-use think\console\input\Option;
-use think\console\Command;
-
-use app\facade\ModelUtils;
-
-class MakeModel extends Command
-{
-    protected $type = "Model";
-
-    protected function configure()
-    {
-        $this->setName('makemodel')
-            ->addArgument('name', Argument::OPTIONAL, "console name")
-            ->setDescription('Create a new model class');
-    }
-
-    protected function execute(Input $input, Output $output)
-    {
-        $name = trim($input->getArgument('name'));
-
-        $classname = $this->getClassName($name);
-
-        try {
-            ModelUtils::makeModel($classname);
-            $output->writeln('<info>' . $this->type . ':' . $classname . ' created successfully.</info>');
-        } catch (\Exception $e) {
-            $output->writeln('<error>' . $e->getMessage() . '</error>');
-        }
-    }
-
-    protected function getClassName($name)
-    {
-        if (strpos($name, '\\') !== false) {
-            return $name;
-        }
-
-        if (strpos($name, '@')) {
-            [$app, $name] = explode('@', $name);
-        } else {
-            $app = '';
-        }
-
-        if (strpos($name, '/') !== false) {
-            $name = str_replace('/', '\\', $name);
-        }
-
-        return $this->getNamespace($app) . '\\' . $name;
-    }
-
-    protected function getNamespace(string $app): string
-    {
-        return 'app' . ($app ? '\\' . $app : '') . '\\model';
-    }
-}

+ 86 - 0
app/command/TagArticleConsole.php

@@ -0,0 +1,86 @@
+<?php
+
+declare (strict_types = 1);
+
+namespace app\command;
+
+// 引入框架内置类
+use think\console\Input;
+use think\console\Output;
+use think\console\input\Argument;
+use think\console\Command;
+use think\facade\Db;
+
+use app\model\Tag;
+use app\model\Article;
+use app\model\TagArticle;
+
+class TagArticleConsole extends Command
+{
+    protected function configure()
+    {
+        $this->setName('tagindex')
+            ->addArgument('name', Argument::OPTIONAL, "console name")
+            ->setDescription('Create a new tag index');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        $name = trim($input->getArgument('name'));
+
+        $name = $name ?: 'thinkphp';
+
+        $this->$name();
+    }
+
+    public function thinkphp()
+    {
+        echo "hello thinkphp";
+    }
+
+    public function makeTagArticleIndex()
+    {
+        // 查找所有keywords
+        $keywordsList = Db::table("hu_article")->field('id,cid,keywords')->select();
+
+        $i = $j = 0;
+        foreach ($keywordsList as $value) {
+            $id = $value['id'];
+            $cid = $value['cid'];
+            $keywords = $value['keywords'];
+            $tags = explode(",",$keywords);
+            foreach ($tags as $val) {
+                $tagname = trim($val);
+                if ($tagname) {
+                    $tag = Tag::where('tagname', $tagname)->findOrEmpty();
+                    if ($tag->isEmpty()) {
+                        $tag->tagname = $tagname;
+                        $tag->nums = 1;
+                        $tag->save();
+                        TagArticle::create([
+                            'tid' => $tag->id,
+                            'aid' => $id,
+                            'cid' => $cid
+                        ]);
+                        $i++;
+                        $j++;
+                    } else {
+                        $tagArticle = TagArticle::where('aid', $id)->where('tid', $tag->id)->findOrEmpty();
+                        if ($tagArticle->isEmpty()) {
+                            $tagArticle->aid = $id;
+                            $tagArticle->cid = $cid;
+                            $tagArticle->tid = $tag->id;
+                            $tagArticle->save();
+                            
+                            $tag->nums += 1;
+                            $tag->save();
+                            $j++;
+                        }
+                    }
+                }
+            }
+        }
+
+        echo "新增标签:" . $i . "\n" . "新增标签关联文章" . $j . "\n";
+    }
+}

+ 1 - 1
app/controller/Article.php

@@ -167,7 +167,7 @@ class Article extends Base
             throw new HttpException(404, '标签不存在');
         }
 
-        $list = TagArticle::queryList($tag->tagid);
+        $list = TagArticle::queryList($tag->tid);
 
         View::assign([
             'list' => $list,

+ 29 - 9
app/controller/sys/Article.php

@@ -18,7 +18,7 @@ use think\facade\View;
 
 use app\model\Category as CategoryModel;
 use app\model\Article as ArticleModel;
-use app\model\TagArticle As TagArticleModel;
+use app\model\TagArticle as TagArticleModel;
 use app\utils\FileUtils;
 use app\utils\ReUtils;
 
@@ -78,22 +78,21 @@ class Article extends Base
 
                     $addTas = array_diff($newTags, $oldTags);
                     $subTas = array_diff($oldTags, $newTags);
-                    TagArticleModel::saveArticleTag($addTas, $article->id, $article->cid);
-                    TagArticleModel::delArticleTag($subTas, $article->id);
+
+                    TagArticleModel::saveArticleTag($addTas, (int) $article->id, (int)$article->cid);
+                    TagArticleModel::delArticleTag($subTas, (int) $article->id);
                 } else {
                     $params['userid'] = $this->getSysUser()->userid;
-                    $params['username'] = $this->getSysUser()->nickname == "" ?: $this->getSysUser()->username;
+                    $params['username'] = $this->getSysUser()->nickname != "" ? $this->getSysUser()->nickname : $this->getSysUser()->username;
                     unset($params['id']);
                     $article = ArticleModel::create($params);
 
                     $tags = explode(",", $article->keywords);
 
-                    TagArticleModel::saveArticleTag($tags, $article->id, $article->cid);
+                    TagArticleModel::saveArticleTag($tags, (int) $article->id, (int) $article->cid);
                 }
             } catch (\Exception $e) {
-                $msg = $e->getMessage();
-
-                $this->error("错误提示:" . $msg);
+                $this->error("错误提示:" . $e->getMessage());
             }
             $this->success('操作成功', (string) url('/sys/article/index'));
         } else {
@@ -149,9 +148,30 @@ class Article extends Base
         try {
             Db::execute($sql);
         } catch (Exception $e) {
-            return ReUtils::error();
+            return ReUtils::error($e->getMessage());
         }
 
         return ReUtils::success();
     }
+
+    /**
+     * 删除
+     * @param int|array $id  info id
+     * @return array
+     */
+    public function delete($id)
+    {
+        if ($this->request->isPost()) {
+            if (ArticleModel::destroy($id)) {
+                if (is_array($id)) {
+                    TagArticleModel::where('aid',"IN",$id)->delete();
+                } else {
+                    TagArticleModel::where('aid',"=",$id)->delete();
+                }
+                return ReUtils::success();
+            } else {
+                return ReUtils::error();
+            }
+        }
+    }
 }

+ 0 - 22
app/controller/sys/Base.php

@@ -115,28 +115,6 @@ abstract class Base
             View::assign('layer', false);
         }
 
-        // // pjax
-        // if (Request::has('_pjax')) {
-        //     View::assign(['pjax' => true]);
-        // } else {
-        //     View::assign(['pjax' => false]);
-        // }
-
-        // 内容管理,获取栏目列表
-        // if (class_exists('\app\model\Cate')) {
-        //     $cates = \app\model\Cate::getList();
-        // }
-        // View::assign(['cates' => unlimitedForLayer($cates['data'] ?? [])]);
-
-        // index应用地址
-        // $domainBind = Config::get('app.domain_bind');
-        // if ($domainBind) {
-        //     $domainBindKey = array_search('index', $domainBind);
-        //     $domainBindKey = $domainBindKey == '*' ? 'www.' : ($domainBindKey ? $domainBindKey . '.' : '');
-        //     $indexUrl      = Request::scheme() . '://' . $domainBindKey . Request::rootDomain() . '/';
-        // }
-        // View::assign(['indexUrl' => $indexUrl ?? '/']);
-
         // 查询系统设置
         $system       = \app\model\System::find(1);
         $this->system = $system;

+ 7 - 6
app/controller/sys/SysRole.php

@@ -6,6 +6,7 @@ use think\facade\View;
 use app\model\SysMenu;
 use app\model\SysUser;
 use app\model\SysRole as SysRoleModel;
+use app\utils\ReUtils;
 use think\facade\Session;
 
 class SysRole extends Base
@@ -83,23 +84,23 @@ class SysRole extends Base
 
             if (is_array($id)) {
                 if (in_array('1', $id)) {
-                    return ['status'=>0,'msg'=>'超级管理员无法删除'];
+                    return ReUtils::error("超级管理员无法删除");
                 }
                 if (in_array($U_role_id, $id)) {
-                    return ['status'=>0,'msg'=>'当前登录用户角色无法删除'];
+                    return ReUtils::error("当前登录用户角色无法删除");
                 }
             } else {
                 if ($id == 1) {
-                    return ['status'=>0,'msg'=>'超级管理员无法删除'];
+                    return ReUtils::error("超级管理员无法删除");
                 }
                 if ($id == $U_role_id) {
-                    return ['status'=>0,'msg'=>'当前登录用户角色无法删除'];
+                    return ReUtils::error("当前登录用户角色无法删除");
                 }
             }
             if (SysRoleModel::destroy($id)) {
-                return ['code' => 1,'msg'=>'操作成功'];
+                return ReUtils::success();
             } else {
-                return ['code' => 0,'msg'=>'操作失败'];
+                return ReUtils::error();
             }
         }
     }

+ 1 - 2
app/event.php

@@ -9,8 +9,7 @@ return [
         'HttpRun'  => [],
         'HttpEnd'  => [],
         'LogLevel' => [],
-        'LogWrite' => [],
-        'SysLog'   => ['app\listener\SysUserLog'],
+        'LogWrite' => []
     ],
 
     'subscribe' => [

+ 0 - 21
app/facade/ControllerUtils.php

@@ -1,21 +0,0 @@
-<?php
-declare(strict_types=1);
-
-namespace app\facade;
-
-use think\Facade;
-
-/**
- * @see \app\utils\ControllerUtils
- * @package app\facade
- * @mixin \app\utils\ControllerUtils
- * @method static void makeModel()
- * @method static string codeModel()
- */
-class ControllerFacade extends Facade
-{
-    protected static function getFacadeClass()
-    {
-        return 'app\utils\ControllerUtils';
-    }
-}

+ 0 - 21
app/facade/ModelFacade.php

@@ -1,21 +0,0 @@
-<?php
-declare(strict_types=1);
-
-namespace app\facade;
-
-use think\Facade;
-
-/**
- * @see \app\utils\ModelUtils
- * @package app\facade
- * @mixin \app\utils\ModelUtils
- * @method static void makeModel()
-* @method static string codeModel()
- */
-class ModelFacade extends Facade
-{
-    protected static function getFacadeClass()
-    {
-        return 'app\utils\ModelUtils';
-    }
-}

+ 0 - 20
app/facade/VueFacade.php

@@ -1,20 +0,0 @@
-<?php
-declare(strict_types=1);
-
-namespace app\facade;
-
-use think\Facade;
-
-/**
- * @see \app\utils\VueUtils
- * @package app\facade
- * @mixin \app\utils\VueUtils
- * @method static string codeModel()
- */
-class VueFacade extends Facade
-{
-    protected static function getFacadeClass()
-    {
-        return 'app\utils\VueUtils';
-    }
-}

+ 0 - 15
app/listener/SysUserLog.php

@@ -1,15 +0,0 @@
-<?php
-declare (strict_types = 1);
-
-namespace app\listener;
-
-use app\model\SysLog;
-
-class SysUserLog
-{
-    public function handle($admin)
-    {
-        // 事件监听处理
-        SysLog::record($admin);
-    }
-}

+ 14 - 7
app/middleware/Admin.php

@@ -13,6 +13,7 @@ use think\facade\Config;
 use think\facade\Session;
 use think\facade\Request;
 use think\exception\HttpResponseException;
+use think\facade\View;
 
 class Admin
 {
@@ -48,9 +49,8 @@ class Admin
         ];
         
         $action = Request::action();
-
-        if ($action != 'index' && !in_array($route, $allow)) {
-            \app\model\SysLog::record();
+        if ($action != 'index' && !in_array($route, $allow) && !(Request::isGet())) {
+            \app\model\SysLog::record($route);
         }
     }
 
@@ -78,7 +78,8 @@ class Admin
             'index/index',      // 首页
             'index/usedspace',      //  使用空间
             'index/clearcache',      // 清除缓存
-            'file_manager/uploadimg',      // 图片上传
+            'file_manager/uploadImage',      // 图片上传
+            'file_manager/ckeditorUploadImage',      // 图片上传
         ];
 
         // 查询所有不验证的方法并放入白名单
@@ -122,11 +123,17 @@ class Admin
         $type = Request::isJson() || Request::isAjax() ? 'json' : 'html';;
 
         if ('html' == strtolower($type)) {
-            $type = 'view';
             $dispatch_error_tmpl = app()->getRootPath().'/vendor/liliuwei/thinkphp-jump/src/tpl/dispatch_jump.tpl';
-            $response = Response::create($dispatch_error_tmpl, $type)->assign($result)->header([]);
+            
+            View::assign($result);
+        
+            View::engine()->layout(false);
+            
+            $data = View::fetch($dispatch_error_tmpl);
+
+            $response = Response::create($data, $type);
         } else {
-            $response = Response::create($result, $type)->header([]);
+            $response = Response::create($result, $type);
         }
 
         throw new HttpResponseException($response);

+ 10 - 10
app/model/Article.php

@@ -14,8 +14,8 @@ class Article extends Base
     protected $pk = 'id';
 
     protected $schema = [
-        "id"          => "int",
-        "cid"         => "int",
+        "id"          => "integer",
+        "cid"         => "integer",
         "title"       => "varchar",
         "writer"      => "varchar",
         "source"      => "varchar",
@@ -23,14 +23,14 @@ class Article extends Base
         "keywords"    => "varchar",
         "summary"     => "varchar",
         "content"     => "varchar",
-        "discussed"   => "int",
-        "status"      => "int",
-        "top"         => "int",
-        "sort"       => "int",
-        "hits"        => "int",
-        "likes"       => "int",
-        "content_type"=> "int",
-        "userid"      => "int",
+        "discussed"   => "integer",
+        "status"      => "integer",
+        "top"         => "integer",
+        "sort"       => "integer",
+        "hits"        => "integer",
+        "likes"       => "integer",
+        "content_type"=> "integer",
+        "userid"      => "integer",
         "username"    => "varchar",
         "create_time" => "int",
         "update_time" => "int"

+ 10 - 1
app/model/ArticleDolikeLog.php

@@ -3,5 +3,14 @@ namespace app\model;
 
 class ArticleDolikeLog extends \think\Model
 {
-    
+    protected $pk = 'id';
+
+    protected $schema = [
+        "id"          => "int",
+        "aid"         => "int",
+        "ip"          => "varchar",
+        "create_time" => "int"
+    ];
+
+    protected $autoWriteTimestamp = false;
 }

+ 2 - 4
app/model/SysLog.php

@@ -25,7 +25,7 @@ class SysLog extends Model
     }
 
     // 管理员日志记录
-    public static function record()
+    public static function record($route = "")
     {
         // 入库信息
         $userid   = Session::get('adminuser.userid', 0);
@@ -37,9 +37,7 @@ class SysLog extends Model
         $userAgent = Request::server('HTTP_USER_AGENT');
 
         // 标题处理
-        $route = strtolower(preg_replace('/(?<=[a-z])([A-Z])/', '_$1', Request::controller())) . '/' . strtolower(preg_replace('/(?<=[a-z])([A-Z])/', '_$1', Request::action()));
-        
-        $active =  \app\model\SysMenu::where('url', $route)->find();
+        $active = \app\model\SysMenu::where('url', $route)->find();
 
         $title =  $active != null ? $active['name'] : "";
 

+ 3 - 2
app/model/Tag.php

@@ -13,9 +13,10 @@ class Tag extends Base
         "id"       => "int",
         "tagname"     => "varchar",
         "nums"        => "int",
-        "create_time" => "int",
-        "update_time" => "int"
+        "create_time" => "int"
     ];
+    // 关闭自动写入update_time字段
+    protected $updateTime = false;
 
     public static function queryList($tagname)
     {

+ 5 - 4
app/model/TagArticle.php

@@ -43,9 +43,8 @@ class TagArticle extends Base
     public static function saveArticleTag(array $tags, int $aid, int $cid)
     {
         foreach ($tags as  $tagname) {
-            $tag = Tag::where('tagname', $tagname)->find();
-            if ($tag == null) {
-                $tag = new Tag();
+            $tag = Tag::where('tagname', $tagname)->findOrEmpty();
+            if ($tag->isEmpty()) {
                 $tag->tagname = $tagname;
             }
             $tag->nums += 1;
@@ -62,11 +61,13 @@ class TagArticle extends Base
     public static function delArticleTag(array $tags, int $aid)
     {
         foreach ($tags as  $tagname) {
-            $tag = Tag::where('tagname', $tagname)->find();
+            $tag = Tag::where('tagname', $tagname)->findOrEmpty();
 
             if ($tag != null) {
                 $tag->nums = $tag->nums - 1;
                 
+                $tag->nums = $tag->nums > 0 ? $tag->nums : 0;
+
                 $tag->save();
 
                 self::where(['aid'=>$aid, 'tid'=>$tag->id])->delete();

+ 1 - 2
config/console.php

@@ -6,7 +6,6 @@ return [
     // 指令定义
     'commands' => [
         'fileconsole' => 'app\command\FileConsole',
-        'makemodel' => 'app\command\MakeModel',
-        'makecontroller' => 'app\command\MakeController',
+        'tagarticleconsole' => 'app\command\TagArticleConsole'
     ],
 ];

+ 49 - 0
view/sys/public/jump.tpl

@@ -0,0 +1,49 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
+    <title>跳转提示</title>
+    <style type="text/css">
+        *{ padding: 0; margin: 0; }
+        body{ background: #fff; font-family: "Microsoft Yahei","Helvetica Neue",Helvetica,Arial,sans-serif; color: #333; font-size: 16px; }
+        .system-message{ padding: 24px 48px; }
+        .system-message h1{ font-size: 100px; font-weight: normal; line-height: 120px; margin-bottom: 12px; }
+        .system-message .jump{ padding-top: 10px; }
+        .system-message .jump a{ color: #333; }
+        .system-message .success,.system-message .error{ line-height: 1.8em; font-size: 36px; }
+        .system-message .detail{ font-size: 12px; line-height: 20px; margin-top: 12px; display: none; }
+    </style>
+</head>
+<body>
+    <div class="system-message">
+        <?php switch ($code) {?>
+            <?php case 1:?>
+            <h1>:)</h1>
+            <p class="success"><?php echo(strip_tags($msg));?></p>
+            <?php break;?>
+            <?php case 0:?>
+            <h1>:(</h1>
+            <p class="error"><?php echo(strip_tags($msg));?></p>
+            <?php break;?>
+        <?php } ?>
+        <p class="detail"></p>
+        <p class="jump">
+            页面自动 <a id="href" href="<?php echo($url);?>">跳转</a> 等待时间: <b id="wait"><?php echo($wait);?></b>
+        </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>

+ 1 - 1
view/sys/sys_log/index.html

@@ -38,7 +38,7 @@
                     <td>{$val.create_time}</td>
                     <td>{$val.ip}</td>
                     <td class="td-manage">
-                        <a title="删除" href="javascript:;" onclick="del(this,'{$val.loginid}')" class="ml-5 btn btn-danger radius">
+                        <a title="删除" href="javascript:;" onclick="del(this,'{$val.id}')" class="ml-5 btn btn-danger radius">
                             <i class="Hui-iconfont">&#xe6e2;</i>
                         </a>
                     </td>

+ 4 - 2
view/sys/sys_role/index.html

@@ -1,6 +1,8 @@
 <article class="cl pd-20">
     <div class="cl pd-5 bg-1 bk-gray">
         <span class="l">
+            <a href="javascript:void(0);" onclick="del_all()" class="btn btn-danger radius">
+                <i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
             <a class="btn btn-primary radius" href="javascript:;" onclick="save(0);">
                 <i class="Hui-iconfont">&#xe600;</i> 添加角色</a>
         </span>
@@ -24,9 +26,9 @@
             <tbody>
                 {foreach $list as $val}
                 <tr class="text-c">
-                    <!-- <td>
+                    <td>
                         <input type="checkbox" value="{$val.roleid}" name="checkbox[]">
-                    </td> -->
+                    </td>
                     <td>{$val.roleid}</td>
                     <td>{$val.name}</td>
                     <td>{$val.permissions}</td>