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.

104 lines
2.9 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use Illuminate\Http\Request;
  4. use Log;
  5. use DB;
  6. use App\Common\ReturnData;
  7. use App\Common\Helper;
  8. use App\Http\Model\Article;
  9. use App\Http\Logic\ArticleLogic;
  10. class ArticleController extends CommonController
  11. {
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. }
  16. public function getLogic()
  17. {
  18. return new ArticleLogic();
  19. }
  20. public function articleList(Request $request)
  21. {
  22. //参数
  23. $limit = $request->input('limit', 10);
  24. $offset = $request->input('offset', 0);
  25. if($request->input('typeid', null) != null){$where['typeid'] = $request->input('typeid');}
  26. $where['ischeck'] = Article::IS_CHECK;
  27. $res = $this->getLogic()->getList($where, array('id', 'desc'), '*', $offset, $limit);
  28. if($res === false)
  29. {
  30. return ReturnData::create(ReturnData::SYSTEM_FAIL);
  31. }
  32. foreach($res['list'] as $k=>$v)
  33. {
  34. $res['list'][$k]->article_detail_url = route('weixin_article_detail',array('id'=>$v->id));
  35. }
  36. return ReturnData::create(ReturnData::SUCCESS,$res);
  37. }
  38. public function articleDetail(Request $request)
  39. {
  40. //参数
  41. $where['id'] = $request->input('id',null);
  42. $where['ischeck'] = Article::IS_CHECK;
  43. if($where['id']==null){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  44. $res = $this->getLogic()->getOne($where);
  45. if($res === false)
  46. {
  47. return ReturnData::create(ReturnData::SYSTEM_FAIL);
  48. }
  49. //$res->pubdate = date('Y-m-d H:i',$res->pubdate);
  50. //$res->addtime = date('Y-m-d H:i',$res->addtime);
  51. return ReturnData::create(ReturnData::SUCCESS,$res);
  52. }
  53. //添加
  54. public function articleAdd(Request $request)
  55. {
  56. if(Helper::isPostRequest())
  57. {
  58. $_POST['user_id'] = Token::$uid;
  59. return $this->getLogic()->add($_POST);
  60. }
  61. }
  62. //修改
  63. public function articleUpdate(Request $request)
  64. {
  65. if($request->input('id',null)!=null){$id = $request->input('id');}else{$id='';}if(preg_match('/[0-9]*/',$id)){}else{return ReturnData::create(ReturnData::PARAMS_ERROR);}
  66. if(Helper::isPostRequest())
  67. {
  68. unset($_POST['id']);
  69. $where['id'] = $id;
  70. //$where['user_id'] = Token::$uid;
  71. return $this->getLogic()->edit($_POST,$where);
  72. }
  73. }
  74. //删除
  75. public function articleDelete(Request $request)
  76. {
  77. if($request->input('id',null)!=null){$id = $request->input('id');}else{$id='';}if(preg_match('/[0-9]*/',$id)){}else{return ReturnData::create(ReturnData::PARAMS_ERROR);}
  78. if(Helper::isPostRequest())
  79. {
  80. unset($_POST['id']);
  81. $where['id'] = $id;
  82. //$where['user_id'] = Token::$uid;
  83. return $this->getLogic()->del($where);
  84. }
  85. }
  86. }