Servicegrade.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. }
  23. /**
  24. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  25. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  26. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  27. */
  28. /**
  29. * 查看
  30. */
  31. public function index()
  32. {
  33. //当前是否为关联查询
  34. $this->relationSearch = true;
  35. //设置过滤方法
  36. $this->request->filter(['strip_tags', 'trim']);
  37. if ($this->request->isAjax()) {
  38. //如果发送的来源是Selectpage,则转发到Selectpage
  39. if ($this->request->request('keyField')) {
  40. return $this->selectpage();
  41. }
  42. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  43. $list = $this->model
  44. ->with(['paper','user'])
  45. ->where($where)
  46. ->order($sort, $order)
  47. ->paginate($limit);
  48. foreach ($list as $row) {
  49. $row->getRelation('paper')->visible(['name']);
  50. $row->getRelation('user')->visible(['nickname']);
  51. }
  52. $result = array("total" => $list->total(), "rows" => $list->items());
  53. return json($result);
  54. }
  55. return $this->view->fetch();
  56. }
  57. /**
  58. * 详情
  59. */
  60. public function detail($ids = null)
  61. {
  62. $row = $this->getDetail($ids);
  63. if (!$row) {
  64. $this->error(__('No Results were found'));
  65. }
  66. $adminIds = $this->getDataLimitAdminIds();
  67. if (is_array($adminIds)) {
  68. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  69. $this->error(__('You have no permission'));
  70. }
  71. }
  72. // dump($row);exit;
  73. $this->view->assign("row", $row);
  74. return $this->view->fetch();
  75. }
  76. /**
  77. * 详情
  78. */
  79. public function one($ids = null)
  80. {
  81. $row = $this->getDetail($ids);
  82. return json($row, 1);
  83. }
  84. /**
  85. * 获取并处理详情数据
  86. *
  87. * @param $ids
  88. * @return \app\admin\model\exam\GradeModel|array
  89. */
  90. protected function getDetail($ids)
  91. {
  92. $row = $this->model->get($ids);
  93. if (!$row) {
  94. $this->error(__('No Results were found'));
  95. }
  96. if (
  97. (!isset($row['question_ids']) || !$row['question_ids']) ||
  98. (!isset($row['user_answers']) || !$row['user_answers'])
  99. ) {
  100. $this->error('答卷数据缺少,无法查看(可能是旧版本未记录数据导致)');
  101. }
  102. $Servicequestion = new Servicequestion();
  103. $row['questions'] = $Servicequestion->whereIn('id', $row['question_ids'])
  104. ->orderRaw("find_in_set(id, '" . $row['question_ids'] . "')")
  105. ->select();
  106. $row['user_answers'] = json_decode($row['user_answers'], true);
  107. $row['createtime_text'] = date('Y-m-d H:i:s', $row['createtime']);
  108. // dump($row['questions']);exit;
  109. return $row;
  110. }
  111. }