满意度调查导出

main
yanzai 12 months ago
parent fa6cde2d9a
commit 521a17e22b

@ -14,65 +14,70 @@ class QuestionController extends Controller
if (!isset($searchInfo['hospital_id'])) return \Yz::echoError1("医院id不能为空");
if (!isset($searchInfo['q_type'])) return \Yz::echoError1("问卷类型不能为空");
$list = DB::table('questions')
->where(['hospital_id'=>$searchInfo['hospital_id'],
'q_type'=>$searchInfo['q_type'],
'is_del'=>0,
])->orderBy('order','asc')->get();
return \Yz::Return(true,"查询成功",['list'=>$list]);
->where(['hospital_id' => $searchInfo['hospital_id'],
'q_type' => $searchInfo['q_type'],
'is_del' => 0,
])->orderBy('order', 'asc')->get();
return \Yz::Return(true, "查询成功", ['list' => $list]);
}
public function Save()
{
$QuestionInfo = request('QuestionInfo');
$params = [
'hospital_id'=>isset($QuestionInfo['hospital_id'])?$QuestionInfo['hospital_id']:null,
'question'=>isset($QuestionInfo['question'])?$QuestionInfo['question']:null,
'content'=>(isset($QuestionInfo['content']) and !empty($QuestionInfo['content']))?json_encode($QuestionInfo['content'],JSON_UNESCAPED_UNICODE):null,
'type'=>isset($QuestionInfo['type'])?$QuestionInfo['type']:null,
'status'=>isset($QuestionInfo['status'])?$QuestionInfo['status']:null,
'order'=>isset($QuestionInfo['order'])?$QuestionInfo['order']:null,
'q_type'=>isset($QuestionInfo['q_type'])?$QuestionInfo['q_type']:null,
'hospital_id' => isset($QuestionInfo['hospital_id']) ? $QuestionInfo['hospital_id'] : null,
'question' => isset($QuestionInfo['question']) ? $QuestionInfo['question'] : null,
'content' => (isset($QuestionInfo['content']) and !empty($QuestionInfo['content'])) ? json_encode($QuestionInfo['content'], JSON_UNESCAPED_UNICODE) : null,
'type' => isset($QuestionInfo['type']) ? $QuestionInfo['type'] : null,
'status' => isset($QuestionInfo['status']) ? $QuestionInfo['status'] : null,
'order' => isset($QuestionInfo['order']) ? $QuestionInfo['order'] : null,
'q_type' => isset($QuestionInfo['q_type']) ? $QuestionInfo['q_type'] : null,
];
$requiredFields = [
'hospital_id','question','content','type','status','order','q_type'
'hospital_id', 'question', 'content', 'type', 'status', 'order', 'q_type'
];
// 判断是否为空
foreach ($requiredFields as $field) {
if (!isset($params[$field]) || $params[$field] === null) {
return \Yz::echoError1('参数' . $field . '不能为空');
return \Yz::echoError1('参数' . $field . '不能为空');
}
}
if(isset($QuestionInfo['id']) and $QuestionInfo['id']<>0){
$insert=DB::table('questions')->where(['id'=>$QuestionInfo['id'],'is_del'=>0])->update($params);
}else{
$insert=DB::table('questions')->insert($params);
if (isset($QuestionInfo['id']) and $QuestionInfo['id'] <> 0) {
$insert = DB::table('questions')->where(['id' => $QuestionInfo['id'], 'is_del' => 0])->update($params);
} else {
$insert = DB::table('questions')->insert($params);
}
if($insert){
return \Yz::Return(true,'操作成功',[]);
}else{
if ($insert) {
return \Yz::Return(true, '操作成功', []);
} else {
return \Yz::echoError1('操作失败');
}
}
public function GetDetail()
{
$id = request('id');
$info=DB::table('questions')->where(['id'=>$id,'is_del'=>0])->first();
if(!!$info){
$info->content=json_decode($info->content,true);
$info = DB::table('questions')->where(['id' => $id, 'is_del' => 0])->first();
if (!!$info) {
$info->content = json_decode($info->content, true);
}
return \Yz::Return(true,'查询完成',$info);
return \Yz::Return(true, '查询完成', $info);
}
public function Del()
{
$id = request('id');
$del=DB::table('questions')->where(['id'=>$id])->update([
'is_del'=>1
$del = DB::table('questions')->where(['id' => $id])->update([
'is_del' => 1
]);
if($del){
return \Yz::Return(true,'操作成功',[]);
}else{
if ($del) {
return \Yz::Return(true, '操作成功', []);
} else {
return \Yz::echoError1('操作失败');
}
}
}

@ -0,0 +1,117 @@
<?php
namespace App\Http\Controllers\API\Admin\YeWu;
use App\Http\Controllers\Controller;
use App\Lib\Tools;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
class QuestionLogController extends Controller
{
public function Export()
{
$q_type = request('q_type');
$q_list=DB::table('questions')->where(['q_type'=>2,'is_del'=>0,'status'=>1])->orderBy('order','asc')->get();
$log_list = DB::table('questions_log')->where(['q_type' => $q_type])->get();
if(count($log_list)==0) return \Yz::echoError1("暂无数据可导出");
$cols_SN = $this->generateSequence(400);
$template_path = Storage::path('public/excel/manyidudiaocha.xlsx');
$spreadsheet = IOFactory::load($template_path);
$worksheet = $spreadsheet->getActiveSheet();
$styleArray = [
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
'color' => ['argb' => 'FF000000'],
],
],
];
$row=3;
foreach ($log_list as $key=> $item) {
$personinfo=DB::table('web_user_person')->where(['id'=>$item->personid])->first();
$sex='未知';
if($personinfo->sex==1) $sex='男';
if($personinfo->sex==2) $sex='女';
$item->content=json_decode($item->content,true);
$worksheet->setCellValueExplicit($cols_SN[0] . $row, $key+1, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
$worksheet->setCellValueExplicit($cols_SN[1] . $row, $personinfo->name, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
$worksheet->setCellValueExplicit($cols_SN[2] . $row, $item->created_at, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
$worksheet->setCellValueExplicit($cols_SN[3] . $row, $personinfo->name, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
$worksheet->setCellValueExplicit($cols_SN[4] . $row, $personinfo->phone, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
$worksheet->setCellValueExplicit($cols_SN[5] . $row, $sex, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
$worksheet->setCellValueExplicit($cols_SN[6] . $row, $personinfo->birthday, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
$worksheet->setCellValueExplicit($cols_SN[7] . $row, Tools::GetAge($personinfo->birthday), \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
foreach ( $item->content as $q_key=>$q_item){
foreach ($q_item['more'] as $morekey=>$moreitem){
if($moreitem<>null){
$q_item['answer'][0]=$q_item['answer'][0].','.$moreitem;
}
}
$worksheet->setCellValueExplicit($cols_SN[8+$q_key] . $row, $q_item['answer'][0], \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
}
$row++;
}
$worksheet->getStyle('A3:Z' . ($row - 1))->applyFromArray($styleArray);
$file_name = Str::orderedUuid();
$dir_path = "public/excel/" . date('Ym') . '/' . $file_name;
Storage::makeDirectory($dir_path);
//$name_date = date('n.j', strtotime($date . ' 00:00:00'));
$excel_path = $dir_path . "/满意度调查.xlsx";
$writer = new Xlsx($spreadsheet);
$writer->save(Storage::path($excel_path));
$url = Storage::url($excel_path);
return \Yz::Return(true,"获取成功",['url' => env('APP_URL').$url]);
}
function generateSequence($L) {
$sequence = [];
$current = '';
// Helper function to increment the sequence
function increment(&$str) {
$len = strlen($str);
$str = strrev($str); // Reverse string for easier manipulation
for ($i = 0; $i < $len; $i++) {
if ($str[$i] == 'Z') {
$str[$i] = 'A';
} else {
$str[$i] = chr(ord($str[$i]) + 1);
break;
}
}
// If we've gone through all characters and they were all 'Z'
if ($i == $len && $str[$len-1] == 'A') {
$str .= 'A'; // Append an 'A' at the end, equivalent to carrying over
}
$str = strrev($str); // Reverse back to original order
}
// Initialize the first value of the sequence
if ($L > 0) {
$current = 'A';
$sequence[] = $current;
}
// Generate the sequence up to length L
for ($i = 1; $i < $L; $i++) {
increment($current);
$sequence[] = $current;
}
return $sequence;
}
}

@ -38,8 +38,13 @@ class QuestionController extends Controller
if (!$user) return \Yz::echoError1('用户不存在');
if(!isset($q_type)) return \Yz::echoError1('问卷类型不能为空');
if(!isset($content) or empty($content)) return \Yz::echoError1('内容不能为空');
$person=DB::table('web_user_person')->where(['user_id' => $user->id, 'is_del' => 0])->orderBy('is_default')->get();
if(count($person)==0){
return \Yz::echoError1('请先绑定就诊人');
}
$data=[
'userid'=>$user->id,
'personid'=>$person[0]->id,
'q_type'=>$q_type,
'content'=>json_encode($content,JSON_UNESCAPED_UNICODE)
];

@ -134,6 +134,9 @@ Route::group(['middleware' => ['checktoken', 'log'], 'prefix' => 'v1'], function
Route::post('admin/CouponsDel', 'App\Http\Controllers\API\Admin\YeWu\CouponsController@Del');
Route::post('admin/CouponsGetDetail', 'App\Http\Controllers\API\Admin\YeWu\CouponsController@GetDetail');
Route::post('admin/QuestionExport', 'App\Http\Controllers\API\Admin\YeWu\QuestionLogController@Export');//导出回答
});

@ -429,4 +429,8 @@ export const PlanListGetList = (data = {}) => {
//导出分诊数据
export const FenzhenInfoExport = (data = {}) => {
return axios({ url: import.meta.env.VITE_APP_API + `FenzhenInfoExport`, data: data })
}
//导出问卷
export const QuestionExport = (data = {}) => {
return axios({ url: import.meta.env.VITE_APP_API + `v1/admin/QuestionExport`, data: data })
}

@ -22,6 +22,11 @@
<el-radio-button :label="1">健康问卷</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item>
<el-button type="warning" style="margin-left: 50px;" @click="Export()"></el-button>
</el-form-item>
</el-row>
</div>
<el-table :data="tableData" style="width: 100%;" row-key="id" v-loading="loading">
@ -120,7 +125,7 @@
} from 'element-plus'
import {
HospitalGetEnableList,
QuestionGetList,QuestionSave,QuestionGetDetail,QuestionDel
QuestionGetList,QuestionSave,QuestionGetDetail,QuestionDel,QuestionExport
} from '@/api/api.js'
import {
Edit,
@ -285,6 +290,23 @@
}
})
}
const Export=()=>{
loading.value = true
QuestionExport({
q_type: searchInfo.value.q_type
}).then(res => {
loading.value = false
if (res.status) {
const a = document.createElement('a');
a.style.display = 'none';
a.href = res.data.url;
document.body.appendChild(a);
a.click();
} else {
ElMessage.error(res.msg)
}
})
}
onMounted(() => {
searchInfo.value.q_type = 2
GetEnableHospitalList_func()

Loading…
Cancel
Save