12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace App\Imports;
- use App\Models\Category;
- use App\Models\Pipeline;
- use App\Models\Shop;
- use App\Repositories\Enums\CheckStatusEnum;
- use App\Repositories\Enums\ModelStatusEnum;
- use Dcat\Admin\Admin;
- 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,
- $profits_money,
- $buy_name,
- $buy_time,
- $status_name,
- $remark
- ) = $row;
- if (empty($shop_name)) 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, 'pid' => 2], ['status' => ModelStatusEnum::OK]);
- }
- $refund_money = bcsub($refund_order_money, $refund_cost_money, 8);
- $profits_money = bcsub(bcadd(bcsub(bcsub($order_money, $cost_money, 8), $other_money, 8), $postage_money, 8), $refund_money, 2);
- $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,
- 'profits_money' => $profits_money,
- 'buy_id' => $buy['id'],
- 'buy_time' => $buy_time,
- 'status_name' => $status_name,
- 'remark' => $remark,
- 'check_status' => CheckStatusEnum::WAIT,
- 'import_time' => now(),
- 'entry_admin_id' => Admin::user()->id ?? 0
- ];
- Pipeline::query()->create($order);
- return true;
- }
- }
|