| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- /**
- *
- * @copyright ©2020 点小铺
- * @author hanj
- * @link: https://dyuit.com
- * Created by VSCode
- */
- namespace app\store\controller\content;
- use app\store\controller\Controller;
- use app\store\model\Article as ArticleModel;
- use app\store\model\Certificate as CertificateModel;
- use app\store\model\article\Category as CategoryModel;
- use app\store\model\CertificateCategory as CertificateCategoryModel;
- /**
- * 文章管理控制器
- * Class article
- *
- * @package app\store\controller\content
- */
- class Certificate extends Controller
- {
- /**
- * 文章列表
- *
- * @return mixed
- * @throws \think\exception\DbException
- */
- public function index()
- {
- $model = new CertificateModel;
- $list = $model->getList();
- $certificateCategoryList = CertificateCategoryModel::getAll();
- return $this->fetch('index', compact('list','certificateCategoryList'));
- }
- /**
- * [add]
- * 添加资质
- *
- * @Author: Yeshihao
- * @DateTime: 2024/11/26 14:56
- * @return array|bool|mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function add()
- {
- $model = new CertificateModel;
- if (!$this->request->isAjax()) {
- $category = CertificateCategoryModel::getAll();
- return $this->fetch('add', compact('category'));
- }
- // 新增记录
- if ($model->add($this->postData())) {
- return $this->renderSuccess('添加成功', url('content.certificate/index'));
- }
- return $this->renderError($model->getError() ?: '添加失败');
- }
- /**
- * 更新文章
- *
- * @param $article_id
- * @return array|mixed
- * @throws \think\exception\DbException
- */
- public function edit($id)
- {
- // 文章详情
- $model = CertificateModel::detail($id);
- if (!$this->request->isAjax()) {
- $category = CertificateCategoryModel::getAll();
- return $this->fetch('edit', compact('model', 'category'));
- }
- // 更新记录
- if ($model->edit($this->postData())) {
- return $this->renderSuccess('更新成功', url('content.certificate/index'));
- }
- return $this->renderError($model->getError() ?: '更新失败');
- }
- /**
- * [delete]
- *
- * @Author: Yeshihao
- * @DateTime: 2024/11/28 10:08
- * @param $id
- * @return array|bool
- * @throws \think\exception\DbException
- */
- public function delete($id)
- {
- // 文章详情
- $model = CertificateModel::detail($id);
- if (!$model->setDelete()) {
- return $this->renderError($model->getError() ?: '删除失败');
- }
- return $this->renderSuccess('删除成功');
- }
- }
|