123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?php
- namespace app\admin\controller\basic;
- /**
- * @title : 学校列表 管理控制器
- * @desc :
- * @Author : 系统开发
- * @Date : 2024-12-27 09:16:45
- * @icon fa fa-leaf
- */
- use app\admin\controller\Base;
- use app\common\model\base\org\OrgType;
- use app\common\model\base\OrgTypeClass;
- use app\common\model\basic\BasicSchool as BasicSchoolModel;
- use daorui\platform\platformAuth;
- class BasicSchool extends Base
- {
- protected $model = null;
- protected $noNeedLogin = ['getOptions'];
- protected $noNeedAuth = [];
- public function initialize()
- {
- parent::initialize();
- $this->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}不存在");
- }
- }
|