Servicegrade.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use app\admin\model\Servicequestion;
  5. use think\Db;
  6. /**
  7. * 社区服务提交内容
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Servicegrade extends Backend
  12. {
  13. /**
  14. * Servicegrade模型对象
  15. * @var \app\admin\model\Servicegrade
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\Servicegrade;
  22. $this->multiFields = 'status_switch';
  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->relationSearch = true;
  36. //设置过滤方法
  37. $this->request->filter(['strip_tags', 'trim']);
  38. if ($this->request->isAjax()) {
  39. //如果发送的来源是Selectpage,则转发到Selectpage
  40. if ($this->request->request('keyField')) {
  41. return $this->selectpage();
  42. }
  43. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  44. $list = $this->model
  45. ->with(['paper','user'])
  46. ->where($where)
  47. ->order($sort, $order)
  48. ->paginate($limit);
  49. foreach ($list as $row) {
  50. $row->getRelation('paper')->visible(['name']);
  51. $row->getRelation('user')->visible(['nickname']);
  52. }
  53. $result = array("total" => $list->total(), "rows" => $list->items());
  54. return json($result);
  55. }
  56. return $this->view->fetch();
  57. }
  58. /**
  59. * 详情
  60. */
  61. public function detail($ids = null)
  62. {
  63. $row = $this->getDetail($ids);
  64. if (!$row) {
  65. $this->error(__('No Results were found'));
  66. }
  67. $adminIds = $this->getDataLimitAdminIds();
  68. if (is_array($adminIds)) {
  69. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  70. $this->error(__('You have no permission'));
  71. }
  72. }
  73. // dump($row);exit;
  74. $this->view->assign("row", $row);
  75. return $this->view->fetch();
  76. }
  77. /**
  78. * 详情
  79. */
  80. public function one($ids = null)
  81. {
  82. $row = $this->getDetail($ids);
  83. return json($row, 1);
  84. }
  85. /**
  86. * 获取并处理详情数据
  87. *
  88. * @param $ids
  89. * @return \app\admin\model\exam\GradeModel|array
  90. */
  91. protected function getDetail($ids)
  92. {
  93. $row = $this->model->get($ids);
  94. if (!$row) {
  95. $this->error(__('No Results were found'));
  96. }
  97. if (
  98. (!isset($row['question_ids']) || !$row['question_ids']) ||
  99. (!isset($row['user_answers']) || !$row['user_answers'])
  100. ) {
  101. $this->error('答卷数据缺少,无法查看(可能是旧版本未记录数据导致)');
  102. }
  103. $Servicequestion = new Servicequestion();
  104. $row['questions'] = $Servicequestion->whereIn('id', $row['question_ids'])
  105. ->orderRaw("find_in_set(id, '" . $row['question_ids'] . "')")
  106. ->select();
  107. $row['user_answers'] = json_decode($row['user_answers'], true);
  108. $row['createtime_text'] = date('Y-m-d H:i:s', $row['createtime']);
  109. // dump($row['questions']);exit;
  110. return $row;
  111. }
  112. }