Configvalue.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace app\admin\controller\general;
  3. use app\admin\model\AdminLog;
  4. use app\common\controller\Backend;
  5. /**
  6. * 基本配置
  7. *
  8. * @icon fa fa-cog
  9. * @remark 用于管理一些字典数据,通常以键值格式进行录入,保存的数据格式为JSON
  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. AdminLog::record(__('Add'), $this->model->getLastInsID());
  70. $this->code = 1;
  71. }
  72. return;
  73. }
  74. return $this->view->fetch();
  75. }
  76. /**
  77. * 编辑
  78. */
  79. public function edit($ids = NULL)
  80. {
  81. $row = $this->model->get(['id' => $ids]);
  82. if (!$row)
  83. $this->error(__('No Results were found'));
  84. // 状态为locked时不允许编辑
  85. if ($row['status'] == 'locked')
  86. $this->error(__('The current item can not be edited'));
  87. if ($this->request->isPost())
  88. {
  89. $this->code = -1;
  90. $params = $this->request->post("row/a");
  91. if ($params)
  92. {
  93. if ($this->request->has('field'))
  94. {
  95. //JSON字段
  96. $fieldarr = $valuearr = [];
  97. $field = $this->request->post('field/a');
  98. $value = $this->request->post('value/a');
  99. foreach ($field as $k => $v)
  100. {
  101. if ($v != '')
  102. {
  103. $fieldarr[] = $field[$k];
  104. $valuearr[] = $value[$k];
  105. }
  106. }
  107. $params['content'] = array_combine($fieldarr, $valuearr);
  108. }
  109. $row->save($params);
  110. AdminLog::record(__('Edit'), $ids);
  111. $this->code = 1;
  112. }
  113. return;
  114. }
  115. $this->view->assign("row", $row);
  116. return $this->view->fetch();
  117. }
  118. }