Help.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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\wxapp;
  10. use app\store\controller\Controller;
  11. use app\store\model\WxappHelp as WxappHelpModel;
  12. /**
  13. * 小程序帮助中心
  14. * Class help
  15. * @package app\store\controller\wxapp
  16. */
  17. class Help extends Controller
  18. {
  19. /**
  20. * 帮助中心列表
  21. * @return mixed
  22. * @throws \think\db\exception\DataNotFoundException
  23. * @throws \think\db\exception\ModelNotFoundException
  24. * @throws \think\exception\DbException
  25. */
  26. public function index()
  27. {
  28. $model = new WxappHelpModel;
  29. $list = $model->getList();
  30. return $this->fetch('index', compact('list'));
  31. }
  32. /**
  33. * 添加帮助
  34. * @return array|mixed
  35. */
  36. public function add()
  37. {
  38. $model = new WxappHelpModel;
  39. if (!$this->request->isAjax()) {
  40. return $this->fetch('add');
  41. }
  42. // 新增记录
  43. if ($model->add($this->postData('help'))) {
  44. return $this->renderSuccess('添加成功', url('wxapp.help/index'));
  45. }
  46. return $this->renderError($model->getError() ?: '添加失败');
  47. }
  48. /**
  49. * 更新帮助
  50. * @param $help_id
  51. * @return array|mixed
  52. * @throws \think\exception\DbException
  53. */
  54. public function edit($help_id)
  55. {
  56. // 帮助详情
  57. $model = WxappHelpModel::detail($help_id);
  58. if (!$this->request->isAjax()) {
  59. return $this->fetch('edit', compact('model'));
  60. }
  61. // 更新记录
  62. if ($model->edit($this->postData('help'))) {
  63. return $this->renderSuccess('更新成功', url('wxapp.help/index'));
  64. }
  65. return $this->renderError($model->getError() ?: '更新失败');
  66. }
  67. /**
  68. * 删除帮助
  69. * @param $help_id
  70. * @return array
  71. * @throws \think\exception\DbException
  72. */
  73. public function delete($help_id)
  74. {
  75. // 帮助详情
  76. $model = WxappHelpModel::detail($help_id);
  77. if (!$model->remove()) {
  78. return $this->renderError($model->getError() ?: '删除失败');
  79. }
  80. return $this->renderSuccess('删除成功');
  81. }
  82. }