82 lines
2.3 KiB
PHP
82 lines
2.3 KiB
PHP
<?php
|
||
|
||
namespace app\controller\manager;
|
||
|
||
use app\model\Feedback as FeedbackModel;
|
||
use app\model\Log;
|
||
use Exception;
|
||
use think\response\Json;
|
||
use think\response\View;
|
||
|
||
/**
|
||
* 意见反馈
|
||
*
|
||
* Class Feedback
|
||
* @package app\controller\manager
|
||
*/
|
||
class Feedback extends Base
|
||
{
|
||
/**
|
||
* 删除
|
||
*
|
||
* @return Json
|
||
*/
|
||
public function del(): Json
|
||
{
|
||
if ($this->request->isPost()) {
|
||
$ids = input('post.ids/a', []);
|
||
if (empty($ids)) {
|
||
$ids[] = input('post.id/d');
|
||
}
|
||
FeedbackModel::deleteByIds($ids);
|
||
Log::write(get_class().'Del', 'del', '涉及到的ID为:'.implode(',', $ids));
|
||
return $this->json();
|
||
}
|
||
return $this->json(4001, '非法请求!');
|
||
}
|
||
|
||
/**
|
||
* 列表
|
||
*
|
||
* @return View|Json
|
||
* @throws Exception
|
||
*/
|
||
public function index()
|
||
{
|
||
if ($this->request->isPost()) {
|
||
$page = input('page/d', 1);
|
||
$limit = input('size/d', 20);
|
||
$searchParams = input('searchParams', []);
|
||
$search = [];
|
||
if ($searchParams) {
|
||
$searchParams = array_map('trim', $searchParams);
|
||
if (isset($searchParams['user_keyword']) && !empty($searchParams['user_keyword'])) {
|
||
$search[] = ['user_name|user_tel|user_email', 'like', '%'.$searchParams['user_keyword'].'%'];
|
||
}
|
||
unset($searchParams['user_keyword']);
|
||
|
||
foreach ($searchParams as $key => $param) {
|
||
if ($param) {
|
||
$search[] = [$key, 'like', '%'.$param.'%'];
|
||
}
|
||
}
|
||
}
|
||
|
||
$items = FeedbackModel::findList($search, [], $page, $limit, function ($q) {
|
||
return $q->with(['account'])->order('id', 'desc');
|
||
});
|
||
|
||
$items['list'] = $items['list']->each(function ($item) {
|
||
if ($item->account) {
|
||
$item->user_name = empty($item->user_name) ? ($item->account->nickname ?? '') : $item->user_name;
|
||
$item->user_tel = empty($item->user_tel) ? ($item->account->mobile ?? '') : $item->user_tel;
|
||
}
|
||
});
|
||
|
||
return $this->json(0, '操作成功', $items);
|
||
}
|
||
|
||
|
||
return $this->view();
|
||
}
|
||
} |