合并分支 'akun' 到 'master'
Akun 查看合并请求 !822
正在显示
1 个修改的文件
包含
102 行增加
和
0 行删除
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Console\Commands\Inquiry; | ||
| 4 | + | ||
| 5 | +use App\Models\Inquiry\InquiryForm; | ||
| 6 | +use App\Models\Inquiry\InquiryFormData; | ||
| 7 | +use App\Services\ProjectServer; | ||
| 8 | +use Illuminate\Console\Command; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 询盘导入 | ||
| 12 | + * Class InquiryList | ||
| 13 | + * @package App\Console\Commands | ||
| 14 | + * @author Akun | ||
| 15 | + * @date 2024/10/24 | ||
| 16 | + */ | ||
| 17 | +class ImportInquiry extends Command | ||
| 18 | +{ | ||
| 19 | + /** | ||
| 20 | + * The name and signature of the console command. | ||
| 21 | + * | ||
| 22 | + * @var string | ||
| 23 | + */ | ||
| 24 | + protected $signature = 'import_inquiry'; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * The console command description. | ||
| 28 | + * | ||
| 29 | + * @var string | ||
| 30 | + */ | ||
| 31 | + protected $description = '询盘导入'; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * Create a new command instance. | ||
| 35 | + * | ||
| 36 | + * @return void | ||
| 37 | + */ | ||
| 38 | + public function __construct() | ||
| 39 | + { | ||
| 40 | + parent::__construct(); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public function handle() | ||
| 44 | + { | ||
| 45 | + $csv_url = 'https://ecdn6.globalso.com/upload/p/2408/image_product/2024-10/rf-miso.csv'; | ||
| 46 | + $project_id = 2408; | ||
| 47 | + $domain = 'www.rf-miso.com'; | ||
| 48 | + | ||
| 49 | + //读取文件 | ||
| 50 | + $line_of_text = []; | ||
| 51 | + try { | ||
| 52 | + $opts = [ | ||
| 53 | + 'http' => [ | ||
| 54 | + 'method' => 'GET', | ||
| 55 | + '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' | ||
| 56 | + ], | ||
| 57 | + 'ssl' => [ | ||
| 58 | + 'verify_peer' => false, | ||
| 59 | + 'verify_peer_name' => false | ||
| 60 | + ] | ||
| 61 | + ]; | ||
| 62 | + $file_handle = fopen($csv_url, 'r', null, stream_context_create($opts)); | ||
| 63 | + while (!feof($file_handle)) { | ||
| 64 | + $line_of_text[] = fgetcsv($file_handle, 0, ','); | ||
| 65 | + } | ||
| 66 | + fclose($file_handle); | ||
| 67 | + } catch (\Exception $e) { | ||
| 68 | + $this->output($e->getMessage()); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + ProjectServer::useProject($project_id); | ||
| 72 | + | ||
| 73 | + foreach ($line_of_text as $k => $v) { | ||
| 74 | + if ($k > 0) { | ||
| 75 | + $data = [ | ||
| 76 | + 'project_id' => $project_id, | ||
| 77 | + 'domain' => $domain, | ||
| 78 | + 'ip' => $v[4], | ||
| 79 | + 'country' => $v[6], | ||
| 80 | + 'referer' => $v[5], | ||
| 81 | + 'user_agent' => '', | ||
| 82 | + 'submit_at' => $v[0], | ||
| 83 | + 'data' => [ | ||
| 84 | + 'name' => $v[1], | ||
| 85 | + 'email' => $v[2], | ||
| 86 | + 'phone' => $v[3], | ||
| 87 | + ] | ||
| 88 | + ]; | ||
| 89 | + $form_id = InquiryForm::getFromId($data['data'], $data['project_id']); | ||
| 90 | + | ||
| 91 | + InquiryFormData::saveData($form_id, $data['domain'], $data['ip'], $data['country'], $data['referer'], $data['user_agent'], $data['submit_at'], $data['data']); | ||
| 92 | + | ||
| 93 | + $this->output($k . ',success'); | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + public function output($message) | ||
| 99 | + { | ||
| 100 | + echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL; | ||
| 101 | + } | ||
| 102 | +} |
-
请 注册 或 登录 后发表评论