<?php
class ShopItem
{
	/**
	 * @method    配件排行
	 * @param     [arr]     $config [参数]
	 * @return    [arr]             [[sale=>[0=>[pro_id=>100032,PRONAME=>xxxx]]],['coll'=>[0=>[pro_id=>100032,PRONAME=>xxxx]]]]
	 * @author 卢
	 * @copyright 2017-09-13
	 */
	public function getTopItem($shopId,$config)
	{
		// print_r($config);
		$B2cProduct=new B2cProduct();
		$B2cShopSort=new B2cShopSort();
		$source=['pro_id','pro_name','pro_sale_price','pro_promotion_price','pro_set_time','pro_add_time','pro_sold_count','pro_coll_count'];
		//配件分类
		$sortRes=$B2cShopSort->getAllShopSort($shopId);
		// print_r($sortRes);
		$cateRes=$B2cShopSort->getEndSortIds($sortRes['data'],$config['shopSort']);
		$cateId=array_unique($cateRes['data']);
		if(count($cateId))
		{
			$sortWhere=sprintf(" and pro_id IN(%s)",sprintf("select prs_pro_id from bc_product_sort where prs_sort_id IN(%s)",implode(',', $cateId)));
		}
		// $sortWhere=count($cateId)>0?sprintf(' and prs_sort_id IN(%s)',implode(',', $cateId)):'';
		$baseWhere=sprintf(' and pro_shop_id=%d and pro_status=1',$shopId);
		//价格范围
		$priceWhere='';
		if(count($config['price']))
		{
			$priceWhere.=sprintf(' and pro_sale_price>=%d',$config['price'][0]);
			$priceWhere.=(isset($config['price'][1])&&$config['price'][1]>0)?sprintf(' and pro_sale_price<=%d',$config['price'][1]):'';
		}
		$saleOrderBy=' order by pro_sold_count desc';
		$where=$baseWhere.$sortWhere.$priceWhere;
		$data=[];
		// echo $where;
		//热销排行
		$collOrderBy=' order by pro_coll_count desc';
		if($config['default']=='sale')
		{
			$where .= $saleOrderBy;
		}
		else
		{
			$where .= $collOrderBy;
		}
		$dataInfo=$B2cProduct->get('bc_product',$source,$where.sprintf(' limit %d',(int)$config['count']));
		// print_r($dataInfo);
		$data=$dataInfo['data'];
		// echo $where.$limit.$saleOrderBy,'</br>';
		if(count($dataInfo['data']))
		{
			$proId=array_column($dataInfo['data'], 'pro_id');
			$proPic=$B2cProduct->getProductPic($proId, false);
			foreach ($data as $k => $v) 
			{
				$data[$k]=isset($proPic['data'][$v['pro_id']][0])?array_merge($data[$k],$proPic['data'][$v['pro_id']][0]):$data[$k];		
			}	
		}
		return $data;
	}
	/**
	 * @method    配件搜索
	 * @author 卢
	 * @copyright 2017-09-18
	 */
	function getItemSearch($shopId,$config)
	{
		$Params = mvc::$URL_PARAMS;
		$B2cProduct=new B2cProduct();
		$B2cShopSort=new B2cShopSort();
		$B2cBase=new B2cBase();
		$ComModel=new ComModel();
		$result = array();

		// 参数
		if(!empty($Params)) $result['search'] = true;
		if($Params['sort'] == 'all') $result['sortAll'] = true;

		//
		if (isset($Params['keyword'])) {
            $Params['keyword'] = LibFc::Escape(str_replace(['onclick', 'ondatabinding', 'ondblclick', 'ondisposed', 'oninit', 'onkeydown', 'onkeypress', 'onkeyup', 'onload', 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onprerender', 'onunload', 'onerror', 'onfocus'], '*', $Params['keyword']));
        }
		$result['arr']=$Params;

		// 页码
		$perPage = $config['count'];
		$nowPage=!empty($Params['page']) ? $Params['page'] : 1;
		$baseWhere=sprintf(' and pro_show_b2c=1 and pro_shop_id =%d and pro_status=1',$shopId);
		$join=' join bc_product_info on pro_id=pri_pro_id';
		$table=' bc_product A ';
		$type= $Params['type']=='number' ? $Params['type'] : 'item';


		// 当前店铺所有分类
		$B2cShopSort = new B2cShopSort();
		$res = $B2cShopSort->getAllShopSort($shopId);
		$result['shopAllsort']=$res['data'];
		if(!empty($Params['sortId'])&& LibFc::Int($Params['sortId']))
		{
			if(isset($Params['brand'])&&(int)$Params['brand']>0)
			{
				$result['shopsort']=[];
			}
			else
			{
				foreach ($res['data'] as $k => $v) 
				{
					if($v['psort_id']==$Params['sortId'])
					{
						$result['shopsort'][]=$v;
					}
				}
			}
		}
		else
		{
			foreach ($res['data'] as $k => $v) 
			{
				if($v['psort_id']== 0)
				{
					$result['shopsort'][]=$v;
				}
			}
		}


		// 所有品牌
		$brandInfo = $ComModel->getAllBrand();
		$res = $B2cProduct->get('bc_product right join bc_product_brand_link on pro_id=pbl_pro_id',['DISTINCT pbl_brand_id'],sprintf(' and pro_status=1 and pro_shop_id=%d',$shopId));
		
		$baradIds = array_unique(array_column($res['data'], 'pbl_brand_id'));
		foreach ($baradIds as $k => $v) {
			$result['brand'][]=$brandInfo['data'][$v];	
		}



		//当前选中的品牌名称(面包屑导航)
		if(!empty($Params['brand']))
		{
			// print_r($Params['brand']);
			$brandParam=trim($Params['brand'],',');
			$brandArr=explode(',', $brandParam);
			foreach ($brandArr as $k => $v) 
			{
				$brandArr[$k]=(int)$v;
			}
			$brandParam=implode(',', $brandArr);
			// print_r($brandArr);
			foreach ($brandArr as $k => $v) 
			{
				$result['brandName'][]=$brandInfo['data'][(int)$v]['brand_name'];
			}
		}


		// 拼接右上角分类信息
		$result['top_right_page'] = array('nowPage'=>$nowPage,'pageCount'=>0);
		$typeWhere='';
		if($type=='item')
		{
			if(!empty($Params['keyword']))
			{
				$keywordArr=LibFc::keyword($Params['keyword']);
				if(count($keywordArr))
				{
					$keywordStr="'".implode("','",$keywordArr)."'";
					$typeWhere=sprintf(" and pro_id in (%s)",sprintf("select prk_pro_id from bc_keyword right join bc_product_keyword on prk_key_id=key_id where key_txt IN(%s)",$keywordStr));
				}
				else
				{
					//关键字为空则查名称
					$typeWhere=sprintf(" and pro_name like '%%%s%%'",LibFc::Escape($Params['keyword']));
				}
			}
		}
		else if($type=='number')
		{
			//搜号码
			//查出号码的配件ID
			$typeWhere='';
			if(!empty($Params['keyword']))
			{
				$formarNum = LibFc::FormatNum($Params['keyword']);
				// $numWhere=sprintf(" and (num_format like '%s%%' or num_reformat like '%s%%')",$formarNum,$formarNum);
				$numTable='bc_product left join bc_number on num_pro_id=pro_id';
				$typeWhere=sprintf(' and pro_id IN(%s)',sprintf("select num_pro_id from bc_number where (num_format like '%s%%' or num_reformat like '%s%%')",$formarNum,$formarNum));
			}
		}
		// echo $typeWhere;
		//配件分类
		$sortWhere='';
		if(isset($Params['sortId'])&&!empty($Params['sortId']))
		{		
			$sortRes=$B2cShopSort->getAllShopSort($shopId);
			$sortArr=explode(',',trim($Params['sortId'],','));
			$cateResArr=[];
			if(count($sortArr))
			{
				foreach ($sortArr as $k => $v) 
				{
					$cateRes=$B2cShopSort->getEndSortIds($sortRes['data'],$v);
					$cateResArr=count($cateRes['data'])?array_merge($cateResArr,$cateRes['data']):$cateResArr;
				}					
			}
			$cateId=array_unique($cateResArr);
			if(count($cateId))
			{
				// $cateArr=$B2cBase->getFieldUniVal('bc_product left join bc_product_sort on pro_id=prs_pro_id','prs_pro_id',sprintf(' and prs_sort_id IN(%s)',implode(',', $cateId)));
				$sortWhere=sprintf(' and pro_id IN(%s)',sprintf("select prs_pro_id from bc_product_sort where prs_sort_id IN(%s)",implode(',', $cateId)));
			}
			else
			{
				$sortWhere=' and pro_id<-1';
			}
		}
		////取品牌		
		if(isset($Params['brand'])&&!empty($Params['brand']))
		{
			// $brandIdArrData=$B2cBase->get('bc_product left join bc_product_brand_link on pro_id=pbl_pro_id',['pro_id'],sprintf(' and pbl_brand_id IN(%s)',$brandParam));
			$branWhere=sprintf(' and pro_id IN(%s)',sprintf("select pbl_pro_id from bc_product_brand_link where pbl_brand_id IN(%s)",$brandParam));
		}
		//价格范围
		$minWhere=($Params['minPrice']&&!empty($Params['minPrice']))?sprintf(' and (CASE when (pro_promotion_btime<=%d and pro_promotion_etime>=%d) then pro_promotion_price else pro_sale_price END) >=%f',time(),time(),$Params['minPrice']):'';
		$maxWhere=($Params['maxPrice']&&!empty($Params['maxPrice']))?sprintf(' and (CASE when (pro_promotion_btime<=%d and pro_promotion_etime>=%d) then pro_promotion_price else pro_sale_price END) <=%f',time(),time(),$Params['maxPrice']):'';
		$where=$baseWhere.$typeWhere.$sortWhere.$minWhere.$maxWhere.$branWhere;
		// die;
		//排序方式
		$orderBy='pro_sale_price desc,pro_set_time desc,pro_sold_count desc,pro_coll_count desc';
		if(isset($Params['order']))
		{
			switch ($Params['order']) 
			{
				// 销量
				case 'hotSale_desc':
					$orderBy=' pro_sold_count desc';
					break;
				// 收藏
				case 'hotKeep_desc':
					$orderBy=' pro_coll_count desc';
					break;
				// 新品
				case 'newOn_desc':
					$orderBy=' pro_set_time desc';
					break;
				// 价格倒序
				case 'price_desc':
					$orderBy=sprintf(' (CASE when (pro_promotion_btime<=%d and pro_promotion_etime>=%d) then pro_promotion_price else pro_sale_price END) desc',time(),time());
					break;
				// 价格升序
				case 'price_asc':
					$orderBy=sprintf(' (CASE when (pro_promotion_btime<=%d and pro_promotion_etime>=%d) then pro_promotion_price else pro_sale_price END) asc',time(),time());
					break;
			}
		}	
		$proTotalData=$B2cProduct->get($table,['count(*) count'],$where,true);
		$proBaseData=$B2cProduct->getProductList($nowPage,$perPage,$proTotalData['data']['count'],$orderBy,$where,$join);
		$data=$proBaseData['data'];
		$proId=array_column($data,'pro_id');
		// print_r($proId);
		
		if(count($proId))
		{
			//商家编码
			$shopNumWhere=sprintf(' and num_pro_id IN(%s) and num_self=1',implode(',',$proId));
			$shopNumArr=$B2cProduct->get('bc_number',['num_pro_id','num_factory','num_display','num_format','num_ismain'],$shopNumWhere);
			$shopNum=array_column($shopNumArr['data'],null, 'num_pro_id');
			//取所有的主号
			$numWhere=sprintf(' and num_pro_id IN(%s) and num_ismain=1 and num_self=0',implode(',',$proId));
			$mainNumArr=$B2cProduct->get('bc_number',['num_pro_id','num_factory','num_display','num_format','num_ismain'],$numWhere);
			$mainNum=array_column($mainNumArr['data'],null, 'num_pro_id');
			if($type=='number')
			{
				//匹配的号码
				$numWhere=sprintf(" and num_pro_id IN(%s) and num_self=0 and (num_format like '%%%s%%' or num_display like '%%%s%%') order by num_self asc",implode(',',$proId),LibFc::FormatNum($Params['keyword']),LibFc::FormatNum($Params['keyword']));
				// echo $numWhere;
				$suitNumArr=$B2cProduct->get('bc_number',['num_pro_id','num_factory','num_display','num_format','num_ismain','num_self','num_reformat '],$numWhere);
				// print_r($suitNumArr);
				$suitNum=array_column($suitNumArr['data'],null, 'num_pro_id');
			}
			//集中取评论
			$evaWhere=sprintf(' and evp_pro_id IN(%s) group by evp_pro_id',implode(',',$proId));
			$evalData=$B2cProduct->get('or_evaluate_product',['count(*) count','evp_pro_id'],$evaWhere);
			//集中取图片
			$proPic=$B2cProduct->getProductPic($proId, false);
			//获取品牌
			$brandArr=$B2cProduct->get('bc_probrand INNER join bc_product on pro_prb_id=prb_id',['prb_name','prb_id','pro_id'],sprintf(' and pro_id IN(%s)',implode(',',$proId)));
			$searchBrandArr=array_column($brandArr['data'],null, 'pro_id');
			//判断包邮
			$frtArrData=array_filter(array_column($data, 'pri_frt_id'));
			if(count($frtArrData))
			{
				$frtArr=$B2cProduct->get('sh_freight_tpl',['frt_id','frt_is_free'],sprintf(' and frt_id IN(%s)',implode(',',$frtArrData)));
				$frtArr=array_column($frtArr['data'], null,'frt_id');
				// print_r($frtArr);
			}
			$shopInfo=$B2cProduct->get('sh_shop left join us_user_base on shop_uid=ub_uid',['shop_id','shop_money_bail','shop_service_status','shop_service','shop_zbnum','shop_smainnum'],sprintf(' and shop_id =%d',$shopId),true);
			$shopInfo = $shopInfo['data'];
			foreach ($data as $k => $v) 
			{
				$data[$k]['evalCount']=0;
				if(count($evalData['data']))
				{
					foreach ($evalData['data'] as $i => $j) 
					{				
						if($j['evp_pro_id']==$v['pro_id']) $data[$k]['evalCount']=$j['count'];
					}
				}
				$data[$k]=isset($proPic['data'][$v['pro_id']][0])?array_merge($data[$k],$proPic['data'][$v['pro_id']][0]):$data[$k];
				$data[$k]['IS_FREE']=isset($frtArr[$v['pri_frt_id']])?$frtArr[$v['pri_frt_id']]['frt_is_free']:'N';
				$data[$k]['SHOP_DISPLAY']=isset($shopNum[$v['pro_id']])?$shopNum[$v['pro_id']]['num_display']:'';
				$data[$k]['SHOP_FACTORY']=isset($shopNum[$v['pro_id']])?$shopNum[$v['pro_id']]['num_factory']:'';
				$data[$k]['num_self']=isset($suitNum[$v['pro_id']])?$suitNum[$v['pro_id']]['num_self']:'';

				$tnum = isset($suitNum[$v['pro_id']])?$suitNum[$v['pro_id']]:$mainNum[$v['pro_id']];
				if(!$shopInfo['shop_smainnum'])
				{
					if(!$tnum['num_ismain'])
					{
						$data[$k]['MAIN_DISPLAY']= $tnum['num_display'];
						$data[$k]['MAIN_FACTORY']= $tnum['num_factory'];
					}
				}
				else
				{
					$data[$k]['MAIN_DISPLAY']=$tnum['num_display'];
					$data[$k]['MAIN_FACTORY']=$tnum['num_factory'];
				}
				$data[$k]['brand']=isset($searchBrandArr[$v['pro_id']])?$searchBrandArr[$v['pro_id']]['prb_name']:'';
				$data[$k]['refundDate']=(!empty($shopInfo['shop_service_status'])&&$shopInfo['shop_service_status']==1)?1:0;
				$data[$k]['bail']=!empty($shopInfo['shop_money_bail'])?$shopInfo['shop_money_bail']:0;
				$data[$k]['service']=!empty($shopInfo['shop_service'])?json_decode($shopInfo['shop_service'],true):'';	
				$data[$k]['shop_zbnum'] = $shopInfo['shop_zbnum']; 
			}
		}
		//print_r($data);
		$result['list']=$data;		
		// 获取分页信息
		$Page = LibPage::Show($proTotalData['data']['count'], $perPage);
		$result['page']=$Page;
		// print_r($result);
		// 拼接右上角分类信息
		$result['top_right_page']['pageCount'] = Ceil($proTotalData['data']['count']/$perPage);
		$result['className'] = 'search-wrapper-'.$config['viewType'];
		return $result;
	}
	/*
	 *左边搜索小框
	 */
	function getLeftSearch($shopId,$config)
	{
		return $config;
	}
	/*
	 *客服信息
	 */
	function getcustomService($shopId,$config)
	{
		return $config;
	}
	/**
	 * @method    获取推荐的配件
	 * @author 卢
	 * @copyright 2017-09-18
	 */
	public function getRecomItem($shopId,$config)
	{
		//判断推荐方式，(大于0)手工或(等于0)自动
		$B2cProduct=new B2cProduct();
		$B2cShopSort=new B2cShopSort();
		$baseWhere=sprintf(" and pro_shop_id=%d and pro_status=1",$shopId);
		$data=[];
		$source=['pro_id','pro_name','pro_sale_price','pro_promotion_price','pro_set_time','pro_add_time','pro_sold_count','pro_coll_count','pro_promotion_btime','pro_promotion_etime'];
		if($config['recomType']>0)
		{
			//手工推荐
			$where=$baseWhere;
			if(!empty($config['recomPro']))
			{
				$where.=sprintf(' and pro_id IN(%s)',trim($config['recomPro'],','));
			}
			else
			{
				$where.=' and pro_id <-1';
			}
			// echo $where;
			$proData=$B2cProduct->get('bc_product',$source,$where);
			// print_r($proData);
			$data=$proData['data'];
		}
		else
		{
			$baseWhere.=" and pro_promoted='Y'";
			//自动推荐
			//配件分类条件
			$sortRes=$B2cShopSort->getAllShopSort($shopId);
			$cateRes=$B2cShopSort->getEndSortIds($sortRes['data'],$config['shopSort']);
			$cateId=array_unique($cateRes['data']);
			//分类
			if(count($cateId))
			{
				$sortWhere=sprintf(" and pro_id IN(%s)",sprintf("select prs_pro_id from bc_product_sort where prs_sort_id IN(%s)",implode(',', $cateId)));
				// $cateProRes=$B2cShopSort->get('bc_product_sort',['prs_pro_id'],sprintf(' and prs_sort_id IN(%s)',implode(',', $cateId)));
				// $catePro=array_column($cateProRes['data'], 'prs_pro_id');
				// if($catePro)
				// {
				// 	// $sortWhere=sprintf(' and pro_id IN(%s)',implode(',',$catePro));
				// }
				// else
				// {
				// 	$sortWhere=' and pro_id<-1';
				// }
			}
			// echo $sortWhere;
			// die;
			// $sortWhere=count($cateId)?sprintf(' and prs_sort_id IN(%s)',implode(',', $cateId)):'';
			//价格范围
			$priceWhere='';
			if(count($config['price']))
			{
				$priceWhere.=sprintf(' and pro_sale_price>=%d',$config['price'][0]);
				$priceWhere.=(isset($config['price'][1])&&$config['price'][1]>0)?sprintf(' and pro_sale_price<=%d',$config['price'][1]):'';
			}
			//取的条数
			$limit=sprintf(' limit %d',(int)$config['count']);
			// $limit='';
			//排序方式
			$orderBy='';
			switch ($config['sort']) 
			{
				case 'hotSell_desc':
					$orderBy=' order by pro_sold_count desc';
					break;
				case 'hotKeep_desc':
					$orderBy=' order by pro_coll_count desc';
					break;
				case 'newOn_desc':
					$orderBy=' order by pro_set_time desc';
					break;
				case 'price_desc':
					$orderBy=sprintf(' order by (CASE when (pro_promotion_btime<=%d and pro_promotion_etime>=%d) then pro_promotion_price else pro_sale_price END) desc',time(),time());
					break;
				case 'price_asc':
					$orderBy=sprintf(' order by (CASE when (pro_promotion_btime<=%d and pro_promotion_etime>=%d) then pro_promotion_price else pro_sale_price END) asc',time(),time());
					break;
				default:
					$orderBy=' order by pro_sold_count desc';
					break;
			}
			// echo $priceWhere;
			// die;
			$where=$baseWhere.$sortWhere.$priceWhere;
			$table=' bc_product';
			$proBaseData=$B2cProduct->get($table,$source,$where.$orderBy.$limit);
			$data=$proBaseData['data'];
			// print_r($data);			
		}
		$proId=array_column($data, 'pro_id');
		//集中取评论
		if(count($proId))
		{
			$evaWhere=sprintf(' and evp_pro_id IN(%s) group by evp_pro_id',implode(',',$proId));
			$evalData=$B2cProduct->get('or_evaluate_product',['count(*) count','evp_pro_id'],$evaWhere);
		}
		//集中取图片
		$proPic=$B2cProduct->getProductPic($proId, false);
		
		foreach ($data as $k => $v) 
		{
			$data[$k]['evalCount']=0;
			if(count($evalData['data']))
			{
				foreach ($evalData['data'] as $i => $j) 
				{				
					if($j['evp_pro_id']==$v['pro_id']) $data[$k]['evalCount']=$j['count'];
				}
			}
			
			$data[$k]=isset($proPic['data'][$v['pro_id']][0])?array_merge($data[$k],$proPic['data'][$v['pro_id']][0]):$data[$k];
				
		}
		// print_r($data);
		return $data;
	}
	/**
	 * @method    配件详细信息
	 * @author 卢
	 * @copyright 2017-09-19
	 */
	public function getitemInfo($shopId)
	{
		$Params = mvc::$URL_PARAMS;
		$proId = (int) $Params['proId'];

		$view=$Params['view']?$Params['view']:0;
		$B2cProduct = new B2cProduct();
		$res = $B2cProduct->getProduct(['*'], sprintf(" and pro_id = %d", $proId), true);
		$proArr['base'] = $res['data'];
		if(empty($proArr['base']['pro_id']))
		{
			//页面不存在
			echo '配件不存在';
			exit;
		}
		if(!empty($proArr['base']['pro_prb_id']))
		{
			$brandArr=$B2cProduct->get('bc_probrand',['prb_name'],sprintf(' and prb_id=%d',$proArr['base']['pro_prb_id']),true);
			$data['brand']=$brandArr['data']['prb_name'];
		}
		$B2cBase = new B2cBase();
		$YpwAddr = new YpwAddr();
		//店铺平均分|最高分
		$B2cShop = new B2cShop();
		$proId = $proArr['base']['pro_id'];
		$B2cPart = new B2cPart();

		$res = $B2cPart->getPartParam($proArr['base']['pro_part_id']);
		$ParaArr=$res['data'];
		
		// print_r($proArr['partParam']);
		// die;
		$res = $B2cProduct->getProductParam($proId);
		$proArr['param'] = $res['data'];
		// print_r($proArr['param']);
		$sort=array();
		if(count($proArr['param'])&&count($ParaArr))
		{
			$sort=array_column($ParaArr, 'ppl_seq');
			array_multisort($sort, SORT_ASC, $ParaArr);
			// print_r($ParaArr);
			// die;
			$valRes=array_column($ParaArr, 'pal_id');
			// print_r($valRes);
			// die;
			$res=$B2cPart->get('bc_param_value',['pav_id','pav_part_id','pav_pal_id','pav_seq','pav_value'],sprintf(' and pav_pal_id IN(%s)',implode(',', $valRes)));
			$sort=[];
			$valRes=[];
			// print_r($res);
			if(count($res['data']))
			{
				foreach ($res['data'] as $v) 
				{
					// print_r($proArr['param'][$v['pal_id']]);
					// die;
					if(!empty($proArr['param'][$v['pav_pal_id']])&&in_array($v['pav_value'], array_values($proArr['param'][$v['pav_pal_id']])))
					{
						$valRes[$v['pav_pal_id']][]=$v;
						$sort[$v['pav_pal_id']][]=$v['pav_seq'];
					}
				}
				// print_r($valRes);
				foreach($ParaArr as $K=>$V)
				{
					if(isset($valRes[$V['pal_id']]))
					{
						array_multisort($sort[$V['pal_id']], SORT_ASC, $valRes[$V['pal_id']]);
						$ParaArr[$K]['valArr']=$valRes[$V['pal_id']];
					}
				}
			}
		}
		$proArr['partParam'] = $ParaArr;
		
		//获取自定义配件参数
		if(LibFc::Int($proId))
		{
			// $res=$B2cBase->get('bc_product',['pro_ppt_id'],sprintf(' and pro_shop_id=%d and pro_id=%d',$shopId,$proId),true);
			$tplId=$proArr['base']['pro_ppt_id'];
			if($tplId)
			{
				// $tplId=$res['data']['pro_ppt_id'];
				$proId=$proId;
				//有值的
				$feild = ['prpv_prl_id', 'prpv_pru_id', 'prpv_value','prl_name','pru_name'];
				$res=$B2cBase->get('bc_product_para_val join bc_product on pro_id= prpv_pro_id left join bc_product_label on prl_id=prpv_prl_id left join bc_product_unit on pru_id=prpv_pru_id', $feild, sprintf(" and pro_id=%d and pro_ppt_id =%d and pro_shop_id=%d and (prpv_value is not null or prpv_value!='')", $proId, $tplId, $shopId));
				// print_r($res);
				$oldValArr = [];
				$oldValArr=array_column($res['data'], null,'prpv_prl_id');
				// print_r($oldValArr);
				//新的
				$fieldArr=['pptl_ppt_id','prl_id','pru_id','pptl_seq','prl_name','pru_name'];
				$newlink=$B2cBase->get('bc_product_para_tpl_link left join bc_product_label on prl_id=pptl_prl_id left join bc_product_unit on pru_id=pptl_pru_id',$fieldArr,sprintf(' and pptl_ppt_id=%d order by pptl_seq asc,pptl_prl_id asc',$tplId));
				$newArr=array_column($newlink['data'], null,'prl_id');
				// print_r($newArr);
				if(count($oldValArr))
				{
					foreach ($oldValArr as $k => $v) 
					{
						$newArr[$k]=isset($newArr[$k])?array_merge($v,$newArr[$k]):$v;
					}
				}
				// print_r($newArr);
			}
			$data['proParams'] = $newArr;
		}
		// 图片权限
		if(in_array('item_pic',mvc::$cfg['permissionArr'])){
			$res = $B2cProduct->getProductPic($proId,true);
			$proArr['imgs'] = $res['data'];
		}
		
		//运费模板
		$frtId=$proArr['base']['pri_frt_id'];
		if($frtId)
		{
			$templateData=$B2cBase->get('sh_freight_tpl',['*'],' and frt_id='.$frtId,true);
			$sendAddrData=$YpwAddr->getAddrByIds($templateData['data']['frt_send_pct']);
			$addrArr=array_slice($sendAddrData['data'], 0,2);
			$templateData['data']['sendAddr']=mb_substr($addrArr[0], 0,2)==mb_substr($addrArr[1], 0,2)? $addrArr[1] : implode('',$addrArr);
			$data['template']=$templateData['data'];
		}
		$dataArr = array();

		$comLabel = $B2cBase->Get('or_evaluate_label_link left join or_evaluate_label on ell_evl_id=evl_id',['evl_id','evl_name'],' and ell_pro_id='.$proArr['base']['pro_id']);
		foreach ($comLabel['data'] as $labK => $labV) 
		{
			$dataArr[$labV['evl_id']] = $labV;
			if(array_key_exists($labV['evl_id'], $dataArr))
			{
				unset($dataArr[$labV['evl_id']]);
				$dataArr[$labV['evl_id']] = $labV;
			}else
			{
				$dataArr[$labV['evl_id']] = $labV;
			}
		}
		$data['comLabelArr']=$dataArr;
		$res = $B2cPart->getAllPart();
		$data['partArr']=$res['data'];

		//店铺分类
		$B2cShopSort = new B2cShopSort();
		$thisShopSort = $B2cShopSort->getShopSort($proArr['base']['pro_shop_id']);
		$data['thisShopSort']=$thisShopSort['data'];
		$data['proArr']=$proArr;
		$data['view']=$view;

		// 售后保障
		$B2cProduct = new B2cProduct();
		$res = $B2cProduct->getProAfterSellService($proId);
		$data['afterSel'] = array_filter($res['data']);
		// print_r($data['afterSel']);
		return $data;
	}
	/**
	 * @method    图片轮播模块信息
	 * @author    廖
	 * @copyright 2017-09-20
	 */
	function getImgCarousel($shopId,$config)
	{
		return $config;
	}
}