getPageParam();//获取请求参数中的页码+分页数 $page = $page_params['page']; $limit = $page_params['limit']; $student_id = Student::where('id',$where['resources_id'])->value('id');//学生id $data = Assignment::where('student_id',$student_id); if(!empty($where['status'])){ $data = $data->where('status',$where['status']); } $data = $data ->order('created_at', 'desc') ->with([ 'student' => function ($query) { $query->with([ 'customerResources' => function ($query2) { $query2->with([ 'member' ]); } ]); }, ]) ->paginate([ 'list_rows' => $limit, 'page' => $page, ])->toArray(); return $data; } //修改 public function edit(array $where,array $data) { if(empty($data['updated_at'])){ $data['updated_at'] = date('Y-m-d H:i:s'); } $student_id = Student::where('id',$where['resources_id'])->value('id');//学生id $data = Assignment::where('id',$where['id']) ->where('student_id',$student_id) ->update($data); $res = [ 'code'=>0, 'msg'=>'操作失败', 'data'=>[] ]; if($data){ $res = [ 'code'=>1, 'msg'=>'操作成功', 'data'=>$data ]; } return $res; } //查询详情 public function getInfo(array $where) { $model = new Assignment(); if (!empty($where['id'])) { $model = $model->where('id', $where['id']); } $data = $model->with([ 'student' => function ($query) { $query->with([ 'customerResources' => function ($query2) { $query2->with([ 'member' ]); } ]); }, ])->find(); if ($data) { $data = $data->toArray(); $res = [ 'code' => 1, 'msg' => '操作成功', 'data' => $data ]; return $res; } else { $res = [ 'code' => 0, 'msg' => '暂无数据', 'data' => [] ]; return $res; } } }