|
|
@@ -84,13 +84,13 @@ class ArticleService extends BaseService
|
|
|
public function getDataList($params, $pageSize = 15)
|
|
|
{
|
|
|
$query = $this->getQuery($params);
|
|
|
- $list = $query->select(['a.id','a.type','a.title','a.cover','a.views','a.create_time','a.content','a.status'])
|
|
|
+ $list = $query->select(['a.id','a.type','a.title','a.cover','a.views','a.cate_id','a.create_time','a.content','a.status'])
|
|
|
->orderBy('a.create_time','desc')
|
|
|
->paginate($pageSize > 0 ? $pageSize : 9999999);
|
|
|
$list = $list? $list->toArray() :[];
|
|
|
if($list){
|
|
|
foreach($list['data'] as &$item){
|
|
|
- $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : '';
|
|
|
+ $item['create_time'] = $item['create_time']? dateFormat($item['create_time']) : '';
|
|
|
$item['cover'] = $item['cover']? get_image_url($item['cover']) : '';
|
|
|
$item['content'] = $item['content']? get_format_content($item['content']) : '';
|
|
|
}
|
|
|
@@ -113,6 +113,8 @@ class ArticleService extends BaseService
|
|
|
$where = ['a.mark' => 1];
|
|
|
$status = isset($params['status'])? $params['status'] : 0;
|
|
|
$type = isset($params['type'])? $params['type'] : 0;
|
|
|
+ $cateId = isset($params['cate_id'])? $params['cate_id'] : 0;
|
|
|
+
|
|
|
if($status>0){
|
|
|
$where['a.status'] = $status;
|
|
|
}
|
|
|
@@ -120,7 +122,11 @@ class ArticleService extends BaseService
|
|
|
$where['a.type'] = $type;
|
|
|
}
|
|
|
|
|
|
- return $this->model->from('article as a')
|
|
|
+ if($cateId>0){
|
|
|
+ $where['a.cate_id'] = $cateId;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->model->with(['category'])->from('article as a')
|
|
|
->where($where)
|
|
|
->where(function ($query) use($params){
|
|
|
$keyword = isset($params['keyword'])? $params['keyword'] : '';
|
|
|
@@ -145,7 +151,7 @@ class ArticleService extends BaseService
|
|
|
}
|
|
|
|
|
|
$info = $this->model->where(['id'=> $id,'status'=>1,'mark'=>1])
|
|
|
- ->select(['id','title','cover','views','create_time','type','content'])
|
|
|
+ ->select(['id','title','cover','views','cate_id','create_time','type','content'])
|
|
|
->first();
|
|
|
$info = $info? $info->toArray() : [];
|
|
|
if($info){
|
|
|
@@ -160,31 +166,25 @@ class ArticleService extends BaseService
|
|
|
return $info;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * 获取分类文章推荐
|
|
|
- * @param int $cateId 推荐分类ID
|
|
|
- * @param int $type 类别:3-普通文章,4-客服回复
|
|
|
+ * 按类型获取文章
|
|
|
+ * @param int $type
|
|
|
* @return array|mixed
|
|
|
*/
|
|
|
- public function getCustomRecommend($cateId=0, $type=4)
|
|
|
+ public function getListByType($type=1)
|
|
|
{
|
|
|
- $cacheKey = "caches:articles:list_{$cateId}";
|
|
|
+ $cacheKey = "caches:articles:indexList_{$type}";
|
|
|
$datas = RedisService::get($cacheKey);
|
|
|
if($datas){
|
|
|
return $datas;
|
|
|
}
|
|
|
|
|
|
- $limitNum = ConfigService::make()->getConfigByCode('custom_recommend_num', 6);
|
|
|
- $limitNum = $limitNum? $limitNum : 6;
|
|
|
- $datas = ArticleCateModel::where(function($query) use($cateId){
|
|
|
- if($cateId){
|
|
|
- $query->where('cate_id', $cateId);
|
|
|
- }
|
|
|
- })->where(['type'=>$type,'status'=>1,'mark'=>1])
|
|
|
- ->select(['id','cate_id','title','description','sort','type','status'])
|
|
|
- ->limit($limitNum)
|
|
|
- ->orderBy('sort','desc')
|
|
|
- ->orderBy('create_time','desc')
|
|
|
+ $limit = ConfigService::make()->getConfigByCode('index_article_num',3);
|
|
|
+ $datas = ArticleCateModel::with(['articles'=>function($query) use($limit){
|
|
|
+ $query->limit($limit);
|
|
|
+ }])->where(['type'=>$type,'status'=>1,'mark'=>1])
|
|
|
+ ->select(['cate_id','name','sort','type'])
|
|
|
->get();
|
|
|
$datas = $datas? $datas->toArray() : [];
|
|
|
if($datas){
|
|
|
@@ -194,12 +194,13 @@ class ArticleService extends BaseService
|
|
|
return $datas;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 获取文章推荐分类
|
|
|
- * @param int $type 1-普通文章分类,2-客服回复文章分类
|
|
|
+ * @param int $type
|
|
|
* @return array|mixed
|
|
|
*/
|
|
|
- public function getCateList($type=2)
|
|
|
+ public function getCateList($type=1)
|
|
|
{
|
|
|
$cacheKey = "caches:articles:cateList_{$type}";
|
|
|
$datas = RedisService::get($cacheKey);
|
|
|
@@ -207,11 +208,8 @@ class ArticleService extends BaseService
|
|
|
return $datas;
|
|
|
}
|
|
|
|
|
|
- $limitNum = ConfigService::make()->getConfigByCode('custom_cate_num', 6);
|
|
|
- $limitNum = $limitNum? $limitNum : 6;
|
|
|
$datas = ArticleCateModel::where(['type'=> $type,'status'=>1,'mark'=>1])
|
|
|
->select(['cate_id','name','sort','type'])
|
|
|
- ->limit($limitNum)
|
|
|
->get();
|
|
|
$datas = $datas? $datas->toArray() : [];
|
|
|
if($datas){
|