Parcourir la source

Merge branch 'master' of ssh://git.9026.com:2212/swdz-WangHaijun/BaoMa

zilong il y a 4 ans
Parent
commit
95a0714da9
40 fichiers modifiés avec 1140 ajouts et 289 suppressions
  1. 0 47
      .env.example
  2. 23 5
      README.md
  3. 1 1
      app/Admin/Controllers/ArticleManagement/ArticleController.php
  4. 0 6
      app/Admin/Controllers/CouponManagement/CouponDistributionUserList.php
  5. 17 5
      app/Admin/Controllers/CouponManagement/CouponManagementController.php
  6. 4 4
      app/Admin/Controllers/DataCenter/FinancialOrderOverview.php
  7. 7 7
      app/Admin/Controllers/DataCenter/FinancialOverview.php
  8. 2 27
      app/Admin/Controllers/OrdersManagement/BookingOrderController.php
  9. 1 1
      app/Admin/Controllers/OrdersManagement/ServicePackDetailsController.php
  10. 1 0
      app/Admin/Controllers/OrdersManagement/ServicePackOrderController.php
  11. 2 0
      app/Admin/Controllers/UserManagement/BmUser/FeedBacksController.php
  12. 1 1
      app/Admin/Controllers/UserManagement/BmUser/UserListController.php
  13. 1 1
      app/Admin/Controllers/UserManagement/BmUser/UserPatientsController.php
  14. 2 0
      app/Admin/Controllers/UserManagement/DocterManagement/ApproveController.php
  15. 7 7
      app/Admin/Controllers/UserManagement/DocterManagement/DoctorManagementController.php
  16. 1 1
      app/Admin/Controllers/UserManagement/DocterManagement/PhoneController.php
  17. 7 2
      app/Admin/Controllers/UserManagement/DocterManagement/UserEvaluatesController.php
  18. 2 5
      app/Admin/Controllers/VaccinesManagement/VaccinesController.php
  19. 1 1
      app/Community/Actions/Nurse/Finished.php
  20. 11 7
      app/Community/Actions/Nurse/OrderCance.php
  21. 1 1
      app/Community/Actions/Nurse/Reserved.php
  22. 9 1
      app/Community/Controllers/OrderController.php
  23. 42 39
      app/Community/Controllers/OrderNurseController.php
  24. 4 1
      app/Community/Controllers/StatController.php
  25. 30 15
      app/Console/Commands/ImportDocter.php
  26. 63 7
      app/Console/Commands/ImportOrder.php
  27. 81 0
      app/Console/Commands/ImportUser.php
  28. 14 13
      app/Imports/Docter/DocterInfo.php
  29. 4 3
      app/Imports/Docter/OrganizationInfo.php
  30. 59 0
      app/Imports/Docter/OrganizationOffice.php
  31. 89 59
      app/Imports/Order/chatOrder.php
  32. 92 14
      app/Imports/Order/nurseSheet.php
  33. 128 0
      app/Imports/Order/phoneOrder.php
  34. 95 0
      app/Imports/Order/serviceOrder.php
  35. 16 0
      app/Imports/Order/vaccineOrder.php
  36. 70 8
      app/Imports/Order/vaccineSheet.php
  37. 35 0
      app/Imports/User/PatientsInfo.php
  38. 110 0
      app/Imports/User/PatientsSheet.php
  39. 35 0
      app/Imports/User/UserInfo.php
  40. 72 0
      app/Imports/User/UserSheet.php

+ 0 - 47
.env.example

xqd
@@ -1,47 +0,0 @@
-APP_NAME=Laravel
-APP_ENV=local
-APP_KEY=
-APP_DEBUG=true
-APP_URL=http://localhost
-
-LOG_CHANNEL=stack
-
-DB_CONNECTION=mysql
-DB_HOST=127.0.0.1
-DB_PORT=3306
-DB_DATABASE=laravel
-DB_USERNAME=root
-DB_PASSWORD=
-DB_PREFIX=bm_
-
-BROADCAST_DRIVER=log
-CACHE_DRIVER=file
-QUEUE_CONNECTION=sync
-SESSION_DRIVER=file
-SESSION_LIFETIME=120
-
-REDIS_HOST=127.0.0.1
-REDIS_PASSWORD=null
-REDIS_PORT=6379
-
-MAIL_DRIVER=smtp
-MAIL_HOST=smtp.mailtrap.io
-MAIL_PORT=2525
-MAIL_USERNAME=null
-MAIL_PASSWORD=null
-MAIL_ENCRYPTION=null
-
-AWS_ACCESS_KEY_ID=
-AWS_SECRET_ACCESS_KEY=
-AWS_DEFAULT_REGION=us-east-1
-AWS_BUCKET=
-
-PUSHER_APP_ID=
-PUSHER_APP_KEY=
-PUSHER_APP_SECRET=
-PUSHER_APP_CLUSTER=mt1
-
-MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
-MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
-
-API_HOST=

+ 23 - 5
README.md

xqd xqd xqd xqd
@@ -52,7 +52,7 @@ cd /www/wwwroot/BaoMa && php artisan  scheduleNotice<br>
 服务包过期 每10分钟执行
 cd /www/wwwroot/BaoMa && php artisan  packExpiredCheck<br>
 
-## 数据清空语句
+# 数据清空语句
 delete from bm_cdms_users where id > 1;<br>
 delete from bm_cdms_role_users where user_id >1;<br>
 delete from bm_admin_operation_log;<br>
@@ -114,7 +114,7 @@ delete from bm_organizations;<br>
 delete from bm_refund_application;<br>
 
 
-##清空用户数据
+## 清空用户数据
 delete  from bm_order_packs where order_id in (select id from bm_orders where user_id =10007 );<br>
 delete  from bm_order_patients where order_id in (select id from bm_orders where user_id =10007 );<br>
 delete  from bm_order_vaccines where order_id in (select id from bm_orders where user_id =10007 );<br>
@@ -124,7 +124,7 @@ delete  from bm_users where id = 10007;<br>
 delete  from bm_orders where user_id = 10007;<br>
 
 
-##清空医生数据
+## 清空医生数据
 delete from bm_docter_settings where docter_id  = 1007;<br>
 delete  from bm_order_packs where order_id in (select docter_id from bm_orders where docter_id=10007 );<br>
 delete  from bm_order_patients where order_id in (select id from bm_orders where docter_id=10007 );<br>
@@ -133,7 +133,25 @@ delete  from bm_order_nurses where order_id in (select id from bm_orders where d
 delete from bm_docters where id = 10007;<br>
 delete from bm_docter_organization where docter_id  = 10007;<br>
 
-
-
+# 导入用户数据
+##  导入用户数据要严格按照顺序来执行
+1. 导入机构表
+    - php artisan import:importDocter organization organization
+2. 导入医生表
+    -  php artisan import:importDocter docter docter
+3. 导入机构科室表 
+    - php artisan import:importDocter organization_office office
+4. 导入用户表
+    - php artisan import:importUser user user
+5. 导入患者表
+    - php artisan import:importUser patients patients
+
+# 导入订单数据
+## 导入订单数据之前必须要导入用户数据,否则会报错
+- php artisan importOrder nurse nurseOrder
+- php artisan importOrder service order
+- php artisan importOrder vaccine vaccineOrder
+- php artisan importOrder chat chatOrder
+- php artisan importOrder phone phoneOrder
 
 

+ 1 - 1
app/Admin/Controllers/ArticleManagement/ArticleController.php

xqd
@@ -32,7 +32,7 @@ class ArticleController extends AdminController
         $grid->column('id', __('Id'));
         $grid->column('type', __('分类'))->using([1=>'健康科普',2=>'疫苗科普']);
         $grid->column('title', __('标题'))->limit(10,'...')->width(100);
-        $grid->column('content', __('内容'))->limit(20,'...')->width(200);
+//        $grid->column('content', __('内容'))->limit(20,'...')->width(200);
         $grid->column('banner_url', __('图片'))->lightbox(['width' =>'', 'height' => 30]);
         $grid->column('created_at', __('创建时间'));
         $grid->column('updated_at', __('更新时间'));

+ 0 - 6
app/Admin/Controllers/CouponManagement/CouponDistributionUserList.php

xqd xqd
@@ -37,11 +37,6 @@ class CouponDistributionUserList extends AdminController
                 0    => '黑名单',
                 1    => '正常',
             ]);
-            $filter->equal('is_pack','用户状态')->radio([
-                ''   => '全部用户',
-                0    => '普通用户',
-                1    => '服务包用户',
-            ]);
         });
         $grid->batchActions(function ($batch) {
             $batch->add(new CouponBatchGrant());
@@ -55,7 +50,6 @@ class CouponDistributionUserList extends AdminController
         $grid->column('sex', __('性别'))->using([0=>'未知',1=>'男',2=>'女']);
         $grid->column('age', __('年龄'));
         $grid->column('status', __('状态'))->using([0=>'黑名单',1=>'正常',]);
-        $grid->column('is_pack', __('用户身份'))->using([0=>'普通用户',1=>'付费用户']);
         $grid->column('balance', __('当前余额'))->display(function ($price){
             return $price/100;
         });

+ 17 - 5
app/Admin/Controllers/CouponManagement/CouponManagementController.php

xqd xqd xqd xqd xqd
@@ -164,6 +164,13 @@ class CouponManagementController extends AdminController
             $f->model()->max_reduce_amount /=100;
             $f->model()->min_consume_amount /=100;
             $f->model()->money /=100;
+            $f->model()->start_time = date('Y-m-d H:i:s',$f->model()->start_time);
+            $f->model()->end_time = date('Y-m-d H:i:s',$f->model()->end_time);
+            if ($f->model()->start_time == 0 || $f->model()->end_time)
+            {
+                $f->model()->end_time = date('Y-m-d H:i:s',time());
+                $f->model()->start_time = date('Y-m-d H:i:s',time());
+            }
         });
         $type = request('type');
         if (isset($type))
@@ -174,7 +181,6 @@ class CouponManagementController extends AdminController
         $form->text('title', __('券标题'));
         $form->text('desc', __('使用说明'));
         $form->text('rules', __('使用规则'));
-//        dd($form->toArray());
         $form->image('icon', __('券图标'))->help('图标大小48px * 48px');
         $form->select('type', '类型')
             ->options([
@@ -216,7 +222,6 @@ class CouponManagementController extends AdminController
                     2=>'部分产品可用'
                 ]);
         }
-
         $form->select('expire_type', '过期类型')
             ->options([
                 1 => '领取N天过期',
@@ -224,8 +229,8 @@ class CouponManagementController extends AdminController
             ])->when(1, function (Form $form) {
                 $form->text('effective_days', __('有效天数'));
             })->when(2, function (Form $form) {
-                $form->date('start_time', __('有效期开始时间'));
-                $form->date('end_time', __('有效期结束时间'));
+                $form->datetime('start_time', __('有效期开始时间'));
+                $form->datetime('end_time', __('有效期结束时间'));
                 $form->saving(function ($form){
                     $form->start_time = strtotime($form->start_time);
                     $form->end_time = strtotime($form->end_time);
@@ -242,7 +247,14 @@ class CouponManagementController extends AdminController
                         {
                             return redirect('admin/coupons/create?type=1');
                         }
-
+                    }
+                    //如果过期类型是领取n天的话就把开始时间和结束时间置空
+                    if ($form->expire_type == 1)
+                    {
+                        $form->start_time = 0;
+                        $form->end_time = 0;
+                    }else{
+                        $form->effective_days = 0;
                     }
                 });
             });

+ 4 - 4
app/Admin/Controllers/DataCenter/FinancialOrderOverview.php

xqd
@@ -27,16 +27,16 @@ class FinancialOrderOverview
             ->row('<h1 text-align="center">订单走势</h1>')
             ->row(function (Row $row) {
                 $row->column(3, function (Column $column) {
-                    $column->append(infoBox('今日支付金额', 'dropbox', '/admin/deliver?status=1', 'green', FinancialSta::getTodayPay()));
+                    $column->append(infoBox('今日支付金额', 'dropbox', '', 'green', FinancialSta::getTodayPay()));
                 });
                 $row->column(3, function (Column $column) {
-                    $column->append(infoBox('昨日支付金额', 'dropbox', '/admin/deliver?status=1', 'green', FinancialSta::getYesterdayPay()));
+                    $column->append(infoBox('昨日支付金额', 'dropbox', '', 'green', FinancialSta::getYesterdayPay()));
                 });
                 $row->column(3, function (Column $column) {
-                    $column->append(infoBox('近七日支付金额', 'dropbox', '/admin/deliver?status=1', 'green', FinancialSta::getSevenDayPay()));
+                    $column->append(infoBox('近七日支付金额', 'dropbox', '', 'green', FinancialSta::getSevenDayPay()));
                 });
                 $row->column(3, function (Column $column) {
-                    $column->append(infoBox('近三十日支付金额', 'dropbox', '/admin/deliver?status=1', 'green', FinancialSta::getOneMonthPay()));
+                    $column->append(infoBox('近三十日支付金额', 'dropbox', '', 'green', FinancialSta::getOneMonthPay()));
                 });
             })
             ->row(function (Row $row){

+ 7 - 7
app/Admin/Controllers/DataCenter/FinancialOverview.php

xqd
@@ -28,28 +28,28 @@ class FinancialOverview
             ->row(function (Row $row) {
                 // 产品类型(1.电话咨询 2.图文咨询 3.门诊预约 4.疫苗接种预约 5.儿保预约 6.服务包 7.充值)
                 $row->column(3, function (Column $column) {
-                    $column->append(infoBox('收入总金额', 'dropbox', '/admin/deliver?status=1', 'green', FinancialSta::getTotalIncome()));
+                    $column->append(infoBox('收入总金额', 'dropbox', '', 'green', FinancialSta::getTotalIncome()));
                 });
                 $row->column(3, function (Column $column) {
-                    $column->append(infoBox('退款总金额', 'dropbox', '/admin/deliver?status=1', 'green', FinancialSta::getTotalRefund()));
+                    $column->append(infoBox('退款总金额', 'dropbox', '', 'green', FinancialSta::getTotalRefund()));
                 });
                 $row->column(3, function (Column $column) {
-                    $column->append(infoBox('用户充值总金额', 'dropbox', '/admin/deliver?status=1', 'green', FinancialSta::getTotalRecharge()));
+                    $column->append(infoBox('用户充值总金额', 'dropbox', '', 'green', FinancialSta::getTotalRecharge()));
                 });
                 $row->column(3, function (Column $column) {
-                    $column->append(infoBox('用户总余额', 'dropbox', '/admin/deliver?status=1', 'green', FinancialSta::getTotalUserBalance()));
+                    $column->append(infoBox('用户总余额', 'dropbox', '', 'green', FinancialSta::getTotalUserBalance()));
                 });
             })
             ->row('<h1 text-align="center">充值记录</h1>')
             ->row(function (Row $row){
                 $row->column(3,function (Column $column){
-                    $column->append(infoBox('当日充值金额', 'dropbox', '/admin/deliver?status=1', 'green', FinancialSta::getTodayReCharge()));
+                    $column->append(infoBox('当日充值金额', 'dropbox', '', 'green', FinancialSta::getTodayReCharge()));
                 });
                 $row->column(3,function (Column $column){
-                    $column->append(infoBox('近七日充值金额', 'dropbox', '/admin/deliver?status=1', 'green', FinancialSta::getSevenDayReCharge()));
+                    $column->append(infoBox('近七日充值金额', 'dropbox', '', 'green', FinancialSta::getSevenDayReCharge()));
                 });
                 $row->column(3,function (Column $column){
-                    $column->append(infoBox('近三十日充值金额', 'dropbox', '/admin/deliver?status=1', 'green', FinancialSta::getOneMonthReCharge()));
+                    $column->append(infoBox('近三十日充值金额', 'dropbox', '', 'green', FinancialSta::getOneMonthReCharge()));
                 });
             })
             ->row(function (Row $row){

+ 2 - 27
app/Admin/Controllers/OrdersManagement/BookingOrderController.php

xqd xqd xqd
@@ -46,6 +46,7 @@ class BookingOrderController extends AdminController
                 $filter->like('user.nickname','用户姓名');
                 $filter->like('docter.name','医生姓名');
                 $filter->like('orderPatient.name','患者姓名');
+                $filter->equal('orderPatient.patient_phone','患者电话');
                 $filter->equal('product_type','预约类型')->radio(
                     [
                         ''=>'不限',
@@ -106,10 +107,6 @@ class BookingOrderController extends AdminController
                         }
                 }
             }
-            //有问题 未支付是订单状态,这里冲突了
-//            if ($actions->row->product_type == 5 && $actions->row->order_status == 5 && $actions->row->payment_status == 2){
-//
-//            }
         });
         $grid->model()->orderBy('id','desc');
         $grid->column('id', __('Id'))->sortable();
@@ -123,29 +120,7 @@ class BookingOrderController extends AdminController
         $grid->column('orderPatient.appoint_end_time', __('就诊日期'))->display(function ($time){
             return date('Y-m-d H:i:s',$time);
         });
-        $grid->column('is_evaluates', __('评价详情'))->expand(function ($model){
-            $infos = $model->evaluate()->get()->map(function ($info){
-                return $info->only(['order_id','content','status']);
-            });
-            $infos = $infos->toArray();
-            foreach ($infos as $key => $value)
-            {
-                if (!empty($infos[$key]))
-                {
-                    if ($infos[$key]['status'] == 1)
-                    {
-                        $infos[$key]['status'] = '待审核';
-                    }else if ($infos[$key]['status'] == 2)
-                    {
-                        $infos[$key]['status'] = '审核成功';
-                    }else{
-                        $infos[$key]['status'] = '审核拒绝';
-                    }
-                }
-            }
-            return new Table(['订单id','评价内容','评价状态'],$infos);
-        });
-        $grid->column('evaluate.score', __('订单评分'));
+//        $grid->column('evaluate.score', __('订单评分'));
         $grid->column('product_type', __('产品类型'))->using([3=>'门诊预约',4=>'疫苗接种预约',5=>'儿保预约']);
         $grid->column('payment_type', __('支付方式'))->display(function ($payment_type){
             if ($payment_type == 1)

+ 1 - 1
app/Admin/Controllers/OrdersManagement/ServicePackDetailsController.php

xqd
@@ -40,7 +40,7 @@ class ServicePackDetailsController extends AdminController
         $grid->column('pack_price', __('服务包价格'))->display(function ($price){
             return $price/100;
         });
-        $grid->column('phone_minutes', __('剩余电话分钟数'));
+        $grid->column('phone_minutes', __('剩余电话数'));
         $grid->column('chat_num', __('剩余图文咨询次数'));
         $grid->column('appoint_num', __('剩余门诊预约次数'));
         $grid->column('vaccine_limit_amount', __('剩余疫苗次数'));

+ 1 - 0
app/Admin/Controllers/OrdersManagement/ServicePackOrderController.php

xqd
@@ -54,6 +54,7 @@ class ServicePackOrderController extends AdminController
             });
         //操作
         $grid->actions(function ($actions) {
+            $actions->disableView();
             // 去掉删除
             $actions->disableDelete();
             // 去掉编辑

+ 2 - 0
app/Admin/Controllers/UserManagement/BmUser/FeedBacksController.php

xqd
@@ -31,6 +31,8 @@ class FeedBacksController extends AdminController
         });
         $grid->filter(function ($filter){
            $filter->like('docter.nickname','名字');
+           $filter->equal('docter.phone','电话');
+           $filter->between('created_at', '创建时间')->datetime();
         });
         $grid->column('id', __('Id'));
         $grid->column('user_id', __('用户id'));

+ 1 - 1
app/Admin/Controllers/UserManagement/BmUser/UserListController.php

xqd
@@ -55,7 +55,7 @@ class UserListController extends AdminController
             $filter->column(1/2, function ($filter) {
                 $filter->disableIdFilter();
                 $filter->equal('phone','手机')->mobile()->placeholder("请输入手机");
-                $filter->like('nickname','昵称');
+                $filter->like('nickname','用户名');
                 $filter->equal('status','用户状态')->radio([
                     ''   => '不限',
                     0    => '黑名单',

+ 1 - 1
app/Admin/Controllers/UserManagement/BmUser/UserPatientsController.php

xqd
@@ -46,7 +46,7 @@ class UserPatientsController extends AdminController
         $grid->column('userspatient.nickname', __('用户姓名'));
         $grid->column('name', __('患者姓名'));
         $grid->column('sex', __('性别'))->using([0=>'未知',1=>'男',2=>'女',]);
-        $grid->column('avatar', __('头像'))->lightbox(['width' =>'', 'height' => 30]);
+//        $grid->column('avatar', __('头像'))->lightbox(['width' =>'', 'height' => 30]);
         $grid->column('age', __('年龄'));
         $grid->column('email', __('邮箱'));
         $grid->column('phone', __('联系电话'));

+ 2 - 0
app/Admin/Controllers/UserManagement/DocterManagement/ApproveController.php

xqd xqd
@@ -35,6 +35,7 @@ class ApproveController extends AdminController
             $filter->disableIdFilter();
             $filter->like('docter.name','医生姓名');
             $filter->like('organization.name','机构名');
+            $filter->equal('state', '认证状态')->select([1=>'已认证',2=>'审核驳回',3=>'待审核']);
             $filter->between('authentication_time', '签约时间')->datetime();
             $filter->between('authentication_end_time', '签约到期时间')->datetime();
         });
@@ -43,6 +44,7 @@ class ApproveController extends AdminController
         $grid->column('id', __('Id'));
         $grid->column('docter.id', __('医生ID'));
         $grid->column('docter.name', __('医生姓名'));
+        $grid->column('docter.phone', __('医生电话'));
         $grid->column('docter.avatar', __('医生头像'))->lightbox(['width' =>'', 'height' => 30]);
         $grid->column('docter.sex', __('性别'))->using([0=>'未知',1=>'男',2=>'女']);
         $grid->column('organization.name', __('机构'));

+ 7 - 7
app/Admin/Controllers/UserManagement/DocterManagement/DoctorManagementController.php

xqd xqd xqd xqd xqd
@@ -40,7 +40,7 @@ class DoctorManagementController extends AdminController
         $grid->filter(function ($filter){
             $filter->disableIdFilter();
             $filter->like('name','昵称');
-//            $filter->like('organization','机构名称');
+            $filter->equal('phone','电话');
             $filter->where(function ($query) {
                 $query->whereHas('organization',function ($query){
                     $query->where('name','like',"%{$this->input}%");
@@ -50,6 +50,10 @@ class DoctorManagementController extends AdminController
                 0    => '禁用',
                 1    => '启用',
             ]);
+            $filter->equal('is_then','认证状态')->select([
+                0    => '未认证',
+                1    => '已认证',
+            ]);
         });
         $grid->actions(function ($actions) {
             // 去掉编辑
@@ -79,12 +83,9 @@ class DoctorManagementController extends AdminController
             'on'  => ['value' => 1, 'text' => '启用', 'color' => 'primary'],
             'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
         ];
-//        $grid->column('organization', __('所属机构'))->pluck('name')->label('info');
         $grid->column('org', __('所属机构'))->display(function (){
-//            dd($organization);
-//            dd($this->id);
             $org_id = DocterOrganization::where('docter_id',$this->id)->where('state',1)->pluck('organization_id')->toArray();
-            $name = Organization::whereIn('id',$org_id)->pluck('name')->toArray();
+            $name = Organization::whereIn('id',$org_id)->pluck('intro')->toArray();
             if (empty($name))
             {
                 return '无';
@@ -93,7 +94,7 @@ class DoctorManagementController extends AdminController
             {
                 return $name;
             }
-        })->label('info');
+        })->label('info')->width(300);
         $grid->column('serviceapply', __('开通服务'))->where('status',2)->pluck('service_type')->toArray()->display(function ($type){
             $type = array_unique($type);
             $type_arr = [];
@@ -119,7 +120,6 @@ class DoctorManagementController extends AdminController
             return $type_arr;
         })->label('info');
         $grid->column('label', __('标签'))->display(function ($label){
-//            dd($label);
             if($label==null)
             {
                 return '无';

+ 1 - 1
app/Admin/Controllers/UserManagement/DocterManagement/PhoneController.php

xqd
@@ -37,7 +37,7 @@ class PhoneController extends AdminController
         $grid->column('type', __('类型'))->using([1=>'电话咨询',2=>'图文咨询',3=>'门诊咨询',4=>'疫苗预约接种',5=>'儿保预约',6=>'服务包',7=>'充值']);
 
         $grid->column('base_price', __('基础价格'));
-        $grid->column('base_price', __('步进价格'));
+        $grid->column('step_price', __('步进价格'));
         $grid->column('am', __('上午服务时间'))->display(function (){
             $service_time = DocterTimes::where('docter_id',$this->docter_id)->where('id',$this->id)->value('service_time');
             $arr = json_decode($service_time);

+ 7 - 2
app/Admin/Controllers/UserManagement/DocterManagement/UserEvaluatesController.php

xqd
@@ -51,13 +51,18 @@ class UserEvaluatesController extends AdminController
             $filter->disableIdFilter();
             $filter->like('user.nickname','用户名字');
             $filter->like('docter.name','医生名字');
-            $filter->like('content','评价内容');
-            $filter->timestampBetween('audit_time', "审核时间")->datetime();
             $filter->equal('status','审核状态')->select([
                 1   => '待审核',
                 2    => '审核通过',
                 3    => '忽略',
             ]);
+            $filter->in('score','评分')->checkbox([
+                1    => 1,
+                2    => 2,
+                3    => 3,
+                4    => 4,
+                5    => 5,
+            ]);
         });
         $grid->model()->orderBy('id','desc');
         $grid->column('id', __('Id'));

+ 2 - 5
app/Admin/Controllers/VaccinesManagement/VaccinesController.php

xqd xqd
@@ -65,7 +65,7 @@ class VaccinesController extends AdminController
             });
             $filter->column(1/2, function ($filter) {
                $filter->like('name','疫苗名称');
-                $filter->equal('organizationvaccines.org_id','机构')->select(Organization::pluck('name','id'));
+                $filter->equal('org_id','机构')->select(Organization::pluck('name','id'));
             });
         });
         //按关键字查询
@@ -91,10 +91,7 @@ class VaccinesController extends AdminController
             $tools->append(new ImportAction());
         });
 
-        $grid->actions(function ($actions){
-            $actions->disableDelete();
-            $actions->disableEdit();
-        });
+        $grid->disableActions();
 
         return $grid;
     }

+ 1 - 1
app/Community/Actions/Nurse/Finished.php

xqd
@@ -12,7 +12,7 @@ class Finished extends RowAction
 
     public function handle(Model $model)
     {
-        $id = $this->row->order_id;
+        $id = $this->row->id;
         $res = Order::where('id',$id)->update(['order_status'=>Order::FINISHED]);
         if($res){
             return $this->response()->success('操作成功!')->refresh();

+ 11 - 7
app/Community/Actions/Nurse/OrderCance.php

xqd xqd
@@ -15,23 +15,27 @@ class OrderCance extends RowAction
 
     public function handle(Model $model)
     {
-        $id = $this->row->order_id;
+        $id = $this->row->id;
         $order = Order::where(['id'=>$id])->with('orderUser')->first();
         $sn = $order->order_sn;
-        if(empty($order->orderUser) || empty($order->orderUser->openid) ) return true;
-        $openid = $order->orderUser->openid;
+
 //        $openid = 'oYmUA5A1OIqtpA1XSrw35tbjtv1w';
         $time = $this->row->created_at;
         $price = ($this->row->total_amount / 100);
 
-        $pantient = $this->row->patients->name;
-        $organization = Organization::where(['id'=>$this->row->orders->organization_id])->value('name');
-        $paystatus = Order::getPayStatus()[$this->row->orders->payment_status];
+        $pantient = $this->row->orderPatient->name;
+        $organization = Organization::where(['id'=>$this->row->organization_id])->value('name');
+        $paystatus = Order::getPayStatus()[$this->row->payment_status];
 
         DB::beginTransaction();
         try {
             //退还余额
             $res = Order::orderCancel($id,'社区取消');
+            if(empty($order->orderUser) || empty($order->orderUser->openid) ) {
+                DB::commit();
+                return $this->response()->success('操作成功!')->refresh();
+            }
+            $openid = $order->orderUser->openid;
             $msg = [
                 $openid,$sn,'儿保预约',$price,$time,$pantient,$organization,'社区取消',$paystatus
             ];
@@ -39,7 +43,7 @@ class OrderCance extends RowAction
                 $openid,$sn,'社区取消','儿保预约',$paystatus
             ];
             //用户和医生都要发
-            $ret = admin_send_wechat_message(1,$msg,$miniMsg);
+//            $ret = admin_send_wechat_message(1,$msg,$miniMsg);
             DB::commit();
         } catch ( \Exception $e){
             dump($e->getMessage());

+ 1 - 1
app/Community/Actions/Nurse/Reserved.php

xqd
@@ -12,7 +12,7 @@ class Reserved extends RowAction
 
     public function handle(Model $model)
     {
-        $id = $this->row->orders->order_id;
+        $id = $this->row->order_id;
 
         $res = Order::where('id',$id)->update(['order_status'=>Order::ISING]);
 

+ 9 - 1
app/Community/Controllers/OrderController.php

xqd
@@ -47,7 +47,15 @@ class OrderController extends AdminController
         $grid->column('id', __('Id'));
         $grid->column('orderUser.nickname', __('预约用户'));
         $grid->column('orderPatient.appoint_start_time', __('预约时间'))->display(function ($w){
-            return date('Y-m-d H:i',$w).'~'.date('H:i',$this->orderPatient->appoint_end_time);
+            $end ='';
+            $start = '';
+            if(!empty($this->orderPatient) && $this->orderPatient->appoint_end_time){
+                $end = date('H:i',$this->orderPatient->appoint_end_time);
+            }
+            if(!empty($w)){
+                $start = date('Y-m-d H:i',$w);
+            }
+            return $start.'~'.$end;
         });
 //        $grid->column('orderPatient.appoint_end_time', __('预约结束时间'))->display(function ($w){
 //            if(empty($w)) return '';

+ 42 - 39
app/Community/Controllers/OrderNurseController.php

xqd xqd xqd xqd xqd
@@ -33,51 +33,54 @@ class OrderNurseController extends AdminController
      */
     protected function grid()
     {
-        $grid = new Grid(new OrderNurse());
+        $grid = new Grid(new Order());
         $grid->model()->orderByDesc('id');
 
         $user = Admin::user();
         $is_admin = Admin::user()->inRoles(['administrator','developer']);
 
+        $where = ['product_type'=>5];
         if(!$is_admin){
             $org_id = $user->org_id;
             $docter_id = $user->docter_id;
-
-            $grid->model()->whereHas('orders',function ($query) use ($org_id,$docter_id) {
-                if($docter_id){
-                    $where['docter_id'] = $docter_id;
-                 } else {
-                    $where['organization_id']=$org_id;
-                }
-                $query->where($where);
-            });
+            if($docter_id){
+                $where['docter_id'] = $docter_id;
+            } else {
+                $where['organization_id']=$org_id;
+            }
         }
+        $grid->model()->where($where);
 
-        $grid->column('orders.id', __('ID'));
-        $grid->column('orders.user_id', __('预约用户'))->display(function($w){
-            return User::where('id',$w)->value('nickname');
+        $grid->column('id', __('ID'));
+        $grid->column('orderUser.user_name', __('预约用户'))->display(function($w){
+            if(empty($w)) return '';
+            return $w;
         });
-        $grid->column('patients.appoint_start_time', __('预约时间'))->display(function ($w){
-            return date('Y-m-d H:i',$w).'~'.date('H:i',$this->patients->appoint_end_time);
+        $grid->column('orderPatient.appoint_start_time', __('预约时间'))->display(function ($w){
+            if(empty($w)) return '';
+            return date('Y-m-d H:i',$w).'~'.date('H:i',$w);
         });
 
-        $grid->column('patients.name', __('儿保患者'));
-        $grid->column('patients.phone', __('电话'))->display(function ($w){
-            if(empty($w)) return $this->patients->phone;
+        $grid->column('orderPatient.name', __('儿保患者'));
+        $grid->column('orderPatient.phoe', __('电话'))->display(function ($w){
+            if(empty($w)) {
+                if(empty($this->orderUser->phone)) return '';
+                return $this->orderUser->phone;
+            }
             return $w;
         });
-        $grid->column('patients.sex', __('患者性别'))->display(function ($w){
+        $grid->column('orderPatient.sex', __('患者性别'))->display(function ($w){
             return $w==1?'男':'女';
         });
-        $grid->column('patients.birthday', __('患者年龄'))->display(function ($w){
+        $grid->column('orderPatient.birthday', __('患者年龄'))->display(function ($w){
             return birthday_to_age($w);
         });
 //        $grid->column('orders.docter_id', __('排班医生'))->display(function ($w){
 //            return Docter::where('id',$w)->value('name');
 //        });
         $grid->column('nurse_name', __('项目名称'));
-        $grid->column('orders.order_status','订单状态')->using(Order::getStatus())->label([1=>'info',2=>'warring',3=>'info',4=>'success',5=>'info']);
-        $grid->column('orders.payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款'])->label('info');
+        $grid->column('order_status','订单状态')->using(Order::getStatus())->label([1=>'info',2=>'warring',3=>'info',4=>'success',5=>'info']);
+        $grid->column('payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款'])->label('info');
 
         //查询
         $grid->quickSearch(function ($model, $query) {
@@ -89,9 +92,9 @@ class OrderNurseController extends AdminController
         $grid->filter(function (Grid\Filter $filter){
             $filter->disableIdFilter();
             $filter->column(1/2, function ($filter) {
-                $filter->equal('orders.docter_id','排班医生')->select('/cdms/api/getDocter');
-                $filter->equal('orders.order_status','订单状态')->select(Order::$_order_status);
-                $filter->between('patients.appoint_start_time','预约时间')->datetime();
+//                $filter->equal('orders.docter_id','排班医生')->select('/cdms/api/getDocter');
+                $filter->equal('order_status','订单状态')->select(Order::$_order_status);
+                $filter->between('orderPatient.appoint_start_time','预约时间')->datetime();
             });
         });
 
@@ -99,7 +102,7 @@ class OrderNurseController extends AdminController
 //            if(!empty($actions->row->orders) && $actions->row->orders->order_status < 2){
 //                $actions->add(new Reserved());
 //            }
-            if(!empty($actions->row->orders) && ($actions->row->orders->order_status<= 3 || $actions->row->order_status == 7) ){
+            if($actions->row->order_status<= 3 || $actions->row->order_status == 7 ){
                 $actions->add(new OrderCance());
                 $actions->add(new Finished());
             }
@@ -123,14 +126,13 @@ class OrderNurseController extends AdminController
         $show = new Show(OrderNurse::findOrFail($id));
 
         $show->field('id', __('Id'));
-        $show->field('order_id', __('Order id'));
-        $show->field('order_patient_id', __('Order patient id'));
-        $show->field('nurse_id', __('Nurse id'));
-        $show->field('nurse_name', __('Nurse name'));
-        $show->field('nurse_price', __('Nurse price'));
-        $show->field('nurse_remark', __('Nurse remark'));
-        $show->field('created_at', __('Created at'));
-        $show->field('updated_at', __('Updated at'));
+        $show->field('orderPatient.name', __('患者用户'));
+        $show->field('orderUser.user_nam', __('患者名称'));
+        $show->field('orderNurse.nurse_name', __('儿保项目'));
+        $show->field('orderNurse.nurse_price', __('订单价格'));
+        $show->field('nurse_remark', __('儿保备注'));
+        $show->field('created_at', __('创建时间'));
+        $show->field('updated_at', __('更新时间'));
 
         return $show;
     }
@@ -142,12 +144,13 @@ class OrderNurseController extends AdminController
      */
     protected function form()
     {
-        $form = new Form(new OrderNurse());
+        $form = new Form(new Order());
 
-        $form->display('order_id', __(' 订单id'));
-        $form->display('patients.name', __('预约用户'));
-        $form->display('nurse_name', __('项目名称'));
-        $form->text('nurse_price', __('订单价格'));
+        $form->display('id', __(' 订单id'));
+        $form->display('orderUser.user_name', __('预约用户'));
+        $form->display('orderPatient.name', __('预约患者'));
+        $form->display('orderNurse.nurse_name', __('项目名称'));
+        $form->text('orderNurse.nurse_price', __('订单价格'));
         $form->textarea('nurse_remark', __('备注'))->rows(5);
 
         $form->setWidth(6);

+ 4 - 1
app/Community/Controllers/StatController.php

xqd
@@ -109,7 +109,10 @@ class StatController extends  Controller
 
         $data['have_num'] = Vaccine::where($where)->sum('stock'); //疫苗库存总数
         $data['less_num'] = Vaccine::where($where)->where(['stock'=>0])->count();//缺苗钟数
-        $ids = Order::where(['product_type'=>4])->where($where)->with('orderPatient','appoint_start_time',strtotime('today'))->pluck('id')->toArray();//订单id
+        $ids = Order::where(['product_type'=>4])->where($where)->whereHas('orderPatient',function ($query){
+           $query->where('appoint_start_time',strtotime('today'));//订单id
+        })->pluck('id')->toArray();
+
         $data['yesterday']= OrderVaccine::whereIn('order_id',$ids)->count(); //疫苗订单总数
 
         return $data;

+ 30 - 15
app/Console/Commands/ImportDocter.php

xqd xqd xqd
@@ -6,6 +6,7 @@ use App\Imports\chatOrder;
 use App\Imports\Docter\DocterInfo;
 use App\Imports\Docter\DocterOrganizationInfo;
 use App\Imports\Docter\OrganizationInfo;
+use App\Imports\Docter\OrganizationOffice;
 use App\Models\Organization;
 use Illuminate\Console\Command;
 use Maatwebsite\Excel\Facades\Excel;
@@ -55,8 +56,11 @@ class ImportDocter extends Command
         if($type == 'organization'){
             $this->makeOrganization($file_path);
         }
-        if($type == 'docter_organization'){
-            $this->makeDocterOrganization($file_path);
+//        if($type == 'docter_organization'){
+//            $this->makeDocterOrganization($file_path);
+//        }
+        if($type == 'organization_office'){
+            $this->makeOrganizationOffice($file_path);
         }
     }
 
@@ -73,31 +77,42 @@ class ImportDocter extends Command
     }
     public function imports($filePath)
     {
-        $filePath = './public/import/' . $filePath . '.xls';
-
+        $filePath = './public/import/' . $filePath . '.xlsx';
         Excel::import(new DocterInfo(), $filePath);
     }
-    //医生机构模块
-    public function makeDocterOrganization($file_path)
+//    //医生机构模块
+//    public function makeDocterOrganization($file_path)
+//    {
+//        $this->importsDocterOrganization($file_path);
+//    }
+//    public function importsDocterOrganization($filePath)
+//    {
+//        $filePath = './public/import/' . $filePath . '.xlsx';
+//
+//        Excel::import(new DocterOrganizationInfo(), $filePath);
+//    }
+
+    //机构模块
+    public function makeOrganization($file_path)
     {
-        $this->importsDocterOrganization($file_path);
+        $this->importsOrganization($file_path);
     }
-    public function importsDocterOrganization($filePath)
+    public function importsOrganization($filePath)
     {
-        $filePath = './public/import/' . $filePath . '.xls';
+        $filePath = './public/import/' . $filePath . '.xlsx';
 
-        Excel::import(new DocterOrganizationInfo(), $filePath);
+        Excel::import(new OrganizationInfo(), $filePath);
     }
 
-    //机构模块
-    public function makeOrganization($file_path)
+    //机构科室模块
+    public function makeOrganizationOffice($file_path)
     {
-        $this->importsOrganization($file_path);
+        $this->importsOrganizationOffice($file_path);
     }
-    public function importsOrganization($filePath)
+    public function importsOrganizationOffice($filePath)
     {
         $filePath = './public/import/' . $filePath . '.xls';
 
-        Excel::import(new OrganizationInfo(), $filePath);
+        Excel::import(new OrganizationOffice(), $filePath);
     }
 }

+ 63 - 7
app/Console/Commands/ImportOrder.php

xqd xqd xqd xqd xqd
@@ -2,7 +2,10 @@
 
 namespace App\Console\Commands;
 
-use App\Imports\chatOrder;
+use App\Imports\Order\chatOrder;
+use App\Imports\Order\nurseOrder;
+use App\Imports\Order\phoneOrder;
+use App\Imports\Order\serviceOrder;
 use App\Imports\Order\vaccineOrder;
 use Illuminate\Console\Command;
 use Maatwebsite\Excel\Facades\Excel;
@@ -20,7 +23,7 @@ class ImportOrder extends Command
      *
      * @var string
      */
-    protected $description = '订单数据导入';
+    protected $description = '订单数据导入 importOrder {订单类型} {导入xls文件名}';
 
     /**
      * Create a new command instance.
@@ -47,14 +50,29 @@ class ImportOrder extends Command
             $this->output->error('请输入完整参数');
         }
         //图文咨询订单导入
-        if($type == 'chat'){
-            $this->makeChat($file_path);
-        }
-        if($type == 'vaccine'){
-            $this->makeVaccine($file_path);
+        switch ($type){
+            case 'chat';
+                $this->makeChat($file_path);
+            break;
+            case 'phone';
+                $this->makePhone($file_path);
+            break;
+            case 'vaccine';
+                $this->makeVaccine($file_path);
+            break;
+            case 'nurse';
+                $this->makeNurse($file_path);
+            break;
+            case 'service';
+                $this->makeService($file_path);
+            break;
+            default;
+                $this->output->error('请输入正确参数');
+            break;
         }
     }
 
+    //图文订单
     public function makeChat($file_path)
     {
         $filePath = './public/import/'.$file_path.'.xls';
@@ -66,6 +84,19 @@ class ImportOrder extends Command
         $this->output->success('Import successful');
     }
 
+    //电话订单
+    public function makePhone($file_path)
+    {
+        $filePath = './public/import/'.$file_path.'.xls';
+        if(!file_exists($filePath)){
+            $this->output->error('文件不存在');
+            exit;
+        }
+        Excel::import(new phoneOrder(), $filePath);
+        $this->output->success('Import successful');
+    }
+
+    //疫苗订单
     public function makeVaccine($file_path)
     {
         $filePath = './public/import/'.$file_path.'.xls';
@@ -75,6 +106,31 @@ class ImportOrder extends Command
         }
         Excel::import(new vaccineOrder(), $filePath);
         $this->output->success('Import successful');
+    }
 
+    //儿保订单
+    public function makeNurse($file_path)
+    {
+        $filePath = './public/import/'.$file_path.'.xls';
+        if(!file_exists($filePath)){
+            $this->output->error('文件不存在');
+            exit;
+        }
+        Excel::import(new nurseOrder(), $filePath);
+        $this->output->success('Import successful');
+    }
+
+
+
+    //服务包订单
+    public function makeService($file_path)
+    {
+        $filePath = './public/import/'.$file_path.'.xls';
+        if(!file_exists($filePath)){
+            $this->output->error('文件不存在');
+            exit;
+        }
+        Excel::import(new serviceOrder(), $filePath);
+        $this->output->success('Import successful');
     }
 }

+ 81 - 0
app/Console/Commands/ImportUser.php

xqd
@@ -0,0 +1,81 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Imports\chatOrder;
+use App\Imports\Docter\DocterInfo;
+use App\Imports\Docter\DocterOrganizationInfo;
+use App\Imports\Docter\OrganizationInfo;
+use App\Imports\User\PatientsInfo;
+use App\Imports\User\UserInfo;
+use App\Models\Organization;
+use Illuminate\Console\Command;
+use Maatwebsite\Excel\Facades\Excel;
+class ImportUser extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'import:importUser {type} {filepath}';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '用户数据导入';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $type = $this->argument('type');
+        $file_path = $this->argument('filepath');
+        //路径相对于项目根目录即 /public
+        if(empty($type) || empty($file_path)){
+            dd('请输入完整参数');
+        }
+        //用户信息导入
+        if($type == 'user'){
+            $this->makeUser($file_path);
+        }
+        if($type == 'patients'){
+            $this->makePatients($file_path);
+        }
+    }
+    //导入用户
+    public function makeUser($file_path)
+    {
+        $this->importsUser($file_path);
+    }
+    public function importsUser($filePath)
+    {
+        $filePath = './public/import/' . $filePath . '.xlsx';
+        Excel::import(new UserInfo(), $filePath);
+    }
+    //导入患者
+    public function makePatients($file_path)
+    {
+        $this->importsPatients($file_path);
+    }
+    public function importsPatients($filePath)
+    {
+        $filePath = './public/import/' . $filePath . '.xlsx';
+        Excel::import(new PatientsInfo(), $filePath);
+    }
+}

+ 14 - 13
app/Imports/Docter/DocterInfo.php

xqd xqd
@@ -19,17 +19,17 @@ class DocterInfo implements ToModel
         if (($row[0] == "姓名")) {
             return null;
         }
-        //职称
-        $qualification_id = 0;
-        if ($row[2])
-        {
-            $qualification_id = Qualification::firstOrCreate([
-                'name' => $row[2]
-            ],[
-                'name' => $row[2],
-                'status' =>1
-            ]);
-        }
+//        //职称
+//        $qualification_id = 0;
+//        if ($row[2])
+//        {
+//            $qualification_id = Qualification::firstOrCreate([
+//                'name' => $row[2]
+//            ],[
+//                'name' => $row[2],
+//                'status' =>1
+//            ]);
+//        }
         if ($row[5] == null)
         {
             $avatar = '';
@@ -42,11 +42,12 @@ class DocterInfo implements ToModel
             //
             'name' => $row[0],
             'phone' => $row[1],
-            'qualification_id' => $qualification_id,
+//            'qualification_id' => $qualification_id,
             'card_photo' => $row[3],
             'practice' => $row[4],
             'avatar' => $avatar,
-            'is_then' => 1
+            'is_then' => 1,
+            'type' => 0
         ]);
     }
 }

+ 4 - 3
app/Imports/Docter/OrganizationInfo.php

xqd xqd
@@ -27,14 +27,14 @@ class OrganizationInfo implements ToModel
             $address = $row[5];
         }
         //经度默认值
-        if ($row[7] == null)
+        if ($row[6] == null)
         {
             $latitude = 0;
         }else{
-            $latitude = $row[7];
+            $latitude = $row[6];
         }
         //纬度默认值
-        if ($row[8] == null)
+        if ($row[7] == null)
         {
             $longitude = 0;
         }else{
@@ -71,6 +71,7 @@ class OrganizationInfo implements ToModel
         }
         return new Organization([
             //
+            'type' => 1,
             'name' => $row[0],
             'level' => $level,
             'introduce' => $row[2],

+ 59 - 0
app/Imports/Docter/OrganizationOffice.php

xqd
@@ -0,0 +1,59 @@
+<?php
+
+namespace App\Imports\Docter;
+
+use App\Models\Office;
+use App\Models\Organization;
+use App\Models\Qualification;
+use Maatwebsite\Excel\Concerns\ToModel;
+use phpDocumentor\Reflection\Types\Nullable;
+
+class OrganizationOffice implements ToModel
+{
+    /**
+    * @param array $row
+    *
+    * @return \Illuminate\Database\Eloquent\Model|null
+    */
+    public function model(array $row)
+    {
+        //跳过首行
+        if (($row[0] == "姓名")) {
+            return null;
+        }
+        $org_id = null;
+        $office_id = null;
+        //所属医院
+        if ($row[3])
+        {
+            $org_id = Organization::firstOrCreate([
+                'name' => $row[3]
+            ],[
+                'name' => $row[3],
+                'type' => 1,
+                'level' => 0,
+                'introduce' => '',
+                'phone' => '',
+                'address' => '',
+                'latitude' => 0,
+                'longitude' => 0,
+            ]);
+        }
+        //所属科室
+        if ($row[4]&&$org_id)
+        {
+            $office_id = Office::firstOrCreate([
+                'org_id' => $org_id['id'],
+                'name' => $row[4]
+            ]);
+        }
+        if ($row[5]==null)
+        {
+            $row[5] ='其它';
+        }else{
+            Qualification::firstOrCreate([
+                'name' => $row[5]
+            ]);
+        }
+    }
+}

+ 89 - 59
app/Imports/Order/chatOrder.php

xqd xqd xqd
@@ -9,25 +9,28 @@ use App\Models\OrderPatient;
 use App\Models\Organization;
 use App\Models\Patient;
 use App\User;
+use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Log;
-use Maatwebsite\Excel\Concerns\ToModel;
+use Maatwebsite\Excel\Concerns\ToCollection;
 use Maatwebsite\Excel\Concerns\WithHeadingRow;
 use Maatwebsite\Excel\Concerns\WithBatchInserts;
 use Maatwebsite\Excel\Concerns\WithChunkReading;
 use Maatwebsite\Excel\Concerns\WithProgressBar;
 
-class chatOrder implements ToModel,WithBatchInserts,WithChunkReading
+class chatOrder implements ToCollection,WithBatchInserts,WithChunkReading
 {
     /**
     * @param array $row
     *
     * @return \Illuminate\Database\Eloquent\Model|null
     */
-    public function model(array $row)
+    public function collection(Collection $collection)
     {
 
+        foreach ($collection as $row) {
+            if ($row[0] == '订单编号') continue;
+//            dd($row);
 
-        if($row[0] == '订单编号') return null;
 //        [
 //            0 => "im20210118173813522",
 //            1 => "云南运营主体",
@@ -50,60 +53,87 @@ class chatOrder implements ToModel,WithBatchInserts,WithChunkReading
 //            18 => "已付款",
 //            19 => "2021-01-18 17:38:13",
 //        ];
-        //检查是否有该订单
-        $isHave = $this->getValue(new Order(),['order_sn'=>$row[0]],'id');
-        if($isHave) return null;
-
-        $patient_id = $this->getValue(new Patient(),['name'=>$row[2]],'id');
-        $user_id = $this->getValue(new User(),['phone'=>$row[3]],'id');
-
-        //如果没有用户不导入该订单
-        if(empty($user_id)){
-            Log::info('订单没有用户信息,订单编号: '.$row[0].PHP_EOL);
-            return null;
+            //检查是否有该订单
+            $isHave = $this->getValue(new Order(), ['order_sn' => $row[0]], 'id');
+            if ($isHave) return null;
+
+            $user_id = $this->getValue(new User(), ['phone' => $row[3]], 'id');
+            if (empty($user_id)) {
+                echo $row[3] . '用户缺失' . PHP_EOL;
+                return null;
+            }
+            //患者信息
+            $patientInfo = Patient::where(['name' => $row[4]])->first();
+            if (empty($patientInfo)) {
+                echo $row[4] . '患者缺失' . PHP_EOL;
+                continue;
+            }
+            $org_id = $this->getValue(new Organization(), ['name' => $row[6]], 'id');
+            if (empty($org_id)) {
+                echo $row[6] . '机构缺失' . PHP_EOL;
+                continue;
+            }
+
+            //如果没有用户不导入该订单
+            if (empty($user_id)) {
+                Log::info('订单没有用户信息,订单编号: ' . $row[0] . PHP_EOL);
+                continue;
+            }
+            //  1 => "未支付"
+            //  2 => "待支付"
+            //  3 => "进行中"
+            //  4 => "已完成"
+            //  5 => "已取消"
+            //  6 => "已超时"
+            //  7 => "已预约"
+            //订单状态
+            $status = Order::getStatus();
+            //订单状态
+            $paystatus = Order::getPayStatus();
+            $pay_status = array_search($row[18], $paystatus);
+            $order_status = array_search($row[9], $status);
+
+
+            $docter_id = $this->getValue(new Docter(), ['name' => $row[4]], 'id');
+            $org_id = $this->getValue(new Organization(), ['name' => $row[6]], 'id');
+            $evaluate = $row[10] == '已评价' ? 1 : 0;
+            $pay_types = [1 => '微信支付', 2 => '余额支付', 3 => '服务包支付'];
+            //支付方式
+            $payType = array_search($row[16], $pay_types) + 1;
+            if ($payType == 1) $payType = 2;
+
+            $orderInfo = [
+                'order_sn' => $row[0],
+                'patient_id' => $patientInfo->id,
+                'user_id' => $user_id,
+                'docter_id' => $docter_id,
+                'order_status' => $order_status,
+                'organization_id' => $org_id,
+                'is_evaluate' => $evaluate,
+                'is_discount' => $row[11],
+                'total_amount' => $row[12] * 100,
+                'discount_amount' => $row[13] * 100,
+                'payment_amount' => $row[15] * 100,
+                'payment_type' => $payType,
+                'payment_status' => $pay_status,
+                'product_type' => 2,
+                'created_at' => $row[19],
+            ];
+            $order = Order::create($orderInfo);
+            $orderId = $order['id'];
+
+            $orderPatient = [
+                'patient_id' => $patientInfo->id,
+                'name' => $row[0],
+                'order_id' => $orderId,
+                'patient_id' => $patientInfo->id,
+                'address' => $patientInfo->address,
+                'sex' => $patientInfo->sex,
+                'organization_id' => $org_id,
+            ];
+            OrderPatient::insert($orderPatient);
         }
-//  1 => "未支付"
-//  2 => "待支付"
-//  3 => "进行中"
-//  4 => "已完成"
-//  5 => "已取消"
-//  6 => "已超时"
-//  7 => "已预约"
-        //订单状态
-        $status = Order::getStatus();
-        //订单状态
-        $paystatus = Order::getPayStatus();
-        $pay_status = array_search($row[18],$paystatus);
-        $order_status = array_search($row[9],$status);
-
-
-        $docter_id = $this->getValue(new Docter(),['name'=>$row[4]],'id');
-        $org_id = $this->getValue(new Organization(),['name'=>$row[6]],'id');
-        $evaluate = $row[10] == '已评价'? 1 : 0;
-        $pay_types = [1=>'微信支付',2=>'余额支付',3=>'服务包支付'];
-        //支付方式
-        $payType = array_search($row[16],$pay_types) + 1;
-        if($payType == 1) $payType = 2;
-
-        $orderInfo = [
-            'order_sn'=>$row[0],
-            'patient_id'=>$patient_id,
-            'user_id'=>$user_id,
-            'docter_id'=>$docter_id,
-            'order_status'=>$order_status,
-            'organization_id'=>$org_id,
-            'is_evaluate'=>$evaluate,
-            'is_discount'=>$row[11],
-            'total_amount'=>$row[12]*100,
-            'discount_amount'=>$row[13]*100,
-            'payment_amount'=>$row[15]*100,
-            'payment_type'=>$payType,
-            'payment_status'=>$pay_status,
-            'product_type'=>1,
-            'created_at'=>$row[19],
-        ];
-        //处理逻辑
-        return new Order($orderInfo);
+        return null;
     }
 
     public function startRow(): int
@@ -113,12 +143,12 @@ class chatOrder implements ToModel,WithBatchInserts,WithChunkReading
 
     public function batchSize(): int
     {
-        return 20;
+        return 1000;
     }
 
     public function chunkSize(): int
     {
-        return 20;
+        return 1000;
     }
 
     public function getValue($model,$where,$field)

+ 92 - 14
app/Imports/Order/nurseSheet.php

xqd xqd
@@ -3,11 +3,16 @@
 namespace App\Imports\Order;
 
 use App\Models\Order;
+use App\Models\OrderPatient;
 use App\Models\Organization;
+use App\Models\Patient;
 use App\Models\Vaccine;
 use App\User;
 use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\Log;
 use Maatwebsite\Excel\Concerns\ToCollection;
+use SebastianBergmann\CodeCoverage\Report\PHP;
 
 class nurseSheet implements ToCollection
 {
@@ -17,34 +22,107 @@ class nurseSheet implements ToCollection
     public function collection(Collection $collection)
     {
         // todo 缺少患者信息导致患者信息无法确定,支付方式,无订单编号,无法去重,没机构,没用户如何处理
-        $i = 1;
-        $order_info = [];
         foreach ($collection as $row) {
+
             if($row[0] == '就诊人姓名') continue;
+
+//            dd($row);
+            //用户信息
             $user_id = $this->getValue(new User(),['phone'=>$row[1]],'id');
-            $vaccine_id = $this->getValue(new Vaccine(),['name'=>$row[3]],'id');
             if(empty($user_id)){
-                Log::info('订单没有用户信息: '.$row[0].' 电话:'.$row[1].' 时间:'.$row[4].PHP_EOL);
+                Log::info('订单没有用户信息: '.$row[0].' 电话:'.$row[1].' 时间:'.$row[3].PHP_EOL);
+                continue;
+            }
+
+            //患者信息
+            $patientInfo = Patient::where(['name'=>$row[0]])->first();
+            if(empty($patientInfo)){
+                echo $row[0].'患者缺失'.PHP_EOL;
+                continue;
+            }
+
+            //下单时间
+            $time = explode(' ',$row[3]);
+            $appion_time = explode('-',$time[1]);
+            $start =strtotime($time[0].$appion_time[0]);
+            //预约时间大于今天
+            ($start- 86400) > strtotime('today') ?$createTimer = strtotime('-1 days') : $createTimer = ($start- 86400) > strtotime('today');
+            $created_at = date('Y-m-d H:i:s',$createTimer);
+            $end = strtotime($time[0].$appion_time[1]);
+
+            $org_id = $this->getValue(new Organization(),['name'=>$row[2]],'id');
+            if(empty($org_id)){
+                $org_id = 0;
+                echo $row[2].'机构缺失'.PHP_EOL;
                 continue;
             }
-            $i ++ ;
-            $status = Order::getStatus();
+
+
+//            $status = Order::getStatus();
             //订单状态
-            $order_status = array_search($row[5],$status);
-            $org_id = $this->getValue(new Organization(),['name'=>$row[6]],'id');
-            if(empty($org_id)) $org_id = 0;
-            $order_sn = build_sn($i);
+            $status = [2=>'待就诊',4=>'已完成',5=>'用户取消',6=>'已过期',7=>'机构取消'];
+            //状态监测
+//            $cacheStatus = Cache::get('nurse_status');
+//            if(empty($cacheStatus)){
+//                $cacheStatus[0] = 'begin';
+//                Cache::set('nurse_status',$cacheStatus);
+//            } else {
+//                dump($cacheStatus);
+//            }
+//            if(!in_array($row[4],$cacheStatus)){
+//                 $cacheStatus[] = $row[4];
+//                Cache::set('nurse_status',$cacheStatus);
+//            }
+//            continue;
+
+            $order_status = array_search($row[4],$status);
+            $notes = '';
+            if($order_status == 5){
+                $notes = '用户取消';
+            }
+            if($order_status == 6){
+                $order_status = 5;
+                $notes = '机构取消';
+            }
+            if(!in_array($row[4],$status)){
+                echo $row[4].PHP_EOL;
+
+            }
+
             //todo 写入计免订单表,订单患者表
-            $order_info[] = [
-                'order_sn'=>$order_sn,
+            $orderInfo= [
                 'user_id'=>$user_id,
                 'docter_id'=>0,
                 'order_status'=>$order_status,
                 'organization_id'=>$org_id,
-                'product_type'=>4,
+                'product_type'=>5,
+                'patient_id'=>$patientInfo->id,
+                'order_notes'=>$notes,
+                'created_at'=>$created_at,
             ];
+
+            $order = Order::create($orderInfo);
+            $orderId = $order['id'];
+            $order_sn = build_sn($orderId);
+            Order::where('id', $orderId)->update(['order_sn' => $order_sn]);
+
+            //没有患者名称不存数据
+            if(empty($patientInfo)) continue;
+
+            $orderPatient = [
+                'name'=>$row[0],
+                'order_id'=>$orderId,
+                'patient_id'=>$patientInfo->id,
+                'address'=>$patientInfo->address,
+                'sex'=>$patientInfo->sex,
+                'appoint_start_time'=>$start,
+                'appoint_end_time'=>$end,
+                'organization_id'=>$org_id,
+            ];
+
+            OrderPatient::insertGetId($orderPatient);
         }
-        Order::insert($order_info);
+        return null;
     }
 
     public function getValue($model,$where,$field)

+ 128 - 0
app/Imports/Order/phoneOrder.php

xqd
@@ -0,0 +1,128 @@
+<?php
+
+namespace App\Imports\Order;
+
+use App\Models\Docter;
+use App\Models\Order;
+use App\Models\OrderPatient;
+use App\Models\Organization;
+use App\Models\Patient;
+use App\User;
+use Illuminate\Support\Collection;
+use Maatwebsite\Excel\Concerns\ToCollection;
+
+class phoneOrder implements ToCollection
+{
+    /**
+    * @param Collection $collection
+    */
+    public function collection(Collection $collection)
+    {
+        foreach ($collection as $row){
+            if ($row[0] == '订单编号') continue;
+
+//        [
+//            0 => "MNC20210131110722347"
+//    1 => "云南运营主体"
+//    2 => "王洛染"
+//    3 => "18669008017"
+//    4 => "姚正"
+//    5 => "昆明儿科联盟"
+//    6 => "云南省昆明市昆明市西山区前卫佳湖社区卫生服务站"
+//    7 => "全科医学科"
+//    8 => "否"
+//    9 => "已完成"
+//    10 => "已评价"
+//    11 => "否"
+//    12 => "19.99"
+//    13 => "0.00"
+//    14 => "19.99"
+//    15 => "19.99"
+//    16 => "微信支付"
+//    17 => "自费"
+//    18 => "已付款"
+//    19 => "2021-01-31 11:07:23"
+
+//        ];
+            //检查是否有该订单
+            $isHave = $this->getValue(new Order(), ['order_sn' => $row[0]], 'id');
+            if ($isHave) return null;
+
+            $user_id = $this->getValue(new User(), ['phone' => $row[3]], 'id');
+            if (empty($user_id)) {
+                echo $row[3] . '用户缺失' . PHP_EOL;
+                return null;
+            }
+            //患者信息
+            $patientInfo = Patient::where(['name' => $row[2]])->first();
+            if (empty($patientInfo)) {
+                echo $row[2] . '患者缺失' . PHP_EOL;
+                continue;
+            }
+            $org_name = substr($row[6],18);
+            $org_id = $this->getValue(new Organization(), ['name' => $org_name], 'id');
+            if (empty($org_id)) {
+                echo $row[6] . '机构缺失' . PHP_EOL;
+                continue;
+            }
+
+            //如果没有用户不导入该订单
+            if (empty($user_id)) {
+                Log::info('订单没有用户信息,订单编号: ' . $row[0] . PHP_EOL);
+                continue;
+            }
+
+            //订单状态
+            $status = Order::getStatus();
+            //订单状态
+            $paystatus = Order::getPayStatus();
+            $pay_status = array_search($row[18], $paystatus);
+            $order_status = array_search($row[9], $status);
+
+
+            $docter_id = $this->getValue(new Docter(), ['name' => $row[4]], 'id');
+            $evaluate = $row[10] == '已评价' ? 1 : 0;
+            $pay_types = [1 => '微信支付', 2 => '余额支付', 3 => '服务包支付'];
+            //支付方式
+            $payType = array_search($row[16], $pay_types) + 1;
+            if ($payType == 1) $payType = 2;
+
+            $orderInfo = [
+                'order_sn' => $row[0],
+                'patient_id' => $patientInfo->id,
+                'user_id' => $user_id,
+                'docter_id' => $docter_id,
+                'order_status' => $order_status,
+                'organization_id' => $org_id,
+                'is_evaluate' => $evaluate,
+                'is_discount' => $row[11],
+                'total_amount' => intval($row[12]) * 100,
+                'discount_amount' => intval($row[13]) * 100,
+                'payment_amount' => intval($row[15]) * 100,
+                'payment_type' => $payType,
+                'payment_status' => $pay_status,
+                'product_type' => 1,
+                'created_at' => $row[19],
+            ];
+            $order = Order::create($orderInfo);
+            $orderId = $order['id'];
+
+            $orderPatient = [
+                'patient_id' => $patientInfo->id,
+                'name' => $row[0],
+                'order_id' => $orderId,
+                'patient_id' => $patientInfo->id,
+                'address' => $patientInfo->address,
+                'sex' => $patientInfo->sex,
+                'organization_id' => $org_id,
+            ];
+            OrderPatient::insert($orderPatient);
+        }
+    }
+
+    public function getValue($model,$where,$field)
+    {
+        return $model->where($where)->value($field);
+    }
+
+}

+ 95 - 0
app/Imports/Order/serviceOrder.php

xqd
@@ -0,0 +1,95 @@
+<?php
+
+namespace App\Imports\Order;
+
+use App\Admin\Actions\backstage\User\service;
+use App\Models\Order;
+use App\Models\OrderPack;
+use App\Models\ServicePack;
+use App\Models\User;
+use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\Log;
+use Maatwebsite\Excel\Concerns\ToCollection;
+
+class serviceOrder implements ToCollection
+{
+    /**
+    * @param Collection $collection
+    */
+    public function collection(Collection $collection)
+    {
+//        0 => "P20200605203723816"
+//        1 => "云南超级宝妈健康管理服务包"
+//        2 => "0.01"
+//        3 => "0.00"
+//        4 => "0.01"
+//        5 => "18487339976"
+//        6 => "已完成"
+//        7 => "2020-06-05 20:37:23"
+
+        foreach ($collection as $row){
+            if($row[0] == '订单编号') continue;
+
+//            dd($row);
+            //用户信息
+            $user_id = $this->getValue(new User(),['phone'=>$row[5]],'id');
+            $servicePack = servicePack::where(['name'=>$row[1]])->first();
+
+            if(empty($user_id)){
+                echo $row[5].'患者缺失'.PHP_EOL;
+                Log::info('订单没有用户信息: '.$row[0].' 电话:'.$row[1].' 时间:'.$row[3].PHP_EOL);
+                continue;
+            }
+            if(empty($servicePack)){
+                echo $row[1].'服务包缺失'.PHP_EOL;
+                continue;
+            }
+            $status = Order::getStatus();
+            //是否用优惠券
+//            $row[3] >0 ? $is_discont = 1 : $is_discont=0;
+            //订单状态
+            $order_status = array_search($row[6],$status);
+            $orderInfo = [
+                'user_id'=>$user_id,
+                'order_status'=>$order_status,
+                'product_type'=>6,
+                'created_at'=>$row[7],
+//                'is_discount'=>$is_discont,
+                'total_amount'=>intval($row[2])*100,
+                'discount_amount'=>intval($row[3])*100,
+                'payment_amount'=>intval($row[4])*100,
+            ];
+            $order = Order::create($orderInfo);
+            $orderId = $order['id'];
+            $order_sn = build_sn($orderId);
+            Order::where('id', $orderId)->update(['order_sn' => $order_sn]);
+
+            $serviceInfo = [
+                'order_id'=>$orderId,
+                'service_pack_id'=>$servicePack->id,
+                'pack_name'=>$row[2],
+                'team_id'=>json_encode($servicePack->team_id),
+                'pack_intro'=>$servicePack->intro,
+                'appoint_num'=>$servicePack->appoint_num,
+                'chat_num'=>$servicePack->chat_num,
+                'phone_minutes'=>$servicePack->id,
+                'team_id'=>json_encode($servicePack->team_id),
+                'vaccine_limit_amount'=>$servicePack->vaccine_limit_amount,
+                'nurses_limit_amount'=>$servicePack->nurses_limit_amount,
+                'effective_days'=>$servicePack->effective_days,
+                'relationship_type'=>1,
+                'start_time'=>time(),
+                'end_time'=>(time() + 86400 * 3650),
+            ];
+
+            OrderPack::insert($serviceInfo);
+        }
+
+        return null;
+    }
+
+    public function getValue($model,$where,$field)
+    {
+        return $model->where($where)->value($field);
+    }
+}

+ 16 - 0
app/Imports/Order/vaccineOrder.php

xqd
@@ -12,7 +12,23 @@ class vaccineOrder implements WithMultipleSheets,WithBatchInserts,WithChunkReadi
 {
     public function sheets(): array
     {
+        //16页
         return [
+            new vaccineSheet(),
+            new vaccineSheet(),
+            new vaccineSheet(),
+            new vaccineSheet(),
+            new vaccineSheet(),
+            new vaccineSheet(),
+            new vaccineSheet(),
+            new vaccineSheet(),
+            new vaccineSheet(),
+            new vaccineSheet(),
+            new vaccineSheet(),
+            new vaccineSheet(),
+            new vaccineSheet(),
+            new vaccineSheet(),
+            new vaccineSheet(),
             new vaccineSheet()
         ];
     }

+ 70 - 8
app/Imports/Order/vaccineSheet.php

xqd xqd
@@ -4,7 +4,10 @@ namespace App\Imports\Order;
 
 use App\Models\Docter;
 use App\Models\Order;
+use App\Models\OrderPatient;
+use App\Models\OrderVaccine;
 use App\Models\Organization;
+use App\Models\Patient;
 use App\Models\Vaccine;
 use App\User;
 use Illuminate\Support\Collection;
@@ -20,34 +23,93 @@ class vaccineSheet implements ToCollection
     {
         // todo 缺少患者信息导致患者信息无法确定,支付方式,无订单编号,无法去重,没机构,没用户如何处理
         $i = 1;
-        $order_info = [];
         foreach ($collection as $row) {
             if($row[0] == '就诊人姓名') continue;
             $user_id = $this->getValue(new User(),['phone'=>$row[1]],'id');
+            if(empty($user_id)){
+                echo $row[1].'用户缺失'.PHP_EOL;
+                continue;
+            }
+
+            $org_id = $this->getValue(new Organization(),['name'=>$row[2]],'id');
+            if(empty($org_id)){
+                echo $row[2].'机构缺失'.PHP_EOL;
+                //todo 没有机构直接跳过
+                continue;
+                $org_id = 0;
+            }
+
             $vaccine_id = $this->getValue(new Vaccine(),['name'=>$row[3]],'id');
+            //疫苗为空直接创建疫苗
+            if(empty($vaccine_id)){
+                $vaccine = ['name'=>$row[3],'org_id'=>$org_id,'type'=>1,'states'=>1];
+                $vaccine_id = Vaccine::insertGetId($vaccine);
+            }
+
+            //患者信息
+            $patientInfo = Patient::where(['name'=>$row[0]])->first();
+            if(empty($patientInfo)){
+                echo $row[0].'患者缺失'.PHP_EOL;
+                continue;
+            }
+
             if(empty($user_id)){
                 Log::info('订单没有用户信息: '.$row[0].' 电话:'.$row[1].' 时间:'.$row[4].PHP_EOL);
                continue;
             }
-            $i ++ ;
+
             $status = Order::getStatus();
             //订单状态
             $order_status = array_search($row[5],$status);
-            $org_id = $this->getValue(new Organization(),['name'=>$row[6]],'id');
             if(empty($org_id)) $org_id = 0;
-            $order_sn = build_sn($i);
+//            $order_sn = build_sn($i);
             //todo 写入计免订单表,订单患者表
-            $order_info[] = [
-                'order_sn'=>$order_sn,
+            $time = explode(' ',$row[4]);
+            $appion_time = explode('-',$time[1]);
+            $start =strtotime($time[0].$appion_time[0]);
+            //预约时间大于今天
+            ($start- 86400) > strtotime('today') ?$createTimer = strtotime('-1 days') : $createTimer = ($start- 86400) > strtotime('today');
+            $created_at = date('Y-m-d H:i:s',$createTimer);
+            $end = strtotime($time[0].$appion_time[1]);
+            $orderInfo = [
                 'user_id'=>$user_id,
+                'patient_id'=>$patientInfo->id,
                 'docter_id'=>0,
                 'order_status'=>$order_status,
                 'organization_id'=>$org_id,
                 'product_type'=>4,
+                'created_at'=>$created_at
+            ];
+            $order = Order::create($orderInfo);
+            $orderId = $order['id'];
+            $order_sn = build_sn($order['id']);
+            Order::where('id', $order['id'])->update(['order_sn' => $order_sn]);
+            //没有患者名称不存数据
+            if(empty($patientInfo)) continue;
+
+            $orderPatient = [
+                'patient_id'=>$patientInfo->id,
+                'name'=>$row[0],
+                'order_id'=>$orderId,
+                'patient_id'=>$patientInfo->id,
+                'address'=>$patientInfo->address,
+                'sex'=>$patientInfo->sex,
+                'appoint_start_time'=>$start,
+                'appoint_end_time'=>$end,
+                'organization_id'=>$org_id,
+            ];
+
+
+            $orderPid = OrderPatient::insertGetId($orderPatient);
+
+            $vaccineOrder = [
+                'vaccine_id'=>$vaccine_id,
+                'order_id'=>$orderId,
+                'order_patient_id'=>$orderPid,
+                'vaccine_name'=>$row[3],
             ];
+            return OrderVaccine::insert($vaccineOrder);
         }
-        return null;
-        Order::insert($order_info);
     }
 
     public function getValue($model,$where,$field)

+ 35 - 0
app/Imports/User/PatientsInfo.php

xqd
@@ -0,0 +1,35 @@
+<?php
+
+namespace App\Imports\User;
+
+use App\Models\User;
+use Maatwebsite\Excel\Concerns\WithBatchInserts;
+use Maatwebsite\Excel\Concerns\WithChunkReading;
+use Maatwebsite\Excel\Concerns\WithMultipleSheets;
+use Maatwebsite\Excel\Concerns\ToModel;
+use Maatwebsite\Excel\Concerns\SkipsUnknownSheets;
+
+
+class PatientsInfo implements WithMultipleSheets,WithBatchInserts,WithChunkReading
+{
+    /**
+    * @param array $row
+    *
+    * @return \Illuminate\Database\Eloquent\Model|null
+    */
+    public function sheets(): array
+    {
+        return [
+            new PatientsSheet()
+        ];
+    }
+    public function batchSize(): int
+    {
+        return 1000;
+    }
+
+    public function chunkSize(): int
+    {
+        return 1000;
+    }
+}

+ 110 - 0
app/Imports/User/PatientsSheet.php

xqd
@@ -0,0 +1,110 @@
+<?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
+                    ]);
+                    \Log::info('新增用户'.$new_user['id']);
+                }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[5] == "男")
+                {
+                    $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];
+            }
+            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;
+    }
+}

+ 35 - 0
app/Imports/User/UserInfo.php

xqd
@@ -0,0 +1,35 @@
+<?php
+
+namespace App\Imports\User;
+
+use App\Models\User;
+use Maatwebsite\Excel\Concerns\WithBatchInserts;
+use Maatwebsite\Excel\Concerns\WithChunkReading;
+use Maatwebsite\Excel\Concerns\WithMultipleSheets;
+use Maatwebsite\Excel\Concerns\ToModel;
+use Maatwebsite\Excel\Concerns\SkipsUnknownSheets;
+
+
+class UserInfo implements WithMultipleSheets,WithBatchInserts,WithChunkReading
+{
+    /**
+    * @param array $row
+    *
+    * @return \Illuminate\Database\Eloquent\Model|null
+    */
+    public function sheets(): array
+    {
+        return [
+            new UserSheet()
+        ];
+    }
+    public function batchSize(): int
+    {
+        return 1000;
+    }
+
+    public function chunkSize(): int
+    {
+        return 1000;
+    }
+}

+ 72 - 0
app/Imports/User/UserSheet.php

xqd
@@ -0,0 +1,72 @@
+<?php
+
+namespace App\Imports\User;
+
+use App\Models\User;
+use Maatwebsite\Excel\Concerns\ToModel;
+use Illuminate\Support\Collection;
+use Maatwebsite\Excel\Concerns\ToCollection;
+
+class UserSheet implements ToCollection
+{
+    /**
+     * @param Collection $collection
+     */
+    public function collection(Collection $collection)
+    {
+        $user_info = [];
+        foreach ($collection as $row) {
+            if ($row[0]=="userId")
+            {
+                continue;
+            }
+            //用户名
+            if ($row[1] == null)
+            {
+                $user_info['user_name'] = '';
+            }else{
+                $user_info['user_name'] = $row[1];
+            }
+            //昵称
+            if ($row[2] == null)
+            {
+                $user_info['nickname'] = '';
+            }else{
+                $user_info['nickname'] = $row[2];
+            }
+            //电话
+            if ($row[3] == null)
+            {
+                $user_info['phone'] = '';
+            }else{
+                $user_info['phone'] = $row[3];
+            }
+
+            if ($row[4] == null)
+            {
+                $user_info['created_at'] =self::excelTime(0);
+            }else{
+                $user_info['created_at'] = self::excelTime($row[4]);
+            }
+
+            if ($row[5] == null)
+            {
+                $user_info['balance'] = '';
+            }else{
+                $user_info['balance'] = $row[5];
+            }
+            User::insert($user_info);
+        }
+
+    }
+    public static function excelTime($date, $time = false) {
+        $date=$date>25568?$date+1:25569;
+        $ofs=(70 * 365 + 17+2) * 86400;
+        $d1 = date("Y-m-d H:i:s",($date * 86400) - $ofs);
+        $d1 = strtotime("-8hours",strtotime($d1));
+        $d1 = date('Y-m-d H:i:s',$d1);
+        $date = $d1;
+        return $date;
+
+    }
+}