AScanTask.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * @author: CeeFee
  4. * @description: 考试
  5. */
  6. class AScanTask extends BusinessActiveRecord {
  7. public static function model($className = __CLASS__){
  8. return parent::model($className);
  9. }
  10. public function tableName(){
  11. return "assist_scan_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_scan_task ";
  30. if($where){
  31. $sql.=' where '.implode(' and ',$where);
  32. }
  33. $offset=($page-1)*$pageLimit;
  34. $sql.=" order by resend_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,scan_task from assist_scan_task where exam_group_id='".$examGroupId."'")->queryRow();
  45. if(!$ExamInfo ) return false;
  46. $updateTask=array();
  47. $time=time();
  48. if($ExamInfo['scan_task']==1){
  49. $updateTask[]=" `scan_task`=2 ";
  50. $updateTask[]=" `scan_task_apply_time`= {$time}";
  51. $updateTask[]=" `scan_task_update_time`= {$time}";
  52. }
  53. $updateTask[]=" `update_time`= {$time}";
  54. $updateTask[]=" `operator`='".$userId."'";
  55. $this->getDbConnection()->createCommand("update assist_scan_task set ".implode(",",$updateTask)." where exam_group_id='".$examGroupId."'")->execute();
  56. $transaction->commit();
  57. return true;
  58. } catch (\Exception $e) {
  59. $transaction->rollBack();
  60. debug($e);
  61. return false;
  62. }
  63. }
  64. //自动分配
  65. public function autoApply($userId){
  66. if(!$userId) return false;
  67. $transaction = $this->getDbConnection()->beginTransaction();
  68. try {
  69. $ExamInfo=$this->getDbConnection()->createCommand("select exam_group_id,scan_task from assist_scan_task where operator=0 and scan_task<>4 order by create_time asc limit 1")->queryRow();
  70. if(!$ExamInfo ) return false;
  71. $updateTask=array();
  72. $time=time();
  73. if($ExamInfo['scan_task']==1){
  74. $updateTask[]=" `scan_task`=2 ";
  75. $updateTask[]=" `scan_task_apply_time`= {$time}";
  76. $updateTask[]=" `scan_task_update_time`= {$time}";
  77. }
  78. $updateTask[]=" `update_time`= {$time}";
  79. $updateTask[]=" `operator`='".$userId."'";
  80. $this->getDbConnection()->createCommand("update assist_scan_task set ".implode(",",$updateTask)." where exam_group_id='".$ExamInfo['exam_group_id']."'")->execute();
  81. $transaction->commit();
  82. return true;
  83. } catch (\Exception $e) {
  84. $transaction->rollBack();
  85. return false;
  86. } catch (\Throwable $e) {
  87. $transaction->rollBack();
  88. return false;
  89. }
  90. }
  91. public function countTask($where=array()){
  92. $sql="select count(*) as count from assist_scan_task ";
  93. if($where){
  94. $sql.=" where ".implode(' and ',$where);
  95. }
  96. $data=$this->getDbConnection()->createCommand($sql)->queryRow();
  97. if($data){
  98. return $data['count'];
  99. }
  100. }
  101. public function getHandleTask($uid){
  102. if(!$uid) return 0;
  103. $sql="select count(*) as count from assist_scan_task where scan_task=2 and operator='".$uid."'";
  104. $data=$this->getDbConnection()->createCommand($sql)->queryRow();
  105. if($data){
  106. return $data['count'];
  107. }
  108. }
  109. }