WellnessRecordController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. <?php
  2. namespace app\admin\controller\member;
  3. use app\admin\validate\life\CinemaIlkValidate;
  4. use app\admin\validate\member\WellnessRecordValidate;
  5. use app\common\File;
  6. use app\controller\Curd;
  7. use app\model\CinemaIlk as CinemaIlkModel;
  8. use app\model\Content;
  9. use app\model\SysField;
  10. use app\model\SysUpload;
  11. use app\model\WellnessRecord;
  12. use support\exception\BusinessException;
  13. use support\Request;
  14. use support\Response;
  15. use Tinywan\Jwt\JwtToken;
  16. class WellnessRecordController extends Curd
  17. {
  18. public function __construct()
  19. {
  20. $this->model = new WellnessRecord();
  21. $this->validate = true;
  22. $this->validateClass = new WellnessRecordValidate();
  23. }
  24. public function info(Request $request): Response
  25. {
  26. $primaryKey = $this->model->getKeyName();
  27. $validateArr = [
  28. $primaryKey => $request->get('id')
  29. ];
  30. if ($this->validate && !$this->validateClass->scene('info')->check($validateArr)) {
  31. return json_fail($this->validateClass->getError());
  32. }
  33. $data = $this->model->where($primaryKey, $request->get('id'))->first();
  34. if ($data['wellness_record_category'] == 'Examine') {
  35. $data->wellness_record_status = 'ACTIVED';
  36. $data->save();
  37. }
  38. if (method_exists($this, "afterInfoQuery")) {
  39. $data = call_user_func([$this, "afterInfoQuery"], $data);
  40. }
  41. return json_success('', $data);
  42. }
  43. public function insert(Request $request): Response
  44. {
  45. if ($this->validate && !$this->validateClass->scene('add')->check($request->post())) {
  46. return json_fail($this->validateClass->getError());
  47. }
  48. try {
  49. $data = $this->insertInput($request);
  50. if ($data['wellness_record_category'] == 'Examine' && !empty($data['wellness_record_file_json'])) {
  51. $recordJson = json_decode($data['wellness_record_file_json'], true);
  52. foreach ($recordJson as $file) {
  53. unset($data['wellness_record_file_json']);
  54. $data['wellness_record_file_json'] = json_encode($file);
  55. $this->doInsert($data);
  56. }
  57. } else {
  58. $this->doInsert($data);
  59. }
  60. } catch (BusinessException $customException) {
  61. return json_fail($customException->getMessage());
  62. } catch (\Exception $e) {
  63. dump($e->getMessage(), $e->getFile(), $e->getLine());
  64. return json_fail('数据写入失败');
  65. }
  66. return json_success('success');
  67. }
  68. /**
  69. * @Desc 我的档案
  70. * @Author Gorden
  71. * @Date 2024/4/1 10:54
  72. *
  73. * @param $memberId
  74. * @return mixed
  75. */
  76. public function my($memberId)
  77. {
  78. $query = $this->model->where('wellness_record_category', 'Archives')
  79. ->where('join_wellness_record_member_id', $memberId);
  80. $paginator = $query->paginate(20);
  81. $total = $paginator->total();
  82. $items = $paginator->items();
  83. $itemsNew = [];
  84. foreach ($items as $item) {
  85. $itemNew = [
  86. 'wellness_record_id' => $item->wellness_record_id,
  87. 'join_wellness_record_member_id' => $item->join_wellness_record_member_id,
  88. 'wellness_record_status' => $item->wellness_record_status,
  89. 'wellness_record_name' => $item->wellness_record_name,
  90. 'wellness_record_datetime' => $item->wellness_record_datetime,
  91. 'wellness_record_json' => $item->wellness_record_json,
  92. 'wellness_record_content' => $item->wellness_record_content,
  93. 'wellness_record_remark' => $item->wellness_record_remark,
  94. 'wellness_record_extend_json' => $item->wellness_record_extend_json,
  95. 'wellness_record_addtimes' => date('Y-m-d H:i:s', $item->wellness_record_addtimes),
  96. ];
  97. if (!empty($item->wellness_record_file_json)) {
  98. $item->wellness_record_file_json = json_decode($item->wellness_record_file_json, true);
  99. $upload = SysUpload::whereIn('upload_file_path', $item->wellness_record_file_json)->get();
  100. foreach ($upload as $value) {
  101. $itemNew['wellness_record_file_json'][] = [
  102. 'url' => getenv('STORAGE_DOMAIN') . $value->upload_file_path,
  103. 'name' => $value->upload_name
  104. ];
  105. }
  106. }
  107. $itemsNew[] = $itemNew;
  108. }
  109. $data = [
  110. 'total' => $total,
  111. 'rows' => $itemsNew
  112. ];
  113. return json(['code' => 200, 'msg' => 'success', 'data' => $data]);
  114. }
  115. /**
  116. * @Desc 我的医嘱
  117. * @Author Gorden
  118. * @Date 2024/4/2 8:44
  119. *
  120. * @param $memberId
  121. * @return Response
  122. */
  123. public function advice(Request $request)
  124. {
  125. $memberId = $request->get('member_id');
  126. $query = $this->model->where('wellness_record_category', 'Advice')
  127. ->where('join_wellness_record_member_id', $memberId)
  128. ->orderBy('wellness_record_addtimes', 'desc');
  129. $paginator = $query->paginate(20);
  130. $total = $paginator->total();
  131. $items = $paginator->items();
  132. $itemsNew = [];
  133. foreach ($items as $item) {
  134. $itemNew = [
  135. 'wellness_record_id' => $item->wellness_record_id,
  136. 'join_wellness_record_member_id' => $item->join_wellness_record_member_id,
  137. 'wellness_record_status' => $item->wellness_record_status,
  138. 'wellness_record_name' => $item->wellness_record_name,
  139. 'wellness_record_datetime' => $item->wellness_record_datetime,
  140. 'wellness_record_content' => $item->wellness_record_content,
  141. 'wellness_record_remark' => $item->wellness_record_remark,
  142. 'wellness_record_extend_json' => $item->wellness_record_extend_json,
  143. 'wellness_record_addtimes' => $item->wellness_record_addtimes,
  144. 'wellness_record_file_json' => json_decode($item->wellness_record_file_json),
  145. 'wellness_record_json' => json_decode($item->wellness_record_json, true),
  146. ];
  147. if (!empty($itemNew['wellness_record_json'])) {
  148. foreach ($itemNew['wellness_record_json'] as $key => $item) {
  149. if (empty($item['entry'])) {
  150. $itemNew['wellness_record_json'][$key]['entry'] = 'none';
  151. }
  152. }
  153. }
  154. $itemsNew[] = $itemNew;
  155. }
  156. $data = [
  157. 'total' => $total,
  158. 'rows' => $itemsNew
  159. ];
  160. return json(['code' => 200, 'msg' => 'success', 'data' => $data]);
  161. }
  162. /**
  163. * @Desc 添加医嘱
  164. * @Author Gorden
  165. * @Date 2024/11/29 11:27
  166. *
  167. * @param Request $request
  168. * @return Response
  169. */
  170. public function insertAdvice(Request $request): Response
  171. {
  172. try {
  173. $params = $request->post();
  174. $params['wellness_record_file_json'] = json_encode($params['wellness_record_file_json']);
  175. $params['wellness_record_json'] = json_encode($params['wellness_record_json']);
  176. $data = $this->inputFilter($params);
  177. $data['wellness_record_datetime'] = date('Y-m-d H:i:s', strtotime($data['wellness_record_datetime']));
  178. $this->doInsert($data);
  179. } catch (BusinessException $customException) {
  180. return json_fail($customException->getMessage());
  181. } catch (\Exception $e) {
  182. return json_fail('数据写入失败11');
  183. }
  184. return json_success('success');
  185. }
  186. /**
  187. * @Desc 编辑医嘱
  188. * @Author Gorden
  189. * @Date 2024/11/29 11:27
  190. *
  191. * @param Request $request
  192. * @return Response
  193. */
  194. public function updateAdvice(Request $request): Response
  195. {
  196. try {
  197. [$id, $data] = $this->updateAdviceInput($request);
  198. $this->doUpdate($id, $data);
  199. } catch (BusinessException $e) {
  200. return json_fail($e->getMessage());
  201. } catch (\Exception $e) {
  202. dump($e->getMessage());
  203. return json_fail('数据更新失败');
  204. }
  205. return json_success('success');
  206. }
  207. /**
  208. * @Desc 编辑医嘱预处理
  209. * @Author Gorden
  210. * @Date 2024/11/29 13:07
  211. *
  212. * @param Request $request
  213. * @return array
  214. * @throws BusinessException
  215. */
  216. protected function updateAdviceInput(Request $request): array
  217. {
  218. $primary_key = $this->model->getKeyName();
  219. $id = $request->post($primary_key);
  220. $model = $this->model->find($id);
  221. if (!$model) {
  222. throw new BusinessException('记录不存在', 2);
  223. }
  224. $params = $request->post();
  225. $params['wellness_record_file_json'] = json_encode($params['wellness_record_file_json']);
  226. $params['wellness_record_json'] = json_encode($params['wellness_record_json']);
  227. $data = $this->inputFilter($params);
  228. $data['wellness_record_datetime'] = date('Y-m-d H:i:s', strtotime($data['wellness_record_datetime']));
  229. unset($data[$primary_key]);
  230. return [$id, $data];
  231. }
  232. /**
  233. * @Desc 我的档案
  234. * @Author Gorden
  235. * @Date 2024/4/22 10:46
  236. *
  237. * @param $memberId
  238. * @return Response
  239. */
  240. public function archives(Request $request)
  241. {
  242. $memberId = $request->get('member_id');
  243. $archives = $this->model->where('wellness_record_category', 'Archives')
  244. ->where('join_wellness_record_member_id', $memberId)
  245. ->first();
  246. if ($archives) {
  247. if (!empty($archives->wellness_record_json)) {
  248. // $recordJson = json_decode($archives->wellness_record_json);
  249. //// $fields = SysField::pluck('field_name', 'field_form_key');
  250. // $newJson = [];
  251. // foreach ($recordJson as $key => $item) {
  252. // if (isset($fields[$key])) {
  253. // $newJson[$fields[$key]] = is_array($item) ? implode(',', $item) : $item;
  254. // }
  255. // }
  256. $archives->wellness_record_json = json_decode($archives->wellness_record_json);;
  257. }
  258. if (!empty($archives->wellness_record_file_json)) {
  259. $archives->wellness_record_file_json = json_decode($archives->wellness_record_file_json, true);
  260. $recordFileJson = [];
  261. foreach ($archives->wellness_record_file_json as $value) {
  262. $recordFileJson[] = [
  263. 'url' => isset($value['url']) ? getenv('STORAGE_DOMAIN') . $value['url'] : '',
  264. 'name' => isset($value['name']) ? $value['name'] : ''
  265. ];
  266. }
  267. $archives->wellness_record_file_json = $recordFileJson;
  268. }
  269. }
  270. return json_success('', $archives);
  271. }
  272. public function checkup(Request $request)
  273. {
  274. $memberId = $request->get('member_id');
  275. $query = $this->model->where('wellness_record_category', 'Examine')
  276. ->where('join_wellness_record_member_id', $memberId)
  277. ->orderBy('wellness_record_addtimes', 'desc');
  278. $paginator = $query->paginate(20);
  279. $total = $paginator->total();
  280. $items = $paginator->items();
  281. $itemsNew = [];
  282. foreach ($items as $item) {
  283. $itemNew = [
  284. 'wellness_record_id' => $item->wellness_record_id,
  285. 'join_wellness_record_member_id' => $item->join_wellness_record_member_id,
  286. 'wellness_record_status' => $item->wellness_record_status,
  287. 'wellness_record_name' => $item->wellness_record_name,
  288. 'wellness_record_datetime' => $item->wellness_record_datetime,
  289. 'wellness_record_json' => $item->wellness_record_json,
  290. 'wellness_record_content' => $item->wellness_record_content,
  291. 'wellness_record_remark' => $item->wellness_record_remark,
  292. 'wellness_record_extend_json' => $item->wellness_record_extend_json,
  293. 'wellness_record_addtimes' => $item->wellness_record_addtimes,
  294. ];
  295. if (!empty($item->wellness_record_file_json)) {
  296. $item->wellness_record_file_json = json_decode($item->wellness_record_file_json, true);
  297. if (isset($item->wellness_record_file_json['file_filename']) && isset($item->wellness_record_file_json['file_savepath'])) {
  298. $itemNew['wellness_record_file_json'][] = [
  299. 'url' => getenv('APP_IMAGE_DOMAIN') . $item->wellness_record_file_json['file_savepath'] . $item->wellness_record_file_json['file_savename'],
  300. 'name' => $item->wellness_record_file_json['file_filename']
  301. ];
  302. } else if (isset($item->wellness_record_file_json['url']) && isset($item->wellness_record_file_json['name'])) {
  303. $itemNew['wellness_record_file_json'][] = [
  304. 'url' => getenv('STORAGE_DOMAIN') . $item->wellness_record_file_json['url'],
  305. 'name' => $item->wellness_record_file_json['name']
  306. ];
  307. } else {
  308. foreach ($item->wellness_record_file_json as $value) {
  309. $itemNew['wellness_record_file_json'][] = [
  310. 'url' => isset($value['url']) ? getenv('STORAGE_DOMAIN') . $value['url'] : '',
  311. 'name' => isset($value['name']) ? $value['name'] : ''
  312. ];
  313. }
  314. }
  315. }
  316. $itemsNew[] = $itemNew;
  317. }
  318. $data = [
  319. 'total' => $total,
  320. 'rows' => $itemsNew
  321. ];
  322. return json(['code' => 200, 'msg' => 'success', 'data' => $data]);
  323. }
  324. public function visit($memberId)
  325. {
  326. $query = $this->model->where('wellness_record_category', 'Visiting')
  327. ->where('join_wellness_record_member_id', $memberId)
  328. ->orderBy('wellness_record_addtimes', 'desc');
  329. $paginator = $query->paginate(20);
  330. $total = $paginator->total();
  331. $items = $paginator->items();
  332. $itemsNew = [];
  333. foreach ($items as $item) {
  334. $itemNew = [
  335. 'wellness_record_id' => $item->wellness_record_id,
  336. 'join_wellness_record_member_id' => $item->join_wellness_record_member_id,
  337. 'wellness_record_status' => $item->wellness_record_status,
  338. 'wellness_record_name' => $item->wellness_record_name,
  339. 'wellness_record_datetime' => $item->wellness_record_datetime,
  340. 'wellness_record_json' => $item->wellness_record_json,
  341. 'wellness_record_content' => $item->wellness_record_content,
  342. 'wellness_record_remark' => $item->wellness_record_remark,
  343. 'wellness_record_extend_json' => $item->wellness_record_extend_json,
  344. 'wellness_record_addtimes' => $item->wellness_record_addtimes,
  345. ];
  346. if (!empty($item->wellness_record_file_json)) {
  347. $item->wellness_record_file_json = json_decode($item->wellness_record_file_json, true);
  348. foreach ($item->wellness_record_file_json as $value) {
  349. $itemNew['wellness_record_file_json'][] = [
  350. 'url' => isset($value['url']) ? getenv('STORAGE_DOMAIN') . $value['url'] : '',
  351. 'name' => isset($value['name']) ? $value['name'] : ''
  352. ];
  353. }
  354. }
  355. $itemsNew[] = $itemNew;
  356. }
  357. $data = [
  358. 'total' => $total,
  359. 'rows' => $itemsNew
  360. ];
  361. return json(['code' => 200, 'msg' => 'success', 'data' => $data]);
  362. }
  363. /**
  364. * @Desc 查询列表
  365. * @Author Gorden
  366. * @Date 2024/3/21 9:58
  367. *
  368. * @param Request $request
  369. * @return Response
  370. * @throws \support\exception\BusinessException
  371. */
  372. public function select(Request $request): Response
  373. {
  374. [$where, $format, $limit, $field, $order] = $this->selectInput($request);
  375. $field = $field ?? 'wellness_record_addtimes';
  376. $order = $request->get('order', 'desc');
  377. $where['wellness_record_category'] = 'Archives';
  378. $query = $this->doSelect($where, $field, $order);
  379. return $this->doFormat($query, $format, $limit);
  380. }
  381. protected function doSelect(array $where, string $field = null, string $order = 'desc')
  382. {
  383. $model = $this->model->with([
  384. 'member' => function ($query) {
  385. $query->select('member_id', 'member_mobile');
  386. },
  387. 'cert' => function ($query) {
  388. $query->select('join_cert_member_id', 'member_cert_name');
  389. }
  390. ]);
  391. foreach ($where as $column => $value) {
  392. if (is_array($value)) {
  393. if ($value[0] === 'like' || $value[0] === 'not like') {
  394. $model = $model->where($column, $value[0], "%$value[1]%");
  395. } elseif (in_array($value[0], ['>', '=', '<', '<>'])) {
  396. $model = $model->where($column, $value[0], $value[1]);
  397. } elseif ($value[0] == 'in' && !empty($value[1])) {
  398. $valArr = $value[1];
  399. if (is_string($value[1])) {
  400. $valArr = explode(",", trim($value[1]));
  401. }
  402. $model = $model->whereIn($column, $valArr);
  403. } elseif ($value[0] == 'not in' && !empty($value[1])) {
  404. $valArr = $value[1];
  405. if (is_string($value[1])) {
  406. $valArr = explode(",", trim($value[1]));
  407. }
  408. $model = $model->whereNotIn($column, $valArr);
  409. } elseif ($value[0] == 'null') {
  410. $model = $model->whereNull($column);
  411. } elseif ($value[0] == 'not null') {
  412. $model = $model->whereNotNull($column);
  413. } elseif ($value[0] !== '' || $value[1] !== '') {
  414. $model = $model->whereBetween($column, $value);
  415. }
  416. } else {
  417. $model = $model->where($column, $value);
  418. }
  419. }
  420. if ($field) {
  421. $model = $model->orderBy($field, $order);
  422. }
  423. return $model;
  424. }
  425. protected function afterQuery($items)
  426. {
  427. foreach ($items as &$item) {
  428. if (!empty($item->wellness_record_file_json)) {
  429. $item->wellness_record_file_json = json_decode($item->wellness_record_file_json, true);
  430. $wellnessRecordFileJson = [];
  431. if (isset($item->wellness_record_file_json['file_filename']) && isset($item->wellness_record_file_json['file_savepath'])) {
  432. $wellnessRecordFileJson[] = [
  433. 'url' => getenv('STORAGE_DOMAIN') . $item->wellness_record_file_json['file_savepath'],
  434. 'name' => $item->wellness_record_file_json['file_filename']
  435. ];
  436. } else if (isset($item->wellness_record_file_json['url']) && isset($item->wellness_record_file_json['name'])) {
  437. $wellnessRecordFileJson[] = [
  438. 'url' => getenv('STORAGE_DOMAIN') . $item->wellness_record_file_json['url'],
  439. 'name' => $item->wellness_record_file_json['name']
  440. ];
  441. } else {
  442. foreach ($item->wellness_record_file_json as $value) {
  443. if (!empty($value['url']) && !empty($value['name'])) {
  444. $wellnessRecordFileJson[] = [
  445. 'url' => getenv('STORAGE_DOMAIN') . $value['url'],
  446. 'name' => $value['name']
  447. ];
  448. }
  449. }
  450. }
  451. $item->wellness_record_file_json = $wellnessRecordFileJson;
  452. }
  453. }
  454. return $items;
  455. }
  456. protected function insertInput(Request $request): array
  457. {
  458. $data = $this->inputFilter($request->post());
  459. if (empty($data['wellness_record_datetime'])) {
  460. $data['wellness_record_datetime'] = date('Y-m-d H:i:s');
  461. } else {
  462. $data['wellness_record_datetime'] = date('Y-m-d H:i:s', strtotime($data['wellness_record_datetime']));
  463. }
  464. if (!empty($data['wellness_record_file_json'])) {
  465. $data['wellness_record_file_json'] = json_decode($data['wellness_record_file_json'], true);
  466. $wellnessRecordFileJson = [];
  467. foreach ($data['wellness_record_file_json'] as $value) {
  468. $wellnessRecordFileJson[] = [
  469. 'url' => str_replace(getenv('STORAGE_DOMAIN'), '', $value['url']),
  470. 'name' => $value['name']
  471. ];
  472. }
  473. $data['wellness_record_file_json'] = json_encode($wellnessRecordFileJson);
  474. } else {
  475. $data['wellness_record_file_json'] = '[]';
  476. }
  477. $data['wellness_record_json'] = '[]';
  478. if (!empty($request->post('records'))) {
  479. $data['wellness_record_json'] = json_encode($request->post('records'));
  480. }
  481. // 记录医生
  482. $extend = JwtToken::getExtend();
  483. $data['wellness_record_extend_json'] = json_encode([
  484. 'doctor' => [
  485. 'name' => $extend['name'],
  486. 'header' => '',
  487. 'userid' => $extend['id']
  488. ]]);
  489. return $data;
  490. }
  491. protected function updateInput(Request $request): array
  492. {
  493. $primary_key = $this->model->getKeyName();
  494. $id = $request->post($primary_key);
  495. $model = $this->model->find($id);
  496. if (!$model) {
  497. throw new BusinessException('记录不存在', 2);
  498. }
  499. $data = $this->inputFilter($request->post());
  500. if (empty($data['wellness_record_datetime'])) {
  501. $data['wellness_record_datetime'] = date('Y-m-d H:i:s');
  502. } else {
  503. $data['wellness_record_datetime'] = date('Y-m-d H:i:s', strtotime($data['wellness_record_datetime']));
  504. }
  505. if (!empty($data['wellness_record_file_json'])) {
  506. $data['wellness_record_file_json'] = json_decode($data['wellness_record_file_json'], true);
  507. $wellnessRecordFileJson = [];
  508. foreach ($data['wellness_record_file_json'] as $value) {
  509. $wellnessRecordFileJson[] = [
  510. 'url' => str_replace(getenv('STORAGE_DOMAIN'), '', $value['url']),
  511. 'name' => $value['name']
  512. ];
  513. }
  514. $data['wellness_record_file_json'] = json_encode($wellnessRecordFileJson);
  515. } else {
  516. $data['wellness_record_file_json'] = '[]';
  517. }
  518. $data['wellness_record_json'] = '[]';
  519. if (!empty($request->post('records'))) {
  520. $data['wellness_record_json'] = json_encode($request->post('records'));
  521. }
  522. unset($data[$primary_key]);
  523. return [$id, $data];
  524. }
  525. public function exportArchivePdf(Request $request)
  526. {
  527. $memberId = $request->get('member_id');
  528. $archive = WellnessRecord::where('join_wellness_record_member_id', $memberId)
  529. ->select('join_wellness_record_member_id', 'wellness_record_status', 'wellness_record_category', 'wellness_record_json', 'wellness_record_datetime')
  530. ->where('wellness_record_category', 'Archives')
  531. ->where('wellness_record_status', 'ACTIVED')
  532. ->first();
  533. if (empty($archive)) {
  534. return json_fail('档案不存在');
  535. }
  536. $archive = $archive->toArray();
  537. $wellnessRecordJson = json_decode($archive['wellness_record_json'], true);
  538. foreach ($wellnessRecordJson as &$recordItem) {
  539. if (is_array($recordItem)) {
  540. $recordItem = implode(',', $recordItem);
  541. }
  542. }
  543. $questions = Content::where('content_category', 'WELLNESSQUESTION')
  544. ->select('content_id', 'content_category', 'content_sort', 'content_config_json', 'content_title')
  545. ->orderBy('content_sort')
  546. ->get()
  547. ->toArray();
  548. foreach ($questions as &$question) {
  549. $contentConfig = json_decode($question['content_config_json'], true);
  550. foreach ($contentConfig as $item) {
  551. $fields = SysField::whereIn('field_id', $item['field'])
  552. ->select('field_id', 'field_name', 'field_form_key', 'field_form_type', 'field_refer_json')
  553. ->orderByDesc('field_sort')
  554. ->get()
  555. ->toArray();
  556. $fieldData = [];
  557. foreach ($fields as $field) {
  558. $fieldData[] = [
  559. 'form_type' => $field['field_form_type'],
  560. 'field_name' => $field['field_name'],
  561. 'field_value' => $wellnessRecordJson[$field['field_form_key']] ?? ''
  562. ];
  563. }
  564. $question['list'][] = [
  565. 'question' => $item['question'],
  566. 'fields' => $fieldData
  567. ];
  568. }
  569. unset($question['content_config_json']);
  570. }
  571. $content = view('member/word', ['questions' => $questions])->rawBody();
  572. $url = File::exportPdf($content, $memberId.'_'.date('YmdHis') . '.pdf');
  573. return json_success("success",['url'=>$url]);
  574. // $pdf->stream('my.pdf', ['Attachment' => 1]);
  575. }
  576. }