<?php
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class Product extends HC_Controller
{
	//注意无须构造函数,使用了构造函数得重构父类 parent::__construct();
	private $power_arr = array();
	function __construct()
	{
		parent::__construct();
		$this->load_lang('adminsys/product');
		
		$this -> load_model('admin'); 
		$this -> power_arr = $this -> admin_mod -> get_power( 'product' );
		
		$this -> load_db();
		$this -> load('helper'); //加载辅助类
		$this -> load_model('pro_sort'); //加载产品分类模型
		$this -> load_model('brand'); 	 //加载品牌模型
		$this -> load_model('pro_type'); 	 //加载类型模型
		//$this-> lang['txt_select'];
	}
 
	
	function info_list()
	{
		$this -> load('page',$this->lang['page']);
		
		$this -> page -> set_page_size(12);
		
		$keyword 	= $this -> input ->  req["keyword"];
		$prs_id 	= $this -> input ->  req["prs_id"];
		$list_val   = $this -> input ->  req["list_val"];
		$list_type  = $this -> input ->  req["list_type"];


		//只能查询一次分类数据
		$prs_info  		= $this -> pro_sort_mod -> get_sort();

		//生成分类ID对应值
		$prs_key_val 	= $this -> helper -> mapped_key_value( $prs_info , $key_index = 'prs_id');
	
		//获取子分类所有ID值
		if( $prs_id !='' ){
		
			$prs_son_id = $this -> pro_sort_mod -> get_prs_son_id( $prs_id ,$prs_key_val );
			$where_add 			.= " AND ( p.prs_id IN ( ".implode(",",$prs_son_id )." ) )";
		}
		
		//生成分类选择控件
		$prs_select_str = $this -> helper -> build_out_str( $prs_info , $object_name = 'prs_id', $object_id = 'prs_id' , $object_val_str = 'prs_id', $object_txt_str = 'prs_name', $prs_id  ,$lang_txt = $this-> lang['txt_select'] );
		
		
		if($keyword!='')
		{ 	
			//$keyword_url 	= urldecode($keyword); 
			$where_add .= " AND ( p.pro_name LIKE  '%".$keyword."%' )";  
		}

		$order_by_val = "";
		if($list_val!='' and $list_type =='DESC' )
		{

			$order_by_val = $list_val ."  DESC ";
		}elseif($list_val!='' and $list_type =='ASC')
		{
			$order_by_val = $list_val." ASC";
		}else{
			$order_by_val = " p.pro_up_time DESC , `pro_id` DESC ";	
		}
		
		//列表字段显示
		$show_arr = array('pro_id' => 1,'pro_name'=>1,'pro_img'=>0,'prs_id'=>1,'pro_num'=>1,'pro_sell_price'=>1,'pro_enabled'=>1,'pro_up_time'=>1);
		$field_show = $this -> helper -> get_th_list( $show_arr , $list_val , $list_type , $lang_arr = $this->lang['field_list'] );
		
		$show_arr = $this -> admin_mod -> get_power_detail( $this -> power_arr['admp_action'] , $show_arr ,'info_list');
		
		$sql_query = " SELECT p.pro_id, p.pro_name,p.prs_id,p.pro_num, p.pro_unit,pro_img, p.pro_sell_price, p.pro_enabled , p.pro_up_time   FROM  ".$this -> db -> prefix."product as p WHERE pro_delete = 0  $where_add   ORDER BY $order_by_val LIMIT  ". $this -> page ->get_limit_val();
		
		$info 		= $this -> db -> select_info( $sql_query );
		
		foreach((array)$info as $pkey => $pval )
		{
			 $info[$pkey]["pro_img"] = $this -> helper -> build_img( $pval["pro_img"] ) ;
		}
		
		$sql_query 	= " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."product as p  WHERE pro_delete = 0  $where_add  ORDER BY p.`pro_id`  ";
		
		$infocount 	= $this -> db -> select_one( $sql_query );
		//$this->lang['page'] 
		
		$page_str 	= $this -> page -> get_admin_page(  $infocount["CNUM"] );
		
		$this -> view -> assign('field_show',$field_show);

		$this -> view -> assign('list_val',$list_val);
		$this -> view -> assign('list_type',$list_type);
	
		$this -> view -> assign('prs_id',$prs_id);
		$this -> view -> assign('keyword',$keyword);


		$this -> view -> assign('prs_key_val',$prs_key_val);
		$this -> view -> assign('prs_select_str',$prs_select_str);

		$this -> view -> assign('page_str',$page_str);
		$this -> view -> assign('info',$info);
		$this -> view -> display('product.tpl');
		
	}
	
	
	
	

	
	function add()
	{	
		
		$this -> admin_mod -> get_power_detail( $this -> power_arr['admp_action'] , '' ,'add_info' );
		//echo $lang_txt = $this-> lang['txt_select'];
		$brand_info 	 = $this -> brand_mod -> get_brand();
 		$brand_select    = $this -> helper ->build_select_obj( $brand_info , $object_name = 'bra_id', $object_id = 'bra_id' , $object_val_str = 'bra_id', $object_txt_str = 'bra_name','',$lang_txt  = $this-> lang['txt_select']);
		
		$pro_type_info 	 = $this -> pro_type_mod -> get_pro_type();
 		$pro_type_select = $this -> helper ->build_select_obj( $pro_type_info , $object_name = 'prt_id', $object_id = 'prt_id' , $object_val_str = 'prt_id', $object_txt_str = 'prt_name', '', $lang_txt = $this-> lang['txt_select'],'get_pro_attribute(this)');
		
		$prs_info 		 = $this -> pro_sort_mod -> get_sort();
		$pro_sort_select = $this -> helper -> build_out_str( $prs_info , $object_name = 'prs_id', $object_id = 'prs_id' , $object_val_str = 'prs_id', $object_txt_str = 'prs_name', '', $lang_txt = $this-> lang['txt_select'] );

		 $ckeditorLoad 	= $this -> helper -> load_ckeditor( 'pro_content' );	//加载文本编辑器
		 $this -> view -> assign( 'ckeditorLoad', $ckeditorLoad);
		
		$this -> view -> assign( 'edit_submit', $this-> lang['add_submit']);
		$this -> view -> assign( 'txt_title', $this-> lang['add_title']);
		$this -> view -> assign( 'pro_sort_select', $pro_sort_select);
		$this -> view -> assign( 'pro_type_select', $pro_type_select);
		$this -> view -> assign( 'brand_select', $brand_select);
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?load=product&act=add_info");
		$this -> view -> display('product_edit.tpl');
		
	}
	
	function add_info()
	{
		$this -> admin_mod -> get_power_detail( $this -> power_arr['admp_action'] , '' ,'add_info' );
		$pro_nameval 			= $this -> input ->  post["pro_name"];
		$pro_phoneticizeval 	= $this -> input ->  post["pro_phoneticize"];
		$prs_id 				= $this -> input ->  post["prs_id"];
		$bra_idval 				= $this -> input ->  post["bra_id"];
		$pro_barcodeval 		= $this -> input ->  post["pro_barcode"];
		$pro_specval 			= $this -> input ->  post["pro_spec"];	
		$pro_numval 			= $this -> input ->  post["pro_num"];
		$pro_unitval 			= $this -> input ->  post["pro_unit"];
		$pro_productionval 		= $this -> input ->  post["pro_production"];
		$pro_sell_priceval 		= $this -> input ->  post["pro_sell_price"];
		$pro_market_priceval 	= $this -> input ->  post["pro_market_price"];
		$pro_lowest_priceval 	= $this -> input ->  post["pro_lowest_price"];
		$pro_buy_priceval 		= $this -> input ->  post["pro_buy_price"];
		$pro_contentval 		= $this -> input ->  post["pro_content"];
		$pro_enabledval 		= $this -> input ->  post["pro_enabled"];	
		$pra_id_price 			= $this -> input ->	 post["pra_id_price"];
		$pra_id 				= $this -> input ->	 post["pra_id"];
		$pro_imgarrayval 		= $this -> input ->  post["pro_img"];
		
		if($pro_imgarrayval[0]!=''){
			$pro_imgval 			= $pro_imgarrayval[0];
		}else{
			
			foreach($pro_imgarrayval as $img_val){
				if($img_val!=''){
					$pro_imgval 	= $img_val;
				 	break;
				}
			}	
		}

		
		//处理类型数据
		$prt_idval 		= $this -> input ->  post["prt_id"];
		
		if($prt_idval !=''){
			$pra_id_arr = $this -> input ->post["pra_id"];
		}
		
		if( $pro_nameval !='' and $prs_id !='' and $pro_sell_priceval !='' and $pro_contentval != '' )
		{
			//应该改库编码不能重复，名称可以重复
			if($pro_barcodeval !=''){
				 $sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."product  WHERE pro_barcode = '".$pro_barcodeval."' ORDER BY `pro_id` ";
				$info = $this -> db -> select_one($sql_query);
			}
			if( $info["CNUM"] < 1 )
			{
				
				$pro_up_timeval  = $pro_add_timeval = date("Y-m-d H:i:s");
				
				$use_idval		 = $_SESSION["emplyeeUser"]["use_id"];
				
				//var_dump($this -> db);
				$pro_specval 	= strip_tags($pro_specval,'<br><p>');
				$pro_contentval = strip_tags($pro_contentval,'<br><p>');
				
				$insertpro =" INSERT INTO `".$this -> db -> prefix."product` (`pro_name` , `pro_phoneticize` , `prs_id` ,`bra_id` ,`prt_id` , `pro_barcode` , `pro_spec` , `pro_num` ,`pro_img`, `pro_unit` , `pro_production` , `pro_sell_price`  , `pro_market_price` , `pro_lowest_price` , `pro_buy_price` , `pro_content` ,`pro_add_time`,`pro_up_time` ,`use_id` ) VALUES (  '$pro_nameval', '$pro_phoneticizeval', '$prs_id', '$bra_idval', '$prt_idval', '$pro_barcodeval', '$pro_specval', '$pro_numval','$pro_imgval', '$pro_unitval', '$pro_productionval', '$pro_sell_priceval', '$pro_market_priceval', '$pro_lowest_priceval', '$pro_buy_priceval', '$pro_contentval', '$pro_add_timeval','$pro_up_timeval','$use_idval')";
				
				$pro_insert_id = $this -> db -> insert_sql($insertpro);

				
				//系统得自动生动编码
				if( $pro_barcodeval == '')
				{
					$this -> build_code( $pro_insert_id );
				}
				foreach((array)$pro_imgarrayval as $pikey => $pival )
				{
					
					if($pival!='' and $pikey!=0 )
					{
					 	$insertimg =" INSERT INTO `".$this -> db -> prefix."pro_img` (`pro_id` , `pri_url` , `pri_desc`  ) VALUES (  '$pro_insert_id', '$pival', '$pri_descval')";
						$imgId = $this -> db -> insert_sql($insertimg);
					}
				
				}
				
				//添加类型值
				if($prt_idval !='' ){

					foreach((array)$pra_id as $k => $v)
					{
					
						foreach($v as $inkey => $inval)
						{
					//var_dump($inval);
					//exit();
							$item_prv_price = '';
							
							if( $pra_id_price[$k][$inkey] ){
						
								$item_prv_price = $pra_id_price[$k][$inkey];
							}
							echo 	$insert_prv_val =" INSERT INTO `".$this -> db -> prefix."pro_att_value` ( `pro_id` , `pra_id` ,`prv_value` ,`prv_price` ) VALUES (  '$pro_insert_id', '$k', '$inval' ,'$item_prv_price' )";
								$prv_id = $this -> db -> insert_sql($insert_prv_val);
						}
					}
					//pav_id 产品属性序号ID号	pro_id 产品ID号	pra_id 产品属性参照表	prv_value 属性值	prv_price 
	
				}

				$this -> view ->  assign('info_title',$this->lang['add_success']);
				$this -> view ->  assign('URL_TIME',URL_TIME);
				$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=product&act=info_list");
				$this -> view ->  display('suggestion.tpl');	
			}else{
				
				$this -> view ->  assign('info_title',$this->lang['err_info_exist']);
				$this -> view ->  assign('URL_TIME',URL_TIME);
				$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=product&act=add");
				$this -> view ->  display('suggestion.tpl');	
			}
			
		}else{
			
			$this -> view ->  assign('info_title',$this->lang['err_info_missing']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=product&act=add");
			$this -> view ->  display('suggestion.tpl');		}
			//var_dump($_REQUEST);
	}
	


	function delete()
	{
		$this -> admin_mod -> get_power_detail( $this -> power_arr['admp_action'] , '' ,'delete' );
		$infoid =  $this -> input ->  delUrl($_REQUEST["id"]);
		
		$del_pro ="DELETE FROM `".$this -> db -> prefix."product` WHERE `pro_id` in ( $infoid ) ";
		$this -> db -> query_sql($del_pro);
		
		//删除图片表中信息
		$del_img =" DELETE FROM `".$this -> db -> prefix."pro_img` WHERE `pro_id`  in ( $infoid ) ";
		$imgId = $this -> db -> query_sql($del_img);
		
		//删除产品属性表中信息
		$del_img =" DELETE FROM `".$this -> db -> prefix."pro_att_value` WHERE `pro_id`  in ( $infoid ) ";
		$imgId = $this -> db -> query_sql($del_img);
		
		
		$this -> view ->  assign('info_title',$this->lang['del_success']);
		$this -> view ->  assign('URL_TIME',URL_TIME);
		$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=product&act=trash_list");
		$this -> view ->  display('suggestion.tpl');
		
	}

	
	
	
	function info()
	{

		$idval = $this -> input ->  get["id"];
		
		//只能查询一次分类数据
		$prs_info  		= $this -> pro_sort_mod -> get_sort();
		$brand_info 	= $this -> brand_mod 	-> get_brand();
		$pro_type_info 	= $this -> pro_type_mod -> get_pro_type();
 		$this -> admin_mod -> get_power_detail( $this -> power_arr['admp_action'] , '' ,'edit_info' );

		
		if( $idval!='' )
		{
			$sql_query = " SELECT *  FROM  ".$this -> db -> prefix."product  WHERE pro_id = '".$idval."' ORDER BY `pro_id` ";
			$info = $this -> db -> select_one($sql_query);
			
			//$info["pro_imgval"][1] = $info["pro_img"]; 
			
			$sql_query = " SELECT pri_id , pri_url  FROM  ".$this -> db -> prefix."pro_img  WHERE pro_id = $idval  GROUP BY pri_id ORDER BY `pri_id` limit 10 ";
			
			$img_info = $this -> db -> select_info($sql_query);

			//生成分类选择控件
			$prs_select_str = $this -> helper -> build_out_str( $prs_info , $object_name = 'prs_id', $object_id = 'prs_id' , $object_val_str = 'prs_id', $object_txt_str = 'prs_name', $info['prs_id']  ,$lang_txt = $this-> lang['txt_select'] );
			
			$brand_select    = $this -> helper ->build_select_obj( $brand_info , $object_name = 'bra_id', $object_id = 'bra_id' , $object_val_str = 'bra_id', $object_txt_str = 'bra_name',$info['bra_id'],$lang_txt = $this-> lang['txt_select']);
			
			$pro_type_select    = $this -> helper ->build_select_obj( $pro_type_info , $object_name = 'prt_id', $object_id = 'prt_id' , $object_val_str = 'prt_id', $object_txt_str = 'prt_name', $info['prt_id'], $lang_txt = $this-> lang['txt_select'],'get_pro_attribute(this)');
			
			//var_dump($info);
			$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?load=product&act=edit_info");
			$this -> view ->  assign('info',$info);
		}
		
		//Product::getSort();
		
		//$this -> helper -> load_ckeditor( 'pro_content' ,$textValue = $info["pro_content"] );	//加载文本编辑器
		$ckeditorLoad 	= $this -> helper -> load_ckeditor( 'pro_content'  , $info["pro_content"] );
		
		$this -> view -> assign('img_info',$img_info);
		$this -> view -> assign('pro_sort_select',$prs_select_str);
		$this -> view -> assign( 'pro_type_select' ,$pro_type_select);
		$this -> view -> assign( 'brand_select' ,$brand_select);
		$this -> view -> assign( 'ckeditorLoad' ,$ckeditorLoad); //加载文本编辑器
		$this -> view -> assign( 'edit_submit', $this-> lang['edit_submit']);
		$this -> view -> assign( 'txt_title', $this-> lang['edit_title']);
		$this -> view -> display('product_edit.tpl');
	
	}
	
	
	function edit_info()
	{	
		$pro_idval 				= $this -> input ->  post["pro_id"];
		$pro_nameval 			= $this -> input ->  post["pro_name"];
		$pro_phoneticizeval 	= $this -> input ->  post["pro_phoneticize"];
		$prs_id 				= $this -> input ->  post["prs_id"];
		$bra_idval 				= $this -> input ->  post["bra_id"];
		$pro_barcodeval 		= $this -> input ->  post["pro_barcode"];
		$pro_specval 			= $this -> input ->  post["pro_spec"];	
		$pro_numval 			= $this -> input ->  post["pro_num"];
		$pro_unitval 			= $this -> input ->  post["pro_unit"];
		$pro_productionval 		= $this -> input ->  post["pro_production"];
		$pro_sell_priceval 		= $this -> input ->  post["pro_sell_price"];
		$pro_market_priceval 	= $this -> input ->  post["pro_market_price"];
		$pro_lowest_priceval 	= $this -> input ->  post["pro_lowest_price"];
		$pro_buy_priceval 		= $this -> input ->  post["pro_buy_price"];
		$pro_contentval 		= $this -> input ->  post["pro_content"];
		$pro_enabledval 		= $this -> input ->  post["pro_enabled"];	

		$pro_imgarrayval 		= $this -> input ->  post["pro_img"];
		if($pro_imgarrayval[0]){
			$pro_imgval 			= $pro_imgarrayval[0];
		}else{
			$pro_imgval 			= $pro_imgarrayval[1];
		}
		$pra_id_price =  $this -> input ->post["pra_id_price"];
		
		//处理类型数据
		$prt_idval 				= $this -> input ->  post["prt_id"];
		
		if($prt_idval !='')
		{
			$pra_id_arr = $this -> input ->post["pra_id"];
		}
		
		//$pro_imgval = $pro_imgarrayval[1];
		
		
		if($pro_idval !='' and  $pro_nameval !='' and $prs_id !='' and $pro_sell_priceval !='' and $pro_contentval != '' )
		{
			$pro_up_timeval  = date("Y-m-d H:i:s");
			
			$pro_specval 	= strip_tags($pro_specval,'<br><p><img>');
			$pro_contentval = strip_tags($pro_contentval,'<br><p><img>');
			
			$updatesql = " UPDATE `".$this -> db -> prefix."product` SET  pro_name = '".$pro_nameval."' , pro_phoneticize = '".$pro_phoneticizeval."' , prs_id = '".$prs_id."', pro_barcode = '".$pro_barcodeval."', pro_spec = '".$pro_specval."', pro_num = '".$pro_numval."', pro_img = '".$pro_imgval."', pro_unit = '".$pro_unitval."', pro_production = '".$pro_productionval."', pro_sell_price = '".$pro_sell_priceval."', pro_market_price = '".$pro_market_priceval."', pro_lowest_price = '".$pro_lowest_priceval."', pro_buy_price = '".$pro_buy_priceval."' , pro_content = '".$pro_contentval."' , pro_up_time = '".$pro_up_timeval."' WHERE  pro_id = '".$pro_idval."' ";
			
			$this -> db -> query_sql( $updatesql );
			
			
			//删除原图片
			$del_img =" DELETE FROM `".$this -> db -> prefix."pro_img` WHERE `pro_id` = $pro_idval ";
			$this -> db -> query_sql($del_img);
			//添加新图片
			foreach($pro_imgarrayval as $pikey => $pival )
			{
				if($pival!='' and $pikey!=1 )
				{
					$pri_urlval = $pival;
					
					$insertimg =" INSERT INTO `".$this -> db -> prefix."pro_img` (`pro_id` , `pri_url` , `pri_desc`  ) VALUES (  '$pro_idval', '$pri_urlval', '$pri_descval')";
					
					$this -> db -> insert_sql($insertimg);
					}	
			}
			
			//删除原属性
			$del_prv =" DELETE FROM `".$this -> db -> prefix."pro_att_value` WHERE `pro_id` = $pro_idval ";
			$this -> db -> query_sql($del_prv);
			
			//添加新属性
			$pra_id = $this -> input ->post["pra_id"];
			
			//var_dump($pra_id);
			foreach((array)$pra_id as $k => $v)
			{

					foreach($v as $inkey => $inval)
					{
						$item_prv_price = '0';
							
						if( $pra_id_price[$k][$inkey] ){
						
							$item_prv_price = $pra_id_price[$k][$inkey];
						}
							$insert_prv_val =" INSERT INTO `".$this -> db -> prefix."pro_att_value` ( `pro_id` , `pra_id` ,`prv_value` ,`prv_price` ) VALUES (  '$pro_idval', '$k', '$inval' ,'$item_prv_price' )";
							$this -> db -> insert_sql($insert_prv_val);
					}
						
			}

			$this -> view ->  assign('info_title',$this->lang['edit_success']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=product&act=info_list");
			$this -> view ->  display('suggestion.tpl');
				
		}else{
		
			$this -> view ->  assign('info_title',$this->lang['err_info_missing'] );
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=product&act=info&id=".$pro_idval);
			$this -> view ->  display('suggestion.tpl');	
		}
		
	}

	function show()
	{
		//$indel = implode(',', $delArray);

		$infoid =  $this -> input ->  delUrl($_REQUEST["id"]);
		
		$upshow = " UPDATE `".$this -> db -> prefix."product` SET pro_enabled = 1  WHERE  `pro_id` in ( $infoid ) ";

		$this -> db -> query_sql($upshow);
		$this -> view ->  assign('info_title',$this->lang['show_success']);
		$this -> view ->  assign('URL_TIME',URL_TIME);
		$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=product&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}


	
	function recycle()
	{
		//$indel = implode(',', $delArray);

		$infoid =  $this -> input ->  delUrl($_REQUEST["id"]);
		
		$upshow = " UPDATE `".$this -> db -> prefix."product` SET pro_delete = 1  WHERE  `pro_id` in ( $infoid ) ";
		$this -> db -> query_sql($upshow);
		
		$this -> view ->  assign('info_title',$this->lang['recycle_success']);
		$this -> view ->  assign('URL_TIME',URL_TIME);
		$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=product&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}
	
	function restore()
	{
		//$indel = implode(',', $delArray);

		$infoid =  $this -> input ->  delUrl($_REQUEST["id"]);
		
		$upshow = " UPDATE `".$this -> db -> prefix."product` SET pro_delete =  0  WHERE  `pro_id` in ( $infoid ) ";

		$this -> db -> query_sql($upshow);
		$this -> view ->  assign('info_title',$this->lang['restore_success']);
		$this -> view ->  assign('URL_TIME',URL_TIME);
		$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=product&act=trash_list");
		$this -> view ->  display('suggestion.tpl');
	}
	
	
	function hide()
	{
		//$indel = implode(',', $delArray);
		
		$infoid =  $this -> input ->  delUrl($_REQUEST["id"]);
		/*
		if($idval)
		{
			$infoid = implode(',', $idval);
		}*/

		$uphide = " UPDATE `".$this -> db -> prefix."product` SET pro_enabled = 0  WHERE `pro_id` in ( $infoid ) ";

		$this -> db -> query_sql($uphide);
		$this -> view ->  assign('info_title',$this->lang['hide_success']);
		$this -> view ->  assign('URL_TIME',URL_TIME);
		$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=product&act=trash_list");
		$this -> view ->  display('suggestion.tpl');
	}
	
	
	
	function build_code( $proid )
	{
		if($proid)
		{
			$znum = 10 - strlen($proid);
			$str = '';
			
			for( $zi=0;  $zi < $znum; $zi++)
			{
				$str ='0'.$str;
			}
			
			$str = 'N'.$str.$proid;
			
			$updatesql = "UPDATE `".$this -> db -> prefix."product` SET pro_barcode = '".$str."' WHERE  pro_id = '".$proid."' ";	
			
			$this -> db -> query_sql( $updatesql );
			
			return $str;
			
		}else{
			return false;
		}
		
	}
	
	function trash_list()
	{

		$this -> load('page',$this->lang['page']);
		
		$this -> page -> set_page_size(12);
		
		$keyword 	= $this -> input ->  req["keyword"];
		$prs_id 	= $this -> input ->  req["prs_id"];
		$list_val   = $this -> input ->  req["list_val"];
		$list_type  = $this -> input ->  req["list_type"];


		//只能查询一次分类数据
		$prs_info  		= $this -> pro_sort_mod -> get_sort();

		//生成分类ID对应值
		$prs_key_val 	= $this -> helper -> mapped_key_value( $prs_info , $key_index = 'prs_id');
	
		//获取子分类所有ID值
		if( $prs_id !='' ){
		
			$prs_son_id = $this -> pro_sort_mod -> get_prs_son_id( $prs_id ,$prs_key_val );
			$where_add 			.= " AND ( p.prs_id IN ( ".implode(",",$prs_son_id )." ) )";
		}
		
		//生成分类选择控件
		$prs_select_str = $this -> helper -> build_out_str( $prs_info , $object_name = 'prs_id', $object_id = 'prs_id' , $object_val_str = 'prs_id', $object_txt_str = 'prs_name', $prs_id  ,$lang_txt = $this-> lang['txt_select'] );
		
		
		if($keyword!='')
		{ 	
			$keyword_url 	= urldecode($keyword); 
			$where_add .= " AND ( p.pro_name LIKE  '%".$keyword."%' )";  
		}

		$order_by_val = "";
		if($list_val!='' and $list_type =='DESC' )
		{

			$order_by_val = $list_val ."  DESC ";
		}elseif($list_val!='' and $list_type =='ASC')
		{
			$order_by_val = $list_val." ASC";
		}else{
			$order_by_val = " p.pro_up_time DESC , `pro_id` DESC ";	
		}
		
		//列表字段显示
		$show_arr = array('pro_id' => 1,'pro_name'=>1,'pro_img'=>0,'prs_id'=>1,'pro_num'=>1,'pro_sell_price'=>1,'pro_enabled'=>1,'pro_up_time'=>1);
		$field_show = $this -> helper -> get_th_list( $show_arr , $list_val , $list_type , $lang_arr = $this->lang['field_list'], 'trash_list');
		$sql_query = " SELECT p.pro_id, p.pro_name,p.prs_id,p.pro_num, p.pro_unit,pro_img, p.pro_sell_price, p.pro_enabled , p.pro_up_time   FROM  ".$this -> db -> prefix."product as p WHERE pro_delete = 1  $where_add   ORDER BY $order_by_val LIMIT  ". $this -> page ->get_limit_val();
		
		$info 		= $this -> db -> select_info($sql_query);
		
		foreach((array)$info as $pkey => $pval )
		{
			 $info[$pkey]["pro_img"] = $this -> helper -> build_img( $pval["pro_img"] ) ;
		}
		
		$sql_query 	= " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."product as p  WHERE pro_delete = 1  $where_add  ORDER BY p.`pro_id`  ";
		
		$infocount 	= $this -> db -> select_one( $sql_query );
		//$this->lang['page'] 
		
		$page_str 	= $this -> page -> get_admin_page(  $infocount["CNUM"] , 'trash_list');
		
		$this -> view -> assign('field_show',$field_show);

		$this -> view -> assign('list_val',$list_val);
		$this -> view -> assign('list_type',$list_type);
	
		$this -> view -> assign('prs_id',$prs_id);
		$this -> view -> assign('keyword',$keyword);


		$this -> view -> assign('prs_key_val',$prs_key_val);
		$this -> view -> assign('prs_select_str',$prs_select_str);

		$this -> view -> assign('page_str',$page_str);
		$this -> view -> assign('info',$info);
		$this -> view -> display('product_trash.tpl');
		
		
	}

}
