<?php
/**
 * 链接管理
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */

namespace Admin\Controller;
class UrlRulesController extends BaseController{
   public function _initialize(){
		parent::_initialize();
       $device_arr=array('0'=>'电脑端','1'=>'移动端','3'=>'微信端','4'=>'小程序');
       $this->assign('device_arr',$device_arr);
    }
    public function ajaxgetgoods_give(){
	      $id=I('id');
	      $vau=I('value');
          $m=M("UrlRules");
          $se=$m->where('id='. $id)->find();
          $result=array();
          $result['status']=1;
         $result['is_module']=$se['is_module'];//是否关联
         $result['urlparam']=$se['urlparam'];//是否参数
         $result['module']=$se['module'];
         $result['moduleid']=$se['moduleid'];
         $result['modulename']=$se['modulename'];
         $result['is_param']=$se['is_param'];//是否参数
         $result['urlparam']=$se['urlparam'];
         $result['theurl']=$se['theurl'];//z地址表达式
                      
           $is_module=$result['is_module'];
           $module=$result['module']; 
           $modulename=$result['modulename'];
           $moduleid=$result['moduleid'];
           $data_goods=''; 
        if($is_module == 1){
	            $ms=M($module);
	            if(empty($module))die;
	            if($se['is_tree'])$fields=$ms->getDbFields();
	            if($se['is_tree'] && in_array('pid', $fields)){
	            	$selarr=$ms->field($moduleid." as id,pid,".$modulename.' as name')->select();
	            	$data_goods=$this->getNodeTree($selarr,$vau);
	            }else{
	          	   $selid=$ms->field($moduleid.",".$modulename)->select();
	               foreach ($selid as $ke => $val) {        	     
	        	       if($vau==$val[$moduleid]){
	                           $data_goods.='<option value="'.$val[$moduleid].'" selected="selected" >'.$val[$modulename].'</option>'; 
	        	       }else{
	                        $data_goods.='<option value="'.$val[$moduleid].'">'.$val[$modulename].'</option>'; 

	        	       }
	               }

	          }

            
          }
           
          $result['optin']=$data_goods;
	      $this->ajaxReturn($result);


    }

    /* 得到节点树 */
	private function getNodeTree($arrs,$pid = '') {
	   $Tree = new \Common\Vendor\Tree();
       $treemini=$Tree->treemini($arrs);
       return  $Tree->treeminioption($treemini,$pid);
    }
  
  	


}
?>