| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use app\common\model\Feedback as FeedbackModel;
- class Feedback extends Backend
- {
- protected $modelClass = null;
- protected $modelValidate = false;
- protected $searchFields = 'id,feedback_type_text,lang,source_page,ip,user_agent';
- protected function initialize()
- {
- parent::initialize();
- $this->modelClass = new FeedbackModel();
- $this->assign('typeList', $this->modelClass->getTypeList());
- }
- public function index()
- {
- if ($this->request->isAjax()) {
- $page = (int)$this->request->param('page/d', 1);
- $limit = (int)$this->request->param('limit/d', 20);
- $sort = (string)$this->request->param('sort/s', 'id');
- $order = (string)$this->request->param('order/s', 'desc');
- $query = $this->buildFeedbackQuery();
- $count = (clone $query)->count();
- $data = $query->order($sort, $order)->page($page, $limit)->select();
- return json(['code' => 0, 'count' => $count, 'data' => $data]);
- }
- return $this->fetch();
- }
- public function del()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式错误');
- }
- $ids = $this->request->post('ids/a', []);
- if (!$ids) {
- $this->error('请先选择评价记录');
- }
- $count = $this->modelClass->where('id', 'in', $ids)->delete();
- $this->success('已删除 ' . (int)$count . ' 条评价记录');
- }
- protected function buildFeedbackQuery()
- {
- $feedbackType = trim((string)$this->request->param('feedback_type/s', ''));
- $lang = trim((string)$this->request->param('lang/s', ''));
- $rating = $this->request->param('rating/s', '');
- $ip = trim((string)$this->request->param('ip/s', ''));
- $sourcePage = trim((string)$this->request->param('source_page/s', ''));
- $createtimeStart = trim((string)$this->request->param('createtime_start/s', ''));
- $createtimeEnd = trim((string)$this->request->param('createtime_end/s', ''));
- $query = $this->modelClass;
- if ($feedbackType !== '') {
- $query = $query->where('feedback_type', $feedbackType);
- }
- if ($lang !== '') {
- $query = $query->where('lang', $lang);
- }
- if ($rating !== '') {
- $query = $query->where('rating', (int)$rating);
- }
- if ($ip !== '') {
- $query = $query->where('ip', 'like', '%' . $ip . '%');
- }
- if ($sourcePage !== '') {
- $query = $query->where('source_page', 'like', '%' . $sourcePage . '%');
- }
- if ($createtimeStart !== '') {
- $timestamp = strtotime($createtimeStart);
- if ($timestamp) {
- $query = $query->where('createtime', '>=', $timestamp);
- }
- }
- if ($createtimeEnd !== '') {
- $timestamp = strtotime($createtimeEnd);
- if ($timestamp) {
- $query = $query->where('createtime', '<=', $timestamp);
- }
- }
- return $query;
- }
- }
|