vaccineSheet.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Imports\Order;
  3. use App\Models\Docter;
  4. use App\Models\Order;
  5. use App\Models\Organization;
  6. use App\Models\Vaccine;
  7. use App\User;
  8. use Illuminate\Support\Collection;
  9. use Maatwebsite\Excel\Concerns\ToCollection;
  10. use Illuminate\Support\Facades\Log;
  11. class vaccineSheet implements ToCollection
  12. {
  13. /**
  14. * @param Collection $collection
  15. */
  16. public function collection(Collection $collection)
  17. {
  18. // todo 缺少患者信息导致患者信息无法确定,支付方式,无订单编号,无法去重,没机构,没用户如何处理
  19. $i = 1;
  20. $order_info = [];
  21. foreach ($collection as $row) {
  22. if($row[0] == '就诊人姓名') continue;
  23. $user_id = $this->getValue(new User(),['phone'=>$row[1]],'id');
  24. $vaccine_id = $this->getValue(new Vaccine(),['name'=>$row[3]],'id');
  25. if(empty($user_id)){
  26. Log::info('订单没有用户信息: '.$row[0].' 电话:'.$row[1].' 时间:'.$row[4].PHP_EOL);
  27. continue;
  28. }
  29. $i ++ ;
  30. $status = Order::getStatus();
  31. //订单状态
  32. $order_status = array_search($row[5],$status);
  33. $org_id = $this->getValue(new Organization(),['name'=>$row[6]],'id');
  34. if(empty($org_id)) $org_id = 0;
  35. $order_sn = build_sn($i);
  36. //todo 写入计免订单表,订单患者表
  37. $order_info[] = [
  38. 'order_sn'=>$order_sn,
  39. 'user_id'=>$user_id,
  40. 'docter_id'=>0,
  41. 'order_status'=>$order_status,
  42. 'organization_id'=>$org_id,
  43. 'product_type'=>4,
  44. ];
  45. }
  46. return null;
  47. Order::insert($order_info);
  48. }
  49. public function getValue($model,$where,$field)
  50. {
  51. return $model->where($where)->value($field);
  52. }
  53. }