更新
This commit is contained in:
@@ -28,7 +28,7 @@ class TcmController extends BaseApiController
|
||||
* @notes 不需要登录的方法
|
||||
* @var array
|
||||
*/
|
||||
public array $notNeedLogin = ['getPatientSignature', 'diagnosisDetail', 'getDict', 'confirmDiagnosis'];
|
||||
public array $notNeedLogin = ['getPatientSignature', 'diagnosisDetail', 'getDict', 'confirmDiagnosis', 'getCardList'];
|
||||
|
||||
/**
|
||||
* @notes 获取患者签名(供小程序调用)
|
||||
@@ -129,4 +129,98 @@ class TcmController extends BaseApiController
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取就诊卡列表(供小程序调用)
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getCardList()
|
||||
{
|
||||
$patientId = $this->request->get('patient_id');
|
||||
|
||||
if (!$patientId) {
|
||||
return $this->fail('患者ID不能为空');
|
||||
}
|
||||
|
||||
try {
|
||||
$result = DiagnosisLogic::getCardList($patientId);
|
||||
|
||||
if ($result === false) {
|
||||
return $this->fail(DiagnosisLogic::getError());
|
||||
}
|
||||
|
||||
return $this->data($result);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 更新就诊卡(供小程序调用)
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function updateCard()
|
||||
{
|
||||
$params = [
|
||||
'id' => $this->request->post('id'),
|
||||
'patient_id' => $this->request->post('patient_id'),
|
||||
'patient_name' => $this->request->post('patient_name'),
|
||||
'gender' => $this->request->post('gender'),
|
||||
'age' => $this->request->post('age'),
|
||||
'diagnosis_date' => $this->request->post('diagnosis_date'),
|
||||
'diagnosis_type' => $this->request->post('diagnosis_type'),
|
||||
'syndrome_type' => $this->request->post('syndrome_type'),
|
||||
'diabetes_type' => $this->request->post('diabetes_type'),
|
||||
// 现病史字段
|
||||
'appetite' => $this->request->post('appetite'),
|
||||
'water_intake' => $this->request->post('water_intake'),
|
||||
'diet_condition' => $this->request->post('diet_condition'),
|
||||
'weight_change' => $this->request->post('weight_change'),
|
||||
'body_feeling' => $this->request->post('body_feeling'),
|
||||
'sleep_condition' => $this->request->post('sleep_condition'),
|
||||
'eye_condition' => $this->request->post('eye_condition'),
|
||||
'head_feeling' => $this->request->post('head_feeling'),
|
||||
'sweat_condition' => $this->request->post('sweat_condition'),
|
||||
'skin_condition' => $this->request->post('skin_condition'),
|
||||
'urine_condition' => $this->request->post('urine_condition'),
|
||||
'stool_condition' => $this->request->post('stool_condition'),
|
||||
'kidney_condition' => $this->request->post('kidney_condition'),
|
||||
'fatty_liver_degree' => $this->request->post('fatty_liver_degree'),
|
||||
// 既往史字段
|
||||
'past_history' => $this->request->post('past_history'),
|
||||
'trauma_history' => $this->request->post('trauma_history'),
|
||||
'surgery_history' => $this->request->post('surgery_history'),
|
||||
'allergy_history' => $this->request->post('allergy_history'),
|
||||
'family_history' => $this->request->post('family_history'),
|
||||
'pregnancy_history' => $this->request->post('pregnancy_history'),
|
||||
// 临床信息
|
||||
'symptoms' => $this->request->post('symptoms'),
|
||||
'tongue_coating' => $this->request->post('tongue_coating'),
|
||||
'pulse' => $this->request->post('pulse'),
|
||||
'treatment_principle' => $this->request->post('treatment_principle'),
|
||||
'prescription' => $this->request->post('prescription'),
|
||||
'doctor_advice' => $this->request->post('doctor_advice'),
|
||||
'remark' => $this->request->post('remark')
|
||||
];
|
||||
|
||||
if (!$params['id']) {
|
||||
return $this->fail('诊单ID不能为空');
|
||||
}
|
||||
|
||||
if (!$params['patient_id']) {
|
||||
return $this->fail('患者ID不能为空');
|
||||
}
|
||||
|
||||
try {
|
||||
$result = DiagnosisLogic::updateCard($params);
|
||||
|
||||
if ($result === false) {
|
||||
return $this->fail(DiagnosisLogic::getError());
|
||||
}
|
||||
|
||||
return $this->success('更新成功');
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ class UserController extends BaseApiController
|
||||
*/
|
||||
public function setInfo()
|
||||
{
|
||||
$params = (new SetUserInfoValidate())->post()->goCheck(null, ['id' => $this->userId]);
|
||||
$params = (new SetUserInfoValidate())->post()->goCheck();
|
||||
$result = UserLogic::setInfo($this->userId, $params);
|
||||
if (false === $result) {
|
||||
return $this->fail(UserLogic::getError());
|
||||
|
||||
@@ -72,13 +72,20 @@ class UserLogic extends BaseLogic
|
||||
{
|
||||
$user = User::where(['id' => $userId])
|
||||
->with('diagnosis')
|
||||
->field('id,sn,sex,account,password,nickname,real_name,avatar,mobile,create_time,user_money')
|
||||
->field('id,sn,sex,account,password,nickname,real_name,avatar,mobile,age,create_time,user_money')
|
||||
->findOrEmpty();
|
||||
$user['has_password'] = !empty($user['password']);
|
||||
$user['has_auth'] = self::hasWechatAuth($userId);
|
||||
$user['version'] = config('project.version');
|
||||
$user->hidden(['password']);
|
||||
return $user->toArray();
|
||||
|
||||
// 字段映射,便于前端使用
|
||||
$result = $user->toArray();
|
||||
$result['phone'] = $result['mobile'] ?? '';
|
||||
$result['gender'] = $result['sex'] ?? 1;
|
||||
$result['patient_name'] = $result['real_name'] ?? '';
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,21 +93,40 @@ class UserLogic extends BaseLogic
|
||||
* @notes 设置用户信息
|
||||
* @param int $userId
|
||||
* @param array $params
|
||||
* @return User|false
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 16:53
|
||||
*/
|
||||
public static function setInfo(int $userId, array $params)
|
||||
{
|
||||
try {
|
||||
if ($params['field'] == "avatar") {
|
||||
$params['value'] = FileService::setFileUrl($params['value']);
|
||||
// 支持批量更新多个字段
|
||||
$updateData = ['id' => $userId];
|
||||
|
||||
// 字段映射
|
||||
$fieldMap = [
|
||||
'avatar' => 'avatar',
|
||||
'phone' => 'mobile',
|
||||
'nickname' => 'nickname',
|
||||
'sex' => 'sex',
|
||||
'age' => 'age',
|
||||
'patient_name' => 'real_name'
|
||||
];
|
||||
|
||||
// 处理头像
|
||||
if (isset($params['avatar']) && !empty($params['avatar'])) {
|
||||
$updateData['avatar'] = FileService::setFileUrl($params['avatar']);
|
||||
}
|
||||
|
||||
return User::update([
|
||||
'id' => $userId,
|
||||
$params['field'] => $params['value']]
|
||||
);
|
||||
|
||||
// 处理其他字段
|
||||
foreach ($fieldMap as $key => $field) {
|
||||
if ($key !== 'avatar' && isset($params[$key])) {
|
||||
$updateData[$field] = $params[$key];
|
||||
}
|
||||
}
|
||||
|
||||
User::update($updateData);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
|
||||
@@ -27,47 +27,20 @@ use app\common\validate\BaseValidate;
|
||||
class SetUserInfoValidate extends BaseValidate
|
||||
{
|
||||
protected $rule = [
|
||||
'field' => 'require|checkField',
|
||||
'value' => 'require',
|
||||
'avatar' => 'string',
|
||||
'phone' => 'regex:/^1[3-9]\d{9}$/|',
|
||||
'nickname' => 'string|max:50',
|
||||
'gender' => 'in:0,1',
|
||||
'age' => 'integer|between:0,150',
|
||||
'patient_name' => 'string|max:50'
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'field.require' => '参数缺失',
|
||||
'value.require' => '值不存在',
|
||||
'phone.regex' => '手机号格式不正确',
|
||||
'nickname.max' => '昵称不能超过50个字符',
|
||||
'gender.in' => '性别参数错误',
|
||||
'age.between' => '年龄必须在0-150之间',
|
||||
'patient_name.max' => '姓名不能超过50个字符'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 校验字段内容
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 17:01
|
||||
*/
|
||||
protected function checkField($value, $rule, $data)
|
||||
{
|
||||
$allowField = [
|
||||
'nickname', 'account', 'sex', 'avatar', 'real_name',
|
||||
];
|
||||
|
||||
if (!in_array($value, $allowField)) {
|
||||
return '参数错误';
|
||||
}
|
||||
|
||||
if ($value == 'account') {
|
||||
$user = User::where([
|
||||
['account', '=', $data['value']],
|
||||
['id', '<>', $data['id']]
|
||||
])->findOrEmpty();
|
||||
if (!$user->isEmpty()) {
|
||||
return '账号已被使用!';
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user