| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- namespace app\admin\controller\system;
- use app\common\controller\AdminController;
- use app\common\model\PayConfigModel;
- use app\common\model\SystemFaq;
- use think\App;
- /**
- * @ControllerAnnotation(title="支付配置")
- */
- class Payconfig extends AdminController
- {
- use \app\admin\traits\Curd;
- public function __construct (App $app)
- {
- parent::__construct($app);
- $this->model = new PayConfigModel();
- }
- /**
- * @NodeAnotation(title="列表")
- */
- public function index ()
- {
- if ($this->request->isAjax()) {
- // if (input('selectFields')) {
- // return $this->selectList();
- // }
- list($page, $limit, $where) = $this->buildTableParames();
- $count = $this->model
- ->where($where)
- ->count();
- $list = $this->model
- ->where($where)
- ->withAttr('channel', function ($val, $data){
- return $val==1?'支付宝':'微信';
- })
- ->page($page, $limit)
- ->order($this->sort)
- ->select();
- // foreach ($list as &$v) {
- // if ($v->parent_id == 0) {
- // $v->parent_id = '最上级';
- // } else {
- // $self = \think\facade\Db::name('system_faq')
- // ->where(['id' => $v->parent_id])
- // ->value('title');
- // $v->parent_id = $self;
- // }
- // }
- $data = [
- 'code' => 0,
- 'msg' => '',
- 'count' => $count,
- 'data' => $list,
- ];
- return json($data);
- }
- return $this->fetch();
- }
- /**
- * @NodeAnotation(title="修改")
- */
- public function edit ($id)
- {
- $row = $this->model->find($id);
- empty($row) && $this->error('数据不存在');
- if ($this->request->isAjax()) {
- $post = $this->request->post();
- $rule = [];
- $this->validate($post, $rule);
- try {
- if (empty($post['url'])) {
- unset($post['url']);
- }
- if (!empty($post['content'])) {
- $post['content'] = htmlspecialchars_decode($post['content']);
- }
- $save = $row->save($post);
- } catch (\Exception $e) {
- $this->error('保存失败');
- }
- $save ? $this->success('保存成功') : $this->error('保存失败');
- }
- $this->assign('row', $row);
- return $this->fetch();
- }
- /**
- * @NodeAnotation(title="添加")
- */
- public function add ()
- {
- if ($this->request->isAjax()) {
- $post = $this->request->post();
- try {
- if ($post['parent_id'] == 1) {
- $db = \think\facade\Db::name('system_faq')
- ->where(['parent_id' => 1])
- ->count();
- if ($db >= 5) {
- $this->error('保存失败');
- }
- }
- if (!empty($post['content'])) {
- $post['content'] = htmlspecialchars_decode($post['content']);
- }
- $save = $this->model->save($post);
- } catch (\Exception $e) {
- $this->error('保存失败');
- }
- $save ? $this->success('保存成功') : $this->error('保存失败');
- }
- return $this->fetch();
- }
- /**
- * @NodeAnotation(title="删除")
- */
- public function delete ($id)
- {
- $row = $this->model->find($id);
- if ($row->id == 1) {
- $this->error('父类常见问题不能删除');
- }
- empty($row) && $this->error('数据不存在');
- try {
- $save = $row->delete();
- } catch (\Exception $e) {
- $this->error('删除失败');
- }
- if ($save) {
- $this->success('删除成功');
- } else {
- $this->error('删除失败');
- }
- }
- /**
- * @NodeAnotation(title="选择上级")
- */
- public function type ()
- {
- $list = \think\facade\Db::name('system_faq')
- ->field('id,title')
- ->where(['parent_id' => 0])
- ->select()
- ->toArray();
- array_push($list, ['id' => 0, 'title' => '最上级']);
- $data = [
- 'code' => 1,
- 'msg' => '',
- 'count' => count($list),
- 'data' => $list,
- ];
- return json($data);
- }
- }
|