diff --git a/app/common/model/Student.php b/app/common/model/Student.php index 7b056c9..a6772b7 100644 --- a/app/common/model/Student.php +++ b/app/common/model/Student.php @@ -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'); + } + } diff --git a/app/common/model/StudentParent.php b/app/common/model/StudentParent.php index cbd0b8a..8c011b8 100644 --- a/app/common/model/StudentParent.php +++ b/app/common/model/StudentParent.php @@ -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'); + } + } diff --git a/app/common/service/StudentService.php b/app/common/service/StudentService.php index ed52949..f2869e5 100644 --- a/app/common/service/StudentService.php +++ b/app/common/service/StudentService.php @@ -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 } } -} \ No newline at end of file +}