todo download
This commit is contained in:
parent
630aaf6beb
commit
33350cfd47
@ -42,7 +42,7 @@ class Admin extends BaseController
|
||||
if (empty($user) || $user->isEmpty()) {
|
||||
return ErrorResponse::createError(ErrorCode::ERROR_ADMIN_LOGIN_PWD, '用户名或者密码错误(1)');
|
||||
}
|
||||
if ($user->password != md5($username.$password . $user->salt)) {
|
||||
if ($user->password != md5($username . $password . $user->salt)) {
|
||||
return ErrorResponse::createError(ErrorCode::ERROR_ADMIN_LOGIN_PWD, '用户名或者密码错误(2)');;
|
||||
}
|
||||
$data = $user->getPartData(['id', 'username', 'email', 'avatar', 'last_login', 'sex']);
|
||||
@ -100,34 +100,56 @@ class Admin extends BaseController
|
||||
{
|
||||
$resultType = $this->request->get('resultType');
|
||||
if ($resultType == null) $resultType = EvaluationService::ResultAll;
|
||||
list($page,$size) = $this->getPageParam();
|
||||
list($page, $size) = $this->getPageParam();
|
||||
$data = EvaluationService::search(
|
||||
intval($resultType),
|
||||
$this->request->get('name'),
|
||||
$this->request->get('sort', EvaluationService::SortByTime),
|
||||
$page,$size
|
||||
$page, $size
|
||||
);
|
||||
return SuccessResponse::create($data->toArray());
|
||||
}
|
||||
|
||||
public function downloadEvaluation(){
|
||||
public function downloadEvaluation()
|
||||
{
|
||||
$resultType = $this->request->get('resultType');
|
||||
if ($resultType == null) $resultType = EvaluationService::ResultAll;
|
||||
list($page,$size) = $this->getPageParam();
|
||||
list($page, $size) = $this->getPageParam();
|
||||
|
||||
$data = EvaluationService::search(
|
||||
intval($resultType),
|
||||
$this->request->get('name'),
|
||||
$this->request->get('sort', EvaluationService::SortByTime),
|
||||
$page,$size);
|
||||
$page, $size);
|
||||
|
||||
|
||||
$dataType = $this->request->post('type');
|
||||
|
||||
$excel = new Spreadsheet();
|
||||
$sheet = $excel->getActiveSheet();
|
||||
// $rowNumber =
|
||||
$sheet->setCellValue('A1', 'Hello World !');
|
||||
$rowNumber = 1;
|
||||
$titles = [
|
||||
'A' => ['text' => '自评时间', 'key' => 'create_time'],
|
||||
'B' => ['text' => '姓名', 'key' => 'realname'],
|
||||
'C' => ['text' => '头痛症状', 'key' => 'headache'],
|
||||
'D' => ['text' => '胃肠道症状', 'key' => 'gastrointestinal'],
|
||||
'E' => ['text' => '劳累或疲劳', 'key' => 'tired'],
|
||||
'F' => ['text' => '头晕或眩晕', 'key' => 'dizzy'],
|
||||
'G' => ['text' => '总分', 'key' => 'score'],
|
||||
'H' => ['text' => '评估结果', 'key' => 'resultType'],
|
||||
'I' => ['text' => '性别', 'key' => 'gender'],
|
||||
'J' => ['text' => '年龄', 'key' => 'age']
|
||||
];
|
||||
$fields = explode(',', 'A,B,C,D,E,F,G.H');
|
||||
foreach ($fields as $f) {
|
||||
$sheet->setCellValue($f . $rowNumber, $titles[$f]);
|
||||
}
|
||||
foreach ($data->dataList as $item) {
|
||||
$rowNumber++;
|
||||
foreach ($fields as $f) {
|
||||
$sheet->setCellValue($f . $rowNumber, $item[$f]);
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
$filename = urlencode("评估记录_") . date('mdHi');
|
||||
@ -135,7 +157,7 @@ class Admin extends BaseController
|
||||
if ($dataType == 'xlsx') {
|
||||
$writer = new Xlsx($excel);
|
||||
$filename .= '.xlsx';
|
||||
}else {
|
||||
} else {
|
||||
$filename .= '.csv';
|
||||
}
|
||||
header('Content-Disposition: attachment;filename=' . $filename);
|
||||
|
@ -11,16 +11,22 @@ namespace app\util;
|
||||
|
||||
class ListCountData
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $totalCount;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $dataList;
|
||||
|
||||
public function __construct(int $count, $data)
|
||||
public function __construct(int $count,array $data)
|
||||
{
|
||||
$this->totalCount = $count;
|
||||
$this->dataList = $data;
|
||||
}
|
||||
|
||||
public static function Create(int $count, $data)
|
||||
public static function Create(int $count, array $data)
|
||||
{
|
||||
return new ListCountData($count, $data);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user