Configvalue.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace app\admin\controller\general;
  3. use app\common\controller\Backend;
  4. /**
  5. * 基本配置
  6. *
  7. * @icon fa fa-cog
  8. * @remark 用于管理一些字典数据,通常以键值格式进行录入,保存的数据格式为JSON
  9. * @internal
  10. */
  11. class Configvalue extends Backend
  12. {
  13. protected $model = null;
  14. public function _initialize()
  15. {
  16. parent::_initialize();
  17. $this->model = model('Configvalue');
  18. }
  19. /**
  20. * 查看
  21. */
  22. public function index()
  23. {
  24. if ($this->request->isAjax())
  25. {
  26. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  27. $total = $this->model
  28. ->where($where)
  29. ->order($sort, $order)
  30. ->count();
  31. $list = $this->model
  32. ->where($where)
  33. ->order($sort, $order)
  34. ->limit($offset, $limit)
  35. ->select();
  36. $result = array("total" => $total, "rows" => $list);
  37. return json($result);
  38. }
  39. return $this->view->fetch();
  40. }
  41. /**
  42. * 添加
  43. */
  44. public function add()
  45. {
  46. if ($this->request->isPost())
  47. {
  48. $this->code = -1;
  49. $params = $this->request->post("row/a");
  50. if ($params)
  51. {
  52. if ($this->request->has('field'))
  53. {
  54. //JSON字段
  55. $fieldarr = $valuearr = [];
  56. $field = $this->request->post('field/a');
  57. $value = $this->request->post('value/a');
  58. foreach ($field as $k => $v)
  59. {
  60. if ($v != '')
  61. {
  62. $fieldarr[] = $field[$k];
  63. $valuearr[] = $value[$k];
  64. }
  65. }
  66. $params['content'] = array_combine($fieldarr, $valuearr);
  67. }
  68. $this->model->save($params);
  69. $this->code = 1;
  70. }
  71. return;
  72. }
  73. return $this->view->fetch();
  74. }
  75. /**
  76. * 编辑
  77. */
  78. public function edit($ids = NULL)
  79. {
  80. $row = $this->model->get(['id' => $ids]);
  81. if (!$row)
  82. $this->error(__('No Results were found'));
  83. // 状态为locked时不允许编辑
  84. if ($row['status'] == 'locked')
  85. $this->error(__('The current item can not be edited'));
  86. if ($this->request->isPost())
  87. {
  88. $this->code = -1;
  89. $params = $this->request->post("row/a");
  90. if ($params)
  91. {
  92. if ($this->request->has('field'))
  93. {
  94. //JSON字段
  95. $fieldarr = $valuearr = [];
  96. $field = $this->request->post('field/a');
  97. $value = $this->request->post('value/a');
  98. foreach ($field as $k => $v)
  99. {
  100. if ($v != '')
  101. {
  102. $fieldarr[] = $field[$k];
  103. $valuearr[] = $value[$k];
  104. }
  105. }
  106. $params['content'] = array_combine($fieldarr, $valuearr);
  107. }
  108. $row->save($params);
  109. $this->code = 1;
  110. }
  111. return;
  112. }
  113. $this->view->assign("row", $row);
  114. return $this->view->fetch();
  115. }
  116. }