/** * Finds the Contract model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Contract the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Contract::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Lists all AccessApp models. * @return mixed */ public function actionPreviewTpl($contr_id = '1') { /** * @var Pdf $pdf * @var Contract $ec * @var Group $group * @var Organization $provider * @var Traveller $assigned * @var Other $other */ $this->layout = 'main_outer.php'; $ec = Contract::findOne($contr_id); if (empty($ec)) { throw new Exception('合同不存在'); } $version = ContractVersion::findOne($ec->vercode); if (empty($version)) { throw new Exception('合同版本不存在'); } $travellers = Traveller::find()->andWhere('contr_id=:contr_id', [':contr_id' => $ec->contr_id])->all(); $provider = Organization::findOne(1); $assigned = Traveller::find()->andWhere('contr_id=:contr_id and is_leader=:is_leader', [':contr_id' => $ec->contr_id, ':is_leader' => '1'])->one(); $group = Group::find()->andWhere('contr_id=:contr_id', [':contr_id' => $ec->contr_id])->one(); $other = Other::findOne($contr_id); $pay = json_decode($other->pay, true); $insurance = json_decode($other->insurance, true); $groupcorp = json_decode($other->groupcorp, true); $otherGroup = json_decode($other->group, true); $effect = json_decode($other->effect, true); $routes = Routes::find()->andWhere('contr_id=:contr_id and parentid=:parentid', [':contr_id' => $ec->contr_id, ':parentid' => 0])->all(); //自愿购物活动补充协议 $shops = ShopAgreement::find()->where("contr_id='{$ec->contr_id}'")->orderBy('index asc')->all(); //自愿参加另行付费旅游项目补充协议 $chargeables = Chargeable::find()->where("contr_id='{$ec->contr_id}'")->orderBy('index asc')->all(); $data = ['contract' => $ec, 'version' => $version, 'provider' => $provider, 'group' => $group, 'assigned' => $assigned, 'travellers' => $travellers, 'routes' => $routes, 'shops' => $shops, 'chargeables' => $chargeables, 'other' => $other, 'pay' => $pay, 'insurance' => $insurance, 'groupcorp' => $groupcorp, 'otherGroup' => $otherGroup, 'effect' => $effect, 'app' => ConfigHelper::getParamsConfigArray('app'), 'company' => ConfigHelper::getParamsConfigArray('company'), 'year' => date('Y'), 'PAGE_BREAK' => PdfHelper::PAGE_BREAK]; //pdf $css = Yii::$app->basePath . "/web/css/ec.css"; $css = file_get_contents($css); $htmlContent = $this->renderPartial('inside.tpl', $data); //file_get_contents("D:/template/t2.htm"); $pdf = Yii::$app->pdf; $pdf->cssInline .= $css; $pdf->content = $htmlContent; $pdf->filename = "电子合同-{$ec->contr_no}.pdf"; //methods $pdf->methods['SetHeader'] = "合同编号<span class=\"color-tno\">{$ec->contr_no}</span>"; $pdf->methods['SetTitle'] = ConfigHelper::getAppConfig('down'); $pdf->methods['SetAuthor'] = ConfigHelper::getAppConfig('author'); $pdf->methods['SetCreator'] = ConfigHelper::getAppConfig('creator'); $pdf->methods['SetSubject'] = ConfigHelper::getAppConfig('subject'); //$pdf->output($htmlContent); return $pdf->render(); //return $this->render('inside.tpl',$data); //echo $htmlContent; }