|
@@ -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);
|