Browse Source

更新患者导入

ChenWuJie 4 years ago
parent
commit
9211f48f6d
2 changed files with 37 additions and 15 deletions
  1. 8 8
      app/Console/Commands/ImportUser.php
  2. 29 7
      app/Imports/User/PatientsSheet.php

+ 8 - 8
app/Console/Commands/ImportUser.php

xqd xqd
@@ -50,12 +50,12 @@ class ImportUser extends Command
         if(empty($type) || empty($file_path)){
             dd('请输入完整参数');
         }
-        //医生信息导入
+        //用户信息导入
         if($type == 'user'){
             $this->makeUser($file_path);
         }
-        if($type == 'patiens'){
-            $this->makePatiens($file_path);
+        if($type == 'patients'){
+            $this->makePatients($file_path);
         }
     }
     //导入用户
@@ -65,17 +65,17 @@ class ImportUser extends Command
     }
     public function importsUser($filePath)
     {
-        $filePath = './public/import/' . $filePath . '.xls';
+        $filePath = './public/import/' . $filePath . '.xlsx';
         Excel::import(new UserInfo(), $filePath);
     }
     //导入患者
-    public function makePatiens($file_path)
+    public function makePatients($file_path)
     {
-        $this->importsPatiens($file_path);
+        $this->importsPatients($file_path);
     }
-    public function importsPatiens($filePath)
+    public function importsPatients($filePath)
     {
-        $filePath = './public/import/' . $filePath . '.xls';
+        $filePath = './public/import/' . $filePath . '.xlsx';
         Excel::import(new PatientsInfo(), $filePath);
     }
 }

+ 29 - 7
app/Imports/User/PatientsSheet.php

xqd xqd xqd xqd
@@ -22,11 +22,6 @@ class PatientsSheet implements ToCollection
             {
                 continue;
             }
-            //todo 用同一个程序的话,excel的字段顺序要对应起来
-            if ($row[0]=="孩子姓名")
-            {
-                continue;
-            }
 
             //姓名
             if ($row[2] == null)
@@ -49,6 +44,7 @@ class PatientsSheet implements ToCollection
                         'created_at' => date('Y-m-d H:i:s',time()),
                         'balance' => 0
                     ]);
+                    \Log::info('新增用户'.$new_user['id']);
                 }else{
                     $new_user['id'] = User::where('phone',$row[1])->value('id');
                 }
@@ -64,7 +60,7 @@ class PatientsSheet implements ToCollection
             {
                 $patients_info['sex'] = 0;
             }else{
-                if ($row[4] == "男")
+                if ($row[5] == "男")
                 {
                     $patients_info['sex'] = 1;
                 }else{
@@ -81,8 +77,34 @@ class PatientsSheet implements ToCollection
             }else{
                 $patients_info['phone'] = $row[1];
             }
-            //todo 患者生日没有导入
+            if ($row[3])
+            {
+                $patients_info['birthday'] = self::excelTime($row[3]);
+            }else{
+                $patients_info['birthday'] = self::excelTime(0);
+            }
             Patient::create($patients_info);
         }
     }
+    static function excelTime($date, $time = false) {
+        if(function_exists('GregorianToJD')){
+            if (is_numeric( $date )) {
+                $jd = GregorianToJD( 1, 1, 1970 );
+                $gregorian = JDToGregorian( $jd + intval ( $date ) - 25569 );
+                $date = explode( '/', $gregorian );
+                $date_str = str_pad( $date [2], 4, '0', STR_PAD_LEFT )
+                    ."-". str_pad( $date [0], 2, '0', STR_PAD_LEFT )
+                    ."-". str_pad( $date [1], 2, '0', STR_PAD_LEFT )
+                    . ($time ? " 00:00:00" : '');
+                return $date_str;
+            }
+        }else{
+            $date=$date>25568?$date+1:25569;
+            /*There was a bug if Converting date before 1-1-1970 (tstamp 0)*/
+            $ofs=(70 * 365 + 17+2) * 86400;
+            $date = date("Y-m-d",($date * 86400) - $ofs).($time ? " 00:00:00" : '');
+        }
+//        dd($date);
+        return $date;
+    }
 }