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.

75 lines
2.2 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
  1. <?php
  2. namespace App\Http\Controllers\Weixin;
  3. use App\Http\Controllers\Weixin\CommonController;
  4. use Illuminate\Http\Request;
  5. class ArticleController extends CommonController
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. //列表页
  12. public function category($cat)
  13. {
  14. $pagesize = 10;
  15. $offset = 0;
  16. //文章分类
  17. $postdata = array(
  18. 'id' => $cat
  19. );
  20. $url = env('APP_API_URL')."/arctype_detail";
  21. $arctype_detail = curl_request($url,$postdata,'GET');
  22. $data['post'] = $arctype_detail['data'];
  23. if(isset($_REQUEST['page'])){$offset = ($_REQUEST['page']-1)*$pagesize;}
  24. //文章列表
  25. $postdata2 = array(
  26. 'limit' => $pagesize,
  27. 'offset' => $offset,
  28. 'typeid' => $cat
  29. );
  30. $url = env('APP_API_URL')."/article_list";
  31. $res = curl_request($url,$postdata2,'GET');
  32. $data['list'] = $res['data']['list'];
  33. $data['totalpage'] = ceil($res['data']['count']/$pagesize);
  34. if(isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax']==1)
  35. {
  36. $html = '';
  37. if($res['data']['list'])
  38. {
  39. foreach($res['data']['list'] as $k => $v)
  40. {
  41. $html .= '<li><a href="'.$v['article_detail_url'].'">'.$v['title'].'</a><p>'.$v['pubdate'].'</p></li>';
  42. }
  43. }
  44. exit(json_encode($html));
  45. }
  46. return view('weixin.article.category', $data);
  47. }
  48. //文章详情页
  49. public function detail($id)
  50. {
  51. //最新资讯
  52. $postdata = array(
  53. 'id' => $id
  54. );
  55. $url = env('APP_API_URL')."/article_detail";
  56. $res = curl_request($url,$postdata,'GET');
  57. if(empty($res['data'])){return redirect()->route('weixin_page404');}
  58. $res['data']['body'] = preg_replace('/src=\"\/uploads\/allimg/',"src=\"".env('APP_URL')."/uploads/allimg",$res['data']['body']);
  59. $res['data']['pubdate'] = date('Y-m-d',$res['data']['pubdate']);
  60. $data['post'] = $res['data'];
  61. return view('weixin.article.detail', $data);
  62. }
  63. }