Help.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\store\controller\content;
  13. use think\response\Json;
  14. use app\store\controller\Controller;
  15. use app\store\model\Help as HelpModel;
  16. /**
  17. * 帮助中心
  18. * Class Help
  19. * @package app\store\controller\content
  20. */
  21. class Help extends Controller
  22. {
  23. /**
  24. * 获取列表记录
  25. * @return Json
  26. * @throws \think\db\exception\DbException
  27. */
  28. public function list(): Json
  29. {
  30. $model = new HelpModel;
  31. $list = $model->getList();
  32. return $this->renderSuccess(compact('list'));
  33. }
  34. /**
  35. * 添加帮助
  36. * @return Json
  37. */
  38. public function add(): Json
  39. {
  40. // 新增记录
  41. $model = new HelpModel;
  42. if ($model->add($this->postForm())) {
  43. return $this->renderSuccess('添加成功');
  44. }
  45. return $this->renderError($model->getError() ?: '添加失败');
  46. }
  47. /**
  48. * 更新帮助
  49. * @param int $helpId
  50. * @return Json
  51. */
  52. public function edit(int $helpId): Json
  53. {
  54. // 帮助详情
  55. $model = HelpModel::detail($helpId);
  56. // 更新记录
  57. if ($model->edit($this->postForm())) {
  58. return $this->renderSuccess('更新成功');
  59. }
  60. return $this->renderError($model->getError() ?: '更新失败');
  61. }
  62. /**
  63. * 删除帮助
  64. * @param int $helpId
  65. * @return Json
  66. */
  67. public function delete(int $helpId): Json
  68. {
  69. // 帮助详情
  70. $model = HelpModel::detail($helpId);
  71. if (!$model->setDelete()) {
  72. return $this->renderError($model->getError() ?: '删除失败');
  73. }
  74. return $this->renderSuccess('删除成功');
  75. }
  76. }