Site.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 library\Controller;
  16. use think\Db;
  17. /**
  18. * 站点管理
  19. * Class help_center
  20. */
  21. class Site extends Controller
  22. {
  23. /**
  24. * 绑定数据表
  25. * @var string
  26. */
  27. protected $table = 'system_site';
  28. /**
  29. * 站点管理
  30. * @auth true
  31. * @menu true
  32. * @throws \think\Exception
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. * @throws \think\exception\DbException
  36. * @throws \think\exception\PDOException
  37. */
  38. public function index()
  39. {
  40. $this->title = '站点管理';
  41. sysoplog('站点管理', '访问站点管理页面');
  42. $query = $this->_query($this->table)->like('name,code')->equal('towns_id');
  43. $query->where('is_del',1)->order('id desc')->page();
  44. }
  45. /**
  46. * 数据列表处理
  47. * @auth true
  48. * @menu true
  49. * @param array $data
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. * @throws \think\exception\DbException
  53. */
  54. protected function _index_page_filter(&$data)
  55. {
  56. foreach ($data as &$v){
  57. $v['towns_name'] = Db::name('system_towns')->where('id',$v['towns_id'])->value('name');
  58. }
  59. $towns = Db::name('system_towns')->where('is_del',1)->field('id,name')->select();
  60. $this->towns =array_merge([['id' => '', 'name' => '--全部--']],$towns );
  61. }
  62. /**
  63. * 添加站点
  64. * @auth true
  65. * @menu true
  66. * @throws \think\Exception
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\ModelNotFoundException
  69. * @throws \think\exception\DbException
  70. * @throws \think\exception\PDOException
  71. */
  72. public function add()
  73. {
  74. $this->create_at = date('Y-m-d H:i:s');
  75. $this->_form($this->table, 'form');
  76. }
  77. /**
  78. * 编辑站点
  79. * @auth true
  80. * @menu true
  81. * @throws \think\Exception
  82. * @throws \think\db\exception\DataNotFoundException
  83. * @throws \think\db\exception\ModelNotFoundException
  84. * @throws \think\exception\DbException
  85. * @throws \think\exception\PDOException
  86. */
  87. public function edit()
  88. {
  89. $this->_form($this->table, 'form');
  90. }
  91. /**
  92. * 表单数据处理
  93. * @param array $vo
  94. * @throws \ReflectionException
  95. * @throws \think\db\exception\DataNotFoundException
  96. * @throws \think\db\exception\ModelNotFoundException
  97. * @throws \think\exception\DbException
  98. */
  99. protected function _form_filter(&$vo)
  100. {
  101. if ($this->request->isGet()) {
  102. $towns = Db::name('system_towns')->where('is_del',1)->select();
  103. $this->towns = $towns;
  104. }elseif ($this->request->isPost()){
  105. if (!isset($vo['towns_id']) || $vo['towns_id']==''){
  106. $this->error('请选择乡镇');
  107. }
  108. $qu = Db::name($this->table)->where('is_del',1)->where('name',$vo['name']);
  109. if (isset($vo['id']) && $vo['id']!=''){
  110. $qu->where('id','neq',$vo['id']);
  111. }
  112. $name = $qu->find();
  113. if ($name){
  114. $this->error('站点已存在');
  115. }
  116. }
  117. }
  118. /**
  119. * 处理成功回调
  120. */
  121. public function _form_result($result,$data){
  122. $name = isset($data['id']) ? '编辑' : '新增';
  123. if ($result) {
  124. sysoplog('站点管理', $name.'成功'.json_encode($data,true));
  125. }else{
  126. sysoplog('站点管理', $name.'失败'.json_encode($data,true));
  127. }
  128. }
  129. /**
  130. * 删除站点
  131. * @auth true
  132. * @menu true
  133. * @throws \think\Exception
  134. * @throws \think\exception\PDOException
  135. */
  136. public function del()
  137. {
  138. $log = ['action'=>'站点管理','content'=>'删除'];
  139. $this->_save($this->table, ['is_del' => '0'],$log);
  140. }
  141. }