소스 검색

行政通知

LiuJ 2 주 전
부모
커밋
0d088e7eab
4개의 변경된 파일191개의 추가작업 그리고 28개의 파일을 삭제
  1. 109 28
      app/JsonRpc/NewsService.php
  2. 27 0
      app/Model/Notice.php
  3. 28 0
      app/Model/User.php
  4. 27 0
      app/Model/UserInfo.php

+ 109 - 28
app/JsonRpc/NewsService.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace App\JsonRpc;
 
 use App\Model\Article;
@@ -10,6 +11,7 @@ use App\Model\jobHunting;
 use App\Model\JobEnum;
 use App\Model\JobIndustry;
 use App\Model\JobPosition;
+use App\Model\Notice;
 use App\Model\JobRecruiting;
 use App\Model\Good;
 use App\Model\JobNature;
@@ -22,6 +24,8 @@ use Hyperf\Utils\Random;
 use Fukuball\Jieba\Jieba;
 use Fukuball\Jieba\Finalseg;
 use App\Model\ChatRecords;
+use App\Model\User;
+use App\Model\UserInfo;
 use Hyperf\Utils\Collection;
 
 #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
@@ -114,7 +118,9 @@ class NewsService implements NewsServiceInterface
         //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
         $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
         $where[] = [
-            'pid', '=', $data['pid'],
+            'pid',
+            '=',
+            $data['pid'],
         ];
         if (isset($data['name'])) {
             array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
@@ -136,7 +142,9 @@ class NewsService implements NewsServiceInterface
     public function categoryList(array $data): array
     {
         $where[] = [
-            'pid', '=', $data['pid'],
+            'pid',
+            '=',
+            $data['pid'],
         ];
         if (isset($data['name'])) {
             array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
@@ -193,7 +201,6 @@ class NewsService implements NewsServiceInterface
             Db::rollBack();
             return Result::error("删除失败");
         }
-
     }
 
     /**
@@ -345,7 +352,9 @@ class NewsService implements NewsServiceInterface
                     //截取varchar240
                     $articleData['imgurl'] = substr($matches[1][0], 0, 240);
                     //如果有图,设置level=3
-                    if (!in_array(3, $levelArr)) {$levelArr[] = 3;}
+                    if (!in_array(3, $levelArr)) {
+                        $levelArr[] = 3;
+                    }
                     $articleData['level'] = json_encode($levelArr);
                 } else {
                     if (!in_array(0, $levelArr)) {
@@ -364,7 +373,6 @@ class NewsService implements NewsServiceInterface
                 $segList = Jieba::cut($articleData['keyword']);
                 $segList1 = array_slice($segList, 0, 8);
                 $articleData['keyword'] = implode(',', $segList1);
-
             }
             if ($articleData['introduce'] == '') {
                 //提取内容中的描述
@@ -419,7 +427,6 @@ class NewsService implements NewsServiceInterface
                     if (empty($suvey_data)) {
                         throw new \Exception("投票数据为空");
                     }
-
                 }
                 $result = ArticleSurvey::insert($suvey_data);
                 if (!$result) {
@@ -515,7 +522,9 @@ class NewsService implements NewsServiceInterface
                     }
                     //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
                     //如果有图,设置level=3
-                    if (!in_array(3, $levelArr)) {$levelArr[] = 3;}
+                    if (!in_array(3, $levelArr)) {
+                        $levelArr[] = 3;
+                    }
                     $articleData['level'] = json_encode($levelArr);
                 } else {
                     if (!in_array(0, $levelArr)) {
@@ -589,7 +598,6 @@ class NewsService implements NewsServiceInterface
                         if (empty($suvey_data)) {
                             throw new \Exception("投票数据为空");
                         }
-
                     }
                 }
                 $result = ArticleSurvey::insert($suvey_data);
@@ -695,10 +703,10 @@ class NewsService implements NewsServiceInterface
                     $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
                         ->orWhereNull("ignore_ids");
                 })
-            //$data['level'] == 4 || $data['level'] == 5 查询随机
+                //$data['level'] == 4 || $data['level'] == 5 查询随机
                 ->when($data['level'] == 5, function ($query) {
                     $query->inRandomOrder()
-                    //updated_at最近三十天;
+                        //updated_at最近三十天;
                         ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
                 })
                 ->when($data['level'] == 4, function ($query) {
@@ -763,7 +771,6 @@ class NewsService implements NewsServiceInterface
             }
         } else {
             return Result::error("此网站暂无此栏目", 0);
-
         }
         return Result::success($result);
     }
@@ -829,7 +836,6 @@ class NewsService implements NewsServiceInterface
             return Result::error("没有信息数据");
         }
         return Result::success($data);
-
     }
     /**
      * 前端-获取新闻详情
@@ -968,7 +974,6 @@ class NewsService implements NewsServiceInterface
             return Result::error("添加失败", 0);
         }
         return Result::error("添加失败", 0);
-
     }
     /**
      * 前端-调查问卷投票
@@ -982,7 +987,6 @@ class NewsService implements NewsServiceInterface
             $website = Website::where('id', $data['website_id'])->first();
             if (empty($website)) {
                 return Result::error("暂无此网站", 0);
-
             }
             if (isset($data['sur_id']) && !empty($data['sur_id'])) {
                 $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
@@ -1043,7 +1047,6 @@ class NewsService implements NewsServiceInterface
                         ->get();
                     $survey['choice'] = $choice_id;
                     return Result::success($survey);
-
                 }
                 return Result::error("参数必填!");
             }
@@ -1241,10 +1244,10 @@ class NewsService implements NewsServiceInterface
                             $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
                         })->orWhereNull("ignore_ids");
                     })
-                // ->where(function ($query) {
-                //     $query->whereNull('imgurl')
-                //         ->orWhere('imgurl', '');
-                // })
+                    // ->where(function ($query) {
+                    //     $query->whereNull('imgurl')
+                    //         ->orWhere('imgurl', '');
+                    // })
                     ->select('*')
                     ->orderBy('updated_at', 'desc')
                     ->limit($data['child_textnum'])
@@ -1256,7 +1259,6 @@ class NewsService implements NewsServiceInterface
                 $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
                 return $child;
             }, $category['child']);
-
         }
         // }
         if (isset($data['img_num']) && !empty($data['img_num'])) {
@@ -1275,10 +1277,10 @@ class NewsService implements NewsServiceInterface
                 ->leftJoin('article', 'article.catid', 'website_category.category_id')
                 ->where('article.status', 1)
 
-            // ->where(function ($query) {
-            //     $query->whereNull('article.imgurl')
-            //           ->orWhere('article.imgurl', '');
-            // })
+                // ->where(function ($query) {
+                //     $query->whereNull('article.imgurl')
+                //           ->orWhere('article.imgurl', '');
+                // })
                 ->select('article.*', 'website_category.category_id', 'website_category.alias')
                 ->orderBy('article.updated_at', 'desc')
                 ->limit($data['text_num'])
@@ -1737,18 +1739,99 @@ class NewsService implements NewsServiceInterface
     }
     public function addNotice(array $data): array
     {
+        date_default_timezone_set('Asia/Shanghai');
+        $data['created_at'] = date('Y-m-d H:i:s');
+        $data['updated_at'] = date('Y-m-d H:i:s');
+        $user_id = UserInfo::
+            //city_id不是null
+            whereNotNull('city_id')
+            ->whereNotNull('department_id')
+            ->where(function ($query) use ($data) {
+                $query->where(function ($subQuery) use ($data) {
+                    $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
+                });
+            })
+            ->where(function ($query) use ($data) {
+                $query->where(function ($subQuery) use ($data) {
+                    $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
+                });
+            })
+            ->pluck('user_id')->toArray();
+        $user_id = array_unique($user_id);
+        $user_id = json_encode($user_id);
+        $data['re_user_ids'] = $user_id;
         $result = Notice::create($data);
+        if (empty($result)) {
+            return Result::error("添加失败", 0);
+        }
         return Result::success($result);
     }
     public function updateNotice(array $data): array
     {
+        date_default_timezone_set('Asia/Shanghai');
+        //根据city_id  和department_id  查询出对应的user_id,放到 re_user_ids
+        $user_id = UserInfo::
+            //city_id不是null
+            whereNotNull('city_id')
+            ->whereNotNull('department_id')
+            ->where(function ($query) use ($data) {
+                $query->where(function ($subQuery) use ($data) {
+                    $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
+                });
+            })
+            ->where(function ($query) use ($data) {
+                $query->where(function ($subQuery) use ($data) {
+                    $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
+                });
+            })
+            ->pluck('user_id')->toArray();
+        $user_id = array_unique($user_id);
+        $user_id = json_encode($user_id);
+        $data['re_user_ids'] = $user_id;
+        $data['updated_at'] = date('Y-m-d H:i:s');
         $result = Notice::where('id', $data['id'])->update($data);
         return Result::success($result);
     }
     public function getNoticeList(array $data): array
     {
-        $result = Notice::where('status', 1)->get();
-        return Result::success($result);
+        $where = [];
+        //title
+        if (isset($data['title']) && !empty($data['title'])) {
+            $where[] = ['title', 'like', '%' . $data['title'] . '%'];
+        }
+        //level
+        if (isset($data['level']) && !empty($data['level'])) {
+            $where[] = ['level', '=', $data['level']];
+        }
+        var_dump($data['type_id'], '-----------------test---------');
+        if ($data['type_id'] == 10000) {
+            $result = Notice::where('status', 1)
+                ->where($where)
+                ->orderBy('updated_at', 'desc')
+                ->limit($data['page_size'])
+                ->offset(($data['page'] - 1) * $data['page_size'])
+                ->get();
+        } else {
+            $result = Notice::where('status', 1)
+                ->where($where)
+                ->where('user_id', $data['user_id'])
+                ->orWhere(function ($query) use ($data) {
+                    $query->where('re_user_ids', 'like', '%' . $data['user_id'] . '%');
+                })
+                ->orderBy('updated_at', 'desc')
+                ->limit($data['page_size'])
+                ->offset(($data['page'] - 1) * $data['page_size'])
+                ->get();
+        }
+        if (empty($result)) {
+            return Result::error("查询失败", 0);
+        }
+        $count = Notice::where('status', 1)->count();
+        $data = [
+            'rows' => $result,
+            'count' => $count,
+        ];
+        return Result::success($data);
     }
     public function getNoticeDetail(array $data): array
     {
@@ -1762,7 +1845,6 @@ class NewsService implements NewsServiceInterface
     {
         $result = Notice::where('id', $data['id'])->delete();
         return Result::success($result);
-
     }
     public function getMSG(array $data): array
     {
@@ -1918,7 +2000,6 @@ class NewsService implements NewsServiceInterface
             return Result::error("查询失败", 0);
         }
         return Result::success($result);
-
     }
 
     //20250324  通知,公告,消息

+ 27 - 0
app/Model/Notice.php

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

+ 28 - 0
app/Model/User.php

@@ -0,0 +1,28 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Model;
+
+use Hyperf\DbConnection\Model\Model;
+
+/**
+ */
+class User extends Model
+{
+    /**
+     * The table associated with the model.
+     */
+    protected ?string $table = 'user';
+
+    /**
+     * The attributes that are mass assignable.
+     */
+    protected array $fillable = ["user_name","avatar","status","email","rong_token"];
+    protected array $hidden = [];
+    /**
+     * The attributes that should be cast to native types.
+     */
+    protected array $casts = [];
+
+}

+ 27 - 0
app/Model/UserInfo.php

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