rkljw 1 тиждень тому
батько
коміт
8d4ef22912

+ 77 - 1
app/JsonRpc/PublicRpcService.php

@@ -1,6 +1,7 @@
 <?php
 namespace App\JsonRpc;
 
+use App\Model\BlackWord;
 use App\Model\Department;
 use App\Model\District;
 use App\Model\LetterOfComplaint;
@@ -8,13 +9,17 @@ use App\Model\LetterType;
 use App\Model\LevelUser;
 use App\Model\UserLevel;
 use App\Tools\Result;
+use Hyperf\DbConnection\Db;
+use Hyperf\Di\Annotation\Inject;
 use Hyperf\RpcServer\Annotation\RpcService;
 use App\Service\MinioService;
+use Hyperf\Redis\Redis;
 
 #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class PublicRpcService implements PublicRpcServiceInterface
 {
-
+    #[Inject]
+    protected Redis $redis;
     /**
      * @param array $data
      * @return array
@@ -522,5 +527,76 @@ class PublicRpcService implements PublicRpcServiceInterface
 
     }
 
+    /**
+     * 黑名单管理
+     * @param array $data
+     * @return array
+     */
+    public function getBlackWordList(array $data) :array
+    {
+        $result = BlackWord::when($data, function ($query) use ($data) {
+            if (isset($data['name']) && $data['name']){
+                $query->where('black_word.name', 'like', '%'.$data['name'].'%');
+            }
+        })->orderBy('black_word.created_at','desc')
+            ->paginate(intval($data['pageSize']),
+                [
+                    'black_word.*',
+                ],
+                'page', intval($data['page']));
+        $count = $result->total();
+        $returnData = [
+            'rows'=>$result->items(),
+            'count'=>$count
+        ];
+        return Result::success($returnData);
+    }
+
+    /**
+     * 添加黑名单
+     * @param array $data
+     * @return array
+     */
+    public function addBlackWord(array $data) :array
+    {
+        Db::beginTransaction();
+        try {
+            $info = BlackWord::where(['name'=>$data['name']])->first();
+            if($info){
+                Db::rollBack();
+                return  Result::error("该黑名单已存在", 0);
+            }
+            $data['type'] = 10;
+            $result = BlackWord::insertGetId($data);
+            $redisKey = 'black_word';
+            $this->redis->sAdd($redisKey, $data['name']);
+            Db::commit();
+            return Result::success(["id" => $result]);
+        }catch (\Exception $e){
+            Db::rollBack();
+            return Result::error("创建失败".$e->getMessage(), 0);
+        }
+
+    }
+    /**
+     * 删除黑名单
+     * @param array $data
+     * @return array
+     */
+    public function delBlackWord(array $data) :array
+    {
+        Db::beginTransaction();
+        try {
+            BlackWord::where(['name'=>$data['name']])->delete();
+            $redisKey = 'black_word';
+            $this->redis->sRem($redisKey, $data['name']);
+            Db::commit();
+            return Result::success([]);
+        }catch (\Exception $e){
+            Db::rollBack();
+            return Result::error("删除失败".$e->getMessage(), 0);
+        }
+    }
+
 }
 

+ 3 - 0
app/JsonRpc/PublicRpcServiceInterface.php

@@ -145,4 +145,7 @@ interface PublicRpcServiceInterface
      * @return array
      */
     public function uploadFile(array $data): array;
+    public function getBlackWordList(array $data): array;
+    public function addBlackWord(array $data): array;
+    public function delBlackWord(array $data): array;
 }

+ 27 - 0
app/Model/BlackWord.php

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