model = (new Attendance()); } //列表 public function getList(array $where, string $field = '*') { $page_params = $this->getPageParam();//获取请求参数中的页码+分页数 $page = $page_params['page']; $limit = $page_params['limit']; $model = $this->model; if (!empty($where['campus_id'])) { $model = $model->where('campus_id', $where['campus_id']); } if (!empty($where['staff_id'])) { $model = $model->where('staff_id', $where['staff_id']); } if (!empty($where['attendance_date'])) { $model = $model->where('attendance_date', $where['attendance_date']); } if (!empty($where['status'])) { $model = $model->where('status', $where['status']); } if (!empty($where['status_arr'])) { $model = $model->whereIn('status', $where['status_arr']); } $res = $model->with([ 'campus', 'personnel', ])->append([ 'status_name' ]) ->order('created_at','desc') ->paginate([ 'list_rows' => $limit, 'page' => $page, ])->toArray(); return $res; } //查询详情 public function info(array $where, string $field = '*') { $res = [ 'code' => 0, 'msg' => '操作失败', 'data' => [], ]; if (empty($where)) { $res['msg'] = '筛选条件不能唯空'; return $res; } $model = $this->model; if (!empty($where['id'])) { $model = $model->where('id', $where['id']); } if (!empty($where['campus_id'])) { $model = $model->where('campus_id', $where['campus_id']); } if (!empty($where['staff_id'])) { $model = $model->where('staff_id', $where['staff_id']); } if (!empty($where['attendance_date'])) { $model = $model->where('attendance_date', $where['attendance_date']); } $data = $model->field($field)->find(); if ($data) { $res = [ 'code' => 1, 'msg' => '操作成功', 'data' => $data->toArray(), ]; } else { $res['msg'] = '暂无数据'; } return $res; } //添加数据 public function addData(array $data) { $add = $this->model->create($data); if ($add) { $res = [ 'code' => 1, 'msg' => '操作成功', 'data' => [], ]; } else { $res = [ 'code' => 0, 'msg' => '操作失败', 'data' => [], ]; } return $res; } //编辑数据 public function editData(array $where, array $data) { $data['updated_at'] = date('Y-m-d H:i:s'); $model = $this->model; if (!empty($where['id'])) { $model = $model->where('id', $where['id']); } $edit = $model->update($data); if ($edit) { $res = [ 'code' => 1, 'msg' => '操作成功', 'data' => [], ]; } else { $res = [ 'code' => 0, 'msg' => '操作失败', 'data' => [], ]; } return $res; } }