作者 张关杰

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into bate

... ... @@ -81,6 +81,13 @@ class VideoTask extends Command
if (empty($task_project)){
break;
}
$domainModel = new DomainInfo();
$domainInfo = $domainModel->read(['project_id'=>$task_project->project_id]);
if($domainInfo === false){
$task_project->status = KeywordVideoTask::STATUS_CLOSE;
$task_project->save();
continue;
}
ProjectServer::useProject($task_project->project_id);
$keyword = $this->getProjectKeyword();
// 已经没有需要生成视频的关键词
... ... @@ -94,12 +101,12 @@ class VideoTask extends Command
if ($log){
continue;
}
$keywordInfo = $this->getKeywordImage($val->id,$task_project->project_id);
$keywordInfo = $this->getKeywordImage($val->id,$task_project->project_id,$domainInfo['domain']);
$array = [
'project_id' => $task_project->project_id,
'keyword_id' => $val->id,
'keyword' => $val->title,
'data' => json_encode(['url' => $keywordInfo['url'],'title' => $keywordInfo['title'], 'description' => $keywordInfo['keyword_content'], 'images' => $keywordInfo['product_list'], 'keywords' => []]),
'data' => json_encode(['url' => $keywordInfo['url'],'title' => $keywordInfo['title'], 'description' => $keywordInfo['keyword_content'], 'images' => $keywordInfo['product_list'], 'keywords' => $keywordInfo['keyword_list']]),
'status' => KeywordVideoTaskLog::STATUS_INIT,
'updated_at' => date('Y-m-d H:i:s'),
'created_at' => date('Y-m-d H:i:s'),
... ... @@ -129,7 +136,7 @@ class VideoTask extends Command
'project_data' => [
'tag_url' => $valData['url'],
'title' => $valData['title'],
'keywords' => [],
'keywords' => $valData['keywords'],
'description' => $valData['description'],
'images' => $valData['images']
],
... ... @@ -173,22 +180,19 @@ class VideoTask extends Command
* @method :post
* @time :2024/2/23 16:28
*/
public function getKeywordImage($keyword_id,$project_id){
public function getKeywordImage($keyword_id,$project_id,$domain){
$keywordModel = new Keyword();
$thumb = $keywordInfo = $keywordModel->read(['id'=>$keyword_id]);
$keywordInfo = $keywordModel->read(['id'=>$keyword_id]);
//TODO::所有产品
$this->getRecommendAndHotProducts($keywordInfo['route'],$project_id);
$domainModel = new DomainInfo();
$domainInfo = $domainModel->read(['project_id'=>$project_id]);
if(!empty($domainInfo)){
$keywordInfo['route'] = $domainInfo['domain'].'/'.$keywordInfo['route'];
}
$thumb = $this->getRecommendAndHotProducts($keywordInfo['route'],$project_id);
$keyword_arr = Keyword::where("project_id",$project_id)->where("status",1)->inRandomOrder()->take(10)->pluck('title')->toArray();;
$data = [
'url'=>$keywordInfo['route'],
'url'=>$domain.'/'.$keywordInfo['route'],
'title'=>$keywordInfo['title'],
'keyword_title'=>$keywordInfo['keyword_title'],
'keyword_content'=>$keywordInfo['keyword_content'],
'product_list'=>$thumb ?? []
'product_list'=>$thumb ?? [],
'keyword_list'=>$keyword_arr ?? []
];
return $data;
}
... ... @@ -196,7 +200,7 @@ class VideoTask extends Command
/**
* 关键词聚合页-推荐&热门产品
*/
public function getRecommendAndHotProducts($project_id,$route): ?array
public function getRecommendAndHotProducts($route,$project_id): ?array
{
$productIds = [];
$productKeyword = Keyword::where("project_id",$project_id)->where("route",$route)->first();
... ... @@ -225,4 +229,6 @@ class VideoTask extends Command
return $data;
}
}
... ...
... ... @@ -64,10 +64,11 @@ class RankData extends BaseCommands
return false;
}
foreach ($list as $item){
echo $item['api_no'] . PHP_EOL;
try {
(new RankDataLogic())->syncRankData($item['api_no'], $site_res);
}catch (\Exception $e){
Log::channel('rank_data')->error('RankData:失败 ' . $e->getMessage());
Log::channel('rank_data')->error('RankData:失败 ' . $item['api_no'] . $e->getMessage());
$error++;
continue;
}
... ...
... ... @@ -16,6 +16,8 @@ use App\Models\Manage\BelongingGroup;
use App\Models\Manage\Dept;
use App\Models\Manage\EntryPosition;
use App\Models\Manage\ManageHr;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\Project\Project;
use App\Models\WebSetting\WebSettingService;
use App\Services\ProjectServer;
... ... @@ -260,17 +262,73 @@ class Demo extends Command
// }
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['delete_status'=>0]);
foreach ($list as $v){
ProjectServer::useProject($v['id']);
$webSettingServiceModel = new WebSettingService();
$info = $webSettingServiceModel->read(['values'=>['like','%+86%']]);
if($info !== false){
echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
}
// $projectModel = new Project();
// $list = $projectModel->list(['delete_status'=>0]);
// foreach ($list as $v){
ProjectServer::useProject(150);
$this->getKeywordImage();
DB::disconnect('custom_mysql');
// }
}
/**
* @remark :根据关键字获取产品主图
* @name :getKeywordList
* @author :lyh
* @method :post
* @time :2024/2/23 16:28
*/
public function getKeywordImage($keyword_id = 1,$project_id = 150){
$keywordModel = new Keyword();
$keywordInfo = $keywordModel->read(['id'=>$keyword_id]);
//TODO::所有产品
$thumb = $this->getRecommendAndHotProducts($keywordInfo['route'],$project_id);
$domainModel = new DomainInfo();
$domainInfo = $domainModel->read(['project_id'=>$project_id]);
if(!empty($domainInfo)){
$keywordInfo['route'] = $domainInfo['domain'].'/'.$keywordInfo['route'];
}
$data = [
'url'=>$keywordInfo['route'],
'title'=>$keywordInfo['title'],
'keyword_title'=>$keywordInfo['keyword_title'],
'keyword_content'=>$keywordInfo['keyword_content'],
'product_list'=>$thumb ?? []
];
dd($data);
return $data;
}
/**
* 关键词聚合页-推荐&热门产品
*/
public function getRecommendAndHotProducts($route,$project_id): ?array
{
$productIds = [];
$productKeyword = Keyword::where("project_id",$project_id)->where("route",$route)->first();
if (!empty($productKeyword)){
$productsQuery = Product::where("project_id", $project_id)->where("status",1)->where("keyword_id","like","%,".$productKeyword->id.",%")->limit(7)->get();
if (!empty($productsQuery)){
foreach ($productsQuery as $item){
$productIds[] = $item->id;
}
if (count($productIds)<7){
$randomData = Product::where("project_id", $project_id)->where("status",1)->whereNotIn('id', $productIds)->inRandomOrder()->take(13-count($productIds))->get();
$products = $productsQuery->merge($randomData);
}else{
$products = $productsQuery;
}
}else{
$products = Product::where("project_id", $project_id)->where("status",1)->inRandomOrder()->take(13)->get();
}
}
$data = [];
if (!empty($products)){
foreach ($products as $item){
$data[] = !empty($item->thumb) && $item->thumb['url'] != "" ? getImageUrl($item->thumb['url']) : "";
}
}
return $data;
}
public function printMessage()
{
... ...
... ... @@ -75,13 +75,13 @@ class QuanqiusouApi
/**
* 获取谷歌排名数据
* @param $api_no
* @param int $lang
* @param string $lang
* @param int $day
* @return array|false|mixed
* @author zbj
* @date 2023/5/11
*/
public function getGoogleRank($api_no, int $lang = 0, int $day = 7, $force = true)
public function getGoogleRank($api_no, string $lang = '', int $day = 7, $force = true)
{
$key = "quanqiusou_api_rank_{$api_no}_{$lang}_{$day}_" . date('Y-m-d');
$res = Cache::get($key);
... ...
... ... @@ -12,6 +12,7 @@ namespace App\Http\Controllers\Aside\Com;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Models\Com\KeywordVideoTask;
use App\Models\Domain\DomainInfo;
class KeywordVideoController extends BaseController
{
... ... @@ -43,6 +44,12 @@ class KeywordVideoController extends BaseController
'project_id.required' => '项目唯一标识不为空',
'number.required' => 'number不为空',
]);
//查看当前项目是否有正式域名
$domainModel = new DomainInfo();
$info = $domainModel->read(['project_id'=>$this->param['project_id']]);
if($info === false){
$this->response('请先设置域名',Code::SYSTEM_ERROR);
}
$keywordModel = new KeywordVideoTask();
$rs = $keywordModel->add($this->param);
if($rs === false){
... ...
... ... @@ -379,7 +379,7 @@ class RankDataLogic extends BaseLogic
$model = RankData::where('project_id', $project_id)->where('lang', '')->first();
if (!$model || $model->updated_date != date('Y-m-d') || $force) {
$res = $api->getGoogleRank($api_no, 0, 7, $force);
$res = $api->getGoogleRank($api_no, '', 7, $force);
if (!$res) {
throw new \Exception("接口数据获取失败,api_no:{$api_no}");
}
... ... @@ -392,7 +392,7 @@ class RankDataLogic extends BaseLogic
if (!empty($lang_list[$api_no])) {
$model = RankData::where('project_id', $project_id)->where('lang', '<>', '')->first();
if (!$model || $model->updated_date != date('Y-m-d') || $force) {
$res = $api->getGoogleRank($api_no, $model->lang, 7, $force);
$res = $api->getGoogleRank($api_no, $lang_list[$api_no], 7, $force);
if (!$res) {
throw new \Exception("接口数据获取失败,api_no:{$api_no},lang");
}
... ... @@ -426,15 +426,15 @@ class RankDataLogic extends BaseLogic
if(!$lang){
foreach ($data as &$ranks){
ksort($ranks);
foreach ($ranks as &$rank){
//处理排名
if(!in_array($project_id, $without_project_ids)){
if($rank['position'] >= 10){
$rank['position'] -= 5;
}
//todo 需要特殊处理排名的项目
}
}
// foreach ($ranks as &$rank){
// //处理排名
// if(!in_array($project_id, $without_project_ids)){
// if($rank['position'] >= 10){
// $rank['position'] -= 5;
// }
// //todo 需要特殊处理排名的项目
// }
// }
$last = Arr::last($ranks);
//第一名
if($last['position'] == 1){
... ...