123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use Mpdf\Tag\P;
- use think\Exception;
- use think\facade\Db;
- use function GuzzleHttp\Psr7\str;
- /**
- * 患者信息管理
- */
- class Patient extends Backend
- {
- /**
- * Patient模型对象
- * @var object
- * @phpstan-var \app\admin\model\Patient
- */
- protected object $model;
- protected string|array $defaultSortField = 'ID,desc';
- protected string|array $quickSearchField = ['ID'];
- protected array $noNeedLogin = ['asyncAttachment'];
- protected array $noNeedPermission = ['asyncAttachment'];
- public function initialize(): void
- {
- parent::initialize();
- $this->model = new \app\admin\model\Patient();
- }
- /**
- * 若需重写查看、编辑、删除等方法,请复制 @see \app\admin\library\traits\Backend 中对应的方法至此进行重写
- */
- /**
- * 查看
- * @throws Throwable
- */
- public function index(): void
- {
- if ($this->request->param('select')) {
- $this->select();
- }
- list($where, $alias, $limit, $order) = $this->queryBuilder();
- $res = $this->model
- ->field($this->indexField)
- ->withJoin($this->withJoinTable, $this->withJoinType)
- ->alias($alias)
- ->where($where)
- ->order($order)
- ->paginate($limit);
- foreach ($res->items() as $k=>&$v)
- {
- $v->ID_CARDNUM = empty($v->ID_CARDNUM) ? '' : substr($v->ID_CARDNUM,0, 10) . '****' . substr($v->ID_CARDNUM,14);
- $v->NAME = mb_substr( $v->NAME, 0, 1) . str_repeat('*', ceil((strlen($v->NAME) - 1)/4));
- $len = strlen($v->INSUR_CARD_NO);
- $v->INSUR_CARD_NO = mb_substr( $v->INSUR_CARD_NO, 0, ceil($len/2)).str_repeat('*', ceil($len/2));
- }
- $this->success('', [
- 'list' => $res->items(),
- 'total' => $res->total(),
- 'remark' => get_route_remark(),
- ]);
- }
- public function asyncAttachment():void
- {
- try {
- $params = $this->request->post();
- $type = $params['file']; //文件流类型 文件后缀
- $url = '/attachment/'.time().'.'.$type;
- $filePath = $_SERVER['DOCUMENT_ROOT'].$url;
- // 确保目录存在
- $dirPath = dirname($filePath);
- if (!is_dir($dirPath)) {
- mkdir($dirPath, 0755, true); // 第三个参数 true 表示可以创建多级目录
- }
- // 写入文件
- $data = $params['data'];
- file_put_contents($filePath, $data);
- $arr = [
- 'report_code'=>$params['report_code'],
- 'type'=>$params['type'],
- 'url'=>$url
- ];
- Db::name('report_attachment')->insert($arr);
- $this->success('success');
- }catch (\Exception $e)
- {
- $this->error($e->getMessage());
- }
- }
- public function getAttachment(): void
- {
- $params = $this->request->post();
- $code = $params['report_code'];
- $url = Db::name('report_attachment')->where('report_code',$code)->value('url');
- if(!empty($url))
- {
- $this->success($url);
- }else{
- $this->error('无可用的附件');
- }
- }
- }
|