// +---------------------------------------------------------------------- namespace app\api\controller\v1\publics; use app\Request; use app\services\article\ArticleServices; use app\services\crud\LeaveWordServices; /** * 文章类 * Class ArticleController * @package app\api\controller\publics */ class ArticleController { protected $services; public function __construct(ArticleServices $services) { $this->services = $services; } /** * 文章列表 * @param $cid * @return mixed * @throws \ReflectionException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function lst($cid) { if ($cid == 0) { $where = ['is_hot' => 1]; } else { $where = ['cid' => $cid]; } [$page, $limit] = $this->services->getPageValue(); $list = $this->services->getList($where, $page, $limit)['list']; foreach ($list as &$item){ $item['add_time'] = date('Y-m-d H:i', $item['add_time']); } return app('json')->success($list); } /** * 文章详情 * @param $id * @return mixed * @throws \ReflectionException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function details($id) { $info = $this->services->getInfo($id); return app('json')->success($info); } /** * 获取热门文章 * @return mixed * @throws \ReflectionException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function hot() { [$page, $limit] = $this->services->getPageValue(); $list = $this->services->getList(['is_hot' => 1], $page, $limit)['list']; foreach ($list as &$item){ $item['add_time'] = date('Y-m-d H:i', $item['add_time']); } return app('json')->success($list); } /** * @return mixed * @throws \ReflectionException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function new() { [$page, $limit] = $this->services->getPageValue(); $data = $this->services->getList([], $page, $limit); $list = $data['list']; $count = $data['count']; foreach ($list as &$item){ $item['add_time'] = date('Y-m-d H:i', $item['add_time']); } return app('json')->success("调用成功",['list'=>$list,"count"=>$count]); } /** * 获取顶部banner文章 * @return mixed * @throws \ReflectionException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function banner() { [$page, $limit] = $this->services->getPageValue(); $list = $this->services->getList(['is_banner' => 1], $page, $limit)['list']; foreach ($list as &$item){ $item['add_time'] = date('Y-m-d H:i', $item['add_time']); } return app('json')->success($list); } /** * 联系我们 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function leave_word(Request $request, LeaveWordServices $service) { $data = $request->postMore([ ['name', ''], ['mobile', ''], ['content', ''], ['create_time', time()], ]); validate(\app\adminapi\validate\crud\LeaveWordValidate::class)->check($data); $service->crudSave($data); return app('json')->success(100021); } }