作者 lyh

gx

@@ -95,7 +95,6 @@ class VideoTask extends Command @@ -95,7 +95,6 @@ class VideoTask extends Command
95 continue; 95 continue;
96 } 96 }
97 $keywordInfo = $this->getKeywordImage($val->id,$task_project->project_id); 97 $keywordInfo = $this->getKeywordImage($val->id,$task_project->project_id);
98 - @file_put_contents(storage_path('logs/lyh_error.log'), var_export($keywordInfo, true) . PHP_EOL, FILE_APPEND);  
99 $array = [ 98 $array = [
100 'project_id' => $task_project->project_id, 99 'project_id' => $task_project->project_id,
101 'keyword_id' => $val->id, 100 'keyword_id' => $val->id,
@@ -16,6 +16,8 @@ use App\Models\Manage\BelongingGroup; @@ -16,6 +16,8 @@ use App\Models\Manage\BelongingGroup;
16 use App\Models\Manage\Dept; 16 use App\Models\Manage\Dept;
17 use App\Models\Manage\EntryPosition; 17 use App\Models\Manage\EntryPosition;
18 use App\Models\Manage\ManageHr; 18 use App\Models\Manage\ManageHr;
  19 +use App\Models\Product\Keyword;
  20 +use App\Models\Product\Product;
19 use App\Models\Project\Project; 21 use App\Models\Project\Project;
20 use App\Models\WebSetting\WebSettingService; 22 use App\Models\WebSetting\WebSettingService;
21 use App\Services\ProjectServer; 23 use App\Services\ProjectServer;
@@ -260,17 +262,73 @@ class Demo extends Command @@ -260,17 +262,73 @@ class Demo extends Command
260 // } 262 // }
261 263
262 public function handle(){ 264 public function handle(){
263 - $projectModel = new Project();  
264 - $list = $projectModel->list(['delete_status'=>0]);  
265 - foreach ($list as $v){  
266 - ProjectServer::useProject($v['id']);  
267 - $webSettingServiceModel = new WebSettingService();  
268 - $info = $webSettingServiceModel->read(['values'=>['like','%+86%']]);  
269 - if($info !== false){  
270 - echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;  
271 - } 265 +// $projectModel = new Project();
  266 +// $list = $projectModel->list(['delete_status'=>0]);
  267 +// foreach ($list as $v){
  268 + ProjectServer::useProject(1);
  269 + $this->getKeywordImage();
272 DB::disconnect('custom_mysql'); 270 DB::disconnect('custom_mysql');
  271 +// }
  272 + }
  273 +
  274 + /**
  275 + * @remark :根据关键字获取产品主图
  276 + * @name :getKeywordList
  277 + * @author :lyh
  278 + * @method :post
  279 + * @time :2024/2/23 16:28
  280 + */
  281 + public function getKeywordImage($keyword_id = 14,$project_id = 1){
  282 + $keywordModel = new Keyword();
  283 + $thumb = $keywordInfo = $keywordModel->read(['id'=>$keyword_id]);
  284 + //TODO::所有产品
  285 + $this->getRecommendAndHotProducts($keywordInfo['route'],$project_id);
  286 + $domainModel = new DomainInfo();
  287 + $domainInfo = $domainModel->read(['project_id'=>$project_id]);
  288 + if(!empty($domainInfo)){
  289 + $keywordInfo['route'] = $domainInfo['domain'].'/'.$keywordInfo['route'];
  290 + }
  291 + $data = [
  292 + 'url'=>$keywordInfo['route'],
  293 + 'title'=>$keywordInfo['title'],
  294 + 'keyword_title'=>$keywordInfo['keyword_title'],
  295 + 'keyword_content'=>$keywordInfo['keyword_content'],
  296 + 'product_list'=>$thumb ?? []
  297 + ];
  298 + echo '返回数据'.json_encode($data);
  299 + return $data;
  300 + }
  301 +
  302 + /**
  303 + * 关键词聚合页-推荐&热门产品
  304 + */
  305 + public function getRecommendAndHotProducts($project_id,$route): ?array
  306 + {
  307 + $productIds = [];
  308 + $productKeyword = Keyword::where("project_id",$project_id)->where("route",$route)->first();
  309 + if (!empty($productKeyword)){
  310 + $productsQuery = Product::where("project_id", $project_id)->where("status",1)->where("keyword_id","like","%,".$productKeyword->id.",%")->limit(7)->get();
  311 + if (!empty($productsQuery)){
  312 + foreach ($productsQuery as $item){
  313 + $productIds[] = $item->id;
  314 + }
  315 + if (count($productIds)<7){
  316 + $randomData = Product::where("project_id", $project_id)->where("status",1)->whereNotIn('id', $productIds)->inRandomOrder()->take(13-count($productIds))->get();
  317 + $products = $productsQuery->merge($randomData);
  318 + }else{
  319 + $products = $productsQuery;
  320 + }
  321 + }else{
  322 + $products = Product::where("project_id", $project_id)->where("status",1)->inRandomOrder()->take(13)->get();
  323 + }
  324 + }
  325 + $data = [];
  326 + if (!empty($products)){
  327 + foreach ($products as $item){
  328 + $data[] = !empty($item->thumb) && $item->thumb['url'] != "" ? getImageUrl($item->thumb['url']) : "";
  329 + }
273 } 330 }
  331 + return $data;
274 } 332 }
275 public function printMessage() 333 public function printMessage()
276 { 334 {