Config.php 3.0 KB

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