AI 3 miesięcy temu
rodzic
commit
d7dfcc9d0b

+ 41 - 8
app/JsonRpc/ChatService.php

@@ -827,33 +827,66 @@ class ChatService implements ChatServiceInterface
                 $data['group_id'] = $group_id;
                 ChatTopic::where(['id' => $result])->update($data);
 
+                // 查询 Chattopic 数据
+                $chattopic = Chattopic::find($result);
+            } else {
+                $chattopic = Chattopic::find($result);
+            }
+            Db::beginTransaction();
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollBack();
+            return Result::error($data, $e->getMessage());
+        }
+        return Result::success($chattopic);
+    }
+    public function applyTopic(array $data): array
+    {
+        date_default_timezone_set('Asia/Shanghai');
+        db::beginTransaction();
+        try {
+            $query = ChatTopic::where(['id' => $data['id']]);
+            $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');
+            if ($data['status'] == 2) {
                 //插入一条消息
                 $chatRecordsData = [
-                    'user_id' => $data['user_id'],
-                    'receiver_id' => $group_id,
+                    'user_id' => $topdata['user_id'],
+                    'receiver_id' => $topdata['group_id'],
                     'content' => '我创建了一个群' . Date('Y-m-d H:i:s'),
                     'msg_type' => 1,
                     'is_read' => 0,
                     'talk_type' => 2,
                     'action' => 'said',
-                    'group_receiver_id' => $data['user_id'],
+                    'group_receiver_id' => $topdata['user_id'],
                 ];
                 ChatRecords::insert($chatRecordsData);
-                // 查询 Chattopic 数据
-                $chattopic = Chattopic::find($result);
             } else {
-                $chattopic = Chattopic::find($result);
+                ChatRecords::where('user_id', $topdata['user_id'])->where('receiver_id', $topdata['group_id'])->delete();
             }
-            Db::beginTransaction();
             Db::commit();
+            if ($result) {
+                return Result::success($data);
+            } else {
+                return Result::error($data);
+            }
         } catch (\Exception $e) {
             Db::rollBack();
             return Result::error($data, $e->getMessage());
         }
-        return Result::success($chattopic);
+        if (empty($data['id'])) {
+            return Result::error('id不能为空');
+        }
     }
     public function updateTopic(array $data): array
     {
+        if (empty($data['id'])) {
+            return Result::error('id不能为空');
+        }
+
         $result = ChatTopic::where(['id' => $data['id']])->update($data);
         if ($result) {
             return Result::success($data);

+ 2 - 0
app/JsonRpc/ChatServiceInterface.php

@@ -215,4 +215,6 @@ interface ChatServiceInterface
      */
     public function getTopicsListAdmin(array $data): array;
 
+    public function applyTopic(array $data): array;
+
 }

+ 2 - 1
config/autoload/server.php

@@ -1,6 +1,6 @@
 <?php
 
-declare(strict_types=1);
+declare (strict_types = 1);
 /**
  * This file is part of Hyperf.
  *
@@ -29,6 +29,7 @@ return [
 
     ],
     'settings' => [
+        'timezone' => 'Asia/Shanghai',
         Constant::OPTION_ENABLE_COROUTINE => true,
         Constant::OPTION_WORKER_NUM => swoole_cpu_num(),
         Constant::OPTION_PID_FILE => BASE_PATH . '/runtime/hyperf.pid',