123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522 |
- <?php
- namespace app\admin\controller\member;
- use app\admin\validate\life\CinemaIlkValidate;
- use app\admin\validate\member\WellnessRecordValidate;
- use app\controller\Curd;
- use app\model\CinemaIlk as CinemaIlkModel;
- use app\model\SysField;
- use app\model\SysUpload;
- use app\model\WellnessRecord;
- use support\exception\BusinessException;
- use support\Request;
- use support\Response;
- use Tinywan\Jwt\JwtToken;
- class WellnessRecordController extends Curd
- {
- public function __construct()
- {
- $this->model = new WellnessRecord();
- $this->validate = true;
- $this->validateClass = new WellnessRecordValidate();
- }
- public function info(Request $request): Response
- {
- $primaryKey = $this->model->getKeyName();
- $validateArr = [
- $primaryKey => $request->get('id')
- ];
- if ($this->validate && !$this->validateClass->scene('info')->check($validateArr)) {
- return json_fail($this->validateClass->getError());
- }
- $data = $this->model->where($primaryKey, $request->get('id'))->first();
- if ($data['wellness_record_category'] == 'Examine'){
- $data->wellness_record_status = 'ACTIVED';
- $data->save();
- }
- if (method_exists($this, "afterInfoQuery")) {
- $data = call_user_func([$this, "afterInfoQuery"], $data);
- }
- return json_success('', $data);
- }
- public function insert(Request $request): Response
- {
- if ($this->validate && !$this->validateClass->scene('add')->check($request->post())) {
- return json_fail($this->validateClass->getError());
- }
- try {
- $data = $this->insertInput($request);
- if ($data['wellness_record_category'] == 'Examine' && !empty($data['wellness_record_file_json'])) {
- $recordJson = json_decode($data['wellness_record_file_json'], true);
- foreach ($recordJson as $file) {
- unset($data['wellness_record_file_json']);
- $data['wellness_record_file_json'] = json_encode($file);
- $this->doInsert($data);
- }
- }else{
- $this->doInsert($data);
- }
- } catch (BusinessException $customException) {
- return json_fail($customException->getMessage());
- } catch (\Exception $e) {
- dump($e->getMessage());
- return json_fail('数据写入失败11');
- }
- return json_success('success');
- }
- /**
- * @Desc 我的档案
- * @Author Gorden
- * @Date 2024/4/1 10:54
- *
- * @param $memberId
- * @return mixed
- */
- public function my($memberId)
- {
- $query = $this->model->where('wellness_record_category', 'Archives')
- ->where('join_wellness_record_member_id', $memberId);
- $paginator = $query->paginate(20);
- $total = $paginator->total();
- $items = $paginator->items();
- $itemsNew = [];
- foreach ($items as $item) {
- $itemNew = [
- 'wellness_record_id' => $item->wellness_record_id,
- 'join_wellness_record_member_id' => $item->join_wellness_record_member_id,
- 'wellness_record_status' => $item->wellness_record_status,
- 'wellness_record_name' => $item->wellness_record_name,
- 'wellness_record_datetime' => $item->wellness_record_datetime,
- 'wellness_record_json' => $item->wellness_record_json,
- 'wellness_record_content' => $item->wellness_record_content,
- 'wellness_record_remark' => $item->wellness_record_remark,
- 'wellness_record_extend_json' => $item->wellness_record_extend_json,
- 'wellness_record_addtimes' => date('Y-m-d H:i:s', $item->wellness_record_addtimes),
- ];
- if (!empty($item->wellness_record_file_json)) {
- $item->wellness_record_file_json = json_decode($item->wellness_record_file_json, true);
- $upload = SysUpload::whereIn('upload_file_path', $item->wellness_record_file_json)->get();
- foreach ($upload as $value) {
- $itemNew['wellness_record_file_json'][] = [
- 'url' => getenv('STORAGE_DOMAIN') . $value->upload_file_path,
- 'name' => $value->upload_name
- ];
- }
- }
- $itemsNew[] = $itemNew;
- }
- $data = [
- 'total' => $total,
- 'rows' => $itemsNew
- ];
- return json(['code' => 200, 'msg' => 'success', 'data' => $data]);
- }
- /**
- * @Desc 我的医嘱
- * @Author Gorden
- * @Date 2024/4/2 8:44
- *
- * @param $memberId
- * @return Response
- */
- public function advice($memberId)
- {
- $query = $this->model->where('wellness_record_category', 'Advice')
- ->where('join_wellness_record_member_id', $memberId)
- ->orderBy('wellness_record_addtimes', 'desc');
- $paginator = $query->paginate(20);
- $total = $paginator->total();
- $items = $paginator->items();
- $itemsNew = [];
- foreach ($items as $item) {
- $itemNew = [
- 'wellness_record_id' => $item->wellness_record_id,
- 'join_wellness_record_member_id' => $item->join_wellness_record_member_id,
- 'wellness_record_status' => $item->wellness_record_status,
- 'wellness_record_name' => $item->wellness_record_name,
- 'wellness_record_datetime' => $item->wellness_record_datetime,
- 'wellness_record_json' => $item->wellness_record_json,
- 'wellness_record_content' => $item->wellness_record_content,
- 'wellness_record_remark' => $item->wellness_record_remark,
- 'wellness_record_extend_json' => $item->wellness_record_extend_json,
- 'wellness_record_addtimes' => $item->wellness_record_addtimes,
- ];
- if (!empty($item->wellness_record_file_json)) {
- $item->wellness_record_file_json = json_decode($item->wellness_record_file_json, true);
- foreach ($item->wellness_record_file_json as $value) {
- $itemNew['wellness_record_file_json'][] = [
- 'url' => isset($value['url']) ? getenv('STORAGE_DOMAIN') . $value['url'] : '',
- 'name' => isset($value['name']) ? $value['name'] : ''
- ];
- }
- }
- if (!empty($item->wellness_record_json)) {
- $itemNew['wellness_record_json'] = json_decode($item->wellness_record_json);
- }
- if (!empty($item->wellness_record_extend_json)) {
- $itemNew['wellness_record_extend_json'] = json_decode($item->wellness_record_extend_json);
- }
- $itemsNew[] = $itemNew;
- }
- $data = [
- 'total' => $total,
- 'rows' => $itemsNew
- ];
- return json(['code' => 200, 'msg' => 'success', 'data' => $data]);
- }
- /**
- * @Desc 我的档案
- * @Author Gorden
- * @Date 2024/4/22 10:46
- *
- * @param $memberId
- * @return Response
- */
- public function archives($memberId)
- {
- $archives = $this->model->where('wellness_record_category', 'Archives')
- ->where('join_wellness_record_member_id', $memberId)
- ->first();
- if ($archives) {
- if (!empty($archives->wellness_record_json)) {
- $recordJson = json_decode($archives->wellness_record_json);
- $fields = SysField::pluck('field_name', 'field_form_key');
- $newJson = [];
- foreach ($recordJson as $key => $item) {
- if (isset($fields[$key])) {
- $newJson[$fields[$key]] = is_array($item) ? implode(',', $item) : $item;
- }
- }
- $archives->wellness_record_json = $newJson;
- }
- if (!empty($archives->wellness_record_file_json)) {
- $archives->wellness_record_file_json = json_decode($archives->wellness_record_file_json, true);
- $recordFileJson = [];
- foreach ($archives->wellness_record_file_json as $value) {
- $recordFileJson[] = [
- 'url' => isset($value['url']) ? getenv('STORAGE_DOMAIN') . $value['url'] : '',
- 'name' => isset($value['name']) ? $value['name'] : ''
- ];
- }
- $archives->wellness_record_file_json = $recordFileJson;
- }
- }
- // ->orderBy('wellness_record_addtimes', 'desc');
- // $paginator = $query->paginate(20);
- // $total = $paginator->total();
- // $items = $paginator->items();
- // $itemsNew = [];
- // foreach ($items as $item) {
- // $itemNew = [
- // 'wellness_record_id' => $item->wellness_record_id,
- // 'join_wellness_record_member_id' => $item->join_wellness_record_member_id,
- // 'wellness_record_status' => $item->wellness_record_status,
- // 'wellness_record_name' => $item->wellness_record_name,
- // 'wellness_record_datetime' => $item->wellness_record_datetime,
- // 'wellness_record_json' => $item->wellness_record_json,
- // 'wellness_record_content' => $item->wellness_record_content,
- // 'wellness_record_remark' => $item->wellness_record_remark,
- // 'wellness_record_extend_json' => $item->wellness_record_extend_json,
- // 'wellness_record_addtimes' => $item->wellness_record_addtimes,
- // ];
- // if (!empty($item->wellness_record_file_json)) {
- // $item->wellness_record_file_json = json_decode($item->wellness_record_file_json, true);
- // foreach ($item->wellness_record_file_json as $value) {
- // $itemNew['wellness_record_file_json'][] = [
- // 'url' => isset($value['url']) ? getenv('STORAGE_DOMAIN') . $value['url'] : '',
- // 'name' => isset($value['name']) ? $value['name'] : ''
- // ];
- // }
- // }
- //
- // $itemsNew[] = $itemNew;
- // }
- //
- // $data = [
- // 'total' => $total,
- // 'rows' => $itemsNew
- // ];
- // return json(['code' => 200, 'msg' => 'success', 'data' => $data]);
- return json_success('', $archives);
- }
- public function checkup($memberId)
- {
- $query = $this->model->where('wellness_record_category', 'Examine')
- ->where('join_wellness_record_member_id', $memberId)
- ->orderBy('wellness_record_addtimes', 'desc');
- $paginator = $query->paginate(20);
- $total = $paginator->total();
- $items = $paginator->items();
- $itemsNew = [];
- foreach ($items as $item) {
- $itemNew = [
- 'wellness_record_id' => $item->wellness_record_id,
- 'join_wellness_record_member_id' => $item->join_wellness_record_member_id,
- 'wellness_record_status' => $item->wellness_record_status,
- 'wellness_record_name' => $item->wellness_record_name,
- 'wellness_record_datetime' => $item->wellness_record_datetime,
- 'wellness_record_json' => $item->wellness_record_json,
- 'wellness_record_content' => $item->wellness_record_content,
- 'wellness_record_remark' => $item->wellness_record_remark,
- 'wellness_record_extend_json' => $item->wellness_record_extend_json,
- 'wellness_record_addtimes' => $item->wellness_record_addtimes,
- ];
- if (!empty($item->wellness_record_file_json)) {
- $item->wellness_record_file_json = json_decode($item->wellness_record_file_json, true);
- if (isset($item->wellness_record_file_json['file_filename']) && isset($item->wellness_record_file_json['file_savepath'])) {
- $itemNew['wellness_record_file_json'][] = [
- 'url' => getenv('APP_IMAGE_DOMAIN') .$item->wellness_record_file_json['file_savepath'].$item->wellness_record_file_json['file_savename'],
- 'name' => $item->wellness_record_file_json['file_filename']
- ];
- } else if (isset($item->wellness_record_file_json['url']) && isset($item->wellness_record_file_json['name'])) {
- $itemNew['wellness_record_file_json'][] = [
- 'url' => getenv('STORAGE_DOMAIN') . $item->wellness_record_file_json['url'],
- 'name' => $item->wellness_record_file_json['name']
- ];
- } else {
- foreach ($item->wellness_record_file_json as $value) {
- $itemNew['wellness_record_file_json'][] = [
- 'url' => isset($value['url']) ? getenv('STORAGE_DOMAIN') . $value['url'] : '',
- 'name' => isset($value['name']) ? $value['name'] : ''
- ];
- }
- }
- }
- $itemsNew[] = $itemNew;
- }
- $data = [
- 'total' => $total,
- 'rows' => $itemsNew
- ];
- return json(['code' => 200, 'msg' => 'success', 'data' => $data]);
- }
- public function visit($memberId)
- {
- $query = $this->model->where('wellness_record_category', 'Visiting')
- ->where('join_wellness_record_member_id', $memberId)
- ->orderBy('wellness_record_addtimes', 'desc');
- $paginator = $query->paginate(20);
- $total = $paginator->total();
- $items = $paginator->items();
- $itemsNew = [];
- foreach ($items as $item) {
- $itemNew = [
- 'wellness_record_id' => $item->wellness_record_id,
- 'join_wellness_record_member_id' => $item->join_wellness_record_member_id,
- 'wellness_record_status' => $item->wellness_record_status,
- 'wellness_record_name' => $item->wellness_record_name,
- 'wellness_record_datetime' => $item->wellness_record_datetime,
- 'wellness_record_json' => $item->wellness_record_json,
- 'wellness_record_content' => $item->wellness_record_content,
- 'wellness_record_remark' => $item->wellness_record_remark,
- 'wellness_record_extend_json' => $item->wellness_record_extend_json,
- 'wellness_record_addtimes' => $item->wellness_record_addtimes,
- ];
- if (!empty($item->wellness_record_file_json)) {
- $item->wellness_record_file_json = json_decode($item->wellness_record_file_json, true);
- foreach ($item->wellness_record_file_json as $value) {
- $itemNew['wellness_record_file_json'][] = [
- 'url' => isset($value['url']) ? getenv('STORAGE_DOMAIN') . $value['url'] : '',
- 'name' => isset($value['name']) ? $value['name'] : ''
- ];
- }
- }
- $itemsNew[] = $itemNew;
- }
- $data = [
- 'total' => $total,
- 'rows' => $itemsNew
- ];
- return json(['code' => 200, 'msg' => 'success', 'data' => $data]);
- }
- /**
- * @Desc 查询列表
- * @Author Gorden
- * @Date 2024/3/21 9:58
- *
- * @param Request $request
- * @return Response
- * @throws \support\exception\BusinessException
- */
- public function select(Request $request): Response
- {
- [$where, $format, $limit, $field, $order] = $this->selectInput($request);
- $field = $field ?? 'wellness_record_addtimes';
- $order = $request->get('order', 'desc');
- $where['wellness_record_category'] = 'Archives';
- $query = $this->doSelect($where, $field, $order);
- return $this->doFormat($query, $format, $limit);
- }
- protected function doSelect(array $where, string $field = null, string $order = 'desc')
- {
- $model = $this->model->with([
- 'member' => function ($query) {
- $query->select('member_id', 'member_mobile');
- },
- 'cert' => function ($query) {
- $query->select('join_cert_member_id', 'member_cert_name');
- }
- ]);
- foreach ($where as $column => $value) {
- if (is_array($value)) {
- if ($value[0] === 'like' || $value[0] === 'not like') {
- $model = $model->where($column, $value[0], "%$value[1]%");
- } elseif (in_array($value[0], ['>', '=', '<', '<>'])) {
- $model = $model->where($column, $value[0], $value[1]);
- } elseif ($value[0] == 'in' && !empty($value[1])) {
- $valArr = $value[1];
- if (is_string($value[1])) {
- $valArr = explode(",", trim($value[1]));
- }
- $model = $model->whereIn($column, $valArr);
- } elseif ($value[0] == 'not in' && !empty($value[1])) {
- $valArr = $value[1];
- if (is_string($value[1])) {
- $valArr = explode(",", trim($value[1]));
- }
- $model = $model->whereNotIn($column, $valArr);
- } elseif ($value[0] == 'null') {
- $model = $model->whereNull($column);
- } elseif ($value[0] == 'not null') {
- $model = $model->whereNotNull($column);
- } elseif ($value[0] !== '' || $value[1] !== '') {
- $model = $model->whereBetween($column, $value);
- }
- } else {
- $model = $model->where($column, $value);
- }
- }
- if ($field) {
- $model = $model->orderBy($field, $order);
- }
- return $model;
- }
- protected function afterQuery($items)
- {
- foreach ($items as &$item) {
- if (!empty($item->wellness_record_file_json)) {
- $item->wellness_record_file_json = json_decode($item->wellness_record_file_json, true);
- $wellnessRecordFileJson = [];
- if (isset($item->wellness_record_file_json['file_filename']) && isset($item->wellness_record_file_json['file_savepath'])) {
- $wellnessRecordFileJson[] = [
- 'url' => getenv('STORAGE_DOMAIN') . $item->wellness_record_file_json['file_savepath'],
- 'name' => $item->wellness_record_file_json['file_filename']
- ];
- } else if (isset($item->wellness_record_file_json['url']) && isset($item->wellness_record_file_json['name'])) {
- $wellnessRecordFileJson[] = [
- 'url' => getenv('STORAGE_DOMAIN') . $item->wellness_record_file_json['url'],
- 'name' => $item->wellness_record_file_json['name']
- ];
- } else {
- foreach ($item->wellness_record_file_json as $value) {
- if (!empty($value['url']) && !empty($value['name'])) {
- $wellnessRecordFileJson[] = [
- 'url' => getenv('STORAGE_DOMAIN') . $value['url'],
- 'name' => $value['name']
- ];
- }
- }
- }
- $item->wellness_record_file_json = $wellnessRecordFileJson;
- }
- }
- return $items;
- }
- protected function insertInput(Request $request): array
- {
- $data = $this->inputFilter($request->post());
- $data['wellness_record_datetime'] = date('Y-m-d H:i:s', strtotime($data['wellness_record_datetime']));
- if (!empty($data['wellness_record_file_json'])) {
- $data['wellness_record_file_json'] = json_decode($data['wellness_record_file_json'], true);
- $wellnessRecordFileJson = [];
- foreach ($data['wellness_record_file_json'] as $value) {
- $wellnessRecordFileJson[] = [
- 'url' => str_replace(getenv('STORAGE_DOMAIN'), '', $value['url']),
- 'name' => $value['name']
- ];
- }
- $data['wellness_record_file_json'] = json_encode($wellnessRecordFileJson);
- } else {
- $data['wellness_record_file_json'] = '[]';
- }
- $data['wellness_record_json'] = '[]';
- if (!empty($request->post('records'))) {
- $data['wellness_record_json'] = json_encode($request->post('records'));
- }
- // 记录医生
- $extend = JwtToken::getExtend();
- $data['wellness_record_extend_json'] = json_encode([
- 'doctor' => [
- 'name' => $extend['name'],
- 'header' => '',
- 'userid' => $extend['id']
- ]]);
- return $data;
- }
- protected function updateInput(Request $request): array
- {
- $primary_key = $this->model->getKeyName();
- $id = $request->post($primary_key);
- $data = $this->inputFilter($request->post());
- $data['wellness_record_datetime'] = date('Y-m-d H:i:s', strtotime($data['wellness_record_datetime']));
- if (!empty($data['wellness_record_file_json'])) {
- $data['wellness_record_file_json'] = json_decode($data['wellness_record_file_json'], true);
- $wellnessRecordFileJson = [];
- foreach ($data['wellness_record_file_json'] as $value) {
- $wellnessRecordFileJson[] = [
- 'url' => str_replace(getenv('STORAGE_DOMAIN'), '', $value['url']),
- 'name' => $value['name']
- ];
- }
- $data['wellness_record_file_json'] = json_encode($wellnessRecordFileJson);
- } else {
- $data['wellness_record_file_json'] = '[]';
- }
- $data['wellness_record_json'] = '[]';
- if (!empty($request->post('records'))) {
- $data['wellness_record_json'] = json_encode($request->post('records'));
- }
- $model = $this->model->find($id);
- if (!$model) {
- throw new BusinessException('记录不存在', 2);
- }
- unset($data[$primary_key]);
- return [$id, $data];
- }
- }
|