Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵增煜
/
tzt-admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
87c4527c
authored
Dec 09, 2024
by
lujunyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
身份证验证
parent
2874dde9
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
27 additions
and
26 deletions
+27
-26
app/Admin/Controllers/DoctorController.php
+1
-4
app/Admin/Controllers/PatientController.php
+1
-3
app/Admin/Controllers/PharmacistController.php
+1
-5
app/Admin/Controllers/PharmacyDrugController.php
+1
-1
app/Api/Controllers/PatientController.php
+2
-2
app/Api/Controllers/PharmacistController.php
+3
-3
app/helpers.php
+18
-8
No files found.
app/Admin/Controllers/DoctorController.php
View file @
87c4527c
...
...
@@ -8,7 +8,6 @@
use
Dcat\Admin\Grid
;
use
Dcat\Admin\Http\Controllers\AdminController
;
use
Dcat\Admin\Show
;
use
Jxlwqq\IdValidator\IdValidator
;
// 医师
class
DoctorController
extends
AdminController
...
...
@@ -147,9 +146,7 @@ protected function form()
if
(
$form
->
mobile
&&
!
preg_match
(
'/^1[3456789]{1}[0-9]{9}$/'
,
$form
->
mobile
))
{
return
$form
->
response
()
->
error
(
'手机号格式错误'
);
}
$idValidator
=
new
IdValidator
();
//if ($form->id_card && ! $idValidator->isValid($form->id_card)) {
if
((
!
empty
(
$form
->
id_card
))
&&
strlen
(
$form
->
id_card
)
!=
18
)
{
if
(
$form
->
id_card
&&
!
validateIDCard
(
$form
->
id_card
))
{
return
$form
->
response
()
->
error
(
'身份证格式错误'
);
}
});
...
...
app/Admin/Controllers/PatientController.php
View file @
87c4527c
...
...
@@ -106,9 +106,7 @@ protected function form()
if
(
$form
->
mobile
&&
!
preg_match
(
'/^1[3456789]{1}[0-9]{9}$/'
,
$form
->
mobile
))
{
return
$form
->
response
()
->
error
(
'手机号格式错误'
);
}
$idValidator
=
new
IdValidator
();
// if ($form->id_card && ! $idValidator->isValid($form->id_card)) {
if
(
!
empty
(
$form
->
id_card
)
&&
strlen
(
$form
->
id_card
)
!=
18
)
{
if
(
$form
->
id_card
&&
!
validateIDCard
(
$form
->
id_card
))
{
return
$form
->
response
()
->
error
(
'身份证格式错误'
);
}
});
...
...
app/Admin/Controllers/PharmacistController.php
View file @
87c4527c
...
...
@@ -15,7 +15,6 @@
use
Dcat\Admin\Widgets\Alert
;
use
Dcat\Admin\Widgets\Tab
;
use
Illuminate\Http\Request
;
use
Jxlwqq\IdValidator\IdValidator
;
// 药师
class
PharmacistController
extends
AdminController
...
...
@@ -193,10 +192,7 @@ protected function form()
if
(
$form
->
mobile
&&
!
preg_match
(
'/^1[3456789]{1}[0-9]{9}$/'
,
$form
->
mobile
))
{
return
$form
->
response
()
->
error
(
'手机号格式错误'
);
}
$idValidator
=
new
IdValidator
();
// if ($form->id_card && ! $idValidator->isValid($form->id_card)) {
if
(
!
empty
(
$form
->
id_card
)
&&
strlen
(
$form
->
id_card
)
!=
18
)
{
if
(
$form
->
id_card
&&
!
validateIDCard
(
$form
->
id_card
))
{
return
$form
->
response
()
->
error
(
'身份证格式错误'
);
}
});
...
...
app/Admin/Controllers/PharmacyDrugController.php
View file @
87c4527c
...
...
@@ -133,7 +133,7 @@ protected function form()
});
// 右上角按钮控制
#
$form->disableDeleteButton(); // 去掉删除按钮
//
$form->disableDeleteButton(); // 去掉删除按钮
$form
->
disableViewButton
();
// 去掉跳转详情页按钮
});
}
...
...
app/Api/Controllers/PatientController.php
View file @
87c4527c
...
...
@@ -68,7 +68,7 @@ public function add(Request $request)
$idValidator
=
new
IdValidator
();
// if (! $idValidator->isValid($data['id_card'])) {
// if( !in_array(strlen($data['id_card']),[15,18])){
if
(
isset
(
$data
[
'id_card'
])
&&
!
validateIDCard
(
$data
[
'id_card'
]))
{
// 身份证非必填项
if
(
isset
(
$data
[
'id_card'
])
&&
!
validateIDCard
(
$data
[
'id_card'
]))
{
// 身份证非必填项
return
$this
->
failed
(
'身份证格式错误'
);
}
...
...
@@ -116,7 +116,7 @@ public function update(Request $request)
// 验证身份证格式
$idValidator
=
new
IdValidator
();
// if (! $idValidator->isValid($id_card)) {
if
(
isset
(
$id_card
)
&&
!
validateIDCard
(
$id_card
))
{
if
(
isset
(
$id_card
)
&&
!
validateIDCard
(
$id_card
))
{
return
$this
->
failed
(
'身份证格式错误'
);
}
...
...
app/Api/Controllers/PharmacistController.php
View file @
87c4527c
...
...
@@ -85,7 +85,7 @@ public function add(Request $request)
$pharmacy
=
PharmacyModel
::
where
(
'user_id'
,
$authInfo
->
id
)
->
first
();
$id_card
=
$request
->
input
(
'id_card'
);
if
(
isset
(
$id_card
)
&&
!
validateIDCard
(
$id_card
)
)
{
if
(
isset
(
$id_card
)
&&
!
validateIDCard
(
$id_card
)
)
{
return
$this
->
failed
(
'身份证号格式错误'
);
}
$pharmacist
=
new
PharmacistModel
();
...
...
@@ -156,7 +156,7 @@ public function update(Request $request)
return
$this
->
failed
(
'该药师不存在'
);
}
$id_card
=
$request
->
input
(
'id_card'
);
if
(
isset
(
$id_card
)
&&
!
validateIDCard
(
$id_card
)
)
{
if
(
isset
(
$id_card
)
&&
!
validateIDCard
(
$id_card
)
)
{
return
$this
->
failed
(
'身份证号格式错误'
);
}
...
...
@@ -175,7 +175,7 @@ public function update(Request $request)
}
$pharmacist
->
name
=
str_replace
(
' '
,
''
,
$request
->
input
(
'name'
));
$pharmacist
->
id_card
=
str_replace
(
' '
,
''
,
$id_card
);
$pharmacist
->
id_card
=
str_replace
(
' '
,
''
,
$id_card
);
$pharmacist
->
mobile
=
str_replace
(
' '
,
''
,
$request
->
input
(
'mobile'
));
$pharmacist
->
license_number
=
str_replace
(
' '
,
''
,
$request
->
input
(
'license_number'
));
$pharmacist
->
practicing_license
=
$practicing_license_path
;
// 执业注册证书链接
...
...
app/helpers.php
View file @
87c4527c
...
...
@@ -135,6 +135,10 @@ function data_masking($str, string $strType)
$maskStr
=
substr
(
$str
,
0
,
4
)
.
'************'
.
substr
(
$str
,
-
4
,
3
);
break
;
case
'idcard'
:
// 只展示前6位和后4位
$idCardCount
=
strlen
(
$str
);
if
(
$idCardCount
!=
15
||
$idCardCount
!=
18
)
{
return
$str
;
}
$maskStr
=
substr
(
$str
,
0
,
6
)
.
str_repeat
(
'*'
,
strlen
(
$str
)
-
10
)
.
substr
(
$str
,
-
4
);
break
;
case
'mobile'
:
// 展示前3位和后4位
...
...
@@ -180,9 +184,10 @@ function validateBirthday($birthday)
if
(
!
function_exists
(
'validateIDCard'
))
{
function
validateIDCard
(
$idCard
)
{
function
validateIDCard
(
$idCard
)
{
// 长度检查
if
(
!
preg_match
(
'/^\d{15}$|^\d{17}[\dXx]$/'
,
$idCard
))
{
if
(
!
preg_match
(
'/^\d{15}$|^\d{17}[\dXx]$/'
,
$idCard
))
{
return
false
;
}
...
...
@@ -197,7 +202,7 @@ function validateIDCard($idCard) {
$month
=
substr
(
$birthDate
,
4
,
2
);
$day
=
substr
(
$birthDate
,
6
,
2
);
if
(
!
checkdate
((
int
)
$month
,
(
int
)
$day
,
(
int
)
$year
))
{
if
(
!
checkdate
((
int
)
$month
,
(
int
)
$day
,
(
int
)
$year
))
{
return
false
;
}
...
...
@@ -205,21 +210,26 @@ function validateIDCard($idCard) {
return
checkIDCardChecksum
(
$idCard
);
}
function
convertIDCard15to18
(
$idCard15
)
{
function
convertIDCard15to18
(
$idCard15
)
{
// 15位身份证转换为18位
$prefix
=
substr
(
$idCard15
,
0
,
6
)
.
'19'
.
substr
(
$idCard15
,
6
);
$prefix
=
substr
(
$idCard15
,
0
,
6
)
.
'19'
.
substr
(
$idCard15
,
6
);
$checksum
=
calculateChecksum
(
$prefix
);
return
$prefix
.
$checksum
;
return
$prefix
.
$checksum
;
}
function
checkIDCardChecksum
(
$idCard18
)
{
function
checkIDCardChecksum
(
$idCard18
)
{
// 检查身份证校验码
$base
=
substr
(
$idCard18
,
0
,
17
);
$checksum
=
calculateChecksum
(
$base
);
return
strtoupper
(
$checksum
)
===
strtoupper
(
$idCard18
[
17
]);
}
function
calculateChecksum
(
$base
)
{
function
calculateChecksum
(
$base
)
{
// 计算校验码
$weights
=
[
7
,
9
,
10
,
5
,
8
,
4
,
2
,
1
,
6
,
3
,
7
,
9
,
10
,
5
,
8
,
4
,
2
];
$checksumMap
=
[
'1'
,
'0'
,
'X'
,
'9'
,
'8'
,
'7'
,
'6'
,
'5'
,
'4'
,
'3'
,
'2'
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment