Browse Source

档案导出

gorden 4 months ago
parent
commit
734230a4a7

+ 3 - 4
app/admin/controller/member/WellnessRecordController.php

@@ -617,12 +617,11 @@ class WellnessRecordController extends Curd
             unset($question['content_config_json']);
         }
 
-        dump($questions);
-
         $content = view('member/word', ['questions' => $questions])->rawBody();
-//        dump($content);
 
-        return File::exportPdf($content, date('YmdHis') . '.pdf');
+        $url = File::exportPdf($content, $memberId.'_'.date('YmdHis') . '.pdf');
+
+        return json_success("success",['url'=>$url]);
 
 //        $pdf->stream('my.pdf', ['Attachment' => 1]);
     }

+ 30 - 13
app/admin/view/member/word.html

@@ -29,7 +29,10 @@
 	</style>
 </head>
 <body>
-<table style="margin: 0 auto;margin-top: 40px;width: 90%" >
+<table style="margin: 0 auto;width: 90%" >
+	<thead>
+		<tr><td style="border: 0;height: 40px"></td></tr>
+	</thead>
 	<tbody>
 	<tr >
 		<th colspan="6" style="text-align: center;"><h2>客户健康档案登记卡</h2></th>
@@ -38,21 +41,35 @@
 		<tr>
 			<th colspan="6"><h3><?= $question['content_title']?></h3></th>
 		</tr>
-		<?php foreach($questions as $question){?>
+		<?php if ($question['content_sort'] > 0) {?>
 			<?php foreach($question['list'] as $key => $questionList){?>
-				<?php if ($key % 3 == 0){?>
+				<?php if ((count($questionList['fields']) > 1)){?>
 					<tr>
-				<?php }?>
-					<?php if ((count($questionList['fields']) > 1)){?>
-						<td><?= $questionList['fields']['question']?></td><td><strong>小红<?= count($question['list'])+1 ?></strong> </td>
-<!--					<td>性别</td><td><strong>女</strong></td>-->
-<!--					<td>年龄</td><td><strong>40岁</strong></td>-->
-					<?php } else { ?>
-						<td><?= ?></td><td><strong>小红<?= count($question['list'])+1 ?></strong> </td>
-					<?php } ?>
-				<?php if ((count($question['list'])+1) % 3 == 2){?>
+						<td rowspan="<?= count($questionList['fields'])?>"><?= $questionList['question'] ?></td>
+						<td><?= $questionList['fields'][0]['field_name']?></td><td colspan="4"><strong><?= $questionList['fields'][0]['field_value']?></strong> </td>
 					</tr>
-				<?php } ?>
+					<?php foreach($questionList['fields'] as $fieldKey => $fieldList){?>
+						<?php if ($fieldKey > 0){?>
+							<tr>
+								<td><?= $fieldList['field_name']?></td><td colspan="4"><strong><?= $fieldList['field_value']?></strong> </td>
+							</tr>
+						<?php } ?>
+					<?php } ?>
+				<?php } else {?>
+					<?php if ($key % 3 == 0){?>
+						<tr>
+					<?php }?>
+					<?php foreach($questionList['fields'] as $fieldList){?>
+						<?php if ($fieldList['form_type'] == 'TEXTAREA'){?>
+							<td><?= $fieldList['field_name']?></td><td colspan="5"><strong><?= $fieldList['field_value']?></strong> </td>
+						<?php } else { ?>
+							<td><?= $fieldList['field_name']?></td><td><strong><?= $fieldList['field_value']?></strong> </td>
+						<?php } ?>
+					<?php } ?>
+					<?php if ($key % 3 == 2 || count($question['list']) == $key + 1){?>
+						</tr>
+					<?php } ?>
+				<?php }?>
 			<?php }?>
 		<?php }?>
 	<?php }?>

+ 5 - 3
app/common/File.php

@@ -17,11 +17,13 @@ class File
 
         $savePath = public_path('storage/files/') . date('Ymd') . '/pdf';
         if (!is_dir($savePath)) {
-            mkdir($savePath,0777,true);
+            mkdir($savePath, 0777, true);
         }
-        $filePath = $savePath .'/'. $fileName;
+        $filePath = $savePath . '/' . $fileName;
         file_put_contents($filePath, $pdfData);
 
-        return response()->file($filePath);
+        $url = getenv('STORAGE_DOMAIN') . '/storage/files/' . date('Ymd') . '/pdf/' . $fileName;
+
+        return $url;
     }
 }