serviceOrder.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App\Imports\Order;
  3. use App\Admin\Actions\backstage\User\service;
  4. use App\Models\Order;
  5. use App\Models\OrderPack;
  6. use App\Models\ServicePack;
  7. use App\Models\User;
  8. use Illuminate\Support\Collection;
  9. use Illuminate\Support\Facades\Log;
  10. use Maatwebsite\Excel\Concerns\ToCollection;
  11. class serviceOrder implements ToCollection
  12. {
  13. /**
  14. * @param Collection $collection
  15. */
  16. public function collection(Collection $collection)
  17. {
  18. // 0 => "P20200605203723816"
  19. // 1 => "云南超级宝妈健康管理服务包"
  20. // 2 => "0.01"
  21. // 3 => "0.00"
  22. // 4 => "0.01"
  23. // 5 => "18487339976"
  24. // 6 => "已完成"
  25. // 7 => "2020-06-05 20:37:23"
  26. foreach ($collection as $row){
  27. if($row[0] == '订单编号') continue;
  28. // dd($row);
  29. //用户信息
  30. $user_id = $this->getValue(new User(),['phone'=>$row[5]],'id');
  31. $servicePack = servicePack::where(['name'=>$row[1]])->first();
  32. if(empty($user_id)){
  33. echo $row[5].'患者缺失'.PHP_EOL;
  34. Log::info('订单没有用户信息: '.$row[0].' 电话:'.$row[1].' 时间:'.$row[3].PHP_EOL);
  35. continue;
  36. }
  37. if(empty($servicePack)){
  38. echo $row[1].'服务包缺失'.PHP_EOL;
  39. continue;
  40. }
  41. $status = Order::getStatus();
  42. //是否用优惠券
  43. // $row[3] >0 ? $is_discont = 1 : $is_discont=0;
  44. //订单状态
  45. $order_status = array_search($row[6],$status);
  46. $orderInfo = [
  47. 'user_id'=>$user_id,
  48. 'order_status'=>$order_status,
  49. 'product_type'=>6,
  50. 'created_at'=>$row[7],
  51. // 'is_discount'=>$is_discont,
  52. 'total_amount'=>intval($row[2])*100,
  53. 'discount_amount'=>intval($row[3])*100,
  54. 'payment_amount'=>intval($row[4])*100,
  55. ];
  56. $order = Order::create($orderInfo);
  57. $orderId = $order['id'];
  58. $order_sn = build_sn($orderId);
  59. Order::where('id', $orderId)->update(['order_sn' => $order_sn]);
  60. $serviceInfo = [
  61. 'order_id'=>$orderId,
  62. 'service_pack_id'=>$servicePack->id,
  63. 'pack_name'=>$row[2],
  64. 'team_id'=>json_encode($servicePack->team_id),
  65. 'pack_intro'=>$servicePack->intro,
  66. 'appoint_num'=>$servicePack->appoint_num,
  67. 'chat_num'=>$servicePack->chat_num,
  68. 'phone_minutes'=>$servicePack->id,
  69. 'team_id'=>json_encode($servicePack->team_id),
  70. 'vaccine_limit_amount'=>$servicePack->vaccine_limit_amount,
  71. 'nurses_limit_amount'=>$servicePack->nurses_limit_amount,
  72. 'effective_days'=>$servicePack->effective_days,
  73. 'relationship_type'=>1,
  74. 'start_time'=>time(),
  75. 'end_time'=>(time() + 86400 * 3650),
  76. ];
  77. OrderPack::insert($serviceInfo);
  78. }
  79. return null;
  80. }
  81. public function getValue($model,$where,$field)
  82. {
  83. return $model->where($where)->value($field);
  84. }
  85. }