|
|
@@ -84,6 +84,7 @@ use App\Model\Message;
|
|
|
use App\Model\ResearchTopic;
|
|
|
use App\Model\RetopicUser;
|
|
|
use App\Model\WebCateinfo;
|
|
|
+use App\Model\SinglePage;
|
|
|
#[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class NewsService implements NewsServiceInterface
|
|
|
{
|
|
|
@@ -9784,4 +9785,314 @@ class NewsService implements NewsServiceInterface
|
|
|
$result = $webCateinfo->toArray();
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 推荐单页管理
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ public function getAdviceSinglePages(array $data): array
|
|
|
+ {
|
|
|
+ $user = User::where('id', $data['user_id'])->first();
|
|
|
+ if (empty($user)) {
|
|
|
+ return Result::error('用户不存在');
|
|
|
+ }
|
|
|
+ $category = WebsiteCategory::where(['website_id' => $data['website_id']])->pluck('category_id');
|
|
|
+ if(empty($category)){
|
|
|
+ return Result::error('推荐单页不存在');
|
|
|
+ }
|
|
|
+ $where = [];
|
|
|
+ if(!empty($data['title'])){
|
|
|
+ array_push($where, ['title', 'like', '%'.$data['title'].'%']);
|
|
|
+ }
|
|
|
+ $result = SinglePage::whereIn('id', $category)
|
|
|
+ ->when(!empty($where), function ($query) use ($where) {
|
|
|
+ $query->where($where);
|
|
|
+ })
|
|
|
+ ->when(!empty($data['catid']), function ($query) use ($data) {
|
|
|
+ $query->where('catid', $data['catid']);
|
|
|
+ })
|
|
|
+ ->where('status', 1)
|
|
|
+ ->select(['id', 'title', 'catid','status','website_id','updated_at'])
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->paginate($data['page_size'], ['*'], 'page', $data['page']);
|
|
|
+ if(empty($result->items())){
|
|
|
+ return Result::error('推荐单页不存在');
|
|
|
+ }
|
|
|
+ $result = [
|
|
|
+ 'rows' => $result->items(),
|
|
|
+ 'total' => $result->total(),
|
|
|
+ ];
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 添加单页
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ public function addSinglePage(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(is_array($data['cat_arr_id'])){
|
|
|
+ $data['cat_arr_id'] = array_map(function($item){
|
|
|
+ return intval($item);
|
|
|
+ }, $data['cat_arr_id']);
|
|
|
+ $data['catid'] = end($data['cat_arr_id']);
|
|
|
+ $data['cat_arr_id'] = json_encode($data['cat_arr_id'], JSON_UNESCAPED_UNICODE);
|
|
|
+ }else{
|
|
|
+ return Result::error('请选择栏目;');
|
|
|
+ }
|
|
|
+ if(!empty($data['commend_id']) && is_array($data['commend_id'])){
|
|
|
+ $data['commend_id'] = json_encode($data['commend_id'], JSON_UNESCAPED_UNICODE);
|
|
|
+ }else{
|
|
|
+ $data['commend_id'] = null;
|
|
|
+ }
|
|
|
+ if ($data['keyword'] == '') {
|
|
|
+ //提取标题+内容中的关键词
|
|
|
+ $articleData['keyword'] = $data['title'];
|
|
|
+ // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
|
|
|
+ Jieba::init(); // 初始化 jieba-php
|
|
|
+ Finalseg::init();
|
|
|
+ $segList = Jieba::cut($articleData['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);
|
|
|
+ }
|
|
|
+ if(empty($data['publiced_at'])){
|
|
|
+ $data['publiced_at'] = null;
|
|
|
+ }
|
|
|
+ $result = SinglePage::insertGetId($data);
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error('添加失败');
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 更新单页
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ public function upSinglePage(array $data): array
|
|
|
+ {
|
|
|
+ $singlePage = SinglePage::where('id', $data['id'])->where('user_id', $data['user_id'])->first();
|
|
|
+ if (empty($singlePage)) {
|
|
|
+ return Result::error('单页不存在');
|
|
|
+ }
|
|
|
+ $user = User::where('id', $data['user_id'])->first();
|
|
|
+ if (empty($user)) {
|
|
|
+ return Result::error('用户不存在');
|
|
|
+ }
|
|
|
+ $where['id'] = $data['id'];
|
|
|
+ unset($data['id']);
|
|
|
+ if($user['type_id'] == 10000){
|
|
|
+ $data['status'] = 1;
|
|
|
+ }else{
|
|
|
+ $data['status'] = 0;
|
|
|
+ }
|
|
|
+ if(is_array($data['cat_arr_id'])){
|
|
|
+ $data['cat_arr_id'] = array_map(function($item){
|
|
|
+ return intval($item);
|
|
|
+ }, $data['cat_arr_id']);
|
|
|
+ $data['catid'] = end($data['cat_arr_id']);
|
|
|
+ $data['cat_arr_id'] = json_encode($data['cat_arr_id'], JSON_UNESCAPED_UNICODE);
|
|
|
+ }else{
|
|
|
+ return Result::error('请选择栏目;');
|
|
|
+ }
|
|
|
+ if(!empty($data['commend_id']) && is_array($data['commend_id'])){
|
|
|
+ $data['commend_id'] = json_encode($data['commend_id'], JSON_UNESCAPED_UNICODE);
|
|
|
+ }else{
|
|
|
+ $data['commend_id'] = null;
|
|
|
+ }
|
|
|
+ if ($data['keyword'] == '') {
|
|
|
+ //提取标题+内容中的关键词
|
|
|
+ $articleData['keyword'] = $data['title'];
|
|
|
+ // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
|
|
|
+ Jieba::init(); // 初始化 jieba-php
|
|
|
+ Finalseg::init();
|
|
|
+ $segList = Jieba::cut($articleData['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);
|
|
|
+ }
|
|
|
+ if(empty($data['publiced_at'])){
|
|
|
+ $data['publiced_at'] = null;
|
|
|
+ }
|
|
|
+ $result = SinglePage::where($where)->update($data);
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error('更新失败');
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 删除单页
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ public function delSinglePage(array $data): array
|
|
|
+ {
|
|
|
+ $singlePage = SinglePage::where('id', $data['id'])->first();
|
|
|
+ if (empty($singlePage)) {
|
|
|
+ return Result::error('单页不存在');
|
|
|
+ }
|
|
|
+ $user = User::where('id', $data['user_id'])->first();
|
|
|
+ if (empty($user)) {
|
|
|
+ return Result::error('用户不存在');
|
|
|
+ }
|
|
|
+ $where['id'] = $data['id'];
|
|
|
+ $result = SinglePage::where($where)->delete();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error('删除失败');
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 审核单页
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ public function checkSinglePage(array $data): array
|
|
|
+ {
|
|
|
+ $user = User::where('id', $data['user_id'])->first();
|
|
|
+ if (empty($user)) {
|
|
|
+ return Result::error('用户不存在');
|
|
|
+ }
|
|
|
+ if($user['type_id'] != 10000 && in_array($data['status'], [1, 2])){
|
|
|
+ return Result::error('非管理员不能审核单页');
|
|
|
+ }
|
|
|
+ if($data['status'] == 2){
|
|
|
+ $update_data['reason'] = $data['reason'] ?? '';
|
|
|
+ }
|
|
|
+ $update_data['status'] = $data['status'];
|
|
|
+ $result = SinglePage::where('id', $data['id'])->update($update_data);
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error('更新失败');
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 更新单页状态
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ public function getSinglePageList(array $data): array
|
|
|
+ {
|
|
|
+ $user = User::where('id', $data['user_id'])->first();
|
|
|
+ if (empty($user)) {
|
|
|
+ return Result::error('用户不存在');
|
|
|
+ }
|
|
|
+ $where = [];
|
|
|
+ if($user['type_id'] != 10000){
|
|
|
+ $where['single_page.user_id'] = $data['user_id'];
|
|
|
+ }
|
|
|
+ if($data['is_master'] == 3){
|
|
|
+ $where['single_page.status'] = 0;
|
|
|
+ }else if($data['is_master'] != 0){
|
|
|
+ $where['single_page.status'] = $data['is_master'];
|
|
|
+ }
|
|
|
+ if(!empty($data['title'])){
|
|
|
+ array_push($where, ['single_page.title', 'like', '%'.$data['title'].'%']);
|
|
|
+ }
|
|
|
+ $result = SinglePage::when($data['is_master'] == 0, function($query) use($data){
|
|
|
+ $query->whereIn('single_page.status', [0, 2]);
|
|
|
+ })
|
|
|
+ ->when(!empty($where), function($query) use($where){
|
|
|
+ $query->where($where);
|
|
|
+ })
|
|
|
+ ->with([
|
|
|
+ 'websiteCategory' => function ($query) {
|
|
|
+ $query->select('website_id', 'category_id', 'alias');
|
|
|
+ },
|
|
|
+ 'user' => function ($query) {
|
|
|
+ $query->select('id', 'nickname');
|
|
|
+ }
|
|
|
+ ])
|
|
|
+ ->select(['single_page.id','single_page.title','single_page.content','single_page.updated_at',
|
|
|
+ 'single_page.status','single_page.catid','single_page.website_id','single_page.user_id'])
|
|
|
+ ->orderBy('single_page.updated_at', 'desc')
|
|
|
+ ->paginate($data['page_size'], ['*'], 'page', $data['page']);
|
|
|
+ if (empty($result->items())) {
|
|
|
+ return Result::error('暂无数据');
|
|
|
+ }
|
|
|
+ $result = [
|
|
|
+ 'rows' => $result->items(),
|
|
|
+ 'total' => $result->total(),
|
|
|
+ ];
|
|
|
+ foreach($result['rows'] as $key => $value){
|
|
|
+ $result['rows'][$key]['category_alias'] = $value['websiteCategory']['alias'] ?? '';
|
|
|
+ $result['rows'][$key]['user_nickname'] = $value['user']['nickname'] ?? '';
|
|
|
+ $result['rows'][$key]['websiteCategory'] = $value['websiteCategory']['alias'] ?? '';
|
|
|
+ unset($result['rows'][$key]['user']);
|
|
|
+ unset($result['rows'][$key]['websiteCategory']);
|
|
|
+ if($user['type_id'] == 10000){
|
|
|
+ if($value['user_id'] == $data['user_id']){
|
|
|
+ $result['rows'][$key]['is_update'] = 1;
|
|
|
+ }else{
|
|
|
+ $result['rows'][$key]['is_update'] = 0;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if($value['website_id'] == $data['website_id']){
|
|
|
+ $result['rows'][$key]['is_update'] = 1;
|
|
|
+ }else{
|
|
|
+ $result['rows'][$key]['is_update'] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取单页详情
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ public function getSinglePageInfo(array $data): array
|
|
|
+ {
|
|
|
+ $singlePage = SinglePage::where('id', $data['id'])->where('user_id', $data['user_id'])->first();
|
|
|
+ if (empty($singlePage)) {
|
|
|
+ return Result::error('单页不存在');
|
|
|
+ }
|
|
|
+ $user = User::where('id', $data['user_id'])->first();
|
|
|
+ if (empty($user)) {
|
|
|
+ return Result::error('用户不存在');
|
|
|
+ }
|
|
|
+ $where['id'] = $data['id'];
|
|
|
+ $result = SinglePage::where($where)->first();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error('获取失败');
|
|
|
+ }
|
|
|
+ $result['cat_arr_id'] = json_decode($result['cat_arr_id'] ?? '[]' , true);
|
|
|
+ $result['commend_id'] = json_decode($result['commend_id'] ?? '[]' , true);
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
}
|