作者 赵彬吉

FB询盘新规则

@@ -12,6 +12,7 @@ use App\Helper\Gpt; @@ -12,6 +12,7 @@ use App\Helper\Gpt;
12 use App\Helper\Translate; 12 use App\Helper\Translate;
13 use App\Helper\Validate; 13 use App\Helper\Validate;
14 use App\Models\Ai\AiCommand; 14 use App\Models\Ai\AiCommand;
  15 +use App\Models\Inquiry\InquiryRelayDetailLog;
15 use App\Models\Inquiry\ReInquiryConfig; 16 use App\Models\Inquiry\ReInquiryConfig;
16 use App\Models\Inquiry\ReInquiryDetail; 17 use App\Models\Inquiry\ReInquiryDetail;
17 use App\Models\Inquiry\ReInquiryDetailLog; 18 use App\Models\Inquiry\ReInquiryDetailLog;
@@ -24,6 +25,7 @@ use App\Models\WebSetting\WebLanguage; @@ -24,6 +25,7 @@ use App\Models\WebSetting\WebLanguage;
24 use GuzzleHttp\Exception\ConnectException; 25 use GuzzleHttp\Exception\ConnectException;
25 use Illuminate\Console\Command; 26 use Illuminate\Console\Command;
26 use Illuminate\Support\Arr; 27 use Illuminate\Support\Arr;
  28 +use Illuminate\Support\Carbon;
27 use Illuminate\Support\Facades\Cache; 29 use Illuminate\Support\Facades\Cache;
28 use Illuminate\Support\Facades\DB; 30 use Illuminate\Support\Facades\DB;
29 use Illuminate\Support\Facades\Http; 31 use Illuminate\Support\Facades\Http;
@@ -433,7 +435,12 @@ class RelayInquiry extends Command @@ -433,7 +435,12 @@ class RelayInquiry extends Command
433 } 435 }
434 //是否有必选的渠道 渠道有一个及以上必选 就在组内随机一个 436 //是否有必选的渠道 渠道有一个及以上必选 就在组内随机一个
435 $require_agent_group = []; 437 $require_agent_group = [];
436 - foreach ($task['target'] as $item) { 438 + foreach ($task['target'] as $k=>$item) {
  439 + //没有广告费的 按频率来 x天一封 发过了先踢掉 优先级高于必选
  440 + if(!$this->checkFrequency($item)){
  441 + unset($item[$k]);
  442 + continue;
  443 + }
437 if (!empty($item['is_require'])) { 444 if (!empty($item['is_require'])) {
438 $require_agent_group[] = $item['agent_group']; 445 $require_agent_group[] = $item['agent_group'];
439 } 446 }
@@ -517,7 +524,7 @@ class RelayInquiry extends Command @@ -517,7 +524,7 @@ class RelayInquiry extends Command
517 524
518 $pre = 0; 525 $pre = 0;
519 $start_time = time(); 526 $start_time = time();
520 - $seconds = $this->delay_seconds($form->inquiry_date); 527 + $seconds = $this->delay_seconds($form->inquiry_date, $domain, $task);
521 $email = ''; 528 $email = '';
522 if($is_inquiry) { 529 if($is_inquiry) {
523 $exists = ReInquiryDetail::where('re_website', $domain)->where('email', $form->email)->first(); 530 $exists = ReInquiryDetail::where('re_website', $domain)->where('email', $form->email)->first();
@@ -547,6 +554,31 @@ class RelayInquiry extends Command @@ -547,6 +554,31 @@ class RelayInquiry extends Command
547 return true; 554 return true;
548 } 555 }
549 556
  557 + public function checkFrequency($item)
  558 + {
  559 + //设置了频率的
  560 + if (!empty($item['frequency'])) {
  561 + $item['is_ad_fee'] = 0; //v5都没有
  562 + if($item['is_v6']){
  563 + $project = Project::getProjectByDomain($item['url']);
  564 + if($project && $project->deploy_build){
  565 + $item['is_ad_fee'] = $project->deploy_build->ads_price ? 1 : 0;
  566 + }
  567 + }
  568 + //没有广告费 是否X天内发送过
  569 + if(!$item['is_ad_fee']){
  570 + $inquiry_log = InquiryRelayDetailLog::where('type', InquiryRelayDetailLog::TYPE_INQUIRY)
  571 + ->where('start_at', '>', date('Y-m-d H:i:s', strtotime('- ' . $item['frequency'] . ' day')))
  572 + ->first();
  573 + if($inquiry_log){
  574 + $this->output('频率限制');
  575 + return false;
  576 + }
  577 + }
  578 + }
  579 + return true;
  580 + }
  581 +
550 public function relayShopDetail($task, $form) 582 public function relayShopDetail($task, $form)
551 { 583 {
552 $this->output('获取商城转发对象'); 584 $this->output('获取商城转发对象');
@@ -580,7 +612,7 @@ class RelayInquiry extends Command @@ -580,7 +612,7 @@ class RelayInquiry extends Command
580 $referrer = $this->getReferer($country_name, $lang); 612 $referrer = $this->getReferer($country_name, $lang);
581 613
582 $start_time = time(); 614 $start_time = time();
583 - $seconds = $this->delay_seconds($form->inquiry_date); 615 + $seconds = $this->delay_seconds($form->inquiry_date, $domain, $task);
584 $exists = ReInquiryDetail::where('re_website', $domain)->where('email', $form->email)->first(); 616 $exists = ReInquiryDetail::where('re_website', $domain)->where('email', $form->email)->first();
585 if($exists){ 617 if($exists){
586 $this->output('转发站点邮件已存在'); 618 $this->output('转发站点邮件已存在');
@@ -616,7 +648,7 @@ class RelayInquiry extends Command @@ -616,7 +648,7 @@ class RelayInquiry extends Command
616 $user_agent = $form->email ? Arr::random($this->pc_ua) : Arr::random($this->mobile_ua); 648 $user_agent = $form->email ? Arr::random($this->pc_ua) : Arr::random($this->mobile_ua);
617 649
618 $start_time = time(); 650 $start_time = time();
619 - $seconds = $this->delay_seconds($form->inquiry_date); 651 + $seconds = $this->delay_seconds($form->inquiry_date, $postid, $task);
620 $exists = ReInquiryDetail::where('re_website', $postid)->where('email', $form->email)->first(); 652 $exists = ReInquiryDetail::where('re_website', $postid)->where('email', $form->email)->first();
621 if($exists){ 653 if($exists){
622 $this->output('转发站点邮件已存在'); 654 $this->output('转发站点邮件已存在');
@@ -945,8 +977,36 @@ class RelayInquiry extends Command @@ -945,8 +977,36 @@ class RelayInquiry extends Command
945 * @author zbj 977 * @author zbj
946 * @date 2025/7/16 978 * @date 2025/7/16
947 */ 979 */
948 - public function delay_seconds($inquiry_date) 980 + public function delay_seconds($inquiry_date, $domain, $task)
949 { 981 {
  982 + $inquiry_date = Carbon::make($inquiry_date);
  983 + //当天的
  984 + if($inquiry_date->isToday()){
  985 + //广告投放日(周一、二、三) 第一封询盘100%及时推送
  986 + $is_first = false;
  987 + if(in_array($inquiry_date->weekday(), [1,2,3])) {
  988 + //是否今天的第一封询盘
  989 + $detail = ReInquiryDetail::where('re_website', $domain)->where('start_at', '>=', $inquiry_date->startOfDay()->toDatetimeString())->first();
  990 + if(!$detail){
  991 + $is_first = true;
  992 + }
  993 + }
  994 + //非广告投放日第一封询盘
  995 + if(!$is_first && $task->second_push_rate != 100){
  996 + //按概率
  997 + $res = $this->get_rand([$task->second_push_rate, 100 - $task->second_push_rate]);
  998 + if($res == 1){
  999 + $this->output('非广告投放日第一封询盘 概率' . (100 - $task->second_push_rate) . '%延迟推送');
  1000 + //随机分配到未投放广告日期
  1001 + $now = Carbon::now();
  1002 + // 随机开始时间(本周四或现在)
  1003 + $startTime = max($now->timestamp, $now->startOfWeek(4)->timestamp);
  1004 +
  1005 + $random = mt_rand($startTime, $now->endOfWeek()->timestamp);
  1006 + return $random - $now->timestamp;
  1007 + }
  1008 + }
  1009 + }
950 $seconds = rand(300, 2 * 3600); // 默认 从5分钟-2小时后开始 1010 $seconds = rand(300, 2 * 3600); // 默认 从5分钟-2小时后开始
951 $time_diff = time() - strtotime($inquiry_date); //2小时前-24小时内的 当天发完 1011 $time_diff = time() - strtotime($inquiry_date); //2小时前-24小时内的 当天发完
952 if ($time_diff > 2 * 3600 && $time_diff <= 24 * 3600) { 1012 if ($time_diff > 2 * 3600 && $time_diff <= 24 * 3600) {
@@ -112,6 +112,15 @@ class AdsController extends BaseController @@ -112,6 +112,15 @@ class AdsController extends BaseController
112 } 112 }
113 $result['relay_site_total'] = $relay_site_total; 113 $result['relay_site_total'] = $relay_site_total;
114 $result['default_ai_param'] = ReInquiryConfig::getDefaultConfigCache(ReInquiryConfig::TYPE_AI_PARAM); 114 $result['default_ai_param'] = ReInquiryConfig::getDefaultConfigCache(ReInquiryConfig::TYPE_AI_PARAM);
  115 + $result['frequency_map'] = [
  116 + '1' => '一天一封询盘',
  117 + '2' => '两天一封询盘',
  118 + '3' => '三天一封询盘',
  119 + '4' => '四天一封询盘',
  120 + '5' => '五天一封询盘',
  121 + '6' => '六天一封询盘',
  122 + '0' => '不限制',
  123 + ];
115 124
116 return $this->response('success', Code::SUCCESS, $result); 125 return $this->response('success', Code::SUCCESS, $result);
117 } 126 }
@@ -134,6 +143,7 @@ class AdsController extends BaseController @@ -134,6 +143,7 @@ class AdsController extends BaseController
134 $status = intval($request->input('status')); 143 $status = intval($request->input('status'));
135 $is_replace_text = intval($request->input('is_replace_text')); 144 $is_replace_text = intval($request->input('is_replace_text'));
136 $ai_param = $request->input('ai_param'); 145 $ai_param = $request->input('ai_param');
  146 + $second_push_rate = $request->input('second_push_rate');
137 if (empty($title) || empty($ad_id)) 147 if (empty($title) || empty($ad_id))
138 return $this->response('请填写完整信息!', Code::USER_ERROR, []); 148 return $this->response('请填写完整信息!', Code::USER_ERROR, []);
139 149
@@ -152,7 +162,7 @@ class AdsController extends BaseController @@ -152,7 +162,7 @@ class AdsController extends BaseController
152 return $this->response('英文缩写参考不能为空!', Code::USER_ERROR, []); 162 return $this->response('英文缩写参考不能为空!', Code::USER_ERROR, []);
153 } 163 }
154 } 164 }
155 - $task = ReInquiryTask::createTask($id, $title, $industry, $ad_id, $ad_url, $ad_img, $num, $status, $is_replace_text, $ai_param, $is_show_fb_source); 165 + $task = ReInquiryTask::createTask($id, $title, $industry, $ad_id, $ad_url, $ad_img, $num, $status, $is_replace_text, $ai_param, $is_show_fb_source, $second_push_rate);
156 166
157 //是否显示FB标识 167 //是否显示FB标识
158 foreach ($task['target'] as $target){ 168 foreach ($task['target'] as $target){
@@ -41,7 +41,7 @@ class ReInquiryTask extends Base @@ -41,7 +41,7 @@ class ReInquiryTask extends Base
41 * @param int $status 41 * @param int $status
42 * @return ReInquiryTask 42 * @return ReInquiryTask
43 */ 43 */
44 - public static function createTask($id, $title, $industry, $ad_id, $ad_url, $ad_img, $num, $status, $is_replace_text, $ai_param, $is_show_fb_source) 44 + public static function createTask($id, $title, $industry, $ad_id, $ad_url, $ad_img, $num, $status, $is_replace_text, $ai_param, $is_show_fb_source, $second_push_rate)
45 { 45 {
46 $self = self::where(['id' => $id])->first(); 46 $self = self::where(['id' => $id])->first();
47 if (empty($self)) 47 if (empty($self))
@@ -56,6 +56,7 @@ class ReInquiryTask extends Base @@ -56,6 +56,7 @@ class ReInquiryTask extends Base
56 $self->is_replace_text = $is_replace_text; 56 $self->is_replace_text = $is_replace_text;
57 $self->ai_param = $ai_param; 57 $self->ai_param = $ai_param;
58 $self->is_show_fb_source = $is_show_fb_source; 58 $self->is_show_fb_source = $is_show_fb_source;
  59 + $self->second_push_rate = $second_push_rate;
59 $self->save(); 60 $self->save();
60 return $self; 61 return $self;
61 } 62 }
@@ -73,6 +74,7 @@ class ReInquiryTask extends Base @@ -73,6 +74,7 @@ class ReInquiryTask extends Base
73 $item['agent_group'] = $item['agent_group'] ?? ''; 74 $item['agent_group'] = $item['agent_group'] ?? '';
74 $item['is_require'] = $item['is_require'] ?? 0; 75 $item['is_require'] = $item['is_require'] ?? 0;
75 $item['price'] = $item['price'] ?? 0; 76 $item['price'] = $item['price'] ?? 0;
  77 + $item['frequency'] = $item['frequency'] ?? '3'; //默认频率3天一次
76 } 78 }
77 return $value; 79 return $value;
78 } 80 }