Towns.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\admin\controller;
  15. use AlibabaCloud\DBFS\DBFS;
  16. use library\Controller;
  17. use think\Db;
  18. /**
  19. * 乡镇管理
  20. * Class help_center
  21. */
  22. class Towns extends Controller
  23. {
  24. /**
  25. * 绑定数据表
  26. * @var string
  27. */
  28. protected $table = 'system_towns';
  29. /**
  30. * 乡镇管理
  31. * @auth true
  32. * @menu true
  33. * @throws \think\Exception
  34. * @throws \think\db\exception\DataNotFoundException
  35. * @throws \think\db\exception\ModelNotFoundException
  36. * @throws \think\exception\DbException
  37. * @throws \think\exception\PDOException
  38. */
  39. public function index()
  40. {
  41. $this->title = '乡镇管理';
  42. sysoplog('乡镇管理', '访问乡镇管理页面');
  43. $query = $this->_query($this->table)->like('name');
  44. $query->where('is_del',1)->order('id desc')->page();
  45. }
  46. /**
  47. * 添加乡镇
  48. * @auth true
  49. * @menu true
  50. * @throws \think\Exception
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. * @throws \think\exception\DbException
  54. * @throws \think\exception\PDOException
  55. */
  56. public function add()
  57. {
  58. $this->create_at = date('Y-m-d H:i:s');
  59. $this->_form($this->table, 'form');
  60. }
  61. /**
  62. * 编辑乡镇
  63. * @auth true
  64. * @menu true
  65. * @throws \think\Exception
  66. * @throws \think\db\exception\DataNotFoundException
  67. * @throws \think\db\exception\ModelNotFoundException
  68. * @throws \think\exception\DbException
  69. * @throws \think\exception\PDOException
  70. */
  71. public function edit()
  72. {
  73. $this->_form($this->table, 'form');
  74. }
  75. /**
  76. * 表单数据处理
  77. * @param array $vo
  78. * @throws \ReflectionException
  79. * @throws \think\db\exception\DataNotFoundException
  80. * @throws \think\db\exception\ModelNotFoundException
  81. * @throws \think\exception\DbException
  82. */
  83. protected function _form_filter(&$vo)
  84. {
  85. if ($this->request->isGet()) {
  86. }elseif ($this->request->isPost()){
  87. $qu = Db::name($this->table)->where('is_del',1)->where('name',$vo['name']);
  88. if (isset($vo['id']) && $vo['id']!=''){
  89. $qu->where('id','neq',$vo['id']);
  90. }
  91. $name = $qu->find();
  92. if ($name){
  93. $this->error('乡镇已存在');
  94. }
  95. }
  96. }
  97. /**
  98. * 处理成功回调
  99. */
  100. public function _form_result($result,$data){
  101. $name = isset($data['id']) ? '编辑' : '新增';
  102. if ($result) {
  103. sysoplog('乡镇管理', $name.'成功'.json_encode($data,true));
  104. }else{
  105. sysoplog('乡镇管理', $name.'失败'.json_encode($data,true));
  106. }
  107. }
  108. /**
  109. * 删除乡镇
  110. * @auth true
  111. * @menu true
  112. * @throws \think\Exception
  113. * @throws \think\exception\PDOException
  114. */
  115. public function del()
  116. {
  117. $log = ['action'=>'乡镇管理','content'=>'删除'];
  118. $this->_save($this->table, ['is_del' => '0'],$log);
  119. }
  120. }