修复数据中带有看不到的空白字符问题
This commit is contained in:
parent
dccaaed733
commit
8cdbbf0af2
|
|
@ -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;
|
||||
}
|
||||
|
||||
######################################################测试#########################################################
|
||||
######################################################测试#########################################################
|
||||
######################################################测试#########################################################
|
||||
|
|
|
|||
Loading…
Reference in New Issue