Browse Source

互认页面适配

lgy 3 weeks ago
parent
commit
1b2345be8a

+ 12 - 6
jcjyhr/app/admin/controller/auth/Admin.php

@@ -176,7 +176,12 @@ class Admin extends Backend
      */
     public function edit($id = null): void
     {
-        $row = $this->model->find($id);
+        $arr = $this->model->find($id);
+        $row = [];
+        foreach ($arr->toArray() as $k=>$v)
+        {
+            $row[strtolower($k)] = $v;
+        }
         if (!$row) {
             $this->error(__('Record not found'));
         }
@@ -218,7 +223,7 @@ class Admin extends Backend
             if ($data['group_arr']) {
                 $checkGroups = [];
                 foreach ($data['group_arr'] as $datum) {
-                    if (!in_array($datum, $row->group_arr)) {
+                    if (!in_array($datum, $arr->group_arr)) {
                         $checkGroups[] = $datum;
                     }
                     $groupAccess[] = [
@@ -249,7 +254,8 @@ class Admin extends Backend
                 {
                     $data['create_user'] = $this->model->where('id',$data['create_user_id'])->value('nickname');
                 }
-                $result = $row->save($data);
+                unset($data['id']);
+                $result = $arr->save($data);
                 if ($groupAccess) Db::name('admin_group_access')->insertAll($groupAccess);
                 $this->model->commit();
             } catch (Throwable $e) {
@@ -295,12 +301,12 @@ class Admin extends Backend
         $this->model->startTrans();
         try {
             foreach ($data as $v) {
-                if ($v->id != $this->auth->id) {
-                    $count += $v->delete();
+//                if ($v->ID != $this->auth->ID) {
+                    $count += $v->where('ID',$v->ID)->delete();
                     Db::name('admin_group_access')
                         ->where('uid', $v['id'])
                         ->delete();
-                }
+//                }
             }
             $this->model->commit();
         } catch (Throwable $e) {

+ 33 - 6
jcjyhr/app/admin/controller/auth/Group.php

@@ -80,14 +80,40 @@ class Group extends Backend
         if ($this->request->param('select')) {
             $this->select();
         }
-
+        $list = $this->getGroups();
+//        $list = json_decode(json_encode($list), true);
+//        $arr = [];
+//        foreach ($list as $k=>$v) {
+//            foreach ($v as $k1=>$v1) {
+//                if(!empty($v1['children'])) {
+//                    $v1 = $this->handleGroup($v1['children']);
+//                }
+//                $arr[$k][strtolower($k1)] = $v1;
+//            }
+//        }
         $this->success('', [
-            'list'   => $this->getGroups(),
+            'list'   => $list,
             'group'  => $this->adminGroups,
             'remark' => get_route_remark(),
         ]);
     }
 
+    public function handleGroup($data)
+    {
+        $arr = [];
+        foreach ($data as $k=>$v) {
+            if(!empty($v['children'] ?? ''))
+            {
+                $arr[$k][strtolower($k)] = $v;
+                $arr[$k]['children'] = $this->handleGroup($v['children']);
+            }else{
+                $arr[$k][strtolower($k)] = $v;
+            }
+        }
+        return $arr;
+
+    }
+
     /**
      * 添加
      * @throws Throwable
@@ -328,15 +354,16 @@ class Group extends Backend
             if (!$absoluteAuth) $authGroups = array_merge($this->adminGroups, $authGroups);
             $where[] = ['id', 'in', $authGroups];
         }
-        $data = $this->model->where($where)->select()->toArray();
+        $field = ['ID','PID','ID AS id', 'PID AS pid','NAME AS name','RULES AS rules','STATUS AS status','UPDATE_TIME AS update_time','CREATE_TIME AS create_time'];
+        $data = $this->model->where($where)->field($field)->select()->toArray();
 
         // 获取第一个权限的名称供列表显示-s
         foreach ($data as &$datum) {
-            if ($datum['RULES']) {
-                if ($datum['RULES'] == '*') {
+            if ($datum['rules']) {
+                if ($datum['rules'] == '*') {
                     $datum['rules'] = __('Super administrator');
                 } else {
-                    $rules = explode(',', $datum['RULES']);
+                    $rules = explode(',', $datum['rules']);
                     if ($rules) {
                         $rulesFirstTitle = AdminRule::where('id', $rules[0])->value('TITLE');
                         $datum['rules']  = count($rules) == 1 ? $rulesFirstTitle : $rulesFirstTitle . '等 ' . count($rules) . ' 项';

+ 94 - 0
jcjyhr/app/admin/controller/dict/Commondata.php

@@ -32,4 +32,98 @@ class Commondata extends Backend
     /**
      * 若需重写查看、编辑、删除等方法,请复制 @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);
+
+        $list = $res->items();
+        $list = (json_decode(json_encode($list), true));
+        $arr = [];
+        foreach ($list as $k=>$v) {
+            foreach ($v as $kk => $vv) {
+                $arr[$k][strtolower($kk)] = $vv;
+            }
+        }
+        $this->success('', [
+            'list'   => $arr,
+            'total'  => $res->total(),
+            'remark' => get_route_remark(),
+        ]);
+    }
+
+    /**
+     * 编辑
+     * @throws Throwable
+     */
+    public function edit(): void
+    {
+        $pk  = $this->model->getPk();
+        $id  = $this->request->param($pk);
+        $row = $this->model->find($id);
+        if (!$row) {
+            $this->error(__('Record not found'));
+        }
+
+        $dataLimitAdminIds = $this->getDataLimitAdminIds();
+        if ($dataLimitAdminIds && !in_array($row[$this->dataLimitField], $dataLimitAdminIds)) {
+            $this->error(__('You have no permission'));
+        }
+
+        if ($this->request->isPost()) {
+            $data = $this->request->post();
+            if (!$data) {
+                $this->error(__('Parameter %s can not be empty', ['']));
+            }
+
+            $data   = $this->excludeFields($data);
+            $result = false;
+            $this->model->startTrans();
+            try {
+                // 模型验证
+                if ($this->modelValidate) {
+                    $validate = str_replace("\\model\\", "\\validate\\", get_class($this->model));
+                    if (class_exists($validate)) {
+                        $validate = new $validate();
+                        if ($this->modelSceneValidate) $validate->scene('edit');
+                        $data[$pk] = $row[$pk];
+                        $validate->check($data);
+                    }
+                }
+                unset($data['id']);
+                $result = $row->save($data);
+                $this->model->commit();
+            } catch (Throwable $e) {
+                $this->model->rollback();
+                $this->error($e->getMessage());
+            }
+            if ($result !== false) {
+                $this->success(__('Update successful'));
+            } else {
+                $this->error(__('No rows updated'));
+            }
+        }
+        $arr = [];
+        foreach (($row->toArray()) as $k=>$v)
+        {
+            $arr[strtolower($k)] = $v;
+        }
+        $this->success('', [
+            'row' => $arr
+        ]);
+    }
 }

+ 11 - 4
jcjyhr/app/admin/controller/dict/Commontable.php

@@ -68,17 +68,19 @@ class Commontable extends Backend
                 // $i++;
             }
         }
+        $arr = [];
+        $list = json_decode(json_encode($list), true);
         foreach ($list as $k=>$v)
         {
             $list[$k]['AREA'] = $arr[$v['CODE']] ?? [];
             foreach ($v as $k1=>$v1)
             {
-                $list[$k][strtolower($k1)] = $v1;
+                $arr[$k][strtolower($k1)] = $v1;
             }
         }
 
         $this->success('', [
-            'list'   => $list,
+            'list'   => $arr,
             'total'  => $res->total(),
             'remark' => get_route_remark(),
         ]);
@@ -174,6 +176,7 @@ class Commontable extends Backend
                 {
                     $data['create_user'] = Admin::where('id',$data['create_user_id'])->value('nickname');
                 }
+                unset($data['id']);
                 $result = $row->save($data);
                 $this->model->commit();
             } catch (Throwable $e) {
@@ -186,9 +189,13 @@ class Commontable extends Backend
                 $this->error(__('No rows updated'));
             }
         }
-
+        $arr = [];
+        foreach (($row->toArray()) as $k=>$v)
+        {
+            $arr[strtolower($k)] = $v;
+        }
         $this->success('', [
-            'row' => $row
+            'row' => $arr
         ]);
     }
 

+ 59 - 4
jcjyhr/app/admin/controller/dict/Examproject.php

@@ -36,6 +36,48 @@ class Examproject extends Backend
      * 若需重写查看、编辑、删除等方法,请复制 @see \app\admin\library\traits\Backend 中对应的方法至此进行重写
      */
 
+    /**
+     * 查看
+     * @throws Throwable
+     */
+    public function index(): void
+    {
+        if ($this->request->param('select')) {
+            $this->select();
+        }
+
+        $field = 'ID AS id,
+                        XM_CODE,
+                        MODALITY AS modality,
+                        BW,
+                        XM,
+                        BW_CODE,
+                        WEIGH AS weigh,
+                        STATUS AS status,
+                        CREATE_TIME AS create_time,
+                        UPDATE_TIME AS update_time,
+                        AREA AS area,
+                        VERSION AS version,
+                        EXT AS ext,
+                        CREATE_USER AS create_user,
+                        CREATE_USER_ID AS create_user_id';
+        list($where, $alias, $limit, $order) = $this->queryBuilder();
+        $res = $this->model
+            ->field($this->indexField)
+            ->withJoin($this->withJoinTable, $this->withJoinType)
+            ->alias($alias)
+            ->where($where)
+            ->order($order)
+            ->field($field)
+            ->paginate($limit);
+
+        $this->success('', [
+            'list'   => $res->items(),
+            'total'  => $res->total(),
+            'remark' => get_route_remark(),
+        ]);
+    }
+
 
     public function import(): void
     {
@@ -49,8 +91,7 @@ class Examproject extends Backend
         $attachment = '';
         try {
             $upload = new Upload($file);
-            $attachment = $upload->upload(null, $this->auth->id);
-            unset($attachment['create_time'], $attachment['quote']);
+            $attachment = $upload->uploadExcel(null, $this->auth->ID);
         } catch (Throwable $e) {
             $this->error($e->getMessage());
         }
@@ -71,7 +112,6 @@ class Examproject extends Backend
         foreach ($excel_data as $key=>$val) {
             foreach ($val as &$v) {
                 $v = str_replace(' ', '', trim($v));
-                $v = str_replace("\xC2\xA0", '', $v);
             }
             unset($v);
             $data[] = [
@@ -149,7 +189,22 @@ class Examproject extends Backend
     {
         $pk  = $this->model->getPk();
         $id  = $this->request->param($pk);
-        $row = $this->model->find($id);
+        $field = 'ID AS id,
+                        XM_CODE,
+                        MODALITY AS modality,
+                        BW,
+                        XM,
+                        BW_CODE,
+                        WEIGH AS weigh,
+                        STATUS AS status,
+                        CREATE_TIME AS create_time,
+                        UPDATE_TIME AS update_time,
+                        AREA AS area,
+                        VERSION AS version,
+                        EXT AS ext,
+                        CREATE_USER AS create_user,
+                        CREATE_USER_ID AS create_user_id';
+        $row = $this->model->field($field)->find($id);
         if (!$row) {
             $this->error(__('Record not found'));
         }

+ 72 - 4
jcjyhr/app/admin/controller/dict/Labitem.php

@@ -30,6 +30,54 @@ class Labitem extends Backend
         parent::initialize();
         $this->model = new \app\admin\model\dict\Labitem();
     }
+    /**
+     * 查看
+     * @throws Throwable
+     */
+    public function index(): void
+    {
+        if ($this->request->param('select')) {
+            $this->select();
+        }
+
+        $field = 'XH,
+                BSYBBM,
+                XMMC,
+                BZ,
+                GJYBBM,
+                BJSHRBM,
+                HRJYXMMC,
+                HRXMXH,
+                ID AS id,
+                WEIGH AS weigh,
+                STATUS AS status,
+                CREATE_TIME AS create_time,
+                UPDATE_TIME AS update_time,
+                VERSION AS version,
+                EXT AS ext,
+                CREATE_USER AS create_user,
+                CREATE_USER_ID AS create_user_id,
+                AREA AS area,
+                CREATE_TIME AS create_datetime,
+                ITEMTYPE,
+                ITEMTYPE_CODE,
+                TMP_XM AS tmp_xm';
+        list($where, $alias, $limit, $order) = $this->queryBuilder();
+        $res = $this->model
+            ->field($this->indexField)
+            ->withJoin($this->withJoinTable, $this->withJoinType)
+            ->alias($alias)
+            ->where($where)
+            ->order($order)
+            ->field($field)
+            ->paginate($limit);
+
+        $this->success('', [
+            'list'   => $res->items(),
+            'total'  => $res->total(),
+            'remark' => get_route_remark(),
+        ]);
+    }
 
 
     /**
@@ -48,8 +96,7 @@ class Labitem extends Backend
         $attachment = '';
         try {
             $upload = new Upload($file);
-            $attachment = $upload->upload(null, $this->auth->id);
-            unset($attachment['create_time'], $attachment['quote']);
+            $attachment = $upload->uploadExcel(null, $this->auth->ID);
         } catch (Throwable $e) {
             $this->error($e->getMessage());
         }
@@ -70,7 +117,6 @@ class Labitem extends Backend
         foreach ($excel_data as $key=>$val) {
             foreach ($val as &$v) {
                 $v = str_replace(' ', '', trim($v));
-                $v = str_replace("\xC2\xA0", '', $v);
             }
             unset($v);
             $data[] = [
@@ -148,7 +194,29 @@ class Labitem extends Backend
     {
         $pk  = $this->model->getPk();
         $id  = $this->request->param($pk);
-        $row = $this->model->find($id);
+        $field = 'XH,
+                BSYBBM,
+                XMMC,
+                BZ,
+                GJYBBM,
+                BJSHRBM,
+                HRJYXMMC,
+                HRXMXH,
+                ID AS id,
+                WEIGH AS weigh,
+                STATUS AS status,
+                CREATE_TIME AS create_time,
+                UPDATE_TIME AS update_time,
+                VERSION AS version,
+                EXT AS ext,
+                CREATE_USER AS create_user,
+                CREATE_USER_ID AS create_user_id,
+                AREA AS area,
+                CREATE_TIME AS create_datetime,
+                ITEMTYPE,
+                ITEMTYPE_CODE,
+                TMP_XM AS tmp_xm';
+        $row = $this->model->field($field)->find($id);
         if (!$row) {
             $this->error(__('Record not found'));
         }

+ 11 - 11
jcjyhr/app/admin/controller/institution/Depart.php

@@ -72,7 +72,7 @@ class Depart extends Backend
         }
 
         $this->success('', [
-            'list'   => $list,
+            'list'   => $arr,
             'total'  => $res->total(),
             'remark' => get_route_remark(),
         ]);
@@ -108,7 +108,7 @@ class Depart extends Backend
         $attachment = '';
         try {
             $upload = new Upload($file);
-            $attachment = $upload->upload(null, $this->auth->id);
+            $attachment = $upload->upload(null, $this->auth->ID);
             unset($attachment['create_time'], $attachment['quote']);
         } catch (Throwable $e) {
             $this->error($e->getMessage());
@@ -139,6 +139,7 @@ class Depart extends Backend
                 'depart_name'=>$val[0],        //科室名称
                 'depart_code'=>$val[1],        //科室编码
                 'institution_id'=>$institution,     //所属机构
+                'create_datetime'=>date('Y-m-d H:i:s'),
             ];
         }
         Cache::delete('allDepart');
@@ -163,7 +164,7 @@ class Depart extends Backend
         $attachment = '';
         try {
             $upload = new Upload($file);
-            $attachment = $upload->upload(null, $this->auth->id);
+            $attachment = $upload->uploadExcel(null, $this->auth->ID);
             unset($attachment['create_time'], $attachment['quote']);
         } catch (Throwable $e) {
             $this->error($e->getMessage());
@@ -189,12 +190,6 @@ class Depart extends Backend
         $data = [];
         $admin = new Admin();
         foreach ($excel_data as $key=>$val) {
-            foreach ($val as &$v) {
-                $v = str_replace(' ', '', trim($v));
-                $v = str_replace("\xC2\xA0", '', $v);
-            }
-            unset($v);
-
             //加密盐
             $salt   = Random::build('alnum', 16);
             //密码
@@ -282,7 +277,12 @@ class Depart extends Backend
     {
         $pk  = $this->model->getPk();
         $id  = $this->request->param($pk);
-        $row = $this->model->find($id);
+        $arr = $this->model->find($id);
+        $row = [];
+        foreach ($arr->toArray() as $k=>$v)
+        {
+            $row[strtolower($k)] = $v;
+        }
         if (!$row) {
             $this->error(__('Record not found'));
         }
@@ -316,7 +316,7 @@ class Depart extends Backend
                 {
                     $data['create_user'] = Admin::where('id',$data['create_user_id'])->value('nickname');
                 }
-                $result = $row->save($data);
+                $result = $arr->save($data);
                 $this->model->commit();
                 Cache::delete('allDepart');
             } catch (Throwable $e) {

+ 14 - 11
jcjyhr/app/admin/controller/institution/Institution.php

@@ -95,8 +95,7 @@ class Institution extends Backend
         $attachment = '';
         try {
             $upload = new Upload($file);
-            $attachment = $upload->upload(null, $this->auth->id);
-            unset($attachment['create_time'], $attachment['quote']);
+            $attachment = $upload->uploadExcel(null, $this->auth->ID);
         } catch (Throwable $e) {
             $this->error($e->getMessage());
         }
@@ -117,10 +116,6 @@ class Institution extends Backend
         }
         $data = [];
         foreach ($excel_data as $key=>$val) {
-            foreach ($val as &$v) {
-                $v = str_replace(' ', '', trim($v));
-                $v = str_replace("\xC2\xA0", '', $v);
-            }
             $parent = '';
             if(!empty($val[3]))
             {
@@ -131,20 +126,28 @@ class Institution extends Backend
                 continue;
             }
             unset($v);
-            $data[] = [
+            $arr = [
                 'name'=>$val[0],                    //机构名称
                 'institution_code'=>$val[1],        //机构编码
                 'institution_type'=>$val[2],        //机构类型
-                'parent_institution_id'=>$parent,   //上级医院
                 'port_empower'=>md5($val[1].rand(100000,999999)),            //接口授权ID
                 'area'=>$val[5],                     //互认范围
             ];
+            if(!empty($parent))
+            {
+                $arr['parent_institution_id'] = $parent;
+            }
+            $data[] = $arr;
         }
         Cache::delete('institution_dashboard');
         Cache::delete('allIns');
         if(!empty($data))
         {
-            $this->model->saveAll($data);
+            try{
+                $this->model->saveAll($data);
+            } catch (Throwable $e) {
+                $this->error($e->getMessage());
+            }
         }else{
             $this->error('导入失败,未读取到数据');
         }
@@ -286,7 +289,7 @@ class Institution extends Backend
         $id  = $this->request->param($pk);
         $arr = $this->model->find($id);
         $row = [];
-        foreach ($arr as $k=>$v)
+        foreach ($arr->toArray() as $k=>$v)
         {
             $row[strtolower($k)] = $v;
         }
@@ -336,7 +339,7 @@ class Institution extends Backend
                     }
                     Cache::delete($row['port_empower']);
                 }
-                $result = $row->save($data);
+                $result = $arr->save($data);
                 $this->model->commit();
                 Cache::delete('institution_dashboard');
                 Cache::delete('allIns');

+ 1 - 1
jcjyhr/app/admin/library/traits/Backend.php

@@ -182,7 +182,7 @@ trait Backend
         $this->model->startTrans();
         try {
             foreach ($data as $v) {
-                $count += $v->delete();
+                $count += $v->where('ID',$v['ID'])->delete();
             }
             $this->model->commit();
         } catch (Throwable $e) {

+ 4 - 1
jcjyhr/app/admin/model/Admin.php

@@ -23,7 +23,7 @@ class Admin extends Model
     /**
      * @var string 自动写入时间戳
      */
-    protected $autoWriteTimestamp = false;
+    protected $autoWriteTimestamp = 'datetime';
     protected $name = 'admins';
 
     /**
@@ -51,6 +51,9 @@ class Admin extends Model
 
     public function getAvatarAttr($value): string
     {
+        if(empty($value)){
+            $value = '';
+        }
         return full_url($value, false, config('buildadmin.default_avatar'));
     }
 

+ 1 - 1
jcjyhr/app/admin/model/dict/Commondata.php

@@ -13,7 +13,7 @@ class Commondata extends Model
     protected $name = 'dict_common_data';
 
     // 自动写入时间戳字段
-    protected $autoWriteTimestamp = true;
+    protected $autoWriteTimestamp = 'datetime';
 
     protected static function onAfterInsert($model): void
     {

+ 1 - 1
jcjyhr/app/admin/model/dict/Commontable.php

@@ -13,7 +13,7 @@ class Commontable extends Model
     protected $name = 'dict_common_table';
 
     // 自动写入时间戳字段
-    protected $autoWriteTimestamp = true;
+    protected $autoWriteTimestamp = 'datetime';
 
     protected static function onAfterInsert($model): void
     {

+ 1 - 1
jcjyhr/app/admin/model/dict/Examproject.php

@@ -13,7 +13,7 @@ class Examproject extends Model
     protected $name = 'dict_exam_project';
 
     // 自动写入时间戳字段
-    protected $autoWriteTimestamp = true;
+    protected $autoWriteTimestamp = 'datetime';
 
     protected static function onAfterInsert($model): void
     {

+ 1 - 1
jcjyhr/app/admin/model/dict/Labitem.php

@@ -13,7 +13,7 @@ class Labitem extends Model
     protected $name = 'dict_lab_item';
 
     // 自动写入时间戳字段
-    protected $autoWriteTimestamp = true;
+    protected $autoWriteTimestamp = 'datetime';
 
     protected static function onAfterInsert($model): void
     {

+ 1 - 2
jcjyhr/app/admin/model/institution/Depart.php

@@ -13,8 +13,7 @@ class Depart extends Model
     protected $name = 'depart';
 
     // 自动写入时间戳字段
-    protected $autoWriteTimestamp = true;
-
+    protected $autoWriteTimestamp = 'datetime';
 
     public function institution(): \think\model\relation\BelongsTo
     {

+ 2 - 2
jcjyhr/app/admin/model/institution/Institution.php

@@ -13,8 +13,8 @@ class Institution extends Model
     protected $name = 'institution';
 
     // 自动写入时间戳字段
-    protected $autoWriteTimestamp = true;
-
+    protected $autoWriteTimestamp = 'datetime';
+//    protected $dateFormat = 'Y-m-d H:i:s'; // 指定时间格式
 
     public function parentInstitution(): \think\model\relation\BelongsTo
     {

+ 1 - 0
jcjyhr/app/zskk/controller/Patient.php

@@ -94,6 +94,7 @@ class Patient extends ZskkApiController
     {
         $params = $this->request->get();
         $id = $params['id_card'] ?? '';
+        $id = 'UPqz1zCNgn8rgkEC5Yfb3bKMkE1tOOCZH4R9Kx7WrmI=';
         $mpiIdCard = Gm::decrypt(\think\facade\Config::get('gm.key'),$id);
         echo $mpiIdCard;
     }

+ 1 - 0
jcjyhr/app/zskk/servies/PatientServies.php

@@ -978,6 +978,7 @@ class PatientServies
             foreach ($hosEmpi as $v)
             {
                 $information = $this->patientModel->getMedicalData(['HOS_EMPI'=>$v,'ORGCODE'=>$params['MEDICAL_INFORMATION']['ORGCODE']],'*');
+                var_dump($information);die;
                 if(empty($information))
                 {
                     return '';