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.
118 lines
3.7 KiB
118 lines
3.7 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
|
// +----------------------------------------------------------------------
|
|
// | Author: CRMEB Team <admin@crmeb.com>
|
|
// +----------------------------------------------------------------------
|
|
namespace app\api\controller\v1\publics;
|
|
|
|
use app\Request;
|
|
use app\services\article\ArticleServices;
|
|
|
|
use think\exception\ValidateException;
|
|
use crmeb\exceptions\ApiException;
|
|
|
|
/**
|
|
* 文章类
|
|
* Class ArticleController
|
|
* @package app\api\controller\publics
|
|
*/
|
|
class ArticleController
|
|
{
|
|
protected $services;
|
|
|
|
public function __construct(ArticleServices $services)
|
|
{
|
|
$this->services = $services;
|
|
}
|
|
|
|
/**
|
|
* 文章列表
|
|
* @param $cid
|
|
* @return mixed
|
|
*/
|
|
public function lst($cid)
|
|
{
|
|
if ($cid == 0) {
|
|
$where = ['is_hot' => 1];
|
|
} else {
|
|
$where = ['cid' => $cid];
|
|
}
|
|
$cid = 1; // 默认新闻资讯分类
|
|
[$page, $limit] = $this->services->getPageValue();
|
|
$list = $this->services->cidByArticleList($where, $page, $limit, "id,title,image_input,visit,from_unixtime(add_time,'%Y-%m-%d %H:%i') as add_time,synopsis,url");
|
|
return app('json')->success($list);
|
|
}
|
|
|
|
/**
|
|
* 文章详情
|
|
* @param $id
|
|
* @return mixed
|
|
*/
|
|
public function details($id)
|
|
{
|
|
$info = $this->services->getInfo($id);
|
|
// 如果不是新闻资讯返回报错信息
|
|
if ($info['cid'] != 1) {
|
|
return app('json')->fail('请选择新闻资讯');
|
|
}
|
|
return app('json')->success($info);
|
|
}
|
|
|
|
/**
|
|
* 获取热门文章
|
|
* @return mixed
|
|
*/
|
|
public function hot()
|
|
{
|
|
[$page, $limit] = $this->services->getPageValue();
|
|
$list = $this->services->cidByArticleList(['is_hot' => 1], $page, $limit, "id,title,image_input,visit,from_unixtime(add_time,'%Y-%m-%d %H:%i') as add_time,synopsis,url");
|
|
return app('json')->success($list);
|
|
}
|
|
|
|
/**
|
|
* @return mixed
|
|
*/
|
|
public function new()
|
|
{
|
|
[$page, $limit] = $this->services->getPageValue();
|
|
$list = $this->services->cidByArticleList([], $page, $limit, "id,title,image_input,visit,from_unixtime(add_time,'%Y-%m-%d %H:%i') as add_time,synopsis,url");
|
|
return app('json')->success($list);
|
|
}
|
|
|
|
/**
|
|
* 获取顶部banner文章
|
|
* @return mixed
|
|
*/
|
|
public function banner()
|
|
{
|
|
[$page, $limit] = $this->services->getPageValue();
|
|
$list = $this->services->cidByArticleList(['is_banner' => 1], $page, $limit, "id,title,image_input,visit,from_unixtime(add_time,'%Y-%m-%d %H:%i') as add_time,synopsis,url");
|
|
return app('json')->success($list);
|
|
}
|
|
|
|
/**
|
|
* 获取(要求授权的)分类下的最新文章
|
|
*/
|
|
public function getArticleLastData(Request $request)
|
|
{
|
|
[$cid] = $request->postMore([['cid', 0]], true);
|
|
$user = $request->user()->toArray();
|
|
$schoolId = $user['school_id'];
|
|
|
|
try {
|
|
if (empty($schoolId) || empty($cid)) {
|
|
throw new ValidateException(100100);
|
|
}
|
|
// 获取数据
|
|
$data = $this->services->getArticleLastData($cid, $schoolId);
|
|
return app('json')->success($data);
|
|
} catch (ValidateException $e) {
|
|
return app('json')->fail($e->getError());
|
|
}
|
|
}
|
|
}
|
|
|