Question.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace app\admin\controller\ask;
  3. use app\common\controller\Backend;
  4. /**
  5. * 问答问题管理
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Question extends Backend
  10. {
  11. /**
  12. * Question模型对象
  13. * @var \app\admin\model\ask\Question
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \app\admin\model\ask\Question;
  20. $this->view->assign("flagList", $this->model->getFlagList());
  21. $this->view->assign("statusList", $this->model->getStatusList());
  22. }
  23. public function index()
  24. {
  25. $this->relationSearch = true;
  26. //设置过滤方法
  27. $this->request->filter(['strip_tags']);
  28. if ($this->request->isAjax()) {
  29. //如果发送的来源是Selectpage,则转发到Selectpage
  30. if ($this->request->request('keyField')) {
  31. return $this->selectpage();
  32. }
  33. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  34. $total = $this->model->with(['user', 'category'])
  35. ->where($where)
  36. ->order($sort, $order)
  37. ->count();
  38. $list = $this->model->with(['user', 'category'])
  39. ->where($where)
  40. ->order($sort, $order)
  41. ->limit($offset, $limit)
  42. ->select();
  43. foreach ($list as $index => $item) {
  44. $item->user->visible(['id', 'nickname']);
  45. }
  46. $list = collection($list)->toArray();
  47. $result = array("total" => $total, "rows" => $list);
  48. return json($result);
  49. }
  50. return $this->view->fetch();
  51. }
  52. /**
  53. * 还原
  54. */
  55. public function restore($ids = "")
  56. {
  57. $pk = $this->model->getPk();
  58. $adminIds = $this->getDataLimitAdminIds();
  59. if (is_array($adminIds)) {
  60. $this->model->where($this->dataLimitField, 'in', $adminIds);
  61. }
  62. if ($ids) {
  63. $this->model->where($pk, 'in', $ids);
  64. }
  65. $count = 0;
  66. $list = $this->model->onlyTrashed()->select();
  67. foreach ($list as $index => $item) {
  68. $item->deletetime = null;
  69. $item->save();
  70. $count++;
  71. }
  72. if ($count) {
  73. $this->success();
  74. }
  75. $this->error(__('No rows were updated'));
  76. }
  77. }