OrderImport.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Imports;
  3. use App\Repositories\Enums\Finance\CheckStatusEnum;
  4. use App\Repositories\Enums\ModelStatusEnum;
  5. use App\Repositories\Models\Finance\Category;
  6. use App\Repositories\Models\Finance\Order;
  7. use App\Repositories\Models\Finance\Shop;
  8. use Illuminate\Support\Facades\Log;
  9. use Maatwebsite\Excel\Concerns\OnEachRow;
  10. use Maatwebsite\Excel\Row;
  11. class OrderImport implements OnEachRow
  12. {
  13. public function onRow(Row $row)
  14. {
  15. if ($row->getIndex() <= 1) return false;
  16. list(
  17. $shop_name,
  18. $order_time,
  19. $order_no,
  20. $out_order_no,
  21. // $nums,
  22. $order_money,
  23. $cost_money,
  24. // $refund_order_money,
  25. // $refund_cost_money,
  26. // $postage_money,
  27. // $other_money,
  28. // $refund_postage_money,
  29. // $return_money,
  30. // $compensate,
  31. $buy_name,
  32. $buy_time,
  33. // $status_name,
  34. $remark
  35. ) = $row;
  36. if (empty($shop_name)) return false;
  37. if (!Shop::query()->where('name', $shop_name)->exists()) {
  38. return false;
  39. }
  40. $shop = Shop::query()->firstOrCreate(['name' => $shop_name], ['status' => ModelStatusEnum::OK]);
  41. if (empty($buy_name)) {
  42. $buy['id'] = 0;
  43. } else {
  44. $buy = Category::query()->firstOrCreate(['name' => $buy_name, 'parent_id' => 2], ['status' => ModelStatusEnum::OK]);
  45. }
  46. $order = [
  47. 'shop_id' => $shop->id,
  48. 'platform' => $shop->platform,
  49. 'order_no' => $order_no,
  50. 'order_time' => $order_time,
  51. 'out_order_no' => $out_order_no,
  52. // 'nums' => (int)$nums,
  53. 'order_money' => $order_money ?? 0.00,
  54. 'cost_money' => $cost_money ?? 0.00,
  55. // 'refund_order_money' => $refund_order_money ?? 0.00,
  56. // 'refund_cost_money' => $refund_cost_money ?? 0.00,
  57. // 'postage_money' => $postage_money ?? 0.00,
  58. // 'other_money' => $other_money ?? 0.00,
  59. // 'refund_postage_money' => $refund_postage_money ?? 0.00,
  60. // 'return_money' => $return_money ?? 0.00,
  61. // 'compensate' => $compensate ?? 0.00,
  62. 'buy_id' => $buy['id'],
  63. 'buy_time' => $buy_time,
  64. // 'status_name' => $status_name,
  65. 'remark' => $remark,
  66. 'check_status' => CheckStatusEnum::WAIT,
  67. 'import_time' => now(),
  68. 'entry_admin_id' => login_admin_id() ?? 0
  69. ];
  70. Log::error(arr2str($order));
  71. Order::query()->create($order);
  72. return true;
  73. }
  74. }