|
|
@@ -67,6 +67,11 @@ class ArticleService extends BaseService
|
|
|
$query->where('a.is_top', $isTop);
|
|
|
}
|
|
|
|
|
|
+ $type = isset($params['type']) ? intval($params['type']) : 0;
|
|
|
+ if ($type > 0) {
|
|
|
+ $query->where('a.type', $type);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
$status = isset($params['status']) ? $params['status'] : 0;
|
|
|
if ($status > 0) {
|
|
|
@@ -99,6 +104,86 @@ class ArticleService extends BaseService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获取列表
|
|
|
+ * @return array
|
|
|
+ * @since 2020/11/11
|
|
|
+ * @author wesmiler
|
|
|
+ */
|
|
|
+ public function getDataList($params)
|
|
|
+ {
|
|
|
+ $page = isset($params['pageSize']) ? intval($params['pageSize']) : PAGE;
|
|
|
+ $pageSize = isset($params['pageSize']) ? intval($params['pageSize']) : PERPAGE;
|
|
|
+
|
|
|
+ $dataList = $this->model::from('article as a')
|
|
|
+ ->leftJoin('article_cates as c', 'a.cate_id', '=', 'c.id')
|
|
|
+ ->where(function ($query) use ($params) {
|
|
|
+ $query->where(['a.mark'=>1,'a.status'=> 1]);
|
|
|
+
|
|
|
+ $title = isset($params['title']) ? trim($params['title']) : '';
|
|
|
+ if (!empty($title)) {
|
|
|
+ $query->where('a.title', 'like', "%{$title}%");
|
|
|
+ }
|
|
|
+
|
|
|
+ $cateId = isset($params['cate_id']) ? intval($params['cate_id']) : 0;
|
|
|
+ if ($cateId > 0) {
|
|
|
+ $query->where('a.cate_id', $cateId);
|
|
|
+ } else if ($cateId == -1) {
|
|
|
+ $query->where('a.is_recommand', 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ $isTop = isset($params['is_top']) ? intval($params['is_top']) : 0;
|
|
|
+ if ($isTop > 0) {
|
|
|
+ $query->where('a.is_top', $isTop);
|
|
|
+ }
|
|
|
+
|
|
|
+ $type = isset($params['type']) ? intval($params['type']) : 0;
|
|
|
+ if ($type > 0) {
|
|
|
+ $query->where('a.type', $type);
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ ->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.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
|
|
|
+ */
|
|
|
+ public function getDetail($id){
|
|
|
+ $info = $this->model::from('article as a')
|
|
|
+ ->leftJoin('article_cates as c', 'a.cate_id', '=', 'c.id')
|
|
|
+ ->where(['a.mark'=> 1,'a.status'=> 1,'a.id'=> $id])
|
|
|
+ ->select(['a.id','a.title','a.thumb','a.cate_id','c.name as cate_name','a.view_num','a.description','a.content','a.publish_at','a.create_time'])
|
|
|
+ ->first();
|
|
|
+ $info = $info? $info->toArray() : [];
|
|
|
+ if($info){
|
|
|
+ $info['thumb'] = $info['thumb']? get_image_url($info['thumb']) : '';
|
|
|
+ $info['publish_at'] = $info['publish_at']? $info['publish_at'] : datetime( $info['create_time'],'Y-m-d H:i:s');
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 添加或编辑
|
|
|
* @return array
|
|
|
* @since 2020/11/11
|