作者 赵彬吉

shop/fob inquiry

... ... @@ -204,7 +204,7 @@ class RelayInquiry extends Command
}
// 未设置对法对象
$target_num_arr = array_map(function ($item) {
return count($item['target']);
return count($item['target']) + count($item['shop_site']) + count($item['fob_pro']);
}, $ad_task);
if (!array_sum($target_num_arr)) {
$val->status = ReInquiryForm::STATUS_FORGO;
... ... @@ -225,6 +225,8 @@ class RelayInquiry extends Command
$res = false;
foreach ($ad_task as $task){
$res += $this->relayDetail($task, $val);
$res += $this->relayShopDetail($task, $val);
$res += $this->relayFobDetail($task, $val);
}
$val->status = $res ? ReInquiryForm::STATUS_SUCCESS : ReInquiryForm::STATUS_FORGO;
$val->save();
... ... @@ -288,7 +290,10 @@ class RelayInquiry extends Command
public function relayDetail($task, $form)
{
$this->output('获取转发对象');
if(empty($task['target'] )){
$this->output('没有独立站转发对象');
return 0;
}
//是否有必选的
$require_data = [];
foreach ($task['target'] as $item){
... ... @@ -327,119 +332,20 @@ class RelayInquiry extends Command
$is_v6 = $item['is_v6'];
$re_website = 'https://' . $domain . '/';
$this->output('转发对象:' . $domain);
$this->output('获取转发链接');
// v6:有邮箱推送主站,没有邮箱推送AMP站;v5:仅推送有邮箱到主站
$lang = '';
if ($is_v6) {
// 获取语种, 6.0是可以确定语种的
$project = Project::getProjectByDomain($domain);
if (empty($project)) {
$this->logChannel()->info('广告任务ID:' . $task['id'] . ', 转发对象:' . $re_website . '非v6链接,转发失败;', ['广告任务ID:' . $task['id'], '询盘ID:' . $form->id]);
continue;
}
$lang = WebLanguage::getLangById($project->main_lang_id ?? 1)['short'];
// 获取访问明细和着陆页
$product_url = $this->getLinksFromSitemap($re_website . 'product_sitemap.xml');
$product_cate_url = $this->getLinksFromSitemap($re_website . 'product_category_sitemap.xml');
$keywords_url = $this->getLinksFromSitemap($re_website . 'product_keywords_sitemap.xml');
$page_url = $this->getLinksFromSitemap($re_website . 'page_sitemap.xml');
} else {
if($form->email){
//通过sitemap拿访问页面
$product_url = $this->getLinksFromSitemap($re_website . 'sitemap_post.xml');
$product_cate_url = $this->getLinksFromSitemap($re_website . 'sitemap_category.xml');
$keywords_url = $this->getLinksFromSitemap($re_website . 'sitemap_post_tag.xml');
$page_url = $this->getLinksFromSitemap($re_website . 'sitemap_page.xml');
}else{
//m站先就往contact-us着陆
$product_url = $product_cate_url = $keywords_url = [];
$page_url = [$re_website . 'contact-us/'];
}
}
// 所有可用url
$urls = $inquiry_urls = [];
//入口url 首页30%,单页10%,聚合页60%
$type = getRandByRatio([30,10,60]);
$inlet = $re_website;
$type == 1 && $inlet = $page_url ? Arr::random($page_url) : $re_website;
$type == 2 && $inlet = $keywords_url ? Arr::random($keywords_url) : $re_website;
$urls[] = $inquiry_urls[] = $inlet;
$all_urls = array_merge($urls, $product_url, $product_cate_url, $keywords_url, $page_url);
$inquiry_urls = array_merge($urls, $product_cate_url, $keywords_url, $page_url);
// 随机访问1-6个页面
$deep = rand(1,6);
if($deep > 2) {
$visit_urls = Arr::random($all_urls, rand(1, count($all_urls) > 4 ? 4 : count($all_urls)));
$urls = array_merge($urls, $visit_urls);
}
if($deep > 1) {
// 推送着落页只能是 首页、产品分类、单页面、聚合页
if (!in_array(end($urls), $inquiry_urls)) {
$urls[] = Arr::random($inquiry_urls);
}
//urls
list($urls, $lang) = $this->getUrls($is_v6, $domain, $re_website, $form, $task);
if(!$urls){
continue;
}
$this->output('获取转发ip');
// TODO 获取IP:如果是简码,查询数据库获取对应的国家, 如果是国家使用翻译, 再转化成IP
$country = $form->country_name;
// 有国家 通过国家查询, 如果没有获取到就随机获取
$where = [];
$country && $where['ip_area'] = $country;
$ip_data = DB::table('gl_xunpan_ipdata')->where($where)->inRandomOrder()->first();
if (empty($ip_data)) {
$ip_data = DB::table('gl_xunpan_ipdata')->inRandomOrder()->first();
}
//ip
$ip_data = $this->getIpData($form->country_name);
$ip = $ip_data->ip;
$country_name = $ip_data->ip_area;
$this->output('转发内容');
$message = $form->message;
$message_id = 0;
//开启文案替换
if ($task['is_replace_text'] == 2) {
//AI生成
$error = 0;
while ($error<3){
$message = $this->ai_send($task['ai_param'], $message);
if(!$message){
$this->output('AI文案生成失败');
$error++;
if($error==2){
$task['is_replace_text'] = 1;
$this->output('AI文案生成失败,使用文案库');
}
}else{
break;
}
}
}
if ($task['is_replace_text'] == 1 || strlen($message) <= 4) {
//配置文案库替换或者字符少于4个,直接替换文案
$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' && !Str::contains($lang, 'zh')) {
$message = Translate::tran($message, $lang);
}
}
//message
list($message, $message_id, $msg_lang) = $this->getMessage($task, $form->message, $domain);
$lang = $lang ?: $msg_lang;
$this->output('获取转发设备信息');
// 客户端 头信息 来源
... ... @@ -474,6 +380,203 @@ class RelayInquiry extends Command
return true;
}
public function relayShopDetail($task, $form)
{
$this->output('获取商城转发对象');
if(empty($task['shop_site'])){
$this->output('没有商城转发对象');
return 0;
}
foreach ($task['shop_site'] as $item) {
//手机号过滤
$phone = $form->phone;
// 推送站点
$domain = $item;
$re_website = 'https://' . $domain . '/';
$paths = ['', 'contact-us'];
$url = $re_website . $paths[array_rand($paths)];
//ip
$ip_data = $this->getIpData($form->country_name);
$ip = $ip_data->ip;
$country_name = $ip_data->ip_area;
//message
list($message, $message_id, $lang) = $this->getMessage($task, $form->message, $domain);
$device_port = $form->email ? '1' : '2'; //1 pc 2移动端
$user_agent = $form->email ? Arr::random($this->pc_ua) : Arr::random($this->mobile_ua);
$referrer = $this->getReferer($country_name, $lang);
$start_time = time();
$seconds = rand(300, 3000); // 开始时间 从5-50分钟后开始
$exists = ReInquiryDetail::where('re_website', $domain)->where('email', $form->email)->first();
if($exists){
$this->output('转发站点邮件已存在');
continue;
}
$re_detail = ReInquiryDetail::createInquiry($task['id'], $form->id, $domain, $country_name, $ip, $form->full_name, $form->email, $phone, $message, $message_id,
$device_port, $user_agent, $referrer, [$url], 0, date('Y-m-d H:i:s', $start_time + $seconds), ReInquiryDetail::STATUS_INIT, 2);
ReInquiryDetailLog::createInquiryLog($re_detail->id, ReInquiryDetailLog::TYPE_INQUIRY, 1, $url, date('Y-m-d H:i:s', $start_time + $seconds));
}
return true;
}
public function relayFobDetail($task, $form)
{
$this->output('获取FOB转发对象');
if(empty($task['fob_pro'])){
$this->output('没有FOB转发对象');
return 0;
}
foreach ($task['fob_pro'] as $item) {
//手机号过滤
$phone = $form->phone;
// 推送站点
$postid = $item;
//message
list($message, $message_id, $lang) = $this->getMessage($task, $form->message, $postid);
$device_port = $form->email ? '1' : '2'; //1 pc 2移动端
$user_agent = $form->email ? Arr::random($this->pc_ua) : Arr::random($this->mobile_ua);
$start_time = time();
$seconds = rand(300, 3000); // 开始时间 从5-50分钟后开始
$exists = ReInquiryDetail::where('re_website', $postid)->where('email', $form->email)->first();
if($exists){
$this->output('转发站点邮件已存在');
continue;
}
$re_detail = ReInquiryDetail::createInquiry($task['id'], $form->id, $postid, $country_name??'', $ip??'', $form->full_name, $form->email, $phone,
$message, $message_id, $device_port, $user_agent, $referrer??'', [$postid], 0, date('Y-m-d H:i:s', $start_time + $seconds), ReInquiryDetail::STATUS_INIT, 3);
ReInquiryDetailLog::createInquiryLog($re_detail->id, ReInquiryDetailLog::TYPE_INQUIRY, 1, $postid, date('Y-m-d H:i:s', $start_time + $seconds));
}
return true;
}
public function getIpData($country_name){
$this->output('获取转发ip');
$country = $country_name;
// 有国家 通过国家查询, 如果没有获取到就随机获取
$where = [];
$country && $where['ip_area'] = $country;
$ip_data = DB::table('gl_xunpan_ipdata')->where($where)->inRandomOrder()->first();
if (empty($ip_data)) {
$ip_data = DB::table('gl_xunpan_ipdata')->inRandomOrder()->first();
}
return $ip_data;
}
public function getMessage($task, $message, $domain){
$this->output('转发内容');
$form_message = $message;
$message_id = 0;
//开启文案替换
if ($task['is_replace_text'] == 2) {
//AI生成
$error = 0;
while ($error<3){
$message = $this->ai_send($task['ai_param'], $message);
if(!$message){
$this->output('AI文案生成失败');
$error++;
if($error==2){
$task['is_replace_text'] = 1;
$this->output('AI文案生成失败,使用文案库');
}
}else{
break;
}
}
}
if ($task['is_replace_text'] == 1 || strlen($message) <= 4) {
//配置文案库替换或者字符少于4个,直接替换文案
$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' && !Str::contains($lang, 'zh')) {
$message = Translate::tran($message, $lang);
}
}
return [$message, $message_id, $lang??''];
}
public function getUrls($is_v6, $domain, $re_website, $form, $task){
$this->output('转发对象:' . $domain);
$this->output('获取转发链接');
// v6:有邮箱推送主站,没有邮箱推送AMP站;v5:仅推送有邮箱到主站
$lang = '';
if ($is_v6) {
// 获取语种, 6.0是可以确定语种的
$project = Project::getProjectByDomain($domain);
if (empty($project)) {
$this->logChannel()->info('广告任务ID:' . $task['id'] . ', 转发对象:' . $re_website . '非v6链接,转发失败;', ['广告任务ID:' . $task['id'], '询盘ID:' . $form->id]);
return [[], $lang];
}
$lang = WebLanguage::getLangById($project->main_lang_id ?? 1)['short'];
// 获取访问明细和着陆页
$product_url = $this->getLinksFromSitemap($re_website . 'product_sitemap.xml');
$product_cate_url = $this->getLinksFromSitemap($re_website . 'product_category_sitemap.xml');
$keywords_url = $this->getLinksFromSitemap($re_website . 'product_keywords_sitemap.xml');
$page_url = $this->getLinksFromSitemap($re_website . 'page_sitemap.xml');
} else {
if($form->email){
//通过sitemap拿访问页面
$product_url = $this->getLinksFromSitemap($re_website . 'sitemap_post.xml');
$product_cate_url = $this->getLinksFromSitemap($re_website . 'sitemap_category.xml');
$keywords_url = $this->getLinksFromSitemap($re_website . 'sitemap_post_tag.xml');
$page_url = $this->getLinksFromSitemap($re_website . 'sitemap_page.xml');
}else{
//m站先就往contact-us着陆
$product_url = $product_cate_url = $keywords_url = [];
$page_url = [$re_website . 'contact-us/'];
}
}
// 所有可用url
$urls = $inquiry_urls = [];
//入口url 首页30%,单页10%,聚合页60%
$type = getRandByRatio([30,10,60]);
$inlet = $re_website;
$type == 1 && $inlet = $page_url ? Arr::random($page_url) : $re_website;
$type == 2 && $inlet = $keywords_url ? Arr::random($keywords_url) : $re_website;
$urls[] = $inquiry_urls[] = $inlet;
$all_urls = array_merge($urls, $product_url, $product_cate_url, $keywords_url, $page_url);
$inquiry_urls = array_merge($urls, $product_cate_url, $keywords_url, $page_url);
// 随机访问1-6个页面
$deep = rand(1,6);
if($deep > 2) {
$visit_urls = Arr::random($all_urls, rand(1, count($all_urls) > 4 ? 4 : count($all_urls)));
$urls = array_merge($urls, $visit_urls);
}
if($deep > 1) {
// 推送着落页只能是 首页、产品分类、单页面、聚合页
if (!in_array(end($urls), $inquiry_urls)) {
$urls[] = Arr::random($inquiry_urls);
}
}
return [$urls, $lang];
}
/**
* 获取待处理询盘表单
* @param int $num
... ... @@ -494,7 +597,7 @@ class RelayInquiry extends Command
{
$cache_key = 'inquiry_ads_tasks';
$ads = Cache::get($cache_key, function () use ($cache_key) {
$ads = ReInquiryTask::where(['status' => ReInquiryTask::STATUS_OPEN])->get(['id', 'ad_id', 'num', 'target', 'is_replace_text', 'ai_param']);
$ads = ReInquiryTask::where(['status' => ReInquiryTask::STATUS_OPEN])->get(['id', 'ad_id', 'num', 'target', 'is_replace_text', 'ai_param', 'shop_site', 'fob_pro']);
$array = [];
foreach ($ads as $key=>$val) {
$ad_ids = explode(',', $val['ad_id']);
... ...
... ... @@ -158,60 +158,26 @@ class postInquiry extends Command
}
public function inquiry(ReInquiryDetail $detail, ReInquiryDetailLog $log){
$website = 'https://' . $detail['re_website'] . '/';
// v6
if($detail['is_v6']) {
$data = [
'name' => $detail['name'],
'phone' => $detail['phone'],
'message' => $detail['message'],
'submit_ip' => $detail['ip'],
'refer' => $log->url,
];
if($detail->email){
$data['email'] = $detail->email;
}else{
$data['__amp_source_origin'] = trim($website, '/');
}
$res = Http::withoutVerifying()->withHeaders(['User-Agent' => $detail['user_agent']])->post($website . 'api/inquiryQd/', $data)->json();
if(empty($res['code']) || $res['code'] != 200){
$log->status = ReInquiryDetailLog::STATUS_FAIL;
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
$log->save();
Log::channel('inquiry_relay')->error('inquiry_relay v6 inquiry error', [$res, $website . 'api/inquiryQd/', $data]);
return false;
$res = false;
if ($detail['type'] == 1) {
// v6
if ($detail['is_v6']) {
$res = $this->v6Inquiry($detail, $log);
} else {
$res = $this->v5Inquiry($detail, $log);
}
}else{
$data = [
'name' => $detail['name'],
'phone' => $detail['phone'],
'message' => $detail['message'],
'email' => $detail['email'],
'ip' => $detail['ip'],
'token' => md5($log->url . $detail['name'] . $detail['ip'] . date("Y-m-d")),
'refer' => $log->url,
'submit_time' => date('Y-m-d H:i:s'),
'source' => 5,
];
$result = Http::withoutVerifying()->post('https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f', $data);
$res = $result->json();
//兼容接口返回格式
if(!empty($res['data'][0]['status'])){
$res['data'][0]['code'] = $res['data'][0]['status'] == 'success' ? 200 : 400;
!empty($res['data'][0]['msg']) && $res['message'] = $res['data'][0]['msg'];
}
if(empty($res['data'][0]['code']) || !in_array($res['data'][0]['code'], [200,300])){
$log->status = ReInquiryDetailLog::STATUS_FAIL;
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
$log->save();
} elseif ($detail['type'] == 2) {
//商城询盘
$res = $this->ShopInquiry($detail, $log);
} elseif ($detail['type'] == 3) {
//Fob询盘
$res = $this->FobInquiry($detail, $log);
}
Log::channel('inquiry_relay')->error('inquiry_relay v4|v5 inquiry error', [$result->body(), 'https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f', $data]);
return false;
}
if(!$res){
return false;
}
$log->status = ReInquiryDetailLog::STATUS_SUCCESS;
$log->save();
... ... @@ -221,6 +187,102 @@ class postInquiry extends Command
return true;
}
public function v6Inquiry($detail, $log){
$website = 'https://' . $detail['re_website'] . '/';
$data = [
'name' => $detail['name'],
'phone' => $detail['phone'],
'message' => $detail['message'],
'submit_ip' => $detail['ip'],
'refer' => $log->url,
];
if ($detail->email) {
$data['email'] = $detail->email;
} else {
$data['__amp_source_origin'] = trim($website, '/');
}
$res = Http::withoutVerifying()->withHeaders(['User-Agent' => $detail['user_agent']])->post($website . 'api/inquiryQd/', $data)->json();
if (empty($res['code']) || $res['code'] != 200) {
$log->status = ReInquiryDetailLog::STATUS_FAIL;
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
$log->save();
Log::channel('inquiry_relay')->error('inquiry_relay v6 inquiry error', [$res, $website . 'api/inquiryQd/', $data]);
return false;
}
return true;
}
public function v5Inquiry($detail, $log){
$data = [
'name' => $detail['name'],
'phone' => $detail['phone'],
'message' => $detail['message'],
'email' => $detail['email'],
'ip' => $detail['ip'],
'token' => md5($log->url . $detail['name'] . $detail['ip'] . date("Y-m-d")),
'refer' => $log->url,
'submit_time' => date('Y-m-d H:i:s'),
'source' => 5,
];
$result = Http::withoutVerifying()->post('https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f', $data);
$res = $result->json();
//兼容接口返回格式
if (!empty($res['data'][0]['status'])) {
$res['data'][0]['code'] = $res['data'][0]['status'] == 'success' ? 200 : 400;
!empty($res['data'][0]['msg']) && $res['message'] = $res['data'][0]['msg'];
}
if (empty($res['data'][0]['code']) || !in_array($res['data'][0]['code'], [200, 300])) {
$log->status = ReInquiryDetailLog::STATUS_FAIL;
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
$log->save();
Log::channel('inquiry_relay')->error('inquiry_relay v4|v5 inquiry error', [$result->body(), 'https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f', $data]);
return false;
}
return true;
}
public function ShopInquiry($detail, $log){
$data = [
'name' => $detail['name'],
'email' => $detail['email'],
'phone' => $detail['phone'],
'message' => $detail['message'],
'submit_ip' => $detail['ip'],
'refer' => $log['url'],
];
ksort($data);
$data['token'] = md5( json_encode($data, JSON_UNESCAPED_UNICODE ) . date("Y-m-d"));
$url = 'https://' . $detail['re_website'] . '/index.php?route=api/ai_inquiry/add';
$res = Http::withoutVerifying()->post($url, $data)->json();
if (empty($res['code']) || $res['code'] != 200) {
$log->status = ReInquiryDetailLog::STATUS_FAIL;
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
$log->save();
Log::channel('inquiry_relay')->error('inquiry_relay shop inquiry error', [$res, $url, $data]);
return false;
}
}
public function FobInquiry($detail, $log){
$data = [
'name' => $detail['name'],
'email' => $detail['email'],
'phone' => $detail['phone'],
'post_id' => $log['url'],
];
$res = Http::withoutVerifying()->post('https://fob.ai.cc/api/ad_to_scrm', $data)->json();
if (empty($res['code']) || $res['code'] != 200) {
$log->status = ReInquiryDetailLog::STATUS_FAIL;
$log->remark = mb_substr($res['message'] ?? '', 0, 200);
$log->save();
Log::channel('inquiry_relay')->error('inquiry_relay fob inquiry error', [$res, 'https://fob.ai.cc/api/ad_to_scrm', $data]);
return false;
}
}
public function output($message)
{
... ...
... ... @@ -23,6 +23,7 @@ use App\Utils\HttpUtils;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
/**
* Class AdsController
... ... @@ -126,7 +127,9 @@ class AdsController extends BaseController
public function setRelaySite(Request $request)
{
$id = intval($request->input('id', 0));
$target = $request->input('target');
$target = $request->input('target', []);
$shop_site = $request->input('shop_site', []);
$fob_pro = $request->input('fob_pro', []);
$task = ReInquiryTask::find($id);
if(!$task){
return $this->response('广告不存在!', Code::USER_ERROR, []);
... ... @@ -153,15 +156,42 @@ class AdsController extends BaseController
if($is_require_num > $task->num){
return $this->response('必选渠道不能大于转发数量!', Code::USER_ERROR, []);
}
foreach ($target as $v){
ReInquiryCount::addInquiryNum($id, $v['url'], 0);
}
//商城
foreach ($shop_site as &$url) {
if (empty($url)) {
return $this->response('商城网站域名不能为空!', Code::USER_ERROR, []);
}
$url = trim(str_replace(['http://', 'https://'], '', $url), '/');
$res = Http::get($url . '/index.php?route=api/ai_inquiry/add')->json();
if (!$res) {
return $this->response($url . '不是商城网站!', Code::USER_ERROR, []);
}
ReInquiryCount::addInquiryNum($id, $url, 0, 2);
}
//超级项目
foreach ($fob_pro as &$postid) {
if (empty($postid)) {
return $this->response('项目ID不能为空!', Code::USER_ERROR, []);
}
ReInquiryCount::addInquiryNum($id, $postid, 0, 3);
}
$task->target = json_encode($target);
$task->shop_site = json_encode($shop_site);
$task->fob_pro = json_encode($fob_pro);
$task->save();
return $this->response('success', Code::SUCCESS, []);
}
public function fob_projects(){
$res = ReInquiryCount::getFobProjects();
return $this->response('success', Code::SUCCESS, $res);
}
/**
* 验证站点5.0还是6.0, 代理商信息
* @param Request $request
... ...
... ... @@ -2,13 +2,16 @@
namespace App\Models\Inquiry;
use App\Enums\Common\Code;
use App\Helper\Arr;
use App\Helper\QuanqiusouApi;
use App\Models\Base;
use App\Models\Domain\DomainInfo;
use App\Models\Project\Project;
use App\Models\Task\TaskOwner;
use App\Utils\HttpUtils;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
/**
* Class ReInquiryCount
... ... @@ -30,26 +33,37 @@ class ReInquiryCount extends Base
* @author zbj
* @date 2024/10/26
*/
public static function addInquiryNum($task_id, $domain, $num = 1)
public static function addInquiryNum($task_id, $domain, $num = 1, $type = 1, $company = '')
{
$model = self::where('domain', $domain)->first();
if (!$model) {
//新增时获取公司名
$company = '';
$domain_info = DomainInfo::where('domain', $domain)->first();
if ($domain_info) {
$company = Project::where('id', $domain_info['project_id'])->value('company');
} else {
$res = (new QuanqiusouApi())->getV5Agent($domain);
if (!empty($res['status']) && $res['status'] == 200) {
$company = $res['company_name'];
if($type == 1) {
//新增时获取公司名
$company = '';
$domain_info = DomainInfo::where('domain', $domain)->first();
if ($domain_info) {
$company = Project::where('id', $domain_info['project_id'])->value('company');
} else {
$res = (new QuanqiusouApi())->getV5Agent($domain);
if (!empty($res['status']) && $res['status'] == 200) {
$company = $res['company_name'];
}
}
}
if($type == 2){
$company = $domain;
}
if($type == 3){
$fob_list = self::getFobProjects();
$fob = collect($fob_list)->where('postid', $domain)->first();
$company = $fob['company'] . ' - ' . $fob['plan'];
}
$model = new self();
$model->domain = $domain;
$model->company = $company;
$model->type = $type;
}
$model->task_ids = $model->task_ids + [$task_id];
$model->num = $model->num + $num;
... ... @@ -78,4 +92,15 @@ class ReInquiryCount extends Base
}
return $tasks;
}
public static function getFobProjects(){
$cache_key = 'GET_BIND_PROJECT_LIST';
$res = Cache::get($cache_key);
if(!$res){
$res = HttpUtils::get('https://fob.ai.cc/api/get_bind_project_list', []);
$res = json_decode($res, true)['data'] ?? [];
Cache::put($cache_key, $res, 120);
}
return $res;
}
}
... ...
... ... @@ -67,7 +67,7 @@ class ReInquiryDetail extends Model
* @return ReInquiryDetail
*/
public static function createInquiry($task_id, $form_id, $re_website, $country, $ip, $name, $email, $phone, $message, $text_id, $device_port,
$user_agent, $referrer, $urls, $is_v6, $start_at, $status = self::STATUS_INIT)
$user_agent, $referrer, $urls, $is_v6, $start_at, $status = self::STATUS_INIT, $type = 1)
{
$self = new self();
$self->task_id = $task_id;
... ... @@ -88,6 +88,7 @@ class ReInquiryDetail extends Model
$self->num = count($urls) + 1;
$self->start_at = $start_at;
$self->status = $status;
$self->type = $type;
$self->save();
return $self;
}
... ... @@ -100,4 +101,4 @@ class ReInquiryDetail extends Model
{
return $this->hasMany(ReInquiryDetailLog::class, 'detail_id', 'id');
}
}
\ No newline at end of file
}
... ...
... ... @@ -105,6 +105,16 @@ How Much 写成 HM',
return $value;
}
public function getShopSiteAttribute($value)
{
return $value ? json_decode($value, true) : [];
}
public function getFobProAttribute($value)
{
return $value ? json_decode($value, true) : [];
}
public function setAiParamAttribute($value)
{
$this->attributes['ai_param'] = Arr::a2s($value);
... ...
... ... @@ -496,6 +496,7 @@ Route::middleware(['aloginauth'])->group(function () {
Route::any('/fb_inquiry_chart', [Aside\Task\AdsController::class, 'fbInquiryChart'])->name('admin.fb_ads_inquiry_chart');
Route::any('/fb_relay_detail_list', [Aside\Task\AdsController::class, 'fbRelayDetail'])->name('admin.fb_ads_relay_detail_list');
Route::any('/fb_relay_count', [Aside\Task\AdsController::class, 'fbRelayCount'])->name('admin.fb_relay_count');
Route::any('/fob_projects', [Aside\Task\AdsController::class, 'fob_projects'])->name('admin.fob_projects');
});
//统计所有项目相关
... ...