OrderImport.php 2.5 KB

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