Browse Source

系统消息

rkljw 23 giờ trước cách đây
mục cha
commit
cef2c40698

+ 20 - 0
app/Amqp/Producer/MqProducer.php

@@ -0,0 +1,20 @@
+<?php
+
+declare (strict_types = 1);
+
+namespace App\Amqp\Producer;
+
+use Hyperf\Amqp\Annotation\Producer;
+use Hyperf\Amqp\Message\ProducerMessage;
+
+#[Producer(exchange: 'chatprod', routingKey: 'chatprod')]
+class MqProducer extends ProducerMessage
+{
+    public function __construct($data)
+    {
+//        $this->poolName = 'default';
+        var_dump($data, '生产者数据');
+
+        $this->payload = $data;
+    }
+}

+ 77 - 37
app/JsonRpc/ChatService.php

@@ -15,7 +15,10 @@ use App\Tools\PublicData;
 use App\Tools\Result;
 use Hyperf\DbConnection\Db;
 use Hyperf\RpcServer\Annotation\RpcService;
+use Hyperf\Context\ApplicationContext as ContextApplicationContext;
+use Hyperf\Amqp\Producer;
 
+use App\Amqp\Producer\MqProducer;
 #[RpcService(name: "ChatService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class ChatService implements ChatServiceInterface
 {
@@ -848,35 +851,13 @@ class ChatService implements ChatServiceInterface
             $data['created_at'] = date('Y-m-d H:i:s');
             $data['updated_at'] = date('Y-m-d H:i:s');
             $result = ChatTopic::insertGetId($data);
-            var_dump($result, 'tedst111111111111111111111111111111');
-
-            if ($result && $data['is_group'] == 1) {
-                //chat_group
-                $group_id = PublicData::uuid();
-                $groupData = [
-                    'id' => $group_id,
-                    'creator_id' => $data['user_id'],
-                    'group_name' => $data['group_name'] ?? '',
-                    'profile' => $data['profile'] ?? 0,
-                ];
-                $groupResult = ChatGroups::insertGetId($groupData);
-                $groupMemberData = [
-                    'id' => PublicData::uuid(),
-                    'user_id' => $data['user_id'],
-                    'group_id' => $group_id,
-                    'leader' => 2,
-                ];
-                $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
-                //更新result的 group_id
-                $data['group_id'] = $group_id;
-                ChatTopic::where(['id' => $result])->update($data);
-
-                // 查询 Chattopic 数据
-                $chattopic = Chattopic::find($result);
-            } else {
-                $chattopic = Chattopic::find($result);
-            }
-
+            $this->sendMessage([
+                'talk_type'=>300,
+                'title'=>$data['title'],
+                'content'=>'提交了审核',
+                'messageType'=>4,
+            ]);
+            $chattopic = Chattopic::find($result);
             Db::commit();
         } catch (\Exception $e) {
             Db::rollBack();
@@ -893,14 +874,33 @@ class ChatService implements ChatServiceInterface
             $topdata = $query->first();
 
             $result = ChatTopic::where(['id' => $data['id']])->update(['status' => $data['status']]);
-            var_dump($result, 'tedst111111111111111');
-            var_dump(date('Y-m-d H:i:s'), 'tedst111111111111111');
+            // var_dump($data, 'tedst111111111111111');
+            // var_dump(date('Y-m-d H:i:s'), 'tedst111111111111111');
             $creatter = $topdata['user_id'];
-            if ($data['status'] == 2) {
+            if ($data['status'] == 2 && $topdata['is_group'] == 1) {
+                $group_id = PublicData::uuid();
+                $groupData = [
+                    'id' => $group_id,
+                    'creator_id' => $topdata['user_id'],
+                    'group_name' => $topdata['group_name'] ?? '',
+                    'profile' => '',
+                ];
+                $groupResult = ChatGroups::insertGetId($groupData);
+                $groupMemberData = [
+                    'id' => PublicData::uuid(),
+                    'user_id' => $topdata['user_id'],
+                    'group_id' => $group_id,
+                    'leader' => 2,
+                ];
+                $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
+                //更新result的 group_id
+                $datas['group_id'] = $group_id;
+                ChatTopic::where(['id' => $data['id']])->update($datas);
+
                 //插入一条消息
                 $chatRecordsData = [
                     'user_id' => $topdata['user_id'],
-                    'receiver_id' => $topdata['group_id'],
+                    'receiver_id' => $group_id,
                     'content' => '我创建了一个群' . Date('Y-m-d H:i:s'),
                     'msg_type' => 1,
                     'is_read' => 0,
@@ -909,10 +909,26 @@ class ChatService implements ChatServiceInterface
                     'group_receiver_id' => $topdata['user_id'],
                 ];
                 ChatRecords::insert($chatRecordsData);
+                $this->sendMessage([
+                    'talk_type'=>301,
+                    'title'=>$topdata['title'],
+                    'content'=>'审核通过',
+                    'messageType'=>4,
+                    'user_id'=>$topdata['user_id'],
+                ]);
             } elseif ($data['status'] == 3) {
-                ChatRecords::where('receiver_id', $topdata['group_id'])->delete();
-                ChatGroupsMember::where('group_id', $topdata['group_id'])
-                    ->where([["user_id", '!=', $creatter]])->delete();
+                $this->sendMessage([
+                    'talk_type'=>301,
+                    'title'=>$topdata['title'],
+                    'content'=>'审核拒绝',
+                    'messageType'=>4,
+                    'user_id'=>$topdata['user_id'],
+                ]);
+                if(isset($topdata['group_id']) && !empty($topdata['group_id'])){
+                    ChatRecords::where('receiver_id', $topdata['group_id'])->delete();
+                    ChatGroupsMember::where('group_id', $topdata['group_id'])
+                        ->where([["user_id", '!=', $creatter]])->delete();
+                }   
             }
             Db::commit();
             if ($result) {
@@ -933,7 +949,12 @@ class ChatService implements ChatServiceInterface
         if (empty($data['id'])) {
             return Result::error('id不能为空');
         }
-
+        $this->sendMessage([
+            'talk_type'=>300,
+            'title'=>$data['title'],
+            'content'=>'提交了审核',
+            'messageType'=>4,
+        ]);
         $result = ChatTopic::where(['id' => $data['id']])->update($data);
         if ($result) {
             return Result::success($data);
@@ -1209,4 +1230,23 @@ class ChatService implements ChatServiceInterface
             ];
         return  Result::success($result);
     }
+     
+    /**
+     * 发送消息
+     * @param array $messageData
+     * @return void
+     */
+    public function sendMessage($messageData){
+        $msg =[
+          'talk_type'=>$messageData['talk_type'],
+          'title'=>$messageData['title'],
+          'content'=>$messageData['content'],
+          'messageType'=>$messageData['messageType'],
+          'user_id'=>$messageData['user_id']??'',
+        ];
+        $message = new MqProducer($msg);
+        $producer = ContextApplicationContext::getContainer()->get(Producer::class);
+        $producer->produce($message);
+        
+    }
 }

+ 61 - 53
app/Tools/PublicData.php

@@ -1,54 +1,62 @@
-<?php
-namespace App\Tools;
-use App\Constants\ErrorCode;
-use Hyperf\Snowflake\IdGeneratorInterface;
-use Hyperf\Context\ApplicationContext;
-class PublicData
-{
-    /**
-     * 递归查询
-     * @param $menuItems
-     * @param $parentId
-     * @return array
-     */
-    public static  function buildMenuTree($menuItems, $parentId = 0) {
-        $tree = [];
-        foreach ($menuItems as $item) {
-            if ($item['pid'] == $parentId) {
-                // 找到子菜单
-                $children = self::buildMenuTree($menuItems, $item['id']);
-                // 如果子菜单存在,则添加到当前菜单的children中
-                if ($children) {
-                    $item['children'] = $children;
-                }
-                // 将当前菜单添加到树中
-                $tree[] = $item;
-            }
-        }
-        return $tree;
-    }
-
-    /**
-     * 计算两个时间差的天数
-     * @param $sTime
-     * @param $eTime
-     * @return float
-     */
-    public static function residueDay($sTime,$eTime)
-    {
-        $startTime = strtotime($sTime);
-        $endTime = strtotime($eTime);
-        $diffDays = floor(($endTime - $startTime) / (60 * 60 * 24));
-        return $diffDays;
-    }
-
-    public static function uuid()
-    {
-        var_dump("uuid==========");
-        $container = ApplicationContext::getContainer();
-        $generator = $container->get(IdGeneratorInterface::class);
-        var_dump("uuid==+++++++++++",$generator->generate());
-        return $generator->generate();
-    }
-
+<?php
+namespace App\Tools;
+use App\Constants\ErrorCode;
+use Hyperf\Snowflake\IdGeneratorInterface;
+use Hyperf\Context\ApplicationContext;
+class PublicData
+{
+    /**
+     * 递归查询
+     * @param $menuItems
+     * @param $parentId
+     * @return array
+     */
+    public static  function buildMenuTree($menuItems, $parentId = 0) {
+        $tree = [];
+        foreach ($menuItems as $item) {
+            if ($item['pid'] == $parentId) {
+                // 找到子菜单
+                $children = self::buildMenuTree($menuItems, $item['id']);
+                // 如果子菜单存在,则添加到当前菜单的children中
+                if ($children) {
+                    $item['children'] = $children;
+                }
+                // 将当前菜单添加到树中
+                $tree[] = $item;
+            }
+        }
+        return $tree;
+    }
+
+    /**
+     * 计算两个时间差的天数
+     * @param $sTime
+     * @param $eTime
+     * @return float
+     */
+    public static function residueDay($sTime,$eTime)
+    {
+        $startTime = strtotime($sTime);
+        $endTime = strtotime($eTime);
+        $diffDays = floor(($endTime - $startTime) / (60 * 60 * 24));
+        return $diffDays;
+    }
+
+    /**
+     * 生成雪花算法ID
+     * @return int|false
+     */
+    public static function uuid()
+    {
+        try {
+            $container = ApplicationContext::getContainer();
+            $generator = $container->get(IdGeneratorInterface::class);
+            return $generator->generate();
+        } catch (\Throwable $e) {
+            // 记录错误日志
+            error_log("Snowflake ID generation failed: " . $e->getMessage());
+            return false;
+        }
+    }
+
 }

+ 1 - 1
composer.json

@@ -42,7 +42,7 @@
         "hyperf/socketio-server": "^3.1",
         "hyperf/utils": "^3.1",
         "hyperf/websocket-server": "^3.1",
-        "ramsey/uuid": "^4.7"
+        "ramsey/uuid": "^4.8"
     },
     "require-dev": {
         "friendsofphp/php-cs-fixer": "^3.0",

+ 51 - 49
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "6b9f543cda6751d2d957153d112192e9",
+    "content-hash": "9ca8016d57cfc223d0b85a820c0fc8bb",
     "packages": [
         {
             "name": "brick/math",
@@ -894,27 +894,36 @@
         },
         {
             "name": "hyperf/amqp",
-            "version": "v3.1.28",
+            "version": "v3.1.58",
             "source": {
                 "type": "git",
                 "url": "https://github.com/hyperf/amqp.git",
-                "reference": "c96e294e99e68113ed3e237db8f976308ee42ba7"
+                "reference": "15ed5c2e39d35e1b28be9afad635c3fd9f93841b"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/hyperf/amqp/zipball/c96e294e99e68113ed3e237db8f976308ee42ba7",
-                "reference": "c96e294e99e68113ed3e237db8f976308ee42ba7",
-                "shasum": ""
+                "url": "https://api.github.com/repos/hyperf/amqp/zipball/15ed5c2e39d35e1b28be9afad635c3fd9f93841b",
+                "reference": "15ed5c2e39d35e1b28be9afad635c3fd9f93841b",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
             },
             "require": {
                 "doctrine/instantiator": "^1.2.0",
                 "hyperf/codec": "~3.1.0",
+                "hyperf/collection": "~3.1.0",
+                "hyperf/context": "~3.1.0",
                 "hyperf/contract": "~3.1.0",
+                "hyperf/coordinator": "~3.1.0",
                 "hyperf/coroutine": "~3.1.0",
+                "hyperf/engine": "^2.0",
                 "hyperf/pool": "~3.1.0",
                 "hyperf/process": "~3.1.0",
                 "hyperf/support": "~3.1.0",
-                "hyperf/utils": "~3.1.0",
                 "php": ">=8.1",
                 "php-amqplib/php-amqplib": "^3.5",
                 "psr/container": "^1.0 || ^2.0",
@@ -927,11 +936,11 @@
             },
             "type": "library",
             "extra": {
-                "branch-alias": {
-                    "dev-master": "3.1-dev"
-                },
                 "hyperf": {
                     "config": "Hyperf\\Amqp\\ConfigProvider"
+                },
+                "branch-alias": {
+                    "dev-master": "3.1-dev"
                 }
             },
             "autoload": {
@@ -966,7 +975,7 @@
                     "type": "open_collective"
                 }
             ],
-            "time": "2024-06-24T01:53:39+00:00"
+            "time": "2025-06-23T03:55:31+00:00"
         },
         {
             "name": "hyperf/cache",
@@ -6342,20 +6351,26 @@
         },
         {
             "name": "ramsey/uuid",
-            "version": "4.7.6",
+            "version": "4.8.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/ramsey/uuid.git",
-                "reference": "91039bc1faa45ba123c4328958e620d382ec7088"
+                "reference": "fdf4dd4e2ff1813111bd0ad58d7a1ddbb5b56c28"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/ramsey/uuid/zipball/91039bc1faa45ba123c4328958e620d382ec7088",
-                "reference": "91039bc1faa45ba123c4328958e620d382ec7088",
-                "shasum": ""
+                "url": "https://api.github.com/repos/ramsey/uuid/zipball/fdf4dd4e2ff1813111bd0ad58d7a1ddbb5b56c28",
+                "reference": "fdf4dd4e2ff1813111bd0ad58d7a1ddbb5b56c28",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
             },
             "require": {
-                "brick/math": "^0.8.8 || ^0.9 || ^0.10 || ^0.11 || ^0.12",
+                "brick/math": "^0.8.8 || ^0.9 || ^0.10 || ^0.11 || ^0.12 || ^0.13",
                 "ext-json": "*",
                 "php": "^8.0",
                 "ramsey/collection": "^1.2 || ^2.0"
@@ -6364,26 +6379,23 @@
                 "rhumsaa/uuid": "self.version"
             },
             "require-dev": {
-                "captainhook/captainhook": "^5.10",
+                "captainhook/captainhook": "^5.25",
                 "captainhook/plugin-composer": "^5.3",
-                "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
-                "doctrine/annotations": "^1.8",
-                "ergebnis/composer-normalize": "^2.15",
-                "mockery/mockery": "^1.3",
+                "dealerdirect/phpcodesniffer-composer-installer": "^1.0",
+                "ergebnis/composer-normalize": "^2.47",
+                "mockery/mockery": "^1.6",
                 "paragonie/random-lib": "^2",
-                "php-mock/php-mock": "^2.2",
-                "php-mock/php-mock-mockery": "^1.3",
-                "php-parallel-lint/php-parallel-lint": "^1.1",
-                "phpbench/phpbench": "^1.0",
-                "phpstan/extension-installer": "^1.1",
-                "phpstan/phpstan": "^1.8",
-                "phpstan/phpstan-mockery": "^1.1",
-                "phpstan/phpstan-phpunit": "^1.1",
-                "phpunit/phpunit": "^8.5 || ^9",
-                "ramsey/composer-repl": "^1.4",
-                "slevomat/coding-standard": "^8.4",
-                "squizlabs/php_codesniffer": "^3.5",
-                "vimeo/psalm": "^4.9"
+                "php-mock/php-mock": "^2.6",
+                "php-mock/php-mock-mockery": "^1.5",
+                "php-parallel-lint/php-parallel-lint": "^1.4.0",
+                "phpbench/phpbench": "^1.2.14",
+                "phpstan/extension-installer": "^1.4",
+                "phpstan/phpstan": "^2.1",
+                "phpstan/phpstan-mockery": "^2.0",
+                "phpstan/phpstan-phpunit": "^2.0",
+                "phpunit/phpunit": "^9.6",
+                "slevomat/coding-standard": "^8.18",
+                "squizlabs/php_codesniffer": "^3.13"
             },
             "suggest": {
                 "ext-bcmath": "Enables faster math with arbitrary-precision integers using BCMath.",
@@ -6418,19 +6430,9 @@
             ],
             "support": {
                 "issues": "https://github.com/ramsey/uuid/issues",
-                "source": "https://github.com/ramsey/uuid/tree/4.7.6"
+                "source": "https://github.com/ramsey/uuid/tree/4.8.1"
             },
-            "funding": [
-                {
-                    "url": "https://github.com/ramsey",
-                    "type": "github"
-                },
-                {
-                    "url": "https://tidelift.com/funding/github/packagist/ramsey/uuid",
-                    "type": "tidelift"
-                }
-            ],
-            "time": "2024-04-27T21:32:50+00:00"
+            "time": "2025-06-01T06:28:46+00:00"
         },
         {
             "name": "swow/psr7-plus",
@@ -11192,12 +11194,12 @@
     ],
     "aliases": [],
     "minimum-stability": "dev",
-    "stability-flags": [],
+    "stability-flags": {},
     "prefer-stable": true,
     "prefer-lowest": false,
     "platform": {
         "php": ">=8.1"
     },
-    "platform-dev": [],
+    "platform-dev": {},
     "plugin-api-version": "2.6.0"
 }

+ 42 - 0
config/autoload/amqp.php

@@ -0,0 +1,42 @@
+<?php
+
+declare (strict_types = 1);
+use function Hyperf\Support\env;
+return [
+    'enable' => true,
+    'default' => [
+        'host' => env('AMQP_HOST', '192.168.1.127'),
+        'port' => (int) env('AMQP_PORT', 5672),
+        'user' => env('AMQP_USER', 'guest'),
+        'password' => env('AMQP_PASSWORD', 'guest'),
+        'vhost' => '/',
+        'concurrent' => [
+            'limit' => 1,
+        ],
+        'pool' => [
+            'min_connections' => 1,
+            'max_connections' => 1, // 限制最大连接数为1
+            'connect_timeout' => 1000.0,
+            'wait_timeout' => 3.0,
+            'heartbeat' => -1,
+            
+        ],
+        'params' => [
+            'insist' => false,
+            'login_method' => 'AMQPLAIN',
+            'login_response' => null,
+            'locale' => 'en_US',
+            'connection_timeout' => 3.0,
+            // 尽量保持是 heartbeat 数值的两倍
+            'read_write_timeout' => 6.0,
+            'context' => null,
+            'keepalive' => false,
+            // 尽量保证每个消息的消费时间小于心跳时间
+            'heartbeat' => 3,
+            'close_on_destruct' => false,
+        ],
+    ],
+    'pool2' => [
+
+    ],
+];

+ 1 - 1
config/autoload/cache.php

@@ -11,7 +11,7 @@ declare(strict_types=1);
  */
 return [
     'default' => [
-        'driver' => Hyperf\Cache\Driver\RedisDriver::class,
+        'driver' => Hyperf\Cache\Driver\FileSystemDriver::class,
         'packer' => Hyperf\Codec\Packer\PhpSerializerPacker::class,
         'prefix' => 'c:',
         'skip_cache_results' => [],

+ 2 - 2
config/autoload/redis.php

@@ -13,8 +13,8 @@ use function Hyperf\Support\env;
 
 return [
     'default' => [
-        'host' => env('REDIS_HOST', '192.168.31.193'),
-        'auth' => env('REDIS_AUTH', 123456),
+        'host' => env('REDIS_HOST', '127.0.0.1'),
+        'auth' => env('REDIS_AUTH', null),
         'port' => (int) env('REDIS_PORT', 6379),
         'db' => (int) env('REDIS_DB', 0),
         'pool' => [

+ 18 - 0
config/autoload/snowflake.php

@@ -0,0 +1,18 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * This file is part of Hyperf.
+ *
+ * @link     https://www.hyperf.io
+ * @document https://hyperf.wiki
+ * @contact  group@hyperf.io
+ * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
+ */
+use function Hyperf\Support\env;
+
+return [
+    'begin_second' => Hyperf\Snowflake\MetaGenerator::DEFAULT_BEGIN_SECOND,
+    'datacenter_id' => env('SNOWFLAKE_DATACENTER_ID', 1),
+    'worker_id' => env('SNOWFLAKE_WORKER_ID', 1),
+];