| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <?php
- /**
- *
- * @copyright ©2020 点小铺
- * @author hanj
- * @link: https://dyuit.com
- * Created by VSCode
- */
- namespace app\store\controller\content\certificate;
- use app\store\controller\Controller;
- use app\store\model\CertificateCategory as CertificateCategoryModel;
- use app\store\model\Certificate as CertificateModel;
- use app\store\model\CertificateApply as CertificateApplyModel;
- use ZipArchive;
- /**
- * 文章分类
- * Class Category
- *
- * @package app\store\controller\content
- */
- class Watermark extends Controller
- {
- /**
- * 文章分类列表
- *
- * @return mixed
- */
- public function index()
- {
- $model = new CertificateApplyModel;
- $list = $model->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('修改成功');
- }
- }
|