id = Dever::input('id'); if (!$this->id) { Dever::error('无效数据'); } } # 更改某个字段的值 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; } } $where['id'] = array('in', $this->id); $state = $this->db->update($where, $data); if ($state) { return '操作成功'; } else { Dever::error('操作失败'); } } # 删除 删除到回收站 public function del_commit(){} public function del() { $where['id'] = array('in', $this->id); $data = $this->db->select($where)->fetchAll(); if ($data) { foreach ($data as $k => $v) { $insert['table'] = Dever::input('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 = Dever::db('manage/recycler')->select($where); if ($data) { foreach ($data as $k => $v) { $state = Dever::db('manage/recycler')->delete($v['id']); if (!$state) { Dever::error('删除失败,请重试'); } $v['content'] = Dever::json_decode($v['content']); $state = $this->db->insert($v['content']); 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 '操作成功'; } }