Help.php 2.1 KB

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