Dimension.php 3.0 KB

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