Standards.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 Standards extends Backend
  12. {
  13. /**
  14. * Standards模型对象
  15. * @var \app\admin\model\manage\Standards
  16. */
  17. protected $model = null;
  18. protected $noNeedRight = ['standardselectlist'];
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = new \app\admin\model\manage\Standards;
  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. $ins = Db::table('institution')->column('id,name');
  42. if($this->auth->isSuperAdmin()){
  43. $more = false;
  44. } else {
  45. $admin = $this->auth->getUserInfo();
  46. $childInsIds = $admin['institution']['my_institution'];
  47. $more = ['institution_id' => ['in', $childInsIds]];
  48. }
  49. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  50. $total = $this->model
  51. ->where($where)
  52. ->where($more)
  53. ->order($sort, $order)
  54. ->count();
  55. $list = $this->model
  56. ->where($where)
  57. ->where($more)
  58. ->order($sort, $order)
  59. ->limit($offset, $limit)
  60. ->select();
  61. $list = collection($list)->toArray();
  62. foreach ($list as $k=>$v)
  63. {
  64. $list[$k]['institution_name'] = $ins[$v['institution_id']] ?? '';
  65. }
  66. $result = array("total" => $total, "rows" => $list);
  67. return json($result);
  68. }
  69. return $this->view->fetch();
  70. }
  71. public function standardSelectList()
  72. {
  73. try{
  74. // 当前可见机构
  75. if($this->auth->isSuperAdmin()){
  76. $more = false;
  77. } else {
  78. $admin = $this->auth->getUserInfo();
  79. $childInsIds = $admin['institution']['my_institution'];
  80. $more = ['id' => ['in', $childInsIds]];
  81. }
  82. // 获取列表
  83. $total = $this->model
  84. ->where($more)
  85. ->count();
  86. $list = $this->model
  87. ->where($more)
  88. ->field('id,title as name')
  89. ->select();
  90. // 格式化
  91. return json(array("total" => $total, "rows" => $list));
  92. } catch ( Exception $exception){
  93. $this->error($exception->getMessage());
  94. }
  95. }
  96. }