Oper.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. }
  15. # 更改某个字段的值
  16. public function up_commit(){}
  17. public function up()
  18. {
  19. $input = Dever::input();
  20. $field = explode(',', Dever::input('field'));
  21. foreach ($field as $k => $v) {
  22. if (isset($input[$v]) && $value = $input[$v]) {
  23. if (is_array($value)) {
  24. $value = implode(',', $value);
  25. }
  26. $data[$v] = $value;
  27. }
  28. }
  29. $where['id'] = array('in', $this->id);
  30. $state = $this->db->update($where, $data);
  31. if ($state) {
  32. return '操作成功';
  33. } else {
  34. Dever::error('操作失败');
  35. }
  36. }
  37. # 删除 删除到回收站
  38. public function del_commit(){}
  39. public function del()
  40. {
  41. $where['id'] = array('in', $this->id);
  42. $data = $this->db->select($where)->fetchAll();
  43. if ($data) {
  44. foreach ($data as $k => $v) {
  45. $insert['table'] = Dever::input('load');
  46. $insert['table_id'] = $v['id'];
  47. $insert['content'] = Dever::json_encode($v);
  48. $state = Dever::db('manage/recycler')->insert($insert);
  49. if (!$state) {
  50. Dever::error('删除失败,请重试');
  51. }
  52. $state = $this->db->delete($v['id']);
  53. if (!$state) {
  54. Dever::error('删除失败,请重试');
  55. }
  56. }
  57. }
  58. return '操作成功';
  59. }
  60. # 从回收站恢复
  61. public function recover_commit(){}
  62. public function recover()
  63. {
  64. $where['id'] = array('in', $this->id);
  65. $data = Dever::db('manage/recycler')->select($where);
  66. if ($data) {
  67. foreach ($data as $k => $v) {
  68. $state = Dever::db('manage/recycler')->delete($v['id']);
  69. if (!$state) {
  70. Dever::error('删除失败,请重试');
  71. }
  72. $v['content'] = Dever::json_decode($v['content']);
  73. $state = $this->db->insert($v['content']);
  74. if (!$state) {
  75. Dever::error('删除失败,请重试');
  76. }
  77. }
  78. }
  79. return '操作成功';
  80. }
  81. # 直接删除
  82. public function delete_commit(){}
  83. public function delete()
  84. {
  85. $where['id'] = array('in', $this->id);
  86. $state = $this->db->delete($where);
  87. if (!$state) {
  88. Dever::error('删除失败,请重试');
  89. }
  90. return '操作成功';
  91. }
  92. }