LiuJ 5 өдөр өмнө
parent
commit
8e8ddba8b3

+ 149 - 2
app/JsonRpc/NewsService.php

@@ -16,7 +16,7 @@ use App\Model\JobRecruiting;
 use App\Model\JobIndustry;
 use App\Model\JobPosition;
 use App\Model\Notice;
-
+use App\Model\Book;
 use App\Model\JobNature;
 use App\Model\JobEnum;
 use App\Model\User;
@@ -42,6 +42,8 @@ use App\Model\ChatGroups;
 use App\Model\ChatGroupsMember;
 use App\Model\ChatRecords;
 use App\Model\Complaint;
+use Hamcrest\Arrays\IsArray;
+use Hyperf\Codec\Json;
 
 #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class NewsService implements NewsServiceInterface
@@ -567,7 +569,8 @@ class NewsService implements NewsServiceInterface
             }
             if ($articleData['introduce'] == '') {
                 //提取内容中的描述
-                $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
+                $articleData['introduce'] = substr(preg_replace('/\s+/', '', strip_tags($data['content'])), 0, 100);
+                // substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
             }
 
             $id = Article::where(['id' => $data['id']])->update($articleData);
@@ -3137,4 +3140,148 @@ class NewsService implements NewsServiceInterface
         return Result::success($result);
     }
     // 20250306 招聘
+    //20250422  书刊音像
+    public function addBook(array $data): array
+    {
+        $user_id = $data['user_id'] ?? 0;
+        $type_id = $data['type_id'] ?? 0;
+        $website_id = $data['website_id'] ?? 0;
+        unset($data['user_id']);
+        unset($data['type_id']);
+        // unset($data['website_id']);
+        //处理数组
+        // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
+        $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']) : '[]';
+        if ($data['img_url'] == '') {
+            $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
+            preg_match_all($reg, $data['detail'], $matches);
+            if (isset($matches[1][0])) {
+                //截取varchar240
+                $data['img_url'] = 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['description'] == '') {
+            //提取内容中的描述
+            $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
+        }
+
+        $result = Book::insertGetId($data);
+        if (empty($result)) {
+            return Result::error("添加失败", 0);
+        }
+        return Result::success($result);
+    }
+    public function getBookList(array $data): array
+    {
+        $where = [];
+        if (!empty($data["title"])) {
+            $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
+        }
+        if (!empty($data['website_name'])) {
+            $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
+        }
+        if (!empty($data['status'])) {
+            $where[] = ['book.status', '=', $data['status']];
+        }
+        var_dump(!empty($data['status1']), '=-===1');
+        $result = Book::where($where)
+            ->leftJoin('website', 'book.website_id', '=', 'website.id')
+            ->leftJoin('category', 'book.cat_id', '=', 'category.id')
+            ->leftJoin('district', 'book.city_id', '=', 'district.id')
+            ->when(!empty($data['status1']) && (isset($data['status']) &&  $data['status'] != 2), function ($query) use ($data) {
+                $query->whereIn('book.status', [1, 3]);
+            })
+            ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
+            ->orderBy("updated_at", "desc")
+            ->paginate($data['page_size'], ['*'], 'page', $data['page']);
+        if (empty($result)) {
+            return Result::error("暂无数据", 0);
+        }
+        // 取出数据
+        $rows = $result->items();
+        $count = $result->total();
+        $responseData = [
+            'rows' => $rows,
+            'count' => $count,
+        ];
+        return Result::success($responseData);
+    }
+    public function deleteBook(array $data): array
+    {
+        $result = Book::where('id', $data['id'])->delete();
+        if (empty($result)) {
+            return Result::error("删除失败", 0);
+        }
+        return Result::success($result);
+    }
+    public function updateBook(array $data): array
+    {
+
+        $user_id = $data['user_id'] ?? 0;
+        $type_id = $data['type_id'] ?? 0;
+        $website_id = $data['website_id'] ?? 0;
+        unset($data['user_id']);
+        unset($data['type_id']);
+        // unset($data['website_id']);
+        //处理数组
+        // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
+        if ($data['img_url'] == '') {
+            $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
+            preg_match_all($reg, $data['detail'], $matches);
+            if (isset($matches[1][0])) {
+                //截取varchar240
+                $data['img_url'] = 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['description'] == '') {
+            //提取内容中的描述
+            $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
+        }
+        $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']) : '[]';
+        $result = Book::where("id", $data["id"])->update($data);
+        if (empty($result)) {
+            return Result::error("更新失败", 0);
+        }
+        return Result::success($result);
+    }
+    public function getBookInfo(array $data): array
+    {
+        $result = Book::where("id", $data["id"])->first();
+        if (empty($result)) {
+            return Result::error("获取失败", 0);
+        }
+        return Result::success($result);
+    }
+    public function updateBookStatus(array $data): array
+    {
+        $result = Book::where("id", $data["id"])->update($data);
+        if (empty($result)) {
+            return Result::error("更新失败", 0);
+        }
+        return Result::success($result);
+    }
+
+    //20250422  书刊音像
 }

+ 27 - 0
app/Model/Book.php

@@ -0,0 +1,27 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Model;
+
+use Hyperf\DbConnection\Model\Model;
+
+/**
+ */
+class Book extends Model
+{
+    /**
+     * The table associated with the model.
+     */
+    protected ?string $table = 'book';
+
+    /**
+     * The attributes that are mass assignable.
+     */
+    protected array $guarded = [];
+
+    /**
+     * The attributes that should be cast to native types.
+     */
+    protected array $casts = [];
+}