ImportInquiry.php 2.9 KB
<?php

namespace App\Console\Commands\Inquiry;

use App\Models\Inquiry\InquiryForm;
use App\Models\Inquiry\InquiryFormData;
use App\Services\ProjectServer;
use Illuminate\Console\Command;

/**
 * 询盘导入
 * Class InquiryList
 * @package App\Console\Commands
 * @author Akun
 * @date 2024/10/24
 */
class ImportInquiry extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'import_inquiry';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '询盘导入';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
//        $csv_url = 'https://ecdn6.globalso.com/upload/p/2408/image_product/2024-10/rf-miso.csv';
//        $project_id = 2408;
//        $domain = 'www.rf-miso.com';
//
//        //读取文件
//        $line_of_text = [];
//        try {
//            $opts = [
//                'http' => [
//                    'method' => 'GET',
//                    'header' => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246'
//                ],
//                'ssl' => [
//                    'verify_peer' => false,
//                    'verify_peer_name' => false
//                ]
//            ];
//            $file_handle = fopen($csv_url, 'r', null, stream_context_create($opts));
//            while (!feof($file_handle)) {
//                $line_of_text[] = fgetcsv($file_handle, 0, ',');
//            }
//            fclose($file_handle);
//        } catch (\Exception $e) {
//            $this->output($e->getMessage());
//        }
//
//        ProjectServer::useProject($project_id);
//
//        foreach ($line_of_text as $k => $v) {
//            if ($k > 0) {
//                $data = [
//                    'project_id' => $project_id,
//                    'domain' => $domain,
//                    'ip' => $v[4],
//                    'country' => $v[6],
//                    'referer' => $v[5],
//                    'user_agent' => '',
//                    'submit_at' => $v[0],
//                    'data' => [
//                        'name' => $v[1],
//                        'email' => $v[2],
//                        'phone' => $v[3],
//                    ]
//                ];
//                $form_id = InquiryForm::getFromId($data['data'], $data['project_id']);
//
//                InquiryFormData::saveData($form_id, $data['domain'], $data['ip'], $data['country'], $data['referer'], $data['user_agent'], $data['submit_at'], $data['data']);
//
//                $this->output($k . ',success');
//            }
//        }
    }

    public function output($message)
    {
        echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
    }
}