OrderImport.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace App\Imports;
  3. use App\Models\Category;
  4. use App\Models\Pipeline;
  5. use App\Models\Shop;
  6. use App\Repositories\Enums\CheckStatusEnum;
  7. use App\Repositories\Enums\ModelStatusEnum;
  8. use Dcat\Admin\Admin;
  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. $profits_money,
  29. $buy_name,
  30. $buy_time,
  31. $status_name,
  32. $remark
  33. ) = $row;
  34. if (empty($shop_name)) return false;
  35. $shop = Shop::query()->firstOrCreate(['name' => $shop_name], ['status' => ModelStatusEnum::OK]);
  36. if (empty($buy_name)) {
  37. $buy['id'] = 0;
  38. } else {
  39. $buy = Category::query()->firstOrCreate(['name' => $buy_name, 'pid' => 2], ['status' => ModelStatusEnum::OK]);
  40. }
  41. $refund_money = bcsub($refund_order_money, $refund_cost_money, 8);
  42. $profits_money = bcsub(bcadd(bcsub(bcsub($order_money, $cost_money, 8), $other_money, 8), $postage_money, 8), $refund_money, 2);
  43. $order = [
  44. 'shop_id' => $shop->id,
  45. 'platform' => $shop->platform,
  46. 'order_no' => $order_no,
  47. 'order_time' => $order_time,
  48. 'out_order_no' => $out_order_no,
  49. 'nums' => (int)$nums,
  50. 'order_money' => $order_money ?? 0.00,
  51. 'cost_money' => $cost_money ?? 0.00,
  52. 'refund_order_money' => $refund_order_money ?? 0.00,
  53. 'refund_cost_money' => $refund_cost_money ?? 0.00,
  54. 'postage_money' => $postage_money ?? 0.00,
  55. 'other_money' => $other_money ?? 0.00,
  56. 'profits_money' => $profits_money,
  57. 'buy_id' => $buy['id'],
  58. 'buy_time' => $buy_time,
  59. 'status_name' => $status_name,
  60. 'remark' => $remark,
  61. 'check_status' => CheckStatusEnum::WAIT,
  62. 'import_time' => now(),
  63. 'entry_admin_id' => Admin::user()->id ?? 0
  64. ];
  65. Pipeline::query()->create($order);
  66. return true;
  67. }
  68. }