Commit 223077ac by 赵增煜

问诊人修改

parent 6b52cb70
...@@ -55,9 +55,9 @@ public function add(Request $request) ...@@ -55,9 +55,9 @@ 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'])){ if (! validateIdCard($data['id_card'])) {
return $this->error(401, '身份证格式错误'); return $this->failed('身份证格式错误');
} }
$idCardInfo = Util::getIdCardInfo($data['id_card']); $idCardInfo = Util::getIdCardInfo($data['id_card']);
$data['gender'] = $idCardInfo['gender']; $data['gender'] = $idCardInfo['gender'];
...@@ -66,7 +66,7 @@ public function add(Request $request) ...@@ -66,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('添加失败');
} }
} }
...@@ -75,15 +75,15 @@ public function update(Request $request) ...@@ -75,15 +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)){ if (! validateIdCard($id_card)) {
return $this->error(401, '身份证格式错误'); return $this->failed('身份证格式错误');
} }
$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;
...@@ -98,7 +98,7 @@ public function delete(Request $request) ...@@ -98,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();
...@@ -128,7 +128,7 @@ public function setDefault(Request $request) ...@@ -128,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();
...@@ -153,7 +153,7 @@ public function getDefault(Request $request) ...@@ -153,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('暂无默认问诊人');
} }
} }
} }
...@@ -245,11 +245,9 @@ function data_masking(string $strType, $str = '') ...@@ -245,11 +245,9 @@ function data_masking(string $strType, $str = '')
} }
} }
if (! function_exists('validateIdCard')) {
if(!function_exists('validateIdCard')){
/** /**
* 身份证号码校验 * 身份证号码校验
* @param $value
*/ */
function validateIdCard($value) function validateIdCard($value)
{ {
...@@ -259,21 +257,23 @@ function validateIdCard($value) ...@@ -259,21 +257,23 @@ function validateIdCard($value)
} }
if ($len === 18) { if ($len === 18) {
$birthday = substr($value, 6, 8); // 6-14 出生日期 $birthday = substr($value, 6, 8); // 6-14 出生日期
if (!validateBirthday($birthday)) { if (! validateBirthday($birthday)) {
return false; return false;
} }
$sex = substr($value, -2, 1); $sex = substr($value, -2, 1);
if (!validateISO7064($value)) { if (! validateISO7064($value)) {
return false; return false;
} }
return true; return true;
} else { } else {
$birthday = substr($value, 6, 6); $birthday = substr($value, 6, 6);
$birthday = '19' . $birthday; $birthday = '19'.$birthday;
if (!validateBirthday($birthday)) { if (! validateBirthday($birthday)) {
return false; return false;
} }
$sex = substr($value, -1); $sex = substr($value, -1);
return true; return true;
} }
} }
...@@ -284,6 +284,7 @@ function validateBirthday($birthday) ...@@ -284,6 +284,7 @@ function validateBirthday($birthday)
$month = substr($birthday, 4, 2); $month = substr($birthday, 4, 2);
$day = substr($birthday, 6, 2); $day = substr($birthday, 6, 2);
$timestamp = mktime(0, 0, 0, $month, $day, $year); $timestamp = mktime(0, 0, 0, $month, $day, $year);
return $timestamp !== false && $timestamp < strtotime('midnight'); return $timestamp !== false && $timestamp < strtotime('midnight');
} }
...@@ -293,7 +294,7 @@ function validateISO7064($value) ...@@ -293,7 +294,7 @@ function validateISO7064($value)
$arr_ch = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']; $arr_ch = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
$sign = 0; $sign = 0;
for ($i = 0; $i < 17; $i++) { for ($i = 0; $i < 17; $i++) {
$b = (int)$value[$i]; $b = (int) $value[$i];
$w = $bits[$i]; $w = $bits[$i];
$sign += $b * $w; $sign += $b * $w;
} }
...@@ -301,8 +302,9 @@ function validateISO7064($value) ...@@ -301,8 +302,9 @@ function validateISO7064($value)
$r = $arr_ch[$n]; $r = $arr_ch[$n];
$last = substr($value, -1); $last = substr($value, -1);
return ($r == $last) return ($r == $last)
|| $r == 10 && ($last == 'x' || $last == 'X'); || $r == 10 && ($last == 'x' || $last == 'X');
} }
} }
\ No newline at end of file
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