ProductProcessTime.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2022/8/2 0002
  6. * Time: 10:14
  7. */
  8. //产品生成流程时间记录
  9. class ProductProcessTime extends MyActiveRecord{
  10. public static function model($className = __CLASS__){
  11. return parent::model($className);
  12. }
  13. public function tableName(){
  14. return 'product_process_time';
  15. }
  16. public function updateDownloadTime($studentIds,$type,$examId){
  17. if(!$studentIds || !$type || !$examId){
  18. return array();
  19. }
  20. //查询所有已经生成PDF的学生
  21. $time = time();
  22. $sql = "select * from product_process_time where exam_id = {$examId}";
  23. $info = $this->getCommandBuilder()->createSqlCommand($sql)->queryAll();
  24. //判断该学生是否第一次下载 否更新download_last_time 是更新download_first_time
  25. if($info){
  26. $firstDownloadStudents = $lastDownloadStudents = array();
  27. foreach($info as $val){
  28. if(!$studentIds || ($studentIds && in_array($val['student_id'], $studentIds))){
  29. if(!$val['download_first_time']){
  30. $firstDownloadStudents[] = $val['student_id'];
  31. }else{
  32. $lastDownloadStudents[] = $val['student_id'];
  33. }
  34. }
  35. }
  36. if($firstDownloadStudents) {
  37. $firstDownloadStudents = implode(',', $firstDownloadStudents);
  38. $sql = "update product_process_time set download_first_time={$time},download_last_time={$time} where exam_id = {$examId} and product_type = {$type} and student_id in ({$firstDownloadStudents})";
  39. $this->getCommandBuilder()->createSqlCommand($sql)->execute();
  40. }
  41. if($lastDownloadStudents){
  42. $lastDownloadStudents = implode(',', $lastDownloadStudents);
  43. $sql = "update product_process_time set download_last_time={$time} where exam_id = {$examId} and product_type = {$type} and student_id in ({$lastDownloadStudents})";
  44. $this->getCommandBuilder()->createSqlCommand($sql)->execute();
  45. }
  46. }
  47. }
  48. }