LiuJ 4 days ago
parent
commit
62ff4c3f12
1 changed files with 53 additions and 1 deletions
  1. 53 1
      app/JsonRpc/NewsService.php

+ 53 - 1
app/JsonRpc/NewsService.php

@@ -3293,10 +3293,36 @@ class NewsService implements NewsServiceInterface
     $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
     $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
     $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
-    unset($data['imgUrl']);
+    unset($data['imgUrl']); //大小写
     if (isset($data['price']) && $data['price'] == '') {
       $data['price'] =  0;
     }
+
+    if ($data['imgurl'] == '') {
+      $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
+      preg_match_all($reg, $data['detail'], $matches);
+      if (isset($matches[1][0])) {
+        //截取varchar240
+        $data['imgurl'] = substr($matches[1][0], 0, 240);
+      }
+    }
+    if ($data['keyword'] == '' ||  $data['keyword'] == array()) {
+      //提取标题+内容中的关键词
+      $data['keyword'] = $data['name'];
+      //  . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
+      Jieba::init(); // 初始化 jieba-php
+      Finalseg::init();
+      $segList = Jieba::cut($data['keyword']);
+      $segList1 = array_slice($segList, 0, 8);
+      $data['keyword'] = implode(',', $segList1);
+    }
+    if ($data['description'] == '') {
+      //提取内容中的描述
+      $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
+    }
+
+
+
     $result = Good::insert($data);
     if (empty($result)) {
       return Result::error("添加失败", 0);
@@ -3316,6 +3342,32 @@ class NewsService implements NewsServiceInterface
     if (isset($data['price']) && $data['price'] == '') {
       $data['price'] =  0;
     }
+
+
+    if ($data['imgurl'] == '') {
+      $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
+      preg_match_all($reg, $data['detail'], $matches);
+      if (isset($matches[1][0])) {
+        //截取varchar240
+        $data['imgurl'] = substr($matches[1][0], 0, 240);
+      }
+    }
+    if ($data['keyword'] == '' ||  $data['keyword'] == array()) {
+      //提取标题+内容中的关键词
+      $data['keyword'] = $data['name'];
+      //  . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
+      Jieba::init(); // 初始化 jieba-php
+      Finalseg::init();
+      $segList = Jieba::cut($data['keyword']);
+      $segList1 = array_slice($segList, 0, 8);
+      $data['keyword'] = implode(',', $segList1);
+    }
+    if ($data['description'] == '') {
+      //提取内容中的描述
+      $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
+    }
+
+
     $result = Good::where('id', $data['id'])->update($data);
     if (empty($result)) {
       return Result::error("更新失败", 0);