You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zhishifufei_php/application/web/model/article/Article.php

105 lines
3.2 KiB

10 months ago
<?php
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace app\web\model\article;
use traits\ModelTrait;
use basic\ModelBasic;
/**新闻model
* Class Article
* @package app\web\model
*/
class Article extends ModelBasic
{
use ModelTrait;
/**字段过滤
* @param string $alias
* @param null $model
* @return Article
*/
public static function PreWhere($alias = '', $model = null)
{
if (is_null($model)) $model = new self();
if ($alias) {
$model->alias($alias);
$alias .= '.';
}
return $model->where(["{$alias}is_show" => 1, "{$alias}hide" => 0]);
}
/**Label 字段处理
* @param $value
* @return mixed
*/
public static function getLabelAttr($value)
{
return is_string($value) ? json_decode($value, true) : $value;
}
/**条件处理
* @param $where
* @return Article
*/
public static function setWhere($where)
{
$model = self::PreWhere();
if (isset($where['cid']) && $where['cid']) {
$model = $model->where('cid', $where['cid']);
}
if (isset($where['search']) && $where['search']) {
$model = $model->where('title|synopsis', 'LIKE', "%$where[search]%");
}
$model = $model->order('sort DESC,add_time DESC');
return $model;
}
/**
* 活动列表
*/
public static function getUnifiendList($where)
{
$model = self::setWhere($where);
$data = $model->page((int)$where['page'], (int)$where['limit'])->select();
$data = count($data) > 0 ? $data->toArray() : [];
foreach ($data as &$item) {
$item['add_time'] = date('Y-m-d', $item['add_time']);
$item['visit'] = (int)$item['visit'];
}
$count = self::setWhere($where)->count();
return compact('data', 'count');
}
/**首页新闻资讯
* @param $where
* @return array
*/
public static function get_article_list($where)
{
$model = self::PreWhere();
if ($where['type'] == 1) {
$model = $model->order('visit DESC');
} else {
$model = $model->order('add_time DESC');
}
$list = $model->limit($where['limit'])->select();
$list = count($list) > 0 ? $list->toArray() : [];
if ($where['type'] == 1) {
foreach ($list as &$item) {
$item['add_time'] = date('Y-m-d', $item['add_time']);
$item['synopsis'] = mb_substr($item['synopsis'], 0, 60, 'utf-8');
}
}
return $list;
}
}