Feedback.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use app\common\model\Feedback as FeedbackModel;
  5. class Feedback extends Backend
  6. {
  7. protected $modelClass = null;
  8. protected $modelValidate = false;
  9. protected $searchFields = 'id,feedback_type_text,lang,source_page,ip,user_agent';
  10. protected function initialize()
  11. {
  12. parent::initialize();
  13. $this->modelClass = new FeedbackModel();
  14. $this->assign('typeList', $this->modelClass->getTypeList());
  15. }
  16. public function index()
  17. {
  18. if ($this->request->isAjax()) {
  19. $page = (int)$this->request->param('page/d', 1);
  20. $limit = (int)$this->request->param('limit/d', 20);
  21. $sort = (string)$this->request->param('sort/s', 'id');
  22. $order = (string)$this->request->param('order/s', 'desc');
  23. $query = $this->buildFeedbackQuery();
  24. $count = (clone $query)->count();
  25. $data = $query->order($sort, $order)->page($page, $limit)->select();
  26. return json(['code' => 0, 'count' => $count, 'data' => $data]);
  27. }
  28. return $this->fetch();
  29. }
  30. public function del()
  31. {
  32. if (!$this->request->isPost()) {
  33. $this->error('请求方式错误');
  34. }
  35. $ids = $this->request->post('ids/a', []);
  36. if (!$ids) {
  37. $this->error('请先选择评价记录');
  38. }
  39. $count = $this->modelClass->where('id', 'in', $ids)->delete();
  40. $this->success('已删除 ' . (int)$count . ' 条评价记录');
  41. }
  42. protected function buildFeedbackQuery()
  43. {
  44. $feedbackType = trim((string)$this->request->param('feedback_type/s', ''));
  45. $lang = trim((string)$this->request->param('lang/s', ''));
  46. $rating = $this->request->param('rating/s', '');
  47. $ip = trim((string)$this->request->param('ip/s', ''));
  48. $sourcePage = trim((string)$this->request->param('source_page/s', ''));
  49. $createtimeStart = trim((string)$this->request->param('createtime_start/s', ''));
  50. $createtimeEnd = trim((string)$this->request->param('createtime_end/s', ''));
  51. $query = $this->modelClass;
  52. if ($feedbackType !== '') {
  53. $query = $query->where('feedback_type', $feedbackType);
  54. }
  55. if ($lang !== '') {
  56. $query = $query->where('lang', $lang);
  57. }
  58. if ($rating !== '') {
  59. $query = $query->where('rating', (int)$rating);
  60. }
  61. if ($ip !== '') {
  62. $query = $query->where('ip', 'like', '%' . $ip . '%');
  63. }
  64. if ($sourcePage !== '') {
  65. $query = $query->where('source_page', 'like', '%' . $sourcePage . '%');
  66. }
  67. if ($createtimeStart !== '') {
  68. $timestamp = strtotime($createtimeStart);
  69. if ($timestamp) {
  70. $query = $query->where('createtime', '>=', $timestamp);
  71. }
  72. }
  73. if ($createtimeEnd !== '') {
  74. $timestamp = strtotime($createtimeEnd);
  75. if ($timestamp) {
  76. $query = $query->where('createtime', '<=', $timestamp);
  77. }
  78. }
  79. return $query;
  80. }
  81. }