作者 Your Name
  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 +}
@@ -352,7 +352,9 @@ class RelayInquiry extends Command @@ -352,7 +352,9 @@ class RelayInquiry extends Command
352 $country_name = $ip_data->ip_area; 352 $country_name = $ip_data->ip_area;
353 353
354 $this->output('转发内容'); 354 $this->output('转发内容');
355 - 355 + $message = $form->message;
  356 + //开启文案替换
  357 + if($task['is_replace_text']) {
356 // 通过字符数量区分, 改成完全获取内置询盘内容 358 // 通过字符数量区分, 改成完全获取内置询盘内容
357 $use_ids = ReInquiryDetail::where(['re_website' => $domain])->where('status', '<>', ReInquiryDetail::STATUS_FAIL)->pluck('text_id')->toArray(); 359 $use_ids = ReInquiryDetail::where(['re_website' => $domain])->where('status', '<>', ReInquiryDetail::STATUS_FAIL)->pluck('text_id')->toArray();
358 $text = ReInquiryText::whereNotIn('id', $use_ids)->where('status', ReInquiryText::STATUS_USABLE)->inRandomOrder()->first(); 360 $text = ReInquiryText::whereNotIn('id', $use_ids)->where('status', ReInquiryText::STATUS_USABLE)->inRandomOrder()->first();
@@ -363,16 +365,17 @@ class RelayInquiry extends Command @@ -363,16 +365,17 @@ class RelayInquiry extends Command
363 $text->save(); 365 $text->save();
364 366
365 //原内容非英语,转为对应语种 367 //原内容非英语,转为对应语种
366 - if(is_numeric($form->message)){ //数字会被识别为中文 368 + if (is_numeric($form->message)) { //数字会被识别为中文
367 $lang = 'en'; 369 $lang = 'en';
368 - }else{ 370 + } else {
369 $translateSl = Translate::translateSl($form->message); 371 $translateSl = Translate::translateSl($form->message);
370 $lang = $translateSl['texts']['sl'] ?? 'en'; 372 $lang = $translateSl['texts']['sl'] ?? 'en';
371 } 373 }
372 374
373 - if($lang != 'en' || $lang != 'zh-CN'){ 375 + if ($lang != 'en' || $lang != 'zh-CN') {
374 $message = Translate::tran($message, $lang); 376 $message = Translate::tran($message, $lang);
375 } 377 }
  378 + }
376 379
377 $this->output('获取转发设备信息'); 380 $this->output('获取转发设备信息');
378 // 客户端 头信息 来源 381 // 客户端 头信息 来源
@@ -81,10 +81,11 @@ class AdsController extends BaseController @@ -81,10 +81,11 @@ class AdsController extends BaseController
81 $ad_img = trim($request->input('ad_img')); 81 $ad_img = trim($request->input('ad_img'));
82 $num = intval($request->input('num')); 82 $num = intval($request->input('num'));
83 $status = intval($request->input('status')); 83 $status = intval($request->input('status'));
  84 + $is_replace_text = intval($request->input('is_replace_text'));
84 if (empty($title) || empty($ad_id)) 85 if (empty($title) || empty($ad_id))
85 return $this->response('请填写完整信息!', Code::USER_ERROR, []); 86 return $this->response('请填写完整信息!', Code::USER_ERROR, []);
86 87
87 - ReInquiryTask::createTask($id, $title, $industry, $ad_id, $ad_url, $ad_img, $num, $status); 88 + ReInquiryTask::createTask($id, $title, $industry, $ad_id, $ad_url, $ad_img, $num, $status, $is_replace_text);
88 return $this->response('success', Code::SUCCESS, []); 89 return $this->response('success', Code::SUCCESS, []);
89 } 90 }
90 91
@@ -40,7 +40,7 @@ class ReInquiryTask extends Base @@ -40,7 +40,7 @@ class ReInquiryTask extends Base
40 * @param int $status 40 * @param int $status
41 * @return ReInquiryTask 41 * @return ReInquiryTask
42 */ 42 */
43 - public static function createTask($id, $title, $industry, $ad_id, $ad_url, $ad_img, $num, $status = self::STATUS_OPEN) 43 + public static function createTask($id, $title, $industry, $ad_id, $ad_url, $ad_img, $num, $status = self::STATUS_OPEN, $is_replace_text = 1)
44 { 44 {
45 $self = self::where(['id' => $id])->first(); 45 $self = self::where(['id' => $id])->first();
46 if (empty($self)) 46 if (empty($self))
@@ -52,6 +52,7 @@ class ReInquiryTask extends Base @@ -52,6 +52,7 @@ class ReInquiryTask extends Base
52 $self->ad_img = $ad_img; 52 $self->ad_img = $ad_img;
53 $self->num = $num; 53 $self->num = $num;
54 $self->status = $status; 54 $self->status = $status;
  55 + $self->is_replace_text = $is_replace_text;
55 $self->save(); 56 $self->save();
56 return $self; 57 return $self;
57 } 58 }