IndexController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace App\Http\Controllers\Demo;
  3. use App\Http\Controllers\Controller;
  4. use App\Model\Column;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\DB;
  7. class IndexController extends Controller
  8. {
  9. public function index()
  10. {
  11. // $data=$this->tree();
  12. $data = $this->showimg();
  13. $new = $this->shownews('news', 4);
  14. $tong = $this->shownews('tzgg', 5);
  15. $wjzd = $this->shownews('wjzd', 8);
  16. $kstd = $this->shownews('kstd', 4);
  17. $xyfc = $this->shownews('xyfc', 5);
  18. return view('web.content', compact('data', 'new', 'tong', 'wjzd', 'kstd', 'xyfc'));
  19. }
  20. public function foot()
  21. {
  22. $data = DB::table('sites')->where('status', '=', '0')->orderBy('order', 'DESC')->select('keys', 'value')->get();
  23. return $data;
  24. }
  25. public function tree($parentid = 0, $columnid = 1)
  26. {
  27. $rows = Column::where([['parentid', '=', $parentid], ['columnid', '=', $columnid]])->orderBy('order', 'ASC')->select('name', 'id', 'url', 'parentid')->get();
  28. $rows = $rows->toArray();
  29. $arr = [];
  30. if (sizeof($rows) != 0) {
  31. foreach ($rows as $key => $val) {
  32. // $val['open']='true';
  33. $val['children'] = $this->tree($val['id']);
  34. $arr[] = $val;
  35. }
  36. return $arr;
  37. }
  38. return;
  39. }
  40. public function show($name, Column $table)
  41. {
  42. $re = $table->showid($name);
  43. // dd($re->toArray());
  44. if ($re[0]->type == 0) {
  45. $data = DB::table('articles')->where('colid', '=', $re[0]->id)->select('title', 'id', 'pushtime')->get();
  46. $n = $table->where('keys', '=', $name)->select('name', 'url', 'parentid')->get();
  47. // dd($n);
  48. if ($n[0]->parentid !== 0) {
  49. $m = $table->where('id', '=', $n[0]->parentid)->select('name')->get();
  50. }
  51. return view('web.list', compact('data', 'm', 'n'));
  52. } else {
  53. $n = $table->where('keys', '=', $name)->select('name', 'url', 'parentid')->get();
  54. // dd($n);
  55. if ($n[0]->parentid !== 0) {
  56. $m = $table->where('id', '=', $n[0]->parentid)->select('name')->get();
  57. }
  58. $data = DB::table('articles')->where('colid', '=', $re[0]->id)->get();
  59. return view('web.detail', compact('data', 'm', 'n'));
  60. }
  61. }
  62. public function showinfo($id)
  63. {
  64. $data = DB::table('articles')->where('id', '=', $id)->get();
  65. return view('demo.detail', compact('data'));
  66. }
  67. public function test(Request $request)
  68. {
  69. $list = DB::table('sites')->orderBy('id', 'desc')->select('id', 'name', 'keys', 'value')->get();
  70. return response(['code' => '0',
  71. 'msg' => '',
  72. 'data' => $list]);
  73. // return $list;
  74. }
  75. public function showimg()
  76. {
  77. $data = DB::table('posters')->where('status', '=', '0')->get();
  78. return $data;
  79. }
  80. // public function shownews($parentid,$n){
  81. // $data=DB::table('columns')->where([['status','=',0],['parentid','=',$parentid]])->select(
  82. // 'id','atype','name','url','keys')->get();
  83. // foreach ($data as $k=>$v){
  84. // $re=DB::table('articles')->where('colid','=',$v->id)->
  85. // orderBy('pushtime','desc')->limit($n)->get();
  86. // if ($re){
  87. // $data['articles']=$re;
  88. // }
  89. // }
  90. // }
  91. public function test1()
  92. {
  93. return view('demo.test');
  94. }
  95. public function shownews($keys, $n)
  96. {
  97. $data = DB::table('columns')->where('keys', '=', $keys)->select('id', 'name', 'url')->get();
  98. $re = DB::table('articles')->where('colid', '=', $data[0]->id)->orderBy('pushtime', 'desc')->limit($n)->get();
  99. if ($re) {
  100. $data[0]->articles = $re;
  101. }
  102. return $data;
  103. }
  104. }