Payconfig.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace app\admin\controller\system;
  3. use app\admin\logic\PayConfigLogic;
  4. use app\admin\logic\SystemFaqLogic;
  5. use app\common\controller\AdminController;
  6. use app\common\model\PayConfigModel;
  7. use app\common\model\SystemFaq;
  8. use think\App;
  9. /**
  10. * @ControllerAnnotation(title="支付配置")
  11. */
  12. class Payconfig extends AdminController
  13. {
  14. use \app\admin\traits\Curd;
  15. public function __construct(App $app)
  16. {
  17. parent::__construct($app);
  18. $this->model = new PayConfigModel();
  19. }
  20. /**
  21. * @NodeAnotation(title="列表")
  22. */
  23. public function index()
  24. {
  25. if ($this->request->isAjax()) {
  26. list($page, $limit, $where) = $this->buildTableParames();
  27. list($count, $list) = PayConfigLogic::getList($page, $limit, $where, $this->sort);
  28. $data = [
  29. 'code' => 0,
  30. 'msg' => '',
  31. 'count' => $count,
  32. 'data' => $list,
  33. ];
  34. return json($data);
  35. }
  36. return $this->fetch();
  37. }
  38. /**
  39. * @NodeAnotation(title="修改")
  40. */
  41. public function edit($id)
  42. {
  43. $row = $this->model->find($id);
  44. empty($row) && $this->error('数据不存在');
  45. if ($this->request->isAjax()) {
  46. $post = $this->request->post();
  47. $rule = [];
  48. $this->validate($post, $rule);
  49. try {
  50. if (empty($post['url'])) {
  51. unset($post['url']);
  52. }
  53. if (!empty($post['content'])) {
  54. $post['content'] = htmlspecialchars_decode($post['content']);
  55. }
  56. $save = $row->save($post);
  57. } catch (\Exception $e) {
  58. $this->error('保存失败');
  59. }
  60. $save ? $this->success('保存成功') : $this->error('保存失败');
  61. }
  62. $this->assign('row', $row);
  63. return $this->fetch();
  64. }
  65. /**
  66. * @NodeAnotation(title="添加")
  67. */
  68. public function add()
  69. {
  70. if ($this->request->isAjax()) {
  71. $post = $this->request->post();
  72. try {
  73. if ($post['parent_id'] == 1) {
  74. $db = \think\facade\Db::name('system_faq')
  75. ->where(['parent_id' => 1])
  76. ->count();
  77. if ($db >= 5) {
  78. $this->error('保存失败');
  79. }
  80. }
  81. if (!empty($post['content'])) {
  82. $post['content'] = htmlspecialchars_decode($post['content']);
  83. }
  84. $save = $this->model->save($post);
  85. } catch (\Exception $e) {
  86. $this->error('保存失败');
  87. }
  88. $save ? $this->success('保存成功') : $this->error('保存失败');
  89. }
  90. return $this->fetch();
  91. }
  92. /**
  93. * @NodeAnotation(title="删除")
  94. */
  95. public function delete($id)
  96. {
  97. $row = $this->model->find($id);
  98. if ($row->id == 1) {
  99. $this->error('父类常见问题不能删除');
  100. }
  101. empty($row) && $this->error('数据不存在');
  102. try {
  103. $save = $row->delete();
  104. } catch (\Exception $e) {
  105. $this->error('删除失败');
  106. }
  107. if ($save) {
  108. $this->success('删除成功');
  109. } else {
  110. $this->error('删除失败');
  111. }
  112. }
  113. /**
  114. * @NodeAnotation(title="选择上级")
  115. */
  116. public function type()
  117. {
  118. $list = SystemFaqLogic::getTopList();
  119. $data = [
  120. 'code' => 1,
  121. 'msg' => '',
  122. 'count' => count($list),
  123. 'data' => $list,
  124. ];
  125. return json($data);
  126. }
  127. }