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.

105 lines
2.9 KiB

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