ATask.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /**
  3. * @author: CeeFee
  4. * @description: 考试
  5. */
  6. class ATask extends BusinessActiveRecord {
  7. public static function model($className = __CLASS__){
  8. return parent::model($className);
  9. }
  10. public function tableName(){
  11. return "assist_task";
  12. }
  13. public function primaryKey(){
  14. return array('exam_group_id');
  15. }
  16. //读取任务详情
  17. public function getTaskByExamGroupId($examGroupId){
  18. $criteria = new CDbCriteria();
  19. $criteria->select = '*';
  20. $criteria->addCondition('exam_group_id=:id');
  21. $criteria->params[':id'] = $examGroupId;
  22. return $this->find($criteria);
  23. }
  24. //更新任务
  25. public function updateTask($examGroupId,$arr){
  26. return $this->updateAll($arr,'exam_group_id=:eid',array(':eid'=>$examGroupId));
  27. }
  28. public function getList($where,$param,$page,$pageLimit){
  29. $sql="select * from assist_task ";
  30. if($where){
  31. $sql.=' where '.implode(' and ',$where);
  32. }
  33. $offset=($page-1)*$pageLimit;
  34. $sql.=" order by create_time desc ";
  35. $sql.=" limit {$offset},{$pageLimit}";
  36. $data=$this->getDbConnection()->createCommand($sql,$param)->queryAll();
  37. return $data;
  38. }
  39. //手动分配
  40. public function apply($examGroupId,$userId){
  41. if(!$examGroupId || !$userId) return false;
  42. $transaction = $this->getDbConnection()->beginTransaction();
  43. try {
  44. $ExamInfo=$this->getDbConnection()->createCommand("select operator,answer_sheet_task,paper_task,parse_task from assist_task where exam_group_id='".$examGroupId."'")->queryRow();
  45. if(!$ExamInfo ) return false;
  46. $updateTask=array();
  47. $time=time();
  48. if($ExamInfo['answer_sheet_task']==1){
  49. $updateTask[]=" `answer_sheet_task`=2 ";
  50. $updateTask[]=" `ast_update_time`= {$time}";
  51. $updateTask[]=" `ast_apply_time`= {$time}";
  52. }
  53. if($ExamInfo['paper_task']==1){
  54. $updateTask[]=" `paper_task`=2 ";
  55. $updateTask[]=" `ppt_update_time`= {$time}";
  56. $updateTask[]=" `ppt_apply_time`= {$time}";
  57. }
  58. if($ExamInfo['parse_task']==1){
  59. $updateTask[]=" `parse_task`=2 ";
  60. $updateTask[]=" `pat_update_time`= {$time}";
  61. $updateTask[]=" `pat_apply_time`= {$time}";
  62. }
  63. $updateTask[]=" `update_time`= {$time}";
  64. $updateTask[]=" `operator`='".$userId."'";
  65. $this->getDbConnection()->createCommand("update assist_task set ".implode(",",$updateTask)." where exam_group_id='".$examGroupId."'")->execute();
  66. $transaction->commit();
  67. return true;
  68. } catch (\Exception $e) {
  69. $transaction->rollBack();
  70. debug($e);
  71. return false;
  72. }
  73. }
  74. //自动分配
  75. public function autoApply($userId){
  76. if(!$userId) return false;
  77. $transaction = $this->getDbConnection()->beginTransaction();
  78. try {
  79. $ExamInfo=$this->getDbConnection()->createCommand("select exam_group_id,answer_sheet_task,paper_task,parse_task from assist_task where operator=0 and (answer_sheet_task=1 or paper_task=1 or parse_task=1) order by create_time asc limit 1")->queryRow();
  80. if(!$ExamInfo ) return false;
  81. $updateTask=array();
  82. $time=time();
  83. if($ExamInfo['answer_sheet_task']==1){
  84. $updateTask[]=" `answer_sheet_task`=2 ";
  85. $updateTask[]=" `ast_update_time`= {$time}";
  86. $updateTask[]=" `ast_apply_time`= {$time}";
  87. }
  88. if($ExamInfo['paper_task']==1){
  89. $updateTask[]=" `paper_task`=2 ";
  90. $updateTask[]=" `ppt_update_time`= {$time}";
  91. $updateTask[]=" `ppt_apply_time`= {$time}";
  92. }
  93. if($ExamInfo['parse_task']==1){
  94. $updateTask[]=" `parse_task`=2 ";
  95. $updateTask[]=" `pat_update_time`= {$time}";
  96. $updateTask[]=" `pat_apply_time`= {$time}";
  97. }
  98. $updateTask[]=" `update_time`= {$time}";
  99. $updateTask[]=" `operator`='".$userId."'";
  100. $this->getDbConnection()->createCommand("update assist_task set ".implode(",",$updateTask)." where exam_group_id='".$ExamInfo['exam_group_id']."'")->execute();
  101. $transaction->commit();
  102. return true;
  103. } catch (\Exception $e) {
  104. $transaction->rollBack();
  105. return false;
  106. } catch (\Throwable $e) {
  107. $transaction->rollBack();
  108. return false;
  109. }
  110. }
  111. public function countTask($where=array()){
  112. $sql="select count(*) as count from assist_task ";
  113. if($where){
  114. $sql.=" where ".implode(' and ',$where);
  115. }
  116. $data=$this->getDbConnection()->createCommand($sql)->queryRow();
  117. if($data){
  118. return $data['count'];
  119. }
  120. }
  121. public function getHandleTask($uid){
  122. if(!$uid) return 0;
  123. $sql="select count(*) as count from assist_task where (answer_sheet_task=2 or paper_task=2 or parse_task=2) and operator='".$uid."'";
  124. $data=$this->getDbConnection()->createCommand($sql)->queryRow();
  125. if($data){
  126. return $data['count'];
  127. }
  128. }
  129. public function getGroupServer($tableName){
  130. $sql="select * from `".$tableName."` ";
  131. $data=$this->getDbConnection()->createCommand($sql)->queryAll();
  132. return $data;
  133. }
  134. }