123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475 |
- <?php
- namespace app\admin\controller\enroll;
- /**
- * @title : enrollStudents 管理控制器
- * @desc :
- * @Author : 系统开发
- * @Date : 2024-12-10 17:45:55
- * @icon fa fa-leaf
- */
- use app\admin\controller\Base;
- use app\admin\extend\enroll\EnrollHandle;
- use app\common\model\base\org\Org;
- use app\common\model\base\org\OrgType;
- use app\common\model\base\user\UserRole;
- use app\common\model\enroll\EnrollStudents as EnrollStudentsModel;
- use app\common\model\guardian\JdfGuardian;
- use app\common\model\guardian\JdfGuardianRelation;
- use app\common\model\periodConfig\JdfPeriodConfig;
- use app\common\model\enroll\JdfEnrollVolunteer;
- use daorui\platform\platformAuth;
- class EnrollStudents extends Base
- {
- protected $model = null;
- protected $noNeedLogin = ['getOptions'];
- protected $noNeedAuth = [];
- public function initialize()
- {
- parent::initialize();
- $this->model = new EnrollStudentsModel;
- }
- /**
- * @title:创建统一查询条件
- * @desc: 描述
- * @param {date} {birthday} {} {出生日期}
- * @param {string} {keyword} {} {搜索关键词,可搜索学生姓名|前学校|家庭住址|籍贯}
- * @return {*}
- * @author: 系统开发
- * @method: POST
- * @Date: 2024-12-10 17:45:55
- */
- private function createWhere()
- {
- $data = $this->request->param();
- $where = [];
- $whereOr = [];
- if (!empty($data['org_ids'])) {
- $where[] = ['a.org_id', 'IN', $data['org_ids']];
- } else {
- if ($this->userinfo && !$this->userinfo['is_developer']) {
- $org_ids = $this->userinfo['org_id'];
- //转为字符串
- if ($org_ids !== 1) {
- if (is_array($org_ids)) {
- $org_ids = implode(',', $org_ids);
- }
- $data['org_ids'] = $org_ids;
- $where[] = ['a.org_id', 'IN', $data['org_ids']];
- }
- }
- }
- if (!empty($data['keyword'])) {
- $keyword = $data['keyword'];
- $where[] = ['b.name|b.idcard', 'LIKE', "%$keyword%"];
- }
- return ['where' => $where, 'whereOr' => $whereOr];
- }
- /**
- * @title:查询数据列表
- * @desc: 描述
- * @param {date} {birthday} {} {出生日期}
- * @param {string} {keyword} {} {搜索关键词,可搜索学生姓名|前学校|家庭住址|籍贯}
- * @param {int} {pageNo} {0} {页码}
- * @param {int} {pageSize} {10} {每页数量}
- * @return {*}
- * @author: 系统开发
- * @method: POST
- * @Date: 2024-12-10 17:45:55
- */
- public function getList(int $pageNo = 0, int $pageSize = 10)
- {
- $whereAry = $this->createWhere();
- $fields = "a.*,b.grade_name,b.grade_code,b.former_city,b.former_school,b.guardian_ids,b.is_adjust,b.apply_uid,b.source
- ,b.name as student_name,b.sex,b.birthday,b.nation,b.prove_type,b.idcard,b.native_place,b.address,b.student_id,b.is_transfer,b.semester_date";
- // ,c.name as student_name,c.sex,c.birthday,c.nation,c.prove_type,c.idcard,c.join_guardian,c.native_place,c.address
- if (!empty($pageNo)) {
- $res = JdfEnrollVolunteer::alias('a')
- ->join("jdf_enroll_students b", "a.enroll_id = b.enroll_id")
- ->field($fields)
- ->where($whereAry['where'])
- ->order('a.create_at asc')
- ->paginate(['page' => $pageNo, 'list_rows' => $pageSize]);
- return pageRes(1, '获取成功', $res->total(), $res->items());
- } else {
- $list = JdfEnrollVolunteer::alias('a')
- ->join("jdf_enroll_students b", "a.enroll_id = b.enroll_id")
- ->field($fields)
- ->where($whereAry['where'])->select();
- return res(1, '获取成功', $list);
- }
- }
- /**
- * @title:选择器数据
- * @desc: 描述
- * @return {*}
- * @author: 系统开发
- * @method: POST
- * @Date: 2024-12-10 17:45:55
- */
- public function getTree($labelField = '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-10 17:45:55
- */
- 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} {name} {} {学生姓名}
- * @param {tinyint} {sex} {0} {学生性别}
- * @param {tinyint} {status} {0} {预约状态}
- * @param {int} {org_id} {0} {组织id}
- * @param {varchar} {former_school} {} {前学校}
- * @param {varchar} {address} {} {家庭住址}
- * @param {date} {birthday} {} {出生日期}
- * @param {int} {idcard} {0} {身份证}
- * @param {varchar} {native_place} {} {籍贯}
- * @param {int} {nation_id} {0} {民族}
- * @param {int} {guardian_id} {0} {监护人id}
- * @return {*}
- * @author: 系统开发
- * @method: POST
- * @Date: 2024-12-10 17:45:55
- */
- 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-10 17:45:55
- */
- 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-10 17:45:55
- */
- public function getOptions()
- {
- $data = $this->request->param();
- $res = (new platformAuth())->interfaceRequest('getSchool', $data);
- if (!$res['code']) return res(2, $res['msg'] ?? '获取失败', $res['data'] ?? '');
- return res(1, "获取成功", $res['data']);
- }
- private $fieldList = [
- 'index' => '序号',
- 'student_name' => '学生姓名',
- 'sex' => '学生性别',
- 'address' => '家庭住址',
- 'birthday' => '出生日期',
- 'prove_type' => '证件类型',
- 'idcard' => '证件号',
- 'grade_name' => '预读年级',
- 'num' => '第几志愿',
- 'name' => '志愿学校',
- 'former_city' => '现就读学校区域',
- 'former_school' => '现就读学校',
- 'semester_date' => '预约时间',
- 'is_transfer' => '预约类型',
- 'school_year' => '学年',
- ];
- /**
- * @title:导出数据
- * @desc: 描述
- * @param {date} {birthday} {} {出生日期}
- * @param {string} {keyword} {} {搜索关键词,可搜索学生姓名|前学校|家庭住址|籍贯}
- * @return {*}
- * @author: 系统开发
- * @method: POST
- * @Date: 2024-12-10 17:45:55
- */
- public function doExport()
- {
- $whereAry = $this->createWhere();
- $fields = "a.*,b.grade_name,b.grade_code,b.former_city,b.former_school,b.guardian_ids,b.is_adjust,b.apply_uid,b.source
- ,b.name as student_name,b.sex,b.birthday,b.nation,b.prove_type,b.idcard,b.native_place,b.address,b.student_id,b.admit_schools,b.is_transfer,b.semester_date,b.school_year
- ,GROUP_CONCAT(CONCAT(c.name, ':', c.phone) ORDER BY c.name SEPARATOR ', ') as guardians_info";
- $list = JdfEnrollVolunteer::alias('a')
- ->join("jdf_enroll_students b", "a.enroll_id = b.enroll_id")
- ->join("jdf_guardian c", "FIND_IN_SET(c.guardian_id, b.guardian_ids)")
- ->field($fields)
- ->order('a.create_at asc')
- ->where($whereAry['where'])->group('a.id')->select()->toArray();
- $head = array_values($this->fieldList);
- // 最多可能的监护人数量,可根据实际情况调整
- $maxGuardians = 2;
- for ($i = 1; $i <= $maxGuardians; $i++) {
- $head[] = "监护人{$i}";
- $head[] = "电话";
- }
- $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];
- }
- }
- // 处理监护人信息
- $guardians = explode(', ', $item['guardians_info']);
- for ($i = 0; $i < $maxGuardians; $i++) {
- if (isset($guardians[$i])) {
- [$name, $phone] = explode(':', $guardians[$i]);
- $body[$index][] = $name;
- $body[$index][] = $phone;
- } else {
- $body[$index][] = '';
- $body[$index][] = "";
- }
- }
- }
- //创建文件夹
- $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, '导出了enrollStudents');
- return res(1, '获取成功', ['url' => $returnpath, 'name' => $filename]);
- }
- public
- function __call($name, $arguments)
- {
- return res(2, "方法{$name}不存在");
- }
- /**
- * Desc :当前订单监护人列表
- * User : zwq
- * Date : 2024-12-18 14:27
- */
- public
- function getGuardianList()
- {
- $guardian_ids = input('guardian_ids/s', "");
- $enroll_id = input('enroll_id/d', 0);
- $student_id = input('student_id/d', 0);
- $list = JdfGuardian::where('guardian_id', 'in', $guardian_ids)->select()->each(function ($item) use ($enroll_id, $student_id) {
- if ($student_id && $student_id >= 0) {
- $item['relation'] = JdfGuardianRelation::where('student_id', $student_id)
- ->where('guardian_id', $item['guardian_id'])
- ->find();
- } else {
- $item['relation'] = JdfGuardianRelation::where('enroll_id', $enroll_id)
- ->where('guardian_id', $item['guardian_id'])
- ->find();
- }
- });
- return res(1, '获取成功', $list);
- }
- /**
- * Desc :获取学段列表
- * User : zwq
- * Date : 2024-12-12 16:37
- */
- public
- function getPeriodList()
- {
- $data = $this->request->param();
- $res = EnrollHandle::getSchoolCode($data);
- if (!$res['code']) return res(2, $res['msg'] ?? '获取失败', $res['data'] ?? '');
- return res(1, "保存成功", $res['data'] ?? '');
- }
- /**
- * Desc :获取分类年级
- * User : zwq
- * Date : 2024-12-12 16:37
- */
- public
- function getGrade()
- {
- $data = $this->request->param();
- $res = (new platformAuth())->interfaceRequest('getGrade', $data);
- if (!$res['code']) return res(2, $res['msg'] ?? '获取失败', $res['data'] ?? '');
- return res(1, "保存成功", $res['data'] ?? '');
- }
- /**
- * Desc :获取学校列表
- * User : zwq
- * Date : 2024-12-12 17:23
- */
- public
- function getSchoolList()
- {
- $data = $this->request->param();
- $pageNo = input('pageNo/d', 1);
- $pageSize = input('pageSize/d', 10);
- $kw = input('keyword/s', '');
- $where = [];
- if ($this->userinfo && !$this->userinfo['is_developer']) {
- $org_ids = $this->userinfo['org_id'];
- if ($org_ids !== 1) {
- //转为字符串
- if (is_array($org_ids)) {
- $org_ids = implode(',', $org_ids);
- }
- $data['org_ids'] = $org_ids;
- $where[] = ['org_id', 'in', $org_ids];
- }
- }
- if (!empty($kw)) {
- $where[] = ['name', 'like', '%' . $kw . '%'];
- }
- $res = (new platformAuth())->interfaceRequest('getSchoolCode', []);
- if (!$res['code']) return res(2, $res['msg'] ?? '查询失败', $res['data'] ?? '');
- $codes = array_column($res['data'], 'code');
- $where[] = ['type', 'in', $codes];
- $where[] = ['status', '=', 1];
- $field = 'org_id,name';
- $list = Org::where($where)->field($field)->paginate(['page' => $pageNo, 'list_rows' => $pageSize]);;
- return pageRes(1, '获取成功', $list->total(), $list->items());
- }
- /**
- * Desc :获取报名学校
- * User : zwq
- * Date : 2025-01-13 16:59
- * @return \think\response\Json
- */
- public
- function getClassSchool()
- {
- $data = $this->request->param();
- $res = EnrollHandle::getClassSchool($data);
- if (!$res['code']) return res(2, $res['msg'] ?? '获取失败', $res['data'] ?? '');
- return res(1, "保存成功", $res['data'] ?? '');
- }
- /**
- * Desc :获取全部省市县区列表
- * User : zwq
- * Date : 2025-01-09 16:18
- */
- public
- function getAreaList()
- {
- $data = $this->request->param();
- $res = (new platformAuth())->interfaceRequest('getArea', $data);
- if (!$res['code']) return res(2, $res['msg'] ?? '获取失败', $res['data'] ?? '');
- return res(1, "保存成功", $res['data'] ?? '');
- }
- /**
- * Desc :获取以前就读学校
- * User : zwq
- * Date : 2025-01-09 16:18
- */
- public
- function getFormerSchool()
- {
- $data = $this->request->param();
- $res = (new platformAuth())->interfaceRequest('getPreviousSchool', $data);
- if (!$res['code']) return res(2, $res['msg'] ?? '获取失败', $res['data'] ?? '');
- return res(1, "获取成功", $res['data']);
- }
- /**
- * Desc :获取监护人关系列表
- * User : zwq
- * Date : 2025-01-13 09:07
- * @return \think\response\Json
- */
- public
- function getRelationList()
- {
- $data = $this->request->param();
- $res = (new platformAuth())->interfaceRequest('getDicPage', $data);
- if (!$res['code']) return res(2, $res['msg'] ?? '获取失败', $res['data'] ?? '');
- return res(1, "获取成功", $res['data']);
- }
- /**
- * Desc :创建报名
- * User : zwq
- * Date : 2024-12-17 10:57
- */
- public
- function createOrder()
- {
- $data = $this->request->param();
- $res = EnrollHandle::createEnroll($this->userinfo, $data);
- if (!$res['code']) return res(2, $res['msg'] ?? '创建失败', $res['data'] ?? '');
- return res(1, "保存成功", $res['data'] ?? '');
- }
- /**
- * Desc :删除报名信息
- * User : zwq
- * Date : 2025-02-07 09:54
- */
- public
- function deleteEnroll()
- {
- $data = $this->request->param();
- $res = EnrollHandle::deleteEnroll($this->userinfo, $data);
- if (!$res['code']) return res(2, $res['msg'] ?? '创建失败', $res['data'] ?? '');
- return res(1, "保存成功", $res['data'] ?? '');
- }
- }
|