瀏覽代碼

订单数据导入

whj 4 年之前
父節點
當前提交
d25df1c29f

+ 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=

+ 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;

+ 62 - 6
app/Console/Commands/ImportOrder.php

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;
@@ -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');
     }
 }

+ 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)