AssistTaskController.php 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  1. <?php
  2. class AssistTaskController extends AssistController
  3. {
  4. //素材切割任务总台
  5. public function actionIndex()
  6. {
  7. $AnswerTask = (int)Req::get('answer_sheet_task');
  8. $PaperTask = (int)Req::get('paper_task');
  9. $ParseTask = (int)Req::get('parse_task');
  10. $searchName = trim(Req::get('search_name'));
  11. $subjectId = trim(Req::get('subject_id'));
  12. $page = (int)Req::get('page');
  13. if(Yii::app()->session['user']['role']!=2){
  14. exit();
  15. }
  16. if(!$page) $page=1;
  17. $where = array();
  18. $param=array();
  19. $where[]=" (answer_sheet_task in(1,2,3) or paper_task in(1,2,3) or parse_task in(1,2,3))";
  20. if($subjectId){
  21. if(in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  22. $where[] = "subject_id in (".implode(',',Yii::app()->params['mathSubjectId']).")";
  23. }else{
  24. $where[] = "subject_id = '{$subjectId}'";
  25. }
  26. }
  27. if ($AnswerTask) {
  28. $where[]= " answer_sheet_task='".$AnswerTask."'";
  29. }
  30. if ($PaperTask) {
  31. $where[]= " paper_task='".$PaperTask."'";
  32. }
  33. if ($ParseTask) {
  34. $where[]= " parse_task='".$ParseTask."'";
  35. }
  36. if ($searchName) {
  37. $where[]= " (exam_name like '%".$searchName."%' or school_name like '%".$searchName."%' or coach_name like'%".$searchName."%' )";
  38. $param[':searchName']='%'.$searchName.'%';
  39. }
  40. $ATask=new ATask();
  41. // 任务列表
  42. $totalCount = $ATask->countTask($where);
  43. $pageLimit=10;
  44. $pages['page']=$page;
  45. $pages['totalPage']=ceil($totalCount/$pageLimit);
  46. $pages['total']=$totalCount;
  47. //$pages = new Pagination(['totalCount' => $totalCount, 'pageSize' => 10]);
  48. //$dataList=ATask::model()->find(implode(' and ',$where),$param)->offset($pages->offset)->limit($pages->limit)->asArray()->all();
  49. $dataList=$ATask->getList($where,$param,$page,$pageLimit);
  50. if($dataList){
  51. foreach ($dataList as $key => $val){
  52. if($val['operator']){
  53. $user=AssistUser::model()->find('user_id=:uid',array(':uid'=>$val['operator']));
  54. $dataList[$key]['operator']=$user['real_name'].'-'.$user['user_name'];
  55. }else{
  56. $dataList[$key]['operator']='--';
  57. }
  58. $taskTextTips=array();
  59. if($val['answer_sheet_task'] && $val['answer_sheet_task']!=4){
  60. $taskTextTips[]='答题卡:'.date('Y-m-d H:i:s',$val['ast_update_time']);
  61. }
  62. if($val['paper_task'] && $val['paper_task']!=4){
  63. $taskTextTips[]='试卷:'.date('Y-m-d H:i:s',$val['ppt_update_time']);
  64. }
  65. if($val['parse_task'] && $val['parse_task']!=4){
  66. $taskTextTips[]='答案解析:'.date('Y-m-d H:i:s',$val['pat_update_time']);
  67. }
  68. if($taskTextTips){
  69. $dataList[$key]['tips']=implode('<br>',$taskTextTips);
  70. }
  71. //读取省市区
  72. $schoolInfo=BusinessSchool::model()->find('school_id=:sid',array(':sid'=>$val['school_id']));
  73. if($schoolInfo){
  74. $province=BusinessRegion::model()->findByPk($schoolInfo->province_id);
  75. $city=BusinessRegion::model()->findByPk($schoolInfo->city_id);
  76. $area=BusinessRegion::model()->findByPk($schoolInfo->area_id);
  77. $dataList[$key]['address']=$province->region_name.'-'.$city->region_name.'-'.$area->region_name;
  78. }
  79. }
  80. }
  81. //查询用户
  82. // $users=AssistUser::model()->find('status=1 and role=1');
  83. $AUser=new AssistUser();
  84. $users=$AUser->getAllUserByLimit("cutting_limit=1");
  85. if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){
  86. $subjects=Yii::app()->params['subjectId'];
  87. unset($subjects[3]);
  88. unset($subjects[51]);
  89. if(isset($subjects[20])) unset($subjects[20]);
  90. }
  91. $data=array(
  92. 'pages' => $pages,
  93. 'dataList' => $dataList,
  94. 'condition' => array(
  95. 'answer_sheet_task' => $AnswerTask,
  96. 'paper_task' => $PaperTask,
  97. 'parse_task' => $ParseTask,
  98. 'search_name' => $searchName,
  99. 'subject_id'=>$subjectId
  100. ),
  101. 'users'=>$users,
  102. 'subjects'=>$subjects,
  103. 'subjectId'=>$subjectId
  104. );
  105. return $this->render('cooperate', $data);
  106. }
  107. //扫描任务总台
  108. public function actionScanTask()
  109. {
  110. $scanTask = (int)Req::get('scan_task');
  111. $searchName = trim(Req::get('search_name'));
  112. $subjectId = trim(Req::get('subject_id'));
  113. $page = (int)Req::get('page');
  114. if(Yii::app()->session['user']['role']!=2){
  115. exit();
  116. }
  117. if(!$page) $page=1;
  118. $where = array();
  119. $param=array();
  120. $where[]=" scan_task in(1,2,3)";
  121. if($subjectId){
  122. if(in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  123. $where[] = "subject_id in (".implode(',',Yii::app()->params['mathSubjectId']).")";
  124. }else{
  125. $where[] = "subject_id = '{$subjectId}'";
  126. }
  127. }
  128. if ($scanTask) {
  129. $where[]= " scan_task='".$scanTask."'";
  130. }
  131. if ($searchName) {
  132. $where[]= " (exam_name like '%".$searchName."%' or school_name like '%".$searchName."%' or coach_name like'%".$searchName."%' )";
  133. $param[':searchName']='%'.$searchName.'%';
  134. }
  135. $ATask=new AScanTask();
  136. // 任务列表
  137. $totalCount = $ATask->countTask($where);
  138. $pageLimit=10;
  139. $pages['page']=$page;
  140. $pages['totalPage']=ceil($totalCount/$pageLimit);
  141. $pages['total']=$totalCount;
  142. $dataList=$ATask->getList($where,$param,$page,$pageLimit);
  143. if($dataList){
  144. $AStudentScanTask=new AStudentScanTask();
  145. foreach ($dataList as $key => $val){
  146. if($val['operator']){
  147. $user=AssistUser::model()->find('user_id=:uid',array(':uid'=>$val['operator']));
  148. $dataList[$key]['operator']=$user['real_name'].'-'.$user['user_name'];
  149. }else{
  150. $dataList[$key]['operator']='--';
  151. }
  152. //查询任务类型
  153. $dataList[$key]['taskType']=$AStudentScanTask->getTaskTypesByExamGroupId($val['exam_group_id']);
  154. //查询任务数量
  155. $dataList[$key]['taskCount']=$AStudentScanTask->getTaskCount($val['exam_group_id']);
  156. //读取省市区
  157. $schoolInfo=BusinessSchool::model()->find('school_id=:sid',array(':sid'=>$val['school_id']));
  158. if($schoolInfo){
  159. $province=BusinessRegion::model()->findByPk($schoolInfo->province_id);
  160. $city=BusinessRegion::model()->findByPk($schoolInfo->city_id);
  161. $area=BusinessRegion::model()->findByPk($schoolInfo->area_id);
  162. $dataList[$key]['address']=$province->region_name.'-'.$city->region_name.'-'.$area->region_name;
  163. }
  164. }
  165. }
  166. //查询用户
  167. // $users=AssistUser::model()->find('status=1 and role=1');
  168. $AUser=new AssistUser();
  169. $users=$AUser->getAllUserByLimit("scan_limit=1");
  170. if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){
  171. $subjects=Yii::app()->params['subjectId'];
  172. unset($subjects[3]);
  173. unset($subjects[51]);
  174. if(isset($subjects[20])) unset($subjects[20]);
  175. }
  176. $data=array(
  177. 'pages' => $pages,
  178. 'dataList' => $dataList,
  179. 'condition' => array(
  180. 'scan_task' => $scanTask,
  181. 'search_name' => $searchName,
  182. 'subject_id'=>$subjectId
  183. ),
  184. 'users'=>$users,
  185. 'subjects'=>$subjects,
  186. 'subjectId'=>$subjectId,
  187. );
  188. return $this->render('cooperate_scan', $data);
  189. }
  190. //我的任务
  191. public function actionMyTask(){
  192. $AnswerTask = (int)Req::get('answer_sheet_task');
  193. $PaperTask = (int)Req::get('paper_task');
  194. $ParseTask = (int)Req::get('parse_task');
  195. $searchName = trim(Req::get('search_name'));
  196. $subjectId = trim(Req::get('subject_id'));
  197. $page = (int)Req::get('page');
  198. if(!$page) $page=1;
  199. if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){
  200. $subjects=Yii::app()->params['subjectId'];
  201. unset($subjects[3]);
  202. unset($subjects[51]);
  203. if(isset($subjects[20])) unset($subjects[20]);
  204. }
  205. // if(!isset(Yii::app()->session['user']['cutting_limit']) || Yii::app()->session['user']['cutting_limit']==0){
  206. //
  207. // return $this->render('mytask', array(
  208. // 'pages' => array(),
  209. // 'dataList' => array(),
  210. // 'condition' => array(
  211. // 'answer_sheet_task' => 0,
  212. // 'paper_task' => 0,
  213. // 'parse_task' => 0,
  214. // 'search_name' => '',
  215. // 'subject_id'=>$subjectId
  216. // ),
  217. // 'subjects'=>$subjects,
  218. // 'subjectId'=>$subjectId,
  219. // 'isNoLimit'=>1
  220. // ));
  221. // }
  222. $where[]='operator='.Yii::app()->session['user']['user_id'];
  223. $param[':userid']=Yii::app()->session['user']['user_id'];
  224. if($subjectId){
  225. if(in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  226. $where[] = "subject_id in (".implode(',',Yii::app()->params['mathSubjectId']).")";
  227. }else{
  228. $where[] = "subject_id = '{$subjectId}'";
  229. }
  230. }
  231. if ($AnswerTask) {
  232. $where[]= " answer_sheet_task='".$AnswerTask."'";
  233. }
  234. if ($PaperTask) {
  235. $where[]= " paper_task='".$PaperTask."'";
  236. }
  237. if ($ParseTask) {
  238. $where[]= " parse_task='".$ParseTask."'";
  239. }
  240. if ($searchName) {
  241. $where[]= " (exam_name like '%".$searchName."%' or school_name like '%".$searchName."%' or coach_name like'%".$searchName."%' )";
  242. }
  243. // 任务列表
  244. $taskModel=new ATask();
  245. $totalCount=$taskModel->countTask($where);
  246. //判断受理中任务
  247. $handleCount=$taskModel->getHandleTask(Yii::app()->session['user']['user_id']);
  248. if($handleCount==0 && Yii::app()->session['user']['role']==1 && Yii::app()->session['user']['cutting_limit']==1){
  249. //领取任务
  250. $apply=$taskModel->autoApply(Yii::app()->session['user']['user_id']);
  251. if(!$apply){
  252. $totalCount = $taskModel->countTask($where);
  253. }
  254. }
  255. $pageLimit=10;
  256. $pages['page']=$page;
  257. $pages['totalPage']=ceil($totalCount/$pageLimit);
  258. $pages['total']=$totalCount;
  259. $ATask=new ATask();
  260. $dataList=$ATask->getList($where,$param,$page,$pageLimit);
  261. if($dataList){
  262. foreach ($dataList as $key => $val){
  263. $taskTextTips=array();
  264. if($val['answer_sheet_task'] && $val['answer_sheet_task']!=4){
  265. $taskTextTips[]='答题卡:'.date('Y-m-d H:i:s',$val['ast_update_time']);
  266. }
  267. if($val['paper_task'] && $val['paper_task']!=4){
  268. $taskTextTips[]='试卷:'.date('Y-m-d H:i:s',$val['ppt_update_time']);
  269. }
  270. if($val['parse_task'] && $val['parse_task']!=4){
  271. $taskTextTips[]='答案解析:'.date('Y-m-d H:i:s',$val['pat_update_time']);
  272. }
  273. if($taskTextTips){
  274. $dataList[$key]['tips']=implode('<br>',$taskTextTips);
  275. }else{
  276. $dataList[$key]['tips']='';
  277. }
  278. //读取省市区
  279. $schoolInfo=BusinessSchool::model()->find('school_id=:sid',array(':sid'=>$val['school_id']));
  280. if($schoolInfo){
  281. $province=BusinessRegion::model()->findByPk($schoolInfo->province_id);
  282. $city=BusinessRegion::model()->findByPk($schoolInfo->city_id);
  283. $area=BusinessRegion::model()->findByPk($schoolInfo->area_id);
  284. $dataList[$key]['address']=$province->region_name.'-'.$city->region_name.'-'.$area->region_name;
  285. }
  286. }
  287. }
  288. return $this->render('mytask', array(
  289. 'pages' => $pages,
  290. 'dataList' => $dataList,
  291. 'condition' => array(
  292. 'answer_sheet_task' => $AnswerTask,
  293. 'paper_task' => $PaperTask,
  294. 'parse_task' => $ParseTask,
  295. 'search_name' => $searchName,
  296. 'subject_id'=>$subjectId
  297. ),
  298. 'subjects'=>$subjects,
  299. 'subjectId'=>$subjectId
  300. ));
  301. }
  302. //我的扫描任务
  303. public function actionMyScanTask(){
  304. $scanTask = (int)Req::get('scan_task');
  305. $searchName = trim(Req::get('search_name'));
  306. $subjectId = trim(Req::get('subject_id'));
  307. $page = (int)Req::get('page');
  308. if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){
  309. $subjects=Yii::app()->params['subjectId'];
  310. unset($subjects[3]);
  311. unset($subjects[51]);
  312. if(isset($subjects[20])) unset($subjects[20]);
  313. }
  314. // if(!isset(Yii::app()->session['user']['scan_limit']) || Yii::app()->session['user']['scan_limit']==0){
  315. //
  316. // return $this->render('my_scan_task', array(
  317. // 'pages' => array(),
  318. // 'dataList' => array(),
  319. // 'condition' => array(
  320. // 'scan_task' => 0,
  321. // 'search_name' => '',
  322. // 'subject_id'=>$subjectId
  323. // ),
  324. // 'subjects'=>$subjects,
  325. // 'subjectId'=>$subjectId,
  326. // 'isNoLimit'=>1
  327. // ));
  328. // }
  329. if(!$page) $page=1;
  330. $where = array();
  331. $param=array();
  332. $where[]=" scan_task in(1,2,3)";
  333. $where[]='operator='.Yii::app()->session['user']['user_id'];
  334. $param[':userid']=Yii::app()->session['user']['user_id'];
  335. if($subjectId){
  336. if(in_array($subjectId,Yii::app()->params['mathSubjectId'])){
  337. $where[] = "subject_id in (".implode(',',Yii::app()->params['mathSubjectId']).")";
  338. }else{
  339. $where[] = "subject_id = '{$subjectId}'";
  340. }
  341. }
  342. if ($scanTask) {
  343. $where[]= " scan_task='".$scanTask."'";
  344. }
  345. if ($searchName) {
  346. $where[]= " (exam_name like '%".$searchName."%' or school_name like '%".$searchName."%' or coach_name like'%".$searchName."%' )";
  347. $param[':searchName']='%'.$searchName.'%';
  348. }
  349. $ATask=new AScanTask();
  350. // 任务列表
  351. $totalCount = $ATask->countTask($where);
  352. //判断受理中任务
  353. $handleCount=$ATask->getHandleTask(Yii::app()->session['user']['user_id']);
  354. if($handleCount==0 && Yii::app()->session['user']['role']==1 && Yii::app()->session['user']['scan_limit']==1){
  355. //领取任务
  356. $apply=$ATask->autoApply(Yii::app()->session['user']['user_id']);
  357. if(!$apply){
  358. $totalCount = $ATask->countTask($where);
  359. }
  360. }
  361. $pageLimit=10;
  362. $pages['page']=$page;
  363. $pages['totalPage']=ceil($totalCount/$pageLimit);
  364. $pages['total']=$totalCount;
  365. $dataList=$ATask->getList($where,$param,$page,$pageLimit);
  366. if($dataList){
  367. $AStudentScanTask=new AStudentScanTask();
  368. foreach ($dataList as $key => $val){
  369. if($val['operator']){
  370. $user=AssistUser::model()->find('user_id=:uid',array(':uid'=>$val['operator']));
  371. $dataList[$key]['operator']=$user['real_name'].'-'.$user['user_name'];
  372. }else{
  373. $dataList[$key]['operator']='--';
  374. }
  375. //查询任务类型
  376. $dataList[$key]['taskType']=$AStudentScanTask->getTaskTypesByExamGroupId($val['exam_group_id']);
  377. //查询任务数量
  378. $dataList[$key]['taskCount']=$AStudentScanTask->getTaskCount($val['exam_group_id']);
  379. //读取省市区
  380. $schoolInfo=BusinessSchool::model()->find('school_id=:sid',array(':sid'=>$val['school_id']));
  381. if($schoolInfo){
  382. $province=BusinessRegion::model()->findByPk($schoolInfo->province_id);
  383. $city=BusinessRegion::model()->findByPk($schoolInfo->city_id);
  384. $area=BusinessRegion::model()->findByPk($schoolInfo->area_id);
  385. $dataList[$key]['address']=$province->region_name.'-'.$city->region_name.'-'.$area->region_name;
  386. }
  387. }
  388. }
  389. //查询用户
  390. // $users=AssistUser::model()->find('status=1 and role=1');
  391. $AUser=new AssistUser();
  392. $users=$AUser->getAllUserByLimit("scan_limit=1");
  393. $data=array(
  394. 'pages' => $pages,
  395. 'dataList' => $dataList,
  396. 'condition' => array(
  397. 'scan_task' => $scanTask,
  398. 'search_name' => $searchName,
  399. 'subject_id'=>$subjectId
  400. ),
  401. 'users'=>$users,
  402. 'subjects'=>$subjects,
  403. 'subjectId'=>$subjectId
  404. );
  405. return $this->render('my_scan_task', $data);
  406. }
  407. //分配操作员
  408. public function actionApply(){
  409. $examGroupId = Req::post('exam_group_id');
  410. $userId = (int)Req::post('user_id');
  411. $return['status']=0;
  412. //分配
  413. $taskModel=new ATask();
  414. if($taskModel->apply($examGroupId,$userId)){
  415. $return['status']=1;
  416. exit(json_encode($return));
  417. }else{
  418. exit(json_encode($return));
  419. }
  420. }
  421. //任务详情
  422. public function actionDetail(){
  423. $examGroupId = Req::get('exam_group_id');
  424. $taskModel=new ATask();
  425. $task=$taskModel->getTaskByExamGroupId($examGroupId)->attributes;
  426. // $task= Task::find()->where('exam_group_id=:eid',array(':eid'=>$examGroupId))->asArray()->one();
  427. if(!$task){
  428. Yii::app()->jump->error('任务数据异常!');
  429. }
  430. if($task['operator']){
  431. $user=AssistUser::model()->findByPk($task['operator']);
  432. $task['user']=$user->real_name;
  433. }else{
  434. $task['user']='--';
  435. }
  436. //答题卡任务耗时
  437. if($task['ast_apply_time']){
  438. if($task['answer_sheet_task']>2){
  439. if($task['ast_update_time'] && ($task['ast_update_time']-$task['ast_apply_time'])>0){
  440. $task['AstConsuming']=$this->consuming($task['ast_update_time'],$task['ast_apply_time']);
  441. }else{
  442. $task['AstConsuming']='--';
  443. }
  444. }elseif($task['answer_sheet_task']==2){
  445. if($task['ast_apply_time'] && (time()-$task['ast_apply_time'])>0){
  446. $task['AstConsuming']=$this->consuming(time(),$task['ast_apply_time']);
  447. }else{
  448. $task['AstConsuming']='--';
  449. }
  450. }
  451. }else{
  452. $task['AstConsuming']='--';
  453. }
  454. //试卷任务耗时
  455. if($task['ppt_apply_time']){
  456. if($task['paper_task']>2){
  457. if($task['ppt_update_time'] && ($task['ppt_update_time']-$task['ppt_apply_time'])>0){
  458. $task['PptConsuming']=$this->consuming($task['ppt_update_time'],$task['ppt_apply_time']);
  459. }else{
  460. $task['PptConsuming']='';
  461. }
  462. }elseif($task['paper_task']==2){
  463. if($task['ppt_apply_time'] && (time()-$task['ppt_apply_time'])>0){
  464. $task['PptConsuming']=$this->consuming(time(),$task['ppt_apply_time']);
  465. }else{
  466. $task['PptConsuming']='';
  467. }
  468. }
  469. }else{
  470. $task['PptConsuming']='';
  471. }
  472. //答案解析任务耗时
  473. if($task['pat_apply_time']){
  474. if($task['parse_task']>2){
  475. if($task['pat_update_time'] && ($task['pat_update_time']-$task['pat_apply_time'])>0){
  476. $task['PatConsuming']=$this->consuming($task['pat_update_time'],$task['pat_apply_time']);
  477. }else{
  478. $task['PatConsuming']='';
  479. }
  480. }elseif($task['parse_task']==2){
  481. if($task['pat_apply_time'] && (time()-$task['pat_apply_time'])>0){
  482. $task['PatConsuming']=$this->consuming(time(),$task['pat_apply_time']);
  483. }else{
  484. $task['PatConsuming']='';
  485. }
  486. }
  487. }else{
  488. $task['PatConsuming']='';
  489. }
  490. $CoachModel=new ThirdAnswerSheet();
  491. $tplData=$CoachModel->getExamTplData($task['dsn'],$task['database_user'],$task['database_password'],$examGroupId);
  492. if($tplData){
  493. $tplData=json_decode($tplData,true);
  494. if(isset($tplData['new_items'])){
  495. $items=array();
  496. foreach ($tplData['new_items'] as $item){
  497. if(isset($item['alias'])){
  498. $items[$item['topic_type']]['no'][]=$item['alias'];
  499. }else{
  500. $items[$item['topic_type']]['no'][]=$item['id'];
  501. }
  502. }
  503. $tplData['items']=$items;
  504. }
  505. $task['paper_topic']=$tplData;
  506. }
  507. //读取省市区
  508. $schoolInfo=BusinessSchool::model()->find('school_id=:sid',array(':sid'=>$task['school_id']));
  509. if($schoolInfo){
  510. $province=BusinessRegion::model()->findByPk($schoolInfo->province_id);
  511. $city=BusinessRegion::model()->findByPk($schoolInfo->city_id);
  512. $area=BusinessRegion::model()->findByPk($schoolInfo->area_id);
  513. $task['address']=$province->region_name.'-'.$city->region_name.'-'.$area->region_name;
  514. }
  515. $data['our']=0;
  516. //是否是自己的任务
  517. if(Yii::app()->session['user']['user_id']==$task['operator']){
  518. $data['our']=1;
  519. //读取模板
  520. $ThirdAnswerTemplate=new ThirdAnswerSheet();
  521. $template=$ThirdAnswerTemplate->getTemplate($task['dsn'],$task['database_user'],$task['database_password'],$examGroupId);
  522. if($template){
  523. $task['paper_template']=$template['paper_template'];
  524. $task['parse_template']=$template['parse_template'];
  525. }
  526. }
  527. $data['task']=$task;
  528. return $this->render('detail',$data);
  529. }
  530. //扫描处理任务详情
  531. public function actionScanTaskDetail(){
  532. $examGroupId = Req::get('exam_group_id');
  533. $taskModel=new AScanTask();
  534. $task=$taskModel->getTaskByExamGroupId($examGroupId)->attributes;
  535. // $task= Task::find()->where('exam_group_id=:eid',array(':eid'=>$examGroupId))->asArray()->one();
  536. $pushStudentData=array(); //待处理学生数据
  537. if(!$task){
  538. Yii::app()->jump->error('任务数据异常!');
  539. }
  540. if($task['operator']){
  541. $user=AssistUser::model()->findByPk($task['operator']);
  542. $task['user']=$user->real_name;
  543. }else{
  544. $task['user']='--';
  545. }
  546. //答题卡任务耗时
  547. if($task['scan_task_apply_time']){
  548. if($task['scan_task']>2){
  549. if($task['scan_task_update_time'] && ($task['scan_task_update_time']-$task['scan_task_apply_time'])>0){
  550. $task['AstConsuming']=$this->consuming($task['scan_task_update_time'],$task['scan_task_apply_time']);
  551. }else{
  552. $task['AstConsuming']='--';
  553. }
  554. }elseif($task['scan_task']==2){
  555. if($task['scan_task_apply_time'] && (time()-$task['scan_task_apply_time'])>0){
  556. $task['AstConsuming']=$this->consuming(time(),$task['scan_task_apply_time']);
  557. }else{
  558. $task['AstConsuming']='--';
  559. }
  560. }
  561. }else{
  562. $task['AstConsuming']='--';
  563. }
  564. //读取扫描数量
  565. $AssistSchoolManager=new AssistSchoolManager($task['school_id']);
  566. $count=$AssistSchoolManager->getStudentCountByExamGroupId($task['exam_group_id'],1);
  567. $task['count']=$count;
  568. if($count['surplus']>0){
  569. //查询待处理数据,准备处理
  570. //$pushStudentData=$AssistSchoolManager->getSurplusDataByExamGroupId($task['exam_group_id']);
  571. }
  572. //读取省市区
  573. $schoolInfo=BusinessSchool::model()->find('school_id=:sid',array(':sid'=>$task['school_id']));
  574. if($schoolInfo){
  575. $province=BusinessRegion::model()->findByPk($schoolInfo->province_id);
  576. $city=BusinessRegion::model()->findByPk($schoolInfo->city_id);
  577. $area=BusinessRegion::model()->findByPk($schoolInfo->area_id);
  578. $task['address']=$province->region_name.'-'.$city->region_name.'-'.$area->region_name;
  579. }
  580. $data['our']=0;
  581. //是否是自己的任务
  582. if(Yii::app()->session['user']['user_id']==$task['operator']){
  583. $data['our']=1;
  584. }
  585. $data['task']=$task;
  586. // $data['pushStudentData']=$pushStudentData;
  587. $AUser=new AssistUser();
  588. $users=$AUser->getAllUserByLimit("scan_limit=1");
  589. $data['users']=$users;
  590. $coachInfo=BusinessDatabase::model()->find('school_id=:id',array(':id'=>$task['school_id']));
  591. $groupServer=$this->getServerGroup();
  592. $data['api_url']=$groupServer[$coachInfo->group_id];
  593. return $this->render('scan_detail',$data);
  594. }
  595. //读取答题卡id
  596. public function actionGetSheet(){
  597. $examGroupId = Req::post('exam_group_id');
  598. $data['status']=0;
  599. $taskModel=new ATask();
  600. $task=$taskModel->getTaskByExamGroupId($examGroupId)->attributes;
  601. if(!$task){
  602. $data['msg']='参数错误2';
  603. exit(json_encode($data));
  604. }
  605. //读取答题卡
  606. $ThirdAnswerTemplate=new ThirdAnswerSheet();
  607. $sheet=$ThirdAnswerTemplate->getAnswerSheet($task['dsn'],$task['database_user'],$task['database_password'],$examGroupId);
  608. exit(json_encode(array('status'=>1,'msg'=>'success','data'=>$sheet)));
  609. }
  610. //分配操作员
  611. public function actionApplyScan(){
  612. $examGroupId = Req::post('exam_group_id');
  613. $userId = (int)Req::post('user_id');
  614. $return['status']=0;
  615. //分配
  616. $taskModel=new AScanTask();
  617. if($taskModel->apply($examGroupId,$userId)){
  618. $return['status']=1;
  619. exit(json_encode($return));
  620. }else{
  621. exit(json_encode($return));
  622. }
  623. }
  624. //读取任务设置情况
  625. public function actionGetDetail(){
  626. $examGroupId = Req::post('exam_group_id');
  627. $data['status']=0;
  628. if(!$examGroupId){
  629. $data['msg']='参数错误1';
  630. exit(json_encode($data));
  631. }
  632. $taskModel=new ATask();
  633. $task=$taskModel->getTaskByExamGroupId($examGroupId)->attributes;
  634. if(!$task){
  635. $data['msg']='参数错误2';
  636. exit(json_encode($data));
  637. }
  638. $CoachModel=new ThirdAnswerSheet();
  639. $return=$CoachModel->getDetail($task['dsn'],$task['database_user'],$task['database_password'],$examGroupId);
  640. if($task['answer_sheet_task']==3 || $task['answer_sheet_task']==4 || $return['answer_card']==0){
  641. $return['answer_card_input_status']=0;
  642. }else{
  643. $return['answer_card_input_status']=1;
  644. }
  645. if($task['paper_task']==3 || $task['paper_task']==4 || $return['paper']==0){
  646. $return['paper_input_status']=0;
  647. }else{
  648. $return['paper_input_status']=1;
  649. }
  650. if($task['parse_task']==3 || $task['parse_task']==4 || $return['parse']==0){
  651. $return['parse_input_status']=0;
  652. }else{
  653. $return['parse_input_status']=1;
  654. }
  655. if($return){
  656. $data['data']=$return;
  657. }
  658. $data['status']=1;
  659. $data['msg']='success';
  660. exit(json_encode($data));
  661. }
  662. //读取扫描异常任务设置情况
  663. public function actionGetScanDetail(){
  664. $examGroupId = Req::post('exam_group_id');
  665. $data['status']=0;
  666. if(!$examGroupId){
  667. $data['msg']='参数错误1';
  668. exit(json_encode($data));
  669. }
  670. $taskModel=new AScanTask();
  671. $task=$taskModel->getTaskByExamGroupId($examGroupId)->attributes;
  672. if(!$task){
  673. $data['msg']='参数错误2';
  674. exit(json_encode($data));
  675. }
  676. if($task['scan_task']==3 || $task['scan_task']==4 ){
  677. $return['scan_task']=0;
  678. }else{
  679. $return['scan_task']=1;
  680. }
  681. //统计处理数量
  682. $AssistSchoolManager=new AssistSchoolManager($task['school_id']);
  683. $return['count']=$AssistSchoolManager->getStudentCountByExamGroupId($task['exam_group_id']);
  684. if($return){
  685. $data['data']=$return;
  686. }
  687. $data['status']=1;
  688. $data['msg']='success';
  689. exit(json_encode($data));
  690. }
  691. //任务完成
  692. public function actionComplete(){
  693. $examGroupId = Req::post('exam_group_id');
  694. $answerCardStatus =Req::post('answer_card');
  695. $paperStatus = Req::post('paper');
  696. $parseStatus = Req::post('parse');
  697. $data['status']=0;
  698. if(!$examGroupId){
  699. $data['msg']='参数错误';
  700. exit(json_encode($data));
  701. }
  702. $taskModel=new ATask();
  703. $task=$taskModel->getTaskByExamGroupId($examGroupId);
  704. if(!$task){
  705. $data['msg']='没找到相关任务';
  706. exit(json_encode($data));
  707. }
  708. $time=time();
  709. if($answerCardStatus==1){
  710. $updateArr['answer_sheet_task']=3;
  711. $updateArr['ast_update_time']=$time;
  712. }
  713. if($paperStatus==1){
  714. $updateArr['paper_task']=3;
  715. $updateArr['ppt_update_time']=$time;
  716. }
  717. if($parseStatus==1){
  718. $updateArr['parse_task']=3;
  719. $updateArr['pat_update_time']=$time;
  720. }
  721. $updateArr['update_time']=$time;
  722. if($taskModel->updateTask($examGroupId,$updateArr)){
  723. //判断受理中任务
  724. $handleCount=$taskModel->getHandleTask(Yii::app()->session['user']['user_id']);
  725. if($handleCount==0 && Yii::app()->session['user']['role']==1){
  726. //领取任务
  727. $taskModel->autoApply(Yii::app()->session['user']['user_id']);
  728. }
  729. $data['status']=1;
  730. $data['msg']='提交成功';
  731. }
  732. exit(json_encode($data));
  733. }
  734. //任务完成
  735. public function actionScanTaskComplete(){
  736. $examGroupId = Req::post('exam_group_id');
  737. $data['status']=0;
  738. if(!$examGroupId){
  739. $data['msg']='参数错误';
  740. exit(json_encode($data));
  741. }
  742. $taskModel=new AScanTask();
  743. $task=$taskModel->getTaskByExamGroupId($examGroupId);
  744. if(!$task){
  745. $data['msg']='没找到相关任务';
  746. exit(json_encode($data));
  747. }
  748. $time=time();
  749. $updateArr['scan_task']=3;
  750. $updateArr['scan_task_update_time']=$time;
  751. $updateArr['update_time']=$time;
  752. if($taskModel->updateTask($examGroupId,$updateArr)){
  753. //判断受理中任务
  754. $handleCount=$taskModel->getHandleTask(Yii::app()->session['user']['user_id']);
  755. if($handleCount==0 && Yii::app()->session['user']['role']==1){
  756. //领取任务
  757. $taskModel->autoApply(Yii::app()->session['user']['user_id']);
  758. }
  759. $data['status']=1;
  760. $data['msg']='提交成功';
  761. }
  762. exit(json_encode($data));
  763. }
  764. //计算耗时
  765. public function consuming($now,$time){
  766. $return='';
  767. $date=floor(($now-$time)/86400);
  768. if($date){
  769. $return.=$date.'天';
  770. }
  771. $hour=floor(($now-$time)%86400/3600);
  772. if($hour){
  773. $return.=$hour.'小时';
  774. }
  775. $minute=floor((($now-$time)%86400)%3600/60);
  776. if($minute){
  777. $return.=$minute.'分种';
  778. }
  779. $second=floor(($now-$time)%86400%3600%60);
  780. if($second){
  781. $return.=$second.'秒';
  782. }
  783. return $return;
  784. }
  785. public function actionDownload()
  786. {
  787. $url = Req::get('url');
  788. $title = Req::get('title');
  789. if (!$url) return false;
  790. $info = get_headers($url, true);
  791. $size = $info['Content-Length'];
  792. header("Content-type:application/octet-stream");
  793. $filename = $url;
  794. if (false !== stripos($url, '?')) {
  795. $filename = substr($url, 0, stripos($url, '?'));
  796. }
  797. if($title){
  798. $origin_name = $title;
  799. }else{
  800. $origin_name = basename($filename);
  801. }
  802. header("Content-Disposition:attachment;filename = " . $origin_name);
  803. header("Accept-ranges:bytes");
  804. header("Accept-length:" . $size);
  805. readfile($url);
  806. exit;
  807. }
  808. public function getServerGroup(){
  809. $taskModel=new ATask();
  810. switch (YII_ENV) {
  811. case 'local':
  812. case 'development':
  813. $improve_url = array();
  814. $static_url = array();
  815. $group_server=$taskModel->getGroupServer('group_server_development');
  816. if ($group_server) {
  817. foreach ($group_server as $v) {
  818. $improve_url[$v['group_id']] = $v['api_url'];
  819. $static_url[$v['group_id']] = $v['static_url'];
  820. }
  821. }
  822. break;
  823. case 'testing':
  824. //报告运行时错误
  825. $improve_url = array();
  826. $static_url = array();
  827. $group_server=$taskModel->getGroupServer('group_server_testing');
  828. if ($group_server) {
  829. foreach ($group_server as $v) {
  830. $improve_url[$v['group_id']] = $v['api_url'];
  831. $static_url[$v['group_id']] = $v['static_url'];
  832. }
  833. }
  834. break;
  835. case 'production':
  836. $improve_url = array();
  837. $static_url = array();
  838. $group_server=$taskModel->getGroupServer('group_server');
  839. if ($group_server) {
  840. foreach ($group_server as $v) {
  841. $improve_url[$v['group_id']] = $v['api_url'];
  842. $static_url[$v['group_id']] = $v['static_url'];
  843. }
  844. }
  845. break;
  846. default:
  847. $improve_url = array();
  848. $static_url = array();
  849. $group_server=$taskModel->getGroupServer('group_server');
  850. if ($group_server) {
  851. foreach ($group_server as $v) {
  852. $improve_url[$v['group_id']] = $v['api_url'];
  853. $static_url[$v['group_id']] = $v['static_url'];
  854. }
  855. }
  856. }
  857. return $improve_url;
  858. }
  859. //查询剩余任务量
  860. public function actionGetSurplus(){
  861. $examGroupId = Req::post('exam_group_id');
  862. $aStudentScanTask=new AStudentScanTask();
  863. $count=$aStudentScanTask->getTaskCount($examGroupId);
  864. if($count['surplus']==0){
  865. $data['status']=0;
  866. $data['msg']='当前已无异常数据';
  867. exit(json_encode($data));
  868. }else{
  869. $data['status']=1;
  870. $data['msg']='';
  871. exit(json_encode($data));
  872. }
  873. }
  874. }