| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace App\Http\Controllers\Api\v1;
- use App\Http\Controllers\Api\webApp;
- use App\Http\Validator\ConsultValidator;
- use App\Services\Api\ArticleService;
- use App\Services\Api\SupervisorsService;
- use App\Services\Common\AdService;
- /**
- * 文章管理
- * Class ArticleController
- * @package App\Http\Controllers\Api
- */
- class ArticleController extends webApp
- {
- /**
- * 列表
- * @return array
- */
- public function index()
- {
- $params =request()->post();
- $pageSize = request()->post('pageSize', 15);
- $datas = ArticleService::make()->getDataList($params, $pageSize);
- return message(1010, true, $datas);
- }
- /**
- * 详情
- */
- public function info()
- {
- $params = request()->all();
- $id = isset($params['id'])? intval($params['id']) : 0;
- if(empty($id)){
- return message(1036, false);
- }
- if($info = ArticleService::make()->getInfo($id)){
- return message(1010, true, $info);
- }else{
- return message(1009, false);
- }
- }
- /**
- * 分类
- * @return array
- */
- public function categorys()
- {
- $type = request()->post('type', 1);
- $datas = ArticleService::make()->getCateList($type);
- return message(1010, true, $datas);
- }
- /**
- * 单页数据
- */
- public function page()
- {
- $params = request()->all();
- $type = isset($params['type'])? intval($params['type']) : 0;
- if(empty($type)){
- return message(1031, false);
- }
- if($info = ArticleService::make()->getInfoByType($type)){
- return message(1010, true, $info);
- }else{
- return message(1009, false);
- }
- }
- /**
- * 咨询提交
- */
- public function consult(ConsultValidator $validator)
- {
- $params = request()->post();
- $params = $validator->check($params, 'submit');
- if (!is_array($params)) {
- return showJson($params, false);
- }
- try {
- if (ArticleService::make()->consultSubmit($this->userId, $params)) {
- return showJson(ArticleService::make()->getError(), true);
- } else {
- return showJson(ArticleService::make()->getError(), false);
- }
- } catch (\Exception $exception) {
- $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
- return showJson(1046, false, $error);
- }
- }
- }
|