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.

106 lines
2.8 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use DB;
  5. class CommonController extends Controller
  6. {
  7. public $user_info;
  8. public function __construct()
  9. {
  10. parent::__construct();
  11. //判断是否登录
  12. if(isset($_SESSION['admin_user_info']))
  13. {
  14. $this->user_info = $_SESSION['admin_user_info'];
  15. }
  16. else
  17. {
  18. header("Location:".route('page404'));
  19. exit();
  20. }
  21. //判断是否拥有权限
  22. if($_SESSION['admin_user_info']['role_id'] <> 1)
  23. {
  24. $uncheck = array('admin_jump','admin','admin_index_upconfig','admin_index_upcache','admin_welcome');
  25. if(in_array(\Route::currentRouteName(), $uncheck))
  26. {
  27. }
  28. else
  29. {
  30. $menu_id = DB::table('menu')->where('action', \Route::currentRouteName())->value('id');
  31. $check = DB::table('access')->where(['role_id' => $_SESSION['admin_user_info']['role_id'], 'menu_id' => $menu_id])->first();
  32. if(!$check)
  33. {
  34. error_jump('你没有权限访问,请联系管理员!', route('admin'));
  35. }
  36. }
  37. }
  38. }
  39. /**
  40. * 获取分页数据及分页导航
  41. * @param string $modelname 模块名与数据库表名对应
  42. * @param array $where 查询条件
  43. * @param string $orderby 查询排序
  44. * @param string $field 要返回数据的字段
  45. * @param int $listRows 每页数量,默认30条
  46. *
  47. * @return 格式化后输出的数据。内容格式为:
  48. * - "code" (string):代码
  49. * - "info" (string):信息提示
  50. *
  51. * - "result" array
  52. *
  53. * - "img_list" (array) :图片队列,默认8张
  54. * - "img_title" (string):车图名称
  55. * - "img_url" (string):车图片url地址
  56. * - "car_name" (string):车名称
  57. */
  58. public function pageList($modelname, $where = '', $orderby = '', $field = '*', $listRows = 30)
  59. {
  60. $model = \DB::table($modelname);
  61. //查询条件
  62. if(!empty($where)){$model = $model->where($where);}
  63. //排序
  64. if($orderby!='')
  65. {
  66. if($orderby == 'rand()')
  67. {
  68. $model = $model->orderBy(\DB::raw('rand()'));
  69. }
  70. else
  71. {
  72. if(count($orderby) == count($orderby, 1))
  73. {
  74. $model = $model->orderBy($orderby[0], $orderby[1]);
  75. }
  76. else
  77. {
  78. foreach($orderby as $row)
  79. {
  80. $model = $model->orderBy($row[0], $row[1]);
  81. }
  82. }
  83. }
  84. }
  85. else
  86. {
  87. $model = $model->orderBy('id', 'desc');
  88. }
  89. //要返回的字段
  90. if($field!='*'){$model = $model->select(\DB::raw($field));}
  91. return $model->paginate($listRows);
  92. }
  93. }