model = new BasicSchoolModel; } /** * @title :创建统一查询条件 * @desc : 描述 * @param {char} {school_code} {} {学校类型} * @param {int} {area_id} {} {所属地区} * @param {string} {keyword} {} {搜索关键词,可搜索学校名称|学校logo} * @return {*} * @author : 系统开发 * @method: POST * @Date : 2024-12-27 09:16:45 */ private function createWhere() { $data = $this->request->param(); $where = []; $whereOr = []; if (!empty($data['school_code'])) { $where[] = ['school_code', '=', $data['school_code']]; } if (!empty($data['area_id'])) { $where[] = ['area_id', '=', $data['area_id']]; } if (!empty($data['keyword'])) { $keyword = $data['keyword']; $where[] = ['school_name|school_logo', 'LIKE', "%$keyword%"]; } return ['where' => $where, 'whereOr' => $whereOr]; } /** * @title :查询数据列表 * @desc : 描述 * @param {char} {school_code} {} {学校类型} * @param {int} {area_id} {} {所属地区} * @param {string} {keyword} {} {搜索关键词,可搜索学校名称|学校logo} * @param {int} {pageNo} {0} {页码} * @param {int} {pageSize} {10} {每页数量} * @return {*} * @author : 系统开发 * @method: POST * @Date : 2024-12-27 09:16:45 */ public function getList(int $pageNo = 0, int $pageSize = 10) { $whereAry = $this->createWhere(); if (!empty($pageNo)) { $res = $this->model ->where($whereAry['where']) ->where(function ($query) use ($whereAry) { $query->whereOr($whereAry['whereOr']); }) ->with([]) ->order(['sort_no' => 'DESC']) ->paginate(['page' => $pageNo, 'list_rows' => $pageSize]); return pageRes(1, '获取成功', $res->total(), $res->items()); } else { $list = $this->model ->where($whereAry['where']) ->where(function ($query) use ($whereAry) { $query->whereOr($whereAry['whereOr']); }) ->order(['sort_no' => 'DESC']) ->with([]) ->select(); return res(1, '获取成功', $list); } } /** * @title :选择器数据 * @desc : 描述 * @return {*} * @author : 系统开发 * @method: POST * @Date : 2024-12-27 09:16:45 */ public function getTree($labelField = 'school_name') { $fields = ['id', $labelField]; $where = []; $list = $this->model->where($where)->field($fields)->select(); return res(1, "获取成功", $list); } /** * @title :查询信息 * @desc : 描述 * @param {int} {id} {} {信息ID} * @return {*} * @author : 系统开发 * @method: POST * @Date : 2024-12-27 09:16:45 */ public function getInfo(int $id = 0) { $info = $this->model->with([])->find($id); return res(1, '获取成功', $info); } /** * @title :新增/编辑信息 * @desc : 描述 * @param {int} {id} {} {主键ID,不传或传0表示新增,大于0表示修改} * @param {varchar} {school_name} {} {学校名称} * @param {char} {school_code} {} {学校类型} * @param {int} {area_id} {} {所属地区} * @param {varchar} {school_logo} {} {学校logo} * @return {*} * @author : 系统开发 * @method: POST * @Date : 2024-12-27 09:16:45 */ public function doEdit() { $data = $this->request->param(); $res = $this->model->replace()->save($data); return res(1, '编辑成功'); } /** * @title :删除信息 * @desc : 描述 * @param {int} id {} {信息ID} * @return {*} * @author : 系统开发 * @method: POST * @Date : 2024-12-27 09:16:45 */ public function doDelete(int $id = 0) { $info = $this->model->find($id); $info->delete(); return res(1, '删除成功'); } /** * @title :获取可选项 * @desc : 描述 * @return {*} * @author : 系统开发 * @method: POST * @Date : 2024-12-27 09:16:45 */ public function getOptions() { $codes = (new platformAuth())->interfaceRequest('getSchoolCode', []); $codes = array_column($codes['data'], 'code'); $SchoolCodeList = []; if ($codes) { $SchoolCodeList = OrgType::where('code', 'IN', $codes)->column('org_type_name', 'code') ?? []; } $data = [ 'SchoolCodeList' => $SchoolCodeList, ]; return res(1, '获取成功', $data); } private $fieldList = [ 'index' => '序号', 'school_name' => '学校名称', 'school_code' => '学校类型', 'area_id' => '所属地区', 'school_logo' => '学校logo', 'create_at' => '创建时间', 'update_at' => '更新时间', ]; /** * @title :导出数据 * @desc : 描述 * @param {char} {school_code} {} {学校类型} * @param {int} {area_id} {} {所属地区} * @param {string} {keyword} {} {搜索关键词,可搜索学校名称|学校logo} * @return {*} * @author : 系统开发 * @method: POST * @Date : 2024-12-27 09:16:45 */ public function doExport() { $whereAry = $this->createWhere(); $list = $this->model->where($whereAry['where'])->where(function ($query) use ($whereAry) { $query->whereOr($whereAry['whereOr']); })->with([])->select()->toArray(); $head = array_values($this->fieldList); $body = []; foreach ($list as $key => $item) { $index = $key + 1; foreach ($this->fieldList as $k => $v) { if ($k == 'index') { $body[$index][] = $index; } else { $body[$index][] = isset($item[$k . '_txt']) ? (is_array($item[$k . '_txt']) ? implode(',', $item[$k . '_txt']) : $item[$k . '_txt']) : $item[$k]; } } } //创建文件夹 $basepath = 'uploads' . DS . 'download' . DS . date('Ymd'); $savepath = public_path() . $basepath; if (!is_dir($savepath)) { @mkdir($savepath, 0777, true); } //保存文件 $filename = time() . GetRandStr() . '.xls'; $path = $savepath . DS . $filename; $export_help = new \excel\MultiHeadExcel(); $export_help->export_help($body, $head, $path); //返回路径 $returnpath = WEBURL . DS . $basepath . DS . $filename; slog(1, '导出了学校列表'); return res(1, '获取成功', ['url' => $returnpath, 'name' => $filename]); } public function __call($name, $arguments) { return res(2, "方法{$name}不存在"); } }