ArticleController.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\ArticleService;
  5. use App\Services\ConfigService;
  6. /**
  7. * 文章
  8. * Class ArticleController
  9. * @package App\Http\Controllers\Api
  10. */
  11. class ArticleController extends webApp
  12. {
  13. /**
  14. * 列表
  15. * @return array
  16. */
  17. public function index()
  18. {
  19. $params =request()->post();
  20. $pageSize = request()->post('pageSize', 15);
  21. $datas = ArticleService::make()->getDataList($params, $pageSize);
  22. return showJson(1010, true, $datas);
  23. }
  24. /**
  25. * 分类
  26. * @return array
  27. */
  28. public function category()
  29. {
  30. $datas = ArticleService::make()->getCategory();
  31. return showJson(1010, true, $datas);
  32. }
  33. /**
  34. * 分类
  35. * @return array
  36. */
  37. public function cates()
  38. {
  39. $type = request()->post('type', 0);
  40. $datas = ArticleService::make()->getCateList($type);
  41. return showJson(1010, true, $datas);
  42. }
  43. /**
  44. * 详情
  45. */
  46. public function info()
  47. {
  48. $id = request()->post('id',0);
  49. if(empty($id)){
  50. return showJson(2501, false);
  51. }
  52. if($info = ArticleService::make()->getInfo($id, $this->userId)){
  53. return showJson(1010, true, $info);
  54. }else{
  55. return showJson(1009, false);
  56. }
  57. }
  58. /**
  59. * 单页数据
  60. */
  61. public function page()
  62. {
  63. $type = request()->post('type','');
  64. if(empty($type)){
  65. return showJson(2501, false);
  66. }
  67. $pageId = ConfigService::make()->getConfigByCode("page_{$type}");
  68. if($pageId<=0){
  69. return showJson(1032, false);
  70. }
  71. if($info = ArticleService::make()->getInfo($pageId)){
  72. return showJson(1010, true, $info);
  73. }else{
  74. return showJson(1009, false);
  75. }
  76. }
  77. }