HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/8.2.20
System: Linux 825a8fd6cf8c 3.10.0-1160.95.1.el7.x86_64 #1 SMP Mon Jul 24 13:59:37 UTC 2023 x86_64
User: apache (48)
PHP: 8.2.20
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/themes/frameMyrskyNew/stock_manage.php
<?php 
/**
 * @desc 库存管理类
 * @author SCIEN
 * @since 2011-05-30
 */

include_once("config.php");
include_once("auto_charset_to_utf8.php");
 
class StockManage{
	
    /*************Attributes******************/
	//public $category_array;
	public $wpdb;
	/*************Methods******************/
	
	public function __construct(){
		//$this->category_array = getEnumArray("part_inventory","category");
		global $servers;
		
		$dbuser = $servers["db"]["username"];//"root";
		$dbpassword = $servers["db"]["password"];//"SnowGeese";
		$dbname = $servers["db"]["dbname"];//"snow7_led";
		$dbhost = $servers["db"]["dbhost"];//"localhost";
		//$db = new clsDBMyConn();
		$this->wpdb = new wpdb($dbuser, $dbpassword, $dbname, $dbhost,'-1');
		//$this->wpdb = new wpdb($dbuser, $dbpassword, $dbname, $dbhost);
		//$this->wpdb->charset = 'latin1';
		
		//$this->userdefined_category_array = getEnumArray("userdefined_part_name_config","category");
		$results = $this->wpdb->get_row("show columns from userdefined_part_name_config like 'category'");	
		$enum_list = $results->Type;
		#增加匹配字符查询,查找匹配的类型,(附件管理中的查询需要改变)。
		 eval("\$found = eregi(\"^set\",\"$enum_list\");");
		if($found)
			$enum_list = explode(",",strtr($enum_list,array("set("=>"",")"=>"","'"=>"")));
		else
			$enum_list = explode(",",strtr($enum_list,array("enum("=>"",")"=>"","'"=>"")));

		if(!empty($enum_list)){
			$this->userdefined_category_array = $enum_list;
		}else{
			$this->userdefined_category_array = array();
		}
	//	$t = $this->getProducts(array("Resistor"));
		
		//var_dump($this->userdefined_category_array);
	}
	
	/**
	 * @desc 根据产品类型获取产品列表
	 * @param String $category
	 */
	public function getProductByCategory($category=null){
		
		return $this->getProducts(array($category));		
	
	}
	
	/**
	 * @desc 根据类型、搜索条件取得产品[只能取自定义元件]
	 * @param Array $category
	 * @param String $search_value
	 */
	public function getProducts($category=null,$search_value=null,$part_id=null,&$total_record_count=null,$start_id=null,$views=null,$order_by=null,$order_by_sort="ASC"){
		global $servers;
		$db =   $this->wpdb;
		$db0 =  $this->wpdb;
		$db1 =  $this->wpdb;				
		if(empty($category)){
			$category = $servers['category'];
		}
		$goods = array();
		$category = implode("','",$category);
		$condition = !empty($category) ? " AND category IN('$category') " : "";
		$condition .= !empty($part_id) ? " AND part_id='$part_id' " : "";
		
		if(($start_id>=0)&&!empty($views)){
			$limit_sql = " limit $start_id, $views";
		}
		if(!empty($order_by)){
			$order_by_sql = " ORDER BY $order_by $order_by_sort";
		}
		
		//取出public为Y的产品
		$sql = "SELECT part_inventory.* FROM part_inventory WHERE public='Y' $condition $order_by_sql $limit_sql";	
		//$db->query($sql);
		$results = $db->get_results($sql,ARRAY_A);
		$results = empty($results) ? array() : $results;
		//$toresultstal_record_count = count($results);//$db->num_rows();
		$total_record_count = count($results);//$db->num_rows();
		//if(($total_record_count==-1)||($toresultstal_record_count<=0))return array();//获取记录总数		
		foreach($results as $row){			
			$p_no = $row["name"];//$db->f("category");//产品类型			
			$category_temp = $row["category"];//$db->f("category");//产品类型			
			$table_name = $category_temp!="LEDs"? "part_".$category_temp."s":"part_".$category_temp;
			$table_name = strtolower($table_name);
			$part_id =  $row["part_id"];//$db->f("part_id");//库存产品ID	
			$lead_time = $row["Material_lead_time"];
			//$name = CCDLookUp("name",$table_name, "part_id='$part_id'", $db0);//产品名称
			$name = $db0->get_var("select name from $table_name where part_id='$part_id'");//产品名称
			$description = $row["description"];//$db->f("description");//库存产品描述
			$ours_amount_in_stock = $row["ours_amount_in_stock"];//$db->f("ours_amount_in_stock");//产品库存可用数量
			$real_amount_in_stock = $row["real_amount_in_stock"];//$db->f("real_amount_in_stock");//产品库存实际数量
			//如果自定义元件
			if(in_array($category_temp, $this->userdefined_category_array)){
				$search_parts = array();
				if(!empty($search_value)){
					$sql_temp = "SELECT part_id FROM part_".$category_temp."s_parameter WHERE value LIKE '%$search_value%'";
					$results_temp = $db0->get_results($sql_temp,ARRAY_A)?$db0->get_results($sql_temp,ARRAY_A) : array();
					foreach($results_temp as $item){
						$search_parts[] = $item["part_id"];//$db0->f("part_id");
					}				
					$sql_name = "SELECT * FROM `$table_name` WHERE name LIKE '%$search_value%' ";
					$results_temp2 = $db0->get_results($sql_name,ARRAY_A)?$db0->get_results($sql_name,ARRAY_A):array();
					foreach($results_temp2 as $item){
						$search_parts[] = $item["part_id"];//$db0->f("part_id");
					}
					
					//var_dump($search_parts);die();
					if(!in_array($part_id, $search_parts)){
						continue;
					}			
				}
				
				//产品参数
				$sql_temp = "SELECT * FROM part_".$category_temp."s_parameter WHERE part_id='$part_id' ";						
				$results = $db0->get_results($sql_temp,ARRAY_A);
				$results = empty($results) ? array() : $results ;
				foreach($results as $item){
					$parameter_code = $item["parameter_code"];//$db0->f("parameter_code");//参数编码
					$parameter_name = gb2312_to_utf8($db1->get_var("select disp_name from userdefined_part_parameter_config where parameter_code='$parameter_code' and category='$category_temp'"));
					if(empty($parameter_name))continue;
					$value = gb2312_to_utf8($item["value"]);//$db0->f("value");//参数值
					$parameters[$parameter_name] = $value;
				}
			

			}else{//不是自定义元件				
				//产品参数				
				$sql_temp = "SELECT * FROM `$table_name` WHERE part_id='$part_id' ";						
				$parameters = $db0->get_row($sql_temp,ARRAY_A);	
			
			}
			
			//销售价格
			$sql_temp = "SELECT unit_price,currency_id,quantity FROM part_post_prices WHERE part_id='$part_id' ORDER BY unit_price desc ";
			$results = $db0->get_results($sql_temp,ARRAY_A);
			//返回不同数量对应的价格数组
			$unit_price = array();
			$i =0;
			if(!empty($results)){
				foreach($results as $item){				
					$unit_price[$i]['quantity'] = $item["quantity"];//$db0->f("quantity");//数量
					$unit_price[$i]['unit_price'] =  $item["unit_price"];//$db0->f("unit_price");//单价
					$currency_id  =  $item["currency_id"];//$db0->f("currency_id");//币种
					$i++;
				}
			}			
			
			$img_url = $db0->get_var("select file_path from qo_item_files where part_id = '$part_id' and file_attribution='picture'");	
			$currency_unit = $db0->get_var("select currency_unit from currency_format_config where currency_id=$currency_id");
			switch ($currency_unit) {
				case "USD":
					$category_symbol = '$';
					break;
				case "RMB":
					$category_symbol = '¥';
					break;
				default:
					$category_symbol = "(".$currency_unit.")";
			}
			//$good = new Goods();
			$good["category"] = gb2312_to_utf8($category_temp);
			$good["p_no"] = gb2312_to_utf8($p_no);
			$good["name"] = gb2312_to_utf8($name);
			$good["parameters"] = $parameters;
			$good["price"] = $unit_price;
			$good["currency_id"] = $currency_id;
			$good["price_unit"] = $currency_unit;
			$good["category_symbol"] = $category_symbol;
			$good["part_id"] = $part_id;
			$good["lead_time"] = $lead_time;
			//$good["img_url"] = gb2312_to_utf8($img_url);
			$good["img_url"] = $img_url;
			$good["description"] = gb2312_to_utf8($description);
			$good["ours_amount_in_stock"] = $ours_amount_in_stock;
			$good["real_amount_in_stock"] = $real_amount_in_stock;
			
			$goods[] = $good;
		}		
		return $goods;	
	}

	/**
	 * @desc 取得数据表的所有列名
	 * @param String $table_name
	 */
	public function getTablesFieldsArr($table_name){
		//$db = new clsDBMyConn();
		$results = $this->wpdb->get_results("desc $table_name",ARRAY_A);
		$results = empty($results) ? array() : $results ;
		foreach($results as $item){
			$arr[] = $item["Field"];
		}
		return $arr;
	}
	
	
	
	/**
	 * @desc 根据part_id获取产品
	 * @param INT $part_id
	 */
	public function getProductByPartID($part_id){
		$info = $this->getProducts(null,null,$part_id);
		return $info[0];//返回对象
	}
	
	public function getProductTypeShow($lang){
	
		$sql_temp = "SELECT category,english_name,china_name FROM userdefined_part_name_config";						
		$results = $this->wpdb->get_results($sql_temp,ARRAY_A);
		$results = empty($results) ? array() : $results;
		foreach($results as $item){
			$key = $item["category"];
			$arr[$key] = $lang == "en" ? $item["english_name"] : auto_charset_to_utf8($item["china_name"]);
		
		}
		return $arr;
	}
	
	
}

/**
 * @desc led销售管理类
 * @author yuanhuan
 * @since 2011-05-30
 */
class SaleManage {
	private $db = null;
	/*
	* @返回销售产品主页滚动图片所需数据
	* $PicList['src'] 图片链接地址
	* $PicList['focusImg'] 大图
	* $PicList['btnImg'] 小图
	* $PicList['ifocus_tx'] 文字介绍
	* @return $PicList
	*/
	function getFocusPicList(){
		$PicList = array();
		$PicList['src'][] = '';
		$PicList['src'][] = 'led_bulb';
		$PicList['src'][] = 'led_strip';
		$PicList['src'][] = 'led_meteor';
		$PicList['focusImg'][] = 'css/focusImg/01.jpg';
		$PicList['focusImg'][] = 'css/focusImg/02.jpg';
		$PicList['focusImg'][] = 'css/focusImg/03.jpg';
		$PicList['focusImg'][] = 'css/focusImg/04.jpg';
		$PicList['btnImg'][] = 'css/focusImg/btn_01.jpg';
		$PicList['btnImg'][] = 'css/focusImg/btn_02.jpg';
		$PicList['btnImg'][] = 'css/focusImg/btn_03.jpg';
		$PicList['btnImg'][] = 'css/focusImg/btn_04.jpg';
		$PicList['ifocus_txh'][] = '';
		$PicList['ifocus_txh'][] = 'LED球形灯泡';
		$PicList['ifocus_txh'][] = 'LED软条装饰灯';
		$PicList['ifocus_txh'][] = 'LED流星灯';
		$PicList['ifocus_tx'][] = ' LED球形灯拥有高效、节能、寿命长、无污染的特性,是代替传统白炽灯的新型节能灯具。<br>LED贴片灯条柔软性好、可塑性强,节能耐用,安装简易,是装饰不可少的选择。<br>LED流星灯采用高亮度优质发光芯片,优质硬性电路板,良好的流星追逐效果,是装饰的好选择';
		$PicList['ifocus_tx'][]  = '节能:比传统的白炽灯节省85%的能源,比传统的节能灯节省30%的能源,比普遍使用于道路照明的高压钠灯节省60%的能源。';
		//$PicList['ifocus_tx'][]  = '使用寿命长:达到50,000小时,相当于50个传统白炽灯、5个传统节能灯。';
		$PicList['ifocus_tx'][]  = '贴片封装(SMD)的高亮度LED为光源,使用硅胶灌装,质材柔软、可任意弯曲、折叠、卷绕。低功耗、发光色彩艳丽、混色均匀、不易损坏、外形美观、安全可靠,安装简易。';
		$PicList['ifocus_tx'][]  = '产品采用优质的硬性PCB电路板,高亮度超优质芯片,双面发光通过IC芯片编程,实现流星追逐的效果。可根据环境任意连接,可根据您的要求设定闪烁效果。颜色多种,是一种新型的工程亮化产品。';
		return $PicList;
	}
	/*
	* @获取销售产品主页左推荐列表
	*/
	function getProductList(){
		global $servers;
		$ProductList = array();
		$category_arr = $servers["category"];
		$category_arr = empty($category_arr) ? array() : $category_arr ;
		foreach($category_arr as $category){
			$ProductList = array_merge($ProductList,$this->getCategoryList($category,5));
		}
	
		return $ProductList;
	}
	/*
	* @获取主页产品分类和推荐主页显示产品
	*/
	function getIndexProduct($kind=null){
		global $servers;
		$category_arr     = empty($servers["category"]) ? array() : $servers["category"];
		$led_category_num = $servers["led_category_num"];
		//具体实现省略
		$indexList    = array();
		$rightProList = array();
		$tempResult   = array();
		$StockManage  = new StockManage();	 
		if($kind!=null){			
			$tempResult   = $StockManage->getProductByCategory($kind); 	
			for($i=0;$i<$led_category_num;$i++){
				if(!empty($tempResult[i])){
					array_push($rightProList, $tempResult[i]);
				}				
			}
			//array_push($rightProList, $tempResult[0]);
		}else{
			foreach($category_arr as $category_temp){
				$tempResult   = $StockManage->getProductByCategory($category_temp); 	 
				//array_push($rightProList, $tempResult[0]);
				for($i=0;$i<$led_category_num;$i++){
					if(!empty($tempResult[$i])){
						array_push($rightProList, $tempResult[$i]);
					}
				}
			}
			
		}	 
		
		foreach($rightProList as $tempResult){
			$pid1     = $tempResult['part_id'];
			$category = $tempResult['category'];
			$indexList[$category][$pid1]['pid']       = $pid1;
			$indexList[$category][$pid1]['pName']     = $tempResult['name'];
			$indexList[$category][$pid1]['imgSrc']    = $tempResult['img_url'];
			$indexList[$category][$pid1]['UnitPrice'] = $tempResult['price'];
			$indexList[$category][$pid1]['Unit']      = $tempResult['price_unit'];
			$indexList[$category][$pid1]['category_symbol']      = $tempResult['category_symbol'];
			$indexList[$category][$pid1]['StockQty']  = $tempResult['ours_amount_in_stock'];//'100';  	
			$indexList[$category][$pid1]['description']  = $tempResult['description'];		
			$indexList[$category][$pid1]['lead_time'] = $tempResult['lead_time'];
			foreach($rightProList[0]['parameters'] as $pKey=>$pVal){
				if($pKey=='features'){
					$indexList[$category][$pid1]['features']  = '100';
					break;
				}		
			}
		}	 
		return $indexList;		
	}   
	
	/*
	 * @根据类型返回推荐的列表
	 */
	private function getCategoryList($category=null,$top=5){
		global $servers;
		if($category===null){
			return ;
		}else{
			$ProductList = array();
			$StockManage  = new StockManage();	 
			$rightProList   = $StockManage->getProductByCategory($category); 
			foreach($rightProList as $tempResult){
				$part_id     = $tempResult['part_id'];
				$ProductList[$category][$part_id] = $tempResult['name'];
			}	 
			/*
			$sql = "SELECT part_inventory.* FROM part_inventory WHERE public='Y' AND (category='$category') order by date_added desc limit $top ";
			
			$dbuser = $servers["db"]["username"];//"root";
			$dbpassword = $servers["db"]["password"];//"SnowGeese";
			$dbname = $servers["db"]["dbname"];//"snow7_led";
			$dbhost = $servers["db"]["dbhost"];//"localhost";
			//$db = new clsDBMyConn();
			//$this->wpdb = new wpdb($dbuser, $dbpassword, $dbname, $dbhost);
			$db  = new wpdb($dbuser, $dbpassword, $dbname, $dbhost ,-1);
			$db0 = new wpdb($dbuser, $dbpassword, $dbname, $dbhost, -1);
			$ProductList = array();
			$results = count($db->get_results($sql,ARRAY_A)) ? $db->get_results($sql,ARRAY_A):array();
			foreach ($results as $item){
				$part_id       = $item["part_id"];//$db->f("part_id");  //库存产品ID
				//$name          = CCDLookUp("name", strtolower("part_".$category."s"), "part_id='$part_id'", $db0);//产品名称
				$name          = $db0->get_var("select name from part_inventory where part_id='$part_id'");//产品名称
				$ProductList[$category][$part_id] = $name;
			} */			
			return $ProductList;
		}
	}
	/*
	 * @根据产品类型,返回显示名称
	 */
	function  getProListName(){
		return array('led_bulb'=>'LED Bulb Lights','led_strip'=>'LED Strip Lights','led_meteor'=>'LED Meteor Lights ');
	}
	
	/*
	 * @根据产品类型,返回显示名称
	 */
	function  getProductByPartID($part_id){
		$StockManage  = new StockManage();	 
		return $StockManage->getProductByPartID($part_id); 
	}
	
	/*
	 * @获取主页联系我们
	 */
	function  getProContactUs(){
		return 
		"<p><strong>电话:</strong> 800-897-2800</p>
		<p><strong>邮箱:</strong> sales@myroled.com</p>		
		<p><strong>地址:</strong> 天津市静海经济开发区</p>
		<p class='leftSpace'> 金海道26号</p>
		<p><strong>邮编:</strong> 300000</p>";
	}
	
	/*
	 * @获取中文分类名
	 */
	function  getCategoryChinaName($key,$lang="en"){
		$StockManage  = new StockManage();	 
		$arr = $StockManage->getProductTypeShow($lang);
		//$arr =  array('living'=>'生活用品','office'=>'办公用品','clothing'=>'服饰');
		return $arr[$key];		
	}
}
?>