Files
2024-10-29 14:04:59 +08:00

126 lines
3.6 KiB
PHP
Executable File

<?php
namespace app\common\model;
use think\Model;
use think\Config;
class Banner extends Model {
use \app\common\traits\IndexModel;
public function getBannerList($where = null, $order = null, $field = null, $limit = null) {
$this->alias('b')->join('banner_type bt', 'b.typeid=bt.id', 'LEFT');
if (is_array($where)) {
$where = array_merge(['b.stat' => 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 getBannerLists($where = null, $order = null, $field = null, $limit = null) {
$this->alias('b')->join('banner_type bt', 'b.typeid=bt.id', 'LEFT');
if (is_array($where)) {
$where = array_merge(['b.stat' => 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') > 0 ? Config::get('list_rows') : 12;
}
//$this->fetchsql(true);
$object = $this->paginate($limit);
// header("content-type:text/html;charset=utf8;");
// print_r($object);
// exit;
return $object;
}
public function getList($where = null, $order = null, $field = null, $limit = null) {
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 getLists($where = null, $order = null, $field = null, $limit = null) {
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 getOneBanner($id, $field = null) {
$object = $this::get(function($query)use($id, $field) {
$query->where(['id' => $id, 'stat' => 0]);
if ($field) {
$query->field($field);
}
});
return $object;
}
public function getBanner($where = null, $field = null, $order = null) {
if (is_array($where)) {
$where = array_merge(['stat' => 0], $where);
}
$object = $this::get(function($query)use($where, $field, $order) {
if ($where) {
$query->where($where);
}
if ($field) {
$query->field($field);
}
if ($order) {
$query->order($order);
}
});
return $object;
}
public function updateBanner($data = [], $where = [], $field = null) {
$object = $this::update($data, $where, $field);
return $object;
}
}