Article.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\api\model\ArticleModel;
  5. /**
  6. * 资讯接口
  7. * @ApiWeigh (97)
  8. */
  9. class Article extends Api
  10. {
  11. protected $noNeedLogin = [];//,'my_keys','my_detail'
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 全部资讯
  15. *
  16. * @ApiTitle (全部资讯)
  17. * @ApiSummary (全部资讯)
  18. * @ApiMethod (POST)
  19. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  20. * @ApiRoute (/api/article/article_list)
  21. * @ApiParams (name="user_id", type="int", required=true, description="用户id")
  22. * @ApiParams (name="token", type="int", required=true, description="请求的Token")
  23. * @ApiReturn ()
  24. */
  25. public function article_list(){
  26. $userId = $this->request->post('user_id');
  27. if (empty($userId)){
  28. $this->result('登录信息丢失');
  29. }
  30. $get_list=ArticleModel::where(['status'=>'1','is_delete'=>'0'])->order('id desc')->field('id,title,images,createtime')->select();
  31. $this->result('success', $get_list, 1);
  32. }
  33. /**
  34. * 资讯详情
  35. *
  36. * @ApiTitle (资讯详情)
  37. * @ApiSummary (资讯详情)
  38. * @ApiMethod (POST)
  39. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  40. * @ApiRoute (/api/article/article_detail)
  41. * @ApiParams (name="user_id", type="int", required=true, description="用户id")
  42. * @ApiParams (name="token", type="int", required=true, description="请求的Token")
  43. * @ApiParams (name="article_id", type="int", required=true, description="列表中的id")
  44. * @ApiReturn ()
  45. */
  46. public function article_detail(){
  47. $userId = $this->request->post('user_id');
  48. if (empty($userId)){
  49. $this->result('登录信息丢失');
  50. }
  51. $article_id = $this->request->post('article_id');
  52. $get_list=ArticleModel::where(['status'=>'1','is_delete'=>'0','id'=>$article_id])->field('id,title,images,createtime,content')->find();
  53. $this->result('success', $get_list, 1);
  54. }
  55. }