chatOrder.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace App\Imports;
  3. use App\Models\Docter;
  4. use App\Models\Order;
  5. use App\Models\OrderPatient;
  6. use App\Models\Organization;
  7. use App\Models\Patient;
  8. use App\User;
  9. use Maatwebsite\Excel\Concerns\ToModel;
  10. use Maatwebsite\Excel\Concerns\WithHeadingRow;
  11. use Maatwebsite\Excel\Concerns\WithBatchInserts;
  12. use Maatwebsite\Excel\Concerns\WithChunkReading;
  13. use Maatwebsite\Excel\Concerns\WithProgressBar;
  14. class chatOrder implements ToModel,WithBatchInserts,WithChunkReading
  15. {
  16. /**
  17. * @param array $row
  18. *
  19. * @return \Illuminate\Database\Eloquent\Model|null
  20. */
  21. public function model(array $row)
  22. {
  23. if($row[0] == '订单编号') return '';
  24. [
  25. 0 => "im20210118173813522",
  26. 1 => "云南运营主体",
  27. 2 => "熊振宇",
  28. 3 => "13708872753",
  29. 4 => "文菊焱",
  30. 5 => "",
  31. 6 => "云南省昆明市昆明市盘龙区联盟街道金康园社区卫生服务站",
  32. 7 => "妇保科",
  33. 8 => "否",
  34. 9 => "进行中",
  35. 10 => "",
  36. 11 => "否",
  37. 12 => "1.99",
  38. 13 => "0.00",
  39. 14 => "1.99",
  40. 15 => "1.99",
  41. 16 => "微信支付",
  42. 17 => "单次图文咨询",
  43. 18 => "已付款",
  44. 19 => "2021-01-18 17:38:13",
  45. ];
  46. $patient_id = $this->getValue(new Patient(),['name'=>$row[2]],'id');
  47. $user_id = $this->getValue(new User(),['phone'=>$row[3]],'id');
  48. $docter_id = $this->getValue(new Docter(),['name'=>$row[4]],'id');
  49. $org_id = $this->getValue(new Organization(),['name'=>$row[6]],'id');
  50. $order_status = $row[9];
  51. $evaluate = $row[10] == '已评价'? 1 : 0;
  52. // 14
  53. $orderInfo = [
  54. 'order_sn'=>$row[0],
  55. 'patient_id'=>$patient_id,
  56. 'user_id'=>$user_id,
  57. 'docter_id'=>$docter_id,
  58. 'order_status'=>$order_status,
  59. 'organization_id'=>$org_id,
  60. 'is_evaluate'=>$evaluate,
  61. 'is_discount'=>$row[11],
  62. 'total_amount'=>$row[12],
  63. 'discount_amount'=>$row[13],
  64. 'payment_amount'=>$row[15],
  65. 'payment_type'=>$row[16],
  66. 'payment_status'=>$row[18],
  67. 'created_at'=>$row[19],
  68. ];
  69. dd($orderInfo);
  70. //处理逻辑
  71. return new Order([
  72. //
  73. ]);
  74. }
  75. public function startRow(): int
  76. {
  77. return 2;
  78. }
  79. public function batchSize(): int
  80. {
  81. return 1000;
  82. }
  83. public function chunkSize(): int
  84. {
  85. return 1000;
  86. }
  87. public function getValue($model,$where,$field)
  88. {
  89. return $model->where($where)->value($field);
  90. }
  91. }