148 lines
4.2 KiB
PHP
Executable File
148 lines
4.2 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\admin\model;
|
|
|
|
use think\Model;
|
|
use think\Request;
|
|
use think\Config;
|
|
|
|
class Article extends Model {
|
|
|
|
use \app\common\traits\AdminModel;
|
|
|
|
protected $insert = ['updatetime'];
|
|
protected $update = ['updatetime'];
|
|
|
|
public function getCategoryArticleList($where = null, $order = null, $field = null, $limit = null) {
|
|
$this->alias('a')->join('article_category c', 'a.cid=c.id', 'LEFT');
|
|
if (is_array($where)) {
|
|
$where = array_merge(['a.stat' => ['eq', '0'], 'c.stat' => ['eq', '0']], $where);
|
|
}
|
|
if ($where) {
|
|
$this->where($where);
|
|
}
|
|
if ($order) {
|
|
$this->order($order);
|
|
}
|
|
if ($field) {
|
|
$this->field($field);
|
|
}
|
|
if ($limit) {
|
|
$this->limit($limit);
|
|
}
|
|
$data = $this->select();
|
|
return $data;
|
|
}
|
|
|
|
public function getArticleLists($where = null, $order = null, $field = null, $limit = null) {
|
|
$this->alias('a')->join('article_category c', 'a.cid=c.id', 'LEFT');
|
|
//->join('user u', 'a.id=u.id', 'LEFT');
|
|
if (is_array($where)) {
|
|
$where = array_merge(['a.stat' => ['eq', '0'], 'c.stat' => ['eq', '0']], $where);
|
|
}
|
|
if ($where) {
|
|
$this->where($where);
|
|
}
|
|
if ($order) {
|
|
$this->order($order);
|
|
}
|
|
if ($field) {
|
|
$this->field($field);
|
|
}
|
|
if (empty($limit)) {
|
|
$limit = Config::get('list_rows');
|
|
}
|
|
//$this->fetchsql(true);
|
|
$object = $this->paginate($limit);
|
|
// header("content-type:text/html;charset=utf8;");
|
|
// print_r($object);
|
|
// exit;
|
|
return $object;
|
|
}
|
|
|
|
public function getRecycleLists($where = null, $order = null, $field = null, $limit = null) {
|
|
$this->alias('a')
|
|
->join('article_category c', 'a.cid=c.id', 'LEFT');
|
|
//->join('user u', 'a.id=u.id', 'LEFT');
|
|
if ($where) {
|
|
$this->where($where);
|
|
}
|
|
if ($order) {
|
|
$this->order($order);
|
|
}
|
|
if ($field) {
|
|
$this->field($field);
|
|
}
|
|
if (empty($limit)) {
|
|
$limit = Config::get('list_rows');
|
|
}
|
|
//$this->fetchsql(true);
|
|
$object = $this->paginate($limit);
|
|
// header("content-type:text/html;charset=utf8;");
|
|
// print_r($object);
|
|
// exit;
|
|
return $object;
|
|
}
|
|
|
|
public function getExportSearchArticleLists($where = null, $order = 'id', $limit = null, $count = false, $field = '*') {
|
|
$this->alias('a')->join('article_category c', 'a.cid=c.id', 'LEFT');
|
|
if (is_array($where)) {
|
|
$this->where($where);
|
|
}
|
|
if ($order) {
|
|
$this->order($order);
|
|
}
|
|
//$object->fetchsql(true);
|
|
if ($count) {
|
|
$result = $this->count();
|
|
return $result;
|
|
}
|
|
if ($field) {
|
|
$this->field($field);
|
|
}
|
|
if ($limit) {
|
|
if (is_array($limit)) {
|
|
//$limit = ['offset' => 1, 'length' => 1];
|
|
$limit = array_values($limit);
|
|
$this->limit($limit[0], $limit[1]);
|
|
} else {
|
|
$this->limit($limit);
|
|
}
|
|
}
|
|
$result = $this->select();
|
|
// header("content-type:text/html;charset=utf8;");
|
|
// print_r($result);
|
|
// exit;
|
|
return $result;
|
|
}
|
|
|
|
// 属性修改器 创建时间
|
|
protected function setCreatetimeAttr($value, $data) {
|
|
if (empty($value)) {
|
|
return time();
|
|
} else {
|
|
return strtotime($value);
|
|
}
|
|
}
|
|
|
|
// 属性修改器 更新时间
|
|
protected function setUpdatetimeAttr($value, $data) {
|
|
return time();
|
|
}
|
|
|
|
// 属性修改器 设置注册ip
|
|
protected function setIpAttr() {
|
|
return Request::instance()->ip();
|
|
}
|
|
|
|
protected function setContentAttr($content, $data) {
|
|
if (!empty($content)) {
|
|
$config = \HTMLPurifier_Config::createDefault();
|
|
$purifier = new \HTMLPurifier($config);
|
|
// $content = $purifier->purify($content);
|
|
}
|
|
return $content;
|
|
}
|
|
|
|
}
|