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.

108 lines
3.1 KiB

7 years ago
4 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
3 years ago
7 years ago
7 years ago
3 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\Support\Facades\Log;
  4. use Illuminate\Support\Facades\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 BaseController
  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. $res['list'][$k]->url = get_front_url(array("id"=>$v->id,"type"=>'content'));
  35. $res['list'][$k]->pubdatetext = date("Y-m-d", $v->pubdate);
  36. }
  37. }
  38. return ReturnData::create(ReturnData::SUCCESS,$res);
  39. }
  40. public function articleDetail(Request $request)
  41. {
  42. //参数
  43. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  44. $id = $request->input('id');
  45. $where['id'] = $id;
  46. $where['ischeck'] = Article::IS_CHECK;
  47. $res = $this->getLogic()->getOne($where);
  48. if(!$res)
  49. {
  50. return ReturnData::create(ReturnData::RECORD_NOT_EXIST);
  51. }
  52. //$res->pubdate = date('Y-m-d H:i',$res->pubdate);
  53. //$res->addtime = date('Y-m-d H:i',$res->addtime);
  54. return ReturnData::create(ReturnData::SUCCESS,$res);
  55. }
  56. //添加
  57. public function articleAdd(Request $request)
  58. {
  59. if(Helper::isPostRequest())
  60. {
  61. $_POST['user_id'] = Token::$uid;
  62. return $this->getLogic()->add($_POST);
  63. }
  64. }
  65. //修改
  66. public function articleUpdate(Request $request)
  67. {
  68. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  69. $id = $request->input('id');
  70. if(Helper::isPostRequest())
  71. {
  72. unset($_POST['id']);
  73. $where['id'] = $id;
  74. //$where['user_id'] = Token::$uid;
  75. return $this->getLogic()->edit($_POST,$where);
  76. }
  77. }
  78. //删除
  79. public function articleDelete(Request $request)
  80. {
  81. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  82. $id = $request->input('id');
  83. if(Helper::isPostRequest())
  84. {
  85. $where['id'] = $id;
  86. //$where['user_id'] = Token::$uid;
  87. return $this->getLogic()->del($where);
  88. }
  89. }
  90. }