add:新增导出用户
This commit is contained in:
parent
3a2689db18
commit
bd7f62b9ed
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace catchAdmin\permissions\controller;
|
||||
|
||||
use catchAdmin\permissions\excel\UserExport;
|
||||
use catcher\base\CatchRequest as Request;
|
||||
use catchAdmin\permissions\model\Permissions;
|
||||
use catchAdmin\permissions\model\Roles;
|
||||
@ -11,6 +12,7 @@ use catcher\base\CatchController;
|
||||
use catcher\CatchAuth;
|
||||
use catcher\CatchCacheKeys;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\library\excel\Excel;
|
||||
use catcher\Tree;
|
||||
use catcher\Utils;
|
||||
use think\facade\Cache;
|
||||
@ -227,4 +229,18 @@ class User extends CatchController
|
||||
'hasRoles' => $roleIds,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出
|
||||
*
|
||||
* @time 2020年09月08日
|
||||
* @param Excel $excel
|
||||
* @param UserExport $userExport
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function export(Excel $excel, UserExport $userExport)
|
||||
{
|
||||
return CatchResponse::success($excel->save($userExport, Utils::publicPath('export/users')));
|
||||
}
|
||||
}
|
||||
|
@ -8,3 +8,71 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
namespace catchAdmin\permissions\excel;
|
||||
|
||||
use catchAdmin\permissions\model\Users;
|
||||
use catcher\library\excel\ExcelContract;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
|
||||
class UserExport implements ExcelContract
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置头部
|
||||
*
|
||||
* @time 2020年09月08日
|
||||
* @return string[]
|
||||
*/
|
||||
public function headers(): array
|
||||
{
|
||||
// TODO: Implement headers() method.
|
||||
return [
|
||||
'id', '用户名', '邮箱', '状态', '创建日期'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理数据
|
||||
*
|
||||
* @time 2020年09月08日
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return \think\Collection
|
||||
*/
|
||||
public function sheets()
|
||||
{
|
||||
// TODO: Implement sheets() method.
|
||||
$users = Users::field(['id', 'username', 'email', 'status', 'created_at'])->select();
|
||||
|
||||
foreach ($users as &$user) {
|
||||
$user->status = $user->status == Users::ENABLE ? '启用' : '停用';
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置开始行
|
||||
*
|
||||
* @time 2020年09月08日
|
||||
* @return int
|
||||
*/
|
||||
public function setRow()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置标题
|
||||
*
|
||||
* @time 2020年09月08日
|
||||
* @return array
|
||||
*/
|
||||
public function setTitle()
|
||||
{
|
||||
return [
|
||||
'A1:G1', '导出用户', Alignment::HORIZONTAL_CENTER
|
||||
];
|
||||
}
|
||||
}
|
@ -23,4 +23,5 @@ $router->group(function () use ($router){
|
||||
$router->put('users/recover/<id>', '\catchAdmin\permissions\controller\User@recover');
|
||||
$router->get('users/get/roles', '\catchAdmin\permissions\controller\User@getRoles');
|
||||
$router->get('user/info', '\catchAdmin\permissions\controller\User@info');
|
||||
$router->get('user/export', '\catchAdmin\permissions\controller\User@export');
|
||||
})->middleware('auth');
|
Loading…
x
Reference in New Issue
Block a user