KeywordVideoController.php
6.9 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
/**
* @remark :
* @name :KeywordVideoController.php
* @author :lyh
* @method :post
* @time :2024/2/26 9:23
*/
namespace App\Http\Controllers\Aside\KeywordVideo;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Models\Com\KeywordVideoTask;
use App\Models\Com\KeywordVideoTaskLog;
use App\Models\Domain\DomainInfo;
use Illuminate\Support\Facades\Cache;
class KeywordVideoController extends BaseController
{
/**
* @remark :任务列表
* @name :lists
* @author :lyh
* @method :post
* @time :2024/2/26 11:36
*/
public function lists(){
$keywordModel = new KeywordVideoTask();
$query = $keywordModel->leftJoin('gl_project', 'gl_keyword_video_task.project_id', '=', 'gl_project.id');
$query = $this->searchParam($query);
$query = $this->orderByList($query);
$lists = $query->paginate($this->row, $this->selectParam(), 'page', $this->page)->toArray();
$this->response('success',Code::SUCCESS,$lists);
}
/**
* 需要查询的字段
* @return array
*/
public function selectParam(){
$select = [
'gl_keyword_video_task.id AS id',
'gl_keyword_video_task.project_id AS project_id',
'gl_keyword_video_task.number AS number',
'gl_keyword_video_task.status AS status',
'gl_keyword_video_task.keywords AS keywords',
'gl_keyword_video_task.sort AS sort',
'gl_keyword_video_task.created_at AS created_at',
'gl_keyword_video_task.updated_at AS updated_at',
'gl_project.title AS title',
'gl_project.company AS company',
];
return $select;
}
/**
* @remark :搜索参数处理
* @name :searchParam
* @author :lyh
* @method :post
* @time :2023/8/18 10:58
*/
public function searchParam(&$query){
if(isset($this->map['title'])){
$query->where('gl_project.title','like','%'.$this->map['title'].'%');
}
if(isset($this->map['status'])){
$query->where('gl_keyword_video_task.status',$this->map['status']);
}
return $query;
}
/**
* @remark :排序
* @name :orderByList
* @author :lyh
* @method :post
* @time :2023/12/29 17:14
*/
public function orderByList(&$query){
$query = $query->orderBy('gl_keyword_video_task.sort', 'desc')->orderBy('gl_keyword_video_task.id', 'desc');
return $query;
}
/**
* @remark :创建关键字任务池子
* @name :saveKeyword
* @author :lyh
* @method :post
* @time :2024/2/26 9:24
*/
public function createKeywordTask(){
$this->request->validate([
'project_id'=>'required',
'number'=>'required'
], [
'project_id.required' => '项目唯一标识不为空',
'number.required' => 'number不为空',
]);
//查看当前项目是否已添加
$keywordModel = new KeywordVideoTask();
$keywordInfo = $keywordModel->read(['project_id'=>$this->param['project_id']]);
if($keywordInfo !== false){
$this->response('当前项目已添加');
}
//查看当前项目是否有正式域名
$domainModel = new DomainInfo();
$info = $domainModel->read(['project_id'=>$this->param['project_id']]);
if($info === false){
$this->response('请先设置域名',Code::SYSTEM_ERROR);
}
//组装数据
$data = [
'project_id'=>$this->param['project_id'],
'number'=>$this->param['number'],
'status'=>$this->param['status'] ?? 0,
'sort'=>$this->param['sort'] ?? 0,
'keywords'=>$this->param['keywords'] ?? '',
'logo_img'=>$this->param['logo_img'] ?? '',
'template_data'=>isset($this->param['template_data']) ? json_encode($this->param['template_data'],true) : null
];
$rs = $keywordModel->add($data);
if($rs === false){
$this->response('添加失败',Code::SYSTEM_ERROR);
}
$this->response('success');
}
/**
* @remark :修改项目
* @name :editSort
* @author :lyh
* @method :post
* @time :2024/2/26 11:35
*/
public function edit(){
$this->request->validate([
'id'=>'required'
], [
'id.required' => '主键标识不为空',
]);
$keywordModel = new KeywordVideoTask();
$rs = $keywordModel->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->response('编辑失败',Code::SYSTEM_ERROR);
}
$this->response('success');
}
/**
* @remark :记录
* @name :getVideoTaskLog
* @author :lyh
* @method :post
* @time :2024/3/1 16:40
*/
public function getVideoTaskLog(){
$this->request->validate([
'project_id'=>'required',
], [
'project_id.required' => '项目唯一标识不为空',
]);
$taskLogModel = new KeywordVideoTaskLog();
$list = $taskLogModel->lists($this->map,$this->page,$this->row);
$this->response('success',Code::SUCCESS,$list);
}
/**
* @remark :获取任务数量
* @name :taskNum
* @author :lyh
* @method :post
* @time :2024/6/13 16:16
*/
public function taskNum(){
$keywordModel = new KeywordVideoTask();
$data['total'] = $keywordModel->count();
$data['start_total'] = $keywordModel->formatQuery(['status'=>0])->count();
$data['end_total'] = $keywordModel->formatQuery(['status'=>1])->count();
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :当月视频总数量
* @name :getVideoCount
* @author :lyh
* @method :post
* @time :2024/8/14 9:58
*/
public function getVideoCount(){
// 当月的开始时间
$start_of_month = date("Y-m-01 00:00:00");
// 当月的结束时间:使用 strtotime() 计算最后一天
$end_of_month = date("Y-m-d 23:59:59", strtotime("last day of this month"));
$taskLogModel = new KeywordVideoTaskLog();
$count = $taskLogModel->formatQuery(['created_at'=>['between',[$start_of_month,$end_of_month]]])->count();
$this->response('success',Code::SUCCESS,['count'=>$count]);
}
/**
* @remark :获取模版库模版
* @name :get_template
* @author :lyh
* @method :post
* @time :2024/11/1 11:48
*/
public function get_template(){
$data = Cache::get('template_data');
if(empty($data)){
$url = 'http://216.250.255.116:7866/get_template';
$header = [
'accept: application/json'
];
$data = http_get($url,$header);
}
$this->response('success',Code::SUCCESS,$data);
}
}