Payconfig.php 4.6 KB

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