<?php
/**
*商城
*/
class b2cAction extends baseAction
{
	/**
	  * @method 获取用户浏览历史
	  * @http  get
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  uid                int  [必填] 用户ID
	  * @param  shopUid            int  [选填] 店铺ID，默认0
	  * @param  page               int  [选填] 第几页，默认1
	  * @param  perPage            int  [选填] 每页多少条，默认10
	  * @author soul
	  * @copyright 2017/8/16
	  * @return 
		{"status":true,"data":[],"code":0}
		{"status":false,"data":'失败原因',"code":0}
	  */
	function getUserHistoryPro()
	{
		$arr = [];
		$uid = isset($_GET['uid']) ? (int) $_GET['uid'] : 0;
		$shopUid = isset($_GET['shopUid']) ? (int) $_GET['shopUid'] : 0;
		$page = isset($_GET['page']) && $_GET['page'] > 0? (int) $_GET['page'] : 1;
		$perPage = isset($_GET['perPage']) && $_GET['perPage'] > 0 ? (int) $_GET['perPage'] : 10;
		if($uid > 0)
		{
			if($shopUid > 0)
			{
				$B2cShop = new B2cShop();
				$res = $B2cShop->getShopId($shopUid);
				$shopId = $res['data'];
			}

			$B2cBase = new B2cBase();
			$where = $shopId > 0 ? sprintf(" and pro_shop_id=%d", $shopId): '';
			$table = 'us_product_history 
					join bc_product pro on prh_pro_id=pro_id and pro_status = 1
					join sh_shop on pro_shop_id = shop_id and shop_status = 1
					left join bc_product_pic on pp_pro_id=pro_id and pp_ismain=1
					left join sh_pic on pp_spi_id = spi_id';
			$where .= sprintf(" and prh_uid=%d group by pro_id order by prh_ltime desc limit %d,%d", $uid, ($page-1)*$perPage, $perPage);
			$res = $B2cBase->get($table, ['pro.*, spi_path, concat(spi_name, \'.\', spi_ext) spi_name'], $where);
			$time = time();
			foreach($res['data'] as $v)
			{
				$price = $v['pro_promotion_btime'] > $time && $v['pro_promotion_etime'] < $time && $v['pro_promotion_price'] > 0?  $v['pro_promotion_price']:  $v['pro_sale_price'];
				$imgUrl = !empty($v['spi_path'])? mvc::$cfg['FILE_CENTER']['b2c']['url_get'].'&c=product&f='.$v['spi_path'].'240/'.$v['spi_name'].mvc::$cfg['FILE_CENTER']['b2c']['get_uri']:mvc::$cfg['urls']['b2c'].'static/images/noimg.gif';
				$temp = [
					'PRO_ID'=>$v['pro_id'],
					'PRO_NAME'=>$v['pro_name'],
					'PRO_PRICE'=>sprintf("%.2f", $price),
					'PRO_URL'=>mvc::$cfg['urls']['b2c'].'item/index?proId='.$v['pro_id'],
					'PRO_IMG'=>$imgUrl
				];
				$arr[] = $temp;
			}
		}
		LibFc::ReturnJson(true, $arr);
	}


	/**
	  * @method 获取用户订单
	  * @http  get
	  * @param  uid                int  [必填] 用户ID
	  * @param  shopUid            int  [选填] 店主UID，默认0
	  * @param  page               int  [选填] 第几页，默认1
	  * @param  perPage            int  [选填] 每页多少条，默认10
	  * @author soul
	  * @copyright 2017/8/16
	  * @return 
		{"status":true,"data":[],"code":0}
		{"status":false,"data":'失败原因',"code":0}
	  */
	function getUserOrder()
	{
		$arr = [];
		$uid = isset($_GET['uid']) ? (int) $_GET['uid'] : 0;
		$shopUid = isset($_GET['shopUid']) ? (int) $_GET['shopUid'] : 0;
		$page = isset($_GET['page']) && $_GET['page'] > 0? (int) $_GET['page'] : 1;
		$perPage = isset($_GET['perPage']) && $_GET['perPage'] > 0 ? (int) $_GET['perPage'] : 10;
		if($uid > 0)
		{
			if($shopUid > 0)
			{
				$B2cShop = new B2cShop();
				$res = $B2cShop->getShopId($shopUid);
				$shopId = $res['data'];
			}
			$B2cBase = new B2cBase();
			$where = $shopId > 0 ? sprintf(" and ord_shop_id=%d", $shopId): '';
			$where .= sprintf(" and ord_uid=%d and ord_status != 'cancel' order by ord_add_time desc limit %d,%d", $uid, ($page-1)*$perPage, $perPage);
			$res = $B2cBase->get('or_order', ['ord_id, ord_total_money, ord_add_time'], $where);
			foreach($res['data'] as $v)
			{
				$temp = [
					'ORD_ID'=> $v['ord_id'],
					'ORD_URL'=> mvc::$cfg['urls']['b2c'].'user/detail?orderId='.$v['ord_id'],
					'ORD_TOTAL_MONEY'=> sprintf("%.2f", $v['ord_total_money']),
					'ORD_ADD_TIME'=> $v['ord_add_time'],
					'ORD_PROS'=>[]
				];
				$arr[$v['ord_id']] = $temp;
			}
			
			if(!empty($arr))
			{
				$table = 'or_order_product as pro
					left join bc_product_pic on pp_pro_id=orp_pro_id and pp_ismain=1
					left join sh_pic on pp_spi_id = spi_id';
				$res = $B2cBase->get($table, ['orp_ord_id','orp_pro_id', 'orp_pro_name', 'orp_sale_price', 'spi_path', 'concat(spi_name, \'.\', spi_ext) as spi_name'], sprintf(" and orp_ord_id in (%s) order by orp_id", implode(',', array_keys($arr))));
				foreach($res['data'] as $v)
				{
					$imgUrl = !empty($v['spi_path'])? mvc::$cfg['FILE_CENTER']['b2c']['url_get'].'&c=product&f='.$v['spi_path'].'240/'.$v['spi_name'].mvc::$cfg['FILE_CENTER']['b2c']['get_uri']:mvc::$cfg['urls']['b2c'].'static/images/noimg.gif';
					$temp = [
						'PRO_ID'=>$v['orp_pro_id'],
						'PRO_NAME'=>$v['orp_pro_name'],
						'PRO_PRICE'=>sprintf("%.2f", $v['orp_sale_price']),
						'PRO_URL'=>mvc::$cfg['urls']['b2c'].'item/index?proId='.$v['orp_pro_id'],
						'PRO_IMG'=>$imgUrl
					];
					$arr[$v['orp_ord_id']]['ORD_PROS'][] = $temp;
				}
			}
		}
		LibFc::ReturnJson(true, $arr);
	}

	
	/**
	  * @method 分析URL返回对应格式的数据
	  * @http  post
	  * @param  url                string  [必填]  urlencode后的url
	  * @author soul
	  * @copyright 2017/8/16
	  * @return 
		{"status":true,"data":{'img'=>'', 'url', 'vals':[{'label':'', 'val':'', 'url':''....}]},"code":0}
		{"status":false,"data":'失败原因',"code":0}
	  */
	function getDataByUrl()
	{
		$arr = [];
		$url = isset($_POST['url']) ? urldecode($_POST['url']): '';
		
		//配件
		if(preg_match('/proId=(\d+)/', $url, $matchArr))
		{
			$B2cBase = new B2cBase();
			$proId = $matchArr[1];
			$table = sprintf("bc_product as pro
				join sh_shop on pro_shop_id = shop_id and shop_status = 1
				left join bc_product_pic on pp_pro_id=pro_id and pp_ismain=1
				left join sh_pic on pp_spi_id = spi_id", $proId);
			$res = $B2cBase->get($table, ['pro.*, spi_path, concat(spi_name, \'.\', spi_ext) as spi_name'], sprintf(" and pro_status = 1 and pro_id=%d", $proId), true);
			if(!empty($res['data']))
			{
				$proData = $res['data'];
				
				$time = time();
				$price = $proData['pro_promotion_btime'] > $time && $proData['pro_promotion_etime'] < $time && $proData['pro_promotion_price'] > 0?  $proData['pro_promotion_price']:  $proData['pro_sale_price'];
				$imgUrl = !empty($proData['spi_path'])? mvc::$cfg['FILE_CENTER']['b2c']['url_get'].'&c=product&f='.$proData['spi_path'].'240/'.$proData['spi_name'].mvc::$cfg['FILE_CENTER']['b2c']['get_uri']:mvc::$cfg['urls']['b2c'].'static/images/noimg.gif';
				$arr = [
					'url'=>mvc::$cfg['urls']['b2c'].'item/index?proId='.$proData['pro_id'],
					'img'=>$imgUrl,
					'proId'=>$proData['pro_id'],
					'vals'=>[
						//['label'=>'配件ID', 'val'=>$proData['pro_id'], 'url'=>''],
						['label'=>'配件名称', 'val'=>$proData['pro_name'], 'url'=>''],
						['label'=>'配件价格', 'val'=>sprintf("%.2f", $price), 'url'=>'']
					]
				];
				
			}
		}
		LibFc::ReturnJson(true, $arr);
	}


	/**
	  * @method 通过订单ID获取订单信息
	  * @http  get
	  * @param  ordId            int  [必填] 订单ID
	  * @author soul
	  * @copyright 2017/8/16
	  * @return 
		{"status":true,"data":[],"code":0}
		{"status":false,"data":'失败原因',"code":0}
	  */
	function getOrderById()
	{
		$arr = [];
		$ordId = isset($_GET['ordId']) ? (int) $_GET['ordId'] : 0;
		if($ordId > 0)
		{
			$B2cBase = new B2cBase();
			$res = $B2cBase->get('or_order', ['*'], sprintf(" and ord_id = %d", $ordId), true);
			if(!empty($res['data']))
			{
				$arr = [
					'ORD_ID'=>$res['data']['ord_id'],
					'ORD_URL'=>mvc::$cfg['urls']['b2c'].'user/detail?orderId='.$res['data']['ord_id'],
					'ORD_TOTAL_MONEY'=>sprintf("%.2f", $res['data']['ord_total_money']),
					'ORD_ADD_TIME'=>$res['data']['ord_add_time'],
					'ORD_PROS'=>[]
				];
				$table = 'or_order_product PRO
					left join bc_product_pic on pp_pro_id=orp_pro_id and pp_ismain=1
					left join sh_pic on pp_spi_id = spi_id';
				$res = $B2cBase->get($table, ['orp_pro_id', 'orp_pro_name', 'orp_sale_price', 'spi_path', 'concat(spi_name, \'.\', spi_ext) as spi_name'], sprintf(" and orp_ord_id = %d order by orp_id", $ordId));
				foreach($res['data'] as $v)
				{
					$imgUrl = !empty($v['spi_path'])? mvc::$cfg['FILE_CENTER']['b2c']['url_get'].'&c=product&f='.$v['spi_path'].'240/'.$v['spi_name'].mvc::$cfg['FILE_CENTER']['b2c']['get_uri']:mvc::$cfg['urls']['b2c'].'static/images/noimg.gif';
					$temp = [
						'PRO_ID'=>$v['orp_pro_id'],
						'PRO_NAME'=>$v['orp_pro_name'],
						'PRO_PRICE'=>sprintf("%.2f", $v['orp_sale_price']),
						'PRO_URL'=>mvc::$cfg['urls']['b2c'].'item/index?proId='.$v['orp_pro_id'],
						'PRO_IMG'=>$imgUrl
					];
					$arr['ORD_PROS'][] = $temp;
				}
			}
		}
		LibFc::ReturnJson(true, $arr);
	}


	/**
	  * @method 通过配件ID获取配件信息
	  * @http  GET
	  * @param  proId                int  [必填]  配件ID
	  * @author soul
	  * @copyright 2017/8/16
	  * @return 
		{"status":true,"data":{'img'=>'', 'url', 'vals':[{'label':'', 'val':'', 'url':''....}]},"code":0}
		{"status":false,"data":'失败原因',"code":0}
	  */
	function getProById()
	{
		$arr = [];
		$proId = isset($_GET['proId']) ? (int) $_GET['proId'] : 0;
		if($proId > 0)
		{
			$B2cBase = new B2cBase();
			$table = 'bc_product PRO
				join sh_shop on pro_shop_id = shop_id and shop_status = 1
				left join bc_product_pic on pp_pro_id=pro_id and pp_ismain=1
				left join sh_pic on pp_spi_id = spi_id';
			$res = $B2cBase->get($table, ['PRO.*, spi_path, concat(spi_name, \'.\', spi_ext) as spi_name'], sprintf(" and pro_status = 1 and pro_id=%d", $proId), true);
			if(!empty($res['data']))
			{
				$proData = $res['data'];
				
				$time = time();
				$price = $proData['pro_promotion_btime'] > $time && $proData['pro_promotion_etime'] < $time && $proData['pro_promotion_price'] > 0?  $proData['pro_promotion_price']:  $proData['pro_sale_price'];
				$imgUrl = !empty($proData['spi_path'])? mvc::$cfg['FILE_CENTER']['b2c']['url_get'].'&c=product&f='.$proData['spi_path'].'240/'.$proData['spi_name'].mvc::$cfg['FILE_CENTER']['b2c']['get_uri']:mvc::$cfg['urls']['b2c'].'static/images/noimg.gif';
				$arr = [
					'url'=>mvc::$cfg['urls']['b2c'].'item/index?proId='.$proData['pro_id'],
					'img'=>$imgUrl,
					'proId'=>$proData['pro_id'],
					'vals'=>[
						//['label'=>'配件ID', 'val'=>$proData['pro_id'], 'url'=>''],
						['label'=>'配件名称', 'val'=>$proData['pro_name'], 'url'=>''],
						['label'=>'配件价格', 'val'=>sprintf("%.2f", $price), 'url'=>'']
					]
				];
				
			}
		}
		LibFc::ReturnJson(true, $arr);
	}


	/**
	  * @method 通过店铺ID获取店铺客服UID
	  * @http  GET
	  * @param  shopId                int  [必填]  店铺ID
	  * @author soul
	  * @copyright 2017/8/16
	  * @return 
		{"status":true,"data":[1,2,3,4],"code":0}
		{"status":false,"data":'失败原因',"code":0}
	  */
	function getKefuByShopId()
	{
		$arr = [];
		$shopId = isset($_GET['shopId']) ? (int) $_GET['shopId'] : 0;
		if($shopId > 0)
		{
			$B2cBase = new B2cBase();
			$res = $B2cBase->getFieldUniVal('sh_worker', 'wor_uid', sprintf(" and wor_status = 1 and wor_kefu = 1 and wor_shop_id=%d", $shopId));
			$arr = $res['data'];
		}
		LibFc::ReturnJson(true, $arr);
	}
	

	/**
	  * @method 通过UID获取店铺ID
	  * @http  GET
	  * @param  uid                int  [必填]  用户ID
	  * @author soul
	  * @copyright 2017/8/16
	  * @return 
		{"status":true,"data":12,"code":0}
		{"status":false,"data":'失败原因',"code":0}
	  */
	function getshopIdByUid()
	{
		$shopId = 0;
		$uid = isset($_GET['uid']) ? (int) $_GET['uid'] : 0;
		if($uid > 0)
		{
			$B2cBase = new B2cBase();
			$res = $B2cBase->get('sh_shop', ['shop_id'], sprintf(" and shop_uid=%d", $uid), true);
			if(!empty($res['data']))
			{
				$shopId = $res['data']['shop_id'];
			}
			else
			{
				$res = $B2cBase->get('sh_worker', ['wor_shop_id'], sprintf(" and wor_uid=%d", $uid), true);
				$shopId = $res['data']['wor_shop_id'];
			}
		}
		LibFc::ReturnJson(true, $shopId);
	}


	/**
	  * @method 通过用户ID 返回它所在店铺ID下所有客服ID
	  * @http  GET
	  * @param  uid                int  [必填]  用户ID
	  * @param  type               int  0:全部[默认] ；1:使用中
	  * @author soul
	  * @copyright 2017/8/16
	  * @return 
		{"status":true,"data":[11,22],"code":0}
		{"status":false,"data":'失败原因',"code":0}
	  */
	function getShopUidsByUid()
	{
		$uidArr = [];
		$uid = isset($_GET['uid']) ? (int) $_GET['uid'] : 0;
		$type = isset($_GET['type']) ? (int) $_GET['type'] : 0;
		if($uid > 0)
		{
			$B2cBase = new B2cBase();
			$res = $B2cBase->get('sh_shop', ['shop_id', 'shop_uid'], sprintf(" and shop_uid=%d", $uid), true);
			if(!empty($res['data']))
			{
				//店主
				$uidArr[] = $res['data']['shop_uid'];
				$shopId = $res['data']['shop_id'];

				$where = sprintf(" and wor_shop_id=%d and wor_kefu = 1", $shopId);
				$where .= $type == 1? ' and wor_status = 1': '';
				$res = $B2cBase->get('sh_worker', ['wor_uid'], $where);
				foreach($res['data'] as $v)
				{
					$uidArr[] = $v['wor_uid'];
				}
			}
			else
			{
				$res = $B2cBase->get('sh_worker', ['wor_shop_id'], sprintf(" and wor_uid=%d", $uid), true);
				if(!empty($res['data']))
				{
					$shopId = $res['data']['wor_shop_id'];
					$where = sprintf(" and wor_shop_id=%d and wor_kefu = 1", $shopId);
					$where .= $type == 1? ' and wor_status = 1': '';
					$res = $B2cBase->get('sh_worker join sh_shop on wor_shop_id=shop_id', ['wor_uid', 'shop_uid'], $where);
					if(!empty($res['data']))
					{
						$uidArr[] = $res['data'][0]['shop_uid'];
						foreach($res['data'] as $v)
						{
							$uidArr[] = $v['wor_uid'];
						}
					}
				}
			}
		}
		LibFc::ReturnJson(true, $uidArr);
	}

	
	/**
	  * @method 过配件名称匹配出末级分类
	  * @http  POST
	  * @param  names    array  [必填]  配件名称
	  * @author soul
	  * @copyright 2017/8/16
	  * @return 
		{"status":true,"data":[],"code":0}
		{"status":false,"data":'失败原因',"code":0}
	  */
	function getEndPartByStr()
	{
		$B2cPart = new B2cPart();
		$res = $B2cPart->getEndPartByStr($_POST['names']);
		LibFc::EchoJson($res);
	}
	/**
	 * @method    获取b2c配件价格
	 * @http post
	 * @param  uid  int  [必填]  报价者id
	 * @param  data[
	 *         'oe号码1'=>配件名称1,  [必填] 
	 *         'oe号码2'=>配件名称2
	 *         ]
	 * @return    [json]      {status:true,data:[{"172999":[{"pro_id":"101237","pro_name":"\u5239\u8f66\u7247\u5239\u8f66\u76ae\u76d8\u5f0f\u7247\/\u5927\u4f17,\u65af\u67ef\u8fbe,\u5954\u817e","pro_shop_id":"172999","price":"0.08","price_type":1,"number":"XYD133"}]}]} 以店铺id为键的json
	 * @author lu
	 * @copyright 2018-11-05
	 */
	function getShopProduct()
	{
		$B2cProduct = new B2cProduct();
		$data=array_filter($_POST);
		if(!empty($data['uid'])&&!empty($data['data']))
		{
			$numArr=array_keys($data['data']);
			//获取b2c中正在运营的并且配件为上线状态的配件
			$res=$B2cProduct->get('bc_product left join sh_shop on shop_id=pro_shop_id right join bc_number on num_pro_id=pro_id',['pro_id','num_format'],sprintf(" and pro_status=1 and shop_status=1 and pro_name in('%s') and num_format in('%s')",implode("','",$data['data']),implode("','",$numArr)));
			$proIdArr=array_column($res['data'], 'pro_id');
			$proNumArr=array_column($res['data'],'num_format','pro_id');
			$result=[];
			if(!empty($proIdArr))
			{
				$shopArr=[];
				$res=$B2cProduct->getAnyProductInfo($proIdArr,$data['uid']);
				if(!empty($res['data']))
				{
					foreach ($res['data'] as $v) 
					{
						$shopArr[$v['pro_shop_id']][]=$v;
					}
					$shopIdArr=array_keys($shopArr);
					//判断是否企业会员
					$res=$B2cProduct->get('us_user_base',['ub_uid','ub_level'],sprintf(' and ub_uid=%d',$data['uid']),true);
					if($res['data']['ub_level']>0)
					{
						//企业会员,获取企业会员折扣
						$res=$B2cProduct->get('sh_shop',['shop_id','shop_com_discount'],sprintf(' and shop_id in(%s)',implode(',',$shopIdArr)));
						$shopDis=array_column($res['data'],'shop_com_discount' ,'shop_id');
					}
					foreach ($shopArr as $shopId => $proArr) 
					{
						foreach ($proArr as $k => $v) 
						{
							if(!empty($shopDis[$shopId])&&$shopDis[$shopId]<10&&$v['price_type']<3)
							{
								$v['price']=round($v['price']*$shopDis[$shopId]*0.1,2);
							}
							$vNumArr=[];
							$vNumArr=array_column($v['num'], 'display');
							$vNumArr=array_map(function($v){
								return LibFc::FormatNum($v);
							}, $vNumArr);
							if(in_array($proNumArr[$v['pro_id']], $vNumArr))
							{
								$v['number']=$proNumArr[$v['pro_id']];
							}
							unset($v['pro_status'],$v['prb_name'],$v['pro_sale_price'],$v['pro_count'],$v['pro_user_discount'],$v['pro_sold_count'],$v['pro_part_id'],$v['pri_code'],$v['pri_weight'],$v['pri_des'],$v['pri_frt_id'],$v['pro_sel_des'],$v['pri_invoice'],$v['pri_warranty'],$v['pri_return_promise'],$v['pro_price'],$v['pic'],$v['num']);
							$proArr[$k]=$v;
						}
						$shopArr[$shopId]=$proArr;
					}
					LibFc::ReturnJson(true, $shopArr);
				}
			}
		}
		LibFc::ReturnJson(true, []);
	}
	/**
	 * @method    获取店铺
	 * @http post
	 * @param where   str   [必填]
	 * @param fields  arr  [选填] 字段
	 * @return    [type]     [description]
	 * @author lu
	 * @copyright 2018-11-26
	 */
	function getShop()
	{
		if(!empty($_POST['where']))
		{
			$fieldArr=!empty($_POST['fields'])?$_POST['fields']:['*'];
			$B2cBase=new B2cBase();
			$res=$B2cBase->get('sh_shop',$fieldArr,$_POST['where']);
			LibFc::ReturnJson(true, $res['data']);
		}
		LibFc::ReturnJson(false, '限定条件不能为空');
	}
	/**
	 * @method    商城关键字搜索
	 * @http get  
	 * @param   m3Id  int  [必填] 车型id
	 * @param   keyword str  [必填] 关键字
	 * @param   page  int  [可选] 当前页码 默认 1
	 * @param   perPage  int  [可选] 每页条数 默认20 
	 * @param   sortId  str  [可选] 分类末级id  逗号分割
	 * @param   minPrice  float  [可选] 筛选价格的最低价
	 * @param   maxPrice  float  [可选] 筛选价格的最高价
	 * @param  uid                int [选填] 用户ID
	 * @param   order  str  [可选]   new-desc[新品]|price-asc[价格升]|price-desc|sold-count[销量倒序]
	 * @return    [json]     {"status":true,"data":{"total":573,"itemArr":[{"pro_id":"101237","prb_name":"信义","pro_status":"1","pro_name":"刹车片刹车皮盘式片\/大众,斯柯达,奔腾","pro_shop_id":"172999","pro_sale_price":"0.08","pro_count":"82","pro_user_discount":"Y","pro_sold_count":"18","pro_part_id":"2927","pri_code":"XYD133","pri_weight":"1.000","pri_frt_id":"3098","pro_sel_des":"一线品牌，性价比超高，放心购买！","pri_invoice":"0","pri_warranty":"0","pri_return_promise":"1","price":"0.08","price_type":1,"pro_price":{"title":"销售价","price":"0.08"},"pic":["http:\/\/192.168.1.42\/file_center\/center\/read.php?site=b2c&c=product&f=shop172999\/product\/400\/9572a9ba8751c46d.jpg&i=42"],"num":[{"factory":"信义","display":"XYD133"},{"factory":"OE","display":"272 016 15 20"}],"shop_id":"172999","shop_name":"广州宜配奔宝","shop_logo":"http:\/\/192.168.1.42\/file_center\/center\/read.php?site=b2c&c=shopLogo&f=100\/ab69897d8bfd60bc.jpg&i=42","shop_pct_ids":"19,1901,14423,14424","shop_address":"三元里大道1181号志诚商贸中心401室","shop_area":["广东省","广州市","白云区","三元里街道"]}]},"code":0,"encry":0,"runtime":495}
	 *pro_id 产品id   prb_name 品牌  pro_status 0未上架   1售卖中  -1违规  2预售  pro_name 名称  pro_shop_id 店铺id  pro_sale_price 销售价 pro_count 库存
	 *pro_sold_count  销量  pro_part_id 分类ID   pri_code 商家型号    price_type 1：销售价 2 促销价 3 会员价  pro_price  展示价格  pic 图片  num 号码
	 * 
	 * @author lu
	 * @copyright 2019-01-08
	 */
	function searchProduct()
	{
		$Params = mvc::$URL_PARAMS;
		$perPage=!empty($Params['perPage'])?(int)$Params['perPage']:20;
		$B2cProduct = new B2cProduct();
		$isPart=!empty($Params['isPart'])?$Params['isPart']:false;
		$res = $B2cProduct->searchShopItem($Params, $perPage,$isPart);
		$result = $res['data'];
		$data=[];
		$data['total']=(int)$res['data']['total'];
		$itemArr = [];
		if(!empty($result['proIds']))
		{
			$res = $B2cProduct->getAnyProductInfo($result['proIds'], $Params['uid'], [], $Params['m3Id']);
			
			$itemArr = array_values($res['data']);
			$shopIdArr=array_unique(array_column($itemArr, 'pro_shop_id'));
			//店铺信息
			if(!empty($shopIdArr))
			{
				// $YpwUser= new YpwUser();
				// $res=$B2cProduct->get('sh_shop',['shop_id','shop_name','shop_logo','shop_pct_ids','shop_address'],sprintf(' and shop_id in (%s)',implode(',',$shopIdArr)));
				// $shopRes=$res['data'];
				// if(!empty($shopRes))
				// {
				// 	foreach ($shopRes as $k=> $v) 
				// 	{
				// 		$v['shop_logo']=mvc::$cfg['FILE_CENTER']['b2c']['url_get'].'&c=shopLogo&f='.$v['shop_logo'].mvc::$cfg['FILE_CENTER']['b2c']['get_uri'];
				// 		if(!empty($v['shop_pct_ids']))
				// 		{
				// 			$areRes=$YpwUser->getAddrByIds($v['shop_pct_ids']);
				// 			$v['shop_area']=array_values($areRes['data']);
				// 		}
				// 		$shopRes[$k]=$v;
				// 	}
				// }
				// $shopRes=array_column($shopRes,null, 'shop_id');
			}
			if(!empty($itemArr))
			{
				foreach ($itemArr as $k => $v) 
				{
					$v=!empty($shopRes[$v['pro_shop_id']])?array_merge($v,$shopRes[$v['pro_shop_id']]):$v;
					$itemArr[$k]=$v;
				}
			}
		}
		$data['itemArr']=$itemArr;
		LibFc::ReturnJson(true, $data);
	}
	/**
	 * @method    获取商城搜索分类
	 * @http get 
	 * @param   mod3Id int  [可选] 车型id
	 * @param   keyword str  [可选] 关键字
	 * @param   minPrice  float  [可选] 筛选价格的最低价
	 * @param   maxPrice  float  [可选] 筛选价格的最高价
	 * @return    [json]        {"status":true,"data":[{"part_id":"3004","pt_parent_part_id":"0","part_name":"转向系统","pt_path":"0","children":[{"part_id":"3006","pt_parent_part_id":"3005","part_name":"横拉杆及球头","pt_path":"0,3004,3005"}]}],"code":0,"encry":0,"runtime":402}
	 * @author lu
	 * @copyright 2019-01-09
	 */
	function getSearchPart()
	{
		$Params = mvc::$URL_PARAMS;
		$B2cProduct = new B2cProduct();
		$res=$B2cProduct->getSearchPart($Params);
		$result=$res['data'];
		$data=[];
		if(!empty($result['sortIds']))
		{
			$res=$B2cProduct->getPart($result['sortIds']);//三级
			$partArr=$res['data'];
			$pidArr=[];
			foreach ($partArr as $v) 
			{
				$pathArr=explode(',',$v['pt_path']);
				$pidArr[]=end($pathArr);
			}
			$pidArr=array_unique($pidArr);
			$res=$B2cProduct->getPart($pidArr);//倒数第二级
			$data=$res['data'];
			foreach ($data as $k=> $v) 
			{				
				foreach ($partArr as $vv) 
				{
					if($v['part_id']==$vv['pt_parent_part_id'])
					{
						$data[$k]['children'][]=$vv;
					}
				}
			}
		}
		LibFc::ReturnJson(true, $data);
	}
	/**
	 * @method    获取热门分类
	 * @http get 
	 * @return    [json]         {"status":true,"data":[{"part_id":"4005","pt_parent_part_id":"3058","part_name":"机顶胶","pt_path":"0,3057,3058"},{"part_id":"4006","pt_parent_part_id":"3058","part_name":"减震器","pt_path":"0,3057,3058"},{"part_id":"4012","pt_parent_part_id":"4011","part_name":"控制臂","pt_path":"0,3057,4011"},{"part_id":"3006","pt_parent_part_id":"3005","part_name":"横拉杆及球头","pt_path":"0,3004,3005"},{"part_id":"2927","pt_parent_part_id":"2917","part_name":"气缸垫","pt_path":"0,2890,2917"},{"part_id":"2928","pt_parent_part_id":"2917","part_name":"气门室盖垫","pt_path":"0,2890,2917"},{"part_id":"2931","pt_parent_part_id":"2930","part_name":"正时皮带","pt_path":"0,2890,2930"},{"part_id":"2933","pt_parent_part_id":"2930","part_name":"正时皮带轮","pt_path":"0,2890,2930"},{"part_id":"2967","pt_parent_part_id":"2966","part_name":"发动机风扇","pt_path":"0,2890,2966"},{"part_id":"2979","pt_parent_part_id":"2966","part_name":"水泵","pt_path":"0,2890,2966"},{"part_id":"2989","pt_parent_part_id":"2988","part_name":"燃油泵","pt_path":"0,2890,2988"},{"part_id":"2957","pt_parent_part_id":"2950","part_name":"机油泵","pt_path":"0,2890,2950"}],"code":0,"encry":0,"runtime":321}
	 * @author lu
	 * @copyright 2019-01-10
	 */
	function getHotSalePart()
	{
		$data=[];
		$index='1,1';//要取的数组下标
		$file=mvc::$cfg['ROOT'].'mod_b2c/cache/indexPart.php';
		if(file_exists($file))
		{
			$allPart=include($file);
			$indexArr=explode(',',$index);
			$part=[];
			$len=count($indexArr);
			if($len>1)
			{
				$part=!empty($allPart['PA'.$indexArr[0]]['part'][$indexArr[1]]['PB'])?$allPart['PA'.$indexArr[0]]['part'][$indexArr[1]]['PB']:[];
			}
			if(!empty($part))
			{
				$seq=array_column($part, 'seq');
				$partId=array_column($part, 'id');
			}
			array_multisort($seq,$partId);
			$partIdSeq=$partId=array_filter($partId);
			if(!empty($partId))
			{
				$B2cProduct = new B2cProduct();
				$table = 'bc_product left join sh_shop on pro_shop_id=shop_id and shop_status = 1 and pro_status =1';
				$res=$B2cProduct->get($table,['distinct(pro_part_id)'],sprintf(' and pro_part_id in (%s)',implode(',',$partId)));
				$partId=array_column($res['data'], 'pro_part_id');
				if(!empty($partId))
				{
					$res=$B2cProduct->getPart($partId);//三级
					$partArr=$res['data'];
					//处理排序
					if(!empty($partArr))
					{
						$partArr=array_column($partArr,null, 'part_id');
						foreach ($partIdSeq as $v) 
						{
							if(!empty($partArr[$v]))
							{
								$data[]=$partArr[$v];
							}
						}
					}
				}
			}
		}
		LibFc::ReturnJson(true, $data);
	}
	function getRecomPart()
	{
		// return $this->getHotSalePart();
		
		$data=[4021,4023,4006,2962];
		$B2cProduct = new B2cProduct();
		$res=$B2cProduct->getPart($data);//三级
		LibFc::ReturnJson(true, $res['data']);
	}


	/**
	  * @method 商城知名品牌的车型品牌
	  * @http	get
	  * @param  shopid              string [必填] 店铺ID
	  * @author soul
	  * @copyright 2019/5/27
	  * @return {"status":true,"data":[{"brand_id":"6","brand_name":"奥迪","brand_initial":"AD","brand_keyword":"AD,AUDI,奥迪","brand_code":"AD"}...],"code":0,"encry":0,"runtime":493}
	  */
	public function getB2cShopBrand()
	{
		$Params = mvc::$URL_PARAMS;
		$shopid = (int) $Params['shopid'];
		$arr = [];
		$B2cBase = new B2cBase();
		$Ypc2Base = new Ypc2Base();
		$table = 'bc_product join sh_shop on pro_shop_id=shop_id and shop_status = 1 and pro_status =1 and shop_id='.$shopid.' join bc_product_brand_link on pbl_pro_id=pro_id';
		$res = $B2cBase->get($table, ['distinct pbl_brand_id'], '');
		if(!empty($res['data']))
		{
			$where = sprintf(" and brand_id in (%s) order by brand_initial", implode(',', array_column($res['data'], 'pbl_brand_id')));
			$res = $Ypc2Base->get('bc_brand', ['brand_id', 'brand_name', 'brand_initial', 'brand_keyword', 'brand_code'], $where);
			$arr = $res['data'];
		}
		LibFc::ReturnJson(true, $arr);
	}


	/**
	  * @method 商城知名品牌的车型品牌的车型级
	  * @http	get
	  * @param  shopid              string [必填] 店铺ID
	  * @param  brand_id              string [必填] 车型品牌ID
	  * @author soul
	  * @copyright 2019/5/27
	  * @return {"status":true,"data":[{"make_id":"34","make_name":"一汽奥迪","mods":[{"mod1_id":"215","mod1_name":"A3"},{"mod1_id":"216","mod1_name":"A4"},{"mod1_id":"217","mod1_name":"A4L"},{"mod1_id":"218","mod1_name":"A6L"},{"mod1_id":"219","mod1_name":"Q3"},{"mod1_id":"220","mod1_name":"Q5"}]},{"make_id":"140","make_name":"奥迪(进口)","mods":[{"mod1_id":"1091","mod1_name":"A1"},{"mod1_id":"1092","mod1_name":"A3"},{"mod1_id":"1093","mod1_name":"A4"},{"mod1_id":"1094","mod1_name":"A5"},{"mod1_id":"1095","mod1_name":"A6"},{"mod1_id":"1096","mod1_name":"A7"},{"mod1_id":"1097","mod1_name":"A8"},{"mod1_id":"1098","mod1_name":"Q3"},{"mod1_id":"1099","mod1_name":"Q5"},{"mod1_id":"1100","mod1_name":"Q7"},{"mod1_id":"1101","mod1_name":"R8"},{"mod1_id":"1102","mod1_name":"RS5"},{"mod1_id":"1298","mod1_name":"RS6"},{"mod1_id":"1103","mod1_name":"RS7"},{"mod1_id":"1104","mod1_name":"S3"},{"mod1_id":"1105","mod1_name":"S5"},{"mod1_id":"1106","mod1_name":"S6"},{"mod1_id":"1107","mod1_name":"S7"},{"mod1_id":"1108","mod1_name":"S8"},{"mod1_id":"1109","mod1_name":"SQ5"},{"mod1_id":"1110","mod1_name":"TT"},{"mod1_id":"1523","mod1_name":"TT RS"},{"mod1_id":"1111","mod1_name":"TTS"}]}],"code":0,"encry":0,"runtime":619}
	  */
	public function getB2cShopModel1()
	{
		$Params = mvc::$URL_PARAMS;
		$shopid = (int) $Params['shopid'];
		$arr = [];
		$Ypc2Model = new Ypc2Model();
		$res = $Ypc2Model->getModel(1, ['distinct mod1_id'], sprintf(" and brand_id=%d", (int) $Params['brand_id']));
		if(!empty($res['data']))
		{
			$B2cBase = new B2cBase();
			$table = 'bc_product join sh_shop on pro_shop_id=shop_id and shop_status = 1 and pro_status =1 and shop_id='.$shopid.' join bc_product_model1_link on pml1_pro_id=pro_id';
			$where = sprintf(" and pml1_mod1_id in(%s)", implode(',', array_column($res['data'], 'mod1_id')));
			$res = $B2cBase->get($table, ['distinct pml1_mod1_id'], $where);
			if(!empty($res['data']))
			{
				$where = sprintf(" and mod1_id in(%s) order by make_seq, make_initial, make_name, mod1_name", implode(',', array_column($res['data'], 'pml1_mod1_id')));
				$res = $Ypc2Model->getModel(1, ['make_id','make_name', 'mod1_id', 'mod1_name'], $where);
				foreach($res['data'] as $v)
				{
					$arr[$v['make_id']]['make_id'] = $v['make_id'];
					$arr[$v['make_id']]['make_name'] = $v['make_name'];
					$arr[$v['make_id']]['mods'][] = ['mod1_id'=>$v['mod1_id'], 'mod1_name'=>$v['mod1_name']];
				}
			}
		}
		LibFc::ReturnJson(true, array_values($arr));
	}


	/**
	  * @method 商城知名品牌的二级车型
	  * @http	get
	  * @param  shopid              string [必填] 店铺ID
	  * @param  mod1_id             string [必填] 一级车型ID
	  * @author soul
	  * @copyright 2019/5/27
	  * @return {"status":true,"data":[{"mod2_id":"413","mod2_name":"A4(B6)","mod2_start_year":"2003","mod2_end_year":"2005"},{"mod2_id":"414","mod2_name":"A4(B7)","mod2_start_year":"2005","mod2_end_year":"2006"}],"code":0,"encry":0,"runtime":353}
	  */
	public function getB2cShopModel2()
	{
		$Params = mvc::$URL_PARAMS;
		$shopid = (int) $Params['shopid'];
		$arr = [];
		$Ypc2Model = new Ypc2Model();
		$res = $Ypc2Model->getModel(2, ['distinct mod2_id'], sprintf(" and mod1_id=%d", (int) $Params['mod1_id']));
		if(!empty($res['data']))
		{
			$B2cBase = new B2cBase();
			$table = 'bc_product join sh_shop on pro_shop_id=shop_id and shop_status = 1 and pro_status =1 and shop_id='.$shopid.' join bc_product_model2_link on pml2_pro_id=pro_id';
			$where = sprintf(" and pml2_mod2_id in(%s)", implode(',', array_column($res['data'], 'mod2_id')));
			$res = $B2cBase->get($table, ['distinct pml2_mod2_id'], $where);
			if(!empty($res['data']))
			{
				$where = sprintf(" and mod2_id in(%s)  order by mod2_name, mod2_start_year desc", implode(',', array_column($res['data'], 'pml2_mod2_id')));
				$res = $Ypc2Model->getModel(2, ['mod2_id', 'mod2_name', 'mod2_start_year', 'mod2_end_year'], $where);
				$arr = $res['data'];
			}
		}
		LibFc::ReturnJson(true, $arr);
	}


	/**
	  * @method 商城知名品牌的车型的排量
	  * @http	get
	  * @param  shopid              string [必填] 店铺ID
	  * @param  mod2_id             string [选填] 二级车型ID
	  * @author soul
	  * @copyright 2019/5/27
	  * @return {"status":true,"data":[{"val":"MS44QE1U","cc":"1.8","tran":"手动"}],"code":0}
	  */
	public function getB2cShopModelCc()
	{
		$Params = mvc::$URL_PARAMS;
		$shopid = (int) $Params['shopid'];
		$arr = [];
		$Ypc2Model = new Ypc2Model();
		$res = $Ypc2Model->getModel(3, ['distinct mod3_id'], sprintf(" and mod2_id=%d", (int) $Params['mod2_id']));
		if(!empty($res['data']))
		{
			$B2cBase = new B2cBase();
			$table = 'bc_product join sh_shop on pro_shop_id=shop_id and shop_status = 1 and pro_status =1 and shop_id='.$shopid.' join bc_product_model3_link on pml3_pro_id=pro_id';
			$where = sprintf(" and pml3_mod3_id in(%s)", implode(',', array_column($res['data'], 'mod3_id')));
			$res = $B2cBase->get($table, ['distinct pml3_mod3_id'], $where);
			if(!empty($res['data']))
			{
				$where = sprintf(" and mod3_id in(%s) GROUP BY mod3_cc_name, mod3_transmission order by mod3_cc_name desc", implode(',', array_column($res['data'], 'pml3_mod3_id')));
				$replaceArr = [
					'tran'=>[
						'A/MT'=>'手自一体',
						'AMT'=>'AMT',
						'DCT'=>'双离合',
						'单速'=>'单速',
						'ASG'=>'序列',
						'E-CVT'=>'无级',
						'CVT'=>'无级',
						'AT'=>'自动',
						'MT'=>'手动',
						'自动（模拟10挡）'=>'自动'
					]
				];
				$res = $Ypc2Model->getModel(3, ['mod3_cc_name, mod3_transmission'], $where);
				foreach($res['data'] as $v)
				{
					$kt = '';
					foreach($replaceArr['tran'] as $kt=>$vt)
					{
						if(stripos($v['mod3_transmission'], $kt) !== false)
						{
							$v['trankey'] = $kt;
							$v['mod3_transmission'] = $vt;
							break;
						}
					}
					$v['mod3_cc_name_key'] = $v['mod3_cc_name'];
					$v['mod3_cc_name'] =  empty($v['mod3_cc_name']) || $v['mod3_cc_name'] == 0.0? '纯电动': $v['mod3_cc_name'];
					$arr[$v['mod3_cc_name_key'].'@'.$kt] =['val'=>base64_encode($v['mod3_cc_name_key'].'@'.$kt), 'cc'=>$v['mod3_cc_name'], 'tran'=>$v['mod3_transmission']];
				}
				$arr = array_values($arr);
			}
		}
		LibFc::ReturnJson(true, $arr);
	}

	/**
	  * @method 商城知名品牌的车型品牌的车型
	  * @http	get
	  * @param  shopid              string [必填] 店铺ID
	  * @param  mod1_id              string [选填] 一级车型ID
	  * @param  mod2_id              string [选填] 二级车型ID
	  * @param  cc                  string [选填] 排量
	  * @param  word                string [选填] 关键字
	  * @author soul
	  * @copyright 2019/5/27
	  * @return {"status":true,"data":[{"mod2_id":"413","mod2_name":"A4(B6)","mod2_start_year":"2003","mod2_end_year":"2005","mod3_id":"1780","mod3_name":"1.8T 手动","mod3_start_year":2004,"mod3_end_year":2005,"mod3_engine":"BKB","mod3_kw":"120","mod3_cc":"1781","mod3_transmission":"5MT","mod3_fuel":"汽油"},{"mod2_id":"413","mod2_name":"A4(B6)","mod2_start_year":"2003","mod2_end_year":"2005","mod3_id":"1781","mod3_name":"1.8T 自动","mod3_start_year":2003,"mod3_end_year":2005,"mod3_engine":"BKB","mod3_kw":"120","mod3_cc":"1781","mod3_transmission":"6CVT","mod3_fuel":"汽油"},{"mod2_id":"413","mod2_name":"A4(B6)","mod2_start_year":"2003","mod2_end_year":"2005","mod3_id":"1783","mod3_name":"2.4L","mod3_start_year":2004,"mod3_end_year":2005,"mod3_engine":"BDV","mod3_kw":"125","mod3_cc":"2393","mod3_transmission":"6CVT","mod3_fuel":"汽油"},{"mod2_id":"413","mod2_name":"A4(B6)","mod2_start_year":"2003","mod2_end_year":"2005","mod3_id":"1784","mod3_name":"3.0L","mod3_start_year":2003,"mod3_end_year":2005,"mod3_engine":"BBJ","mod3_kw":"162","mod3_cc":"2976","mod3_transmission":"5A\/MT","mod3_fuel":"汽油"}],"code":0,"encry":0,"runtime":1007}
	  */
	public function getB2cShopModel3()
	{
		$Params = mvc::$URL_PARAMS;
		$shopid = (int) $Params['shopid'];
		$arr = [];
		$Ypc2Model = new Ypc2Model();
		$where = '';
		if(!empty($Params['mod1_id'])) $where .= sprintf(" and mod1_id=%d", (int) $Params['mod1_id']);
		if(!empty($Params['cc']))
		{
			$Params['cc'] = base64_decode($Params['cc']);
			$cc = explode('@', $Params['cc']);
			$where .= sprintf(" and mod3_cc_name = '%s' and (mod3_transmission ='%s' or mod3_transmission REGEXP '^[0-9]+%s$' or mod3_transmission like '电动车%s%%')", LibFc::Escape($cc[0]), LibFc::Escape($cc[1]), LibFc::Escape($cc[1]), LibFc::Escape($cc[1]));
		}

		if(!empty($Params['word']))
		{
			$word = strtoupper(LibFc::Escape($Params['word']));
			$where .= sprintf(" and (UPPER(mod1_name) like '%%%s%%' or UPPER(mod2_name) like '%%%s%%' or UPPER(mod3_name) like '%%%s%%')", $word, $word, $word);
		}
		
		if(!empty($Params['year'])) $where .= sprintf(" and %d >= mod3_start_year  and (%d <= mod3_end_year or mod3_end_year=0) ", $Params['year'], $Params['year']);
		if(!empty($Params['mod2_id'])) $where .= sprintf(" and mod2_id = %d", $Params['mod2_id']);
		if(!empty($where))
		{
			$res = $Ypc2Model->getModel(3, ['distinct mod3_id'], $where);
			if(!empty($res['data']))
			{
				$B2cBase = new B2cBase();
				$table = 'bc_product join sh_shop on pro_shop_id=shop_id and shop_status = 1 and pro_status =1 and shop_id='.$shopid.' join bc_product_model3_link on pml3_pro_id=pro_id';
				$where = sprintf(" and pml3_mod3_id in(%s)", implode(',', array_column($res['data'], 'mod3_id')));
				$res = $B2cBase->get($table, ['distinct pml3_mod3_id'], $where);
				if(!empty($res['data']))
				{
					$where = sprintf(" and mod3_id in(%s)  order by mod3_name, mod3_start_year desc", implode(',', array_column($res['data'], 'pml3_mod3_id')));
					$res = $Ypc2Model->getModel(3, ['brand_etk_id', 'mod3_id', 'make_show_brand', 'brand_name', 'make_name', 'mod2_name', 'mod3_name', 'mod3_start_year', 'mod3_end_year', 'mod3_engine', 'mod3_kw', 'mod3_cc', 'mod3_transmission', 'mod3_fuel'], $where);
					$arr = $res['data'];
				}
			}
		}
		LibFc::ReturnJson(true, $arr);
	}


	/**
	  * @method 商城知名品牌的发动机查询
	  * @http	get
	  * @param  shopid             string [必填] 店铺ID
	  * @param  word                string [必填] 关键字 至少2个字符  CAL
	  * @author soul
	  * @copyright 2019/5/27
	  * @return {"status":true,"data":[{"brand_name":"奥迪","engine":"CALA","fuel":"汽油","kw":"195","cc":"3197"},{"brand_name":"奥迪","engine":"CALB","fuel":"汽油","kw":"199","cc":"3197"}],"code":0}
	  */
	public function searchB2cShopEngine()
	{
		$Params = mvc::$URL_PARAMS;
		$shopid = (int) $Params['shopid'];
		$word = LibFc::FormatNum($Params['word']);
		$arr = [];
		if(strlen($word) < 2) LibFc::ReturnJson(true, $arr);
		
		$B2cBase = new B2cBase();
		$Ypc2Model = new Ypc2Model();
		$where = sprintf(" and mod3_engine_format like '%%%s%%'", $word);
		$res = $Ypc2Model->get('bc_model3', ['distinct mod3_id'], $where);
		if(!empty($res['data']))
		{
			$where = sprintf(" and pml3_mod3_id in(%s)", implode(',', array_column($res['data'], 'mod3_id')));
			$table = 'bc_product join sh_shop on pro_shop_id=shop_id and shop_status = 1 and pro_status =1 and shop_id='.$shopid.' join bc_product_model3_link on pml3_pro_id=pro_id';
			$res = $B2cBase->get($table, ['distinct pml3_mod3_id'], $where);
			if(!empty($res['data']))
			{
				$where = sprintf(" and mod3_id in(%s) group by mod3_engine order by max(brand_initial), mod3_engine", implode(',', array_column($res['data'], 'pml3_mod3_id')));
				$res = $Ypc2Model->getModel(3, ['max(brand_name) brand_name', 'mod3_engine engine', 'max(mod3_fuel) fuel', 'max(mod3_kw) kw','max(mod3_cc) cc'], $where);
				$arr = $res['data'];
			}
		}
		LibFc::ReturnJson(true, $arr);
	}


	/**
	  * @method 商城知名品牌的配件
	  * @http	get
	  * @param  shopid              string [必填] 店铺ID
	  * @param  mod3_id            int [选填] 车型品牌ID
	  * @param  word               string [选填] 关键字
	  * @param  engine              string [选填] 发动机编码
	  * @param  number             string [选填] 号码
	  * @param  spart_id            string [选填] 配件分类
	  * @param  sort_id            string [选填] 店铺分类
	  * @param  uid                int [选填] 用户ID
	  * @author soul
	  * @copyright 2019/5/27
	  * @return {"status":true,"data":{{"pro_id":"134073","prb_name":"路宝陆（KGN）","pro_status":"1","pro_name":"路宝陆（KGN) 水泵 大众 甲壳虫 帕萨特 OE：06A 121 011T","pro_shop_id":"230275","pro_sale_price":"177.00","pro_count":"10","pro_user_discount":"Y","pro_sold_count":"0","pro_part_id":"2979","pri_code":"KGN-VW0353","pri_weight":"0.000","pri_frt_id":"3170","pro_sel_des":"","pri_invoice":"0","pri_warranty":"0","pri_return_promise":"1","price":"177.00","price_type":1,"pro_price":{"title":"销售价","price":"177.00"},"pic":["http:\/\/192.168.1.42\/file_center\/center\/read.php?site=b2c&c=product&f=shop230275\/product\/400\/5cb5dca429399340.jpg&i=42"],"num":[{"factory":"路宝陆（KGN）","display":"KGN-VW0353"},{"factory":"OE","display":"06A 121 011T"}]}....},"code":0,"encry":0,"runtime":398}
	  */
	public function getB2cShopItem()
	{
		$Params = mvc::$URL_PARAMS;
		$arr = [];
		$shopid = (int) $Params['shopid'];
		if(!empty($Params['number']))
		{
			$searchBy = [
				'keyword'=>$Params['number'],
				'type'=>'number',
				'spart_id'=>$Params['spart_id'],
				'sort_id'=>$Params['sort_id'],
			];
		}
		else
		{
			$searchBy = [
				'keyword'=>$Params['word'],
				'mod3Id'=>$Params['mod3_id'],
				'engine'=>$Params['engine'],
				'spart_id'=>$Params['spart_id'],
				'sort_id'=>$Params['sort_id'],
				'type'=>'all'
			];
		}
		$B2cSearch = new B2cSearch();
		$res = $B2cSearch->searchShopItem($shopid, $searchBy, 100);
		if(!empty($res['data']['proIds']))
		{
			$B2cProduct = new B2cProduct();
			$res = $B2cProduct->getAnyProductInfo($res['data']['proIds'], $Params['uid'], []);
			$arr = $res['data'];
		}
		LibFc::ReturnJson(true, $arr);
	}



	/**
	  * @method 第三方数据转换成商城参数
	  * @http	get
	  * @param  partId             int [必填] 商城零件分类ID
	  * @param  type               string [必填] tcd|yp
	  * @param  proId              int [必填] type对应的产品ID
	  * @author soul
	  * @copyright 2019/5/27
	  * @return 
	  */
	public function getPartParaByAny()
	{
		$Params = mvc::$URL_PARAMS;
		$arr = [];
		$partId = (int) $Params['partId'];
		$proId = (int) $Params['proId'];
		if($partId < 1 || $proId < 1 || empty($Params['type'])) LibFc::ReturnJson(true, $arr);
		$B2cBase = new B2cBase();
		$toNamefiled = $Params['type'] == 'tcd'? ['ppl_toname_tcd', 'ppl_toname_tcdcn']: ['ppl_toname_'.$Params['type'].' as ppl_toname'];
		$res = $B2cBase->get('bc_part_param_link join bc_param_label on ppl_pal_id=pal_id', array_merge(['ppl_pal_id as pal_id, pal_name, ppl_style'], $toNamefiled), sprintf(" and ppl_part_id=%d order by ppl_seq", $partId));
		if(empty($res['data'])) LibFc::ReturnJson(true, $arr);
		$arr = $res['data'];
		
		//获取对应产品参数
		$proPara = [];
		switch($Params['type'])
		{
			case 'yp':
				$YpsBase = new YpsBase();
				$res = $YpsBase->get('yp_para_string_link as psl join yp_para_label as pl on psl.labelid = pl.labelid', ['pl.name as pal_name, cn_value as val, 0 AS ppl_style'], sprintf(" AND pid=%d", $proId));
				foreach($res['data'] as $v)
				{
					if(!empty($v['val']))
						$proPara[strtoupper($v['pal_name'])][] = $v['val'];
				}

				$res = $YpsBase->get('yp_para_float_link as psl join yp_para_label as pl on psl.labelid = pl.labelid', ['pl.name as pal_name, value as val, 1 AS ppl_style'], sprintf(" AND pid=%d", $proId));
				foreach($res['data'] as $v)
				{
					if(!empty($v['val']))
						$proPara[strtoupper($v['pal_name'])][] = $v['val'];
				}
				$arr = $this->comparePara($arr, $proPara, 'ppl_toname');
			break;
			case 'tcd':
				$TcdmArt = new TcdmArt();
				//是否有中国版数据
				$tcdcn = false;
				$res = $TcdmArt->get('tof_articles', ['art_cn_artid'], sprintf(" and art_id =%d", $proId), true);
				if(!empty($res['data']))
				{
					$artArr = $res['data'];
					if(!empty($artArr['art_cn_artid']))
					{
						//中国版数据
						$TcdCnBase = new TcdCnBase();
						$res = $TcdCnBase->get('data_product_param', ['case when pam_attrShortName ="" then pam_attrName else pam_attrShortName end as pal_name, pam_attrValue as val, case when pam_attrUnit ="" then 0 else 1 end as ppl_style'], sprintf(" and pam_pro_id=%d AND pam_attrValue !=''", $artArr['art_cn_artid']));
						if(!empty($res['data']))
						{
							$tcdcn = true;
							foreach($res['data'] as $v)
							{
								if(!empty($v['val']))
									$proPara[strtoupper($v['pal_name'])][] = $v['val'];
							}
							$arr = $this->comparePara($arr, $proPara, 'ppl_toname_tcdcn');
						}
					}
					//欧版数据
					if(!$tcdcn)
					{
						mvc::$cfg['dLang'] = 'en';
						$res = $TcdmArt->getArtParam([$proId]);
						if(!empty($res['data'][$proId]))
						{
							foreach($res['data'][$proId] as $row)
							{
								$proPara[strtoupper($row['name'])][] = $row['val'];
							}
						}
						$arr = $this->comparePara($arr, $proPara, 'ppl_toname_tcd');
					}
				}
			break;
			case 'zhipei':
				$BaseDb = new BaseDb(mvc::$cfg['DB']['ZHIPEI']);
				$res = $BaseDb->get('2_param', ['label, value'], sprintf(" and OemId =%d group by label", $proId));
				foreach($res['data'] as $v)
				{
					if(!empty($v['value'])) $proPara[strtoupper($v['label'])][] = $v['value'];
				}
				$arr = $this->comparePara($arr, $proPara, 'ppl_toname');
			break;
		}
		LibFc::ReturnJson(true, array_values($arr));
	}

	//比较参数匹配值
	private function comparePara($arr, $proPara, $filedname)
	{
		//通过名称比较数据
		foreach($arr as $k=>$v)
		{
			foreach(explode(',', $v[$filedname]) as $tname)
			{
				$unistr = strtoupper($tname);
				if(!empty($proPara[$unistr]))
				{
					$v['val'] = implode(',', $proPara[$unistr]);
					unset($proPara[$unistr]);
					break;
				}
			}
			if(!empty($v['val']))
			{
				$arr[$k] = $v;
			}
			else
			{
				unset($arr[$k]);
			}
		}
		return $arr;
	}


	/**
	  * @method 加入购物车
	  * @http  get
	  * @param uid      int [必填]  用户ID
	  * @param proId    int [必填]  产品ID
	  * @param count    int [选填]  增加数量  默认1
	  * @param isCheck  bool [选填]  是否在购物车中选择 true|false  默认true
	  * @author soul
	  * @copyright 2019/10/16
	  * @return {"status":true,"data":此产品在购物车的最新数量,"code":0}
	  */
	public function addProToCart()
	{
		$Params = mvc::$URL_PARAMS;
		$B2cCart = new B2cCart();
		$count = isset($Params['count']) ? $Params['count']: 1;
		$isCheck = isset($Params['isCheck']) ? $Params['isCheck']: true;
		$res = $B2cCart->addCart($Params['proId'], $Params['uid'], $count, $isCheck);
		LibFc::EchoJson($res);
	}


	/**
	  * @method 修改购物车中某配件的信息
	  * @http  get
	  * @param uid      int [必填]  用户ID
	  * @param proId    int [必填]  产品ID
	  * @param count    int [选填]  增加数量  默认1
	  * @param isCheck  bool [选填]  是否在购物车中选择 true|false  默认true
	  * @author soul
	  * @copyright 2019/10/16
	  * @return {"status":true,"data":此产品在购物车的最新数量,"code":0}
	  */
	public function changeCartPro()
	{
		$Params = mvc::$URL_PARAMS;
		$uid = (int) $Params['uid'];
		$proId = (int) $Params['proId'];
		
		$setArr = [];
		if(isset($Params['count']) && $Params['count'] > 0)
			$setArr['car_count'] = (int) $Params['count'];
		if(isset($Params['isCheck']))
			$setArr['car_checked'] = empty($Params['isCheck'])? 0: 1;

		if($uid > 0 && $proId > 0 && !empty($setArr))
		{
			$B2cBase = new B2cBase();
			$B2cBase->set('us_cart', $setArr, sprintf(" and car_pro_id =%d and car_uid=%d", $proId, $uid));
		}
		LibFc::EchoJson(['status'=>true, 'data'=>true]);
	}


	/**
	  * @method 从购物车删除配件或者清空购物车
	  * @http  get
	  * @param uid      int [必填]  用户ID
	  * @param style   string [必填]  根据产品ID删除：pro| 清空：clear
	  * @param proIds   string [style=pro必填]  产品ID 多个逗号分隔
	  * @author soul
	  * @copyright 2019/10/16
	  * @return {"status":true,"data":true,"code":0}
	  */
	public function delCart()
	{
		$Params = mvc::$URL_PARAMS;
		if(!empty($Params['uid']))
		{
			$uid = (int) $Params['uid'];
			$B2cBase = new B2cBase();
			switch($Params['style'])
			{
				case 'pro':
					$t = [];
					foreach(explode(',', $Params['proIds']) as $v)
					{
						$t[] = (int) $v;
					}
					if(!empty($t))
						$B2cBase->del('us_cart', sprintf(" and car_pro_id in (%s) and car_uid=%d", implode(',', $t), $uid));	
				break;
				case 'clear':
					$B2cBase->del('us_cart', 'and car_uid='.$uid);
				break;
			
			}
		}
		LibFc::EchoJson(['status'=>true, 'data'=>true]);
	}


	/**
	  * @method 购物车详情
	  * @http  get
	  * @param uid      int [必填]  用户ID
	  * @author soul
	  * @copyright 2019/10/16
	  * @return pro_sale_price:普通销售价   price：实际购买价格  car_add_price：加入购物车时的价格
	  {"status":true,"data":[{"shop_info":{"shop_id":"224467","shop_uid":"224467","shop_name":"\u83f2\u5c14\u5954\u5b9d","shop_domain":"https:\/\/www.paojd.cn\/shop224467\/"},"items":[{"car_add_price":"140.00","car_checked":"1","car_count":"1","car_prpa_id":"0","shop_id":"224467","pro_id":"122202","pro_name":"FREY(\u83f2\u5c14)\u54c1\u724c\u5b9d\u9a6cE36\u524d\u4e0b\u60ac\u6302\u7403\u5934\u5de6\u53f3\u901a\u7528","pro_sale_price":"140.00","price":"140.00","price_type":1,"pic":["https:\/\/file.paojd.cn\/center\/read.php?site=b2c&c=product&f=shop224467\/product\/400\/e4743d18c0fe56a7.jpg&i=f1"]},{"car_add_price":"50.00","car_checked":"1","car_count":"2","car_prpa_id":"0","shop_id":"224467","pro_id":"121319","pro_name":"FREY(\u83f2\u5c14)\u54c1\u724c\u5b9d\u9a6c N45 N46 N40 E90 E46 E83 E81\u673a\u6cb9\u6ee4\u6e05\u5668","pro_sale_price":"50.00","price":"50.00","price_type":1,"pic":["https:\/\/file.paojd.cn\/center\/read.php?site=b2c&c=product&f=shop224467\/product\/400\/f4f3654e2585f172.jpg&i=f1"]}]},{"shop_info":{"shop_id":"230275","shop_uid":"230275","shop_name":"\u8def\u5b9d\u9646\u54c1\u724c\u6613\u635f\u8d85\u5e02","shop_domain":"https:\/\/www.paojd.cn\/shop230275\/"},"items":[{"car_add_price":"280.00","car_checked":"0","car_count":"1","car_prpa_id":"0","shop_id":"230275","pro_id":"132012","pro_name":"\u8def\u5b9d\u9646\uff08KGN\uff09 \u5239\u8f66\u7247 \u6602\u79d1\u96f7 \u540e\u5239\u8f66\u7247 D883","pro_sale_price":"280.00","price":"280.00","price_type":1,"pic":["https:\/\/file.paojd.cn\/center\/read.php?site=b2c&c=product&f=shop230275\/product\/400\/a002118a7dd2cf1f.jpg&i=f1"]}]}],"code":0}
	  */
	public function getCartList()
	{
		$Params = mvc::$URL_PARAMS;
		$B2cCart = new B2cCart();
		$res = $B2cCart->getCartList($Params['uid']);
		LibFc::EchoJson($res);
	}

	/**
	  * @method 根据购买的产品获取对应的运费【产品必须是同一个店铺内的】
	  * @http  post
	  * @param uid      int [选填]  用户ID
	  * @param pros    string [必填]  产品ID1@数量;产品ID2@数量;.....
	  * @param pct_ids string [必填]  省市区ID  19,1901,14423
	  * @param style string [选填] 运送方式  快递0  EMS1  默认all(返回所有类型)  
	  * @author soul
	  * @copyright 2019/10/16
	  * @return {"status":true,"data":[{"baoyou":0,"yunfei":"40.00","style":0,"style_name":"快递"},{"baoyou":0,"yunfei":"40.00","style":1,"style_name":"EMS"}],"code":0}
	  */
	public function getProFreight()
	{
		$B2cCart = new B2cCart();
		$style = isset($_POST['style']) ? $_POST['style']: 'all';
		$proArr = [];
		foreach(explode(';', $_POST['pros']) as $v)
		{
			$t = explode('@', $v);
			if(count($t) >= 2 && $t[0] > 0 && $t[1] > 0)
			{
				$proArr[] = [
					'pro_id'=>(int) $t[0],	
					'buy_count'=>(int) $t[1],	
				];
			}
		}
		$res = $B2cCart->getProFreight($proArr, $_POST['pct_ids'], $_POST['uid'], $style);
		LibFc::EchoJson($res);
	}

	/**
	 * @method 通过号码或者产品ID  匹配车型
	 * @param  proId  int[$proId、$numArr二选一，优先产品ID]  产品ID  
	 * @param  nums array[$proId、$numArr二选一，优先产品ID]  [
							[
								'factory'=>'OE',
								'display'=>'123-456-789'
							]...
						]
	 * @param  spartId  string [选填] 商城分类ID	1111_22
	 * @author soul12
	 * @copyright 2020/6/10
	 */
	public function matchB2cItemModel()
	{
		$B2cProduct = new B2cProduct();
		$res = $B2cProduct->matchB2cItemModel($_POST['proId'], $_POST['nums'], $_POST['spartId']);
		LibFc::EchoJson($res);
	}


	/**
	 * @method 批量匹配商城产品车型  匹配车型
	 * @param  proIds   array  [['proId'=>xx, 'spartId'=>'商城分类ID 选填']]
	 * @author soul12
	 * @copyright 2020/6/10
	 */
	public function matchB2cAnyItemModel()
	{
		$B2cProduct = new B2cProduct();
		$arr = [];
		foreach($_POST['proIds'] as $v)
		{
			$res = $B2cProduct->matchB2cItemModel($v['proId'], $v['spartId']);
			if(!empty($res['data']['m3ids']))
			{
				$arr[$v['proId']] = $res['data'];
			}
		}
		LibFc::EchoJson(['status'=>true, 'data'=>$arr]);
	}


	/**
	  * @method 获取配件基本信息
	  * @http POST  
	  * @param  proIds array [必填] [11,2222....]
	  * @param  uid int [选填] 用户ID
	  * @param  types [选填] ['numMain', 'picMain', 'picAll', 'desc']
	  * @param  mod3Id [选填] 车型ID
	  * @author soul
	  * @copyright 2017/7/7
	  * @return 
			成功 ["status"=>true, "data"=> [11=>[], ...]] 
			失败 ["status"=>false, "data"=> 错误信息] 
	  */
	public function getAnyProductInfo()
	{
		$B2cProduct = new B2cProduct();
		$res = $B2cProduct->getAnyProductInfo($_POST['proIds'], $_POST['uid'], $_POST['types'], $_POST['mod3Id']);
		LibFc::EchoJson($res);
	}
	

	/**
	  * @method 搜索
	  * @http POST  
	  * @param  word string 关键字
	  * @param  pro_id string 指定配件ID，英文逗号分隔
	  * @param  count int 返回数量 默认 10000
	  * @author soul 
	  * @return
	  */
	public function searchByEs()
	{
		$proIdArr = empty($_POST['pro_id'])? []: explode(',', $_POST['pro_id']);
		$blparams = ['word'=>$_POST['word'], 'shop_id'=>(int)$_POST['shop_id'], 'count'=>(int)$_POST['count'], 'pro_id'=>$proIdArr];
		$B2cElastic = new B2cElastic();
		$res = $B2cElastic->searchProId($blparams);
		LibFc::EchoJson($res);
	}

	/**
	  * @method 重置配件全文搜索  $shopId && $proIdArr 同时为空时，重置所有
	  * @http POST  
	  * @param  shop_id int 指定店铺
	  * @param  pro_id string 指定配件ID，英文逗号分隔
	  * @author soul 
	  * @return
	  */
	public function updateItemWordByEs()
	{
		$B2cElastic = new B2cElastic();
		$proIdArr = empty($_POST['pro_id'])? []: explode(',', $_POST['pro_id']);
		$res = $B2cElastic->updateItemWord((int)$_POST['shop_id'], $proIdArr);
		LibFc::EchoJson($res);
	}


	/**
	  * @method 删除配件索引
	  * @http POST  
	  * @param  pro_id string 指定配件ID，英文逗号分隔
	  * @author soul 
	  * @return
	  */
	public function delItemWordByEs()
	{
		$B2cElastic = new B2cElastic();
		$proIdArr = empty($_POST['pro_id'])? []: explode(',', $_POST['pro_id']);
		$res = $B2cElastic->delItemWord($proIdArr);
		LibFc::EchoJson($res);
	}


	/**
	  * @method 检查商城用户是否需要验证码
	  * @http	get
	  * @param  uid      int [必填] 用户ID
	  * @param  shopid   int [必填] 目录店铺ID
	  * @author soul
	  * @copyright 2022/9/23
	  * @return {"status":true,"data":{"need":false},"code":"","runtime":68}
	  */
	public function checkVinCaptcha()
	{
		$Params = mvc::$URL_PARAMS;
		$need = false;
		$uid = (int) $Params['uid'];
		if(empty($uid)) LibFc::ReturnJson(true, ['need'=>true]);
		
		//当天的查询情况统计
		$date = date('Ymd');
		$YpwBase = new YpwBase();

		$where = sprintf(" and cap_shopid=0 and cap_type='user' and cap_date=%d and cap_uid=%d order by cap_id desc limit 1", $date, $uid);
		$YpwBase = new YpwBase();
		$res = $YpwBase->get('yp_captcha', ['cap_id'], $where, true);
		if(empty($res['data'])) LibFc::ReturnJson(true, ['need'=>true]);

		$where = sprintf(" and v_atime >= %d and v_uid=%d and v_from in ('PJD')", strtotime($date), $uid);
		$res = $YpwBase->get('yt_vin', ['count(*) total'], $where, true);
		$total = $res['data']['total'];
		$max = 50;
		if(empty($total)) LibFc::ReturnJson(true, ['need'=>true]);
		if(
			($total > $max && $total%2 === 0) || 
			($total > 50 && $total%2 === 0)||
			($total <= 50 && $total%3 === 0) ||
			($total <= 10 && $total%4 === 0)
		) LibFc::ReturnJson(true, ['need'=>true]);
		
		LibFc::ReturnJson(true, ['need'=>$need]);
	}

	/**
	 * @method 初始化微信账号
	 * @http	get
	 * @param  room_id      string [必填] 微信群ID，多个用，分割
	 * @author zhengweihua 
	 * @copyright 2025-09-27
	 * @return {"status":true,"data":{"need":false},"code":"","runtime":68}
	 */
	public function initWxAccount()
	{
		$Params = mvc::$URL_PARAMS;
		$room_id = [];
		if(!is_array($Params['room_id'])){
			$room_id = explode(',', $Params['room_id']);
		}
		$B2cShop = new B2cShop();
		$res = $B2cShop->initWxAccount($room_id);
		LibFc::EchoJson($res);
	}
}