Oper.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php namespace Manage\Api\Page;
  2. use Dever;
  3. use Manage\Lib\Page;
  4. # 操作
  5. class Oper extends Page
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct('oper');
  10. $this->id = Dever::input('id');
  11. if (!$this->id) {
  12. Dever::error('无效数据');
  13. }
  14. $this->checkFunc();
  15. }
  16. # 更改某个字段的值
  17. public function up_commit(){}
  18. public function up()
  19. {
  20. $input = Dever::input();
  21. $field = explode(',', Dever::input('field'));
  22. foreach ($field as $k => $v) {
  23. if (isset($input[$v]) && $value = $input[$v]) {
  24. if (is_array($value)) {
  25. $value = implode(',', $value);
  26. }
  27. $data[$v] = $value;
  28. }
  29. }
  30. if (isset($this->config['up_start']) && $this->config['up_start']) {
  31. list($this->id, $data) = Dever::call($this->config['up_start'], array($this->id, $data));
  32. }
  33. $where['id'] = array('in', $this->id);
  34. $state = $this->db->update($where, $data);
  35. if ($state) {
  36. if (isset($this->config['up_end']) && $this->config['up_end']) {
  37. Dever::call($this->config['up_end'], array($this->id, $data));
  38. }
  39. return '操作成功';
  40. } else {
  41. Dever::error('操作失败');
  42. }
  43. }
  44. # 删除 删除到回收站
  45. public function recycle_commit(){}
  46. public function recycle()
  47. {
  48. $where['id'] = array('in', $this->id);
  49. $data = $this->db->select($where);
  50. if ($data) {
  51. foreach ($data as $k => $v) {
  52. $insert['table'] = $this->db->config['load'];
  53. $insert['table_id'] = $v['id'];
  54. $insert['content'] = Dever::json_encode($v);
  55. $state = Dever::db('manage/recycler')->insert($insert);
  56. if (!$state) {
  57. Dever::error('删除失败,请重试');
  58. }
  59. $state = $this->db->delete($v['id']);
  60. if (!$state) {
  61. Dever::error('删除失败,请重试');
  62. }
  63. }
  64. }
  65. return '操作成功';
  66. }
  67. # 从回收站恢复
  68. public function recover_commit(){}
  69. public function recover()
  70. {
  71. $where['id'] = array('in', $this->id);
  72. $data = $this->db->select($where);
  73. if ($data) {
  74. foreach ($data as $k => $v) {
  75. $v['content'] = Dever::json_decode($v['content']);
  76. $state = Dever::db($v['table'])->insert($v['content']);
  77. if (!$state) {
  78. Dever::error('恢复失败,请重试');
  79. }
  80. $state = $this->db->delete($v['id']);
  81. if (!$state) {
  82. Dever::error('恢复失败,请重试');
  83. }
  84. }
  85. }
  86. return '操作成功';
  87. }
  88. # 直接删除
  89. public function delete_commit(){}
  90. public function delete()
  91. {
  92. $where['id'] = array('in', $this->id);
  93. $state = $this->db->delete($where);
  94. if (!$state) {
  95. Dever::error('删除失败,请重试');
  96. }
  97. return '操作成功';
  98. }
  99. }