init: 项目初始代码
This commit is contained in:
105
app/index/model/News.php
Normal file
105
app/index/model/News.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\index\model;
|
||||
|
||||
|
||||
/**
|
||||
* 新闻模型
|
||||
*/
|
||||
class News extends BaseModel
|
||||
{
|
||||
protected $connection = 'yc';
|
||||
|
||||
/**
|
||||
* 获取新闻动态矩阵
|
||||
* @param $data
|
||||
* @param $languageId
|
||||
* @return \think\Paginator
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getNewsList($languageId,$data)
|
||||
{
|
||||
$where = [
|
||||
'site_id' => $languageId,
|
||||
'status' => 0,
|
||||
];
|
||||
if (isset($data['news_type_id']) && $data['news_type_id'] != 0) {
|
||||
$where['news_type_id'] = $data['news_type_id'];
|
||||
}
|
||||
|
||||
$listRow = [
|
||||
'query' => isset($data['news_type_id']) ? ['news_type_id'=>$data['news_type_id']??0] : [], //url额外参数
|
||||
'fragment' => '', //url锚点
|
||||
'var_page' => 'page', //分页变量
|
||||
'list_rows' => $data['size']??6, //每页数量
|
||||
];
|
||||
return $this->where($where)->order('create_time','desc')->paginate($listRow);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取品牌矩阵分类
|
||||
* @param $languageId
|
||||
* @param $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getNewsTypeList($languageId,$data):array
|
||||
{
|
||||
$result = NewsType::where('site_id',$languageId)->select()->toArray();
|
||||
if (!empty($result)) {
|
||||
$arr[] = [
|
||||
'id' => 0,
|
||||
'name' => '全部新闻',
|
||||
];
|
||||
$result = array_merge($arr,$result);
|
||||
foreach ($result as $key => $item) {
|
||||
$result[$key]['is_display'] = !empty($data) ? isset($data['news_type_id']) && $data['news_type_id'] == $item['id'] : $item['id'] == 0;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $languageId
|
||||
* @param $data
|
||||
* @return array|string[]
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getNewsBanner($languageId,$data):array
|
||||
{
|
||||
$space = AdvertiseSpace::where('name',$data)->select()->toArray();
|
||||
if (!empty($space)) {
|
||||
return $this->getBanner($languageId,$space[0]['id']);
|
||||
}
|
||||
return ['image' => ''];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上一篇,下一篇
|
||||
*/
|
||||
public function getPreNexInfo($data)
|
||||
{
|
||||
if (isset($data['id'])) {
|
||||
$info = $this->find($data['id'])->toArray();
|
||||
// 下一条
|
||||
$next = $this->field(['id','title'])->where('news_type_id',$info['news_type_id'])->where('id','>',$data['id'])->limit(1)->select()->toArray();
|
||||
// 上一条
|
||||
$pre = $this->field(['id','title'])->where('news_type_id',$info['news_type_id'])->where('id','<',$data['id'])->limit(1)->select()->toArray();
|
||||
|
||||
return [
|
||||
'pre' => empty($pre) ? [] : $pre[0],
|
||||
'next' => empty($next) ? [] : $next[0]
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user