作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into master-server

... ... @@ -197,7 +197,10 @@ class RelayInquiry extends Command
continue;
}
// 未设置对法对象
if (empty($ad_task['target'])) {
$target_num_arr = array_map(function ($item) {
return count($item['target']);
}, $ad_task);
if (!array_sum($target_num_arr)) {
$val->status = ReInquiryForm::STATUS_FORGO;
$val->remark = '广告任务转发对象为空!';
$val->save();
... ... @@ -213,7 +216,12 @@ class RelayInquiry extends Command
}
try {
$this->relayDetail($ad_task, $val);
$res = false;
foreach ($ad_task as $task){
$res += $this->relayDetail($task, $val);
}
$val->status = $res ? ReInquiryForm::STATUS_SUCCESS : ReInquiryForm::STATUS_FORGO;
$val->save();
} catch (\Exception $e) {
$this->logChannel()->info('执行询盘错误:' . $e->getMessage());
$this->output('执行询盘错误:' . $e->getMessage());
... ... @@ -294,9 +302,7 @@ class RelayInquiry extends Command
if (empty($random_data)) {
$this->logChannel()->info('当前任务未发现转发对象!', ['广告任务ID:' . $task['id'], '询盘ID:' . $form->id]);
$form->status = ReInquiryForm::STATUS_FORGO;
$form->remark = '当前任务未发现转发对象,广告ID: ' . $form->ad_id . '!';
$form->save();
$form->remark = $form->remark . '当前任务未发现转发对象,广告ID: ' . $form->ad_id . '!';
return false;
}
... ... @@ -352,7 +358,7 @@ class RelayInquiry extends Command
// 随机访问1-6个页面
$deep = rand(1,6);
if($deep > 2) {
$visit_urls = Arr::random($all_urls, rand(1, count($all_urls) > 3 ? 3 : count($all_urls)));
$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) {
... ... @@ -444,9 +450,6 @@ class RelayInquiry extends Command
}
}
}
$form->status = ReInquiryForm::STATUS_SUCCESS;
$form->save();
return true;
}
... ... @@ -468,12 +471,15 @@ class RelayInquiry extends Command
*/
public function getAdTask($ad_id)
{
$cache_key = 'inquiry_ads_task';
$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']);
$array = [];
foreach ($ads as $key=>$val) {
$array[$val->ad_id] = $val;
$ad_ids = explode(',', $val['ad_id']);
foreach ($ad_ids as $ad_id){
$array[$ad_id][] = $val;
}
}
if ($array)
Cache::put($cache_key, $array, 60);
... ...
... ... @@ -8,6 +8,7 @@ use App\Models\Inquiry\ReInquiryForm;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
/**
* Class postInquiry
... ... @@ -50,6 +51,18 @@ class postInquiry extends Command
}
// 询盘数据入库
foreach ($list as $key => $val) {
//加个锁 避免重复执行
$lockKey = 're_inquiry_detail_log_lock_' . $val->id;
if(!Redis::setnx($lockKey, 1)){
continue;
}
Redis::expire($lockKey, 60);
$log = ReInquiryDetailLog::find($val->id);
if($log->status != ReInquiryDetailLog::STATUS_INIT){
continue;
}
$this->output('开始执行' . $val->id);
try {
$detail = ReInquiryDetail::find($val['detail_id']);
... ...
... ... @@ -7,8 +7,10 @@ use App\Models\Com\Notify;
use App\Models\Devops\ServerConfig;
use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainInfo;
use App\Models\Product\Keyword;
use App\Models\Project\Project;
use App\Services\BatchExportService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
... ... @@ -29,11 +31,86 @@ class Temp extends Command
protected $description = '临时脚本';
/**
* 关键词首字母
* @author Akun
* @date 2024/10/30 15:37
*/
public function handle()
{
$projects = Project::where('id', '>', 52)->select(['id'])->orderBy('id', 'asc')->get();
foreach ($projects as $project) {
ProjectServer::useProject($project->id);
//处理关键词首字母
try {
Keyword::select(['id', 'title', 'first_word'])->chunk(1000, function ($query) {
foreach ($query as $item) {
if ($item->first_word === null) {
$item->first_word = $this->getTitleFirstLetter($item->title);
$item->save();
}
}
});
} catch (\Exception $e) {
$this->output($e->getMessage());
continue;
}
$this->output('ID:' . $project->id . ',success');
}
}
protected function getTitleFirstLetter($title)
{
$first = mb_strtolower(mb_substr($title, 0, 1, 'utf-8'), 'utf-8');
if (in_array($first, ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"])) {
$firstLetter = 0;
} else {
if (in_array($first, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'])) {
$rule = [
"a" => 1,
"b" => 2,
"c" => 3,
"d" => 4,
"e" => 5,
"f" => 6,
"g" => 7,
"h" => 8,
"i" => 9,
"j" => 10,
"k" => 11,
"l" => 12,
"m" => 13,
"n" => 14,
"o" => 15,
"p" => 16,
"q" => 17,
"r" => 18,
"s" => 19,
"t" => 20,
"u" => 21,
"v" => 22,
"w" => 23,
"x" => 24,
"y" => 25,
"z" => 26,
];
$firstLetter = $rule[$first];
} else {
$firstLetter = 27;
}
}
return $firstLetter;
}
/**
* 获取指定服务器所有项目
* @author Akun
* @date 2024/09/30 17:01
*/
public function handle()
public function handle3()
{
$server_id = 1;
... ... @@ -79,7 +156,7 @@ class Temp extends Command
* @author Akun
* @date 2024/09/26 10:48
*/
public function handle1()
public function handle2()
{
$server_id = 15;
... ... @@ -131,7 +208,7 @@ class Temp extends Command
* @author Akun
* @date 2024/09/26 10:48
*/
public function handle2()
public function handle1()
{
$notify_model = new Notify();
$project_model = new Project();
... ...
... ... @@ -176,6 +176,7 @@ class ProjectUpdate extends Command
'seo_title' => $item['seo_title'] ?? '',
'seo_keywords' => $item['seo_keywords'] ?? '',
'seo_description' => $item['seo_description'] ?? '',
'first_word' => $this->getTitleFirstLetter($item['name']),
'is_upgrade' => 1,
'route' => $route
]);
... ... @@ -1225,4 +1226,48 @@ class ProjectUpdate extends Command
return false;
}
}
//获取关键词首字母对应数字
protected function getTitleFirstLetter($title)
{
$first = mb_strtolower(mb_substr($title, 0, 1, 'utf-8'), 'utf-8');
if (in_array($first, ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"])) {
$firstLetter = 0;
} else {
if (in_array($first, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'])) {
$rule = [
"a" => 1,
"b" => 2,
"c" => 3,
"d" => 4,
"e" => 5,
"f" => 6,
"g" => 7,
"h" => 8,
"i" => 9,
"j" => 10,
"k" => 11,
"l" => 12,
"m" => 13,
"n" => 14,
"o" => 15,
"p" => 16,
"q" => 17,
"r" => 18,
"s" => 19,
"t" => 20,
"u" => 21,
"v" => 22,
"w" => 23,
"x" => 24,
"y" => 25,
"z" => 26,
];
$firstLetter = $rule[$first];
} else {
$firstLetter = 27;
}
}
return $firstLetter;
}
}
... ...
... ... @@ -62,7 +62,7 @@ class AdsController extends BaseController
foreach ($result as &$item){
$relay_site_total += count($item->target);
$item->requiry_num = ReInquiryDetail::where('task_id', $item->id)->where('status', ReInquiryDetail::STATUS_SUCCESS)->count();
$item->form_num = ReInquiryForm::where('ad_id', $item->ad_id)->count();
$item->form_num = ReInquiryForm::whereIn('ad_id', explode(',', $item->ad_id))->count();
}
$result = $result->toArray();
$result['relay_site_total'] = $relay_site_total;
... ... @@ -169,7 +169,8 @@ class AdsController extends BaseController
if($channel){
$data = [
'is_v6' => 1,
'agent' => trim(explode('-', Channel::getChannelText($channel['user_id']??0))[0]),
'agent' => Channel::getChannelText($channel['user_id']??0),
'agent_group' => trim(explode('-', Channel::getChannelText($channel['user_id']??0))[0]),
'domain' => $domain,
];
return $this->response('success', Code::SUCCESS, $data);
... ... @@ -180,13 +181,10 @@ class AdsController extends BaseController
return $this->response($res['msg'] ?? '验证失败,请稍后再试!', Code::USER_ERROR, []);
}
$agent = implode(',', array_map(function ($v){
return trim(explode('-', $v)[0]);
}, explode(',', $res['data'] ?? '')));
$data = [
'is_v6' => 0,
'agent' => $agent,
'agent' => $res['data'],
'agent_group' => trim(explode('-', explode(',', $res['data'] ?? '')[0])[0]),
'domain' => $domain,
];
return $this->response('success', Code::SUCCESS, $data);
... ...