ProductdownteacherController.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2021/5/31 0031
  6. * Time: 15:59
  7. */
  8. class ProductdownteacherController extends Controller
  9. {
  10. /**
  11. * 下载假期报告(教师版)
  12. */
  13. public function actionGetTeacherHolidayFile()
  14. {
  15. $reportId = (string)Req::get("reportId");
  16. $reportId = trim(trim($reportId),",");
  17. $params = array();
  18. if (!$reportId ) {
  19. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  20. exit();
  21. }
  22. //获取组ID
  23. $sql = "select school_group_id,semester_id from holiday_teacher_report_setting where report_id in ({$reportId})";
  24. $report_setting_data = $this->sConn->createCommand($sql)->queryRow();
  25. if (!$report_setting_data) {
  26. echo json_encode(array("success" => 0, "message" => "设置信息错误"));
  27. exit();
  28. } else {
  29. $school_group_id = $report_setting_data['school_group_id'];
  30. }
  31. if (isset($school_group_id) && $school_group_id) {
  32. $apiUrl = isset(Yii::app()->params["improve_url"][$school_group_id]) ? Yii::app()->params["improve_url"][$school_group_id] : null;
  33. } else {
  34. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  35. }
  36. //*****获取生成的老师**//
  37. $sql = "select teacher_id,report_pdf_path from holiday_report_teacher where report_id in ({$reportId}) and is_report_pdf = 1";
  38. $rs = $this->getDbConnection()->createCommand($sql)->queryRow();
  39. if (!$rs) {
  40. echo json_encode(array("success" => 0, "message" => "无生成的pdf"));
  41. exit();
  42. }
  43. if (!$apiUrl) {
  44. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  45. exit();
  46. }
  47. $params['schoolId'] = $this->schoolId;
  48. $params['type'] = 1;
  49. $params['reportId'] = explode(",", $reportId);
  50. $rs = Curl::post($apiUrl . "/rest/download_teacher_pdf/index", $params);
  51. if (!($rs = json_decode($rs))) {
  52. $rs = array("success" => 0, "message" => "请求接口失败");
  53. } else {
  54. //更新下载时间
  55. $this->updateTeacherHrpDownStatus($reportId);
  56. }
  57. if (isset($school_group_id) && $school_group_id && isset($rs->downloadPath)) {
  58. if (YII_ENV == 'pro' || YII_ENV == 'production') {
  59. $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/', 'http://zstatic' . $school_group_id, $rs->downloadPath);
  60. }
  61. }
  62. echo json_encode($rs);
  63. exit;
  64. }
  65. /**
  66. * 更新教师版假期报告下载状态
  67. * @param $reportId
  68. */
  69. private function updateTeacherHrpDownStatus( $reportId){
  70. $time = time();
  71. $sql = "update holiday_report_teacher set is_report_download = 1,report_download_time={$time} where report_id in ({$reportId}) and report_download_time = 0";
  72. $this->sConn->createCommand($sql)->execute();
  73. }
  74. }