feat: 添加留言记录(联系我们)分页/导出接口
This commit is contained in:
75
app/admin/controller/v1/LeaveMessage.php
Normal file
75
app/admin/controller/v1/LeaveMessage.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\admin\controller\v1;
|
||||
|
||||
use app\admin\model\v1\LeaveMessageModel;
|
||||
|
||||
/**
|
||||
* 留言记录(联系我们)控制器
|
||||
*/
|
||||
class LeaveMessage
|
||||
{
|
||||
// 分页
|
||||
public function index()
|
||||
{
|
||||
$param = request()->param([
|
||||
'created_at',
|
||||
'page/d' => 1,
|
||||
'size/d' => 10
|
||||
]);
|
||||
|
||||
$msgs = LeaveMessageModel::withoutField([
|
||||
'language_id',
|
||||
'user_agent'
|
||||
])
|
||||
->withSearch(['created_at'], [
|
||||
'created_at' => !empty($param['created_at']) ? explode(',', $param['created_at']) : null
|
||||
])
|
||||
->language(request()->lang_id)
|
||||
->order(['id' => 'desc'])
|
||||
->paginate([
|
||||
'list_rows' => $param['size'],
|
||||
'page' => $param['page']
|
||||
]);
|
||||
|
||||
return success('获取成功', $msgs);
|
||||
}
|
||||
|
||||
// 导出
|
||||
public function export()
|
||||
{
|
||||
$schema = [
|
||||
'id' => 'ID',
|
||||
'name' => '姓名',
|
||||
'email' => '邮箱',
|
||||
'ip' => 'IP',
|
||||
'content' => '留言内容',
|
||||
'created_at' => '提交时间'
|
||||
];
|
||||
|
||||
// 获取留言导出数据
|
||||
$msgs = $this->getLeaveMessageExportData();
|
||||
|
||||
// 导出
|
||||
return xlsx_writer($msgs, $schema);
|
||||
}
|
||||
// 获取留言导出数据
|
||||
private function getLeaveMessageExportData()
|
||||
{
|
||||
$param = request()->param([
|
||||
'created_at'
|
||||
]);
|
||||
|
||||
return LeaveMessageModel::withoutField([
|
||||
'language_id',
|
||||
'user_agent'
|
||||
])
|
||||
->withSearch(['created_at'], [
|
||||
'created_at' => !empty($param['created_at']) ? explode(',', $param['created_at']) : null
|
||||
])
|
||||
->language(request()->lang_id)
|
||||
->order(['id' => 'desc'])
|
||||
->select();
|
||||
}
|
||||
}
|
||||
32
app/admin/model/v1/LeaveMessageModel.php
Normal file
32
app/admin/model/v1/LeaveMessageModel.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\admin\model\v1;
|
||||
|
||||
use app\common\model\LeaveMessageBaseModel;
|
||||
|
||||
/**
|
||||
* 留言记录(联系我们)模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class LeaveMessageModel extends LeaveMessageBaseModel
|
||||
{
|
||||
// 根据语言查询
|
||||
public function scopeLanguage($query, $value)
|
||||
{
|
||||
$query->where('language_id', '=', $value);
|
||||
}
|
||||
|
||||
// 按添加时间搜索
|
||||
public function searchCreatedAtAttr($query, $value, $data)
|
||||
{
|
||||
if (is_null($value)) return;
|
||||
if (is_array($value)) {
|
||||
if (count($value) > 1) {
|
||||
$query->whereBetweenTime('created_at', $value[0], $value[1]);
|
||||
} else {
|
||||
$query->whereTime('created_at', '>=', $value[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -519,6 +519,15 @@ Route::group('v1', function () {
|
||||
Route::delete('delete/:id', 'Faq/delete');
|
||||
});
|
||||
|
||||
// 反馈管理 - 留言记录(联系我们)
|
||||
Route::group('leavemsg', function() {
|
||||
// 留言记录(联系我们)分页
|
||||
Route::get('index', 'LeaveMessage/index');
|
||||
|
||||
// 留言记录(联系我们)导出
|
||||
Route::get('export', 'LeaveMessage/export');
|
||||
});
|
||||
|
||||
// 配置项列表
|
||||
Route::group('config', function() {
|
||||
// 配置分组
|
||||
|
||||
Reference in New Issue
Block a user