From 46abae81481aa821092f021d4f3207221f3084a2 Mon Sep 17 00:00:00 2001 From: ASUS <515617283@qq.com> Date: Fri, 5 Dec 2025 13:55:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B8=B8=E8=A7=81=E7=BE=A4=E8=81=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chat/controller/GroupController.php | 66 ----------------------- app/chat/controller/MessageController.php | 6 +-- app/chat/model/ChatGroup.php | 52 ++++++++++++++++++ config/route.php | 1 - scripts/orderDetailUpdate.php | 60 +++++++++++---------- 5 files changed, 87 insertions(+), 98 deletions(-) diff --git a/app/chat/controller/GroupController.php b/app/chat/controller/GroupController.php index e97b07f..49bc1af 100644 --- a/app/chat/controller/GroupController.php +++ b/app/chat/controller/GroupController.php @@ -94,72 +94,6 @@ class GroupController extends ApiController return $this->success($data); } - - - /** - * 创建群(仅商家可创建) - */ - public function create(Request $request): Response - { - if ($this->user_type == 1) { // 2=商家 - return $this->error('仅商家可创建群聊'); - } - $shop_id = $request->post('shop_id', 0); - if(empty($shop_id)) { - return $this->error('参数不完整'); - } - $shop = Db::name('tb_shop_info')->where(['id' => $shop_id])->find(); - if(empty($shop)) { - return $this->error('店铺不存在'); - } - // 查找群数量 - $count = Db::name('chat_group')->where(['shop_id' => $shop_id])->count(); - $name = $request->post('name')?:$shop['shop_name'] . '粉丝福利' . $count + 1 . '群'; - $avatar = $request->post('avatar')?:$shop['logo']; - $announcement = $request->post('announcement', ''); - $isPublic = $request->post('is_public', 0); - $now = d(); - try { - Db::startTrans(); - // 创建群 - $group_id = Db::name('chat_group')->insertGetId([ - 'id' => Random::build('alnum', 32), - 'name' => $name, - 'shop_id' => $shop_id, - 'avatar' => $avatar, - 'owner_id' => $this->uid, - 'announcement' => $announcement, - 'is_public' => $isPublic, - 'created_time' => $now, - ]); - // 群主加入群 - Db::name('chat_group_member')->insert([ - 'group_id' => $group_id, - 'user_id' => $this->uid, - 'role' => 1, // 1=群主 - 'join_time' => $now, - ]); - $user = Db::name('chat_user')->where(['user_id' => $this->uid])->find(); - $data = [ - 'group_info' => [ - 'id' => $group_id, - 'name' => $name, - 'avatar' => $avatar, - ], - 'member_info' => [ - 'user_id' => $this->uid, - 'avatar' => $user['avatar'], - 'nick_name' => $user['nick_name'], - ] - ]; - Db::commit(); - return $this->success($data); - }catch (\Throwable $exception) { - Db::rollback(); - return $this->error($exception->getMessage()); - } - } - /** * 加群 */ diff --git a/app/chat/controller/MessageController.php b/app/chat/controller/MessageController.php index 39767cf..44da371 100644 --- a/app/chat/controller/MessageController.php +++ b/app/chat/controller/MessageController.php @@ -149,8 +149,8 @@ class MessageController extends ApiController return $this->error('请传入有效会话ID'); } $msgIds = explode(',', $msgIds); - $query = Db::name('chat_message')->whereIn('session_id', $msgIds)->where('to_id', $this->uid) - ->where('is_read', 0); +// $query = Db::name('chat_message')->whereIn('session_id', $msgIds)->where('to_id', $this->uid) +// ->where('is_read', 0); try { Db::startTrans(); // 更新未读计数 @@ -158,7 +158,7 @@ class MessageController extends ApiController Db::name('chat_unread_count')->where(['user_id' => $this->uid, 'session_id' => $sessionId])->update(['count' => 0, 'updated_time' => d()]); } // 批量更新 - $query->update(['is_read' => 1]); +// $query->update(['is_read' => 1]); Db::commit(); return $this->success(true); }catch (\Throwable $exception) { diff --git a/app/chat/model/ChatGroup.php b/app/chat/model/ChatGroup.php index 5179c5a..b6aa68a 100644 --- a/app/chat/model/ChatGroup.php +++ b/app/chat/model/ChatGroup.php @@ -2,6 +2,8 @@ namespace app\chat\model; +use ba\Random; +use support\Log; use support\think\Db; class ChatGroup extends BaseModel @@ -20,4 +22,54 @@ class ChatGroup extends BaseModel } + // 创建群聊 + public static function addShop($shop_id) + { + $shop = Db::name('tb_shop_info')->where(['id' => $shop_id])->find(); + if(empty($shop)) { + Log::info('店铺不存在'); + } + // 查找群数量 + $count = Db::name('chat_group')->where(['shop_id' => $shop_id])->count(); + $name = $shop['shop_name'] . '粉丝福利' . $count + 1 . '群'; + $avatar = $shop['logo']; + $now = d(); + try { + Db::startTrans(); + // 创建群 + $group_id = Db::name('chat_group')->insertGetId([ + 'id' => Random::build('alnum', 32), + 'name' => $name, + 'shop_id' => $shop_id, + 'avatar' => $avatar, + 'owner_id' => $shop_id, + 'created_time' => $now, + ]); + // 群主加入群 + Db::name('chat_group_member')->insert([ + 'group_id' => $group_id, + 'user_id' => $shop_id, + 'role' => 1, // 1=群主 + 'join_time' => $now, + ]); + $user = Db::name('chat_user')->where(['user_id' => $shop_id])->find(); + if(!$user) { + $res = Db::name('chat_user')->insert([ + 'user_id' => $shop_id, + 'nick_name' => $shop['shop_name'], + 'avatar' => $shop['logo'], + 'type' => 2, + 'created_time' => d(), + ]); + Log::info('创建店铺结果 ' . $res . $shop_id); + } + Db::commit(); + }catch (\Throwable $exception) { + Db::rollback(); + Log::info('创建店铺错误 ' . $exception->getMessage()); + } + } + + + } \ No newline at end of file diff --git a/config/route.php b/config/route.php index c70af75..b23ae97 100644 --- a/config/route.php +++ b/config/route.php @@ -28,7 +28,6 @@ Route::group('/api/chat', function () { Route::group('/group', function () { Route::post('/shopinfo', app\chat\controller\GroupController::class . '@shopInfo'); // 店铺群信息 Route::post('/info', app\chat\controller\GroupController::class . '@info'); // 群信息 - Route::post('/create', app\chat\controller\GroupController::class . '@create'); // 创建群(商家) Route::post('/join', app\chat\controller\GroupController::class . '@join'); // 加群 Route::post('/getgrepurl', app\chat\controller\GroupController::class . '@getgrepurl'); // 群邀请参数 Route::post('/quit', app\chat\controller\GroupController::class . '@quit'); // 退群 diff --git a/scripts/orderDetailUpdate.php b/scripts/orderDetailUpdate.php index 71db8ca..bdccff1 100644 --- a/scripts/orderDetailUpdate.php +++ b/scripts/orderDetailUpdate.php @@ -40,35 +40,39 @@ use support\Redis; Log::info('MQ收到消息[商品状态更新]--->' . $data . '--->' . $date_time . "\n"); $datInfo= json_decode($data, true); if(is_array($datInfo)) { - // 如果是数字。则打印订单 - $is_log = false; - $curl_error = ''; - $rand = 'product_update' . Random::build(); - $send_id = Base::get_shopping_save_uid($datInfo['shopId'], 'all'); - $snd_data =[ - 'msg' => '购物车刷新', - 'operate_type' => 'reload', - 'msg_id' => $rand, - 'type' => $datInfo['type'], - 'data_type' => 'cart', - 'status' => 1 - ]; - Log::info('推送组'.$send_id.'内容'.json_encode($snd_data)); - $snd_data_json = json_encode($snd_data); - Gateway::$registerAddress = '127.0.0.1:1238'; - $res = Gateway::sendToGroup($send_id, $snd_data_json); - Log::info('商品状态更新推送结果-->' . $res); + if($datInfo['type'] == 'add_shop') { + // 创建群聊 + \app\chat\model\ChatGroup::addShop($datInfo); + }else { + $is_log = false; + $curl_error = ''; + $rand = 'product_update' . Random::build(); + $send_id = Base::get_shopping_save_uid($datInfo['shopId'], 'all'); + $snd_data =[ + 'msg' => '购物车刷新', + 'operate_type' => 'reload', + 'msg_id' => $rand, + 'type' => $datInfo['type'], + 'data_type' => 'cart', + 'status' => 1 + ]; + Log::info('推送组'.$send_id.'内容'.json_encode($snd_data)); + $snd_data_json = json_encode($snd_data); + Gateway::$registerAddress = '127.0.0.1:1238'; + $res = Gateway::sendToGroup($send_id, $snd_data_json); + Log::info('商品状态更新推送结果-->' . $res); - if($is_log) { - Db::table('tb_mq_log')->insert([ - 'queue' => $queue, - 'msg' => $data, - 'type' => 'product_update', - 'plat' => 'product', - 'create_time' => date('Y-m-d H:i:s'), - 'fail_time' => date('Y-m-d H:i:s'), - 'err_info' => $curl_error, - ]); + if($is_log) { + Db::table('tb_mq_log')->insert([ + 'queue' => $queue, + 'msg' => $data, + 'type' => 'product_update', + 'plat' => 'product', + 'create_time' => date('Y-m-d H:i:s'), + 'fail_time' => date('Y-m-d H:i:s'), + 'err_info' => $curl_error, + ]); + } } } $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);