|
@@ -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
|