diff --git a/Laravel/app/Http/Controllers/API/Admin/YeWu/QuestionController.php b/Laravel/app/Http/Controllers/API/Admin/YeWu/QuestionController.php
index b43c455..8b7fbf5 100644
--- a/Laravel/app/Http/Controllers/API/Admin/YeWu/QuestionController.php
+++ b/Laravel/app/Http/Controllers/API/Admin/YeWu/QuestionController.php
@@ -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('操作失败');
}
}
+
+
}
diff --git a/Laravel/app/Http/Controllers/API/Admin/YeWu/QuestionLogController.php b/Laravel/app/Http/Controllers/API/Admin/YeWu/QuestionLogController.php
new file mode 100644
index 0000000..d0048f5
--- /dev/null
+++ b/Laravel/app/Http/Controllers/API/Admin/YeWu/QuestionLogController.php
@@ -0,0 +1,117 @@
+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;
+ }
+}
diff --git a/Laravel/app/Http/Controllers/API/H5/QuestionController.php b/Laravel/app/Http/Controllers/API/H5/QuestionController.php
index 0d1f753..6abeb3c 100644
--- a/Laravel/app/Http/Controllers/API/H5/QuestionController.php
+++ b/Laravel/app/Http/Controllers/API/H5/QuestionController.php
@@ -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)
];
diff --git a/Laravel/routes/api.php b/Laravel/routes/api.php
index 7834830..c32ec5b 100644
--- a/Laravel/routes/api.php
+++ b/Laravel/routes/api.php
@@ -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');//导出回答
+
+
});
diff --git a/admin/src/api/api.js b/admin/src/api/api.js
index a3b631a..7bf5e0d 100644
--- a/admin/src/api/api.js
+++ b/admin/src/api/api.js
@@ -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 })
}
\ No newline at end of file
diff --git a/admin/src/views/HospitalMngr/Questions.vue b/admin/src/views/HospitalMngr/Questions.vue
index 541b477..bee866f 100644
--- a/admin/src/views/HospitalMngr/Questions.vue
+++ b/admin/src/views/HospitalMngr/Questions.vue
@@ -22,6 +22,11 @@
健康问卷
+
+ 导出用户问卷
+
+
+
@@ -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()