<?php

namespace App\Console\Commands;

use App\Http\Services\DataService;
use App\Http\Services\StatisticsSkuUploadService;
use App\Http\Services\SupplierService;
use App\Http\Services\SyncSupplierService;
use App\Model\SupplierChannelModel;
use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
use PhpAmqpLib\Connection\AMQPStreamConnection;

//设置供应商是否需要跟进
class SyncAllSupplierToErp extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'sync_all_supplier_to_erp';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Display an inspiring quote';

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        ini_set('memory_limit', -1);
        $supplierIds = SupplierChannelModel::where('is_type', 0)->where('group_code','!=','')
            ->pluck('supplier_id')->toArray();
        $conn = new AMQPStreamConnection(config('database.connections.rabbitmq.host'),
            config('database.connections.rabbitmq.port'),
            config('database.connections.rabbitmq.login'),
            config('database.connections.rabbitmq.password'));
        foreach ($supplierIds as $supplierId) {
            usleep(100000);
            dump($supplierId);
            (new SyncSupplierService())->syncSupplierToErp($supplierId, $conn);
        }
    }
}