EnrollStudents.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <?php
  2. namespace app\admin\controller\enroll;
  3. /**
  4. * @title : enrollStudents 管理控制器
  5. * @desc :
  6. * @Author : 系统开发
  7. * @Date : 2024-12-10 17:45:55
  8. * @icon fa fa-leaf
  9. */
  10. use app\admin\controller\Base;
  11. use app\admin\extend\enroll\EnrollHandle;
  12. use app\common\model\base\org\Org;
  13. use app\common\model\base\org\OrgType;
  14. use app\common\model\base\user\UserRole;
  15. use app\common\model\enroll\EnrollStudents as EnrollStudentsModel;
  16. use app\common\model\guardian\JdfGuardian;
  17. use app\common\model\guardian\JdfGuardianRelation;
  18. use app\common\model\periodConfig\JdfPeriodConfig;
  19. use app\common\model\enroll\JdfEnrollVolunteer;
  20. use daorui\platform\platformAuth;
  21. class EnrollStudents extends Base
  22. {
  23. protected $model = null;
  24. protected $noNeedLogin = ['getOptions'];
  25. protected $noNeedAuth = [];
  26. public function initialize()
  27. {
  28. parent::initialize();
  29. $this->model = new EnrollStudentsModel;
  30. }
  31. /**
  32. * @title:创建统一查询条件
  33. * @desc: 描述
  34. * @param {date} {birthday} {} {出生日期}
  35. * @param {string} {keyword} {} {搜索关键词,可搜索学生姓名|前学校|家庭住址|籍贯}
  36. * @return {*}
  37. * @author: 系统开发
  38. * @method: POST
  39. * @Date: 2024-12-10 17:45:55
  40. */
  41. private function createWhere()
  42. {
  43. $data = $this->request->param();
  44. $where = [];
  45. $whereOr = [];
  46. if (!empty($data['org_ids'])) {
  47. $where[] = ['a.org_id', 'IN', $data['org_ids']];
  48. } else {
  49. if ($this->userinfo && !$this->userinfo['is_developer']) {
  50. $org_ids = $this->userinfo['org_id'];
  51. //转为字符串
  52. if ($org_ids !== 1) {
  53. if (is_array($org_ids)) {
  54. $org_ids = implode(',', $org_ids);
  55. }
  56. $data['org_ids'] = $org_ids;
  57. $where[] = ['a.org_id', 'IN', $data['org_ids']];
  58. }
  59. }
  60. }
  61. if (!empty($data['keyword'])) {
  62. $keyword = $data['keyword'];
  63. $where[] = ['b.name|b.idcard', 'LIKE', "%$keyword%"];
  64. }
  65. return ['where' => $where, 'whereOr' => $whereOr];
  66. }
  67. /**
  68. * @title:查询数据列表
  69. * @desc: 描述
  70. * @param {date} {birthday} {} {出生日期}
  71. * @param {string} {keyword} {} {搜索关键词,可搜索学生姓名|前学校|家庭住址|籍贯}
  72. * @param {int} {pageNo} {0} {页码}
  73. * @param {int} {pageSize} {10} {每页数量}
  74. * @return {*}
  75. * @author: 系统开发
  76. * @method: POST
  77. * @Date: 2024-12-10 17:45:55
  78. */
  79. public function getList(int $pageNo = 0, int $pageSize = 10)
  80. {
  81. $whereAry = $this->createWhere();
  82. $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
  83. ,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";
  84. // ,c.name as student_name,c.sex,c.birthday,c.nation,c.prove_type,c.idcard,c.join_guardian,c.native_place,c.address
  85. if (!empty($pageNo)) {
  86. $res = JdfEnrollVolunteer::alias('a')
  87. ->join("jdf_enroll_students b", "a.enroll_id = b.enroll_id")
  88. ->field($fields)
  89. ->where($whereAry['where'])
  90. ->order('a.create_at asc')
  91. ->paginate(['page' => $pageNo, 'list_rows' => $pageSize]);
  92. return pageRes(1, '获取成功', $res->total(), $res->items());
  93. } else {
  94. $list = JdfEnrollVolunteer::alias('a')
  95. ->join("jdf_enroll_students b", "a.enroll_id = b.enroll_id")
  96. ->field($fields)
  97. ->where($whereAry['where'])->select();
  98. return res(1, '获取成功', $list);
  99. }
  100. }
  101. /**
  102. * @title:选择器数据
  103. * @desc: 描述
  104. * @return {*}
  105. * @author: 系统开发
  106. * @method: POST
  107. * @Date: 2024-12-10 17:45:55
  108. */
  109. public function getTree($labelField = 'name')
  110. {
  111. $fields = ['id', $labelField];
  112. $where = [];
  113. $list = $this->model->where($where)->field($fields)->select();
  114. return res(1, "获取成功", $list);
  115. }
  116. /**
  117. * @title:查询信息
  118. * @desc: 描述
  119. * @param {int} {id} {} {信息ID}
  120. * @return {*}
  121. * @author: 系统开发
  122. * @method: POST
  123. * @Date: 2024-12-10 17:45:55
  124. */
  125. public function getInfo(int $id = 0)
  126. {
  127. $info = $this->model->with([])->find($id);
  128. return res(1, '获取成功', $info);
  129. }
  130. /**
  131. * @title:新增/编辑信息
  132. * @desc: 描述
  133. * @param {int} {id} {} {主键ID,不传或传0表示新增,大于0表示修改}
  134. * @param {varchar} {name} {} {学生姓名}
  135. * @param {tinyint} {sex} {0} {学生性别}
  136. * @param {tinyint} {status} {0} {预约状态}
  137. * @param {int} {org_id} {0} {组织id}
  138. * @param {varchar} {former_school} {} {前学校}
  139. * @param {varchar} {address} {} {家庭住址}
  140. * @param {date} {birthday} {} {出生日期}
  141. * @param {int} {idcard} {0} {身份证}
  142. * @param {varchar} {native_place} {} {籍贯}
  143. * @param {int} {nation_id} {0} {民族}
  144. * @param {int} {guardian_id} {0} {监护人id}
  145. * @return {*}
  146. * @author: 系统开发
  147. * @method: POST
  148. * @Date: 2024-12-10 17:45:55
  149. */
  150. public function doEdit()
  151. {
  152. $data = $this->request->param();
  153. $res = $this->model->replace()->save($data);
  154. return res(1, '编辑成功');
  155. }
  156. /**
  157. * @title:删除信息
  158. * @desc: 描述
  159. * @param {int} id {} {信息ID}
  160. * @return {*}
  161. * @author: 系统开发
  162. * @method: POST
  163. * @Date: 2024-12-10 17:45:55
  164. */
  165. public function doDelete(int $id = 0)
  166. {
  167. $info = $this->model->find($id);
  168. $info->delete();
  169. return res(1, '删除成功');
  170. }
  171. /**
  172. * @title:获取可选项
  173. * @desc: 描述
  174. * @return {*}
  175. * @author: 系统开发
  176. * @method: POST
  177. * @Date: 2024-12-10 17:45:55
  178. */
  179. public function getOptions()
  180. {
  181. $data = $this->request->param();
  182. $res = (new platformAuth())->interfaceRequest('getSchool', $data);
  183. if (!$res['code']) return res(2, $res['msg'] ?? '获取失败', $res['data'] ?? '');
  184. return res(1, "获取成功", $res['data']);
  185. }
  186. private $fieldList = [
  187. 'index' => '序号',
  188. 'student_name' => '学生姓名',
  189. 'sex' => '学生性别',
  190. 'address' => '家庭住址',
  191. 'birthday' => '出生日期',
  192. 'prove_type' => '证件类型',
  193. 'idcard' => '证件号',
  194. 'grade_name' => '预读年级',
  195. 'num' => '第几志愿',
  196. 'name' => '志愿学校',
  197. 'former_city' => '现就读学校区域',
  198. 'former_school' => '现就读学校',
  199. 'semester_date' => '预约时间',
  200. 'is_transfer' => '预约类型',
  201. 'school_year' => '学年',
  202. ];
  203. /**
  204. * @title:导出数据
  205. * @desc: 描述
  206. * @param {date} {birthday} {} {出生日期}
  207. * @param {string} {keyword} {} {搜索关键词,可搜索学生姓名|前学校|家庭住址|籍贯}
  208. * @return {*}
  209. * @author: 系统开发
  210. * @method: POST
  211. * @Date: 2024-12-10 17:45:55
  212. */
  213. public function doExport()
  214. {
  215. $whereAry = $this->createWhere();
  216. $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
  217. ,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
  218. ,GROUP_CONCAT(CONCAT(c.name, ':', c.phone) ORDER BY c.name SEPARATOR ', ') as guardians_info";
  219. $list = JdfEnrollVolunteer::alias('a')
  220. ->join("jdf_enroll_students b", "a.enroll_id = b.enroll_id")
  221. ->join("jdf_guardian c", "FIND_IN_SET(c.guardian_id, b.guardian_ids)")
  222. ->field($fields)
  223. ->order('a.create_at asc')
  224. ->where($whereAry['where'])->group('a.id')->select()->toArray();
  225. $head = array_values($this->fieldList);
  226. // 最多可能的监护人数量,可根据实际情况调整
  227. $maxGuardians = 2;
  228. for ($i = 1; $i <= $maxGuardians; $i++) {
  229. $head[] = "监护人{$i}";
  230. $head[] = "电话";
  231. }
  232. $body = [];
  233. foreach ($list as $key => $item) {
  234. $index = $key + 1;
  235. foreach ($this->fieldList as $k => $v) {
  236. if ($k == 'index') {
  237. $body[$index][] = $index;
  238. } else {
  239. $body[$index][] = isset($item[$k . '_txt']) ? (is_array($item[$k . '_txt']) ? implode(',', $item[$k . '_txt']) : $item[$k . '_txt']) : $item[$k];
  240. }
  241. }
  242. // 处理监护人信息
  243. $guardians = explode(', ', $item['guardians_info']);
  244. for ($i = 0; $i < $maxGuardians; $i++) {
  245. if (isset($guardians[$i])) {
  246. [$name, $phone] = explode(':', $guardians[$i]);
  247. $body[$index][] = $name;
  248. $body[$index][] = $phone;
  249. } else {
  250. $body[$index][] = '';
  251. $body[$index][] = "";
  252. }
  253. }
  254. }
  255. //创建文件夹
  256. $basepath = 'uploads' . DS . 'download' . DS . date('Ymd');
  257. $savepath = public_path() . $basepath;
  258. if (!is_dir($savepath)) {
  259. @mkdir($savepath, 0777, true);
  260. }
  261. //保存文件
  262. $filename = time() . GetRandStr() . '.xls';
  263. $path = $savepath . DS . $filename;
  264. $export_help = new \excel\MultiHeadExcel();
  265. $export_help->export_help($body, $head, $path);
  266. //返回路径
  267. $returnpath = WEBURL . DS . $basepath . DS . $filename;
  268. slog(1, '导出了enrollStudents');
  269. return res(1, '获取成功', ['url' => $returnpath, 'name' => $filename]);
  270. }
  271. public
  272. function __call($name, $arguments)
  273. {
  274. return res(2, "方法{$name}不存在");
  275. }
  276. /**
  277. * Desc :当前订单监护人列表
  278. * User : zwq
  279. * Date : 2024-12-18 14:27
  280. */
  281. public
  282. function getGuardianList()
  283. {
  284. $guardian_ids = input('guardian_ids/s', "");
  285. $enroll_id = input('enroll_id/d', 0);
  286. $student_id = input('student_id/d', 0);
  287. $list = JdfGuardian::where('guardian_id', 'in', $guardian_ids)->select()->each(function ($item) use ($enroll_id, $student_id) {
  288. if ($student_id && $student_id >= 0) {
  289. $item['relation'] = JdfGuardianRelation::where('student_id', $student_id)
  290. ->where('guardian_id', $item['guardian_id'])
  291. ->find();
  292. } else {
  293. $item['relation'] = JdfGuardianRelation::where('enroll_id', $enroll_id)
  294. ->where('guardian_id', $item['guardian_id'])
  295. ->find();
  296. }
  297. });
  298. return res(1, '获取成功', $list);
  299. }
  300. /**
  301. * Desc :获取学段列表
  302. * User : zwq
  303. * Date : 2024-12-12 16:37
  304. */
  305. public
  306. function getPeriodList()
  307. {
  308. $data = $this->request->param();
  309. $res = EnrollHandle::getSchoolCode($data);
  310. if (!$res['code']) return res(2, $res['msg'] ?? '获取失败', $res['data'] ?? '');
  311. return res(1, "保存成功", $res['data'] ?? '');
  312. }
  313. /**
  314. * Desc :获取分类年级
  315. * User : zwq
  316. * Date : 2024-12-12 16:37
  317. */
  318. public
  319. function getGrade()
  320. {
  321. $data = $this->request->param();
  322. $res = (new platformAuth())->interfaceRequest('getGrade', $data);
  323. if (!$res['code']) return res(2, $res['msg'] ?? '获取失败', $res['data'] ?? '');
  324. return res(1, "保存成功", $res['data'] ?? '');
  325. }
  326. /**
  327. * Desc :获取学校列表
  328. * User : zwq
  329. * Date : 2024-12-12 17:23
  330. */
  331. public
  332. function getSchoolList()
  333. {
  334. $data = $this->request->param();
  335. $pageNo = input('pageNo/d', 1);
  336. $pageSize = input('pageSize/d', 10);
  337. $kw = input('keyword/s', '');
  338. $where = [];
  339. if ($this->userinfo && !$this->userinfo['is_developer']) {
  340. $org_ids = $this->userinfo['org_id'];
  341. if ($org_ids !== 1) {
  342. //转为字符串
  343. if (is_array($org_ids)) {
  344. $org_ids = implode(',', $org_ids);
  345. }
  346. $data['org_ids'] = $org_ids;
  347. $where[] = ['org_id', 'in', $org_ids];
  348. }
  349. }
  350. if (!empty($kw)) {
  351. $where[] = ['name', 'like', '%' . $kw . '%'];
  352. }
  353. $res = (new platformAuth())->interfaceRequest('getSchoolCode', []);
  354. if (!$res['code']) return res(2, $res['msg'] ?? '查询失败', $res['data'] ?? '');
  355. $codes = array_column($res['data'], 'code');
  356. $where[] = ['type', 'in', $codes];
  357. $where[] = ['status', '=', 1];
  358. $field = 'org_id,name';
  359. $list = Org::where($where)->field($field)->paginate(['page' => $pageNo, 'list_rows' => $pageSize]);;
  360. return pageRes(1, '获取成功', $list->total(), $list->items());
  361. }
  362. /**
  363. * Desc :获取报名学校
  364. * User : zwq
  365. * Date : 2025-01-13 16:59
  366. * @return \think\response\Json
  367. */
  368. public
  369. function getClassSchool()
  370. {
  371. $data = $this->request->param();
  372. $res = EnrollHandle::getClassSchool($data);
  373. if (!$res['code']) return res(2, $res['msg'] ?? '获取失败', $res['data'] ?? '');
  374. return res(1, "保存成功", $res['data'] ?? '');
  375. }
  376. /**
  377. * Desc :获取全部省市县区列表
  378. * User : zwq
  379. * Date : 2025-01-09 16:18
  380. */
  381. public
  382. function getAreaList()
  383. {
  384. $data = $this->request->param();
  385. $res = (new platformAuth())->interfaceRequest('getArea', $data);
  386. if (!$res['code']) return res(2, $res['msg'] ?? '获取失败', $res['data'] ?? '');
  387. return res(1, "保存成功", $res['data'] ?? '');
  388. }
  389. /**
  390. * Desc :获取以前就读学校
  391. * User : zwq
  392. * Date : 2025-01-09 16:18
  393. */
  394. public
  395. function getFormerSchool()
  396. {
  397. $data = $this->request->param();
  398. $res = (new platformAuth())->interfaceRequest('getPreviousSchool', $data);
  399. if (!$res['code']) return res(2, $res['msg'] ?? '获取失败', $res['data'] ?? '');
  400. return res(1, "获取成功", $res['data']);
  401. }
  402. /**
  403. * Desc :获取监护人关系列表
  404. * User : zwq
  405. * Date : 2025-01-13 09:07
  406. * @return \think\response\Json
  407. */
  408. public
  409. function getRelationList()
  410. {
  411. $data = $this->request->param();
  412. $res = (new platformAuth())->interfaceRequest('getDicPage', $data);
  413. if (!$res['code']) return res(2, $res['msg'] ?? '获取失败', $res['data'] ?? '');
  414. return res(1, "获取成功", $res['data']);
  415. }
  416. /**
  417. * Desc :创建报名
  418. * User : zwq
  419. * Date : 2024-12-17 10:57
  420. */
  421. public
  422. function createOrder()
  423. {
  424. $data = $this->request->param();
  425. $res = EnrollHandle::createEnroll($this->userinfo, $data);
  426. if (!$res['code']) return res(2, $res['msg'] ?? '创建失败', $res['data'] ?? '');
  427. return res(1, "保存成功", $res['data'] ?? '');
  428. }
  429. /**
  430. * Desc :删除报名信息
  431. * User : zwq
  432. * Date : 2025-02-07 09:54
  433. */
  434. public
  435. function deleteEnroll()
  436. {
  437. $data = $this->request->param();
  438. $res = EnrollHandle::deleteEnroll($this->userinfo, $data);
  439. if (!$res['code']) return res(2, $res['msg'] ?? '创建失败', $res['data'] ?? '');
  440. return res(1, "保存成功", $res['data'] ?? '');
  441. }
  442. }