From 8cdbbf0af28fe44fc90d0b75ec035c836ce54888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0?= Date: Thu, 4 Sep 2025 22:41:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE=E4=B8=AD?= =?UTF-8?q?=E5=B8=A6=E6=9C=89=E7=9C=8B=E4=B8=8D=E5=88=B0=E7=9A=84=E7=A9=BA?= =?UTF-8?q?=E7=99=BD=E5=AD=97=E7=AC=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ZengJieCode/controller/app/Savemsg.php | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/application/ZengJieCode/controller/app/Savemsg.php b/application/ZengJieCode/controller/app/Savemsg.php index 2c65a64..4e48925 100644 --- a/application/ZengJieCode/controller/app/Savemsg.php +++ b/application/ZengJieCode/controller/app/Savemsg.php @@ -210,11 +210,13 @@ class Savemsg extends Base{ } public function save_sn_msg_action($data){ + $data = $this->chuli_str_kongbai($data); $zengjie = Db::connect('zengjie_db'); - // $sn_code = $zengjie->table('sn_code_all')->where(['sn_code'=>$data['sn_code']])->count(); - // if($sn_code > 0){ - // return $this->msg(10002,'该码已录入'); - // } + $sn_code = $zengjie->table('sn_code_all')->where(['sn_code'=>$data['sn_code']])->count(); + if($sn_code > 0){ + return $this->msg(10002,'该码已录入'); + } + $result = $zengjie->table('sn_code_all')->insert([ 'sn_code'=>$data['sn_code'], 'bluetooth_name'=>$data['bl_name'], @@ -229,10 +231,12 @@ class Savemsg extends Base{ } public function save_box_msg_action($data) { + $data = $this->chuli_str_kongbai($data); $zengjie = Db::connect('zengjie_db'); // 1. 检查sn_code_all中是否有重复数据 $snCodes = explode(',', $data['sn_code_all']); + $snCodes = $this->chuli_str_kongbai($snCodes); if (count($snCodes) !== count(array_unique($snCodes))) { return $this->msg(10003, 'SN码列表中存在重复数据'); } @@ -256,7 +260,7 @@ class Savemsg extends Base{ 'box_code' => $data['box_serial_number'], 'box_num' => $num, 'create_time' => date('Y-m-d H:i:s'), - 'content_str' => $data['sn_code_all'], + 'content_str' => implode(',',$snCodes), ]); $affectedRows = $zengjie->table('sn_code_all') @@ -339,6 +343,17 @@ class Savemsg extends Base{ } } + + public function chuli_str_kongbai($data){ + foreach ($$data as $key => $value) { + // 1. 移除所有空字符和不可见字符 + $data[$key] = preg_replace('/[\x00-\x1F\x7F]/', '', $value); + // 2. 去除首尾空白 + $data[$key] = trim($value); + } + return $data; + } + ######################################################测试######################################################### ######################################################测试######################################################### ######################################################测试#########################################################