作者 赵彬吉
... ... @@ -18,6 +18,7 @@ yarn-error.log
/.vscode
composer.lock
app/Console/Commands/Test/Demo.php
app/Console/Commands/Test/DataRecovery.php
/public/upload
/public/runtime
public/nginx.htaccess
... ...
... ... @@ -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'),
... ... @@ -113,26 +119,26 @@ class VideoTask extends Command
*/
public function sendSubTask()
{
$subTask = KeywordVideoTaskLog::where(['status' => TaskSub::STATUS_INIT])->orderBy('id', 'asc')->limit($this->max_sub_task)->get();
$subTask = KeywordVideoTaskLog::where(['status' => KeywordVideoTaskLog::STATUS_INIT])->orderBy('id', 'asc')->limit($this->max_sub_task)->get();
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' => env('APP_URL') . '/api/video_task_callback',
];
$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_RUNNING;
$val->request_result = $result;
$val->save();
}
... ... @@ -159,4 +165,64 @@ 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]);
//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 ?? []
];
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;
}
}
... ...
... ... @@ -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()
{
... ...
... ... @@ -7,9 +7,13 @@
*/
namespace App\Http\Controllers\Api;
use App\Models\Com\KeywordVideoTaskLog;
use App\Models\Product\Keyword;
use App\Models\Visit\SyncSubmitTask;
use App\Models\Visit\Visit;
use App\Services\ProjectServer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
/**
* Class NoticeController
... ... @@ -58,4 +62,46 @@ class NoticeController extends BaseController
SyncSubmitTask::createTask($array, SyncSubmitTask::TYPE_VISIT);
return $this->success([]);
}
/**
* 生成视频任务回调
* @param Request $request
* @return int
*/
public function videoTaskCallback(Request $request)
{
// 获取参数
$task_id = $request->input('task_id');
$status = intval($request->input('status', 0));
$thumb = $request->input('video_thumb');
$video = $request->input('callback_resource');
$embed_code = $request->input('embed_code');
$all = $request->all();
// 获取子任务
$log = KeywordVideoTaskLog::where(['task_id' => $task_id])->first();
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)){
return 200;
}
$keyword->video = $video;
$keyword->embed_code = $embed_code;
$keyword->video_thumb = $thumb;
$keyword->save();
DB::disconnect('custom_mysql');
return 200;
}
}
... ...
... ... @@ -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
... ... @@ -102,60 +103,4 @@ class IndexController extends BaseController
}
$this->response('success');
}
/**
* @remark :根据关键字获取产品主图
* @name :getKeywordList
* @author :lyh
* @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);
}
$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;
}
}
$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);
}
}
... ...
... ... @@ -7,6 +7,8 @@ use App\Enums\Common\Code;
use App\Http\Logic\Aside\LoginLogic;
use App\Models\Domain\DomainInfo;
use App\Models\Manage\Manage;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\Project\Project;
use App\Models\Sms\SmsLog;
use App\Rules\Mobile;
... ...
... ... @@ -82,16 +82,26 @@ class CreateKeywordLogic extends BaseLogic
if(empty($this->param['keyword'])){
return $this->success($data);
}
$prefix_keyword = $this->prefixKeyword($this->param['prefix'] ?? [],$this->param['keyword']);
$keyword_suffix = $this->keywordSuffix($this->param['suffix'] ?? [],$this->param['keyword']);
$prefix_keyword_suffix = $this->prefixKeywordSuffix($this->param['prefix'] ?? [],$this->param['suffix'] ?? [],$this->param['keyword']);
$except_k = ['Quality','Philippines','USA','UK','America','China','Wholesale','Hot Sale','Cheap','cheap','price','pricelist','hot sale','Price','Pricelist','With ','For ','And ','Oem','Odm','Supplier','Manufacturer','CE Certification','Factory','Exporters','Company','Companies','Suppliers','Manufacturers','Factories','Company','Companies','Exporters','Exporter','Buy ',' Buy','Where ','What ','When ','How ','Which ','Producer','Producers','Best Selling','Hot Selling','Near','Chinese','India','use','high quality','discount','online','custom','customized','Enterprise','Agent','Plant','Refinery','Foundry','Maker','Distributor'];
$filterKeywords = [];
foreach ($this->param['keyword'] as $k=>$v){
if(in_array($v,$except_k)){
unset($this->param['keyword'][$k]);
$filterKeywords[] = $v;
}
}
$prefix_keyword = $this->prefixKeyword($this->param['prefix'] ?? [],$this->param['keyword'],$except_k);
$keyword_suffix = $this->keywordSuffix($this->param['suffix'] ?? [],$this->param['keyword'],$except_k);
$prefix_keyword_suffix = $this->prefixKeywordSuffix($this->param['prefix'] ?? [],$this->param['suffix'] ?? [],$this->param['keyword'],$except_k);
$data = [
'prefix_keyword'=>$prefix_keyword,
'prefix_keyword_count'=>count($prefix_keyword),
'keyword_suffix'=>$keyword_suffix,
'keyword_suffix_count'=>count($keyword_suffix),
'prefix_keyword_suffix'=>$prefix_keyword_suffix,
'prefix_keyword_suffix_count'=>count($prefix_keyword_suffix)
'prefix_keyword_suffix_count'=>count($prefix_keyword_suffix),
'filterKeywords'=>$filterKeywords,
'filterKeywords_count'=>count($filterKeywords),
];
return $this->success($data);
}
... ... @@ -103,7 +113,7 @@ class CreateKeywordLogic extends BaseLogic
* @method :post
* @time :2023/12/19 11:11
*/
public function prefixKeyword($prefix,$keyword){
public function prefixKeyword($prefix,$keyword,$except_k){
$prefix_keyword = array();
if(!empty($prefix)){//前缀+关键词
foreach ($keyword as $keywordItem){
... ...
... ... @@ -96,7 +96,9 @@ class CountLogic extends BaseLogic
];
$data = $rankDataModel->read($param,['first_num','first_page_num','first_three_pages_num','first_five_pages_num','first_ten_pages_num']);
if($data === false){
$param['updated_date'] = Carbon::yesterday()->toDateString();
$param = [
'project_id' => $this->user['project_id']
];
$data = $rankDataModel->read($param,['first_num','first_page_num','first_three_pages_num','first_five_pages_num','first_ten_pages_num']);
if($data === false){
$data = [];
... ...
... ... @@ -16,5 +16,5 @@ class KeywordVideoTask extends Base
const STATUS_OPEN = 0;
const STATUS_CLOSE = 1;//停止
protected $table = 'gl_promotion_keyword_task';
protected $table = 'gl_keyword_video_task';
}
... ...
... ... @@ -14,7 +14,8 @@ use App\Models\Base;
class KeywordVideoTaskLog extends Base
{
const STATUS_INIT = 0;
const STATUS_RUNING = 0;
const STATUS_RUNNING = 1;
const STATUS_FINISH = 2;
protected $table = 'gl_keyword_video_task_log';
}
... ...
... ... @@ -24,3 +24,4 @@ Route::get('get_project_route', [\App\Http\Controllers\Api\PrivateController::cl
Route::any('get_product_images', [\App\Http\Controllers\Api\ProductController::class, 'getImages'])->name('api.get_product_images');
Route::post('inquiry_submit', [\App\Http\Controllers\Api\InquiryController::class, 'submit'])->name('api.inquiry_submit');
Route::post('video_task_callback', [\App\Http\Controllers\Api\NoticeController::class, 'videoTaskCallback'])->name('api.video_task_callback');
\ No newline at end of file
... ...
... ... @@ -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('/getKeywordImage', [Aside\Com\IndexController::class, 'getKeywordImage'])->name('admin.getKeywordImage');
});
... ...