Commit 91695858 by lujunyi
parents d30d5d6b 223077ac
...@@ -55,6 +55,10 @@ public function add(Request $request) ...@@ -55,6 +55,10 @@ public function add(Request $request)
$pharmacy = PharmacyModel::query()->where('user_id', $authInfo->id)->first(); $pharmacy = PharmacyModel::query()->where('user_id', $authInfo->id)->first();
$data['pharmacy_id'] = $pharmacy->id; $data['pharmacy_id'] = $pharmacy->id;
} }
// 验证身份证格式
if (! validateIdCard($data['id_card'])) {
return $this->failed('身份证格式错误');
}
$idCardInfo = Util::getIdCardInfo($data['id_card']); $idCardInfo = Util::getIdCardInfo($data['id_card']);
$data['gender'] = $idCardInfo['gender']; $data['gender'] = $idCardInfo['gender'];
$data['is_default'] = 0; $data['is_default'] = 0;
...@@ -62,7 +66,7 @@ public function add(Request $request) ...@@ -62,7 +66,7 @@ public function add(Request $request)
if ($res) { if ($res) {
return $this->success($res); return $this->success($res);
} else { } else {
return $this->error(401, '添加失败'); return $this->failed('添加失败');
} }
} }
...@@ -71,12 +75,15 @@ public function update(Request $request) ...@@ -71,12 +75,15 @@ public function update(Request $request)
{ {
$id = $request->input('id'); $id = $request->input('id');
$id_card = $request->input('id_card'); $id_card = $request->input('id_card');
// 验证身份证格式
if (! validateIdCard($id_card)) {
return $this->failed('身份证格式错误');
}
// TODO 提取身份信息
$idCardInfo = Util::getIdCardInfo($id_card); $idCardInfo = Util::getIdCardInfo($id_card);
$data = PatientModel::find($id); $data = PatientModel::find($id);
if (! $data) { if (! $data) {
return $this->error(401, '该问诊人不存在'); return $this->failed('该问诊人不存在');
} }
$data->name = $request->input('name'); $data->name = $request->input('name');
$data->id_card = $id_card; $data->id_card = $id_card;
...@@ -91,7 +98,7 @@ public function delete(Request $request) ...@@ -91,7 +98,7 @@ public function delete(Request $request)
$id = $request->input('id'); $id = $request->input('id');
$data = PatientModel::find($id); $data = PatientModel::find($id);
if (! $data) { if (! $data) {
return $this->error(401, '该问诊人不存在'); return $this->failed('该问诊人不存在');
} }
$data->delete(); $data->delete();
...@@ -121,7 +128,7 @@ public function setDefault(Request $request) ...@@ -121,7 +128,7 @@ public function setDefault(Request $request)
$id = $request->input('id'); $id = $request->input('id');
$data = PatientModel::find($id); $data = PatientModel::find($id);
if (! $data) { if (! $data) {
return $this->error(401, '该问诊人不存在'); return $this->failed('该问诊人不存在');
} }
$data->is_default = 1; $data->is_default = 1;
$data->save(); $data->save();
...@@ -146,7 +153,7 @@ public function getDefault(Request $request) ...@@ -146,7 +153,7 @@ public function getDefault(Request $request)
if ($data) { if ($data) {
return $this->success($data); return $this->success($data);
} else { } else {
return $this->error(401, '暂无默认问诊人'); return $this->failed('暂无默认问诊人');
} }
} }
} }
...@@ -244,3 +244,67 @@ function data_masking(string $strType, $str = '') ...@@ -244,3 +244,67 @@ function data_masking(string $strType, $str = '')
return $maskStr; return $maskStr;
} }
} }
if (! function_exists('validateIdCard')) {
/**
* 身份证号码校验
*/
function validateIdCard($value)
{
$len = strlen($value);
if ($len != 15 && $len != 18) {
return false;
}
if ($len === 18) {
$birthday = substr($value, 6, 8); // 6-14 出生日期
if (! validateBirthday($birthday)) {
return false;
}
$sex = substr($value, -2, 1);
if (! validateISO7064($value)) {
return false;
}
return true;
} else {
$birthday = substr($value, 6, 6);
$birthday = '19'.$birthday;
if (! validateBirthday($birthday)) {
return false;
}
$sex = substr($value, -1);
return true;
}
}
function validateBirthday($birthday)
{
$year = substr($birthday, 0, 4);
$month = substr($birthday, 4, 2);
$day = substr($birthday, 6, 2);
$timestamp = mktime(0, 0, 0, $month, $day, $year);
return $timestamp !== false && $timestamp < strtotime('midnight');
}
function validateISO7064($value)
{
$bits = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
$arr_ch = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
$sign = 0;
for ($i = 0; $i < 17; $i++) {
$b = (int) $value[$i];
$w = $bits[$i];
$sign += $b * $w;
}
$n = $sign % 11;
$r = $arr_ch[$n];
$last = substr($value, -1);
return ($r == $last)
|| $r == 10 && ($last == 'x' || $last == 'X');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment