huwhois 2 лет назад
Родитель
Сommit
06eaeff0b6
2 измененных файлов с 10 добавлено и 343 удалено
  1. 0 211
      app/common/model/Article.php
  2. 10 132
      app/common/model/FileManager.php

+ 0 - 211
app/common/model/Article.php

@@ -1,177 +1,3 @@
-<<<<<<< HEAD
-<?php
-
-declare(strict_types=1);
-
-namespace app\common\model;
-
-use think\exception\HttpException;
-
-use app\common\model\Base;
-use think\facade\Config;
-
-class Article extends Base
-{
-    protected $schema = [
-        "id"          => "int",
-        "cid"         => "int",
-        "title"       => "varchar",
-        "writer"      => "varchar",
-        "source"      => "varchar",
-        "titlepic"    => "varchar",
-        "keywords"    => "varchar",
-        "summary"     => "varchar",
-        "content"     => "varchar",
-        "discussed"   => "int",
-        "status"      => "int",
-        "top"         => "int",
-        "sort"       => "int",
-        "hits"        => "int",
-        "likes"       => "int",
-        "content_type"=> "int",
-        "userid"      => "int",
-        "username"    => "varchar",
-        "create_time" => "int",
-        "update_time" => "int"
-    ];
-
-    protected $disuse = ['top','discussed'];
-
-    public function category()
-    {
-        return $this->belongsTo('Category', 'cid')->bind(['category_name' => 'name', 'category_url' => 'url', 'route' => 'route']);
-    }
-
-    public static function queryPage($params)
-    {
-        $where = [];
-
-        if (isset($params['status'])) {
-            $where[] = ['status', '=', (int) $params['status']];
-        }
-
-        if (!empty($params['cid'])) {
-            $where[] = ['cid', '=', (int) $params['cid']];
-        }
-
-        if (!empty($params['key'])) {
-            $where[] = ['title|keywords', 'LIKE', '%' . (string)$params['key'] . '%'];
-        }
-
-        if (!empty($params['yearMonth'])) {
-            if (!preg_match("/^([0-9]{4})\/([0-9]{1,2})$/", $params['yearMonth']) && !preg_match("/^([0-9]{4})-([0-9]{1,2})$/", $params['yearMonth'])) {
-                throw new HttpException(404, '日期格式不正确');
-            }
-            $separator = strrpos('/', $params['yearMonth']) ? '/' : '-';
-            
-            $year = $month = '';
-            
-            if (strnatcasecmp(PHP_VERSION, '7.0.0') >= 0) {
-                list($year, $month) = explode($separator, $params['yearMonth']);
-            } else {
-                list($month, $year) = explode($separator, $params['yearMonth']);
-            }
-            
-            if ((int) $month < 1 || (int) $month > 12) {
-                throw new HttpException(404, '日期格式不正确');
-            }
-            
-            $days = month_frist_and_last_day($year, $month);
-            
-            // $where['create_time'] = ['between', [$days['firstday'], $days['lastday']]];
-            $where[] = ['create_time','between', [$days['firstday'], $days['lastday']]];
-        }
-
-        $limit = empty($params['limit']) ? Config::get('app.page_size', 20) : (int)$params['limit'];
-        
-        $order = ['id desc'];
-        if (!empty($params['order'])) {
-            if (is_array($params['order'])) {
-                $order = array_unique(array_merge($params['order']));
-            } else {
-                array_push($order, $params['order']);
-                $order = array_unique($order);
-            }
-        }
-
-        $list = self::where($where)
-            ->field('id,cid,title,titlepic,username,summary,content_type,hits,sort,status,create_time')
-            ->with(['category'])
-            ->order($order)->paginate(['list_rows'=>$limit, 'query' => $params]);
-
-        return $list;
-    }
-
-    public static function getListByCid($cid = 0, $limit = 10, $order = "")
-    {
-        $where = [];
-
-        if ($cid != 0) {
-            if ($cid < 0) {
-                $where[] = ['cid', '<>', abs($cid)];
-            } else {
-                $where[] = ['cid', '=', $cid];
-            }
-        }
-        
-        $where[] = ['status', '=', 1];
-
-        $order = $order ?? "sort ASC,id DESC";
-
-        return self::with('category')->where($where)
-            ->field('id,cid,title,titlepic,username,summary,hits,sort,status,create_time')
-            ->order($order)->limit($limit)->select();
-    }
-
-    public static function getTop($limit)
-    {
-        return self::with('category')->field('id,cid,title,titlepic,summary,username,hits,sort,status,create_time')
-            ->order('sort ASC, id DESC')->limit($limit)->select();
-    }
-
-    public static function getOne($id)
-    {
-        if (!$id) {
-            throw new HttpException(404, '页面不存在');
-        }
-
-        return self::with('category')->find($id);
-    }
-
-    public static function getNextPrev($id, $cid = null)
-    {
-        $whereP = [];
-        $whereN = [];
-
-        $whereP[] = ['status', '=', 1];
-        $whereN[] = ['status', '=', 1];
-        
-        if ($cid) {
-            $whereP[] = ['cid', '=', $cid];
-            $whereN[] = ['cid', '=', $cid];
-        }
-
-        $whereP[] = ['id', ">", $id];
-        $whereN[] = ['id', "<", $id];
-
-        $data_P = self::where($whereP)->order("id desc")->limit(1)->find();
-        $data_N = self::where($whereN)->order("id desc")->limit(1)->find();
-
-        return ['prev' => $data_P, 'next' => $data_N];
-    }
-
-    public static function createTimeArchive($limit = 0)
-    {
-        if ($limit == 0) {
-            $timeList = self::distinct(true)->fieldRaw("FROM_UNIXTIME(`create_time`, '%Y-%m') as pubmonth")->order('pubmonth desc')->select();
-        } else {
-            $timeList = self::distinct(true)->fieldRaw("FROM_UNIXTIME(`create_time`, '%Y-%m') as pubmonth")->order('pubmonth desc')->limit($limit)->select();
-        }
-
-        return $timeList;
-    }
-}
-=======
 <?php
 
 declare(strict_types=1);
@@ -343,41 +169,4 @@ class Article extends Base
 
         return $timeList;
     }
-
-    public static function createOne($data)
-    {
-        $article = new static;
-
-        $article->allowField(['cid','title','writer','source','titlepic','keywords','summary','content',
-            'status','sort','hits','content_type','userid','username'])->save($data);
-
-        FileManager::saveInfoid($article->id, $data['cjid']);
-
-        $keys = explode(',', $data['keywords']);
-
-        Tag::saveTags($keys, (int) $article->id);
-    }
-
-    public static function updateOne($data)
-    {
-        $article = self::find($data['id']);
-        
-        $oldkeys = explode(',', $article->keywords);
-
-        $article->allowField(['cid','title','writer','source','titlepic','keywords','summary','content',
-            'status','sort','hits','content_type','userid','username'])->save($data);
-
-        FileManager::saveInfoid($article->id, $data['cjid']);
-
-        $newkeys = explode(',', $data['keywords']);
-
-        $keys = array_diff($newkeys, $oldkeys);
-
-        $dec  = array_diff($oldkeys, $newkeys);
-
-        Tag::saveTags($keys, (int) $article->id);
-
-        Tag::decNums($dec, (int) $article->id);
-    }
 }
->>>>>>> 78b76253c8ce5873016cf837373af5e30ac80c86

+ 10 - 132
app/common/model/FileManager.php

@@ -1,77 +1,9 @@
-<<<<<<< HEAD
-<?php
-declare(strict_types=1);
-
-namespace app\common\model;
-
-use think\facade\Config;
-
-class FileManager extends \think\Model
-{
-    protected $pk = "fileid";
-
-    protected $schema = [
-        'fileid'        => "int",      // '文件id'
-        'filename'      => "varchar",  // '文件名称'
-        'filesize'      => "int",      // '文件大小字节'
-        'filetime'      => "int",      // '文件上传时间'
-        'filepath'      => "varchar",  // '文件路径'
-        'fileextension' => "varchar",  // '文件扩展名'
-        'title'         => "varchar",  // '文件title'
-        'type'          => "int",      // '0为附件,1为图片,2为Flash文件,3为多媒体文件'
-        'onclick'       => "int",      // '下载量'
-        'username'      => "varchar",  // '上传者'
-        'cid'           => "int",      // '栏目ID'
-        'infoid'        => "int",      // '信息ID', 
-        'cjid'          => "int",       // '信息临时ID'
-        'hash_md5'       => "varcahr"       // hash值(MD5)
-    ];
-
-    protected $autoWriteTimestamp = false;
-
-    public static function queryPage(array $param = [])
-    {
-        $limit = (int)$param['limit'];
-
-        $where = [];
-
-        return self::where($where)->field('fileid,filename,filesize,filetime,filepath,fileextension,title,username')->paginate(['list_rows'=>$limit, 'query' => $param]);
-    }
-
-    public static function saveFileInfo(\think\File $file)
-    {
-        $fileinfo = self::where('hash_md5', $file->md5())->find();
-
-        $publicRootPath = str_replace('\\', '/', Config::get('filesystem.disks.public.root'));
-
-        $publicUrlPath =  Config::get('filesystem.disks.public.url');
-
-        if ($fileinfo == null) {
-            $fileinfo = new static();
-        } elseif ($publicRootPath . $fileinfo->filepath == $file->getPathname())  { // 路径不同的文件
-            $fileinfo = new static();
-        }
-
-        $fileinfo->filename       = $file->getFilename();
-        $fileinfo->filesize       = $file->getSize();
-        $fileinfo->filetime       = $file->getCTime();
-        $fileinfo->filepath       = $publicUrlPath . str_replace($publicRootPath, '', $file->getPathname());
-        $fileinfo->fileextension  = $file->getExtension();
-        $fileinfo->username       = 'system';
-        $fileinfo->hash_md5       = $file->md5();
-
-        $fileinfo->save();
-    }
-}
-=======
 <?php
 declare(strict_types=1);
 
 namespace app\common\model;
 
 use think\facade\Config;
-use think\File;
-use think\exception\FileException;
 
 class FileManager extends \think\Model
 {
@@ -88,6 +20,7 @@ class FileManager extends \think\Model
         'type'          => "int",      // '0为附件,1为图片,2为Flash文件,3为多媒体文件'
         'onclick'       => "int",      // '下载量'
         'username'      => "varchar",  // '上传者'
+        'cid'           => "int",      // '栏目ID'
         'infoid'        => "int",      // '信息ID', 
         'cjid'          => "int",       // '信息临时ID'
         'hash_md5'       => "varcahr"       // hash值(MD5)
@@ -101,29 +34,10 @@ class FileManager extends \think\Model
 
         $where = [];
 
-        return self::where($where)->field('fileid,filename,filesize,filetime,filepath,fileextension,title,username')->order('fileid DESC')->paginate(['list_rows'=>$limit, 'query' => $param]);
+        return self::where($where)->field('fileid,filename,filesize,filetime,filepath,fileextension,title,username')->paginate(['list_rows'=>$limit, 'query' => $param]);
     }
 
-    public static function queryList(array $param = [])
-    {
-        $where = [];
-
-        $cjid = isset($param['cjid']) ? (int) $param['cjid'] : 0;
-
-        $infoid = isset($param['infoid']) ? (int) $param['infoid'] : 0;
-
-        if ($cjid) {
-            $where[] = ['cjid', '=', $cjid];
-        }
-
-        if ($infoid) {
-            $where[] = ['infoid', '=', $infoid];
-        }
-
-        return self::where($where)->field('fileid,filename,filesize,filetime,filepath,fileextension,title,username')->order('fileid DESC')->select();
-    }
-
-    public static function saveFile(File $file)
+    public static function saveFileInfo(\think\File $file)
     {
         $fileinfo = self::where('hash_md5', $file->md5())->find();
 
@@ -137,50 +51,14 @@ class FileManager extends \think\Model
             $fileinfo = new static();
         }
 
-        $fileinfo->filename      = $file->getFilename();
-        $fileinfo->filesize      = $file->getSize();
-        $fileinfo->filetime      = $file->getCTime();
-        $fileinfo->filepath      = $publicUrlPath . str_replace($publicRootPath, '', $file->getPathname());
-        $fileinfo->fileextension = $file->getExtension();
-        $fileinfo->hash_md5      = $file->md5();
-        $fileinfo->username      = 'system';
+        $fileinfo->filename       = $file->getFilename();
+        $fileinfo->filesize       = $file->getSize();
+        $fileinfo->filetime       = $file->getCTime();
+        $fileinfo->filepath       = $publicUrlPath . str_replace($publicRootPath, '', $file->getPathname());
+        $fileinfo->fileextension  = $file->getExtension();
+        $fileinfo->username       = 'system';
+        $fileinfo->hash_md5       = $file->md5();
 
         $fileinfo->save();
     }
-
-    public static function saveFileInfo($file, $savename, $originalName = '', $id = 0, $cjid = 0, $username = 'system')
-    {
-        if (is_string($file)) {
-            $file = new File($file);
-        }
-
-        if (!$file->isFile()) {
-            throw new FileException('file not exist');
-        }
-
-        $publicUrlPath =  Config::get('filesystem.disks.public.url');
-
-        $fileinfo = new static();
-                
-        $fileinfo->filename      = basename($savename);
-        $fileinfo->filepath      = $publicUrlPath . '/'. $savename;
-        $fileinfo->title         = $originalName;
-        $fileinfo->id            = $id;
-        $fileinfo->cjid          = $cjid;
-        $fileinfo->username      = $username;
-        $fileinfo->filesize      = $file->getSize();
-        $fileinfo->filetime      = $file->getCTime();
-        $fileinfo->fileextension = $file->extension();
-        $fileinfo->hash_md5      = $file->md5();
-        
-        $fileinfo->save();
-
-        return $fileinfo;
-    }
-
-    public static function saveInfoid($infoid, $cjid)
-    {
-        self::where('cjid', 'IN', $cjid)->data(['infoid'=>$infoid, 'cjid'=>0])->update();
-    }
 }
->>>>>>> 78b76253c8ce5873016cf837373af5e30ac80c86