作者 lyh

gx

... ... @@ -9,11 +9,16 @@ namespace App\Console\Commands\KeywordInVideo;
use App\Console\Commands\Model;
use App\Console\Commands\TaskSub;
use App\Enums\Common\Code;
use App\Models\Com\KeywordVideoTask;
use App\Models\Com\KeywordVideoTaskLog;
use App\Models\Domain\DomainInfo;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
... ... @@ -89,11 +94,12 @@ class VideoTask extends Command
if ($log){
continue;
}
$keywordInfo = $this->getKeywordImage($val->id,$task_project->project_id);
$array = [
'project_id' => $task_project->project_id,
'keyword_id' => $val->id,
'keyword' => $val->title,
'data' => json_encode(['url' => '', 'description' => '', 'images' => [], 'keywords' => []]),
'data' => json_encode(['url' => $keywordInfo['url'],'title' => $keywordInfo['title'], 'description' => $keywordInfo['keyword_content'], 'images' => $keywordInfo['product_list'], 'keywords' => []]),
'status' => KeywordVideoTaskLog::STATUS_INIT,
'updated_at' => date('Y-m-d H:i:s'),
'created_at' => date('Y-m-d H:i:s'),
... ... @@ -117,22 +123,22 @@ class VideoTask extends Command
if ($subTask->isEmpty())
return true;
foreach ($subTask as $val) {
$valData = json_decode($val->data);
$task_id = 'v6-' . uniqid();
$data = [
'project_data' => [
'tag_url' => '',
'title' => '',
'tag_url' => $valData['url'],
'title' => $valData['title'],
'keywords' => [],
'description' => '',
'images' => ''
'description' => $valData['description'],
'images' => $valData['images']
],
'task_id' => $task_id,
'callback_url' => '',
'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;
$val->status = STATUS_RUNING::STATUS_RUNING;
$val->status = KeywordVideoTaskLog::STATUS_RUNING;
$val->request_result = $result;
$val->save();
}
... ... @@ -159,4 +165,47 @@ class VideoTask extends Command
$project_id = 110;
return $project_id;
}
/**
* @remark :根据关键字获取产品主图
* @name :getKeywordList
* @author :lyh
* @method :post
* @time :2024/2/23 16:28
*/
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->list([],'sort',['thumb','title']);
//获取7个产品主图
}
$product_image = [];
foreach ($productList as $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;
}
}
$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'=>$product_image
];
return $data;
}
}
... ...
... ... @@ -17,6 +17,7 @@ use App\Services\ProjectServer;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Log;
/**
* Class IndexController
... ... @@ -110,52 +111,15 @@ class IndexController extends BaseController
* @method :post
* @time :2024/2/23 16:28
*/
public function getKeywordImage(){
$arr = explode('/',trim(str_replace('https://', '', $this->param['url']),'/'));
if(empty($arr) || !is_array($arr)){
$this->response('当前项目不存在..',Code::SYSTEM_ERROR);
}
$domainModel = new DomainInfo();
$domainInfo = $domainModel->read(['domain'=>$arr[0]]);
if($domainInfo === false){
$this->response('当前项目不存在.',Code::SYSTEM_ERROR);
}
ProjectServer::useProject($domainInfo['project_id']);
$routeMapModel = new RouteMap();
$routeInfo = $routeMapModel->read(['route'=>$arr[1]]);
if($domainInfo === false){
$this->response('当前路由不存在.',Code::SYSTEM_ERROR);
}
public function getKeywordVideo(){
ProjectServer::useProject($this->param['project_id']);
$keywordModel = new Keyword();
$keywordInfo = $keywordModel->read(['id'=>$routeInfo['source_id']]);
$count = Product::where('keyword_id','like' ,'%,'.$keywordInfo['id'].',%')->count();
$productModel = new Product();
if($count < 5){
$productList = $productModel->list([],'sort',['thumb','title']);
//获取7个产品主图
}else{
$productList = $productModel->list(['keyword_id'=>['like','%,'.$keywordInfo['id'].',%']],['thumb','title']);
}
$product_image = [];
foreach ($productList as $k => $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;
}
$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']);
}
$data = [
'title'=>$keywordInfo['title'],
'keyword_title'=>$keywordInfo['keyword_title'],
'keyword_content'=>$keywordInfo['keyword_content'],
'product_list'=>$product_image
];
DB::disconnect('custom_mysql');
$this->response('success',Code::SUCCESS,$data);
$this->response('success');
}
}
... ...
... ... @@ -14,7 +14,7 @@ use App\Models\Base;
class KeywordVideoTaskLog extends Base
{
const STATUS_INIT = 0;
const STATUS_RUNING = 0;
const STATUS_RUNING = 1;
protected $table = 'gl_keyword_video_task_log';
}
... ...
... ... @@ -389,7 +389,7 @@ 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('/getKeywordImage', [Aside\Com\IndexController::class, 'getKeywordImage'])->name('admin.getKeywordImage');
Route::any('/getKeywordVideo', [Aside\Com\IndexController::class, 'getKeywordVideo'])->name('admin.getKeywordVideo');
});
... ...