From 8545b230653dccec7ce127cf7b0249f68a577a78 Mon Sep 17 00:00:00 2001 From: ASUS <515617283@qq.com> Date: Mon, 22 Dec 2025 13:36:17 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=90=E6=97=B6=E6=8A=98=E6=89=A3=E7=9B=B8?= =?UTF-8?q?=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/workermans/model/Base.php | 61 ++++++++++++++++++++++++++++ extend/workermans/model/Shopping.php | 40 +++++++++++++----- plugin/webman/gateway/Events.php | 36 ++++++++-------- 3 files changed, 108 insertions(+), 29 deletions(-) diff --git a/extend/workermans/model/Base.php b/extend/workermans/model/Base.php index 8a44e7b..b8f8767 100644 --- a/extend/workermans/model/Base.php +++ b/extend/workermans/model/Base.php @@ -783,6 +783,10 @@ class Base extends Model } } $res = Db::execute($sql); + // 顺便修改限时折扣 + (new static())->delTimeInfo($message); + $message['table_code'] = $message['new_table_code']; + (new static())->setTimeInfo($message); Db::commit(); return $res; }catch (Exception $e) { @@ -918,6 +922,63 @@ class Base extends Model } } + // 获取限时折扣 + public function getTimeInfo($message) + { + $redis_str = Base::get_shopping_save_uid($message['shop_id'], $message['table_code']) . ':time_discount'; + $time_dis_info = Redis::get($redis_str); + if($time_dis_info) { + $time_dis_info = json_decode($time_dis_info, true); + }else { + if(!empty($message['time_dis_info'])) { + $time_dis_info = !is_array($message['time_dis_info'])?json_decode($message['time_dis_info'], true):$message['time_dis_info']; + }else { + $time_dis_info = null; + } + } + return $time_dis_info; + } + + // 限时折扣修改 + public function setTimeInfo($message) + { + $redis_str = Base::get_shopping_save_uid($message['shop_id'], $message['table_code']) . ':time_discount'; + if(empty($message['data'])) { + $res = Redis::del($redis_str); + }else { + $res = Redis::setEx($redis_str, '86400', json_encode($message['data'])); + // 将桌号存入redis 以便及时删除 + $time_discount_info = Redis::get('time_discount:info'); + if($time_discount_info) { + $arr_time_discount_info = explode(',', $time_discount_info); + if(!in_array($redis_str, $arr_time_discount_info)) { + $time_discount_info = array_merge($arr_time_discount_info, [$redis_str]); + Redis::set('time_discount:info', implode(',', $time_discount_info)); + } + }else { + Redis::set('time_discount:info', $redis_str); + } + } + return $res; + } + + + // 限时折扣删除 + public function delTimeInfo($message) + { + $redis_str = Base::get_shopping_save_uid($message['shop_id'], $message['table_code']) . ':time_discount'; + Redis::del($redis_str); + $time_discount_info = Redis::get('time_discount:info'); + if($time_discount_info) { + $arr_time_discount_info = explode(',', $time_discount_info); + $result = array_search($redis_str, $arr_time_discount_info); + if($result !== false) { + unset($time_discount_info[$result]); + Redis::set('time_discount:info', implode(',', $time_discount_info)); + } + } + } + } \ No newline at end of file diff --git a/extend/workermans/model/Shopping.php b/extend/workermans/model/Shopping.php index f545a88..19e6805 100644 --- a/extend/workermans/model/Shopping.php +++ b/extend/workermans/model/Shopping.php @@ -61,17 +61,18 @@ class Shopping extends Base // 绑定桌码和 client_id Gateway::bindUid($client_id, $table_code); // 限时折扣 - $redis_str = Base::get_shopping_save_uid($message['shop_id'], $message['table_code']) . ':time_discount'; - $time_dis_info = Redis::get($redis_str); - if($time_dis_info) { - $time_dis_info = json_decode($time_dis_info, true); - }else { - if(!empty($message['time_dis_info'])) { - $time_dis_info = !is_array($message['time_dis_info'])?json_decode($message['time_dis_info'], true):$message['time_dis_info']; - }else { - $time_dis_info = null; - } - } +// $redis_str = Base::get_shopping_save_uid($message['shop_id'], $message['table_code']) . ':time_discount'; +// $time_dis_info = Redis::get($redis_str); +// if($time_dis_info) { +// $time_dis_info = json_decode($time_dis_info, true); +// }else { +// if(!empty($message['time_dis_info'])) { +// $time_dis_info = !is_array($message['time_dis_info'])?json_decode($message['time_dis_info'], true):$message['time_dis_info']; +// }else { +// $time_dis_info = null; +// } +// } + $time_dis_info = (new Base())->getTimeInfo($message); if(!empty($message['one_more_order'])) { // 再来一单 if(empty($message['order_id']) || empty($message['user_id'])) { @@ -361,6 +362,23 @@ class Shopping extends Base ] ]; self::gateway_query('sendToClient', [$client_id, json_encode($snd_data)]); + + // 直接回馈初始化后的内容 + $car = Db::query(" + SELECT * FROM `tb_cashier_cart` WHERE + `shop_id`={$message['shop_id']} AND + `table_code`='{$message['new_table_code']}' + "); + $snd_data = [ + 'msg' => '购物车初始化', + 'operate_type' => 'init', + 'msg_id' => $rand, + 'type' => 'shopping', + 'table_code' => $message['table_code'], + 'data' => $car, + 'time_dis_info' => (new Base())->getTimeInfo($message) + ]; + self::gateway_query('sendToClient', [$client_id, json_encode($snd_data)]); }catch (\ba\Exception $e) { Log::info('修改购物车时转桌[error]->>>>>' . $e->getMessage()); } diff --git a/plugin/webman/gateway/Events.php b/plugin/webman/gateway/Events.php index d45fd2d..628610f 100644 --- a/plugin/webman/gateway/Events.php +++ b/plugin/webman/gateway/Events.php @@ -135,29 +135,29 @@ class Events 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(empty($message['data'])) { - $res = Redis::del($redis_str); - }else { - $res = Redis::set($redis_str, json_encode($message['data'])); - // 将桌号存入redis 以便及时删除 - $time_discount_info = Redis::get('time_discount:info'); - if($time_discount_info) { - $arr_time_discount_info = explode(',', $time_discount_info); - if(!in_array($redis_str, $arr_time_discount_info)) { - $time_discount_info = array_merge($arr_time_discount_info, [$redis_str]); - Redis::set('time_discount:info', implode(',', $time_discount_info)); - } - }else { - Redis::set('time_discount:info', $redis_str); - } - } +// $redis_str = Base::get_shopping_save_uid($message['shop_id'], $message['table_code']) . ':time_discount'; +// if(empty($message['data'])) { +// $res = Redis::del($redis_str); +// }else { +// $res = Redis::set($redis_str, json_encode($message['data'])); +// // 将桌号存入redis 以便及时删除 +// $time_discount_info = Redis::get('time_discount:info'); +// if($time_discount_info) { +// $arr_time_discount_info = explode(',', $time_discount_info); +// if(!in_array($redis_str, $arr_time_discount_info)) { +// $time_discount_info = array_merge($arr_time_discount_info, [$redis_str]); +// Redis::set('time_discount:info', implode(',', $time_discount_info)); +// } +// }else { +// Redis::set('time_discount:info', $redis_str); +// } +// } $snd_data = [ 'msg' => '折扣修改', 'operate_type' => $message['operate_type'], 'msg_id' => '', 'type' => 'time_discount', - 'status' => $res, + 'status' => (new Base())->setTimeInfo($message), 'data' => $message['data'], ]; Gateway::sendToClient($client_id, json_encode($snd_data));