12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace App\Imports\User;
- use App\Models\Patient;
- use App\Models\User;
- use Maatwebsite\Excel\Concerns\ToModel;
- use Illuminate\Support\Collection;
- use Maatwebsite\Excel\Concerns\ToCollection;
- use phpDocumentor\Reflection\DocBlock;
- class PatientsSheet implements ToCollection
- {
- /**
- * @param Collection $collection
- */
- public function collection(Collection $collection)
- {
- $patients_info = [];
- foreach ($collection as $row) {
- if ($row[0]=="患者姓名")
- {
- continue;
- }
- //姓名
- if ($row[2] == null)
- {
- $user_name = '默认用户';
- $nickname = '默认用户';
- }else{
- $user_name = $row[2] ;
- $nickname = $row[2] ;
- }
- if ($row[1])
- {
- $has_user = User::where('phone',$row[1])->count();
- if ($has_user == 0)
- {
- $new_user = User::create([
- 'nickname' =>$nickname,
- 'user_name' => $user_name,
- 'phone' => $row[1],
- 'created_at' => date('Y-m-d H:i:s',time()),
- 'balance' => 0
- ]);
- }else{
- $new_user['id'] = User::where('phone',$row[1])->value('id');
- }
- }
- if ($new_user['id'] != null)
- {
- $patients_info['user_id'] = $new_user['id'];
- }else{
- $patients_info['user_id'] = 0;
- }
- if ($row[4] == null)
- {
- $patients_info['sex'] = 0;
- }else{
- if ($row[4] == "男")
- {
- $patients_info['sex'] = 1;
- }else{
- $patients_info['sex'] = 2;
- }
- }
- if ($row[0]==null){
- $patients_info['name'] = '默认用户';
- }else{
- $patients_info['name'] = $row[0];
- }
- if ($row[1] == null){
- $patients_info['phone'] = 0;
- }else{
- $patients_info['phone'] = $row[1];
- }
- //todo 患者生日没有导入
- Patient::create($patients_info);
- }
- }
- }
|