1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2021/5/31 0031
- * Time: 15:59
- */
- class ProductdownteacherController extends Controller
- {
- /**
- * 下载假期报告(教师版)
- */
- public function actionGetTeacherHolidayFile()
- {
- $reportId = (string)Req::get("reportId");
- $reportId = trim(trim($reportId),",");
- $params = array();
- if (!$reportId ) {
- echo json_encode(array("success" => 0, "message" => "缺少参数"));
- exit();
- }
- //获取组ID
- $sql = "select school_group_id,semester_id from holiday_teacher_report_setting where report_id in ({$reportId})";
- $report_setting_data = $this->sConn->createCommand($sql)->queryRow();
- if (!$report_setting_data) {
- echo json_encode(array("success" => 0, "message" => "设置信息错误"));
- exit();
- } else {
- $school_group_id = $report_setting_data['school_group_id'];
- }
- if (isset($school_group_id) && $school_group_id) {
- $apiUrl = isset(Yii::app()->params["improve_url"][$school_group_id]) ? Yii::app()->params["improve_url"][$school_group_id] : null;
- } else {
- $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
- }
- //*****获取生成的老师**//
- $sql = "select teacher_id,report_pdf_path from holiday_report_teacher where report_id in ({$reportId}) and is_report_pdf = 1";
- $rs = $this->getDbConnection()->createCommand($sql)->queryRow();
- if (!$rs) {
- echo json_encode(array("success" => 0, "message" => "无生成的pdf"));
- exit();
- }
- if (!$apiUrl) {
- echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
- exit();
- }
- $params['schoolId'] = $this->schoolId;
- $params['type'] = 1;
- $params['reportId'] = explode(",", $reportId);
- $rs = Curl::post($apiUrl . "/rest/download_teacher_pdf/index", $params);
- if (!($rs = json_decode($rs))) {
- $rs = array("success" => 0, "message" => "请求接口失败");
- } else {
- //更新下载时间
- $this->updateTeacherHrpDownStatus($reportId);
- }
- if (isset($school_group_id) && $school_group_id && isset($rs->downloadPath)) {
- if (YII_ENV == 'pro' || YII_ENV == 'production') {
- $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/', 'http://zstatic' . $school_group_id, $rs->downloadPath);
- }
- }
- echo json_encode($rs);
- exit;
- }
- /**
- * 更新教师版假期报告下载状态
- * @param $reportId
- */
- private function updateTeacherHrpDownStatus( $reportId){
- $time = time();
- $sql = "update holiday_report_teacher set is_report_download = 1,report_download_time={$time} where report_id in ({$reportId}) and report_download_time = 0";
- $this->sConn->createCommand($sql)->execute();
- }
- }
|