StudentController.class.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. <?php
  2. namespace Home\Controller;
  3. /**
  4. * 学生
  5. * @author Devil
  6. * @blog http://gong.gg/
  7. * @version 0.0.1
  8. * @datetime 2017-03-02T22:48:35+0800
  9. */
  10. class StudentController extends CommonController
  11. {
  12. /**
  13. * [_initialize 前置操作-继承公共前置方法]
  14. * @author Devil
  15. * @blog http://gong.gg/
  16. * @version 0.0.1
  17. * @datetime 2017-03-02T22:48:35+0800
  18. */
  19. public function _initialize()
  20. {
  21. // 调用父类前置方法
  22. parent::_initialize();
  23. // 登录校验
  24. $this->Is_Login();
  25. }
  26. /**
  27. * [Index 首页]
  28. * @author Devil
  29. * @blog http://gong.gg/
  30. * @version 0.0.1
  31. * @datetime 2017-02-22T16:50:32+0800
  32. */
  33. public function Index()
  34. {
  35. // 获取列表
  36. $where = array('us.user_id'=>$this->user['id']);
  37. $list = $this->StudentSetDataHandle(M('UserStudent')->alias('AS us')->join('__STUDENT__ AS s ON s.id=us.student_id ')->field('s.*, us.id AS user_student_id,us.add_time AS bundled_time')->where($where)->select());
  38. // 数据列表
  39. $this->assign('list', $list);
  40. $this->display('Index');
  41. }
  42. /**
  43. * [StudentSetDataHandle 数据处理]
  44. * @author Devil
  45. * @blog http://gong.gg/
  46. * @version 0.0.1
  47. * @datetime 2016-12-29T21:27:15+0800
  48. * @param [array] $data [学生数据]
  49. * @return [array] [处理好的数据]
  50. */
  51. private function StudentSetDataHandle($data)
  52. {
  53. $result = array();
  54. if(!empty($data))
  55. {
  56. $c = M('Class');
  57. $r = M('Region');
  58. $s = M('Semester');
  59. foreach($data as $k=>$v)
  60. {
  61. if(!isset($result[$v['semester_id']]))
  62. {
  63. // 学期
  64. $result[$v['semester_id']]['id'] = $v['semester_id'];
  65. $result[$v['semester_id']]['name'] = $s->where(array('id'=>$v['semester_id']))->getField('name');
  66. }
  67. // 班级
  68. $tmp_class = $c->field(array('pid', 'name'))->find($v['class_id']);
  69. if(!empty($tmp_class))
  70. {
  71. $p_name = ($tmp_class['pid'] > 0) ? $c->where(array('id'=>$tmp_class['pid']))->getField('name') : '';
  72. $v['class_name'] = empty($p_name) ? $tmp_class['name'] : $p_name.'-'.$tmp_class['name'];
  73. } else {
  74. $v['class_name'] = '';
  75. }
  76. // 地区
  77. $v['region_name'] = $r->where(array('id'=>$v['region_id']))->getField('name');
  78. // 学期
  79. $v['semester_text'] = $result[$v['semester_id']]['name'];
  80. // 出生
  81. $v['birthday'] = date('Y-m-d', $v['birthday']);
  82. // 报名时间
  83. $v['add_time'] = date('Y-m-d H:i:s', $v['add_time']);
  84. // 更新时间
  85. $v['upd_time'] = date('Y-m-d H:i:s', $v['upd_time']);
  86. // 绑定时间
  87. $v['bundled_time'] = date('Y-m-d H:i:s', $v['bundled_time']);
  88. // 性别
  89. $v['gender'] = L('common_gender_list')[$v['gender']]['name'];
  90. // 状态
  91. $v['state'] = L('common_student_state_list')[$v['state']]['name'];
  92. // 缴费状态
  93. $v['tuition_state_text'] = L('common_tuition_state_list')[$v['tuition_state']]['name'];
  94. $result[$v['semester_id']]['item'][] = $v;
  95. }
  96. }
  97. return $result;
  98. }
  99. /**
  100. * [ScoreInfo 成绩查询]
  101. * @author Devil
  102. * @blog http://gong.gg/
  103. * @version 0.0.1
  104. * @datetime 2017-03-22T22:39:04+0800
  105. */
  106. public function ScoreInfo()
  107. {
  108. $id = I('id');
  109. if(!empty($id))
  110. {
  111. $field = array('s.username', 's.class_id', 'f.score', 'f.subject_id', 'f.score_id', 'f.comment', 'f.add_time');
  112. $where = array('us.user_id'=>$this->user['id'], 'us.id'=>$id);
  113. $data = $this->ScoreSetDataHandle(M('UserStudent')->alias('AS us')->join('__STUDENT__ AS s ON us.student_id=s.id')->join('__FRACTION__ AS f ON s.id=f.student_id')->where($where)->field($field)->order('f.score_id ASC')->select());
  114. $this->assign('data', $data);
  115. $this->assign('student_score_title_list', L('student_score_title_list'));
  116. }
  117. $this->display('ScoreInfo');
  118. }
  119. /**
  120. * [ScoreSetDataHandle 数据处理]
  121. * @author Devil
  122. * @blog http://gong.gg/
  123. * @version 0.0.1
  124. * @datetime 2016-12-29T21:27:15+0800
  125. * @param [array] $data [学生数据]
  126. * @return [array] [处理好的数据]
  127. */
  128. private function ScoreSetDataHandle($data)
  129. {
  130. $result = array();
  131. if(!empty($data))
  132. {
  133. $score = M('Score');
  134. $subject = M('Subject');
  135. $class = M('Class');
  136. $score_level = L('common_fraction_level_list');
  137. foreach($data as $k=>$v)
  138. {
  139. // 基础资料
  140. if(!isset($result['username']))
  141. {
  142. // 姓名
  143. $result['username'] = $v['username'];
  144. // 班级
  145. $tmp_class = $class->field(array('pid', 'name'))->find($v['class_id']);
  146. if(!empty($tmp_class))
  147. {
  148. $p_name = ($tmp_class['pid'] > 0) ? $class->where(array('id'=>$tmp_class['pid']))->getField('name') : '';
  149. $result['class_name'] = empty($p_name) ? $tmp_class['name'] : $p_name.'-'.$tmp_class['name'];
  150. }
  151. }
  152. // 学期key
  153. $score_key = $v['score_id'];
  154. // 成绩期号
  155. if(!isset($result['item'][$score_key]))
  156. {
  157. $result['item'][$score_key]['name'] = $score->where(array('id'=>$v['score_id']))->getField('name');
  158. }
  159. // 科目
  160. $v['subject_name'] = $subject->where(array('id'=>$v['subject_id']))->getField('name');
  161. // 成绩等级
  162. foreach($score_level as $level)
  163. {
  164. if($v['score'] >= $level['min'] && $v['score'] <= $level['max'])
  165. {
  166. $v['score_level'] = $level['name'];
  167. }
  168. }
  169. if(!isset($v['score_level']))
  170. {
  171. $v['score_level'] = '';
  172. }
  173. // 添加时间
  174. $v['add_time'] = date('Y-m-d', $v['add_time']);
  175. unset($v['username'], $v['class_id'], $v['subject_id'], $v['score_id']);
  176. $result['item'][$score_key]['item'][] = $v;
  177. }
  178. }
  179. return $result;
  180. }
  181. /**
  182. * [PolyInfo 学生关联-页面]
  183. * @author Devil
  184. * @blog http://gong.gg/
  185. * @version 0.0.1
  186. * @datetime 2017-03-15T11:22:33+0800
  187. */
  188. public function PolyInfo()
  189. {
  190. $this->display('PolyInfo');
  191. }
  192. /**
  193. * [Delete 学生关联-解除]
  194. * @author Devil
  195. * @blog http://gong.gg/
  196. * @version 0.0.1
  197. * @datetime 2016-12-25T22:36:12+0800
  198. */
  199. public function Delete()
  200. {
  201. if(!IS_AJAX)
  202. {
  203. $this->error(L('common_unauthorized_access'));
  204. }
  205. // 数据删除
  206. if(M('UserStudent')->where(array('id'=>I('id'), 'user_id'=>$this->user['id']))->delete())
  207. {
  208. $this->ajaxReturn(L('common_operation_delete_success'));
  209. } else {
  210. $this->ajaxReturn(L('common_operation_delete_error'), -100);
  211. }
  212. }
  213. /**
  214. * [Poly 学生关联]
  215. * @author Devil
  216. * @blog http://gong.gg/
  217. * @version 0.0.1
  218. * @datetime 2017-03-22T16:47:29+0800
  219. */
  220. public function Poly()
  221. {
  222. // 是否ajax请求
  223. if(!IS_AJAX)
  224. {
  225. $this->error(L('common_unauthorized_access'));
  226. }
  227. // 参数是否有误
  228. if(empty($_POST['id']) || empty($_POST['accounts']) || empty($_POST['verify']))
  229. {
  230. $this->ajaxReturn(L('common_param_error'), -1);
  231. }
  232. // 账户是否存在
  233. $accounts = I('accounts');
  234. $field = $this->StudentPolyAccountsCheck($accounts);
  235. // 验证码校验
  236. $verify_param = array(
  237. 'key_prefix' => 'student_poly',
  238. 'expire_time' => MyC('common_verify_expire_time'),
  239. 'time_interval' => MyC('common_verify_time_interval'),
  240. );
  241. if($field == 'email')
  242. {
  243. $obj = new \My\Email($verify_param);
  244. } else {
  245. $obj = new \My\Sms($verify_param);
  246. }
  247. // 是否已过期
  248. if(!$obj->CheckExpire())
  249. {
  250. $this->ajaxReturn(L('common_verify_expire'), -10);
  251. }
  252. // 是否正确
  253. if(!$obj->CheckCorrect(I('verify')))
  254. {
  255. $this->ajaxReturn(L('common_verify_error'), -11);
  256. }
  257. // 查询用户数据
  258. $where = array('id'=>I('id'), $field=>$accounts, 'semester_id'=>MyC('admin_semester_id'));
  259. $student_id = M('Student')->where($where)->getField('id');
  260. if(!empty($student_id))
  261. {
  262. $data = array(
  263. 'student_id' => $student_id,
  264. 'user_id' => $this->user['id'],
  265. 'add_time' => time(),
  266. );
  267. if(M('UserStudent')->add($data))
  268. {
  269. // 清除验证码
  270. $obj->Remove();
  271. $this->ajaxReturn(L('common_operation_join_success'));
  272. }
  273. $this->ajaxReturn(L('common_operation_join_error'), -100);
  274. }
  275. $this->ajaxReturn(L('common_student_no_exist_error'), -1000);
  276. }
  277. /**
  278. * [PolyQuery 学生关联-数据查询]
  279. * @author Devil
  280. * @blog http://gong.gg/
  281. * @version 0.0.1
  282. * @datetime 2017-03-17T16:58:26+0800
  283. */
  284. public function PolyQuery()
  285. {
  286. // 是否ajax请求
  287. if(!IS_AJAX)
  288. {
  289. $this->error(L('common_unauthorized_access'));
  290. }
  291. // 参数是否有误
  292. if(empty($_POST['username']) || empty($_POST['student_number']) || empty($_POST['id_card']))
  293. {
  294. $this->ajaxReturn(L('common_param_error'), -1);
  295. }
  296. // 查询用户数据
  297. $where = array('username'=>I('username'), 'number'=>I('student_number'), 'id_card'=>I('id_card'), 'semester_id'=>MyC('admin_semester_id'));
  298. $data = M('Student')->field(array('id', 'my_mobile', 'parent_mobile', 'email'))->where($where)->find();
  299. if(!empty($data))
  300. {
  301. // 是否已关联过
  302. $temp = M('UserStudent')->where(array('student_id'=>$data['id'], 'user_id'=>$this->user['id']))->getField('id');
  303. if(!empty($temp))
  304. {
  305. $this->ajaxReturn(L('student_join_accounts_exist_tips'), -2);
  306. }
  307. // 封装返回数据
  308. $result = array('id' => $data['id'], 'contact_list' => array());
  309. if(!empty($data['my_mobile']))
  310. {
  311. $result['contact_list'][] = $data['my_mobile'];
  312. }
  313. if(!empty($data['parent_mobile']))
  314. {
  315. $result['contact_list'][] = $data['parent_mobile'];
  316. }
  317. if(!empty($data['email']))
  318. {
  319. $result['contact_list'][] = $data['email'];
  320. }
  321. $this->ajaxReturn(L('common_operation_success'), 0, $result);
  322. }
  323. $this->ajaxReturn(L('common_student_no_exist_error'), -1000);
  324. }
  325. /**
  326. * [PolyVerifyEntry 学生关联-验证码显示]
  327. * @author Devil
  328. * @blog http://gong.gg/
  329. * @version 0.0.1
  330. * @datetime 2017-03-05T15:10:21+0800
  331. */
  332. public function PolyVerifyEntry()
  333. {
  334. $this->CommonVerifyEntry(I('type', 'student_poly'));
  335. }
  336. /**
  337. * [PolyVerifySend 学生关联-验证码发送]
  338. * @author Devil
  339. * @blog http://gong.gg/
  340. * @version 0.0.1
  341. * @datetime 2017-03-10T17:35:03+0800
  342. */
  343. public function PolyVerifySend()
  344. {
  345. // 是否ajax请求
  346. if(!IS_AJAX)
  347. {
  348. $this->error(L('common_unauthorized_access'));
  349. }
  350. // 参数
  351. $accounts = I('accounts');
  352. if(empty($accounts))
  353. {
  354. $this->ajaxReturn(L('common_param_error'), -10);
  355. }
  356. // 账户是否存在
  357. $type = $this->StudentPolyAccountsCheck($accounts);
  358. // 验证码公共基础参数
  359. $verify_param = array(
  360. 'key_prefix' => 'student_poly',
  361. 'expire_time' => MyC('common_verify_expire_time'),
  362. 'time_interval' => MyC('common_verify_time_interval'),
  363. );
  364. // 是否开启图片验证码
  365. $verify = $this->CommonIsImaVerify($verify_param);
  366. // 验证码
  367. $code = GetNumberCode(6);
  368. // 邮箱
  369. if($type == 'email')
  370. {
  371. $obj = new \My\Email($verify_param);
  372. $email_param = array(
  373. 'email' => $accounts,
  374. 'content' => MyC('home_email_user_student_binding'),
  375. 'title' => MyC('home_site_name').' - '.L('student_operation_binding_text'),
  376. 'code' => $code,
  377. );
  378. $state = $obj->SendHtml($email_param);
  379. // 短信
  380. } else {
  381. $obj = new \My\Sms($verify_param);
  382. $state = $obj->SendText($accounts, MyC('home_sms_user_student_binding'), $code);
  383. }
  384. // 状态
  385. if($state)
  386. {
  387. // 清除验证码
  388. if(isset($verify) && is_object($verify))
  389. {
  390. $verify->Remove();
  391. }
  392. $this->ajaxReturn(L('common_send_success'));
  393. } else {
  394. $this->ajaxReturn(L('common_send_error').'['.$obj->error.']', -100);
  395. }
  396. }
  397. /**
  398. * [StudentPolyAccountsCheck 学生是否存在]
  399. * @author Devil
  400. * @blog http://gong.gg/
  401. * @version 0.0.1
  402. * @datetime 2017-03-22T17:39:56+0800
  403. * @param [string] $accounts [my_mobile, parent_mobile, email]
  404. * @return [string] [表字段名称 my_mobile, parent_mobile, email]
  405. */
  406. private function StudentPolyAccountsCheck($accounts)
  407. {
  408. $field = array('my_mobile', 'parent_mobile', 'email');
  409. $where = array(
  410. array(
  411. 'my_mobile' => $accounts,
  412. 'parent_mobile' => $accounts,
  413. 'email' => $accounts,
  414. '_logic' => 'OR',
  415. ),
  416. 'semester_id' => MyC('admin_semester_id'),
  417. );
  418. $data = M('Student')->field($field)->where($where)->find();
  419. if(!empty($data))
  420. {
  421. $key = array_search($accounts, $data);
  422. return ($key === false) ? '' : $key;
  423. } else {
  424. $this->ajaxReturn(L('common_student_no_exist_error'), -1000);
  425. }
  426. }
  427. }
  428. ?>