getList(); return $this->fetch('index', compact('list')); } /** * 添加文章分类 * * @return array|mixed */ public function add() { $model = new CertificateApplyModel; if (!$this->request->isAjax()) { $category = CertificateCategoryModel::getAll(); return $this->fetch('add', compact('category')); } // 新增记录 if ($model->add($this->postData())) { return $this->renderSuccess('添加成功', url('content.certificate.watermark/index')); } return $this->renderError($model->getError() ?: '添加失败'); } /** * 编辑文章分类 * * @param $id * @return array|mixed * @throws \think\exception\DbException */ public function edit($id) { // 分类详情 $model = CertificateApplyModel::detail($id); if (!$this->request->isAjax()) { $category = CertificateCategoryModel::getAll(); $certificateList = CertificateModel::getCertificateList(['id' => ['in', $model['certificate_ids']]]); return $this->fetch('edit', compact('model', 'category', 'certificateList')); } // 更新记录 if ($model->edit($this->postData())) { return $this->renderSuccess('审核成功', url('content.certificate.watermark/index')); } return $this->renderError($model->getError() ?: '审核失败'); } /** * [detail] * * @Author: Yeshihao * @DateTime: 2024/11/28 16:52 * @param $id * @return array|bool|mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function detail($id) { // 分类详情 $model = CertificateApplyModel::detail($id); if (!$this->request->isAjax()) { $category = CertificateCategoryModel::getAll(); $certificateList = CertificateModel::getCertificateList(['id' => ['in', $model['certificate_ids']]]); return $this->fetch('detail', compact('model', 'category', 'certificateList')); } // 更新记录 if ($model->edit($this->postData())) { return $this->renderSuccess('审核成功', url('content.certificate.watermark/index')); } return $this->renderError($model->getError() ?: '审核失败'); } /** * [delete] * * @Author: Yeshihao * @DateTime: 2024/11/28 10:09 * @param $id * @return array|bool */ public function delete($id) { $model = CertificateApplyModel::detail($id); if ($model['status'] != 10) { return $this->renderError('取消失败'); } if (!$model->setDelete()) { return $this->renderError($model->getError() ?: '取消失败'); } return $this->renderSuccess('取消成功'); } /** * [getCertificateList] * * @Author: Yeshihao * @DateTime: 2024/11/27 10:51 * @param array $category_ids * @return array|bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getCertificateList($category_ids = []) { $model = new CertificateModel; if (!$list = $model->getCertificateList(['certificate_category_id' => ['in', $category_ids], 'is_delete' => ['=', 0]], ['id', 'name'])) { return $this->renderError($model->getError() ?: '请求失败'); } return $this->renderSuccess('请求成功', '', $list); } /** * [zipDownload] * 下载zip * * @Author: Yeshihao * @DateTime: 2024/11/28 11:15 * @param $id * @throws \think\exception\DbException */ public function zipDownload($id) { $model = CertificateApplyModel::detail($id); if (empty($model) || empty($model['result_data'])) { return $this->renderError('查无文件'); } //TP自带的类 $zip = new \ZipArchive(); //压缩文件名 $filename = Date('Ymd').$model['project'].'.zip'; $zipFilePath = RUNTIME_PATH."/temp/".$filename; if (file_exists($zipFilePath)) { unlink($zipFilePath); } //新建zip压缩包 $zip->open($zipFilePath, \ZIPARCHIVE::OVERWRITE | \ZIPARCHIVE::CREATE); //循环压缩文件 foreach ($model['result_data'] as $value) { $substr = mb_substr($value['file_path'], mb_strrpos($value['file_path'], ".")); //查询文件名称(若之前保存文件为源文件名保存可跳过该步骤) $zip->addFile($value['file_path'], basename($value['name'].$substr)); } //打包zip $zip->close(); header("Cache-Control:public"); header("Content-Description: File Transfer"); header("Content-disposition: attachment; filename=".basename($filename));//文件名 header("Content-Type:application/zip"); //格式为zip header("Content-Transfer-Encoding:binary"); //这是二进制文件 header("Content-Length:".filesize($zipFilePath)); //文件大小 @readfile($zipFilePath); } /** * [settingAlpha] * * @Author: Yeshihao * @DateTime: 2024/12/2 16:35 * @param $id * @param string $alpha * @return array|bool * @throws \think\exception\DbException */ public function settingAlpha($id, string $alpha) { if (!$model = CertificateApplyModel::detail($id)) { return $this->renderError('查无该资质申请'); } if (!$model->changeAlpha($alpha)) { return $this->renderError($model->getError() ?: '修改失败'); } return $this->renderSuccess('修改成功'); } }