ApiController.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <?php
  2. class ApiController extends AssistController
  3. {
  4. // 系统用户登录
  5. public function actionLogin()
  6. {
  7. $username=Req::post('username');
  8. $password=Req::post('password');
  9. $return['status']=0;
  10. if(!$username || !$password){
  11. $return['msg']='登录信息不完整';
  12. exit(json_encode($return));
  13. }
  14. // $user=AssistUser::find()->where('user_name=:username',[':username'=>$username])->asArray()->one();
  15. $user=AssistUser::model()->find('user_name=:username',array(':username'=>$username));
  16. if(!$user){
  17. $return['msg']='用户名不正确';
  18. exit(json_encode($return));
  19. }else{
  20. if($this->producePassword($password)!=$user['password']){
  21. $return['msg']='密码不正确';
  22. exit(json_encode($return));
  23. }
  24. if($user["status"]==0)
  25. {
  26. $return['msg']='此账号被冻结';
  27. exit(json_encode($return));
  28. }
  29. $data=array(
  30. 'user_id' => $user['user_id'],
  31. 'username' => $user['user_name'],
  32. 'real_name' => $user['real_name'],
  33. 'role'=>$user['role'],
  34. 'cutting_limit'=>$user['cutting_limit'],
  35. 'scan_limit'=>$user['scan_limit'],
  36. );
  37. Yii::app()->session['user'] = $data;
  38. $token=Yii::app()->getSecurityManager()->generateRandomString(32,true);
  39. $data['sig']=$token;
  40. //更新用户登录信息到redis
  41. Yii::app()->cache->setValue($token,json_encode($data),86400);
  42. // if(AssistUser::model()->updateAll(array('token'=>$token),'user_id=:id',array(':id'=>$user['user_id']))){
  43. $return['status']=1;
  44. $return['msg']='登录成功';
  45. $return['data']=$data;
  46. // }
  47. exit(json_encode($return));
  48. }
  49. }
  50. // 系统用户退出
  51. public function actionOut()
  52. {
  53. Yii::app()->user->logout();
  54. return $this->redirect(array('login/index'));
  55. }
  56. //系统设置
  57. public function actionSetting(){
  58. $cutting_task=(int)Req::post('cutting_task');
  59. $open_cutting_upper_limit=(int)Req::post('open_cutting_upper_limit');
  60. $cutting_task_upper_limit_num=(int)Req::post('cutting_task_upper_limit_num');
  61. $scan_task=(int)Req::post('scan_task');
  62. $open_scan_upper_limit=(int)Req::post('open_scan_upper_limit');
  63. $scan_task_upper_limit_num=(int)Req::post('scan_task_upper_limit_num');
  64. $return['status']=0;
  65. $data=array(
  66. 'cutting_task'=>$cutting_task,
  67. 'open_cutting_upper_limit'=>$open_cutting_upper_limit,
  68. 'cutting_task_upper_limit_num'=>$cutting_task_upper_limit_num,
  69. 'scan_task'=>$scan_task,
  70. 'open_scan_upper_limit'=>$open_scan_upper_limit,
  71. 'scan_task_upper_limit_num'=>$scan_task_upper_limit_num,
  72. );
  73. $rs=AssistSetting::model()->updateAssistSetting($data);
  74. if($rs){
  75. $return['status']=1;
  76. $return['msg']='设置成功';
  77. exit(json_encode($return));
  78. }else{
  79. $return['msg']='设置失败';
  80. exit(json_encode($return));
  81. }
  82. }
  83. //读取系统设置
  84. public function actionGetSetting(){
  85. $setting=AssistSetting::model()->getAssistSetting();
  86. if($setting){
  87. $return['status']=1;
  88. $return['msg']='读取成功';
  89. $return['data']=array(
  90. 'cutting_task'=>$setting['cutting_task'],
  91. 'open_cutting_upper_limit'=>$setting['open_cutting_upper_limit'],
  92. 'cutting_task_upper_limit_num'=>$setting['cutting_task_upper_limit_num'],
  93. 'scan_task'=>$setting['scan_task'],
  94. 'open_scan_upper_limit'=>$setting['open_scan_upper_limit'],
  95. 'scan_task_upper_limit_num'=>$setting['scan_task_upper_limit_num'],
  96. );
  97. exit(json_encode($return));
  98. }else{
  99. $return['status']=1;
  100. $return['msg']='读取成功';
  101. $return['data']=array(
  102. 'cutting_task'=>1,
  103. 'open_cutting_upper_limit'=>0,
  104. 'cutting_task_upper_limit_num'=>0,
  105. 'scan_task'=>1,
  106. 'open_scan_upper_limit'=>0,
  107. 'scan_task_upper_limit_num'=>0,
  108. );
  109. exit(json_encode($return));
  110. }
  111. }
  112. //修改密码
  113. public function actionChangepassword(){
  114. $currPwd=Req::post('currPwd');
  115. $newPwd=Req::post('newPwd');
  116. $userId=Req::post('user_id');
  117. $return['status']=0;
  118. if(!$userId)
  119. {
  120. $return['msg']='未指定用户';
  121. exit(json_encode($return));
  122. }
  123. if(!$currPwd){
  124. $return['msg']='请输入旧密码';
  125. exit(json_encode($return));
  126. }
  127. if(!$newPwd){
  128. $return['msg']='请输入新密码';
  129. exit(json_encode($return));
  130. }
  131. if($currPwd == $newPwd){
  132. $return['msg']='新密码和旧密码相同,未修改';
  133. exit(json_encode($return));
  134. }
  135. $findUser = AssistUser::model()->findByPk($userId)->attributes;
  136. if(!$findUser){
  137. $return['msg']='用户不存在';
  138. exit(json_encode($return));
  139. }
  140. if($findUser['password']!=$this->producePassword($currPwd)){
  141. $return['msg']='旧密码不正确';
  142. exit(json_encode($return));
  143. }
  144. if(AssistUser::model()->updateAll(array('password'=>$this->producePassword($newPwd)),'user_id=:uid',array(':uid'=>$userId))){
  145. $return['status']=1;
  146. $return['msg']='修改成功';
  147. exit(json_encode($return));
  148. }else{
  149. $return['msg']='修改失败';
  150. exit(json_encode($return));
  151. }
  152. }
  153. //读取附件地址
  154. public function actionGetTaskImg(){
  155. $examGroupId=Req::post('exam_group_id');
  156. $type=(int)Req::post('type');
  157. $return['status']=0;
  158. if(!in_array($type,array(1,2,3))){
  159. $return['msg']='类型错误';
  160. exit(json_encode($return));
  161. }
  162. $taskModel=new ATask();
  163. $task=$taskModel->getTaskByExamGroupId($examGroupId)->attributes;
  164. if(!$task){
  165. $return['msg']='任务不存在';
  166. exit(json_encode($return));
  167. }
  168. $data=array();
  169. switch ($type){
  170. case 1:
  171. $data=explode(',',$task['answer_card_img']);
  172. break;
  173. case 2:
  174. $data=explode(',',$task['paper_img']);
  175. break;
  176. case 3:
  177. $data=explode(',',$task['parse_img']);
  178. break;
  179. }
  180. $return['status']=1;
  181. $return['msg']='修改成功';
  182. $return['data']=$data;
  183. exit(json_encode($return));
  184. }
  185. //读取科目列表
  186. public function actionGetSubjects(){
  187. $subjects=Yii::app()->params['subjectId'];
  188. if(isset($subjects[20])){
  189. unset($subjects[20]);
  190. }
  191. $return['status']=1;
  192. $return['msg']='成功';
  193. $return['data']=$subjects;
  194. exit(json_encode($return));
  195. }
  196. //发送在线答题卡测试数据
  197. public function actionSendTestData(){
  198. $item=array(
  199. array(
  200. 'student_id'=>'17536408539753897824',
  201. 'paper_id'=>'570614822981877760',
  202. 'class_id'=>'17536408539753896731',
  203. 'student_card'=>'47649726',
  204. 'exam_id'=>'570614822926188544',
  205. 'student_name'=>'黄陈希',
  206. 'class_name'=>'22'
  207. ),
  208. array(
  209. 'student_id'=>'17536408539753897825',
  210. 'paper_id'=>'570614822981877760',
  211. 'class_id'=>'17536408539753896731',
  212. 'student_card'=>'47649727',
  213. 'exam_id'=>'570614822926188544',
  214. 'student_name'=>'雷汝芬',
  215. 'class_name'=>'22'
  216. ),
  217. array(
  218. 'student_id'=>'17536408539753897826',
  219. 'paper_id'=>'570614822981877760',
  220. 'class_id'=>'17536408539753896731',
  221. 'student_card'=>'47649728',
  222. 'exam_id'=>'570614822926188544',
  223. 'student_name'=>'黎政丰',
  224. 'class_name'=>'22'
  225. ),
  226. );
  227. $arr=array(
  228. 'schoolId'=>476,
  229. 'examGroupId'=>'570614821953171456',
  230. 'savedInfoUrl'=>'http://zxhx.cn-bj.ufileos.com/zsyas2%2Fcardonline%2F476%2F2020%2F04%2F28%2F570614821953171456.zip?r=303',
  231. 'students'=>$item,
  232. 'qrcode'=>1,
  233. 'semesterId'=>'17535877358591649378'
  234. );
  235. $key='zsyas2-online-card-notify';
  236. $return=sendDataToKafka($key,$arr);
  237. if($return){
  238. exit('发送成功');
  239. }else{
  240. exit('发送失败');
  241. }
  242. }
  243. }