作者 Your Name
<?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;
}
}
... ...
... ... @@ -352,26 +352,29 @@ class RelayInquiry extends Command
$country_name = $ip_data->ip_area;
$this->output('转发内容');
$message = $form->message;
//开启文案替换
if($task['is_replace_text']) {
// 通过字符数量区分, 改成完全获取内置询盘内容
$use_ids = ReInquiryDetail::where(['re_website' => $domain])->where('status', '<>', ReInquiryDetail::STATUS_FAIL)->pluck('text_id')->toArray();
$text = ReInquiryText::whereNotIn('id', $use_ids)->where('status', ReInquiryText::STATUS_USABLE)->inRandomOrder()->first();
$message = $text->content;
$message_id = $text->id;
// 获取后,使用次数+1
$text->use_time += 1;
$text->save();
//原内容非英语,转为对应语种
if (is_numeric($form->message)) { //数字会被识别为中文
$lang = 'en';
} else {
$translateSl = Translate::translateSl($form->message);
$lang = $translateSl['texts']['sl'] ?? 'en';
}
// 通过字符数量区分, 改成完全获取内置询盘内容
$use_ids = ReInquiryDetail::where(['re_website' => $domain])->where('status', '<>', ReInquiryDetail::STATUS_FAIL)->pluck('text_id')->toArray();
$text = ReInquiryText::whereNotIn('id', $use_ids)->where('status', ReInquiryText::STATUS_USABLE)->inRandomOrder()->first();
$message = $text->content;
$message_id = $text->id;
// 获取后,使用次数+1
$text->use_time += 1;
$text->save();
//原内容非英语,转为对应语种
if(is_numeric($form->message)){ //数字会被识别为中文
$lang = 'en';
}else{
$translateSl = Translate::translateSl($form->message);
$lang = $translateSl['texts']['sl'] ?? 'en';
}
if($lang != 'en' || $lang != 'zh-CN'){
$message = Translate::tran($message, $lang);
if ($lang != 'en' || $lang != 'zh-CN') {
$message = Translate::tran($message, $lang);
}
}
$this->output('获取转发设备信息');
... ...
... ... @@ -81,10 +81,11 @@ class AdsController extends BaseController
$ad_img = trim($request->input('ad_img'));
$num = intval($request->input('num'));
$status = intval($request->input('status'));
$is_replace_text = intval($request->input('is_replace_text'));
if (empty($title) || empty($ad_id))
return $this->response('请填写完整信息!', Code::USER_ERROR, []);
ReInquiryTask::createTask($id, $title, $industry, $ad_id, $ad_url, $ad_img, $num, $status);
ReInquiryTask::createTask($id, $title, $industry, $ad_id, $ad_url, $ad_img, $num, $status, $is_replace_text);
return $this->response('success', Code::SUCCESS, []);
}
... ...
... ... @@ -40,7 +40,7 @@ class ReInquiryTask extends Base
* @param int $status
* @return ReInquiryTask
*/
public static function createTask($id, $title, $industry, $ad_id, $ad_url, $ad_img, $num, $status = self::STATUS_OPEN)
public static function createTask($id, $title, $industry, $ad_id, $ad_url, $ad_img, $num, $status = self::STATUS_OPEN, $is_replace_text = 1)
{
$self = self::where(['id' => $id])->first();
if (empty($self))
... ... @@ -52,6 +52,7 @@ class ReInquiryTask extends Base
$self->ad_img = $ad_img;
$self->num = $num;
$self->status = $status;
$self->is_replace_text = $is_replace_text;
$self->save();
return $self;
}
... ...