id = Dever::input('id'); if (!$this->id) { Dever::error('无效数据'); } $this->checkFunc(); } # 更改某个字段的值 public function up_commit(){} public function up() { $input = Dever::input(); $field = explode(',', Dever::input('field')); foreach ($field as $k => $v) { if (isset($input[$v]) && $value = $input[$v]) { if (is_array($value)) { $value = implode(',', $value); } $data[$v] = $value; } } if (isset($this->config['up_start']) && $this->config['up_start']) { list($this->id, $data) = Dever::call($this->config['up_start'], array($this->id, $data)); } $where['id'] = array('in', $this->id); $state = $this->db->update($where, $data); if ($state) { if (isset($this->config['up_end']) && $this->config['up_end']) { Dever::call($this->config['up_end'], array($this->id, $data)); } return '操作成功'; } else { Dever::error('操作失败'); } } # 删除 删除到回收站 public function recycle_commit(){} public function recycle() { $where['id'] = array('in', $this->id); $data = $this->db->select($where); if ($data) { foreach ($data as $k => $v) { $insert['table'] = $this->db->config['load']; $insert['table_id'] = $v['id']; $insert['content'] = Dever::json_encode($v); $state = Dever::db('manage/recycler')->insert($insert); if (!$state) { Dever::error('删除失败,请重试'); } $state = $this->db->delete($v['id']); if (!$state) { Dever::error('删除失败,请重试'); } } } return '操作成功'; } # 从回收站恢复 public function recover_commit(){} public function recover() { $where['id'] = array('in', $this->id); $data = $this->db->select($where); if ($data) { foreach ($data as $k => $v) { $v['content'] = Dever::json_decode($v['content']); $state = Dever::db($v['table'])->insert($v['content']); if (!$state) { Dever::error('恢复失败,请重试'); } $state = $this->db->delete($v['id']); if (!$state) { Dever::error('恢复失败,请重试'); } } } return '操作成功'; } # 直接删除 public function delete_commit(){} public function delete() { $where['id'] = array('in', $this->id); $state = $this->db->delete($where); if (!$state) { Dever::error('删除失败,请重试'); } return '操作成功'; } }