Oper.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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();
  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. $where['id'] = array('in', $this->id);
  31. $state = $this->db->update($where, $data);
  32. if ($state) {
  33. return '操作成功';
  34. } else {
  35. Dever::error('操作失败');
  36. }
  37. }
  38. # 删除 删除到回收站
  39. public function recycle_commit(){}
  40. public function recycle()
  41. {
  42. $where['id'] = array('in', $this->id);
  43. $data = $this->db->select($where)->fetchAll();
  44. if ($data) {
  45. foreach ($data as $k => $v) {
  46. $insert['table'] = Dever::input('load');
  47. $insert['table_id'] = $v['id'];
  48. $insert['content'] = Dever::json_encode($v);
  49. $state = Dever::db('manage/recycler')->insert($insert);
  50. if (!$state) {
  51. Dever::error('删除失败,请重试');
  52. }
  53. $state = $this->db->delete($v['id']);
  54. if (!$state) {
  55. Dever::error('删除失败,请重试');
  56. }
  57. }
  58. }
  59. return '操作成功';
  60. }
  61. # 从回收站恢复
  62. public function recover_commit(){}
  63. public function recover()
  64. {
  65. $where['id'] = array('in', $this->id);
  66. $data = $this->db->select($where);
  67. if ($data) {
  68. foreach ($data as $k => $v) {
  69. $v['content'] = Dever::json_decode($v['content']);
  70. $v['table'] = ltrim($v['table'], '/');
  71. $state = Dever::db($v['table'])->insert($v['content']);
  72. if (!$state) {
  73. Dever::error('恢复失败,请重试');
  74. }
  75. $state = $this->db->delete($v['id']);
  76. if (!$state) {
  77. Dever::error('恢复失败,请重试');
  78. }
  79. }
  80. }
  81. return '操作成功';
  82. }
  83. # 直接删除
  84. public function delete_commit(){}
  85. public function delete()
  86. {
  87. $where['id'] = array('in', $this->id);
  88. $state = $this->db->delete($where);
  89. if (!$state) {
  90. Dever::error('删除失败,请重试');
  91. }
  92. return '操作成功';
  93. }
  94. }