LiuJ 4 päivää sitten
vanhempi
sitoutus
6757aba587
1 muutettua tiedostoa jossa 214 lisäystä ja 208 poistoa
  1. 214 208
      app/JsonRpc/NewsService.php

+ 214 - 208
app/JsonRpc/NewsService.php

@@ -62,6 +62,7 @@ use App\Model\Idiom;
 use App\Model\WhiteRouter;
 use Illuminate\Support\Facades\Cache;
 use App\Model\Company;
+
 #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class NewsService implements NewsServiceInterface
 {
@@ -3318,7 +3319,9 @@ class NewsService implements NewsServiceInterface
     }
     if ($data['description'] == '') {
       //提取内容中的描述
-      $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
+      $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
+      $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
+      // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
     }
 
 
@@ -3364,7 +3367,8 @@ class NewsService implements NewsServiceInterface
     }
     if ($data['description'] == '') {
       //提取内容中的描述
-      $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
+      $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
+      $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
     }
 
 
@@ -5125,7 +5129,8 @@ class NewsService implements NewsServiceInterface
     }
     if ($data['description'] == '') {
       //提取内容中的描述
-      $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
+      $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
+      $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
     }
     var_dump($data, '--');
 
@@ -5216,7 +5221,8 @@ class NewsService implements NewsServiceInterface
     }
     if ($data['description'] == '') {
       //提取内容中的描述
-      $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
+      $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
+      $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
     }
     $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
     $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
@@ -5847,216 +5853,216 @@ class NewsService implements NewsServiceInterface
     return Result::success($result);
   }
   /**
-     * 企业管理
-     * @param array $data
-     * @return array
-     */
-    public function getCompanyList(array $data): array
-    {
-        $where = [];
-        $user = User::where('id', $data['user_id'])->first();
-        if(empty($user)){
-            return Result::error('用户不存在!');
-        }
-        if($user['type_id']!= 10000){
-            $where['user_id'] = $data['user_id'];
-        }
-        if(isset($data['title']) && $data['title']){
-            array_push($where, ['company.title', 'like', '%'. $data['title']. '%']);
-        }
-        if(isset($data['website_id']) && $data['website_id']){
-            $where['company.website_id'] = $data['website_id'];
-        }
-        if(isset($data['ischeck']) && !empty($data['ischeck'])){
-            if($data['ischeck'] == 1){
-                $query =  Company::whereIn('company.status', [0,2]);
-            }else{
-                $query =  Company::where('company.status', 1);
-            }
-        }
-        $result = $query->where($where)
-        ->leftJoin('website_category', function ($query) {
-            $query->on('website_category.category_id', '=', 'company.category_id')
-                ->on('website_category.website_id', '=', 'company.website_id');        
-        })
-        ->leftJoin('website', 'company.website_id', '=', 'website.id')
-        ->select(
-          'company.id', 
-          'company.title', 
-          'company.website_id', 
-          'company.category_id', 
-          'website.website_name', 
-          'website_category.alias as category_name',
-          'company.status',
-          'company.updated_at',
-        )
-        ->orderBy('company.updated_at', 'desc')
-        ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
+   * 企业管理
+   * @param array $data
+   * @return array
+   */
+  public function getCompanyList(array $data): array
+  {
+    $where = [];
+    $user = User::where('id', $data['user_id'])->first();
+    if (empty($user)) {
+      return Result::error('用户不存在!');
+    }
+    if ($user['type_id'] != 10000) {
+      $where['user_id'] = $data['user_id'];
+    }
+    if (isset($data['title']) && $data['title']) {
+      array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
+    }
+    if (isset($data['website_id']) && $data['website_id']) {
+      $where['company.website_id'] = $data['website_id'];
+    }
+    if (isset($data['ischeck']) && !empty($data['ischeck'])) {
+      if ($data['ischeck'] == 1) {
+        $query =  Company::whereIn('company.status', [0, 2]);
+      } else {
+        $query =  Company::where('company.status', 1);
+      }
+    }
+    $result = $query->where($where)
+      ->leftJoin('website_category', function ($query) {
+        $query->on('website_category.category_id', '=', 'company.category_id')
+          ->on('website_category.website_id', '=', 'company.website_id');
+      })
+      ->leftJoin('website', 'company.website_id', '=', 'website.id')
+      ->select(
+        'company.id',
+        'company.title',
+        'company.website_id',
+        'company.category_id',
+        'website.website_name',
+        'website_category.alias as category_name',
+        'company.status',
+        'company.updated_at',
+      )
+      ->orderBy('company.updated_at', 'desc')
+      ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
 
-      if($result->isEmpty()){
-          return Result::error("暂无企业", 0);
+    if ($result->isEmpty()) {
+      return Result::error("暂无企业", 0);
+    }
+    return Result::success($result);
+  }
+  /**
+   * 添加企业
+   * @param array $data
+   * @return array
+   */
+  public function addCompany(array $data): array
+  {
+    $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
+    if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
+      $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
+      $data['cat_arr_id'] = json_encode($car_arr_id);
+    } else {
+      $data['cat_arr_id'] = '';
+    }
+    if ($data['imgurl'] == '') {
+      //content中提取图片第一个图,正则提取
+      $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
+      preg_match_all($reg, $data['content'], $matches);
+      if (isset($matches[1][0])) {
+        //截取varchar240
+        $data['imgurl'] = substr($matches[1][0], 0, 240);
       }
-        return Result::success($result);
     }
-    /**
-     * 添加企业
-     * @param array $data
-     * @return array
-     */
-    public function addCompany(array $data): array
-    {
-        $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
-        if(isset($data['cat_arr_id']) &&!empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])){
-          $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
-          $data['cat_arr_id'] = json_encode($car_arr_id);
-        }else{
-            $data['cat_arr_id'] = '';
-        }
-        if ($data['imgurl'] == '') {
-            //content中提取图片第一个图,正则提取
-            $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
-            preg_match_all($reg, $data['content'], $matches);
-            if (isset($matches[1][0])) {
-                //截取varchar240
-                $data['imgurl'] = substr($matches[1][0], 0, 240);
-            } 
-        }
-        if ($data['keyword'] == '') {
-            //提取标题+内容中的关键词
-            $data['keyword'] = $data['title'];
-            //  . 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['introduce'] == '') {
-            //提取内容中的描述
-            $data['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
-        }
-        $user = User::where('id', $data['user_id'])->first();
-        if(empty($user)){
-            return Result::error('用户不存在!');
-        }
-        if($user['type_id']== 10000){
-            $data['status'] = 1;
-        }
-        $result = Company::insertGetId($data);
-        if ($result) {
-            return Result::success($result);
-        } else {
-            return Result::error('添加失败');
-        }
+    if ($data['keyword'] == '') {
+      //提取标题+内容中的关键词
+      $data['keyword'] = $data['title'];
+      //  . 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);
     }
-    /**
-     * 更新企业
-     * @param array $data
-     * @return array
-     */
-    public function upCompany(array $data): array
-    {
-        $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
-        if(isset($data['cat_arr_id']) &&!empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])){
-            $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
-            $data['cat_arr_id'] = json_encode($car_arr_id);
-        }else{
-            $data['cat_arr_id'] = '';
-        }
-        
-        // $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
-        if ($data['imgurl'] == '') {
-            //content中提取图片第一个图,正则提取
-            $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
-            preg_match_all($reg, $data['content'], $matches);
-            if (isset($matches[1][0])) {
-                //截取varchar240
-                $data['imgurl'] = substr($matches[1][0], 0, 240);
-            } 
-        }
-        if ($data['keyword'] == '') {
-            //提取标题+内容中的关键词
-            $data['keyword'] = $data['title'];
-            //  . 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['introduce'] == '') {
-            //提取内容中的描述
-            $data['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
-        }
-        $user = User::where('id', $data['user_id'])->first();
-        if(empty($user)){
-            return Result::error('用户不存在!');
-        }
-        if($user['type_id']== 10000){
-            $data['status'] = 1;
-        }else{
-            $data['status'] = 0;
-        }
-        $result = Company::where('id', $data['id'])->update($data);
-        if ($result) {
-            return Result::success($result);
-        } else {
-            return Result::error('修改失败');
-        }
+    if ($data['introduce'] == '') {
+      //提取内容中的描述
+      $data['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
     }
-    /**
-     * 删除企业
-     * @param array $data
-     * @return array
-     */
-    public function delCompany(array $data): array
-    {
-        $result = Company::where('id', $data['id'])->delete();
-        if ($result) {
-            return Result::success($result);
-        } else {
-            return Result::error('删除失败');
-        }
+    $user = User::where('id', $data['user_id'])->first();
+    if (empty($user)) {
+      return Result::error('用户不存在!');
     }
-    /**
-     * 审核企业
-     * @param array $data
-     * @return array
-     */
-    public function checkCompany(array $data): array
-    {
-        $user = User::where('id', $data['user_id'])->first();
-        if(empty($user)){
-            return Result::error('用户不存在!');
-        }
-        $company = Company::where('id', $data['id'])->first();
-        if(empty($company)){
-            return Result::error('企业不存在!');
-        }
-        // 状态:0:未审核 1:已审核 2:已拒绝
-        if($company['status'] == 0 || $company['status'] == 1){
-            $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
-        }else{
-            $result = Company::where('id', $data['id'])->update(['status' => $data['status'],'reject_reason'=> $data['reject_reason']]);
-        }
-        if(empty($result)){
-            return Result::error('审核失败!');
-        }else{
-            return Result::success($result);
-        }
+    if ($user['type_id'] == 10000) {
+      $data['status'] = 1;
     }
-    /**
-     * 获取企业信息
-     * @param array $data
-     * @return array
-     */
-    public function getCompanyInfo(array $data): array
-    {
-        $result = Company::where('id', $data['id'])->first();
-        if(empty($result)){
-            return Result::error('企业不存在!');
-        }else{
-            return Result::success($result);
-        }
+    $result = Company::insertGetId($data);
+    if ($result) {
+      return Result::success($result);
+    } else {
+      return Result::error('添加失败');
+    }
+  }
+  /**
+   * 更新企业
+   * @param array $data
+   * @return array
+   */
+  public function upCompany(array $data): array
+  {
+    $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
+    if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
+      $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
+      $data['cat_arr_id'] = json_encode($car_arr_id);
+    } else {
+      $data['cat_arr_id'] = '';
+    }
+
+    // $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
+    if ($data['imgurl'] == '') {
+      //content中提取图片第一个图,正则提取
+      $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
+      preg_match_all($reg, $data['content'], $matches);
+      if (isset($matches[1][0])) {
+        //截取varchar240
+        $data['imgurl'] = substr($matches[1][0], 0, 240);
+      }
+    }
+    if ($data['keyword'] == '') {
+      //提取标题+内容中的关键词
+      $data['keyword'] = $data['title'];
+      //  . 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['introduce'] == '') {
+      //提取内容中的描述
+      $data['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
+    }
+    $user = User::where('id', $data['user_id'])->first();
+    if (empty($user)) {
+      return Result::error('用户不存在!');
+    }
+    if ($user['type_id'] == 10000) {
+      $data['status'] = 1;
+    } else {
+      $data['status'] = 0;
+    }
+    $result = Company::where('id', $data['id'])->update($data);
+    if ($result) {
+      return Result::success($result);
+    } else {
+      return Result::error('修改失败');
+    }
+  }
+  /**
+   * 删除企业
+   * @param array $data
+   * @return array
+   */
+  public function delCompany(array $data): array
+  {
+    $result = Company::where('id', $data['id'])->delete();
+    if ($result) {
+      return Result::success($result);
+    } else {
+      return Result::error('删除失败');
+    }
+  }
+  /**
+   * 审核企业
+   * @param array $data
+   * @return array
+   */
+  public function checkCompany(array $data): array
+  {
+    $user = User::where('id', $data['user_id'])->first();
+    if (empty($user)) {
+      return Result::error('用户不存在!');
+    }
+    $company = Company::where('id', $data['id'])->first();
+    if (empty($company)) {
+      return Result::error('企业不存在!');
+    }
+    // 状态:0:未审核 1:已审核 2:已拒绝
+    if ($company['status'] == 0 || $company['status'] == 1) {
+      $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
+    } else {
+      $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reject_reason']]);
     }
+    if (empty($result)) {
+      return Result::error('审核失败!');
+    } else {
+      return Result::success($result);
+    }
+  }
+  /**
+   * 获取企业信息
+   * @param array $data
+   * @return array
+   */
+  public function getCompanyInfo(array $data): array
+  {
+    $result = Company::where('id', $data['id'])->first();
+    if (empty($result)) {
+      return Result::error('企业不存在!');
+    } else {
+      return Result::success($result);
+    }
+  }
 }