Config.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace app\home\controller;
  3. use think\Lang;
  4. class Config extends AdminControl {
  5. public function _initialize() {
  6. parent::_initialize();
  7. Lang::load(APP_PATH . 'home/lang/' . config('default_lang') . '/config.lang.php');
  8. }
  9. /**
  10. * 接入信息管理
  11. */
  12. public function index()
  13. {
  14. $model_access = Model('Access');
  15. $title = input('post.title');
  16. $condition = array();
  17. $condition['access_pid'] = session('service_pid');
  18. if($title){
  19. $condition['access_appid|access_appsecrect'] = $title;
  20. }
  21. $access_list = $model_access->getAccessList($condition, '*', 10);
  22. $this->assign('access_list', $access_list);
  23. $this->assign('show_page', $model_access->page_info->render());
  24. $this->setAdminCurItem('index');
  25. return $this->fetch();
  26. }
  27. /**
  28. * 添加接入信息管理
  29. * @return mixed
  30. */
  31. public function add()
  32. {
  33. if (request()->isPost()) {
  34. $model_access = Model('Access');
  35. $data = array(
  36. 'access_url' => input('post.access_url'),
  37. 'access_status' => input('post.access_status') ? input('post.access_status'):0,
  38. 'access_appid' => random(22,0).time(),
  39. 'access_appsecrect' => random(32,0),
  40. 'access_pid' => session('service_pid'),//所属三方公司id
  41. 'access_addtime' => TIMESTAMP,
  42. );
  43. //添加到数据库
  44. $result = $model_access->addAccess($data);
  45. if ($result) {
  46. dsLayerOpenSuccess("添加成功!");
  47. } else {
  48. $this->error("添加失败!");
  49. }
  50. } else {
  51. $access = array(
  52. 'access_url' => '',
  53. 'access_status' => 0,
  54. );
  55. $model_access = Model('Access');
  56. $this->assign('access',$access);
  57. return $this->fetch('form');
  58. }
  59. }
  60. public function edit()
  61. {
  62. $this->assign('is_super',session('access_id'));
  63. $access_id = input('param.access_id');
  64. if (empty($access_id)) {
  65. $this->error(lang('param_error'));
  66. }
  67. $model_access = Model('Access');
  68. if (!request()->isPost()) {
  69. $condition['access_id'] = $access_id;
  70. $access = $model_access->getAccessInfo($condition);
  71. $this->assign('access', $access);
  72. return $this->fetch('form');
  73. } else {
  74. $data = array(
  75. 'access_status' => input('post.access_status'),
  76. 'access_url' => input('post.access_url')
  77. );
  78. //验证数据 END
  79. $result = $model_access->editAccess(array('access_id' => intval($access_id)), $data);
  80. if ($result) {
  81. dsLayerOpenSuccess("编辑成功!");
  82. } else {
  83. $this->error("编辑失败!");
  84. }
  85. }
  86. }
  87. public function del()
  88. {
  89. $access_id = input('param.access_id');
  90. if (empty($access_id)) {
  91. $this->error(lang('param_error'));
  92. }
  93. $result = db('access')->delete($access_id);
  94. if ($result) {
  95. ds_json_encode(10000, "删除成功!");
  96. } else {
  97. ds_json_encode(10001, "删除失败!");
  98. }
  99. }
  100. protected function getAdminItemList()
  101. {
  102. $menu_array = array(
  103. array(
  104. 'name' => 'index', 'text' => lang('ds_manage'), 'url' => url('Config/index')
  105. ), array(
  106. 'name' => 'add', 'text' => lang('ds_add'), 'url' => "javascript:dsLayerOpen('".url('Config/add')."','".lang('ds_add')."')"
  107. ),
  108. );
  109. return $menu_array;
  110. }
  111. }