113 lines
3.5 KiB
PHP
Executable File
113 lines
3.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\common\model;
|
|
|
|
use think\Model;
|
|
use think\Request;
|
|
use think\Config;
|
|
|
|
class Blog extends Model {
|
|
|
|
use \app\common\traits\IndexModel;
|
|
|
|
|
|
public function getBlogLists($where = null, $order = null, $field = null, $limit = null) {
|
|
//echo "<pre>++"; print_r($where); die;
|
|
//$this->alias('a')->join('blog_remark', 'a.b_id=blog_remark.id', 'LEFT');
|
|
if (is_array($where)) {
|
|
$where = array_merge(['stat' => ['eq', '1']], $where);
|
|
}
|
|
if ($where) {
|
|
$this->where($where);
|
|
}
|
|
if ($order) {
|
|
$this->order($order);
|
|
}
|
|
if ($field) {
|
|
$this->field($field);
|
|
}
|
|
if (empty($limit)) {
|
|
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
|
|
}
|
|
|
|
$object = $this->paginate($limit);
|
|
|
|
//header("content-type:text/html;charset=utf8;");
|
|
//print_r($object);
|
|
//exit;
|
|
return $object;
|
|
}
|
|
|
|
public function getRemarkList($where = null, $order = null, $field = null, $limit = null) {
|
|
$this->alias('a')->join('blog_remark', 'a.id=blog_remark.b_id', 'LEFT');
|
|
if (is_array($where)) {
|
|
$where = array_merge(['blog_remark.stat' => ['eq', '1']], $where);
|
|
}
|
|
if ($where) {
|
|
$this->where($where);
|
|
}
|
|
if ($order) {
|
|
$this->order($order);
|
|
}
|
|
if ($field) {
|
|
$this->field($field);
|
|
}
|
|
if (empty($limit)) {
|
|
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
|
|
}
|
|
|
|
$object = $this->paginate($limit);
|
|
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
public function getBlogDetail($id){
|
|
|
|
}
|
|
|
|
public function getOneRow($where, $field = null, $order = null, $stat = true) {
|
|
$object = $this::get(function($query)use($where, $field, $order, $stat) {
|
|
if ($stat) {
|
|
$query->where(['stat' => ['eq', '1']]);
|
|
}
|
|
$query->where('id', $where);
|
|
if ($field) {
|
|
$query->field($field);
|
|
}
|
|
if ($order) {
|
|
$query->order($order);
|
|
}
|
|
//$query->fetchsql(true);
|
|
});
|
|
return $object;
|
|
}
|
|
|
|
public function getRow($where = null, $field = null, $order = null, $fetchsql = false) {
|
|
$object = $this::get(function($query)use($where, $field, $order, $fetchsql) {
|
|
if (is_numeric($where)) {
|
|
$query->where(['stat' => ['eq', '1']])->where('id', $where);
|
|
}
|
|
if (is_array($where)) {
|
|
$where = array_merge(['stat' => ['eq', '1']], $where);
|
|
$query->where($where);
|
|
}
|
|
if ($field) {
|
|
$query->field($field);
|
|
}
|
|
if ($order) {
|
|
$query->order($order);
|
|
}
|
|
//$fetchsql ? $query->fetchsql(true) : '';
|
|
});
|
|
return $object;
|
|
}
|
|
|
|
/*public function updateRow($data = [], $where = [], $field = null) {
|
|
$object = $this::update($data, $where, $field);
|
|
return $object;
|
|
}*/
|
|
|
|
}
|