chatOrder.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace App\Imports\Order;
  3. use AlibabaCloud\Gpdb\V20160503\DeleteDatabase;
  4. use App\Models\Docter;
  5. use App\Models\Order;
  6. use App\Models\OrderPatient;
  7. use App\Models\Organization;
  8. use App\Models\Patient;
  9. use App\User;
  10. use Illuminate\Support\Facades\Log;
  11. use Maatwebsite\Excel\Concerns\ToModel;
  12. use Maatwebsite\Excel\Concerns\WithHeadingRow;
  13. use Maatwebsite\Excel\Concerns\WithBatchInserts;
  14. use Maatwebsite\Excel\Concerns\WithChunkReading;
  15. use Maatwebsite\Excel\Concerns\WithProgressBar;
  16. class chatOrder implements ToModel,WithBatchInserts,WithChunkReading
  17. {
  18. /**
  19. * @param array $row
  20. *
  21. * @return \Illuminate\Database\Eloquent\Model|null
  22. */
  23. public function model(array $row)
  24. {
  25. if($row[0] == '订单编号') return null;
  26. // [
  27. // 0 => "im20210118173813522",
  28. // 1 => "云南运营主体",
  29. // 2 => "熊振宇",
  30. // 3 => "13708872753",
  31. // 4 => "文菊焱",
  32. // 5 => "",
  33. // 6 => "云南省昆明市昆明市盘龙区联盟街道金康园社区卫生服务站",
  34. // 7 => "妇保科",
  35. // 8 => "否",
  36. // 9 => "进行中",
  37. // 10 => "",
  38. // 11 => "否",
  39. // 12 => "1.99",
  40. // 13 => "0.00",
  41. // 14 => "1.99",
  42. // 15 => "1.99",
  43. // 16 => "微信支付",
  44. // 17 => "单次图文咨询",
  45. // 18 => "已付款",
  46. // 19 => "2021-01-18 17:38:13",
  47. // ];
  48. //检查是否有该订单
  49. $isHave = $this->getValue(new Order(),['order_sn'=>$row[0]],'id');
  50. if($isHave) return null;
  51. $patient_id = $this->getValue(new Patient(),['name'=>$row[2]],'id');
  52. $user_id = $this->getValue(new User(),['phone'=>$row[3]],'id');
  53. //如果没有用户不导入该订单
  54. if(empty($user_id)){
  55. Log::info('订单没有用户信息,订单编号: '.$row[0].PHP_EOL);
  56. return null;
  57. }
  58. // 1 => "未支付"
  59. // 2 => "待支付"
  60. // 3 => "进行中"
  61. // 4 => "已完成"
  62. // 5 => "已取消"
  63. // 6 => "已超时"
  64. // 7 => "已预约"
  65. //订单状态
  66. $status = Order::getStatus();
  67. //订单状态
  68. $paystatus = Order::getPayStatus();
  69. $pay_status = array_search($row[18],$paystatus);
  70. $order_status = array_search($row[9],$status);
  71. $docter_id = $this->getValue(new Docter(),['name'=>$row[4]],'id');
  72. $org_id = $this->getValue(new Organization(),['name'=>$row[6]],'id');
  73. $evaluate = $row[10] == '已评价'? 1 : 0;
  74. $pay_types = [1=>'微信支付',2=>'余额支付',3=>'服务包支付'];
  75. //支付方式
  76. $payType = array_search($row[16],$pay_types) + 1;
  77. if($payType == 1) $payType = 2;
  78. $orderInfo = [
  79. 'order_sn'=>$row[0],
  80. 'patient_id'=>$patient_id,
  81. 'user_id'=>$user_id,
  82. 'docter_id'=>$docter_id,
  83. 'order_status'=>$order_status,
  84. 'organization_id'=>$org_id,
  85. 'is_evaluate'=>$evaluate,
  86. 'is_discount'=>$row[11],
  87. 'total_amount'=>$row[12]*100,
  88. 'discount_amount'=>$row[13]*100,
  89. 'payment_amount'=>$row[15]*100,
  90. 'payment_type'=>$payType,
  91. 'payment_status'=>$pay_status,
  92. 'product_type'=>1,
  93. 'created_at'=>$row[19],
  94. ];
  95. //处理逻辑
  96. return new Order($orderInfo);
  97. }
  98. public function startRow(): int
  99. {
  100. return 2;
  101. }
  102. public function batchSize(): int
  103. {
  104. return 20;
  105. }
  106. public function chunkSize(): int
  107. {
  108. return 20;
  109. }
  110. public function getValue($model,$where,$field)
  111. {
  112. return $model->where($where)->value($field);
  113. }
  114. }