|
|
@@ -198,6 +198,79 @@ class ArticleService extends BaseService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 相关推荐列表
|
|
|
+ * @return array
|
|
|
+ * @since 2020/11/11
|
|
|
+ * @author wesmiler
|
|
|
+ */
|
|
|
+ public function getRelactionList($params)
|
|
|
+ {
|
|
|
+ $page = isset($params['pageSize']) ? intval($params['pageSize']) : PAGE;
|
|
|
+ $pageSize = isset($params['pageSize']) ? intval($params['pageSize']) : PERPAGE;
|
|
|
+ $id = isset($params['id']) ? intval($params['id']) : PERPAGE;
|
|
|
+
|
|
|
+ $info = $this->model::from('article as a')
|
|
|
+ ->leftJoin('article_cates as c', 'a.cate_id', '=', 'c.id')
|
|
|
+ ->where(['a.id'=> $id,'makr'=> 1,'status'=> 1])
|
|
|
+ ->select(['a.id','a.cate_id','a.type'])
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ $dataList = $this->model::from('article as a')
|
|
|
+ ->leftJoin('article_cates as c', 'a.cate_id', '=', 'c.id')
|
|
|
+ ->where(function ($query) use ($params, $info) {
|
|
|
+ $query->where(['a.mark'=>1,'a.status'=> 1]);
|
|
|
+ $cateId = isset($info['cate_id']) ? intval($info['cate_id']) : 0;
|
|
|
+ if ($cateId > 0) {
|
|
|
+ $query->where('a.cate_id', $cateId);
|
|
|
+ }
|
|
|
+
|
|
|
+ $type = isset($info['type']) ? intval($info['type']) : 0;
|
|
|
+ if ($type > 0) {
|
|
|
+ $query->where('a.type', $type);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->where(function($query) use($params){
|
|
|
+ $keyword = isset($params['keyword']) ? trim($params['keyword']) : '';
|
|
|
+ if (!empty($keyword)) {
|
|
|
+ $query->where('a.title', 'like', "%{$keyword}%")->orWhere('c.name','like',"%{$keyword}%");
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->select(['a.id', 'a.cate_id', 'c.name as cate_name', 'a.title', 'a.is_form', 'a.is_recommand', 'a.view_num', 'a.thumb', 'a.status', 'a.create_time', 'a.update_time', 'a.description', 'a.sort','a.publish_at'])
|
|
|
+ ->orderBy('a.sort', 'desc')
|
|
|
+ ->orderBy('a.update_time', 'desc')
|
|
|
+ ->paginate($pageSize);
|
|
|
+
|
|
|
+ $dataList = $dataList ? $dataList->toArray() : [];
|
|
|
+ if(empty($dataList)){
|
|
|
+ $dataList = $this->model::from('article as a')
|
|
|
+ ->leftJoin('article_cates as c', 'a.cate_id', '=', 'c.id')
|
|
|
+ ->where(['a.mark'=>1,'a.status'=> 1])
|
|
|
+ ->select(['a.id', 'a.cate_id', 'c.name as cate_name', 'a.title', 'a.is_form', 'a.is_recommand', 'a.view_num', 'a.thumb', 'a.status', 'a.create_time', 'a.update_time', 'a.description', 'a.sort','a.publish_at'])
|
|
|
+ ->orderBy(\DB::raw('rand()'))
|
|
|
+ ->orderBy('a.update_time', 'desc')
|
|
|
+ ->paginate($pageSize);
|
|
|
+ $dataList = $dataList ? $dataList->toArray() : [];
|
|
|
+ }
|
|
|
+ if ($dataList) {
|
|
|
+ foreach ($dataList['data'] as &$item) {
|
|
|
+ $item['thumb'] = $item['thumb'] ? get_image_url($item['thumb']) : '';
|
|
|
+ $item['create_time'] = $item['create_time'] ? datetime($item['create_time'],'Y-m-d H:i:s') : '';
|
|
|
+ $item['publish_at'] = $item['publish_at'] ? $item['publish_at'] : $item['create_at'];
|
|
|
+
|
|
|
+ }
|
|
|
+ unset($item);
|
|
|
+ }
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'code' => 0,
|
|
|
+ 'success'=> true,
|
|
|
+ 'msg' => '操作成功',
|
|
|
+ 'count' => isset($dataList['total']) ? $dataList['total'] : 0,
|
|
|
+ 'data' => isset($dataList['data']) ? $dataList['data'] : 0,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取详情
|
|
|
* @param $id
|
|
|
*/
|