Config.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php namespace App\Http\Controllers\Admin;
  2. use App\Models\Config as Model;
  3. /**
  4. * 地区管理
  5. *
  6. * @author 刘相欣
  7. *
  8. */
  9. class Config extends Auth{
  10. protected function _initialize(){
  11. parent::_initialize();
  12. $this->assign('breadcrumb1','系统');
  13. $this->assign('breadcrumb2','基础配置');
  14. }
  15. /**
  16. * 列表页
  17. *
  18. * */
  19. public function index(Model $Model){
  20. // 超管可以管理所有
  21. $map = in_array(admin('uid'), explode(',', config('administrator'))) ? [] : [['is_settings','=','1']];
  22. // 查询用户
  23. $list = $Model->query()->where($map)->paginate(config('page_num',10))->appends(request()->all());
  24. // 分配数据
  25. $this->assign('list',$list);
  26. $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
  27. // 加载模板
  28. return $this->fetch();
  29. }
  30. /**
  31. * 修改
  32. *
  33. * */
  34. public function edit(Model $Model){
  35. // 接受参数
  36. $id = request('id',0);
  37. // 查询数据
  38. $oldData = $Model->query()->find($id);
  39. // 修改
  40. if(request()->isMethod('post')){
  41. // 组合数据
  42. $data['value'] = request('value','');
  43. // 写入
  44. $result = $Model->edit($id,$data);
  45. // 提示新增失败
  46. if( !$result ) return json_send(['code'=>'error','msg'=>'修改失败']);
  47. // 记录行为
  48. $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,$data);
  49. // 告知结果
  50. return json_send(['code'=>'success','msg'=>'修改成功','action'=>'edit']);
  51. }
  52. // 如果是没有数据
  53. if( !$oldData ) return $this->error('查无数据');
  54. // 分配数据
  55. $this->assign('crumbs','修改'.$oldData['info']);
  56. $this->assign('oldData',$oldData);
  57. // 加载模板
  58. return $this->fetch();
  59. }
  60. }