diff --git a/niucloud/app/adminapi/controller/student/Student.php b/niucloud/app/adminapi/controller/student/Student.php index 79aa7266..b6adede6 100644 --- a/niucloud/app/adminapi/controller/student/Student.php +++ b/niucloud/app/adminapi/controller/student/Student.php @@ -126,4 +126,15 @@ class Student extends BaseAdminController return success(( new StudentService() )->label_all()); } + /** + * 通过名称查询学员 + */ + public function getStudentByName() + { + $data = $this->request->params([ + ["name", ""], + ]); + $list = (new StudentService())->getStudentByName($data['name']); + return success($list); + } } diff --git a/niucloud/app/adminapi/route/student.php b/niucloud/app/adminapi/route/student.php index 5414025d..9274554c 100644 --- a/niucloud/app/adminapi/route/student.php +++ b/niucloud/app/adminapi/route/student.php @@ -39,6 +39,8 @@ Route::group('student', function () { Route::get('label_all','student.Student/label_all'); + Route::get('getStudentByName','student.Student/getStudentByName'); + })->middleware([ AdminCheckToken::class, diff --git a/niucloud/app/model/student/Student.php b/niucloud/app/model/student/Student.php index 31b108a8..e5d2e31b 100644 --- a/niucloud/app/model/student/Student.php +++ b/niucloud/app/model/student/Student.php @@ -141,15 +141,15 @@ class Student extends BaseModel public function customerResources(){ - return $this->hasOne(CustomerResources::class, 'id', 'user_id')->joinType('left')->withField('name,id')->bind(['user_id_name'=>'name']); + return $this->hasOne(CustomerResources::class, 'id', 'user_id'); } public function campus(){ - return $this->hasOne(Campus::class, 'id', 'campus_id')->joinType('left')->withField('campus_name,id')->bind(['campus_id_name'=>'campus_name']); + return $this->hasOne(Campus::class, 'id', 'campus_id'); } public function classGrade(){ - return $this->hasOne(ClassGrade::class, 'id', 'class_id')->joinType('left')->withField('class_name,id')->bind(['class_id_name'=>'class_name']); + return $this->hasOne(ClassGrade::class, 'id', 'class_id'); } } diff --git a/niucloud/app/service/admin/student/StudentService.php b/niucloud/app/service/admin/student/StudentService.php index f64b3a9b..2d6b0e0d 100644 --- a/niucloud/app/service/admin/student/StudentService.php +++ b/niucloud/app/service/admin/student/StudentService.php @@ -44,7 +44,7 @@ class StudentService extends BaseAdminService $field = 'id,user_id,campus_id,class_id,name,gender,age,birthday,member_label,emergency_contact,contact_phone,note,status,created_at,updated_at,deleted_at'; $order = 'id asc'; - $search_model = $this->model->withSearch(["campus_id","name","emergency_contact","contact_phone","created_at","member_label"], $where)->with(['customerResources','campus','classGrade'])->field($field)->order($order); + $search_model = $this->model->withSearch(["campus_id", "name", "emergency_contact", "contact_phone", "created_at", "member_label"], $where)->with(['customerResources', 'campus', 'classGrade'])->field($field)->order($order); return $this->pageQuery($search_model, function ($item, $key) { $item = $this->makeUp($item); }); @@ -59,7 +59,7 @@ class StudentService extends BaseAdminService { $field = 'id,user_id,campus_id,class_id,name,gender,age,birthday,emergency_contact,member_label,contact_phone,note,status,created_at,updated_at,deleted_at'; - $info = $this->makeUp($this->model->field($field)->where([['id', "=", $id]])->with(['customerResources','campus','classGrade'])->findOrEmpty()->toArray()); + $info = $this->makeUp($this->model->field($field)->where([['id', "=", $id]])->with(['customerResources', 'campus', 'classGrade'])->findOrEmpty()->toArray()); return $info; } @@ -68,9 +68,10 @@ class StudentService extends BaseAdminService * 组合整理数据 * @param $data */ - public function makeUp($data){ + public function makeUp($data) + { //会员标签 - if(!empty($data['member_label'])){ + if (!empty($data['member_label'])) { $data['member_label_array'] = (new StudentLabelService())->getMemberLabelListByLabelIds($data['member_label']); } return $data; @@ -114,26 +115,40 @@ class StudentService extends BaseAdminService } - public function getCustomerResourcesAll(){ - $customerResourcesModel = new CustomerResources(); - return $customerResourcesModel->select()->toArray(); + public function getCustomerResourcesAll() + { + $customerResourcesModel = new CustomerResources(); + return $customerResourcesModel->select()->toArray(); } - public function getCampusAll(){ - $campusModel = new Campus(); - return $campusModel->select()->toArray(); + public function getCampusAll() + { + $campusModel = new Campus(); + return $campusModel->select()->toArray(); } - public function getClassGradeAll(){ - $classGradeModel = new ClassGrade(); - return $classGradeModel->select()->toArray(); + public function getClassGradeAll() + { + $classGradeModel = new ClassGrade(); + return $classGradeModel->select()->toArray(); } - public function label_all(){ + public function label_all() + { $field = 'label_id, label_name'; - return (new StudentLabel())->where([ ['label_id', '>', 0] ])->field($field)->order('sort desc,create_time desc')->select()->toArray(); + return (new StudentLabel())->where([['label_id', '>', 0]])->field($field)->order('sort desc,create_time desc')->select()->toArray(); } + public function getStudentByName($name) + { + $query = $this->model->with(['customer_resources'])->where([['name', 'like', '%' . $name . '%']]); + $list = $query->select()->toArray(); + foreach ($list as &$item) { + $item['client_name'] = $item['name'] . '(家长:' . $item['customer_resources']['name'] . ' 电话:' . $item['customer_resources']['phone_number'] . ')'; + + } + return $list; + } }