123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace App\Imports;
- use App\Repositories\Enums\Finance\CheckStatusEnum;
- use App\Repositories\Enums\ModelStatusEnum;
- use App\Repositories\Models\Finance\Category;
- use App\Repositories\Models\Finance\Order;
- use App\Repositories\Models\Finance\Shop;
- use Illuminate\Support\Facades\Log;
- use Maatwebsite\Excel\Concerns\OnEachRow;
- use Maatwebsite\Excel\Row;
- class OrderImport implements OnEachRow
- {
- public function onRow(Row $row)
- {
- if ($row->getIndex() <= 1) return false;
- list(
- $shop_name,
- $order_time,
- $order_no,
- $out_order_no,
- // $nums,
- $order_money,
- $cost_money,
- // $refund_order_money,
- // $refund_cost_money,
- // $postage_money,
- // $other_money,
- // $refund_postage_money,
- // $return_money,
- // $compensate,
- $buy_name,
- $buy_time,
- // $status_name,
- $remark
- ) = $row;
- if (empty($shop_name)) return false;
- if (!Shop::query()->where('name', $shop_name)->exists()) {
- return false;
- }
- $shop = Shop::query()->firstOrCreate(['name' => $shop_name], ['status' => ModelStatusEnum::OK]);
- if (empty($buy_name)) {
- $buy['id'] = 0;
- } else {
- $buy = Category::query()->firstOrCreate(['name' => $buy_name, 'parent_id' => 2], ['status' => ModelStatusEnum::OK]);
- }
- $order = [
- 'shop_id' => $shop->id,
- 'platform' => $shop->platform,
- 'order_no' => $order_no,
- 'order_time' => $order_time,
- 'out_order_no' => $out_order_no,
- // 'nums' => (int)$nums,
- 'order_money' => $order_money ?? 0.00,
- 'cost_money' => $cost_money ?? 0.00,
- // 'refund_order_money' => $refund_order_money ?? 0.00,
- // 'refund_cost_money' => $refund_cost_money ?? 0.00,
- // 'postage_money' => $postage_money ?? 0.00,
- // 'other_money' => $other_money ?? 0.00,
- // 'refund_postage_money' => $refund_postage_money ?? 0.00,
- // 'return_money' => $return_money ?? 0.00,
- // 'compensate' => $compensate ?? 0.00,
- 'buy_id' => $buy['id'],
- 'buy_time' => $buy_time,
- // 'status_name' => $status_name,
- 'remark' => $remark,
- 'check_status' => CheckStatusEnum::WAIT,
- 'import_time' => now(),
- 'entry_admin_id' => login_admin_id() ?? 0
- ];
- Log::error(arr2str($order));
- Order::query()->create($order);
- return true;
- }
- }
|