作者 lyh

gx

... ... @@ -135,7 +135,6 @@ class VideoTask extends Command
],
'task_id' => $task_id,
'callback_url' => env('APP_URL') . '/api/video_task_callback',
// 'callback_url' => url('a/getKeywordVideo?project_id='.$val->project_id.'&keyword_id='.$val->keyword_id.'&video='),
];
$result = Http::post('http://216.250.255.116:7866/create_task', $data);
$val->task_id = $task_id;
... ... @@ -176,26 +175,9 @@ class VideoTask extends Command
*/
public function getKeywordImage($keyword_id,$project_id){
$keywordModel = new Keyword();
$keywordInfo = $keywordModel->read(['id'=>$keyword_id]);
$productModel = new Product();
$productList = $productModel->list(['keyword_id'=>['like','%,'.$keywordInfo['id'].',%']],['thumb','title']);
if(count($productList) < 5){
$productList = $productModel->inRandomOrder()->take(100)->get()->toArray();
//获取7个产品主图
}
$product_image = [];
foreach ($productList as $v){
$v = (array)$v;
$image = [];
if(!empty($v['thumb']) && !empty($v['thumb']['url'])){
$image['image'] = getImageUrl($v['thumb']['url']);
$image['title'] = $v['title'];
$product_image[] = $image;
}
if(count($product_image) > 6){
break;
}
}
$thumb = $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)){
... ... @@ -206,8 +188,41 @@ class VideoTask extends Command
'title'=>$keywordInfo['title'],
'keyword_title'=>$keywordInfo['keyword_title'],
'keyword_content'=>$keywordInfo['keyword_content'],
'product_list'=>$product_image
'product_list'=>$thumb ?? []
];
return $data;
}
/**
* 关键词聚合页-推荐&热门产品
*/
public function getRecommendAndHotProducts($project,$route): ?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 != "[]"? getImageUrl(json_decode($item->thumb)->url) : "";
}
}
return $data;
}
}
... ...
... ... @@ -79,24 +79,24 @@ class NoticeController extends BaseController
$all = $request->all();
// 获取子任务
$log = KeywordVideoTaskLog::where(['task_id' => $task_id])->first();
if (empty($log))
if (empty($log)){
return 200;
}
// 更新子任务状态 更新任务信息
$log->status = KeywordVideoTaskLog::STATUS_FINISH;
$log->result_status = $status;
$log->result_info = json_encode($all);
$log->save();
if ($status != 200) {
return 200;
}
// 更新关键词信息
ProjectServer::useProject($log->project_id);
$keyword = Keyword::where(['id' => $log->keyword_id])->first();
// 关键词可能已被删除
if (empty($keyword))
if (empty($keyword)){
return 200;
}
$keyword->video = $video;
$keyword->embed_code = $embed_code;
$keyword->video_thumb = $thumb;
... ...
... ... @@ -103,23 +103,4 @@ class IndexController extends BaseController
}
$this->response('success');
}
/**
* @remark :根据关键字获取产品主图
* @name :getKeywordList
* @author :lyh
* @method :post
* @time :2024/2/23 16:28
*/
public function getKeywordVideo(){
ProjectServer::useProject($this->param['project_id']);
$keywordModel = new Keyword();
$rs = $keywordModel->edit(['video'=>$this->param['video']],['id'=>$this->param['keyword_id']]);
if($rs === false){
Log::info('回调失败.'.$this->param['project_id'].'video:'.$this->param['video']);
}
DB::disconnect('custom_mysql');
$this->response('success');
}
}
... ...
... ... @@ -389,7 +389,6 @@ Route::group([], function () {
Route::any('/collect', [Aside\Collect\CollectController::class, 'index'])->name('admin.collect');
//同步询盘
Route::any('/sync_inquiry', [Aside\Com\IndexController::class, 'sync_inquiry'])->name('admin.sync_inquiry');
Route::any('/getKeywordVideo', [Aside\Com\IndexController::class, 'getKeywordVideo'])->name('admin.getKeywordVideo');
});
... ...