Certificate.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\store\controller\content;
  10. use app\store\controller\Controller;
  11. use app\store\model\Article as ArticleModel;
  12. use app\store\model\Certificate as CertificateModel;
  13. use app\store\model\article\Category as CategoryModel;
  14. use app\store\model\CertificateCategory as CertificateCategoryModel;
  15. /**
  16. * 文章管理控制器
  17. * Class article
  18. *
  19. * @package app\store\controller\content
  20. */
  21. class Certificate extends Controller
  22. {
  23. /**
  24. * 文章列表
  25. *
  26. * @return mixed
  27. * @throws \think\exception\DbException
  28. */
  29. public function index()
  30. {
  31. $model = new CertificateModel;
  32. $list = $model->getList();
  33. return $this->fetch('index', compact('list'));
  34. }
  35. /**
  36. * [add]
  37. * 添加资质
  38. * @Author: Yeshihao
  39. * @DateTime: 2024/11/26 14:56
  40. * @return array|bool|mixed
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. * @throws \think\exception\DbException
  44. */
  45. public function add()
  46. {
  47. $model = new CertificateModel;
  48. if (!$this->request->isAjax()) {
  49. $category = CertificateCategoryModel::getAll();
  50. return $this->fetch('add', compact('category'));
  51. }
  52. // 新增记录
  53. if ($model->add($this->postData())) {
  54. return $this->renderSuccess('添加成功', url('content.certificate/index'));
  55. }
  56. return $this->renderError($model->getError() ?: '添加失败');
  57. }
  58. /**
  59. * 更新文章
  60. *
  61. * @param $article_id
  62. * @return array|mixed
  63. * @throws \think\exception\DbException
  64. */
  65. public function edit($id)
  66. {
  67. // 文章详情
  68. $model = CertificateModel::detail($id);
  69. if (!$this->request->isAjax()) {
  70. $category = CertificateCategoryModel::getAll();
  71. return $this->fetch('edit', compact('model', 'category'));
  72. }
  73. // 更新记录
  74. if ($model->edit($this->postData())) {
  75. return $this->renderSuccess('更新成功', url('content.certificate/index'));
  76. }
  77. return $this->renderError($model->getError() ?: '更新失败');
  78. }
  79. /**
  80. * [delete]
  81. *
  82. * @Author: Yeshihao
  83. * @DateTime: 2024/11/28 10:08
  84. * @param $id
  85. * @return array|bool
  86. * @throws \think\exception\DbException
  87. */
  88. public function delete($id)
  89. {
  90. // 文章详情
  91. $model = CertificateModel::detail($id);
  92. if (!$model->setDelete()) {
  93. return $this->renderError($model->getError() ?: '删除失败');
  94. }
  95. return $this->renderSuccess('删除成功');
  96. }
  97. }