Config.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace app\admin\controller\wechat;
  3. use app\common\controller\Backend;
  4. use app\common\model\Configvalue;
  5. /**
  6. * 配置管理
  7. *
  8. * @icon fa fa-list-alt
  9. */
  10. class Config extends Backend
  11. {
  12. protected $wechatcfg = NULL;
  13. protected $obj = [];
  14. public function _initialize()
  15. {
  16. parent::_initialize();
  17. $this->wechatcfg = Configvalue::get('wechat');
  18. $this->obj = $this->wechatcfg->content;
  19. }
  20. /**
  21. * 查看
  22. */
  23. public function index()
  24. {
  25. if ($this->request->isAjax())
  26. {
  27. $configlist = isset($this->obj['config']) ? $this->obj['config'] : [];
  28. $list = array();
  29. foreach ($configlist as $row)
  30. {
  31. $list[] = $row;
  32. }
  33. $total = count($list);
  34. $result = array("total" => $total, "rows" => $list);
  35. return json($result);
  36. }
  37. return $this->view->fetch();
  38. }
  39. /**
  40. * 添加
  41. */
  42. public function add()
  43. {
  44. if ($this->request->isPost())
  45. {
  46. $this->obj['config'][] = $this->request->post('row/a');
  47. $this->wechatcfg->content = $this->obj;
  48. $this->wechatcfg->save();
  49. $this->code = 1;
  50. return;
  51. }
  52. return $this->view->fetch();
  53. }
  54. /**
  55. * 编辑
  56. */
  57. public function edit($ids = NULL)
  58. {
  59. $row = [];
  60. foreach ($this->obj['config'] as $k => $v)
  61. {
  62. if ($v['id'] == $ids)
  63. {
  64. $row = $v;
  65. break;
  66. }
  67. }
  68. if (!$row)
  69. $this->error(__('No Results were found'));
  70. if ($this->request->isPost())
  71. {
  72. $params = $this->request->post('row/a');
  73. $this->obj['config'][$k] = $params;
  74. $this->obj['config'] = array_values($this->obj['config']);
  75. $this->wechatcfg->content = $this->obj;
  76. $this->wechatcfg->save();
  77. $this->code = 1;
  78. return;
  79. }
  80. $this->view->assign("row", $row);
  81. return $this->view->fetch();
  82. }
  83. /**
  84. * 删除
  85. */
  86. public function del($ids = "")
  87. {
  88. $this->code = -1;
  89. if ($ids)
  90. {
  91. $ids = is_array($ids) ? $ids : explode(',', $ids);
  92. foreach ($this->obj['config'] as $k => $v)
  93. {
  94. if (in_array($v['id'], $ids))
  95. {
  96. unset($this->obj['config'][$k]);
  97. }
  98. }
  99. $this->wechatcfg->content = $this->obj;
  100. $this->wechatcfg->save();
  101. $this->code = 1;
  102. }
  103. return;
  104. }
  105. /**
  106. * 批量更新
  107. */
  108. public function multi($ids = "")
  109. {
  110. $this->code = -1;
  111. //不支持指操作
  112. return;
  113. }
  114. }