123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- <?php
- class ApiController extends AssistController
- {
- // 系统用户登录
- public function actionLogin()
- {
- $username=Req::post('username');
- $password=Req::post('password');
- $return['status']=0;
- if(!$username || !$password){
- $return['msg']='登录信息不完整';
- exit(json_encode($return));
- }
- // $user=AssistUser::find()->where('user_name=:username',[':username'=>$username])->asArray()->one();
- $user=AssistUser::model()->find('user_name=:username',array(':username'=>$username));
- if(!$user){
- $return['msg']='用户名不正确';
- exit(json_encode($return));
- }else{
- if($this->producePassword($password)!=$user['password']){
- $return['msg']='密码不正确';
- exit(json_encode($return));
- }
- if($user["status"]==0)
- {
- $return['msg']='此账号被冻结';
- exit(json_encode($return));
- }
- $data=array(
- 'user_id' => $user['user_id'],
- 'username' => $user['user_name'],
- 'real_name' => $user['real_name'],
- 'role'=>$user['role'],
- 'cutting_limit'=>$user['cutting_limit'],
- 'scan_limit'=>$user['scan_limit'],
- );
- Yii::app()->session['user'] = $data;
- $token=Yii::app()->getSecurityManager()->generateRandomString(32,true);
- $data['sig']=$token;
- //更新用户登录信息到redis
- Yii::app()->cache->setValue($token,json_encode($data),86400);
-
- // if(AssistUser::model()->updateAll(array('token'=>$token),'user_id=:id',array(':id'=>$user['user_id']))){
- $return['status']=1;
- $return['msg']='登录成功';
- $return['data']=$data;
- // }
- exit(json_encode($return));
- }
- }
- // 系统用户退出
- public function actionOut()
- {
- Yii::app()->user->logout();
- return $this->redirect(array('login/index'));
- }
- //系统设置
- public function actionSetting(){
- $cutting_task=(int)Req::post('cutting_task');
- $open_cutting_upper_limit=(int)Req::post('open_cutting_upper_limit');
- $cutting_task_upper_limit_num=(int)Req::post('cutting_task_upper_limit_num');
- $scan_task=(int)Req::post('scan_task');
- $open_scan_upper_limit=(int)Req::post('open_scan_upper_limit');
- $scan_task_upper_limit_num=(int)Req::post('scan_task_upper_limit_num');
- $return['status']=0;
- $data=array(
- 'cutting_task'=>$cutting_task,
- 'open_cutting_upper_limit'=>$open_cutting_upper_limit,
- 'cutting_task_upper_limit_num'=>$cutting_task_upper_limit_num,
- 'scan_task'=>$scan_task,
- 'open_scan_upper_limit'=>$open_scan_upper_limit,
- 'scan_task_upper_limit_num'=>$scan_task_upper_limit_num,
- );
- $rs=AssistSetting::model()->updateAssistSetting($data);
- if($rs){
- $return['status']=1;
- $return['msg']='设置成功';
- exit(json_encode($return));
- }else{
- $return['msg']='设置失败';
- exit(json_encode($return));
- }
- }
- //读取系统设置
- public function actionGetSetting(){
- $setting=AssistSetting::model()->getAssistSetting();
-
- if($setting){
- $return['status']=1;
- $return['msg']='读取成功';
- $return['data']=array(
- 'cutting_task'=>$setting['cutting_task'],
- 'open_cutting_upper_limit'=>$setting['open_cutting_upper_limit'],
- 'cutting_task_upper_limit_num'=>$setting['cutting_task_upper_limit_num'],
- 'scan_task'=>$setting['scan_task'],
- 'open_scan_upper_limit'=>$setting['open_scan_upper_limit'],
- 'scan_task_upper_limit_num'=>$setting['scan_task_upper_limit_num'],
- );
- exit(json_encode($return));
- }else{
- $return['status']=1;
- $return['msg']='读取成功';
- $return['data']=array(
- 'cutting_task'=>1,
- 'open_cutting_upper_limit'=>0,
- 'cutting_task_upper_limit_num'=>0,
- 'scan_task'=>1,
- 'open_scan_upper_limit'=>0,
- 'scan_task_upper_limit_num'=>0,
- );
- exit(json_encode($return));
- }
- }
- //修改密码
- public function actionChangepassword(){
- $currPwd=Req::post('currPwd');
- $newPwd=Req::post('newPwd');
- $userId=Req::post('user_id');
- $return['status']=0;
- if(!$userId)
- {
- $return['msg']='未指定用户';
- exit(json_encode($return));
- }
- if(!$currPwd){
- $return['msg']='请输入旧密码';
- exit(json_encode($return));
- }
- if(!$newPwd){
- $return['msg']='请输入新密码';
- exit(json_encode($return));
- }
- if($currPwd == $newPwd){
- $return['msg']='新密码和旧密码相同,未修改';
- exit(json_encode($return));
- }
- $findUser = AssistUser::model()->findByPk($userId)->attributes;
- if(!$findUser){
- $return['msg']='用户不存在';
- exit(json_encode($return));
- }
- if($findUser['password']!=$this->producePassword($currPwd)){
- $return['msg']='旧密码不正确';
- exit(json_encode($return));
- }
- if(AssistUser::model()->updateAll(array('password'=>$this->producePassword($newPwd)),'user_id=:uid',array(':uid'=>$userId))){
- $return['status']=1;
- $return['msg']='修改成功';
- exit(json_encode($return));
- }else{
- $return['msg']='修改失败';
- exit(json_encode($return));
- }
- }
- //读取附件地址
- public function actionGetTaskImg(){
- $examGroupId=Req::post('exam_group_id');
- $type=(int)Req::post('type');
- $return['status']=0;
- if(!in_array($type,array(1,2,3))){
- $return['msg']='类型错误';
- exit(json_encode($return));
- }
- $taskModel=new ATask();
- $task=$taskModel->getTaskByExamGroupId($examGroupId)->attributes;
- if(!$task){
- $return['msg']='任务不存在';
- exit(json_encode($return));
- }
- $data=array();
- switch ($type){
- case 1:
- $data=explode(',',$task['answer_card_img']);
- break;
- case 2:
- $data=explode(',',$task['paper_img']);
- break;
- case 3:
- $data=explode(',',$task['parse_img']);
- break;
- }
- $return['status']=1;
- $return['msg']='修改成功';
- $return['data']=$data;
- exit(json_encode($return));
- }
- //读取科目列表
- public function actionGetSubjects(){
- $subjects=Yii::app()->params['subjectId'];
- if(isset($subjects[20])){
- unset($subjects[20]);
- }
- $return['status']=1;
- $return['msg']='成功';
- $return['data']=$subjects;
- exit(json_encode($return));
- }
- //发送在线答题卡测试数据
- public function actionSendTestData(){
- $item=array(
- array(
- 'student_id'=>'17536408539753897824',
- 'paper_id'=>'570614822981877760',
- 'class_id'=>'17536408539753896731',
- 'student_card'=>'47649726',
- 'exam_id'=>'570614822926188544',
- 'student_name'=>'黄陈希',
- 'class_name'=>'22'
- ),
- array(
- 'student_id'=>'17536408539753897825',
- 'paper_id'=>'570614822981877760',
- 'class_id'=>'17536408539753896731',
- 'student_card'=>'47649727',
- 'exam_id'=>'570614822926188544',
- 'student_name'=>'雷汝芬',
- 'class_name'=>'22'
- ),
- array(
- 'student_id'=>'17536408539753897826',
- 'paper_id'=>'570614822981877760',
- 'class_id'=>'17536408539753896731',
- 'student_card'=>'47649728',
- 'exam_id'=>'570614822926188544',
- 'student_name'=>'黎政丰',
- 'class_name'=>'22'
- ),
- );
- $arr=array(
- 'schoolId'=>476,
- 'examGroupId'=>'570614821953171456',
- 'savedInfoUrl'=>'http://zxhx.cn-bj.ufileos.com/zsyas2%2Fcardonline%2F476%2F2020%2F04%2F28%2F570614821953171456.zip?r=303',
- 'students'=>$item,
- 'qrcode'=>1,
- 'semesterId'=>'17535877358591649378'
- );
- $key='zsyas2-online-card-notify';
- $return=sendDataToKafka($key,$arr);
- if($return){
- exit('发送成功');
- }else{
- exit('发送失败');
- }
- }
- }
|