|
@@ -59,7 +59,9 @@ use Hyperf\Utils\Parallel;
|
|
|
use Hyperf\Coroutine\Concurrent;
|
|
use Hyperf\Coroutine\Concurrent;
|
|
|
use function Hyperf\Coroutine\batch;
|
|
use function Hyperf\Coroutine\batch;
|
|
|
use Swoole\Coroutine;
|
|
use Swoole\Coroutine;
|
|
|
-
|
|
|
|
|
|
|
+use Fukuball\Jieba\Jieba;
|
|
|
|
|
+use Fukuball\Jieba\Finalseg;
|
|
|
|
|
+use App\Model\WebCateinfo;
|
|
|
#[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
#[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class WebsiteService implements WebsiteServiceInterface
|
|
class WebsiteService implements WebsiteServiceInterface
|
|
|
{
|
|
{
|
|
@@ -3474,4 +3476,56 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
}
|
|
}
|
|
|
return Result::success($result);
|
|
return Result::success($result);
|
|
|
}
|
|
}
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 添加网站导航
|
|
|
|
|
+ * @param array $data
|
|
|
|
|
+ */
|
|
|
|
|
+ public function addWebCateinfo(array $data): array
|
|
|
|
|
+ {
|
|
|
|
|
+ $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;
|
|
|
|
|
+ }
|
|
|
|
|
+ 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['description'] == '') {
|
|
|
|
|
+ //提取内容中的描述
|
|
|
|
|
+ $content = $data['content'];
|
|
|
|
|
+ // 去除 <style> 和 <script> 标签及其内容
|
|
|
|
|
+ $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
|
|
|
|
|
+ // 去除所有 HTML 标签
|
|
|
|
|
+ $content = strip_tags($content);
|
|
|
|
|
+ // 去除 HTML 实体
|
|
|
|
|
+ $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
|
|
|
|
+ // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
|
|
|
|
|
+ $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
|
|
|
|
|
+ // 去除多余空白
|
|
|
|
|
+ $content = preg_replace('/\s+/u', '', $content);
|
|
|
|
|
+ // 截取 100 个字符
|
|
|
|
|
+ $data['description'] = mb_substr($content, 0, 100);
|
|
|
|
|
+ }
|
|
|
|
|
+ $data['cate_name'] = empty($data['cate_name']) ? '官网导航' : $data['cate_name'];
|
|
|
|
|
+ $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
|
|
|
|
|
+ $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
|
|
|
|
|
+ $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
|
|
|
|
|
+ unset($data['users_id']);
|
|
|
|
|
+ $result = WebCateinfo::insertGetId($data);
|
|
|
|
|
+ if (empty($result)) {
|
|
|
|
|
+ return Result::error('添加失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result::success($result);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|