123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace App\Imports\Order;
- use App\Models\Docter;
- use App\Models\Order;
- use App\Models\Organization;
- use App\Models\Vaccine;
- use App\User;
- use Illuminate\Support\Collection;
- use Maatwebsite\Excel\Concerns\ToCollection;
- use Illuminate\Support\Facades\Log;
- class vaccineSheet implements ToCollection
- {
- /**
- * @param Collection $collection
- */
- public function collection(Collection $collection)
- {
- // todo 缺少患者信息导致患者信息无法确定,支付方式,无订单编号,无法去重,没机构,没用户如何处理
- $i = 1;
- $order_info = [];
- foreach ($collection as $row) {
- if($row[0] == '就诊人姓名') continue;
- $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);
- 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);
- //todo 写入计免订单表,订单患者表
- $order_info[] = [
- 'order_sn'=>$order_sn,
- 'user_id'=>$user_id,
- 'docter_id'=>0,
- 'order_status'=>$order_status,
- 'organization_id'=>$org_id,
- 'product_type'=>4,
- ];
- }
- return null;
- Order::insert($order_info);
- }
- public function getValue($model,$where,$field)
- {
- return $model->where($where)->value($field);
- }
- }
|