public function move()
{
$id = $_GET['id'];
$same_field = isset($_GET['same_field'])?$_GET['same_field']:'pid';
if(!in_array($_GET['type'],array("up","down")) && !in_array($same_field,array('pid','menu_id')))
{
$this->ajaxReturn(0,"参数错误!",0);
}
$where = array();
//取得当前配置信息
$current = $this->model->where("id=".$id)->find();
$where = array($same_field => $current[$same_field]);
//上移:是否已在最上面
if($_GET['type'] == 'up')
{
$where['weight'] = array("lt",$current['weight']);
$neighbor = $this->model->where($where)->order("weight desc")->find();
$sql = M()->getLastSql();
if(!$neighbor)
{
$this->ajaxReturn(0,$sql."移动失败,已经在最上面了!",0);
}
}
//下移:是否已在最下面
if($_GET['type'] == 'down')
{
$where['weight'] = array("gt",$current['weight']);
$neighbor = $this->model->where($where)->order("weight asc")->find();
if(!$neighbor)
{
$this->ajaxReturn(0,"移动失败,已经在最下面了!",0);
}
}
//开始移动
if($neighbor)
{
$neighbor_data = array("weight" => $current['weight']);
$current_data = array("weight" => $neighbor['weight']);
$this->model->data($neighbor_data)->where("id = ".$neighbor['id'])->save();
$this->model->data($current_data)->where("id = ".$current['id'])->save();
$this->ajaxReturn(0,"移动成功!",1);
}
}
{
$id = $_GET['id'];
$same_field = isset($_GET['same_field'])?$_GET['same_field']:'pid';
if(!in_array($_GET['type'],array("up","down")) && !in_array($same_field,array('pid','menu_id')))
{
$this->ajaxReturn(0,"参数错误!",0);
}
$where = array();
//取得当前配置信息
$current = $this->model->where("id=".$id)->find();
$where = array($same_field => $current[$same_field]);
//上移:是否已在最上面
if($_GET['type'] == 'up')
{
$where['weight'] = array("lt",$current['weight']);
$neighbor = $this->model->where($where)->order("weight desc")->find();
$sql = M()->getLastSql();
if(!$neighbor)
{
$this->ajaxReturn(0,$sql."移动失败,已经在最上面了!",0);
}
}
//下移:是否已在最下面
if($_GET['type'] == 'down')
{
$where['weight'] = array("gt",$current['weight']);
$neighbor = $this->model->where($where)->order("weight asc")->find();
if(!$neighbor)
{
$this->ajaxReturn(0,"移动失败,已经在最下面了!",0);
}
}
//开始移动
if($neighbor)
{
$neighbor_data = array("weight" => $current['weight']);
$current_data = array("weight" => $neighbor['weight']);
$this->model->data($neighbor_data)->where("id = ".$neighbor['id'])->save();
$this->model->data($current_data)->where("id = ".$current['id'])->save();
$this->ajaxReturn(0,"移动成功!",1);
}
}