Commit 994d719e by 赵增煜

身份证改成非必填项,增加年龄,性别

parent edd18da5
......@@ -67,20 +67,30 @@ public function add(Request $request)
$idValidator = new IdValidator();
// if (! $idValidator->isValid($data['id_card'])) {
// if( !in_array(strlen($data['id_card']),[15,18])){
if (strlen($data['id_card']) != 18) {
return $this->failed('身份证格式错误');
if (strlen($data['id_card']) != 18) { # 身份证非必填项
# return $this->failed('身份证格式错误');
}
if (is_int($data['age']) || $data['age'] <= 0) {
return $this->failed('年龄格式错误');
}
if( !array_key_exists($data['gender'],PatientModel::SEX_MAP) ){
return $this->failed('性别错误');
}
$mobile = $data['mobile'];
$verificationCode = cache()->get("sms_verification_code_{$mobile}");
$code = $data['code'];
if ($verificationCode != $code) {
return $this->failed('验证码错误');
}
$idCardInfo = Util::getIdCardInfo($data['id_card']);
# $idCardInfo = Util::getIdCardInfo($data['id_card']);
$patient->name = $data['name'];
$patient->id_card = $data['id_card'];
$patient->mobile = $mobile;
$patient->gender = $idCardInfo['gender'];
$patient->gender = $data['gender'];
$patient->age = $data['age'];
$patient->is_default = 0;
// $res = PatientModel::create($data);
$res = $patient->save();
......@@ -96,13 +106,25 @@ public function update(Request $request)
{
$id = $request->input('id');
$id_card = $request->input('id_card');
$gender = $request->input('gender');
$age = $request->input('age');
// 验证身份证格式
$idValidator = new IdValidator();
// if (! $idValidator->isValid($id_card)) {
if (strlen($id_card) != 18) {
return $this->failed('身份证格式错误');
# return $this->failed('身份证格式错误');
}
$idCardInfo = Util::getIdCardInfo($id_card);
if (is_int($age) || $age <= 0) {
return $this->failed('年龄格式错误');
}
if( !array_key_exists($gender,PatientModel::SEX_MAP) ){
return $this->failed('性别错误');
}
# $idCardInfo = Util::getIdCardInfo($id_card);
$data = PatientModel::find($id);
if (! $data) {
return $this->failed('该问诊人不存在');
......@@ -116,7 +138,8 @@ public function update(Request $request)
$data->name = $request->input('name');
$data->id_card = $id_card;
$data->gender = $idCardInfo['gender'];
$data->gender = $gender;
$data->age = $age;
$data->mobile = $mobile;
$data->save();
......
......@@ -3,8 +3,10 @@
namespace App\Console\Commands;
use App\Models\InquiryModel;
use App\Models\PatientModel;
use App\Models\PrescriptionModel;
use Illuminate\Console\Command;
use App\Common\Util;
class TestCommand extends Command
{
......@@ -28,14 +30,23 @@ class TestCommand extends Command
public function handle()
{
// 刷新问诊问题
$prescriptions = PrescriptionModel::orderBy('id', 'desc')->get();
foreach ($prescriptions as $prescription) {
$inquiry_info = $prescription->inquiry_info;
foreach ($inquiry_info as &$v) {
$v['question'] = InquiryModel::find($v['inquiry_id'])->question;
// $prescriptions = PrescriptionModel::orderBy('id', 'desc')->get();
// foreach ($prescriptions as $prescription) {
// $inquiry_info = $prescription->inquiry_info;
// foreach ($inquiry_info as &$v) {
// $v['question'] = InquiryModel::find($v['inquiry_id'])->question;
// }
// $prescription->inquiry_info = $inquiry_info;
// $prescription->save();
// }
// 刷新存量问诊人年龄
$patients = PatientModel::query()->whereNotNull('id_card')->where('age',0)->get();
if( $patients->count() > 0 ){
foreach ($patients as $patient) {
$patient->age = getAgeByIdCard($patient->id_card);
$patient->save();
}
$prescription->inquiry_info = $inquiry_info;
$prescription->save();
}
}
}
}
......@@ -17,7 +17,7 @@ public function up(): void
$table->bigIncrements('id');
$table->string('name', 32)->comment('姓名');
$table->tinyInteger('gender')->default(0)->comment('性别。[1=男性,2=女性,0=未知]');
$table->string('id_card', 18)->index('idx_idcard')->comment('身份证号');
$table->string('id_card', 18)->nullable()->index('idx_idcard')->comment('身份证号');
$table->string('mobile', 11)->index('idx_mobile')->comment('手机号');
$table->bigInteger('user_id')->nullable()->index('idx_userid')->comment('用户表ID。用户添加问诊人才有值');
$table->bigInteger('pharmacy_id')->nullable()->index('idx_pharmacyid')->comment('药店表ID。药店添加问诊人猜有值');
......
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('patient', function (Blueprint $table) {
$table->integer('age')->default(0)->comment('问诊人年龄');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('patient', function (Blueprint $table) {
//
});
}
};
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