学生、家长信息

This commit is contained in:
Dai 2024-08-09 16:47:03 +08:00
parent 1327e12b0f
commit f7d6448863
3 changed files with 15 additions and 20 deletions

View File

@ -28,4 +28,9 @@ class Student extends BaseModel
return $this->hasOne(StudentParent::class, 'id', 'parent_id')->bind(['parent_name']);
}
public function parentArr()
{
return $this->hasOne(StudentParent::class, 'id', 'parent_id');
}
}

View File

@ -5,23 +5,13 @@ namespace app\common\model;
use app\BaseModel;
use support\Model;
/**
* wa_student_parent 家长
* @property integer $id (主键)
* @property string $parent_name 家长姓名
* @property string $account 账号
* @property string $salt 密码盐
* @property string $password 密码
* @property string $nickname 昵称
* @property string $avatar 头像
* @property string $mobile 手机号
* @property string $birthday 生日
* @property mixed $created_at 创建时间
* @property string $updated_at 更新时间
* @property string $deleted_at
*/
class StudentParent extends BaseModel
{
public function studentArr()
{
return $this->hasOne(Student::class, 'parent_id', 'id');
}
}

View File

@ -82,14 +82,14 @@ class StudentService
throw new Exception('请登陆后再查看');
}
if(!empty((array)$request->student)){
$student = Student::where(['id' => $request->student->id])->field('id,student_name,account,openid,avatar')->findOrEmpty();
$student = Student::where(['id' => $request->student->id])->with(['parentArr'])->field('id,student_name,account,openid,avatar,parent_id')->findOrEmpty();
if ($student->isEmpty()) {
throw new Exception('未找到学生信息');
}
$info = $student->toArray();
$info['role'] = 'student';
}elseif (!empty((array)$request->parent)){
$parent = StudentParent::where(['id' => $request->parent->id])->field('id,parent_name,account,openid,avatar')->findOrEmpty();
$parent = StudentParent::where(['id' => $request->parent->id])->with(['studentArr'])->field('id,parent_name,account,openid,avatar')->findOrEmpty();
if ($parent->isEmpty()) {
throw new Exception('未找到家长信息');
}
@ -159,4 +159,4 @@ class StudentService
}
}
}
}