PopularTemplateLabel.php
3.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* @remark :
* @name :PopularTemplateLabel.php
* @author :lyh
* @method :post
* @time :2024/6/3 17:00
*/
namespace App\Console\Commands\TemplateLabel;
use App\Models\Template\Template;
use App\Models\Template\TemplateLabel as TemplateLabelModel;
use App\Models\Template\TemplateModule;
use Illuminate\Console\Command;
class PopularTemplateLabel extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'popular_template_label';
/**
* The console command description.
*
* @var string
*/
protected $description = '设置热门label';
/**
* @remark :执行脚本
* @name :handle
* @author :lyh
* @method :post
* @time :2024/6/3 17:01
*/
public function handle(){
$this->setTemplate();
$this->setTemplateModule();
return true;
}
/**
* @remark :公共模块热门模块
* @name :setTemplate
* @author :lyh
* @method :post
* @time :2024/6/3 15:56
*/
public function setTemplate(){
$templateModel = new Template();
$info = $templateModel->list(['test_model'=>0,'number'=>['<>',0]],'number',['id'],'desc',50);
if(empty($info)){
return true;
}else{
//清除当前所有最新标签
$labelModel = new TemplateLabelModel();
$labelModel->del(['name'=>'热门','type'=>1]);
$data = [];
foreach ($info as $v){
$data[] = [
'name'=>'热门',
'type'=>1,
'template_id'=>$v['id'],
'manager_id'=>0,
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s')
];
}
//设置为最新
$labelModel->insert($data);
}
return true;
}
/**
* @remark :左侧模块
* @name :templateModule
* @author :lyh
* @method :post
* @time :2024/6/3 15:54
*/
public function setTemplateModule(){
$templateModuleModel = new TemplateModule();
$moduleInfo = $templateModuleModel->list(['test_model'=>0,'number'=>['<>',0]],'id',['id']);
if(empty($moduleInfo)){
return true;
}else{
//清除当前所有最新标签
$labelModel = new TemplateLabelModel();
$labelModel->del(['name'=>'热门','type'=>2]);
$moduleData = [];
foreach ($moduleInfo as $k => $v){
$moduleData[] = [
'name'=>'热门',
'type'=>2,
'template_id'=>$v['id'],
'manager_id'=>0,
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s')
];
}
//设置为最新
$labelModel->insert($moduleData);
}
return true;
}
}