From 3c45d268fdde145d7acdf0aee6b60c2d75423c2b Mon Sep 17 00:00:00 2001 From: ASUS <515617283@qq.com> Date: Wed, 22 Oct 2025 15:02:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=98=E6=89=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/workermans/model/Base.php | 22 ++++++++++++- plugin/webman/gateway/Events.php | 56 ++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/extend/workermans/model/Base.php b/extend/workermans/model/Base.php index 26d756a..94887df 100644 --- a/extend/workermans/model/Base.php +++ b/extend/workermans/model/Base.php @@ -259,11 +259,13 @@ class Base extends Model } - // 定时器处理消息回执/在线列表 + // 定时器处理消息回执/在线列表/折扣信息 public static function geteventredis_new() { print_r('定时器' . "\r\n"); $gateway = Gateway::class; + // 处理折扣消息 + self::savetimediscount(); // 处理消息(包含推送) $redis_name = Gateway::getAllClientSessions(); foreach ($redis_name as $client_id => $client_id_data) { @@ -354,6 +356,24 @@ class Base extends Model } + public static function savetimediscount() + { + $table = Redis::get('time_discount_info'); + if($table) { + $table_arr = json_decode($table, true); + foreach ($table_arr as $k => $v) { + if(!Gateway::getClientCountByGroup($v)) { + print_r($v . '过期'); + unset($table_arr[$k]); + Redis::del($v); + } + } + Redis::set('time_discount_info', json_encode($table_arr)); + } + } + + + public static function saveonlinelist(array $client_id_list) { if(is_array($client_id_list)) { diff --git a/plugin/webman/gateway/Events.php b/plugin/webman/gateway/Events.php index 131020a..afc46fb 100644 --- a/plugin/webman/gateway/Events.php +++ b/plugin/webman/gateway/Events.php @@ -117,6 +117,62 @@ class Events return; } + if(!empty($message['operate_type'])) { + // 桌码 + if(empty($message['table_code']) || empty($message['shop_id'])) { + Gateway::sendToClient($client_id, json_encode(['msg' => '桌码或shop_id不能为空'])); + return; + } + $redis_str = Base::get_shopping_save_uid($message['shop_id'], $message['table_code']) . ':time_discount'; + // 限时折扣修改 + if($message['operate_type'] == 'time_discount_save') { + if(empty($message)) { + $res = Redis::del($redis_str); + }else { + $res = Redis::set($redis_str, $message['data']); + // 将桌号存入redis 以便及时删除 + $time_discount_info = Redis::get('time_discount_info'); + if($time_discount_info) { + $time_discount_info_arr = json_decode($time_discount_info, true); + $time_discount_info_arr = array_merge($time_discount_info_arr, $redis_str); + Redis::set('time_discount_info', json_encode($time_discount_info_arr)); + }else { + Redis::set('time_discount_info', json_encode($redis_str)); + } + } + $snd_data = [ + 'msg' => '折扣修改', + 'operate_type' => $message['operate_type'], + 'msg_id' => '', + 'type' => 'time_discount', + 'status' => $res, + 'data' => json_decode($message, true), + ]; + Gateway::sendToClient($client_id, json_encode($snd_data)); + return; + }elseif ($message['operate_type'] == 'time_discount_get') { + // 限时折扣获取 + $snd_data = [ + 'msg' => '折扣获取', + 'operate_type' => $message['operate_type'], + 'msg_id' => '', + 'type' => 'time_discount', + 'status' => 1, + 'data' => Redis::get($redis_str), + ]; + Gateway::sendToClient($client_id, json_encode($snd_data)); + return; + } + } + if(!empty($message['operate_type']) && $message['operate_type'] == 'time_discount_get') { + // 桌码 + if(empty($message['table_code'])) { + Gateway::sendToClient($client_id, json_encode(['msg' => '桌码或data不能为空'])); + return; + } + + } + // 只在初始化的时候绑定 if(!empty($message['operate_type']) && $message['operate_type'] == 'init') { // 添加在线客户端数量