Certificate.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. $certificateCategoryList = CertificateCategoryModel::getAll();
  34. return $this->fetch('index', compact('list','certificateCategoryList'));
  35. }
  36. /**
  37. * [add]
  38. * 添加资质
  39. *
  40. * @Author: Yeshihao
  41. * @DateTime: 2024/11/26 14:56
  42. * @return array|bool|mixed
  43. * @throws \think\db\exception\DataNotFoundException
  44. * @throws \think\db\exception\ModelNotFoundException
  45. * @throws \think\exception\DbException
  46. */
  47. public function add()
  48. {
  49. $model = new CertificateModel;
  50. if (!$this->request->isAjax()) {
  51. $category = CertificateCategoryModel::getAll();
  52. return $this->fetch('add', compact('category'));
  53. }
  54. // 新增记录
  55. if ($model->add($this->postData())) {
  56. return $this->renderSuccess('添加成功', url('content.certificate/index'));
  57. }
  58. return $this->renderError($model->getError() ?: '添加失败');
  59. }
  60. /**
  61. * 更新文章
  62. *
  63. * @param $article_id
  64. * @return array|mixed
  65. * @throws \think\exception\DbException
  66. */
  67. public function edit($id)
  68. {
  69. // 文章详情
  70. $model = CertificateModel::detail($id);
  71. if (!$this->request->isAjax()) {
  72. $category = CertificateCategoryModel::getAll();
  73. return $this->fetch('edit', compact('model', 'category'));
  74. }
  75. // 更新记录
  76. if ($model->edit($this->postData())) {
  77. return $this->renderSuccess('更新成功', url('content.certificate/index'));
  78. }
  79. return $this->renderError($model->getError() ?: '更新失败');
  80. }
  81. /**
  82. * [delete]
  83. *
  84. * @Author: Yeshihao
  85. * @DateTime: 2024/11/28 10:08
  86. * @param $id
  87. * @return array|bool
  88. * @throws \think\exception\DbException
  89. */
  90. public function delete($id)
  91. {
  92. // 文章详情
  93. $model = CertificateModel::detail($id);
  94. if (!$model->setDelete()) {
  95. return $this->renderError($model->getError() ?: '删除失败');
  96. }
  97. return $this->renderSuccess('删除成功');
  98. }
  99. }