1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php namespace Manage\Api\Page;
- use Dever;
- use Manage\Lib\Page;
- # 操作
- class Oper extends Page
- {
- public function __construct()
- {
- parent::__construct();
- $this->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;
- }
- }
- $where['id'] = array('in', $this->id);
- $state = $this->db->update($where, $data);
- if ($state) {
- return '操作成功';
- } else {
- Dever::error('操作失败');
- }
- }
- # 删除 删除到回收站
- public function recycle_commit(){}
- public function recycle()
- {
- $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 = $this->db->select($where);
- if ($data) {
- foreach ($data as $k => $v) {
- $v['content'] = Dever::json_decode($v['content']);
- $v['table'] = ltrim($v['table'], '/');
- $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 '操作成功';
- }
- }
|