Film.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\admin\controller\manage\statics;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. *
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Film extends Backend
  11. {
  12. /**
  13. * Film模型对象
  14. * @var \app\admin\model\manage\statics\Film
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\manage\statics\Film;
  21. }
  22. /**
  23. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  24. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  25. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  26. */
  27. /**
  28. * 查看
  29. */
  30. public function index()
  31. {
  32. //设置过滤方法
  33. $this->request->filter(['strip_tags']);
  34. if ($this->request->isAjax()) {
  35. //如果发送的来源是Selectpage,则转发到Selectpage
  36. if ($this->request->request('keyField')) {
  37. return $this->selectpage();
  38. }
  39. // 过滤机构
  40. $childInsIds = $this->auth->getMyInsId();
  41. if($childInsIds == false){
  42. $more = false;
  43. } else {
  44. $more = ['e.institution_id' => ['in', $childInsIds]];
  45. }
  46. $field = ['name,institution_id,e.depart,e.exam_class as device,q.study_result,q.study_score'];
  47. $ins = Db::table('institution')->cache('allins',180)->column('id,name');
  48. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  49. $total = $this->model
  50. ->alias('q')
  51. ->join(['exams'=>'e'],'e.id=q.exam_id')
  52. ->where("q.type = 1 or q.type = 3")
  53. ->where('task_type',1)
  54. ->where($where)
  55. ->where($more)
  56. ->order($sort, $order)
  57. ->count();
  58. $list = $this->model
  59. ->alias('q')
  60. ->join(['exams'=>'e'],'e.id=q.exam_id')
  61. ->where("q.type = 1 or q.type = 3")
  62. ->where('task_type',1)
  63. ->where($where)
  64. ->where($more)
  65. ->field($field)
  66. ->order($sort, $order)
  67. ->limit($offset, $limit)
  68. ->select();
  69. $list = collection($list)->toArray();
  70. foreach ($list as $k=>$v)
  71. {
  72. $list[$k]['institution_name'] = $ins[$v['institution_id']] ?? '';
  73. }
  74. $result = array("total" => $total, "rows" => $list);
  75. return json($result);
  76. }
  77. return $this->view->fetch();
  78. }
  79. }