phoneOrder.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Imports\Order;
  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\Models\UserBalanceLog;
  9. use App\User;
  10. use Illuminate\Support\Collection;
  11. use Maatwebsite\Excel\Concerns\ToCollection;
  12. class phoneOrder implements ToCollection
  13. {
  14. /**
  15. * @param Collection $collection
  16. */
  17. public function collection(Collection $collection)
  18. {
  19. foreach ($collection as $row){
  20. if ($row[0] == '订单编号') continue;
  21. //订单状态
  22. $status = Order::getStatus();
  23. //订单状态
  24. $paystatus = Order::getPayStatus();
  25. $pay_status = array_search($row[18], $paystatus);
  26. $order_status = array_search($row[9], $status);
  27. if($row[9] == '已过期') $order_status = 6;
  28. if($row[18] == '未付款' || empty($row[18])) $pay_status = 1;
  29. $pay_types = [1 => '微信支付', 2 => '余额支付', 3 => '服务包支付'];
  30. //支付方式
  31. $payType = array_search($row[16], $pay_types) + 1;
  32. if ($payType == 1) $payType = 2;
  33. $order = Order::where('order_sn',$row[0])->first();
  34. if(!empty($order)){
  35. $orderInfo = [
  36. 'order_sn' => $row[0],
  37. 'order_status' => $order_status,
  38. 'order_notes' => '',
  39. 'payment_status'=>$pay_status,
  40. ];
  41. $old_order_status = intval($order->order_status);
  42. $old_notice = intval($order->order_notes);
  43. if($old_order_status == 5 && ($old_notice == '医生超时未接单自动取消' || $old_notice == '医生超时未接单自动取消') ){
  44. $log = UserBalanceLog::where(['relation_id'=>$order->id])->first();
  45. if(!empty($log)){
  46. $user = \App\Models\User::where('id',$order->user_id)->first();
  47. if($user->balance >0){
  48. User::where('id',$order->user_id)->decrement('balance',$log->change_balance);
  49. UserBalanceLog::where('id',$log->id)->delete();
  50. }
  51. }
  52. Order::where('id',$order->id)->update($orderInfo);
  53. }
  54. } else {
  55. continue;
  56. }
  57. }
  58. return null;
  59. }
  60. public function getValue($model,$where,$field)
  61. {
  62. return $model->where($where)->value($field);
  63. }
  64. }