作者 lyh
@@ -55,7 +55,7 @@ class VideoTask extends Command @@ -55,7 +55,7 @@ class VideoTask extends Command
55 /** 55 /**
56 * @var int 最大子任务 56 * @var int 最大子任务
57 */ 57 */
58 - public $max_sub_task = 800; 58 + public $max_sub_task = 200;
59 59
60 /** 60 /**
61 * @return bool 61 * @return bool
@@ -189,23 +189,39 @@ class VideoTask extends Command @@ -189,23 +189,39 @@ class VideoTask extends Command
189 } 189 }
190 190
191 /** 191 /**
192 - * @remark :根据关键字获取产品主图  
193 - * @name :getKeywordList  
194 - * @author :lyh  
195 - * @method :post  
196 - * @time :2024/2/23 16:28 192 + * 根据关键字获取产品主图
  193 + * @param $keyword_id
  194 + * @param $project_id
  195 + * @param $domain
  196 + * @return array
197 */ 197 */
198 public function getKeywordImage($keyword_id,$project_id,$domain){ 198 public function getKeywordImage($keyword_id,$project_id,$domain){
199 $keywordModel = new Keyword(); 199 $keywordModel = new Keyword();
200 $keywordInfo = $keywordModel->read(['id'=>$keyword_id]); 200 $keywordInfo = $keywordModel->read(['id'=>$keyword_id]);
  201 + // TODO 当内容太多时,生成视频过长, 尽量保证生成视频30秒左右, 所以需要控制文案内容长度
  202 + $content = $keywordInfo['keyword_content'];
  203 + $content_array = explode(" ", $content);
  204 + if (count($content_array) > 80) {
  205 + $content_array = preg_split("/[,,。]/u", $content);
  206 + $tmp = '';
  207 + foreach ($content_array as $val) {
  208 + $tmp .= $val . '.';
  209 + $tmp_array = explode(' ', $tmp);
  210 + if (count($tmp_array) > 60) {
  211 + $content = $tmp;
  212 + break;
  213 + }
  214 + }
  215 + }
  216 +
201 //TODO::所有产品 217 //TODO::所有产品
202 $thumb = $this->getRecommendAndHotProducts($keywordInfo['route'],$project_id); 218 $thumb = $this->getRecommendAndHotProducts($keywordInfo['route'],$project_id);
203 - $keyword_arr = Keyword::where("project_id",$project_id)->where("status",1)->inRandomOrder()->take(10)->pluck('title')->toArray();; 219 + $keyword_arr = Keyword::where("project_id",$project_id)->where("status",1)->inRandomOrder()->take(10)->pluck('title')->toArray();
204 $data = [ 220 $data = [
205 'url'=>$domain.'/'.$keywordInfo['route'], 221 'url'=>$domain.'/'.$keywordInfo['route'],
206 'title'=>$keywordInfo['title'], 222 'title'=>$keywordInfo['title'],
207 'keyword_title'=>$keywordInfo['keyword_title'], 223 'keyword_title'=>$keywordInfo['keyword_title'],
208 - 'keyword_content'=>$keywordInfo['keyword_content'], 224 + 'keyword_content'=>$content,
209 'product_list'=>$thumb ?? [], 225 'product_list'=>$thumb ?? [],
210 'keyword_list'=>$keyword_arr ?? [] 226 'keyword_list'=>$keyword_arr ?? []
211 ]; 227 ];
@@ -271,13 +287,13 @@ class VideoTask extends Command @@ -271,13 +287,13 @@ class VideoTask extends Command
271 } 287 }
272 288
273 /** 289 /**
274 - * @remark :获取图片  
275 - * @name :getImage  
276 - * @author :lyh  
277 - * @method :post  
278 - * @time :2024/3/12 15:29 290 + * 获取图片
  291 + * @param $domainInfo
  292 + * @return array
279 */ 293 */
280 public function getImage($domainInfo){ 294 public function getImage($domainInfo){
  295 + $logo = $bg = '';
  296 + try {
281 $dom = file_get_html('https://'.$domainInfo['domain'].'/'); 297 $dom = file_get_html('https://'.$domainInfo['domain'].'/');
282 $logoDom = $dom->find('.logo', 0)->find("img",0); 298 $logoDom = $dom->find('.logo', 0)->find("img",0);
283 if($logoDom != null){ 299 if($logoDom != null){
@@ -288,6 +304,9 @@ class VideoTask extends Command @@ -288,6 +304,9 @@ class VideoTask extends Command
288 $bg = $bgDom->src; 304 $bg = $bgDom->src;
289 } 305 }
290 $dom->clear(); 306 $dom->clear();
291 - return ['logo'=>$logo ?? '','bg'=>$bg ?? '']; 307 + } catch (\Exception $e) {
  308 + Log::error('file_get_html: ' . $domainInfo['domain'] . ', error message: ' . $e->getMessage());
  309 + }
  310 + return ['logo' => $logo, 'bg' => $bg];
292 } 311 }
293 } 312 }
@@ -665,8 +665,6 @@ class ProjectUpdate extends Command @@ -665,8 +665,6 @@ class ProjectUpdate extends Command
665 foreach ($item['extend'] as $ke => $ve) { 665 foreach ($item['extend'] as $ke => $ve) {
666 $extend = $extend_model->read(['title' => $ke]); 666 $extend = $extend_model->read(['title' => $ke]);
667 if ($extend) { 667 if ($extend) {
668 - $extend_info = $extend_info_model->read(['key' => $extend['key'], 'content_id' => $id]);  
669 - if (!$extend_info) {  
670 if ($extend['type'] == 3) { 668 if ($extend['type'] == 3) {
671 $gallery = []; 669 $gallery = [];
672 if (is_array($ve)) { 670 if (is_array($ve)) {
@@ -682,6 +680,9 @@ class ProjectUpdate extends Command @@ -682,6 +680,9 @@ class ProjectUpdate extends Command
682 } else { 680 } else {
683 $value = $ve; 681 $value = $ve;
684 } 682 }
  683 +
  684 + $extend_info = $extend_info_model->read(['key' => $extend['key'], 'content_id' => $id]);
  685 + if (!$extend_info) {
685 $extend_info_model->add([ 686 $extend_info_model->add([
686 'key' => $extend['key'], 687 'key' => $extend['key'],
687 'type' => $extend['type'], 688 'type' => $extend['type'],
@@ -690,6 +691,8 @@ class ProjectUpdate extends Command @@ -690,6 +691,8 @@ class ProjectUpdate extends Command
690 'module_id' => $custom_info['id'], 691 'module_id' => $custom_info['id'],
691 'values' => $value, 692 'values' => $value,
692 ]); 693 ]);
  694 + } else {
  695 + $extend_info_model->edit(['type' => $extend['type'], 'values' => $value], ['key' => $extend['key'], 'content_id' => $id]);
693 } 696 }
694 } 697 }
695 } 698 }