<?php
class sellerAction
{
	//只能调用/static/目录下的 js | css | 控件[webuploader、datetimepicker、ueditor、zTree]
	private $HEAD_CSSJS = ['css'=>['css/seller.css'], 'js'=>['js/seller.js'], 'plugin'=>[]];

	function __construct()
	{
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		if(!empty($_SESSION['_shopid']))
		{
			$B2cShop = new B2cShop();
			$shopData = $B2cShop->getShopInfo($_SESSION['_shopid']);
			LibTpl::Set('shopData', $shopData['data']);

			//店铺未读聊天记录条数 包括子账号的id
			$workId = [];
			if (!empty($_SESSION['_shopowner']))
			{
				$res =  $B2cShop->get('sh_worker',['wor_uid'],sprintf('and wor_shop_id = %s',$_SESSION['_shopid']));
				$workId = array_column($res['data'], 'wor_uid');
			}

			$uIdArr = empty($workId) ? [$_SESSION['_shopid']] : array_merge($workId,[$_SESSION['_shopid']]);
			$uidStr = implode(',', $uIdArr);

			$ImBase = new ImBase();
			$where = sprintf('and to_uid in (%s) and readed = 0', $uidStr);
			$total = $ImBase->get('msg',['count(*) as count'],$where,true);
			LibTpl::Set('IMnoRead', $total['data']['count']);
		}

	}


	/**
	  * @method 卖家首页
	  * @author soul 2017/6/16
	  */
	function index()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		LibFc::Go(mvc::$cfg['HOST']['sadmin']);

		$Params = mvc::$URL_PARAMS;
		$headArr = [
			'title'=>'卖家中心-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		$B2cBase = new B2cBase();
		//店铺状态
		$shopStatus = $B2cBase->get('sh_shop',['shop_status','shop_window_count'],sprintf('and shop_id=%d',$_SESSION['_shopid']),true);
		$shopStatusArr=array('-2'=>'开通中','-1'=>'禁用','0'=>'暂停','1'=>'营业中',);
		LibTpl::Set('shopStatus',$shopStatusArr[$shopStatus['data']['shop_status']]);
		LibTpl::Set('windowCount',$shopStatus['data']['shop_window_count']);
		//计算出售中的宝贝
		$sale = $B2cBase->get('bc_product',['count(*) count','pro_status'],sprintf('and pro_shop_id=%d and (pro_status=1 or pro_status=0) group by pro_status',$_SESSION['_shopid']));
		$sale = array_column($sale['data'],'count','pro_status');
		LibTpl::Set('onSale',$sale['1']);
		//计算等待上架的宝贝
		LibTpl::Set('notOnSale',$sale['0']);

		//计算待付款的订单
		$pay = $B2cBase->get('or_order',['count(*) count','ord_status'],sprintf("and ord_shop_id=%d and (ord_status='creat' or ord_status='paied') and ord_seller_delete=0 and ord_user_delete=0 group by ord_status",$_SESSION['_shopid']));
		$pay = array_column($pay['data'],'count','ord_status');
		LibTpl::Set('waitPay',$pay['creat']);
		//计算待发货的订单
		LibTpl::Set('waitSend',$pay['paied']);

		//计算售后中的订单
		$refund = $B2cBase->get('or_order ',['count(*) count'],sprintf("and ord_id in(select orp_ord_id from or_order left join or_order_product on ord_id=orp_ord_id where orp_refund_status in ('wait','confirm','refuse','refundpro') and ord_shop_id=%d and ord_status != 'cancel') ",$_SESSION['_shopid']),true);
		LibTpl::Set('refund',$refund['data']['count']);

		//计算未使用橱窗的配件
		$promoted = $B2cBase->get('bc_product',['count(*) count','pro_promoted'],sprintf("and pro_shop_id=%d and pro_status=1 and pro_promoted='Y'  group by pro_promoted",$_SESSION['_shopid']));
		$promoted = array_column($promoted['data'],'count','pro_promoted');
		// print_r($promoted);
		LibTpl::Set('noPromoted',$promoted['N']);
		//计算已使用橱窗的配件
		LibTpl::Set('promoted',$promoted['Y']);

		LibTpl::Set('headArr', $headArr);
		LibTpl::Put();
	}


	/**
	  * @method 开通店铺
	  * @author soul 2017/6/16
	  */
	function open()
	{
		$OthCheck = new OthCheck();
		$OthCheck->noShop();

		$Params = mvc::$URL_PARAMS;
		$B2cBase=new B2cBase();
		$res=$B2cBase->get('sh_shop',['shop_id','shop_uid','shop_status','shop_name','shop_logo','shop_pct_ids','shop_address','shop_license','shop_idcard','shop_com_code','shop_apply_tatus','shop_apply_res','shop_com_name','shop_main_idcard','shop_main_tel','shop_cor_tel','shop_cor_name','shop_main_name','shop_apply_sers'],sprintf(' and shop_id=%d',$_SESSION['_shopid']),true);
		// print_r($res['data']);
		// if(empty($res['data']))
		// 	LibFc::Go('/seller/index');
		$res['data']['shop_idcard']=explode(',',$res['data']['shop_idcard']);
		$res['data']['shop_main_idcard']=explode(',',$res['data']['shop_main_idcard']);
		$res['data']['shop_apply_sers'] = explode(',',$res['data']['shop_apply_sers']);
		
		LibTpl::Set('data',$res['data']);
		$headArr = [
			'title'=>'开通店铺-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		$this->HEAD_CSSJS['plugin'][] = 'webuploader';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('店铺申请', $ComTitle);
		LibTpl::Put();
	}


	/**
	  * @method 选择发布配件分类
	  * @author soul 2017/6/16
	  */
	function productPart()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('PC01');
		$Params = mvc::$URL_PARAMS;
		LibTpl::Set('Params', $Params);

		$headArr = [
			'js'=>'part',
			'title'=>'选择发布配件的分类-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		$this->HEAD_CSSJS['js'][] = 'js/part.js';
		$this->HEAD_CSSJS['js'][] = 'js/sellerProduct.js';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Put();
	}


	/**
	  * @method 通过关键字获取零件ID
	  * @author soul 2017/6/22
	  */
	function ajaxGetPartByword()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$word = LibFc::Escape($Params['word']);
		$resArr = [];
		if($word != '')
		{
			$B2cBase = new B2cBase();
			$res = $B2cBase->get('bc_part', ['distinct part_id part_id'], sprintf(" and (part_keyword like '%%%s%%' or part_name like '%%%s%%')", $word, $word));
			if(!empty($res['data']))
			{
				$whereArr = [];
				$temPartidArr = [];
				foreach($res['data'] as $v)
				{
					$temPartidArr[] = $v['part_id'];
					$whereArr[] = sprintf(" pt_path like '%%,%s,%%' or pt_path like '%%,%s'", $v['part_id'], $v['part_id']);
				}
				$whereArr[] = sprintf(" pt_part_id in (%s)", implode(',', $temPartidArr));
				$res = $B2cBase->get('bc_part_tree join bc_part on part_id=pt_part_id', ["concat(pt_path, ',', pt_part_id) as path"], sprintf(" and (%s)  and part_is_end = 1 order by pt_seq", implode(' or ', $whereArr)));
				foreach($res['data'] as $v)
				{
					$resArr[] = $v['path'];
				}
			}
		}
		LibFc::ajaxJsonEncode(['status'=>true, 'data'=>array_unique($resArr)]);
	}


	/**
	  * @method 获取店铺最近使用的零件
	  * @author soul 2017/6/22
	  */
	function ajaxGetRecentPart()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$resArr = [];
		$B2cBase = new B2cBase();
		$res = $B2cBase->get('sh_recent_part', ['rep_part_path'], sprintf(" and rep_shop_id = %d order by rep_etime desc", $_SESSION['_shopid']));
		foreach($res['data'] as $v)
		{
			$resArr[] = $v['rep_part_path'];
		}
		LibFc::ajaxJsonEncode(['status'=>true, 'data'=>array_unique($resArr)]);
	}

	/**
	  * @method 获取运费模板列表
	  * @author soul 2017/6/22
	  */
	function ajaxGetFreightTpl()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		$res = $B2cBase->get('sh_freight_tpl', ['frt_id pid', 'frt_name pname'], sprintf(" and frt_shop_id = %d order by frt_default desc", $_SESSION['_shopid']));
		$resArr = $res['data'];
		LibFc::ajaxJsonEncode(['status'=>true, 'data'=>$resArr]);
	}


	/**
	  * @method 获取添加产品中某运费模板明细
	  * @author soul 2017/6/22
	  */
	function getFreightTplDes()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = MVC::$URL_PARAMS;
		$templateId=$Params['frtId'];
		if((int)$templateId)
		{
			$B2cFreight=new B2cFreight();
			$YpwAddr= new YpwAddr();
			$res=$B2cFreight->getSellerTemplateList($_SESSION['_shopid'],$templateId);
			// print_r($res['data']);
			$emsTemplate='';
			$freTemplate='';
			foreach ($res['data'] as $k => $v)
			{
				$contentHtml='';
				$headContent='';
				$data=$YpwAddr->getAddrByIds($v['frt_send_pct']);
				$cityName=implode('',$data['data']);
				$foot='<div class="freightTplDes-foot">发货地：'.$cityName.'，承诺发货时间：'.$v['frt_send_hour'].'小时</div>';
				$unit=$v['frt_valuation_method']>0 ? 'kg':'件';
				$tag[0]=1;
				$tag[1]=1;
				foreach ($v['link'] as $i => $j)
				{
					if($j['ftl_default']=='Y')
					{
						$contentHtml='<div class="gray2">默认：'.$j['ftl_begin_count'].$unit.'内'.sprintf('%.2f',$j['ftl_begin_money']).'元，每增加'.$j['ftl_next_count'].$unit.'，加'.sprintf('%.2f',$j['ftl_next_money']).'元</div>';
						if($j['ftl_shipping_method']>0)
						{
							//ems
							$emsTemplate.=$contentHtml;
							$headContent.='<span onmouseover="showTemp(this,\'ems\');">EMS</span>';
						}
						else
						{
							$freTemplate.=$contentHtml;
							$headContent.='<span class="" onmouseover="showTemp(this,\'fre\');">快递</span>';
						}
					}
					else
					{
						if($tag[$j['ftl_shipping_method']]>1) continue;
						$pathArr=explode(',', $j['path']);
						if(count($pathArr)>10)
						{
							$city=implode(',',array_slice($pathArr, 0,10)).'.....';
						}
						else
						{
							$city=$j['path'];
						}
						$contentHtml2='<div class="gray2">指定地区：'.$city.'&nbsp;&nbsp;'.$j['ftl_begin_count'].$unit.'内'.sprintf('%.2f',$j['ftl_begin_money']).'元，每增加'.$j['ftl_next_count'].$unit.'，加'.sprintf('%.2f',$j['ftl_next_money']).'元</div>';
						if($j['ftl_shipping_method']>0)
						{
							//ems
							$emsTemplate.=$contentHtml2;
						}
						else
						{
							$freTemplate.=$contentHtml2;
						}
						$tag[$j['ftl_shipping_method']]++;
					}

				}
				if($freTemplate!=='')
				{
					$freTemplate='<div class="freightLeft" id="fre">'.$freTemplate.'</div>';
				}
				if($emsTemplate!=='')
				{
					$emsTemplate='<div class="freightLeft" id="ems">'.$emsTemplate.'</div>';
				}
				if($res['data'][0]['frt_is_free']=='Y')
				{
					$html='<div><div class="proPublishNav"><a class="a_blue" target="_blank" href="/seller/addSellerTemplate?frt_tid='.$templateId.'">查看模板详情</a></div><div>免运费</div></div>'.$foot;
				}
				else
				{
					$html='<div><div class="proPublishNav">'.$headContent.'<a class="a_blue" target="_blank" href="/seller/addSellerTemplate?frt_tid='.$templateId.'">查看模板详情</a></div>'.$freTemplate.$emsTemplate.'</div>'.$foot;
				}
			}
			LibFc::ajaxJsonEncode(['status'=>true, 'data'=>$html]);
		}
	}

	/**
	  * @method 获取车型数据
	  * @author soul 2017/6/22
	  */
	function ajaxGetModel()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();

		$html = '';
		$modelArr = [];
		if(!empty($_POST['type']))
		{
			$ComModel = new ComModel();
			$ComBase = new ComBase();
			switch($_POST['type'])
			{
				case 'tree':
					//某品牌的所有车型树
					$brandId = empty($_POST['brandId'])? 0: (int) $_POST['brandId'];
					if($brandId > 0)
					{
						$where = sprintf(" and mod1_brand_id =%d order by make_seq, make_initial, mod1_name, mod2_name, mod3_name", $brandId);
						$res = $ComModel->getModel(3, ['*'], $where);
						$modelArr = $res['data'];
					}
					LibTpl::Set('modelArr', $modelArr);
					$html = LibTpl::Fetch('seller/ajaxGetTreeModel.php');
					LibFc::ajaxJsonEncode(['status'=>true, 'data'=>$html]);
					exit;
				break;
                case 'keyword':
					$wordArr = LibFc::keyword($_POST['keyword']);
                    if(!empty($wordArr))
					{
						$ComModel = new ComModel();
						$wordIdArr = [];
						$caseArr = [];
						foreach($wordArr as $word)
						{
							$res = $ComModel->get('yp_model_word', ['mw_id'], sprintf(" and mw_word like '%s%%'", LibFc::Escape($word)));
							if(!empty($res['data']))
							{
								$ids = array_column($res['data'], 'mw_id');
								$caseArr[] = sprintf("WHEN mwl_mw_id IN (%s) THEN %d", implode(',', $ids), count($caseArr)+1);
								$wordIdArr = array_merge($wordIdArr, $ids);
							}
						}
						if(!empty($caseArr))
						{
							$wordIdArr = array_unique($wordIdArr);
							for($i = count($caseArr); $i > 0; $i--)
							{
								$table = sprintf("( SELECT mwl_mod3_id, CASE %s END AS mwl_mw_id FROM yp_model_word_link WHERE mwl_mw_id IN (%s)) AS a", implode(' ', $caseArr), implode(',', $wordIdArr));
								$res = $ComModel->get($table, ['mwl_mod3_id'], sprintf(" GROUP BY mwl_mod3_id HAVING COUNT(DISTINCT mwl_mw_id) = %d limit 100", $i));
								if(!empty($res['data']))
								{
									$mod3IdArr = array_column($res['data'], 'mwl_mod3_id');
									break;
								}
							}
						}
                    }
					if(!empty($mod3IdArr))
					{
						$where = sprintf(" and mod3_id in (%s) order by brand_seq, brand_initial, make_seq, make_initial, mod1_name, mod2_name, mod3_name", implode(',', $mod3IdArr));
						$res = $ComModel->getModel(3, ['*'], $where);
						$modelArr = $res['data'];
					}
                    LibTpl::Set('modelArr', $modelArr);
                    $html = LibTpl::Fetch('seller/ajaxGetTreeModel.php');
                    LibFc::ajaxJsonEncode(['status'=>true, 'data'=>$html]);
                    exit;
                break;
				case 'proModel':
					if(!empty($_POST['mod3Ids']))
					{
						$mod3IdArr = [];
						foreach(explode(',', $_POST['mod3Ids']) as $v)
						{
							$mod3IdArr[] = (int) $v;
						}
						$mod3IdArr = array_unique($mod3IdArr);
						$ComModel = new ComModel();
						$where = sprintf(" and mod3_id in (%s) order by brand_seq, brand_initial, make_seq, make_initial, mod1_name, mod2_name, mod3_name", implode(',', $mod3IdArr));
						$res = $ComModel->getModel(3, ['*'], $where);
						$modelArr = $res['data'];
					}
					LibTpl::Set('modelArr', $modelArr);
					$html = LibTpl::Fetch('seller/ajaxGetProModel.php');
					LibFc::ajaxJsonEncode(['status'=>true, 'data'=>$html]);
					exit;
				break;
				case 'oeNum':
					$oeArr = [];
					if(!empty($_POST['oeNum'])) $oeArr = $_POST['oeNum'];

					//隐藏的OE
					if(!empty($_POST['proId']))
					{
						$B2cBase = new B2cBase();
						$res = $B2cBase->get('bc_number', ['num_display'], sprintf(" and num_factory = 'OE' and num_show=0 and num_pro_id=%s", $_POST['proId']));
						$oeArr = array_merge($oeArr, array_column($res['data'], 'num_display'));
					}

					$LibYpApi = new LibYpApi();
					//通过第三方数据来的
					if(!empty($_POST['fromPro']))
					{
						$LibEncry = new LibEncry();
						$t = $LibEncry->decode(base64_decode($_POST['fromPro']));
						$tArr = explode('@', $t);

						//宜配产品 TCD产品数据
						if(!empty($tArr[0]) && !empty($tArr[1]))
						{
							$fromType = $tArr[0];
							$fromProId = $tArr[1];
							$res = $LibYpApi->Get('number/itemNumber', ['type'=>$fromType, 'proId'=>$fromProId, 'numtype'=>'oe']);
							$oeArr = array_merge($oeArr, array_column($res['data'], 'display'));
						}
					}

					if(!empty($oeArr))
					{
						$res = $LibYpApi->get('ypc/getM3idsByNum', [], ['nums'=>$oeArr]);
						if(!empty($res['data']))
						{
							$mod3IdArr = $res['data'];
							$ComModel = new ComModel();
							$where = sprintf(" and mod3_id in (%s) order by brand_seq, brand_initial, make_seq, make_initial, mod1_name, mod2_name, mod3_name", implode(',', $mod3IdArr));
							$res = $ComModel->getModel(3, ['*'], $where);
							$modelArr = $res['data'];
						}
					}
					LibTpl::Set('modelArr', $modelArr);
					$html = LibTpl::Fetch('seller/ajaxGetNumModel.php');
					LibFc::ajaxJsonEncode(['status'=>true, 'data'=>$html]);
					exit;
				break;
				case 'engine':
					$tempArr = [];
					foreach($_POST['engs'] as $v)
					{
						$tempArr[] = sprintf("'%s'", LibFc::Escape($v));
					}
					if(!empty($tempArr))
					{
						$ComModel = new ComModel();
						$where = sprintf(" and mod3_engine in (%s) order by brand_seq, brand_initial, make_seq, make_initial, mod1_name, mod2_name, mod3_name", implode(',', $tempArr));
						$res = $ComModel->getModel(3, ['*'], $where);
						$modelArr = $res['data'];
					}
					LibTpl::Set('modelArr', $modelArr);
					$html = LibTpl::Fetch('seller/ajaxGetEngModel.php');
					LibFc::ajaxJsonEncode(['status'=>true, 'data'=>$html]);
					exit;
				break;
			}
		}
		LibFc::ajaxJsonEncode(['status'=>true, 'data'=>$html]);
	}

	/**
	  * @method 搜索发动机
	  * @author soul 2017/6/22
	  */
	function ajaxGetEngine()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$engArr = [];
		if(!empty($Params['word']))
		{
			$ComBase = new ComBase();
			$where = sprintf(" and mod3_engine_format like '%%%s%%' order by length(mod3_engine_format), mod3_engine", LibFc::FormatNum($Params['word']));
			$res = $ComBase->get('bc_model3', ['distinct mod3_engine'], $where);
			$engArr = $res['data'];
		}
		LibTpl::Set('engArr', $engArr);
		$html = LibTpl::Fetch();
		LibFc::ajaxJsonEncode(['status'=>true, 'data'=>$html]);
	}


	/**
	  * @method 获取添加产品中某运费模板明细
	  * @author soul 2017/6/22
	  */
	function ajaxGetProDesTpl()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		$res= $B2cBase->get('bc_product_desc_tpl', ['pdt_id', 'pdt_name'], sprintf(" and pdt_shop_id=%d", $_SESSION['_shopid']));
		LibFc::ajaxJsonEncode($res);
	}

	/**
	  * @method 发布配件
	  * @author soul 2017/6/16
	  */
	function productPublish()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();

		$Params = mvc::$URL_PARAMS;
		if(!empty($Params['proId']))
		{
			$OthCheck->rule('PC02');
		}else
		{
			$OthCheck->rule('PC01');
		}
		$B2cBase = new B2cBase();
		$B2cBrand=new B2cBrand();
		$B2cProduct = new B2cProduct();
		if(!empty($_POST['pro']))
		{

			$brandName=$_POST['shopBrand'];
			if(!empty($brandName))
			{
				$brandIdData=$B2cBrand->addShopBrand($_SESSION['_shopid'],$brandName);
				if($brandIdData['data'])
				{
					$_POST['pro']['prb_id']=$brandIdData['data'];
				}
			}else
			{
				$_POST['pro']['prb_id']=0;
			}
			$baseArr = [];
			foreach($_POST['pro'] as $k=>$v)
			{
				$v = trim($v);
				switch($k)
				{
					case 'name':
					break;
					case 'price_vip1':
						$v=(float) $v;
					break;
					case 'price_vip2':
						$v=(float)($v);
					break;
					case 'price_vip3':
						$v=(float)($v);
					break;
					case 'price_vip4':
						$v=(float)($v);
					break;

				}
				$baseArr['pro_'.$k] = $v;
			}
			$baseArr['pro_shop_id'] = $_SESSION['_shopid'];
			$baseArr['pro_smt_code'] = $_POST['modtype'];
			$dataArr = [
				'base'=>$baseArr,
				'info'=>$_POST['info'],
				'imgs'=>$_POST['imgs'],
				'nums'=>[],
				'shopSort'=>explode(',', $_POST['shopSort'])
			];
			$dataArr[$baseArr['pro_smt_code']] = [];
			switch($baseArr['pro_smt_code'])
			{
				case 'all':
					$dataArr['modall'] = [];
					if(!empty($_POST['modall']['mod']) && is_array($_POST['modall']['mod']))
					{
						foreach($_POST['modall']['mod'] as $mk=>$mv)
						{
							$dataArr['modall'][] = ['pml3_mod3_id'=>$mv, 'pml3_remark'=>$_POST['modall']['remark'][$mk]];
						}
					}
				break;
				case 'chassis':
					if(!empty($_POST['modchassis']['mod']) && is_array($_POST['modchassis']['mod']))
					{
						foreach($_POST['modchassis']['mod'] as $mk=>$mv)
						{
							$dataArr['modchassis'][] = ['pmc_mch_code'=>$mv, 'pmc_remark'=>$_POST['modchassis']['remark'][$mk]];
						}
					}
				break;
				case 'engine':
					if(!empty($_POST['modengine']['mod']) && is_array($_POST['modengine']['mod']))
					{
						foreach($_POST['modengine']['mod'] as $mk=>$mv)
						{
							$dataArr['modengine'][] = ['pme_men_code'=>$mv, 'pme_remark'=>$_POST['modengine']['remark'][$mk]];
						}
					}
				break;
			}

			$dataArr['info']['pri_return_promise'] = !empty($dataArr['info']['pri_return_promise'])? 1: 0;
			$dataArr['base']['pro_promoted'] = !empty($dataArr['base']['pro_promoted'])? 'Y': 'N';

			switch($dataArr['base']['pro_status'])
			{
				case 1:
					$dataArr['info']['pri_publish_time'] = time();
				break;
				case 2:
					$dataArr['info']['pri_publish_time'] = strtotime($dataArr['info']['pri_publish_time']);
				break;
				default:
					$dataArr['info']['pri_publish_time'] = 0;
				break;
			}
			if(!empty($_POST['promotion']))
			{
				$dataArr['base']['pro_promotion_btime'] = strtotime($dataArr['base']['pro_promotion_btime']);
				$dataArr['base']['pro_promotion_etime'] = strtotime($dataArr['base']['pro_promotion_etime']);
			}
			else
			{
				$dataArr['base']['pro_promotion_btime'] = 0;
				$dataArr['base']['pro_promotion_etime'] = 0;
			}

			//号码'nums'
			$mainNum = isset($_POST['mainNum'])? $_POST['mainNum']: 0;
			if(count($_POST['num'])){
				foreach($_POST['num'] as $k=>$v)
				{
					if(trim($v['factory']) != '' && trim($v['display']) != ''&&preg_match('/\w+/',trim($v['display'])))
					{
						$dataArr['nums'][] = [
							'num_factory'=>$v['factory'],
							'num_display'=>$v['display'],
							'num_show'=>1,
							'num_from'=>'',
							'num_fromid'=>0,
							'num_ismain'=> $mainNum == $k? 1: 0
						];
					}
				}
			}

			$oriTpl='';
			if(!empty($_POST['proId']))
			{
				$proId = $_POST['proId'];
				//获取原来的tpl id
				$orTplData=$B2cProduct->get('bc_product',['pro_ppt_id'],sprintf(' and pro_id=%d and pro_shop_id=%d',$proId,$_SESSION['_shopid']),true);
				$oriTpl=$orTplData['data']['pro_ppt_id'];
				$B2cProduct->setProduct($_SESSION['_shopid'], $proId, $dataArr);
			}
			else
			{
				$res = $B2cProduct->addProduct($dataArr,$_SESSION['_shopid']);
				$proId = $res['data'];
			}
			if($_POST['pro']['ppt_id'])
			{
				//修改自定义参数
				$B2cProduct->setShopParam($_SESSION['_shopid'],$proId,$_POST['pro']['ppt_id'],$_POST['paramVal'],$_POST['paramLabel'],$_POST['paramUnit'],$oriTpl);
			}
			$historyData=$B2cProduct->addProductHistory($proId,$_SESSION['_shopid']);
			if($historyData['status']&&$historyData['data'])
			{
				$B2cProduct->set('bc_product',['pro_prh_id'=>$historyData['data']],sprintf(' and pro_id=%d and pro_shop_id=%d',$proId,$_SESSION['_shopid']));
			}
			LibTpl::Set('proId',$proId);
			LibTpl::Put('/seller/publishSuccess.php');
			exit();
			//防止重复提交
			// LibTpl::Success('保存成功', mvc::$cfg['HOST']['b2c'].'seller/productPublish?proId='.$proId);
		}

		$res = $B2cProduct->get('sh_modtype', ['smt_code', 'smt_name'], ' order by smt_seq');
		LibTpl::Set('modTypeArr', array_column($res['data'], null, 'smt_code'));

		$proArr = [
			'base'=>[],
			'nums'=>[],
			'ypcnums'=>[],
			'hidenum'=>[],
			'modall'=>[],
			'modchassis'=>[],
			'modengine'=>[],
		];
		$proArr['base']['pro_status'] = 1;
		$B2cPart  = new B2cPart();

		$copyProId = 0;
		if(!empty($Params['proId']))
		{
			$proId = (int) $Params['proId'];
		}
		else if(!empty($Params['copyProId']))
		{
			$copyProId = (int) $Params['copyProId'];
			$proId = $copyProId;
		}

		if($proId > 0)
		{
			$res = $B2cProduct->getProduct(['*'], sprintf(" and pro_id = %d and pro_shop_id=%d", $proId, $_SESSION['_shopid']), true);
			$proArr['base'] = $res['data'];
			//产品不存在或者是其它店铺的产品
			if(empty($proArr['base']))
			{
				LibFc::Go('/seller/productPart');
			}
		}

		if(!empty($Params['partPath']))
		{
			$temp = [];
			foreach(explode(',', $Params['partPath']) as $k=>$v)
			{
				$temp[] = (int) $v;
			}
			$last = array_pop($temp);
			//查询是否有该分类
			$res = $B2cBase->get('bc_part_tree join bc_part on part_id=pt_part_id', ['pt_part_id', 'pt_path'], sprintf(" and pt_part_id=%d and pt_path='%s' and part_is_end=1", $last, implode(',', $temp)), true);
			if(empty($res['data']))
			{
				LibFc::Go('/seller/productPart');
			}
			$res = $res['data'];
			$proArr['base']['pro_part_id'] = $res['pt_part_id'];
			$proArr['base']['pro_part_path'] = $res['pt_path'].','.$res['pt_part_id'];
			//新增产品
			$B2cPart->addRecentPart($_SESSION['_shopid'], $proArr['base']['pro_part_path']);
		}

		if(isset($Params['drafId'])&&LibFc::Int($Params['drafId']))
		{
			$draftWhere=((int)$proId>0)?
				sprintf(' and prda_id=%d and prda_pro_id=%d and prda_shop_id=%d',(int)$Params['drafId'],$proId,$_SESSION['_shopid'])
				:
				sprintf(' and prda_id=%d and prda_shop_id=%d',(int)$Params['drafId'],$_SESSION['_shopid']);
			$result=$B2cBase->get('bc_product_draft',['prda_id','prda_name','prda_etime','prda_text'],$draftWhere,true);
			if(!$result['data'])
			{
				LibFc::Go('/seller/productList');
				exit();
			}
		}
		//配件品牌
		if($proArr['base']['pro_prb_id'])
		{
			$brandNowData=$B2cBase->get('bc_probrand',['prb_id','prb_name'],sprintf(' and prb_id=%d',$proArr['base']['pro_prb_id']),true);
			$proArr['base']['prb_name'] = $brandNowData['data']['prb_name'];
		}
		$brandData=$B2cBrand->get('sh_probrand_link left join bc_probrand on sprl_prb_id=prb_id',['prb_id','prb_name'],sprintf(' and sprl_shop_id=%d order by sprl_seq asc',$_SESSION['_shopid']));
		// $brandData=$B2cBrand->getBrandByPart($proArr['base']['pro_part_id']);
		if(count($brandData['data']))
		{
			$proArr['brandArr']=$brandData['data'];
		}
		//最后编辑的配件品牌
		$lastBrand=$B2cBase->get('bc_product', ['pro_prb_id'], sprintf(" and pro_shop_id=%d order by pro_set_time desc", $_SESSION['_shopid']),true);
		// print_r($lastBrand);
		LibTpl::Set('lastBrand', $lastBrand['data']['pro_prb_id']);
		$res = $B2cPart->getAllPart();
		$AllPart = $res['data'];

		$proArr['partNames'] = [];
		foreach(explode(',', $proArr['base']['pro_part_path']) as $v)
		{
			if(!empty($AllPart[$v]))
			{
				$proArr['partNames'][] = $AllPart[$v]['part_name'];
			}
		}

		//分类参数 2019/7/12
		/*$res = $B2cPart->getPartParam($proArr['base']['pro_part_id']);
		$ParaArr=$res['data'];
		$sort=array();
		if(count($ParaArr))
		{
			$sort=array_column($ParaArr, 'ppl_seq');
			array_multisort($sort, SORT_ASC, $ParaArr);
			// print_r($ParaArr);
			// die;
			$valRes=array_column($ParaArr, 'pal_id');
			$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=[];
			if(count($res['data']))
			{
				foreach ($res['data'] as $v)
				{
					$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']];
					}
				}
			}
		}*/
		// print_r($ParaArr);
		$proArr['partParam'] = $ParaArr;
		$hasShopSortId = [];

		//配件已有数据
		if($proArr['base']['pro_id'] > 0)
		{
			//参数
			$res = $B2cProduct->getProductParam($proArr['base']['pro_id']);
			$proArr['param'] = $res['data'];
			// print_r($proArr['param']);
			//图片
			$res = $B2cProduct->getProductPic($proId, true);
			$proArr['imgs'] = $res['data'];
			// print_r($proArr['imgs']);

			//号码
			$res = $B2cBase->get('bc_number', ['num_id', 'num_factory', 'num_display', 'num_format', 'num_ismain'], sprintf(" and num_self=0 and num_show=1 and num_pro_id=%s order by num_factory, num_format", $proId));
			$proArr['nums'] = $res['data'];

			if($proArr['base']['pro_smt_code'] == 'chassis')
			{
				//底盘模式的车型
				$res = $B2cBase->get('bc_product_modchassis', ['pmc_mch_code as mch_code, pmc_remark as remark, 1 chk'], sprintf(" and pmc_pro_id=%d", $proId));
				$proArr['modchassis'] = array_column($res['data'], null, 'mch_code');
			}
			else if($proArr['base']['pro_smt_code'] == 'engine')
			{
				//发动机模式的车型
				$res = $B2cBase->get('bc_product_modengine', ['pme_men_code as men_code, pme_remark as remark, 1 chk'], sprintf(" and pme_pro_id=%d", $proId));
				$proArr['modengine'] = array_column($res['data'], null, 'men_code');
			}
			else
			{
				//全车件模式
				$res = $B2cBase->get('bc_product_model3_link', ['pml3_mod3_id as mod3_id, pml3_remark as remark, 1 chk'], sprintf(" and pml3_pro_id=%d", $proId));
				$proArr['modall'] = array_column($res['data'], null, 'mod3_id');
				if(!empty($proArr['modall'])) $proArr['base']['pro_smt_code'] = 'all';
			}

			//店铺分类
			$res = $B2cBase->getFieldUniVal('bc_product_sort', 'prs_sort_id', sprintf(" and prs_pro_id=%d", $proId));
			$hasShopSortId = $res['data'];
		}

		//车型模式
		if(empty($proArr['base']['pro_smt_code']))
		{
			if(!empty($proArr['base']['pro_part_id']))
			{
				$res = $B2cBase->get('bc_product', ['pro_smt_code'], sprintf(" and pro_shop_id=%d and pro_part_id=%d and pro_smt_code != '' order by pro_id desc limit 1",$_SESSION['_shopid'], $proArr['base']['pro_part_id']), true);
				if(!empty($res['data']['pro_smt_code'])) $proArr['base']['pro_smt_code'] = $res['data']['pro_smt_code'];
			}

			if(empty($proArr['base']['pro_smt_code']))
			{
				$res = $B2cBase->get('sh_shop', ['shop_smt_code'], sprintf(" and shop_id=%d limit 1",$_SESSION['_shopid']), true);
				if(!empty($res['data']['shop_smt_code'])) $proArr['base']['pro_smt_code'] = $res['data']['shop_smt_code'];
			}
		}

		//自动获取上一次添加产品的的配件品牌
		if(empty($proArr['base']['prb_name']))
		{
			$twhere = sprintf(" and pro_shop_id=%d order by pro_id desc limit 1", $_SESSION['_shopid']);
			$res = $B2cBase->get('bc_product join bc_probrand on pro_prb_id=prb_id', ['prb_name'], $twhere, true);
			if(!empty($res['data'])) $proArr['base']['prb_name_last'] = $res['data']['prb_name'];
		}

		$proArr['base']['pri_publish_time'] = isset($proArr['base']['pri_publish_time'])? $proArr['base']['pri_publish_time']: time();

		$imgCount = !empty($proArr['imgs']) ? count($proArr['imgs']): 0;
		for($i = $imgCount; $i < 5; $i++)
		{
			$proArr['imgs'][$i] = [];
		}
	
		//店铺分类
		$B2cShopSort = new B2cShopSort();
		$res = $B2cShopSort->getShopSortZtree($_SESSION['_shopid'], $hasShopSortId, false);
		LibTpl::Set('shopSortArr', $res['data']);
		LibTpl::Set('hasShopSortId', $hasShopSortId);
		//计算草稿数量
		//
		$draftWhere=sprintf(' and prda_shop_id=%d and prda_pro_id=%d',$_SESSION['_shopid'],(int)$Params['proId']);
		$draftCount=$B2cBase->get('bc_product_draft',['count(*) count'],$draftWhere,true);
		// print_r($draftCount);
		LibTpl::Set('draftCount', $draftCount['data']['count']);
		//厂商自动完成
		$res = $B2cProduct->getAutoFactory($_SESSION['_shopid']);
		LibTpl::Set('autoFactory', $res['data']);



		$res = $B2cBase->get('sh_shop', ['shop_window_count'], sprintf(" and shop_id=%d", $_SESSION['_shopid']), true);
		$shopInfo = $res['data'];

		$res = $B2cBase->get('bc_product', ['count(*) window_used'], sprintf(" and pro_shop_id=%d and pro_promoted = 'Y'", $_SESSION['_shopid']), true);
		$shopInfo['window_used'] =  $res['data']['window_used'];

		LibTpl::Set('shopInfo', $shopInfo);
		//获取自定义配件参数
		if(!empty($Params['proId']))
		{
			$res=$B2cBase->get('bc_product',['pro_ppt_id'],sprintf(' and pro_shop_id=%d and pro_id=%d',$_SESSION['_shopid'],$Params['proId']),true);
			if($res['data']['pro_ppt_id'])
			{
				$tplId=$res['data']['pro_ppt_id'];
				$proId=$Params['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, $_SESSION['_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);
			}
			LibTpl::Set('paramArr', $newArr);
		}
		// 会员等级信息
		$B2cShop = new B2cShop();
		$res = $B2cShop->getMemberSetting($_SESSION['_shopid']);
		// var_dump($res);
		LibTpl::Set('memberSetting',$res['data']);
		$is_show = array_filter(array_column($res['data'], 'mem_status'));
		LibTpl::Set('memberSettingHide',empty($is_show)?1:0);

		$res = $B2cBase->get('bc_part_small', ['pas_id', 'pas_name'], sprintf(" and pas_part_id=%d order by pas_seq", $proArr['base']['pro_part_id']));
		LibTpl::Set('smallPartArr', $res['data']);

		//复制产品，置空产品ID
		if($copyProId > 0)
		{
			$proId = 0;
			$proArr['base']['pro_id'] = 0;
		}
		LibTpl::Set('proArr', $proArr);

		// meta
		$headArr = [
			'js'=>'part',
			'title'=>'发布配件-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('Params',$Params);
		// js控件
		$this->HEAD_CSSJS['plugin'][] = 'webuploader';
		$this->HEAD_CSSJS['plugin'][] = 'ueditor';
		$this->HEAD_CSSJS['plugin'][] = 'typeahead';
		$this->HEAD_CSSJS['plugin'][] = 'zTree';
		$this->HEAD_CSSJS['plugin'][] = 'datetimepicker';
		$this->HEAD_CSSJS['plugin'][] = 'layui';
		$this->HEAD_CSSJS['js'][] = 'js/part.js';
		$this->HEAD_CSSJS['js'][] = 'js/sellerProduct.js';
		$this->HEAD_CSSJS['js'][] = 'js/jquery.autocomplete.js';
		$this->HEAD_CSSJS['css'][] = 'css/jquery.autocomplete.css';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Put();
	}


	//通过全车件模式选择车型
	function getAllModByAny()
	{
		$Params = $_POST;
		$numsArr = [];
		if(!empty($_POST['nums']))
		{
			foreach($_POST['nums'] as $v)
			{
				$t = explode('@', $v);
				$numsArr[] = ['factory'=>$t[0], 'display'=>$t[1]];
			}
		}

		//车型号码
		if(!empty($_POST['ypcnum']))
		{
			$LibEncry = new LibEncry();
			foreach($_POST['ypcnum'] as $v)
			{
				$t = json_decode($LibEncry->decode($v), true);
				if(!empty($t['num_display']) && !empty($t['num_factory']) && !empty($t['num_fromid']))
				{
					$numsArr[] = ['factory'=>$t['num_factory'], 'display'=>$t['num_display']];
				}
			}
		}

		//隐藏的OE
		if(!empty($_POST['hideNum']))
		{
			$LibEncry = new LibEncry();
			$hideNum = $LibEncry->decode($_POST['hideNum']);
			$hideNum = json_decode($hideNum, true);
			if(!empty($hideNum) && is_array($hideNum))
			{
				foreach($hideNum as $k=>$v)
				{
					$numsArr[] = ['factory'=>$v['num_factory'], 'display'=>$v['num_display']];
				}
			}
		}
		if(!empty($numsArr)) $Params['nums'] = $numsArr;
		$ComModel = new ComModel();
		$res = $ComModel->getAllModByAny($Params);
		LibFc::ajaxJsonEncode($res);
	}


	//通过底盘件模式选择车型
	function getChassisModByAny()
	{
		$Params = $_REQUEST;
		$ComModel = new ComModel();
		$res = $ComModel->getChassisModByAny($Params);
		LibFc::ajaxJsonEncode($res);
	}
	
	//通过发动机件模式选择车型
	function getEngineModByAny()
	{
		$Params = $_REQUEST;
		$ComModel = new ComModel();
		$res = $ComModel->getEngineModByAny($Params);
		LibFc::ajaxJsonEncode($res);
	}


	/**
	*@method 发货地址库
	*@author 卢 2017/6/12
	*/
	function address()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SG04');
		$Params = mvc::$URL_PARAMS;
		$headArr = [
			'js'=>'part',
			'title'=>'发货地址库-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		$B2cBase = new B2cBase();
		$B2cAddr=new B2cAddr();
		$shopid=$_SESSION['_shopid'];
		$Mylist=$B2cAddr->getMyListSeller($shopid);
		LibTpl::Set('LeftMenu', 'address');
		LibTpl::set('Mylist',$Mylist['data']);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Put();
	}
	/**
	 *@method ajax修改默认地址
	 * @author 卢 2017/6/12
	 */
	function ajaxSetAddr()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SG02');
		$Params = mvc::$URL_PARAMS;
		$id=(int)$Params['id'];
		if($id)
		{
			$arr=array();
			if($Params['name']=='default')
			{
				$arr[]='addr_send_default';
			}
			else if($Params['name']=='refund')
			{
				$arr[]='addr_refund_default';
			}
			$shopid=$_SESSION['_shopid'];
			$B2cAddr=new B2cAddr();
			$re=$B2cAddr->setSellerDefaultAddr($id,$shopid,$arr);
		}
	}
		/**
	  * @method 删除地址
	  * @author 卢 2017/6/12
	  */
	function addressDelete()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SG03');
		if(isset($_GET['addid']))
		{
			$aid=(int)$_GET['addid'];
			if($aid>0)
			{
				$shopid=$_SESSION['_shopid'];
				$B2cBase = new B2cBase();
				$B2cBase->Del('sh_address',' and addr_id='.$aid.' and addr_shop_id='.$shopid);
			}
			LibFc::Go('/seller/address');
			exit();
		}
		else
		{
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>false]);
		}
	}
		/**
	 * @method ajax获取某条收货地址弹窗内容
	 * @author 卢 2017/6/14
	 */
	function ajaxSetAddrHtml()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		$shopId = $_SESSION['_shopid'];
		$Params = mvc::$URL_PARAMS;
		$id = isset($Params['id']) ? (int) $Params['id']: null;
		if($id)
		{
			$AddrDetail=$B2cBase->get('sh_address',['*'],' and addr_id='.$id.' and addr_shop_id='.$shopId,true);
			LibTpl::Set('AddrDetail',$AddrDetail['data']);
		}
		LibTpl::Set('method',$Params['method']);
		$result=LibTpl::Fetch('seller/ajaxSetAddrHtml.php');
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$result]);
		exit;
	}
	/**
	 *@method ajax添加地址
	 * @author 卢 2017/6/14
	 */
	function ajaxAddNewAddr()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SG01');
		$B2cBase = new B2cBase();
		$B2cAddr = new B2cAddr();
		$shopid=$_SESSION['_shopid'];
		if(!empty($_POST['tag']))
		{
			$PathArr=$_POST['province'];
			foreach($PathArr as $k => $v)
			{
				if($v=='0')
				{
					unset($PathArr[$k]);
				}
			}
			$Path=implode(',' , $PathArr);
			$Target=array(
				'addr_shop_id'=>$shopid,
				'addr_name'=>$_POST['name'],
				'addr_pct_ids'=>$Path,
				'addr_address'=>$_POST['detail_addr'],
				'addr_tel'=>$_POST['phone'],
				'addr_alias'=>$_POST['byname']
				);
			$Target['addr_send_default']= $_POST['default']==1 ? 1:0;
			$Target['addr_refund_default']= $_POST['refund']==1 ? 1:0;
			if($_POST['tag']=='add')
			{

				$re=$B2cAddr->checkSellerUniqueAddr($Target,'sh_address');
				if(!$re['data'])
				{
					LibFc::ajaxJsonEncode($re);
					exit;
				}
				else
				{
					$Id = $B2cBase->Add('sh_address',$Target);
					$Insertid=$Id['data'];
				}
			}
			else if($_POST['tag']=='edit')
			{

				$addid=(int)$_POST['addid'];
				$sql=sprintf(' and addr_id=%d and addr_shop_id=%d',$addid,$shopid);
				$res=$B2cBase->Set('sh_address',$Target,$sql);
				$Insertid=$addid;
			}
			$arr=array();
			if($_POST['default']==1&&isset($Insertid))
			{

				$arr[]='addr_send_default';
			}
			if($_POST['refund']==1&&isset($Insertid))
			{
				$arr[]='addr_refund_default';
			}
			if(!empty($arr))
			{
				$B2cAddr->setSellerDefaultAddr($Insertid,$shopid,$arr);
			}
			LibFc::ajaxJsonEncode($res);
			exit;
		}
		else
		{
			LibFc::ajaxJsonEncode(array('status'=>false,'data'=>'false'));
		}
	}
	/**
	 *@method 运费模板
	 * @author 卢 2017/6/15
	 */
	function collhop()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('YF04');
		$Params = mvc::$URL_PARAMS;
		$headArr = [
			'js'=>'part',
			'title'=>'运费模板-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		$shopId=$_SESSION['_shopid'];
		$B2cFreight=new B2cFreight();
		$list=$B2cFreight->getSellerTemplateList($shopId);
		// print_r($list);
		foreach ($list['data'] as $k => $v)
		{
			$emsTotal=0;
			$fTotal=0;
			foreach ($v['link'] as $i => $j)
			{
				if($j['ftl_shipping_method']>0)
				{
					$emsTotal+=1;
				}
				else
				{
					$fTotal+=1;
				}
			}
			$list['data'][$k]['total'][0]=$fTotal;
			$list['data'][$k]['total'][1]=$emsTotal;
		}
		// print_r($list['data']);
		// die;
		LibTpl::Set('LeftMenu', 'collhop');
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('list', $list['data']);
		LibTpl::Put();
	}
	/**
	 *@method 运费模板添加和修改
	 * @author 卢 2017/6/20
	 */
	function addSellerTemplate()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$headArr = [
			'js'=>'part',
			'title'=>'运费模板-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		$B2cBase = new B2cBase();
		$shopId=$_SESSION['_shopid'];
		$B2cFreight=new B2cFreight();
		if(!empty($_POST['tag']))
		{
			$OthCheck->rule('YF01');
			$link=$_POST['default'];
			$pathArr=$_POST['province'];
			foreach($pathArr as $k => $v)
			{
				if($v=='0')
				{
					unset($pathArr[$k]);
				}
			}
			$path=implode(',' , $pathArr);
			$targetTpl=array(
					'frt_shop_id'=>$shopId,
					'frt_name'=>$_POST['name'],
					'frt_is_free'=>$_POST['is_free'],
					'frt_valuation_method'=>$_POST['method'],
					'frt_send_pct'=>$path,
					'frt_send_hour'=>$_POST['send_hour'],
					'frt_add_time'=>time(),
					'frt_last_time'=>time()
				);
			if($_POST['frt_default']=="Y")
			{
				$targetTpl['frt_default']='Y';
			}
			else
			{
				$targetTpl['frt_default']='N';
			}
			if($_POST['tag']=='add')
			{
				$B2cFreight->addSellerTemplate($targetTpl,$link);
				LibFc::Go('/seller/collhop');
			}
			else if($_POST['tag']=='edit')
			{
				unset($targetTpl['frt_add_time']);
				$B2cFreight->editSellerTemplate($targetTpl,$link,$_POST['frt_tid'],$shopId);
			}
			LibFc::Go('/seller/collhop');
		}
		if(isset($Params['frt_tid'])&&LibFc::Int($Params['frt_tid']))
		{
			$OthCheck->rule('YF02');
			$data=$B2cFreight->getSellerTemplateList($shopId,$Params['frt_tid']);
			$method=array();
			foreach ($data['data'][0]['link'] as $k => $v)
			{
				$method[]=$v['ftl_shipping_method'];
				$exit[$v['ftl_shipping_method']][]=$v['ftl_default'];
			}
			$method=array_unique($method);
			LibTpl::Set('exit', $exit);
			LibTpl::Set('method', $method);
			LibTpl::Set('detail', $data['data']);
		}else
		{
			$OthCheck->rule('YF01');
		}
		LibTpl::Set('LeftMenu', 'collhop');
		LibTpl::Set('headArr', $headArr);
		LibTpl::Put();
	}
	/**
	 *@method 运费模板删除
	 * @author 卢 2017/6/21
	 */
	function deleteSellerTemplate()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('YF03');
		$Params = mvc::$URL_PARAMS;
		$shopId=$_SESSION['_shopid'];
		if(LibFc::Int($Params['frt_id']))
		{
			$B2cFreight=new B2cFreight();
			$B2cProduct=new B2cProduct();
			$res=$B2cProduct->getProduct(['pri_pro_id'],sprintf(' and pri_frt_id=%d and pro_shop_id=%d',$Params['frt_id'],$shopId));
			if(count($res['data']))
			{
				LibTpl::Error('该模板已被使用，不允许删除');
				exit();
			}
			$result=$B2cProduct->get('bc_product_pack',['prpa_frt_id'],sprintf(' and prpa_frt_id=%d and prpa_shop_id=%d',$Params['frt_id'],$shopId));
			if(count($result['data']))
			{
				LibTpl::Error('该模板已被使用，不允许删除');
				exit();
			}
			$B2cFreight->deleteSellerTemplate($shopId,$Params['frt_id']);
			LibFc::Go('/seller/collhop');
		}
		LibTpl::Error('模板不属于该店铺');
		exit();
	}
	/**
	 *@method 默认运费模板修改
	 * @author 卢 2017/6/29
	 */
	function setTemplateDefault()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('YF02');
		$Params = mvc::$URL_PARAMS;
		if(LibFc::Int($Params['templateId']))
		{
			$shopId=$_SESSION['_shopid'];
			$B2cFreight=new B2cFreight();
			$B2cFreight->setTemplateDefault($Params['templateId'],$shopId);
		}

	}
	/**
	 *@method ajax获取弹窗地址列表
	 * @author 卢 2017/6/15
	 */
	function ajaxGetAddrHtml()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$path=trim($_POST['path'],',');
		$otherPath=trim($_POST['otherPath'],',');
		$parentPath=trim($_POST['parentPath']);
		$YpwAddr=new YpwAddr();
		$data=$YpwAddr->getAddrTree();
		LibTpl::Set('list',$data['data']);
		LibTpl::Set('path',explode(',', $path));
		LibTpl::Set('parentPath',explode(',', $parentPath));
		LibTpl::Set('otherPath',explode(',', $otherPath));
		LibTpl::Set('method',$_POST['method']);
		$result=LibTpl::Fetch('seller/ajaxSelectAddrHtml.php');
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$result]);
		exit;
	}
	/**
	 *@method ajax拼接选中的地址
	 * @author 卢 2017/6/15
	 */
	function ajaxAddAddr()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$YpwAddr=new YpwAddr();
		$arr=array('status'=>true,'data'=>'','code'=>'');
		if(isset($_POST['id'])||isset($_POST['pid']))
		{
			$parent='';
			if(isset($_POST['pid']))
			{
				$parentName='';
				foreach ($_POST['pid'] as $k => $v)
				{

					$num=$YpwAddr->Get('yp_province_city',['count(*) as count'],' and pc_pid='.$k,true);
					if($num['data']['count']!=count($_POST['idArr'][$k]))
					{
						$parentIdArr=implode(',',$_POST['idArr'][$k]);
						$where1=sprintf(' and pc_id in (%s)',$parentIdArr);
						$data=$YpwAddr->Get('yp_province_city',['pc_name'],$where1);
						foreach ($data['data'] as $i => $j)
						{
							$parentName.=$j['pc_name'].',';
						}
					}
					else
					{
						$where2=sprintf(' and pc_id = %s',$k);
						$data=$YpwAddr->Get('yp_province_city',['pc_name'],$where2);
						foreach ($data['data'] as $i => $j)
						{
							$parentName.=$j['pc_name'].',';
						}
					}
					$parentId.=implode(',',$_POST['idArr'][$k]).',';
					$parent.=','.$k;
				}
				$parent=trim($parent,',');
			}
			if(isset($_POST['id']))
			{
				$_POST['id']=array_filter($_POST['id'], 'LibFc::Int');
				$childId=implode(',',$_POST['id']);
				$where=sprintf(' and pc_id in (%s)',$childId);
				$data=$YpwAddr->Get('yp_province_city',['pc_name'],$where);
				$childName='';
				foreach ($data['data'] as $k => $v)
				{
					$childName.=','.$v['pc_name'];
				}
				$childName=trim($childName,',');
			}
			$name=$parentName.$childName;
			$id=$parentId.$childId;
			$arr['data']=['name'=>trim($name,','),'id'=>trim($id,','),'pid'=>$parent];
		}
		else
		{
			$arr['status']=false;
			$arr['data']='请选择一个有效地区';
		}
		LibFc::ajaxJsonEncode($arr);
		exit;
	}

    /**
      * @method 保存更改/显示店铺分类页面
      * @author xu
      * @copyright 2017/06/30
      * @return  array('status'=> false,'data'=>'hasChild/success/hasGoods','code'=>0);
      */
	function shopSort()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SC01');
		$Params = mvc::$URL_PARAMS;
		$B2cShopSort = new B2cShopSort();
		//获取表单数据,执行入库和修改操作
		if($_SERVER['REQUEST_METHOD']=="POST")
		{
			$data = $_POST['data'];
			$B2cShopSort->saveShopSort($_SESSION['_shopid'], $data);
			$B2cShopSort->getAllShopSort($_SESSION['_shopid'], false);
		}
		//获取店铺分类的数据
		$data = $B2cShopSort->getShopSort($_SESSION['_shopid']);
		LibTpl::Set('sortArr', $data['data']);

		$headArr = [
			'title'=>'店铺分类-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('LeftMenu', 'shopSort');
		LibTpl::Set('headArr', $headArr);
		LibTpl::Put();
	}

    /**
      * @method ajax改变店铺页默认展开情况
      * @author xu
      * @copyright 2017/07/31
      * @return  array('status'=> true,'data'=>'success','code'=>0);/array('status'=> false,'data'=>'error','code'=>0);
      */
	function togSortOpenStatus()
	{
		//店铺是否存在判定
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SC02');
		//类型判定
		$B2cBase = new B2cBase();
		if(!empty($_POST['sort_id']) && !LibFc::Int($_POST['sort_id'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);

		$sort_id = $_POST['sort_id'];

		$where = sprintf(" and sort_id=%d and sort_shop_id=%d",$sort_id,$_SESSION['_shopid']);
		//对传过来的status做状态判定
		$status = (!empty($_POST['STATUS']) && ($_POST['STATUS'] == 'on'))? 1 : 0;

		$B2cBase->set("sh_sort",['sort_open'=>$status],$where);

		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'success']);
	}


    /**
      * @method 删除店铺分类
      * @param  $_POST['id']; 店铺分类ID int
      * @author xu
      * @copyright 2017/06/30
      * @return  '{"status":true,"data":"success/hasGoods","code":0}'
      */
	function checkDelShopSort()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SC03');
		//参数判断
		if(empty($_POST['id'])||!LibFc::Int($id=$_POST['id'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		$B2cShopSort = new B2cShopSort();
		$res = $B2cShopSort->checkDelShopSort($id);
		LibFc::ajaxJsonEncode($res);
	}



	/**
	 * @method  店铺基本设置
	 * @author 廖
	 * @copyright 2017/6/30
	 */
	function shopBase()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SS00');
		$Params = mvc::$URL_PARAMS;
		LibTpl::Set('order','shopBase');
		$B2cBase = new B2cBase();
		if($_SERVER['REQUEST_METHOD'] == 'POST')
		{
			//店铺名称
			if (empty($_POST['shopName']))
			{
				$error = '店铺名称不能为空！';
				goto error;
			}
			//店铺所在地区
			if(!empty($_POST['province']))
			{
				$province = implode(array_filter($_POST['province'],'LibFc::Int'),',');
				if (empty($province))
				{
					$error = '店铺所在地区不能为空！';
					goto error;
				}
			} else
			{
				$error = '店铺所在地区不能为空！';
				goto error;
			}
			//经营地址
			if (empty($_POST['shopAddr']))
			{
				$error = '店铺经营地址不能为空！';
				goto error;
			}
			// 检测店铺名称合法性
			$Where = sprintf(" and shop_id !=%d and shop_name='%s'",$_SESSION['_shopid'],LibFc::Escape($_POST['shopName']));
			$re = $B2cBase->Get('sh_shop',['count(*) count'],$Where,true);
			//检测通过
			if($re['status'] && $re['data']['count'] == 0)
			{
				$dataArr = [
					'shop_name'=>$_POST['shopName'],
					'shop_pct_ids'=>$province,
					'shop_address'=>$_POST['shopAddr'],
					'shop_profile'=>$_POST['profile'],
					'shop_info'=>$_POST['shopInfo']
					];
				$logo = '';
				if (!empty($_POST['imgs']))
				{
					$logoArr = json_decode($_POST['imgs'] ,true);
					$logo = $logoArr['sfile'];
					if(!empty($logo))
					{
						$dataArr['shop_logo'] = $logo;
					}
				}

				if(!empty($_POST['shuiyin-img'])){
                    $logoArrs = json_decode($_POST['shuiyin-img'] ,true);
                    $logos = $logoArrs['sfile'];
                    if($logos){
                        $dataArr['shop_warter'] = $logos;
                    }
                }else{
                    $dataArr['shop_warter'] = '';
                }

				//获取图片旧图片 准备更新
				$logoInfo = $B2cBase->get('sh_shop',['shop_logo','shop_name','shop_profile','shop_warter'],sprintf('and shop_id=%s',$_SESSION['_shopid']),true);
				//更新信息
				$re = $B2cBase->set('sh_shop',$dataArr,' and shop_id='.$_SESSION['_shopid'],['shop_info']);
				if(!$re['status'])
				{
					$error = '更新信息失败';
					goto error;
				}
				//更新数据库之后删除文件中心的旧图片);
				if(!empty($logo) && $logoInfo['data']['shop_logo'] != $logo && !empty($logoInfo['data']['shop_logo']))
				{
					$delLogoArr = ['cate'=>'shopLogo', 'files'=>[$logoInfo['data']['shop_logo']]];
					$OthFileCenter = new OthFileCenter();
					$OthFileCenter->del($delLogoArr);
				}

                //更新数据库之后删除文件中心的水印图片);
                if(empty($dataArr['shop_warter']))
                {
                    $delLogoArr = ['cate'=>'warter', 'files'=>[$logoInfo['data']['shop_warter']]];
                    $OthFileCenter = new OthFileCenter();
                    $OthFileCenter->del($delLogoArr);
                }

				if ($logoInfo['data']['shop_name'] != $_POST['shopName'] || $logoInfo['data']['shop_profile'] != $_POST['profile'])
				{
					//重置关键字
					$B2cKeyword = new B2cKeyword();
					$res = $B2cKeyword->resetShopKeyword([$_SESSION['_shopid']]);
				}
			}else
			{
				$error = '店铺名称已被使用';
			}
		}
		error:
		$dataArr = $B2cBase->get('sh_shop',['*'],' and shop_id='.$_SESSION['_shopid'],true);
		$headArr = [
			'title'=>'店铺基本设置-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		$this->HEAD_CSSJS['plugin'][] = 'webuploader';
		$this->HEAD_CSSJS['plugin'][] = 'ueditor';
		$this->HEAD_CSSJS['plugin'][] = 'autocomplete';
		$this->HEAD_CSSJS['plugin'][] = 'zTree';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('Error',$error);
		LibTpl::Set('LeftMenu','shopBase');
		LibTpl::Set('data',$dataArr['data']);
		LibTpl::Put();
	}

	/**
	 * 店铺的基本设置
	 * @method ajax 验证店铺名称
	 * @author liao
	 * @copyright 2017/6/30
	 * @return  '{"status":true,"data":"0没有相同数据 或者 >1 有相同的数据"}'
	 */
	function checkShopNameUnique()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Where = '';
		$Where = sprintf(" and shop_id !=%d and shop_name='%s'",$_SESSION['_shopid'],LibFc::Escape($_POST['shopName']));
		$B2cBase = new B2cBase();
		$Return = $B2cBase->Get('sh_shop',['count(*) count'],$Where,true);
		$Return = ['status'=>true, 'data'=>$Return['data']['count']];
		LibFc::ajaxJsonEncode($Return);
	}
	/**
	 * @method    检测域名设置唯一性
	 * @author     廖
	 * @copyright 2017-09-07
	 */
	function ajaxCheckDomainUnique()
	{
		if($_POST['domName']!='')
		{
			$B2cBase = new B2cBase();
			$re = $B2cBase->Get('sh_shop',['count(*) count'],sprintf(" and shop_domain='%s' or shop_domain='%s' and shop_id !=%d",LibFc::Escape($_POST['domName']),LibFc::Escape($_POST['domName']),$_SESSION['_shopid']),true);
			LibFc::ajaxJsonEncode($re);
		}else
		{
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数不正确']);
		}

	}
	/**
	 * @method   更新域名
	 * @author     廖
	 * @copyright 2017-09-07
	 */
	function ajaxOperateBindDomain()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		if($_POST['order']=='bind')
		{
			if($_POST['domUrl']!='')
			{
				$newtime = time();
				$re = $B2cBase->Set('sh_shop',['shop_domain'=>LibFc::Escape($_POST['domUrl']),'shop_top_domain_TIME'=>$newtime],' and shop_id='.$_SESSION['_shopid']);
				if($re['status'] && $re['data']>0)
				{
					$newtime = date('Y-m-d',$newtime);
					LibFc::ajaxJsonEncode(['status'=>true,'data'=>$newtime]);
				}else
				{
					LibFc::ajaxJsonEncode(['status'=>false,'data'=>'更新域名失败']);
				}
			}else
			{
				LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数不正确']);
			}
		}else if($_POST['order']=='unbind')
		{
			$re = $B2cBase->Set('sh_shop',['shop_domain'=>'','shop_top_domain_TIME'=>time()],' and shop_id='.$_SESSION['_shopid']);
			LibFc::ajaxJsonEncode($re);
		}else
		{
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数不正确']);
		}
	}
	/**
	 * @method    配件详情模版
	 * @author     廖
	 * @copyright 2017-07-25
	 */
	public function proDescTpl()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('PM04');
		$B2cBase = new B2cBase();
		$proData = $B2cBase->Get('bc_product_desc_tpl',['pdt_id','pdt_name','pdt_remark','pdt_add_time'],sprintf(' and pdt_shop_id=%d and pdt_type=0 order by pdt_add_time asc',$_SESSION['_shopid']));
		LibTpl::Set('pdtArr',$proData['data']);
		$headArr = [
			'title'=>'配件详情模版-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','proDescTpl');
		LibTpl::Put();
	}
	/**
	 * @method    配件详情模版管理 add/edit
	 * @author     廖
	 * @copyright 2017-07-25
	 */
	public function proDescTplManage()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$headArr = [
				'title'=>'配件模版-跑街的',
				'keyword'=>'',
				'des'=>''
			];

		if($Params['order']=='edit' && LibFc::Int($Params['pdtId']))
		{
			$OthCheck->rule('PM02');
			$B2cBase = new B2cBase();
			$proData = $B2cBase->get('bc_product_desc_tpl',['*'],sprintf(' and pdt_id=%d and pdt_shop_id=%d',$Params['pdtId'],$_SESSION['_shopid']),true);
			if (empty($proData['data']))
				LibTpl::Error('配件模版参数错误','/seller/proDescTpl');
			LibTpl::Set('pdtArr',$proData['data']);
			$headArr['title'] = '编辑配件模版-跑街的';
		}else if($Params['order']=='add')
		{
			$OthCheck->rule('PM01');
			$headArr['title'] = '新增配件模版-跑街的';
		}
		$this->HEAD_CSSJS['plugin'][] = 'webuploader';
		$this->HEAD_CSSJS['plugin'][] = 'ueditor';
		$this->HEAD_CSSJS['plugin'][] = 'autocomplete';
		$this->HEAD_CSSJS['plugin'][] = 'zTree';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','proDescTpl');
		LibTpl::Put();
	}
	/**
	 * @method    删除配件模版
	 * @author     廖
	 * @copyright 2017-10-26
	 */
	public function delproDescTpl()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('PM03');
		if($_POST['order']=='del' && LibFc::Int($_POST['pdtId']))
		{
			$B2cBase = new B2cBase();
			$re =$B2cBase->Del('bc_product_desc_tpl',sprintf(' and pdt_id=%d and pdt_shop_id=%d',$_POST['pdtId'],$_SESSION['_shopid']));
			LibFc::ajaxJsonEncode($re);
		}
		LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数不正确！']);
	}
	/**
	 * @method    保存配件模版数据
	 * @author     廖
	 * @copyright 2017-07-26
	 * @return    ["status"=>true,"data"=>"xxx","code"=>0]
	 */
	public function savePDTInfo()
	{

		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		$infoDataArr = array();
		foreach($_POST['infoArr'] as $key=>$value)
		{
			$infoDataArr[$value['name']]=$value['value'];
		}
		if($infoDataArr['orderType'] == 'add' && !empty(LibFc::Escape($infoDataArr['formatName'])))
		{
			$OthCheck->rule('PM01');
			$dataArr =[
				'pdt_shop_id'=>$_SESSION['_shopid'],
				'pdt_name'=>$infoDataArr['formatName'],
				'pdt_remark'=>$infoDataArr['pdtRemark'],
				'pdt_txt'=>$infoDataArr['pdtTxt'],
				'pdt_add_time'=>time()
			];
			$re = $B2cBase->Add('bc_product_desc_tpl',$dataArr, ['pdt_txt']);
			LibFc::ajaxJsonEncode($re);
		}
		if($infoDataArr['orderType'] == 'edit' && !empty(LibFc::Escape($infoDataArr['formatName'])) && LibFc::Int($infoDataArr['pdtId']))
		{
			$OthCheck->rule('PM02');
			$dataArr =[
				'pdt_shop_id'=>$_SESSION['_shopid'],
				'pdt_name'=>LibFc::Escape($infoDataArr['formatName']),
				'pdt_remark'=>LibFc::Escape($infoDataArr['pdtRemark']),
				'pdt_txt'=>LibFc::Escape($infoDataArr['pdtTxt']),
				'pdt_set_time'=>time()
			];
			$re = $B2cBase->Set('bc_product_desc_tpl',$dataArr,sprintf(' and pdt_id=%d and pdt_shop_id=%d',$infoDataArr['pdtId'],$_SESSION['_shopid']), ['pdt_txt']);
			$re['data']=$infoDataArr['pdtId'];
			LibFc::ajaxJsonEncode($re);
		}
	}
	/**
	 * @method    配件列表
	 * @author 卢
	 * @copyright 2017-07-27
	 */
	public function productList()
	{
		set_time_limit(0);
		ini_set('memory_limit', '512M');
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('PC04');
		$headArr = [
				'title'=>'配件列表-跑街的',
				'keyword'=>'',
				'des'=>''
			];
		$this->HEAD_CSSJS['plugin'][] = 'zTree';
		LibTpl::Set('headArr', $headArr);
		$shopId=$_SESSION['_shopid'];
		$Params = mvc::$URL_PARAMS;
		// print_r($Params);
		// die;
		$where=' and pro_shop_id='.$shopId;
		$perPage=isset($_COOKIE['perPage'])? $_COOKIE['perPage'] : 20;
		$B2cProduct=new B2cProduct();
		$B2cPart = new B2cPart();
		$B2cBase=new B2cBase();
		$B2cShopSort=new B2cShopSort();
		//零件分类
		$res=$B2cPart->getPartByPath();
		LibTpl::Set('partArr',$res['data']);
		$page=isset($Params['page']) ? $Params['page'] : 1;
		$where.=isset($Params['status'])&&$Params['status']!='' &&$Params['status']!='default'?' and pro_status='.$Params['status']:'';
		$where.=isset($Params['recom'])&&$Params['recom']!='default'?sprintf(" and pro_promoted='%s'",$Params['recom']):'';
		$where.=(isset($Params['proId'])&&LibFc::Int($Params['proId']))?sprintf(' and pro_id=%d',(int)$Params['proId']):'';
		LibTpl::Set('params', $Params);

		//分类处理
		$path1=isset($Params['path1'])&&!empty($Params['path1']) ? ','.$Params['path1'] : '';
		$path2=isset($Params['path2'])&&!empty($Params['path2']) ? ','.$Params['path2'] : '';
		$path3=isset($Params['path3'])&&!empty($Params['path3']) ? ','.$Params['path3'] : '';
		$partPath='0'.$path1.$path2.$path3;
		$start=strrpos($partPath,',');
		$last=trim(substr($partPath, $start),',');
		if(LibFc::Int($last)&&$last>0)
		{
			// echo $last;
			$partRes=$B2cProduct->get('bc_part left join bc_part_tree on part_id=pt_part_id',['part_id','pt_parent_part_id','part_is_end']);
			// print_r($partRes);
			$cateRes=$B2cPart->getPartIsEnd($partRes['data'],$last);
			// print_r($cateRes);
			$cateId=array();
			$cateId=array_column($cateRes['data'], 'part_id');
			$cateId=array_unique($cateId);
			if(count($cateId))
			{
				$where.=sprintf(' and pro_part_id in(%s)',implode(',', $cateId));

			}
			else
			{
				$where.=' and pro_id<-1';
			}
		}
		if(!empty($Params['partName']))
		{
			$keywordArr=LibFc::keyword($Params['partName']);
			if(count($keywordArr))
			{
				$keywordStr="'".implode("','",$keywordArr)."'";
				// $keywordWhere=sprintf(' and key_txt in(%s)',$keywordStr);
				// $keywordProData=$B2cProduct->get('bc_keyword right join bc_product_keyword on prk_key_id=key_id',['prk_pro_id'],$keywordWhere);
				$where.=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) group by prk_pro_id having count(*)=%d",$keywordStr, count($keywordArr)));
			}
			else
			{
				//关键字搜索为空，搜索名称
				$where.=sprintf(" and pro_name like '%%%s%%'",LibFc::Escape($Params['partName']));
			}
		}
		if(!empty($Params['pri_self_remark'])) $where.=sprintf(" and pri_self_remark like '%%%s%%'",LibFc::Escape($Params['pri_self_remark']));
		//价格范围
		if(isset($Params['minPrice']) && $Params['minPrice'] != '')
			$where.= sprintf(' and (case when (pro_promotion_btime<=%d and pro_promotion_etime>=%d) then pro_promotion_price else pro_sale_price end) >= %.2f',time(),time(), $Params['minPrice']);
		if(isset($Params['maxPrice']) && $Params['maxPrice'] != '')
			$where.= sprintf(' and (case when (pro_promotion_btime<=%d and pro_promotion_etime>=%d) then pro_promotion_price else pro_sale_price end) <=%.2f',time(),time(), $Params['maxPrice']);
		//销量范围
		$where.=(isset($Params['minCount'])&&LibFc::Int($Params['minCount'])) ? sprintf(" and pro_sold_count >=%d",LibFc::Int($Params['minCount'])) : '';
		$where.=(isset($Params['maxCount'])&&LibFc::Int($Params['maxCount'])) ? sprintf(" and pro_sold_count <=%d",LibFc::Int($Params['maxCount'])) : '';
		//促销
		switch ($Params['promote'])
		{
			case 'Y':
				$where.=' and (pro_promotion_btime >0)';
				break;
			case 'N':
				$where.=' and (pro_promotion_btime is null or pro_promotion_btime =0)';
				break;
			case 'ON':
				$where.=sprintf(' and (pro_promotion_btime <=%d and pro_promotion_etime>=%d)',time(),time());
				break;
		}
		//满减
		switch ($Params['manjian'])
		{
			case 'Y':
				$where.=" and pro_manjian='Y'";
				break;
			case 'N':
				$where.=" and pro_manjian='N'";
				break;
		}
		//会员打折
		switch ($Params['discount'])
		{
			case 'Y':
				$where.=" and pro_user_discount='Y'";
				break;

			case 'N':
				$where.=" and pro_user_discount='N'";
				break;
		}
		//橱窗
		switch ($Params['proHost'])
		{
			case 'Y':
				$where.=" and pro_promoted='Y'";
				break;

			case 'N':
				$where.=" and pro_promoted='N'";
				break;
		}
		if(!empty($Params['pic']))
		{
			switch ($Params['pic'])
			{
				case '1':
					$where.=sprintf(' and pro_id not in(%s)',sprintf("select pro_id from bc_product_pic left join bc_product on pp_pro_id=pro_id where pro_shop_id=%d",$_SESSION['_shopid']));
					break;

				case '2':
					$where.=sprintf(' and pro_id in(%s)',sprintf("select pro_id from bc_product_pic left join bc_product on pp_pro_id=pro_id where pro_shop_id=%d",$_SESSION['_shopid']));
					break;
			}
		}
		//库存
		if(isset($Params['minProCount']) && $Params['minProCount'] != '')
			$where .= sprintf(" and pro_count >= %d", $Params['minProCount']);

		if(isset($Params['maxProCount']) && $Params['maxProCount'] != '')
			$where .= sprintf(" and pro_count <=%d", $Params['maxProCount']);

		//店铺分类
		$shopCate=(!empty($Params['shopCate'])) ? trim($Params['shopCate'],',') : '';
		if(!empty($shopCate))
		{
			$shopCateArr=explode(',',$shopCate);
			$shopCateArr=array_filter($shopCateArr,'LibFc::Int');
			$shopCate=implode(',',$shopCateArr);
			$where.=sprintf(' and pro_id in(%s)',sprintf('select prs_pro_id from bc_product left join bc_product_sort on pro_id=prs_pro_id where prs_sort_id in(%s)',$shopCate));
		}
		//配件号码
		if(!empty($Params['proNumber']))
		{
			$where.=sprintf(" and pro_id in(select num_pro_id from bc_number where num_format like '%%%s%%' or num_display like '%%%s%%')",LibFc::Escape($Params['proNumber']),LibFc::Escape($Params['proNumber']));
		}
		if(LibFc::Int($Params['nonum']))
		{
			switch ($Params['nonum']) {
				case '1':
					$where.=sprintf(' and pro_id not in(select num_pro_id  from bc_number left join bc_product on pro_id=num_pro_id where num_self=0 and pro_shop_id=%d)',$_SESSION['_shopid']);
					break;
				case '2':
					$where.=sprintf(' and pro_id in(select num_pro_id  from bc_number left join bc_product on pro_id=num_pro_id where num_self=0 and pro_shop_id=%d)',$_SESSION['_shopid']);
					break;
			}
		}
		if(LibFc::Int($Params['nomodel']))
		{
			switch ($Params['nomodel']) {
				case '1':
					$where.=' and pro_id not in(select pml1_pro_id from bc_product_model1_link)';
					break;
				case '2':
					$where.=' and pro_id in(select pml1_pro_id from bc_product_model1_link)';
					break;
			}
		}
		//排序
		switch ($Params['order'])
		{
			case 'sedesc':
				$order=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 'seasc':
				$order=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;
			case 'tasc':
				$order='pro_add_time asc';
				break;
			case 'stasc':
				$order='pro_set_time asc';
				break;
			case 'stdesc':
				$order='pro_set_time desc';
				break;
			case 'sdesc':
				$order='pro_sold_count desc';
				break;
			case 'sasc':
				$order='pro_sold_count asc';
				break;
			case 'toasc':
				$order='pro_count asc';
				break;
			case 'todesc':
				$order='pro_count desc';
				break;
			default:
				$order='pro_add_time desc';
				break;
		}

		//下载
		if(!empty($Params['export']))
		{
			$table = 'bc_product join bc_product_info on pri_pro_id = pro_id';
			$temptable = $table.' join bc_part on pro_part_id = part_id
			left join bc_probrand on pro_prb_id = prb_id
			left join bc_part_small on pro_pas_id = pas_id';
			$res = $B2cBase->get($temptable, ['*'], $where.' order by part_name, pas_name, pri_code');
			$proArr = array_column($res['data'], null, 'pro_id');

			if(!empty($proArr))
			{
				//号码
				$twhere = sprintf(" and num_self=0 and num_show=1 and num_pro_id in (%s) order by num_ismain desc, num_factory asc, num_format asc", implode(',', array_keys($proArr)));
				$res = $B2cBase->get('bc_number', ['num_pro_id', 'num_factory', 'num_display'], $twhere);
				foreach($res['data'] as $v)
				{
					if(!empty($proArr[$v['num_pro_id']]['number']))
						$proArr[$v['num_pro_id']]['number'][] = $v['num_factory'].':'.$v['num_display'];
					else
						$proArr[$v['num_pro_id']]['number'] = [$v['num_factory'].':'.$v['num_display']];
				}
				//自定义参数
				$table = 'bc_product_para_val JOIN bc_product_label ON prl_id = prpv_prl_id
				LEFT JOIN bc_product_unit ON pru_id = prpv_pru_id';
				$res = $B2cBase->get($table, ['prpv_pro_id, prl_name, prpv_value, pru_name'], sprintf(" and prpv_pro_id in(%s)  ORDER BY prpv_seq, prl_name", implode(',', array_keys($proArr))));
				foreach($res['data'] as $v)
				{
					$proArr[$v['prpv_pro_id']]['pro_param'][] = $v['prl_name'].':'.$v['prpv_value'].(empty($v['pru_name']) ? '': $v['pru_name']);
				}

				//分类
				$res = $B2cBase->get('bc_product_sort JOIN sh_sort ON prs_sort_id = sort_id', ['prs_pro_id, sort_name'], sprintf(" and prs_pro_id in(%s) ORDER BY sort_seq",  implode(',', array_keys($proArr))));
				foreach($res['data'] as $v)
				{
					$proArr[$v['prs_pro_id']]['shop_sort'][] = $v['sort_name'];
				}

			}
			$B2cProduct = new B2cProduct();
			$B2cProduct->exportB2cItem([], $proArr, '商城配件'.date('Ymd').'.xls');
			exit;
		}

		//当前条件总数
		$totalData=$B2cProduct->get('bc_product join bc_product_info on pri_pro_id = pro_id',['count(*) count'],$where,true);
		// print_r($totalData);
		//配件列表
		$proData=$B2cProduct->getProductList($page,$perPage,$totalData['data']['count'],$order,$where,' join bc_product_info on pri_pro_id=pro_id');
		$proData['data']=array_column($proData['data'], null,'pro_id');
		// print_r($proData);
		if(!empty($proData['data']))
		{
			$proId=array();
			$partId=array();
			foreach ($proData['data'] as $k => $v)
			{
				$partId[]=$v['pro_part_id'];
				array_push($proId, $v['pro_id']);
			}
			//分类
			$cateArrData=$B2cPart->get('bc_part',['part_name','part_id'],sprintf(' and part_id in(%s)',implode(',',$partId)));
			$numberArrData=$B2cProduct->get('bc_number',['num_display','num_format','num_pro_id','num_ismain','num_factory'],sprintf(' and num_pro_id in(%s) and num_ismain>0',implode(',',$proId)));
			if(!empty($numberArrData['data']))
			{
				foreach ($numberArrData['data'] as $v)
				{
					$proData['data'][$v['num_pro_id']]['num_format']=$v['num_display'];
					$proData['data'][$v['num_pro_id']]['num_factory']=$v['num_factory'];
				}
			}
			if(!empty($proId))
			{
				//获取品牌
				$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)));
				$proBrandArr=array_column($brandArr['data'],null, 'pro_id');
				LibTpl::Set('proBrandArr',$proBrandArr);
			}
			//配件图片
			$picData=$B2cProduct->getProductPic($proId);
			foreach ($proData['data'] as $k => $v)
			{
				if(!empty($picData['data'][$v['pro_id']][0]))
				{
					$proData['data'][$k]=isset($picData['data'][$v['pro_id']][0])?array_merge($picData['data'][$v['pro_id']][0],$proData['data'][$k]):$proData['data'][$k];
				}
				foreach ($cateArrData['data'] as $i => $j)
				{
					if($j['part_id']==$v['pro_part_id'])
					{
						$proData['data'][$k]['cateName']=$j['part_name'];
					}
				}
			}
			//店铺分类
			$Page = LibPage::Show($totalData['data']['count'], $perPage, true);
			LibTpl::Set('Page', $Page);

			LibTpl::Set('proList',$proData['data']);
		}
		// print_r($proData['data']);
		//该店铺产品总数
		$allTotalData=$B2cProduct->Get('bc_product',['pro_id'],' and pro_shop_id='.$shopId);
		$allProId=array();
		foreach ($allTotalData['data'] as $k => $v)
		{
			$allProId[]=$v['pro_id'];
		}
		LibTpl::Set('total', count($allTotalData['data']));
		$treeData=$B2cShopSort->getShopSortZtree($shopId,$allProId);
		// print_r($treeData);

		LibTpl::Set('treeArr',$treeData['data']);

		$res = $B2cProduct->Get('bc_product_desc_tpl',['pdt_id, pdt_name'],' and pdt_shop_id='.$shopId);
		LibTpl::Set('desTplArr', $res['data']);

        $this->HEAD_CSSJS['plugin'][] = 'webuploader';
        $this->HEAD_CSSJS['plugin'][] = 'ueditor';
        $this->HEAD_CSSJS['plugin'][] = 'typeahead';
        $this->HEAD_CSSJS['plugin'][] = 'zTree';
        $this->HEAD_CSSJS['plugin'][] = 'datetimepicker';
        $this->HEAD_CSSJS['js'][] = 'js/part.js';
        $this->HEAD_CSSJS['js'][] = 'js/sellerProduct.js';
        $this->HEAD_CSSJS['js'][] = 'js/jquery.autocomplete.js';
        $this->HEAD_CSSJS['css'][] = 'css/jquery.autocomplete.css';
		$this->HEAD_CSSJS['plugin'][] = 'layui';
		LibTpl::Set('LeftMenu', 'productList');
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Put();
	}
	/**
	 * @method    ajax获取下级子类
	 * @author 卢
	 * @copyright 2017-07-27
	 */
	function getChildPart()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$B2cPart=new B2cPart();
		$res=$B2cPart->getPartByPath($Params['path']);
		LibFc::ajaxJsonEncode($res);
	}
	/**
	 * @method    ajax处理选中的配件
	 * @author 卢
	 * @copyright 2017-07-28
	 */
	function dealWithPro()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		if(isset($Params['tag']))
		{
			// print_r($_POST);
			$B2cProduct=new B2cProduct();
			$B2cLog = new B2cLog();
			$shopId=$_SESSION['_shopid'];
			$proId=$_POST['proId'];
			$proArr=is_array($proId)?$proId:[(int)$proId];
			$proArr=array_filter($proArr, 'LibFc::Int');
			if(count($proArr))
			{
				//日志
				$logArr=['log_shop_id'=>$_SESSION['_shopid'],'log_category'=>1];
				$logArr['log_dataid']=$proArr;
				$where=sprintf(' and pro_shop_id=%d and pro_id IN(%s)',$shopId,implode(',',$proArr));
				$target=[];
				$OthCheck->rule('PC02');
				if($Params['tag']=='recommend')
				{
					$re=$B2cProduct->get('sh_shop',['shop_window_count'],sprintf(' and shop_id=%d',$_SESSION['_shopid']),true);
					$windowCount=$re['data']['shop_window_count'];
					$useTotal=$B2cProduct->get('bc_product',['count(1) count'],sprintf(" and pro_promoted='Y' and pro_shop_id=%d",$_SESSION['_shopid']),true);
					$lest=$windowCount-$useTotal['data']['count'];
					// print_r($windowCount);
					// echo $useTotal['data']['count'];
					// print_r($lest);
					// die;
					if($lest>0)
					{
						$proArr=array_slice($proArr,0,$lest);
						$where=sprintf(' and pro_shop_id=%d and pro_id IN(%s)',$shopId,implode(',',$proArr));
					}else
					{
						LibFc::ajaxJsonEncode(['status'=>true,'data'=>true]);
						exit();
					}

					// echo 132;
					$target=['pro_promoted'=>'Y'];
				}
				elseif($Params['tag']=='unrecommend')
				{
					$target=['pro_promoted'=>'N'];
				}
				elseif($Params['tag']=='out')
				{
					$target=['pro_status'=>0];
				}
				elseif($Params['tag']=='sell')
				{
					$target=['pro_status'=>1];
				}
				// print_r($proArr);
				// die;
				$res=$B2cProduct->dealWithPro($shopId,$where,$Params['tag'],$proArr,$target);
				LibFc::ajaxJsonEncode($res);
			}
		}
		LibFc::ajaxJsonEncode(array('status'=>false,'data'=>'参数错误'));
	}
	/**
	 * @method    会员等级管理
	 * @author     xu
	 * @copyright 2017-07-27
	 * @return
	 */
	public function member()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();

		// 权限
		$OthCheck->rule('SU05');

		// 会员设置
		$B2cShop = new B2cShop();
		$res = $B2cShop->getMemberSetting($_SESSION['_shopid']);
		LibTpl::Set('data',$res['data']);

		// meta
		$headArr = array(
			'title'=>'会员等级设置-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','member');
		LibTpl::Put();
	}

	/**
	 * @method    ajax保存等级信息
	 * @author     xu
	 * @copyright 2017-07-29
	 * @return 成功：{'status':true,'data':'success','code':0} 失败：{'status':false,'data':'error'/'参数错误！','code':0}
	 */
	public function saveMember()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SU04');
		//参数
		$B2cBase = new B2cBase();
		if(empty($_POST['memDiscount'])||empty($_POST['memId'])||!($memId=LibFc::Int($_POST['memId'])))
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
    	$memDiscount = sprintf("%.2f",trim($_POST['memDiscount']));
    	if(10<$memDiscount||$memDiscount<0.01)
    		LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		//保存
		$where = sprintf(" and mem_shop_id=%d and mem_id=%d",$_SESSION['_shopid'],$memId);
		$B2cBase->set("sh_member",['mem_discount'=>$memDiscount],$where);

		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'折扣率更改成功！']);
	}


	/**
	 * @method ajax设置当前店铺会员卡名称
	 * @author     xu
	 * @copyright 2017-07-29
	 * @return 成功：{'status':true,'data':'success','code':0} 失败：{'status':false,'data':'error'/'参数错误！','code':0}
	 */
	public function setMemCardName()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SU04');
		//参数判断
		$B2cBase = new B2cBase();
		if(empty($_POST['newName']) || empty(LibFc::Escape($newName = $_POST['newName'])))
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		//执行
		$where = sprintf(" and shop_id=%d",$_SESSION['_shopid']);
		$B2cBase->set('sh_shop',['shop_vip_name'=>$newName],$where);
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'success']);

	}


	/**
	 * @method    ajax更改会员等级开启关闭状态
	 * @author     xu
	 * @copyright 2017-07-31
	 * @return 成功：{'status':true,'data':'success','code':0} 失败：{'status':false,'data':'error'/'参数错误！','code':0}
	 */
	public function togMemStatus()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SU04');
		$B2cBase = new B2cBase();
    	//参数判断
		if(empty($_POST['memId']) || !LibFc::Int($_POST['memId'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		$status = (!empty($_POST['memStatus']) && ($_POST['memStatus']==1)) ? 0 : 1;
		$notice = (!empty($_POST['memStatus']) && boolval($_POST['memStatus'])) ? '会员等级不启用！' : '已启用会员等级！';
		// 执行
		$where = sprintf(" and mem_shop_id=%d and mem_id=%d",$_SESSION['_shopid'],$_POST['memId']);
		$B2cBase->set('sh_member',['mem_status'=>$status],$where);

		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$notice]);
	}

    public function memberRegister()
    {

        $OthCheck = new OthCheck();
        $OthCheck->hasShop();
        $OthCheck->rule('SU05');
        $Params = mvc::$URL_PARAMS;
        $shopId = (int) $_SESSION['_shopid'];
       // $shopId = 252312;
        $B2cBase = new B2cBase();
        $level = $B2cBase->get('sh_member_level',['mel_id','mel_name']," and mel_id > 0 order by mel_id asc ");
        LibTpl::Set('level',$level['data']);
        $YpwBase = new YpwBase();
        $field = [
            'u_id','u_name','u_mobile','u_register_time'
        ];
        $where = '';
        if($Params['userName']){
            $where .= sprintf(" and u_name like '%%%s%%'",trim($Params['userName']));
        }
        if($Params['userId']) {
            $where .= sprintf(" and u_id=%d",(int) $Params['userId']);
        }
        if($Params['mobile']){
            $where .= sprintf(" and u_mobile like '%%%s%%'",trim($Params['mobile']));
        }
        if(!empty($Params['starttime']) && strtotime($Params['starttime']))
            $where .= sprintf(" and u_register_time >%d",strtotime($Params['starttime']));
        if(!empty($Params['endtime']) && strtotime($Params['endtime']))
            $where .= sprintf(" and u_register_time <%d",strtotime($Params['endtime']));
        $NowPage = isset($Params['page']) && $Params['page'] > 0 ? (int) $Params['page']:1;
        $PerPage = 20;
        $count = $YpwBase->get("yp_user",["count(*) as count"],sprintf(" and u_from = 'PJDSGZH' and u_from_uid = %d",$shopId),true);
        $data = $YpwBase->get("yp_user",$field,sprintf(" and u_from = 'PJDSGZH' and u_from_uid = %d and 1=1 %s order by u_register_time limit %s,%s",$shopId,$where,($NowPage-1)*$PerPage,$PerPage));
        if(!empty($data['data'])){
            $uIds = array_column($data['data'],'u_id');
            $levelList = $B2cBase->get("sh_member_link join sh_member on meml_mem_id=mem_id join sh_member_level on mem_mel_id=mel_id",['meml_uid','mel_name'],sprintf(" and meml_uid in (%s) and meml_shop_id = %d",implode(",",$uIds),$_SESSION['_shopid']));
          // var_dump($levelList);exit();
            if(!empty($levelList['data'])) {
                $levelList = array_column($levelList['data'],null,'meml_uid');
            }else{
                $levelList = [];
            }
            foreach ($data['data'] as &$value)
            {
                if(!empty($levelList) && isset($levelList[$value['u_id']]) && is_array($levelList[$value['u_id']])){
                    $value['level'] = $levelList[$value['u_id']]['mel_name'];
                }else{
                    $value['level'] = '';
                }
                $value['u_register_time'] = date('Y-m-d H:i',$value['u_register_time']);
            }
			unset($value);
        }
        $this->HEAD_CSSJS['plugin'][] = 'datetimepicker';
        LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
        $Page = LibPage::Show($count['data']['count'], $PerPage);
        LibTpl::Set('Params',$Params);
        LibTpl::Set("Page",$Page);
        LibTpl::Set('LeftMenu','member');
        LibTpl::Set('list',$data['data']);
        LibTpl::Put();
    }

	/**
	 * @method    ajax更改会员是否参与满减
	 * @author     xu
	 * @copyright 2017-07-31
	 * @return 成功：{'status':true,'data':'success','code':0} 失败：{'status':false,'data':'error'/'参数错误！','code':0}
	 */
	public function togMemManJian()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SU04');
		$B2cBase = new B2cBase();
    	//参数判断
		if(empty($_POST['memId']) || !LibFc::Int($_POST['memId'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		// 执行
		$status = (!empty($_POST['memManjian']) && ($_POST['memManjian']==1))?0:1;
		$notice = $status ? '会员等级与满减优惠叠加开启！' : '会员等级不可与满减优惠叠加！';
		$where = sprintf(" and mem_shop_id=%d and mem_id=%d",$_SESSION['_shopid'],$_POST['memId']);
		$B2cBase->set('sh_member',['men_manjian'=>$status],$where);
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$notice]);
	}

	/**
	 * @method    会员列表
	 * @author     xu
	 * @copyright 2017-07-27
	 * @return    ["status"=>true,"data"=>"xxx","code"=>0]
	 */
	public function memberList()
	{
		// 店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SU05');
		$Params = mvc::$URL_PARAMS;

		// 参数
		$search = '';
		if(!empty($Params['userName']))
		{
			$LibYpApi = new LibYpApi();
			$res = $LibYpApi->Get('user/searchUser',[], ['word'=>$Params['userName']]);
			if(!empty($res['data']))
				$search .= sprintf(" and ub_uid in (%s)", implode(',', array_column($res['data'], 'u_id')));
			else
				$search .= ' and 1= 0';
		}
		if(!empty($Params['level']) && LibFc::Int($Params['level']))
			$search.=' and mel_id='.$Params['level'];
		if(!empty($Params['starttime']) && strtotime($Params['starttime']))
			$search .= sprintf(" and meml_add_time >%d",strtotime($Params['starttime']));
		if(!empty($Params['endtime']) && strtotime($Params['endtime']))
			$search .= sprintf(" and meml_add_time <%d",strtotime($Params['endtime']));
		if(!empty($Params['meml_remark']))
			$search .= sprintf(" and meml_remark like '%%%s%%'",trim($Params['meml_remark']));
		$NowPage = isset($Params['page']) && $Params['page'] > 0 ? (int) $Params['page']:1;
		$PerPage = 20;

		// 数量
		$table='sh_member_link join sh_member on meml_mem_id=mem_id join sh_member_level on mem_mel_id=mel_id join us_user_base on meml_uid=ub_uid';
		$where =' and meml_shop_id=mem_shop_id and meml_shop_id='.$_SESSION['_shopid'].$search;
		$B2cBase = new B2cBase();
		$res = $B2cBase->get($table , ['count(1) count'], $where, true);
		$total = $res['data']['count'];
		if($total > 0)
		{
			$where .= sprintf(" order by meml_add_time limit %d,%d", ($NowPage-1)*$PerPage, $PerPage);
			$res = $B2cBase->get($table, ['*'], $where);
			$memArr = $res['data'];
			if(!empty($memArr))
			{
				$YpwBase = new YpwBase();
				$res = $YpwBase->get("yp_user",["u_id, u_mobile"],sprintf(" and u_id in (%s)", implode(',', array_column($memArr, 'ub_uid'))));
				LibTpl::Set('userArr', array_column($res['data'], null, 'u_id'));
			}
			LibTpl::Set('data', $memArr);
		}

		// 页码
		$Page = LibPage::Show($total, $PerPage);
		LibTpl::Set('Page', $Page);


		// 会员级别
		$res = $B2cBase->get('sh_member_level',['mel_id','mel_name']," and mel_id > 0 order by mel_id asc ");
		LibTpl::Set('level',$res['data']);

		// meta
		$headArr = array(
			'title'=>'会员等级设置-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		$this->HEAD_CSSJS['plugin'][] = 'datetimepicker';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','member');
		LibTpl::Put();
	}


	/**
	 * @method    删除店铺会员
	 * @author     xu
	 * @copyright 2017-08-30
	 * @return 成功：{'status':true,'data':'success','code':0} 失败：{'status':false,'data':'error'/'参数错误！','code':0}
	 */
	public function delThisMemUser()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SU03');
		$B2cBase = new B2cBase();
    	//参数判断
		if(empty($_POST['meml_uid']) || !LibFc::Int($meml_uid = $_POST['meml_uid'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		// 执行
		$where = sprintf(" and meml_shop_id=%d and meml_uid=%d",$_SESSION['_shopid'],$meml_uid);
		$res = $B2cBase->del('sh_member_link',$where);
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'删除成功！']);
	}


	/**
	 * @method    批量删除店铺会员
	 * @author     xu
	 * @copyright 2017-09-05
	 * @return 成功：{'status':true,'data':'success','code':0} 失败：{'status':false,'data':'error'/'参数错误！','code':0}
	 */
	public function delThisMemUsers()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SU03');
		$B2cBase = new B2cBase();
    	//参数判断
		if(empty($_POST['meml_uidS']) || empty($memUids = array_filter($_POST['meml_uidS'],'LibFc::Int')))
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		// 执行
		$where = sprintf(" and meml_shop_id=%d and meml_uid in (%s)",$_SESSION['_shopid'],implode(',',$memUids));
		$B2cBase->del('sh_member_link',$where);

		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'删除成功！']);
	}


	/**
	 * @method    ajax获取配件详细模板
	 * @author 卢
	 * @copyright 2017-08-01
	 */
	public function ajaxGetDesTpl()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();
		$perPage=5;
		$shopId=$_SESSION['_shopid'];
		$where=sprintf(' and pdt_shop_id=%d and pdt_type=0',$shopId);

		$keyWordWhere=isset($Params['keyWord'])&&!empty($Params['keyWord']) ? sprintf(" and pdt_name like '%%%s%%'",LibFc::Escape($Params['keyWord'])) : '';
		if(isset($Params['tplId'])&&LibFc::Int($Params['tplId']))
		{
			$where.=' and pdt_id='.$Params['tplId'];
		}
		$where.=$keyWordWhere;
		// echo $where;
		$totalData=$B2cBase->Get('bc_product_desc_tpl',['count(*) count'],$where,true);
		$nowPage=isset($Params['page'])? $Params['page'] : 1;
		$total=$totalData['data']['count'];
		$totalPage=ceil($total/$perPage);
		$where .=sprintf(' order by pdt_add_time desc limit %d,%d', ($nowPage-1)*$perPage, $perPage);
		$tplData=$B2cBase->Get('bc_product_desc_tpl',['*'], $where);
		// print_r($tplData);
		$result=array('status'=>true,'data'=>array('data'=>$tplData['data'],'nowPage'=>$nowPage,'totalPage'=>$totalPage));
		LibFc::ajaxJsonEncode($result);
	}
	/**
	 * @method    保存编辑器内容
	 * @author 卢
	 * @copyright 2017-08-03
	 */
	function saveTplContent()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		$tag=$_POST['tag']=='auto'? 0 : 1;
		if(LibFc::Int($_POST['proId']))
		{
			//统计保存数量
			$allTotalData=$B2cBase->Get('bc_product_desc_history',['count(*) count'],sprintf(' and pdh_pro_id=%d',LibFc::Int($_POST['proId'])),true);
			//判断是否大于10条，大于10条把旧的删除
			if($allTotalData['data']['count']>=10)
			{
				$re=$B2cBase->Get('bc_product_desc_history',['pdh_pro_id','pdh_add_time'],sprintf(' and pdh_pro_id=%d order by pdh_auto asc,pdh_add_time asc',LibFc::Int($_POST['proId'])),true);
				$B2cBase->Del('bc_product_desc_history',sprintf(' and pdh_pro_id=%d and pdh_add_time=%d',$re['data']['pdh_pro_id'],$re['data']['pdh_add_time']));
			}
			//判断是否一样
			$existData=$B2cBase->Get('bc_product_desc_history',['count(*) count'],sprintf(" and pdh_pro_id=%d and pdh_pro_des_crc32='%s'",LibFc::Int($_POST['proId']),LibFc::GetCrc32($_POST['content'])),true);
			if($existData['data']['count']>0)
			{
				//一样就更新时间
				$res=$B2cBase->Set('bc_product_desc_history',['pdh_add_time'=>time()],sprintf(" and pdh_pro_id=%d and pdh_pro_des_crc32='%s'",LibFc::Int($_POST['proId']),LibFc::GetCrc32($_POST['content'])));
			}else
			{
				//不一样就添加
				$targetArr=array('pdh_pro_id'=>$_POST['proId'],'pdh_pro_des'=>$_POST['content'],'pdh_add_time'=>time(),'pdh_auto'=>$tag,'pdh_pro_des_crc32'=>LibFc::GetCrc32($_POST['content']));
				$res=$B2cBase->Add('bc_product_desc_history',$targetArr,['pdh_pro_des']);
			}
			LibFc::ajaxJsonEncode($res);
		}
	}
	/**
	 * @method    获取配件详情历史模板
	 * @author 卢
	 * @copyright 2017-08-03
	 */
	function getTplContent()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		$proId=(int)($_POST['proId']);
		$addTime=(int)$_POST['time'];
		if($proId)
		{
			$where=sprintf(' and pdh_pro_id=%d',$proId);
			$where.=(isset($_POST['time'])&&!empty($_POST['time']))? sprintf(' and pdh_add_time=%d',$addTime) : '';
			$res=$B2cBase->Get('bc_product_desc_history',['*'],$where.' order by pdh_add_time desc');
			LibFc::ajaxJsonEncode($res);
		}
	}

	/**
	 * @method 图片空间
	 * @author xu
	 * @copyright 2017-08-07
	 */
	function picZone()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SI00');
		if($OthCheck->rule('IF01',false))
		{
			$upLoadImg = true;
			LibTpl::Set('upLoadImg',$upLoadImg);
		}
		if($OthCheck->rule('IF02',false))
		{
			$editImg = true;
			LibTpl::Set('editImg',$editImg);
		}
		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();
		// 获取当前店铺的图片分类
		$where = sprintf(" and pica_shop_id=%d order by pica_id asc",$_SESSION['_shopid']);
		$allCategory = $B2cBase->get('sh_pic_category',['*'],$where);
		// 拼接正确格式的JSON数据传递给zTree
		$allCategoryJson = array();
		foreach ($allCategory['data'] as $key => $value)
		{
			// 拼接上pica_style意味着店铺分类图片的分类顶级是01而宝贝分类顶级是00
			$allCategoryJson[$key]['id'] = $value['pica_id'].$value['pica_style'];
			$allCategoryJson[$key]['pId'] = $value['pica_pid'].$value['pica_style'];
			$allCategoryJson[$key]['name'] = $value['pica_name'];
		}
		// 现在拼接数组店铺图片、宝贝图片两个array
		$allCategoryJson[] = array('id'=>'00','pId'=>0,'name'=>'配件图片','open'=>'true');
		$allCategoryJson[] = array('id'=>'01','pId'=>0,'name'=>'店铺装修图片','open'=>'true');
		// 将拼接好的JSON格式数据传递给zTree
		LibTpl::Set('allCategoryJson',json_encode($allCategoryJson));
		$this->HEAD_CSSJS['js'][] = 'js/piczone.js';
		$this->HEAD_CSSJS['plugin'][] = 'webuploader';
		// $this->HEAD_CSSJS['plugin'][] = 'autocomplete';
		$this->HEAD_CSSJS['plugin'][] = 'zTree';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('data',$dataArr['data']);
		$headArr = array(
			'title'=>'图片空间-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','picZone');
		LibTpl::Put();
	}


	/**
	 * @method 点击查看大图获取图片相关数据
	 * @author xu
	 * @copyright 2017-09-05
	 */
	function picZoneGetPicDetail()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SI00');
		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();

		// 参数
		if(empty($_POST['imgId']) || !($spi_id=LibFc::Int($_POST['imgId'])))
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);

		// 图片
		$where = sprintf(" and spi_id=%d and spi_shop_id=%d ",$spi_id,$_SESSION['_shopid']);
		$allPicMsg = $B2cBase->get('sh_pic left join sh_pic_category on spi_pica_id=pica_id',['*'],$where);
		$allPicMsg = current($allPicMsg['data']);
		if(empty($allPicMsg['pica_name'])) $allPicMsg['pica_name'] = $allPicMsg['spi_style']?'店铺装修图片':'配件图片';

		// 图片详情
		$allPicMsg['normal_pic_path'] = mvc::$cfg['FILE_CENTER']['b2c']['url_get'].'&c='.$allPicMsg['spi_cate'].'&f='.$allPicMsg['spi_path'].$allPicMsg['spi_name'].'.'.$allPicMsg['spi_ext'].mvc::$cfg['FILE_CENTER']['b2c']['get_uri'];
		$allPicMsg['one_zero_zero_pic_path'] = mvc::$cfg['FILE_CENTER']['b2c']['url_get'].'&c='.$allPicMsg['spi_cate'].'&f='.$allPicMsg['spi_path'].'100/'.$allPicMsg['spi_name'].'.'.$allPicMsg['spi_ext'].mvc::$cfg['FILE_CENTER']['b2c']['get_uri'];
		$allPicMsg['two_four_zero_pic_path'] = mvc::$cfg['FILE_CENTER']['b2c']['url_get'].'&c='.$allPicMsg['spi_cate'].'&f='.$allPicMsg['spi_path'].'240/'.$allPicMsg['spi_name'].'.'.$allPicMsg['spi_ext'].mvc::$cfg['FILE_CENTER']['b2c']['get_uri'];
		$allPicMsg['localtime'] = date('Y-m-d H:i',$allPicMsg['spi_atime']);
		$allPicMsg['pic_filesize'] =  round($allPicMsg['spi_size']/1000,1).'KB';

		// 返回
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$allPicMsg]);
	}



	/**
	 * @method 移动图片实例化的数据
	 * @author xu
	 * @copyright 2017-08-28
	 */
	function ajaxMoveImg()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('IF02');
		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();
		// 校验
		if(!isset($_POST['nowThisTreeType'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		$type = boolval($_POST['nowThisTreeType'])?1:0;
		// 获取
		$where = sprintf(" and pica_shop_id=%d and pica_style=%d order by pica_id asc",$_SESSION['_shopid'],$type);
		$res = $B2cBase->get('sh_pic_category',['*'],$where);
		// 拼接
		$temp = array();
		foreach ($res['data'] as $key => $value)
		{
			$temp[$key]['id'] = $value['pica_id'].$value['pica_style'];
			$temp[$key]['pId'] = $value['pica_pid'].$value['pica_style'];
			$temp[$key]['name'] = $value['pica_name'];
			// $temp[$key]['icon'] = "/static/zTree_v3-master/css/zTreeStyle/img/diy/11.png";
		}
		// 拼接
		$temp[] = $type ? ['id'=>'01','pId'=>0,'name'=>'店铺装修图片','open'=>'true']:['id'=>'00','pId'=>0,'name'=>'配件图片','open'=>'true'];
		// 返回
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$temp]);
	}


	/**
	 * @method 移动图片确认
	 * @author xu
	 * @copyright 2017-08-28
	 */
	function commithisMoveAction()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('IF02');
		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();
		// 校验
		if(empty($_POST['thisPicCatId']) || !($spiPicaId=LibFc::Int($_POST['thisPicCatId'])))
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		if(empty($_POST['thismoveImgId']) || empty($spiIds = array_filter(explode(',',$_POST['thismoveImgId']),'LibFc::Int')) )
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		// 获取pica_id
		$str = substr($spiPicaId,0,-1);
		// 更新
		$where = sprintf(" and spi_id in (%s) and spi_shop_id=%d ",implode(',', $spiIds),$_SESSION['_shopid']);
		$B2cBase->set('sh_pic',['spi_pica_id'=>$str],$where);
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'移动成功！']);
	}

	/**
	  * @method ajax保存图片
	  * @author xu 2017/8/15
	  */
	function saveNewImg()
	{
		//店铺登录
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('IF01');
		// 校验
		if(!isset($_POST['spi_style']) || empty($_POST['spi_id']) || !($spi = LibFc::Int($_POST['spi_id'])))
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误1！']);

		if(!isset($_POST['spi_pica_id']) || ($_POST['spi_pica_id']!=0 && !LibFc::Int($_POST['spi_pica_id'])) )
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);

		$pica = $_POST['spi_pica_id'];
		$style = $_POST['spi_style']?1:0;
		// 执行
		$B2cBase = new B2cBase();
		$where = sprintf(' and spi_id=%d and spi_shop_id=%d ',$spi,$_SESSION['_shopid']);
		$B2cBase->set('sh_pic',['spi_pica_id'=>$pica,'spi_style'=>$style],$where);
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'success']);
	}

	/**
	 * @method 图片空间加载文件夹图片
	 * @author xu
	 * @copyright 2017-08-10
	 */
	function picZonePic()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SI00');
		$B2cBase = new B2cBase();

		// 参数
		if(empty($_POST['pica_id'])||!LibFc::Int($pica_id = $_POST['pica_id'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		$pica_id = substr($pica_id,0,-1);
		$type = preg_replace('/^'.$pica_id.'/','',$_POST['pica_id']);
		LibTpl::Set('nowThisTreeType',$type);
		LibTpl::Set('nowThisTreePicaId',$pica_id);
		// 页码
		$NowPage = isset($_POST['page']) && $_POST['page'] > 0 ? (int) $_POST['page']:1;
		$PerPage = 35;
		// 数量
		$where = ($type==='0' && $pica_id==='0')?sprintf(" and spi_shop_id=%d and spi_style=%d ",$_SESSION['_shopid'],$type):sprintf(" and spi_shop_id=%d and spi_pica_id=%d and spi_style=%d ",$_SESSION['_shopid'],$pica_id,$type);

		$res = $B2cBase->get('sh_pic', ['count(1) count'], $where, true);
		$Total = $res['data']['count'];
		$Page = '';
		if($Total > 0)
		{
			if($NowPage>(ceil($Total/$PerPage)))
			{
				$NowPage=ceil($Total/$PerPage);
			}
			$where .= sprintf(" order by spi_id desc limit %d,%d", ($NowPage-1)*$PerPage, $PerPage);
			$res = $B2cBase->get('sh_pic', ['*'], $where);
			LibTpl::Set('allPic', $res['data']);
			$Page = $this->minePicZonePage($Total,$PerPage,$NowPage);
		}
		LibTpl::Set('Page', $Page);
		// 模板
		$data = LibTpl::Fetch('seller/picZonePic.php');
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$data]);
	}

	/**
	 * @method 图片空间自定义的页码
	 * @author xu
	 * @copyright 2017-08-10
	 */
	function minePicZonePage($Total = 0, $PerPage = 10,$NowPage)
	{
		$TotalPage = ceil($Total/$PerPage);
		// 获取当前页码,现在当前页码全部由参数传递过来
		$NowPage = $NowPage > $TotalPage? $TotalPage: $NowPage;
		$prePage = $NowPage-1;
		$nxtPage = $NowPage+1;
		// 拼接URL参数
		$PageStr = '';
		if($TotalPage > 0)
		{
			$PageStr .= $NowPage == 1 ? '<li class="page-disabled"><a href="javascript:">上一页</a></li>' : '<li><a href="javascript:;" onclick="jumpOutherPage('.$prePage.')">上一页</a></li>';
		}
		if($TotalPage <= 7)
		{
			for($I = 1; $I <=$TotalPage; $I++)
			{
				if($NowPage == $I)
				{
					$PageStr .= '<li class="page-choose"><a href="javascript:">'.$I.'</a></li>';
				}
				else
				{
					$PageStr .= '<li><a href="javascript:;" onclick="jumpOutherPage('.$I.')">'.$I.'</a></li>';//'.self::ReplaceUrl($Url, $I).'
				}
			}
		}
		else
		{//上一页 5 6 7 8 9 10 11 12 下一页
			//计算开始页
			if($NowPage < 4)
			{//[1] [2] 3 [4]...
				$BPage = 1;
			}
			else if(($TotalPage-$NowPage) < 3)
			{
				$BPage = $NowPage-6+($TotalPage-$NowPage);
			}
			else
			{
				$BPage = $NowPage-3;
			}
			for($I = $BPage; $I < $BPage+7; $I++)
			{
				if($I > $TotalPage)
				{
					break;
				}
				if($NowPage == $I)
				{
					$PageStr .= '<li class="page-choose"><a href="javascript:">'.$I.'</a></li>';
				}
				else
				{
					$PageStr .= '<li><a href="javascript:;" onclick="jumpOutherPage('.$I.')">'.$I.'</a></li>';//'.self::ReplaceUrl($Url, $I).'
				}
			}
		}
		if($TotalPage > 0)
		{
			$PageStr .= $NowPage == $TotalPage ? '<li class="page-disabled"><a href="javascript:">下一页</a></li>' : '<li><a href="javascript:;" onclick="jumpOutherPage('.$nxtPage.')">下一页</a></li>';
		}
		//跳转到'.self::ReplaceUrl($Url, $NowPage + 1).'
		$GoHtml = '';
		if($TotalPage > 10)
		{
			$GoHtml .= '<div class="page-go">共<b>'.$TotalPage.'</b>页，到第 <input type="text" id="fastJumpOutherPage" class="to_page_txt form-control" size="2" base="" value="'.$NowPage.'"/> 页 <button type="button" onclick="fastJumpOutherPage()" class="btn btn-info btn-sm to_page_btn">跳转</button ></div>';
		}

		return '<div class="page-box"><ul class="page">'.$PageStr.'</ul>'.$GoHtml.'</div>';
	}



	/**
	 * @method 搜索图片以及文件夹
	 * @author xu
	 * @copyright 2017-08-26
	 */
	function picZonePicFind()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		// 获取当前分类下面的图片ID
		$B2cBase = new B2cBase();
		// 过滤一下当前搜索的名称
		$searchKey = LibFc::Escape($_POST['searchKey']);
		LibTpl::Set('searchKey',$searchKey);
		// 搜索文件夹
		$table = "sh_pic_category";
		$where = sprintf(" and pica_shop_id=%d and pica_name like '%%%s%%'",$_SESSION['_shopid'],$searchKey);
		$sh_pic_category_MSG = $B2cBase->get($table,['*'],$where);
		LibTpl::Set('SonCategory',$sh_pic_category_MSG['data']);
		// 搜索图片
		$table = "sh_pic left join sh_pic_category on pica_id=spi_pica_id ";
		$where = sprintf(" and spi_shop_id=%d and spi_oriname like '%%%s%%'",$_SESSION['_shopid'],$searchKey);
		$sh_pic_MSG = $B2cBase->get($table,['*'],$where);
		LibTpl::Set('allPic',$sh_pic_MSG['data']);
		// 将渲染好的HTML代码传递过去
		$Tpl = LibTpl::Fetch('seller/picZonePic.php');
		$array = array('status'=>true,'data'=>$Tpl,'code'=>0);
		LibFc::ajaxJsonEncode($array);
	}

	/**
	 * @method 点击ztree获取面包屑导航数据
	 * @author xu
	 * @copyright 2017-08-17
	 */
	function getPicZonePath()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		// 获取当前分类下面的图片ID
		$B2cBase = new B2cBase();

		// 校验当前目录ID
		if(empty($_POST['pica_id']) || !LibFc::Int($pipaId = $_POST['pica_id'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);

		if($pipaId==00||$pipaId==01)
		{
			// 根目录
			$type = preg_replace('/^0/','',$_POST['pica_id']);
			$data = ($type==1)?[['pica_id'=>0,'pica_name'=>'店铺装修图片','pica_style'=>1]]:[['pica_id'=>0,'pica_name'=>'配件图片','pica_style'=>0]];
			LibFc::ajaxJsonEncode(['status'=>true,'data'=>$data]);
		}
		// 目录
		$pipaId = substr($pipaId,0,-1);
		$type = preg_replace('/^'.$pipaId.'/','',$_POST['pica_id']);
		// 拼接SQL获取当前目录下pica_path
		$res = $B2cBase->get('sh_pic_category',['pica_path'],sprintf(" and pica_shop_id=%d and pica_id=%d and pica_style=%d ",$_SESSION['_shopid'],$pipaId,$type),true);
		$res = $res['data'];

		$picaPath = preg_replace('/^0,/','',$res['pica_path']).','.$pipaId;
		$where = sprintf(" and pica_shop_id=%d and pica_id in (%s) order by pica_id desc",$_SESSION['_shopid'],$picaPath);
		$res = $B2cBase->get('sh_pic_category',['*'],$where);
		$msg = $res['data'];
		// 根路径
		$temp = ($type===1)?['pica_id'=>0,'pica_name'=>'店铺装修图片','pica_style'=>1]:['pica_id'=>0,'pica_name'=>'配件图片','pica_style'=>0];
		array_push($msg,$temp);

		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$msg]);
	}

	/**
	 * @method ajax重命名目录
	 * @author xu
	 * @copyright 2017-08-09
	 */
	function picZoneRenameCategory()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('IL02');
		$B2cBase = new B2cBase();
		// 校验当前目录ID
		if(empty($_POST['pica_id']) || !LibFc::Int($pipaId = $_POST['pica_id']) || empty($_POST['pica_name'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		// 目录
		$pipaName=LibFc::Escape($_POST['pica_name']);
		$pipaId = substr($pipaId,0,-1);
		// 执行
		$where = sprintf(' and pica_shop_id=%d and pica_id=%d ',$_SESSION['_shopid'],$pipaId);
		$B2cBase->set('sh_pic_category',['pica_name'=>$pipaName],$where);
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'success']);

	}


	/**
	 * @method ajax更新数据表图片名称
	 * @author xu
	 * @copyright 2017-08-09
	 */
	function renameImgOriname()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('IF02');
		$B2cBase = new B2cBase();
		// 校验当前目录ID
		if(empty($_POST['spi_oriname']))
		{
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'图片名称不能为空']);
		}
		if(empty($_POST['spi_id']) || !LibFc::Int($spiId = $_POST['spi_id']))
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		// 过滤
		$oriName = LibFc::Escape($_POST['spi_oriname']);
		// 执行
		$where = sprintf(' and spi_shop_id=%d and spi_id=%s ',$_SESSION['_shopid'],$spiId);
		$B2cBase->set("sh_pic",['spi_oriname'=>$oriName],$where);
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'success']);
	}

	/**
	 * @method 删除我的图片
	 * @author xu
	 * @copyright 2017-08-09
	 */
	function delMyImg()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('IF03');
		$B2cBase = new B2cBase();
		// 参数
		if(empty($_POST['spi_idS']) || !is_array($_POST['spi_idS']) || empty($spiIds=array_filter($_POST['spi_idS'],'LibFc::Int')))
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		// 删除
		$B2cProduct = new B2cProduct();
		$B2cProduct->delPiczonePic($spiIds,$_SESSION['_shopid'],1);
		// 返回
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'success']);
	}


	/**
	 * @method ajax删除目录之前调用函数(检测当前目录是否还有图片)
	 * @author xu
	 * @copyright 2017-08-16
	 */
	function zTreeBeforeRemove()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('IL03');
		$B2cBase = new B2cBase();
		// 参数
		if(empty($_POST['pica_id']) || !LibFc::Int($pica_id = $_POST['pica_id'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);

		// 目录
		$picaId = substr($pica_id,0,-1);
		// 检测当前目录下面是否还有图片
		$where = sprintf(' and spi_shop_id=%d and spi_pica_id=%d ',$_SESSION['_shopid'],$picaId);
		$res = $B2cBase->get("sh_pic",['count(*) sum'],$where,true);

		if($res['data']['sum']>0)
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'当前目录下还有图片，删除失败!']);
		else
			LibFc::ajaxJsonEncode(['status'=>true,'data'=>'success']);
	}


	/**
	 * @method ajax添加子目录
	 * @author xu
	 * @copyright 2017-08-09
	 */
	function picZoneAddCategory()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('IL01');
		$B2cBase = new B2cBase();
		// 校验parentid
		if(empty($_POST['pica_pid']) || !LibFc::Int($pica_pid = $_POST['pica_pid'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);

		// 类型+目录
		$pica_style = substr($pica_pid,-1);
		$pica_pid = substr($pica_pid,0,-1);
		// 过滤目录名称
		$pica_name = LibFc::Escape($_POST['pica_name']);
		// 获取父级ID的路由
		if($pica_pid == 0)
		{
			$pica_path = 0;
		}
		else
		{
			$where = sprintf(' and pica_id=%d and pica_shop_id=%d ',$pica_pid,$_SESSION['_shopid']);
			$data =  $B2cBase->get("sh_pic_category",['pica_path'],$where,true);
			// 拼接新增目录的路由
			$data = $data['data'];
			$pica_path = $data['pica_path'].','.$pica_pid;
		}
		// 拼接新目录数据
		$temp = array(
			'pica_name'=>$pica_name,
			'pica_path'=>$pica_path,
			'pica_pid'=>$pica_pid,
			'pica_add_time'=>time(),
			'pica_shop_id'=>$_SESSION['_shopid'],
			'pica_style'=>$pica_style
		);
		$primaryId = $B2cBase->add("sh_pic_category",$temp);
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$primaryId['data'].$pica_style]);
	}


	/**
	 * @method ajax删除子目录
	 * @author xu
	 * @copyright 2017-08-09
	 */
	function picZoneDelCategory()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('IL03');
		$B2cBase = new B2cBase();
		// 参数
		if(empty($_POST['pica_id']) || !LibFc::Int($picaId = $_POST['pica_id'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		// 获取目录
		$picaId = substr($picaId,0,-1);
		$where = sprintf(' and pica_shop_id=%d and pica_id=%d ',$_SESSION['_shopid'],$picaId);
		$B2cBase->del("sh_pic_category",$where);
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'success']);
	}

	/**
	 * @method    卖家评价管理
	 * @author     廖
	 * @copyright 2017-08-17
	 */
	public function evaluate()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR04');
		LibTpl::Set('LeftMenu','evaluate');
		$nowPage = isset($Params['page']) ? $Params['page'] : 1;
		$perPage = 20;
		$Params = mvc::$URL_PARAMS;
		$status = isset($Params['status']) ? $Params['status'] : 'all';
		LibTpl::Set('status', $status);
		LibTpl::Set('Params', $Params);
		LibTpl::Set('LeftMenu','evaluate');
		$B2cOrder = new B2cOrder();
		$headArr = array(
			'title'=>'评论管理-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		LibTpl::Set('headArr', $headArr);
		switch ($status) {
			case 'all':
				$evaluateWhere=" and ord_status='completed' and ord_seller_delete=0 and ord_user_delete=0 and orp_status='completed' and (orp_evaluate=1 or (orp_refund_status='refunded' or orp_refund_status='close' or orp_refund_status is null)) ";
				break;
			case 'noreply':
				$evaluateWhere=" and ord_id in (select orp_ord_id from or_order_product left join or_evaluate_product on orp_id=evp_orp_id where orp_evaluate=1 and evp_shop_reply is null and orp_status='completed')";
				break;
			case 'replied':
				$evaluateWhere=" and ord_id in(select orp_ord_id from or_order_product left join or_evaluate_product on orp_id=evp_orp_id where orp_evaluate=1 and evp_shop_reply is not null and orp_status='completed')";
				break;
			case 'search':
				$evaluateWhere='';
				if(LibFc::Int($Params['orderId'])) $evaluateWhere .= sprintf(" and ord_id like'%%%s%%'",LibFc::Escape($Params['orderId']));
				if($Params['buyerName']!='') $evaluateWhere .= sprintf(" and ub_username like'%%%s%%'",LibFc::Escape($Params['buyerName']));
				break;
		}
		$baseWhere=sprintf(" and ord_shop_id=%d and ord_seller_delete=0 and ord_status='completed'",$_SESSION['_shopid']);
		$baseOrderBy='ord_add_time desc';
		$where = $baseWhere.$evaluateWhere;
		//获取订单列表
		$orderListData=$B2cOrder->getOrderList($nowPage,$perPage,$baseOrderBy,$where);
		//获取订单评价列表
		$B2cComment = new B2cComment();
		$orderEva = $B2cComment->getorderComInfo(array_column($orderListData['data'], 'ord_id'));
		LibTpl::Set('orderEva', $orderEva['data']);
		if($status=='replied')
		{
			if(!empty($orderListData['data']))
			{
				foreach ($orderListData['data'] as $key => $value)
				{
					foreach ($value['proArr'] as $k => $v)
					{
						if(empty($orderEva['data'][$value['ord_id']]['pro'][$v['orp_pro_id']]['evp_shop_reply'])) unset($orderListData['data'][$key]['proArr'][$k]);
					}
				}
			}
		}
		if($status=='noreply')
		{
			if(!empty($orderListData['data']))
			{
				foreach ($orderListData['data'] as $key => $value)
				{
					foreach ($value['proArr'] as $k => $v)
					{
						if(!empty($orderEva['data'][$value['ord_id']]['pro'][$v['orp_pro_id']]['evp_shop_reply'])) unset($orderListData['data'][$key]['proArr'][$k]);
					}
				}
			}
		}
		LibTpl::Set('orderList', $orderListData['data']);
		$Page = LibPage::Show($orderListData['data'][0]['total'], $perPage);
		LibTpl::Set('Page', $Page);
		LibTpl::Put();
	}


	/**
	 * @method    卖家订单
	 * @author 卢
	 * @copyright 2017-08-08
	 */
	public function order()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR09');
		$B2cOrder = new B2cOrder();
		$B2cProduct=new B2cProduct();
		$B2cBase=new B2cBase();
		$Params = mvc::$URL_PARAMS;
		$headArr = array(
			'title'=>'订单管理-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		$this->HEAD_CSSJS['plugin'][] = 'datetimepicker';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','order');
		//计算每个状态数量
		$statusCount=$B2cOrder->get('or_order',['count(ord_id) count','ord_status'],' and ord_seller_delete=0 and ord_user_delete=0 and ord_shop_id='.$_SESSION['_shopid'].' group by ord_status');
		$reOrder=$B2cBase->getFieldUniVal('or_order left join or_order_product on ord_id=orp_ord_id','orp_ord_id',sprintf(" and orp_refund_status in ('wait','confirm','refuse','refundpro') and ord_shop_id=%d and ord_status != 'cancel' and ord_seller_delete=0 and ord_user_delete=0",$_SESSION['_shopid']));
		foreach ($statusCount['data'] as $k => $v)
		{
			$sTotal=$v['count']?$v['count']:0;
			$sCount[$v['ord_status']]=$sTotal;
		}
		$sCount['refund']=count($reOrder['data']);
		LibTpl::Set('sCount',$sCount);
		$perPage=10;
		$monthTime=3*30*24*60*60;
		LibTpl::Set('Params',$Params);
		$userIdWhere=(isset($Params['userId'])&&LibFc::Int($Params['userId']))? sprintf(' and ord_uid=%d',LibFc::Int($Params['userId'])) : '';
		$nowPage=!empty($Params['page']) ? $Params['page'] : 1;
		$status=isset($Params['status']) ? $Params['status'] : '';
		$evaluate=isset($Params['evaluate']) ? $Params['evaluate'] : 'all';
		LibTpl::Set('status', $status);
		switch ($status) {
			case 'creat':
				$statusWhere=" and ord_status='creat'";
				break;
			case 'paied':
				$statusWhere=" and ord_status='paied'";
				break;
			case 'send':
				$statusWhere=" and ord_status='send'";
				break;
			case 'cancel':
				$statusWhere=" and ord_status='cancel'";
				break;
			case 'refund':
				if(count($reOrder['data']))
				{
					$statusWhere=sprintf(' and ord_id in(%s)',implode(',',$reOrder['data']));
				}else
				{
					$statusWhere=' and ord_id <-1';
					// goto end;
				}
				break;
			case 'completed':
				$statusWhere=" and ord_status='completed'";
				break;
			case 'evaluate':
				$statusWhere=" and ((ord_evaluate>0 and (orp_evaluate<1 or orp_evaluate is null )) or ((ord_evaluate is null  or ord_evaluate<1) and orp_evaluate>0) or (ord_evaluate <1 and orp_evaluate<1)) and ord_status='completed'";
				break;
		}
		switch ($evaluate) {
			case 'wait':
				$evaluateWhere=" and ((ord_evaluate>0 and (orp_evaluate<1 or orp_evaluate is null )) or ((ord_evaluate is null or ord_evaluate<1) and orp_evaluate>0) or (ord_evaluate <1 and orp_evaluate<1)) and ord_status='completed'";
				break;
			case 'completed':
				$evaluateWhere=" and ord_evaluate >0 and orp_evaluate>0 and ord_status='completed' and ord_id not in (select orp_ord_id from or_order_product where orp_evaluate = 0)";
				break;
			default:
				$evaluateWhere='';
				break;
		}
		$proNameWhere='';
		//配件名称和配件ID处理
		if(isset($Params['proName'])&&!empty($Params['proName']))
		{
			$keywordArr=LibFc::keyword($Params['proName']);
			if(count($keywordArr))
			{
				$keywordStr="'".implode("','",$keywordArr)."'";
				$keywordWhere=sprintf(' and key_txt in(%s)',$keywordStr);
				$keywordProData=$B2cProduct->get('bc_keyword right join bc_product_keyword on prk_key_id=key_id',['prk_pro_id'],$keywordWhere);
			}
			if(!count($keywordArr)||!count($keywordProData['data']))
			{
				//关键字搜索为空，搜索名称
				$nameOrder=$B2cProduct->get('bc_product left join or_order_product on orp_pro_id=pro_id',['orp_ord_id'],sprintf(" and orp_pro_name like '%%%s%%' group by orp_ord_id",LibFc::Escape($Params['proName'])));
				if(count($nameOrder['data']))
				{
					$orderResArr=array_column($nameOrder['data'], 'orp_ord_id');
					$proNameWhere=sprintf(' and ord_id in(%s)',implode(',',$orderResArr));
				}
				else
				{
					$proNameWhere=' and ord_id <-1';
				}
				// $orderListData['data']=[];
				// goto end;
			}else
			{
				$keywordPro=array_unique(array_column($keywordProData['data'],'prk_pro_id'));
				$proNameWhere=count($keywordPro)?sprintf(" and orp_pro_id in (%s)",implode(',',$keywordPro)):'';
			}
		}
		$proIdWhere=(isset($Params['proId'])&&!empty($Params['proId']))&&LibFc::Int($Params['proId'])? ' and orp_pro_id='.$Params['proId'] : '';
		$buyerWhere='';
		if(isset($Params['buyerName'])&&!empty($Params['buyerName']))
		{
			$userIdArr=$B2cProduct->get('us_user_base',['ub_uid'],sprintf(" and ub_username like'%%%s%%'",LibFc::Escape($Params['buyerName'])));
			if(count($userIdArr['data']))
			{
				$uIdArr=array_column($userIdArr['data'], 'ub_uid');
				$buyerWhere=sprintf(' and ord_uid in(%s)',implode(',',$uIdArr));
			}
			else
			{
				$buyerWhere=' and ord_id <-1';
				// goto end;
			}
		}
		$minTime=(isset($Params['completeMix'])&&!empty($Params['completeMix'])) ? sprintf(" and ord_add_time >%d",strtotime($Params['completeMix'])): '';
		$maxTime=(isset($Params['completeMax'])&&!empty($Params['completeMax'])) ? sprintf(" and ord_add_time <%d",strtotime($Params['completeMax'])): '';
		$orderSnWhere=(isset($Params['orderId'])&&!empty($Params['orderId'])) ? sprintf(" and ord_id =%d",LibFc::Escape($Params['orderId'])): '';
		$baseWhere=sprintf(' and ord_shop_id=%d and ord_seller_delete=0 and ord_user_delete=0',$_SESSION['_shopid']);
		$where=$baseWhere.$statusWhere.$proNameWhere.$proIdWhere.$minTime.$maxTime.$orderSnWhere.$buyerWhere.$evaluateWhere.$userIdWhere;
		$baseOrderBy='ord_add_time desc';
		$orderBy=$baseOrderBy;
		$orderListData=$B2cOrder->getOrderList($nowPage,$perPage,$orderBy,$where);
		// end:
		LibTpl::Set('orderList', $orderListData['data']);
		$Page = LibPage::Show($orderListData['data'][0]['total'], $perPage);
		LibTpl::Set('Page', $Page);
		LibTpl::Put();
	}
	/**
	 * @method    订单详情
	 * @author 卢
	 * @copyright 2017-08-08
	 */
	public function detail()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR09');
		$B2cOrder = new B2cOrder();
		$YpwAddr= new YpwAddr();
		$this->HEAD_CSSJS['css'][] ='css/order.css';
		$Params = mvc::$URL_PARAMS;
		$headArr = array(
			'title'=>'订单详情-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','order');
		if(!LibFc::Int($Params['orderId']))
		{
			LibTpl::Error('订单信息错误','/seller/order');
			exit();
		}
		$res=$B2cOrder->get('or_order',['count(*) count'],sprintf(' and ord_id=%d and ord_shop_id=%d',$Params['orderId'],$_SESSION['_shopid']),true);
		if(!$res['data']['count'])
		{
			LibTpl::Error('订单信息错误','/seller/order');
			exit();
		}
		//订单信息
		$orderRes=$B2cOrder->getOrderDetail($Params['orderId'],$_SESSION['_shopid']);
		//获取运单
		if($orderRes['data']['ord_status']!=='cancel'&&$orderRes['data']['ord_status']!=='paied'&&$orderRes['data']['ord_status']!=='creat')
		{
			$extId = array_column($orderRes['data']['proArr'],'orp_ext_id','orp_id');
			if(count($extId))
			{
				$pro_ext = [];
				foreach ($extId as $k=>$v)
				{
					$pro_ext[$v][] = $k;
				}
				$B2cExpress = new B2cExpress();
				$expInfo = $B2cExpress->getLogisticInfo(array_unique(array_values($extId)),true);
				if(!empty($expInfo['data']['same']))
				{
					foreach ($expInfo['data']['same'] as $key => $value)
					{
						if(!empty($value))
						{
							foreach ($value as $v)
							{
								$pro_ext[$key] = array_merge($pro_ext[$key],$pro_ext[$v]);
								unset($pro_ext[$v]);
							}
						}
					}
				}
				unset($expInfo['data']['same']);
				LibTpl::Set('ext',$pro_ext);
				LibTpl::Set('expInfo',$expInfo['data']);
			}
		}
		//店铺信息
		$shopInfo=$B2cOrder->Get('sh_shop',['*'],sprintf(' and shop_id=%d',$orderRes['data']['ord_shop_id']),true);
		$addrInfo=$YpwAddr->getAddrByIds($shopInfo['data']['shop_pct_ids']);
		LibTpl::Set('addrInfo',implode('', $addrInfo['data']));
		LibTpl::Set('shopInfo',$shopInfo['data']);
		LibTpl::Set('orderInfo',$orderRes['data']);
		LibTpl::Put();
	}
	/**
	 * @method    ajax订单删除
	 * @author 卢
	 * @copyright 2017-08-10
	 */
	public function ajaxDelOrder()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR03');
		$B2cOrder = new B2cOrder();
		$res=['status'=>false,'data'=>false];
		if(empty($_POST['orderId']))
		{
			$res['data']='请选择订单';
			LibFc::ajaxJsonEncode($res);
			exit();
		}
		$orderArr=is_array($_POST['orderId'])?$_POST['orderId']:[$_POST['orderId']];
		$orderArr=array_filter($orderArr,'LibFc::Int');
		// print_r($orderArr);
		if(count($orderArr))
		{
			$real=$_POST['real']=='real'? true:false;
			$status=$B2cOrder->get('or_order',['ord_status','ord_id'],sprintf(' and ord_shop_id=%d and ord_id in(%s)',$_SESSION['_shopid'],implode(',', $orderArr)));
			$orderId=[];
			$forbidArr=[];
			foreach ($status['data'] as $k => $v)
			{
				if($v['ord_status']=='cancel')
				{
					$orderId[]=$v['ord_id'];
					continue;
				}
				$forbidArr[]=$v['ord_id'];
			}
			if(count($orderId)>0)
			{
				$res=$B2cOrder->delOrder($orderId,$_SESSION['_shopid'],false,$real);
			}
			else
			{
				$res=['status'=>false,'data'=>'订单号为：'.implode(',',$forbidArr).'的订单不允许删除'];
			}
			LibFc::ajaxJsonEncode($res);
		}
	}
	/**
	 * @method    取消订单
	 * @return    [type]      [description]
	 * @author 卢
	 * @copyright 2017-08-10
	 */
	public function cancelOrder()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR02');
		$Params = mvc::$URL_PARAMS;
		$B2cOrder = new B2cOrder();
		$orderId=(int)$Params['orderId'];
		$res=['status'=>false,'data'=>'订单错误'];
		if($orderId)
		{
			$statusData=$B2cOrder->get('or_order',['ord_status'],sprintf(' and ord_shop_id=%d and ord_id=%d',$_SESSION['_shopid'],$orderId),true);
			$res=['status'=>false,'data'=>'不允许取消订单'];
			if($statusData['data']['ord_status']=='creat')
			{
				$res=$B2cOrder->updateOrderStatus($orderId,$_SESSION['_shopid'],['ord_status'=>'cancel'],$isUser=false);
			}
		}
		LibFc::ajaxJsonEncode($res);
	}
	/**
	 * @method    ajax获取物流信息
	 * @author     廖
	 * @copyright 2017-08-28
	 * @return    ajaxJsonEncode  {'extName':xxx,data['time':xxx,...]..}
	 */
	function ajaxGetLogisticInfo()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR09');
		if(LibFc::Int($_POST['orderId']))
		{
			$B2cExpress = new B2cExpress();
			$where = sprintf(" and orp_ord_id=%d and ord_shop_id=%d and orp_ext_id is not null",$_POST['orderId'],$_SESSION['_shopid']);
			$re = $B2cExpress->Get('or_order left join or_order_product on ord_id=orp_ord_id',['*'],$where);
			if(!empty($re['data']))
			{
				$data = array_unique(array_column($re['data'], 'orp_ext_id'));
				$res = $B2cExpress->getLogisticInfo($data);
				unset($res['data']['same']);
			}
			LibTpl::Set('data', $res['data']);
			LibTpl::Set('orderId', $_POST['orderId']);
			$result=LibTpl::Fetch('seller/ajaxGetLogisticInfo.php');
			LibFc::ajaxJsonEncode(['status'=>true,'data'=>$result]);
		}else
		{
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数不正确']);
		}
	}
	/**
	 * @method    获取物流信息
	 * @author     廖
	 * @copyright 2017-08-28
	 * @return    ajaxJsonEncode  {'extName':xxx,data['time':xxx,...]..}
	 */
	function getLogisticInfo()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR09');
		$Params = mvc::$URL_PARAMS;
		$headArr = array(
			'title'=>'查看物流-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		LibTpl::Set('headArr', $headArr);
		$B2cExpress = new B2cExpress();
		if(LibFc::Int($Params['orderId']))
		{
			//获取所有的快递信息数据 //缓存读取
			$B2cProduct = new B2cProduct();
			$YpwAddr = new YpwAddr();
			$exp = $B2cExpress->getExpress();
			$where = sprintf(" and ord_id=%d and ord_shop_id=%d ",$Params['orderId'],$_SESSION['_shopid']);
			$baseData = ['ord_id','ord_uid','ord_status','ord_shop_remark','ord_add_name','ord_add_tel','ord_add_mobile','ord_send_time','ord_shop_id','ord_add_pct','ord_add_address','shop_uid','shop_name','shop_domain'];
			$re = $B2cExpress->get('or_order left join sh_shop on ord_shop_id=shop_id',$baseData,$where,true);
			LibTpl::Set('order',$re['data']);
			if(!empty($re['data']))
			{
				if($re['data']['ord_status'] == 'completed' || $re['data']['ord_status'] == 'send' || $re['data']['ord_status'] == 'cancel')
				{
					$where = LibFc::Int($Params['orpId'])?' and orp_id='.$Params['orpId']:'';
					//获取该订单下的所有订单配件
					$res = $B2cExpress->get('or_order_product',['orp_id','orp_pro_id','orp_pro_name','orp_count','orp_ext_id'],sprintf("and orp_ord_id=%d and (orp_status='send' or orp_status='completed' or orp_status='cancel') %s",$Params['orderId'],$where));
					$ImgArr = array_unique(array_column($res['data'], 'orp_pro_id'));
					$extIdArr = array_unique(array_column($res['data'], 'orp_ext_id'));
					// //获取配件信息
					if(!empty($ImgArr)) $img = $B2cProduct->getProductPic($ImgArr,false);
					// //获取快递信息
					if(!empty($extIdArr))
					{
						$expInfo = $B2cExpress->getLogisticInfo($extIdArr,true);
						$expInfo = $expInfo['data'];
					}
					$expPro=[];
					if(!empty($res['data']))
					{
						foreach ($res['data'] as $key => $value)
						{
							$expPro[$value['orp_ext_id']]['pro'][$value['orp_pro_id']] = array_merge($value,$img['data'][$value['orp_pro_id']][0]);
						}
					}
					//合併
					if(count($extIdArr)>0)
					{
						//合并数据
						foreach ($expPro as $key=>$value)
						{
							if(!empty($expInfo[$key]))
							{
								$expPro[$key] = array_merge($value,$expInfo[$key]);
							}
							//这个是重复的物流表单号
							if(!empty($expInfo['same']) && !empty($expInfo['same'][$key]))
							{
								foreach ($expInfo['same'][$key] as $k=> $v)
								{
									if(!empty($expPro[$v]['pro']))
									{
										$expPro[$key]['pro'] = array_merge($expPro[$key]['pro'],$expPro[$v]['pro']);
									}
									unset($expPro[$v]);
								}
							}
						}
					}
					LibTpl::Set('expId',$extIdArr);
					LibTpl::Set('data',$expPro);
				}
				else
				{
					$logArr = ['creat'=>'订单还没有付款!','paied'=>'订单等待发货!'];
					LibTpl::Error($logArr[$re['data']['ord_status']],mvc::$cfg['HOST']['b2c'].'seller/detail?orderId='.$re['data']['ord_id']);
					exit;
				}
			}
			else
			{
				LibTpl::Error('订单不存在!',mvc::$cfg['HOST']['b2c'].'seller/order');
				exit;
			}
			LibTpl::Set('orderlog',true);
		}
		elseif(LibFc::Int($Params['repId']))
		{
			$res = $B2cExpress->get('or_refund_pact left join sh_shop on rep_shop_id=shop_id left join or_order_product on rep_orp_id=orp_id',['rep_uid','rep_ord_id','rep_orp_id','rep_refund_pro_time','rep_refund_addr','rep_express_des','shop_id','shop_uid','shop_name','shop_domain','orp_pro_id','orp_pro_name'],sprintf('and rep_id=%d and rep_shop_id=%d and rep_type>0',$Params['repId'],$_SESSION['_shopid']),true);
			if(!empty($res['data']))
			{
				$res['data']['rep_refund_addr'] = json_decode($res['data']['rep_refund_addr'],true);
				$res['data']['rep_express_des'] = json_decode($res['data']['rep_express_des'],true);
				// print_r($res['data']);
				LibTpl::Set('data',$res['data']);
				//调用api获取物流信息
				if(!empty($res['data']['rep_express_des']['expcode']))
				{
					$LibYpApi = new LibYpApi();
					$dataArr = [
						'ext_exp_code'=>$res['data']['rep_express_des']['expcode'],
						'ext_number'=>$res['data']['rep_express_des']['number'],
						'ext_from'=>'B2C'
					];
					$resArr = $LibYpApi->Get('express/getTrack',$dataArr);
					$resArr['data']['ext_track'] = json_decode($resArr['data']['ext_track'],true);
					//获取缓存中的物流公司信息
					$exp = $B2cExpress->getExpress();
					$resArr['data'] = array_merge($resArr['data'],$exp['data'][$resArr['data']['ext_exp_code']]);
					LibTpl::Set('logic',$resArr['data']);
					//配件图片
					$B2cProduct = new B2cProduct;
					$picData = $B2cProduct->getProductPic([$res['data']['orp_pro_id']]);
					LibTpl::Set('pic',$picData['data'][$res['data']['orp_pro_id']][0]);
				}
			}
			LibTpl::Set('refunded',true);
		}
		else
		{
			LibTpl::Error('订单不存在!',mvc::$cfg['HOST']['b2c'].'seller/order');
			exit;
		}
		$status = $B2cExpress->expressStatus();
		LibTpl::Set('status',$status);
		$week=array(
		    "1"=>"周一",
		    "2"=>"周二",
		    "3"=>"周三",
		    "4"=>"周四",
		    "5"=>"周五",
		    "6"=>"周六",
		    "7"=>"周日"
		);
		LibTpl::Set('week',$week);
		$this->HEAD_CSSJS['css'][] = 'css/logistic.css';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Put();
	}
	/**
	 * @method    保存店主回复内容
	 * @author    廖
	 * @copyright 2017-08-14
	 * @return    LibFc::ajaxJsonEncode(['status'=>true,'data'=>1,'code'=>xxx])
	 */
	public function ajaxSaveReplyCom()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR04');
		if(LibFc::Int($_POST['commId']))
		{
			if(empty($_POST['replyCom']))
			{
				LibFc::ajaxJsonEncode(['status'=>false,'data'=>'回复内容不能为空！']);
				exit;
			}
			$B2cBase = new B2cBase();
			$re = $B2cBase->Set('or_evaluate_product',['evp_shop_reply'=>$_POST['replyCom'],'evp_reply_time'=>time()],' and evp_id='.$_POST['commId']);
			LibFc::ajaxJsonEncode($re);
		}else
		{
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数不正确']);
		}

	}
	/**
	 * @method    发货
	 * @author 卢
	 * @copyright 2017-08-16
	 */
	public function collroduct()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR06');
		$B2cOrder = new B2cOrder();
		$Params = mvc::$URL_PARAMS;
		$headArr = array(
			'title'=>'发货-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','collroduct');
		//计算每个状态数量
		$statusCount=$B2cOrder->get('or_order left join or_order_product on ord_id=orp_ord_id',['count(ord_id) count','ord_status']," and (orp_refund_status is null or orp_refund_status='') and ord_user_delete=0 and ord_seller_delete=0 and ord_shop_id=".$_SESSION['_shopid'].' group by ord_status');
		foreach ($statusCount['data'] as $k => $v)
		{
			$sTotal=$v['count']?$v['count']:0;
			$sCount[$v['ord_status']]=$sTotal;
		}
		LibTpl::Set('sCount',$sCount);
		$perPage=4;
		$monthTime=3*30*24*60*60;
		LibTpl::Set('Params',$Params);
		$userIdWhere=(isset($Params['userId'])&&LibFc::Int($Params['userId']))? sprintf(' and ord_uid=%d',$Params['userId']) : '';
		$nowPage=isset($Params['page']) ? $Params['page'] : 1;
		$status=isset($Params['status']) ? $Params['status'] : 'paied';
		LibTpl::Set('status', $status);
		switch ($status) {
			case 'paied':
				$statusWhere=" and ord_status='paied'";
				break;
			case 'send':
				$statusWhere=" and ord_status='send'";
				break;
		}
		$baseWhere=sprintf(" and ord_shop_id=%d and ord_seller_delete=0 and ord_user_delete=0 and (orp_refund_status is null or orp_refund_status='')",$_SESSION['_shopid']);
		$where=$baseWhere.$statusWhere;
		$baseOrderBy='ord_add_time desc';
		$orderBy=$baseOrderBy;
		$orderListData=$B2cOrder->getOrderList($nowPage,$perPage,$orderBy,$where);
		// print_r($orderListData);
		LibTpl::Set('orderList', $orderListData['data']);
		$Page = LibPage::Show($orderListData['data'][0]['total'], $perPage);
		LibTpl::Set('Page', $Page);
		LibTpl::Put();
	}
	/**
	 * @method    订单回收站
	 * @author 卢
	 * @copyright 2017-08-18
	 */
	public function recyledOrder()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR11');
		$Params = mvc::$URL_PARAMS;
		$B2cOrder = new B2cOrder();
		$headArr = array(
			'title'=>'订单回收站-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','recyledOrder');
		$perPage=10;
		// echo $_SESSION['_shopid'];
		$nowPage=isset($Params['page']) ? $Params['page'] : 1;
		$baseWhere=sprintf(' and ord_shop_id=%d and ((ord_user_delete=1 and ord_seller_delete=1) or (ord_user_delete=1 and ord_seller_delete=0) or (ord_user_delete=0 and ord_seller_delete=1))',$_SESSION['_shopid']);
		$where=$baseWhere;
		$baseOrderBy='ord_add_time desc';
		$orderBy=$baseOrderBy;
		$orderListData=$B2cOrder->getOrderList($nowPage,$perPage,$orderBy,$where);
		// print_r($orderListData);
		LibTpl::Set('orderList', $orderListData['data']);
		$Page = LibPage::Show($orderListData['data'][0]['total'], $perPage);
		LibTpl::Set('Page', $Page);
		LibTpl::Put();
	}
	/**
	 * @method    还原订单
	 * @author 卢
	 * @copyright 2017-08-18
	 */
	public function ajaxRestoreOrder()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR12');
		$B2cOrder = new B2cOrder();
		$B2cLog = new B2cLog();
		$res=['status'=>false,'data'=>false];
		if(empty($_POST['orderId']))
		{
			LibFc::ajaxJsonEncode($res);
			exit();
		}
		$orderArr=is_array($_POST['orderId'])?$_POST['orderId']:[$_POST['orderId']];
		$orderArr=array_filter($orderArr,'LibFc::Int');
		if(count($orderArr)>0)
		{
			$res=$B2cOrder->restoreDeleteOrder($orderArr,$_SESSION['_shopid']);
		}
		LibFc::ajaxJsonEncode($res);
	}
	/**
	 * @method   ajax获取ueditor图片空间弹窗
	 * @author 卢
	 * @copyright 2017-08-23
	 */
	public function getUeditorPic()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		//分类树
		$cateData=$B2cBase->get('sh_pic_category',['*'],sprintf(' and pica_shop_id=%d',$_SESSION['_shopid']));
		foreach ($cateData['data'] as $k => $v)
		{
			$cate=$v['pica_style']>0?'adorn':'product';
			$data[]=['id'=>$v['pica_style'].'.'.$v['pica_id'],'pid'=>$v['pica_style'].'.'.$v['pica_pid'],'name'=>$v['pica_name'],'picType'=>$v['pica_style'],'cate'=>$cate];
		}
		$data[]=['id'=>'0.0','pid'=>'0','name'=>'配件图片','picType'=>0,'cate'=>'product','open'=>true];
		$data[]=['id'=>'1.0','pid'=>'0','name'=>'店铺装修图片','picType'=>1,'cate'=>'adorn','open'=>true];
		$where = sprintf(' and spi_shop_id=%d order by spi_atime desc limit 18',$_SESSION['_shopid']);
		$res=$B2cBase->get('sh_pic',['*'], $where);
		LibTpl::Set('list', $res['data']);
		LibTpl::Set('treeArr', json_encode($data));
		$data=LibTpl::Fetch('/seller/getUeditorPic.php');
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$data]);
	}
	/**
	 * @method   ajax获取ueditor图片空间弹窗
	 * @author 卢
	 * @copyright 2017-08-23
	 */
	public function getProPic()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		//分类树
		$cateData=$B2cBase->get('sh_pic_category',['*'],sprintf(' and pica_shop_id=%d and pica_style=0',$_SESSION['_shopid']));
		foreach ($cateData['data'] as $k => $v)
		{
			$cate=$v['pica_style']>0?'adorn':'product';
			$data[]=['id'=>$v['pica_style'].'.'.$v['pica_id'],'pid'=>$v['pica_style'].'.'.$v['pica_pid'],'name'=>$v['pica_name'],'picType'=>$v['pica_style'],'cate'=>$cate];
		}
		$data[]=['id'=>'0.0','pid'=>'0','name'=>'配件图片','picType'=>0,'cate'=>'product','open'=>true];
		// $data[]=['id'=>'1.0','pid'=>'0','name'=>'店铺装修图片','picType'=>1,'cate'=>'adorn','open'=>true];
		// print_r($data);
		$where=sprintf(" and spi_shop_id=%d and spi_cate='product' order by spi_atime desc limit 18",$_SESSION['_shopid']);
		$res=$B2cBase->get('sh_pic',['*'], $where);
		LibTpl::Set('list', $res['data']);
		LibTpl::Set('treeArr', json_encode($data));
		$data=LibTpl::Fetch('/seller/getProPic.php');
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$data]);
	}
	/**
	 * @method   ajax获取装修图片空间弹窗
	 * @author   liao
	 * @copyright 2017-09-27
	 */
	public function getDesignBannerPic()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();
		//分类树
		$cateData=$B2cBase->get('sh_pic_category',['*'],sprintf(' and pica_shop_id=%d',$_SESSION['_shopid']));
		foreach ($cateData['data'] as $k => $v)
		{
			$cate=$v['pica_style']>0?'adorn':'product';
			$data[]=['id'=>$v['pica_style'].'.'.$v['pica_id'],'pid'=>$v['pica_style'].'.'.$v['pica_pid'],'name'=>$v['pica_name'],'picType'=>$v['pica_style'],'cate'=>$cate];
		}
		$data[]=['id'=>'0.0','pid'=>'0','name'=>'配件图片','picType'=>0,'cate'=>'product','open'=>true];
		$data[]=['id'=>'1.0','pid'=>'0','name'=>'店铺装修图片','picType'=>1,'cate'=>'adorn','open'=>true];
		// print_r($data);
		$where=sprintf(' and spi_shop_id=%d order by spi_atime desc limit 18',$_SESSION['_shopid']);
		$res=$B2cBase->get('sh_pic',['*'], $where);

		LibTpl::Set('type',$Params['type']);
		LibTpl::Set('list', $res['data']);
		LibTpl::Set('treeArr', json_encode($data));
		$data=LibTpl::Fetch('/module/designImageZoom.php');
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$data]);
	}
	/**
	 * @method   ueditor图片在线空间获取图片
	 * @author 卢
	 * @copyright 2017-08-23
	 */
	public function getCatePic(){
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();
		$nowPage=isset($Params['page'])?$Params['page'] :1;
		//排序
		switch ($Params['orderBy']) {
			case 'tdesc':
				$order='spi_atime desc';
				break;
			case 'tasc':
				$order='spi_atime asc';
				break;
			case 'sdesc':
				$order='spi_size desc';
				break;
			case 'sasc':
				$order='spi_size asc';
				break;
			case 'nasc':
				$order='spi_name desc';
				break;
			case 'ndesc':
				$order='spi_name asc';
				break;
			default:
				$order='spi_atime desc';
				break;
		}
		//where条件
		//顶级
		if(empty($Params['pid'])&&!empty($Params['id']))
		{
			//数据表中不存在的顶级分类
			$where=sprintf(" and spi_style=%d and (spi_pica_id is null or spi_pica_id=0) and spi_shop_id=%d and spi_cate='%s'",LibFc::Int($Params['picType']),$_SESSION['_shopid'],LibFc::Escape($Params['cate']));
		}
		else if(!empty($Params['pid'])&&!empty($Params['id']))
		{
			//选中数据表中存在分类
			$cateId=explode('.',$Params['id']);
			$where=sprintf(" and spi_style=%d and spi_pica_id =%d and spi_shop_id=%d and spi_cate='%s'",LibFc::Int($Params['picType']),LibFc::Int($cateId[1]),$_SESSION['_shopid'],LibFc::Escape($Params['cate']));
		}else
		{
			//默认按时间排列分类
			$where=' and spi_shop_id='.$_SESSION['_shopid'];
		}
		if(!empty($Params['picName']))
		{
			$where.=sprintf(" and spi_oriname like '%%%s%%' or spi_name like  '%%%s%%' ",LibFc::Escape($Params['picName']),LibFc::Escape($Params['picName']));
		}
		$totalData=$B2cBase->get('sh_pic',['count(*) total'],$where,true);
		$total=$totalData['data']['total'];
		$perPage=18;
		//计算总页数
		$totalPage=ceil($total/$perPage);
		$where .=sprintf(' order by %s limit %d,%d', $order, ($nowPage-1)*$perPage, $perPage);
		$res=$B2cBase->get('sh_pic',['*'], $where);
		LibTpl::Set('list', $res['data']);
		LibTpl::Set('total',$totalPage);
		LibTpl::Set('page',$realPage);
		LibTpl::Set('Params', $Params);
		$data=LibTpl::Fetch('/seller/getCatePic.php');
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$data]);
	}
	/**
	 * @method    获取修改订单价格弹窗页面
	 * @author 卢
	 * @copyright 2017-08-24
	 */
	public function ajaxEditOrderPrice()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR02');
		$Params = mvc::$URL_PARAMS;
		$B2cOrder = new B2cOrder();
		$YpwAddr= new YpwAddr();
		$orderRes=$B2cOrder->getOrderDetail($Params['orderId'],$_SESSION['_shopid']);
		if($orderRes['data']['ord_status']!='creat')
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'该订单暂不可修改价格']);
		$proId=array_keys($orderRes['data']['proArr']);
		if(count($proId))
		{
			foreach ($proId as $k => $v)
			{
				$source[$orderRes['data']['ord_shop_id']][$v]=$orderRes['data']['proArr'][$v]['orp_count'];
			}
			$proInfoRes=$B2cOrder->getProductRealInfo($proId,$orderRes['data']['ord_uid'],[$orderRes['data']['ord_shop_id']],$source);
			// print_r($proInfoRes);
			//店铺信息
			$shopInfo=$B2cOrder->Get('sh_shop',['*'],sprintf(' and shop_id=%d',$orderRes['data']['ord_shop_id']),true);
			$addrInfo=$YpwAddr->getAddrByIds($shopInfo['data']['shop_pct_ids']);
			LibTpl::Set('addrInfo',implode('', $addrInfo['data']));
			LibTpl::Set('shopInfo',$shopInfo['data']);
			LibTpl::Set('proInfo',$proInfoRes['data']);
			LibTpl::Set('orderInfo',$orderRes['data']);
			$data=LibTpl::Fetch('/seller/editOrderPrice.php');
			LibFc::ajaxJsonEncode(['status'=>true,'data'=>$data]);
		}
	}
	/**
	 * @method    修改订单价格
	 * @author 卢
	 * @copyright 2017-08-28
	 */
	public function editOrder()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR02');
		$B2cOrder = new B2cOrder();
		// print_r($_POST);
		// die;
		$res=$B2cOrder->editorOrderPrice($_SESSION['_shopid'],$_POST['discount'],$_POST['price'],$_POST['frtPrice'],$_POST['orderId']);
		LibFc::ajaxJsonEncode($res);
	}

	/**
	 * @method    校验用户名称
	 * @author xu
	 * @copyright 2017-08-28
	 */
	public function checkUserName()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		// 参数
		if(empty($_POST['newUserName'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'输入错误！']);
		$newUserName = LibFc::Escape($_POST['newUserName']);
		// 用户信息
		$B2cBase = new B2cBase();
		$YpwBase = new YpwBase();
		$user = $YpwBase->get('yp_user',['u_id as ub_uid'],sprintf(" and (u_name='%s' or (u_mobile='%s' and u_mobile_check='Y'))",$newUserName,$newUserName),true);
		if(empty($user['data'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'用户不存在！']);
		// 管理员
		$shop = $B2cBase->get('sh_shop',['shop_uid'],sprintf(" and shop_id=%d ",$_SESSION['_shopid']),true);
		if($user['data']['ub_uid'] == $shop['data']['shop_uid']) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'不能添加自己作为自己店铺会员！']);
		// 会员
		$member = $B2cBase->get('sh_member_link left join sh_member on mem_id=meml_mem_id ',['*'],sprintf(" and mem_shop_id=%d and meml_uid=%d ",$_SESSION['_shopid'],$user['data']['ub_uid']),true);
		if(!empty($member['data'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'该用户已经是您的会员！']);
		// 校验通过
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$user['data']['ub_uid']]);
	}

	/**
	 * @method    提交新增会员表单
	 * @author xu
	 * @copyright 2017-08-28
	 */
	public function submitnewUid()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SU01');
		$B2cBase = new B2cBase();
		//参数
		if(empty($_POST['allUid'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		$uids = $_POST['allUid'];
		// 获取级别ID
		$res = $B2cBase->get('sh_member',['mem_id','mem_mel_id'],sprintf(" and mem_shop_id = %d ",$_SESSION['_shopid']));
		$temp = array_column($res['data'],'mem_id','mem_mel_id');
		foreach($uids as $k=>$v)
		{
			if($v[0] == -1)
			{
				$B2cBase->del('sh_member_link', sprintf(" and meml_uid=%d and meml_shop_id=%d",$v[1],$_SESSION['_shopid']));
			}
			else
			{
				if(!LibFc::Int($v[0]) || empty($temp[$v[0]]) || !LibFc::Int($v[1])) continue;
				$res = $B2cBase->get('sh_member_link',['*'],sprintf(" and meml_uid=%d and meml_shop_id=%d ",$v[1],$_SESSION['_shopid']));
				if(empty($res['data']))
				{
					// 新增会员
					$data = ['meml_uid'=>$v[1],'meml_mem_id'=>$temp[$v[0]],'meml_add_time'=>time(),'meml_shop_id'=>$_SESSION['_shopid']];
					if(isset($v[2])) $data['meml_remark'] = $v[2];
					$res = $B2cBase->add('sh_member_link',$data);
				}
				else
				{
					// 修改等级
					$data = ['meml_mem_id'=>$temp[$v[0]]];
					if(isset($v[2])) $data['meml_remark'] = $v[2];
					$B2cBase->set('sh_member_link', $data,sprintf(" and meml_uid=%d and meml_shop_id=%d",$v[1],$_SESSION['_shopid']));
				}
			}
		}
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'新增会员成功！']);
	}

	/**
	 * @method  更新会员等级
	 * @author xu
	 * @copyright 2017-08-28
	 */
	public function editThisShopMem()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SU02');
		//校验传递过来的用户ID为整数
		$B2cBase = new B2cBase();
		//参数
		if(empty($_POST['uid'])||!LibFc::Int($uid=$_POST['uid'])||empty($_POST['level'])||!LibFc::Int($level=$_POST['level']))
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		// 更新会员等级
		$res = $B2cBase->get('sh_member',['mem_id'],sprintf(" and mem_shop_id=%d and mem_mel_id=%d ",$_SESSION['_shopid'],$level),true);
		$where = sprintf(' and meml_shop_id=%d and meml_uid=%d ',$_SESSION['_shopid'],$uid);
		$B2cBase->set('sh_member_link',array('meml_mem_id'=>$res['data']['mem_id'], 'meml_remark'=>$_POST['remark']),$where);
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'编辑会员成功！']);
	}


	/**
	 * @method  批量更新会员等级
	 * @author xu
	 * @copyright 2017-09-05
	 */
	public function editThisShopMems()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SU02');
		//校验传递过来的用户ID为整数
		$B2cBase = new B2cBase();
		//参数
		if(empty($_POST['uids'])||empty($uids=array_filter($_POST['uids'],'LibFc::Int'))||empty($_POST['level'])||!LibFc::Int($level=$_POST['level']))
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
    	// 等级的mem_id
		$res = $B2cBase->get('sh_member',['mem_id'],sprintf(" and mem_shop_id=%d and mem_mel_id=%d ",$_SESSION['_shopid'],$level),true);
    	// 批量更新会员等级信息
		$where = sprintf(' and meml_shop_id=%d and meml_uid in (%s) ',$_SESSION['_shopid'],implode(',',$uids));
		$B2cBase->set('sh_member_link',array('meml_mem_id'=>$res['data']['mem_id']),$where);
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'编辑会员成功！']);
	}

	/**
	 * @method  店铺促销
	 * @author xu
	 * @copyright 2017-08-28
	 */
	public function promotion()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('CX05');
		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();
		// 店铺信息
		$shop = $B2cBase->get('sh_shop',['*'],sprintf(" and shop_id=%d ",$_SESSION['_shopid']),true);
		LibTpl::Set('shopData',$shop['data']);
		//满减
		$res = $B2cBase->get('sh_manjian',['*'],' and man_shop_id='.$_SESSION['_shopid']);
		$manjian = $res['data'];
		$future = array();
		$pre = array();
		$now = array();
		foreach ($manjian as $key => $value) {
			// 生效
			if($value['man_etime']>time() && time()>$value['man_btime'])
			{
				$now[] = $value;
			}
			// 失效
			if($value['man_etime']<time())
			{
				$pre[] = $value;
			}
			// 未来
			if(time()<$value['man_btime'])
			{
				$future[] = $value;
			}
		}
		LibTpl::Set('manjianDataNow', $now);
		LibTpl::Set('manjianDataPre', $pre);
		LibTpl::Set('manjianDataFuture', $future);
		// meta
		$headArr = array(
			'title'=>'促销设置-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		// 引用datetimepicker插件
		$this->HEAD_CSSJS['plugin'][] = 'datetimepicker';
		$this->HEAD_CSSJS['plugin'][] = 'jqueryValidation';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','promotion');
		LibTpl::Put();
	}

	/**
	 * @method  新增店铺促销规则
	 * @author xu
	 * @copyright 2017-08-31
	 */
	public function savenewManjian()
	{
		//开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('CX01');
		$B2cBase = new B2cBase();
		$man_name = LibFc::Escape($_POST['man_name']);
		$data= array(
				'man_shop_id'=>$_SESSION['_shopid'],
				'man_full_money'=>sprintf("%.2f",$_POST['FULL_MONEY']),
				'man_cut_money'=>sprintf("%.2f",$_POST['CUT_MONEY']),
				'man_btime'=>strtotime($_POST['BTIME']),
				'man_etime'=>strtotime($_POST['ETIME']),
				'man_name'=>$man_name
			);
		// 入库
		$data = $B2cBase->add('sh_manjian',$data);
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'添加成功！']);
	}

	/**
	 * @method  删除当前店铺的满减规则
	 * @author xu
	 * @copyright 2017-08-31
	 */
	public function delThisManjianRecord()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('CX03');
		$B2cBase = new B2cBase();
		// 参数
		if(empty($_POST['man_id']) || !LibFc::Int($_POST['man_id'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		// 执行
		$where = sprintf(" and man_id=%d and man_shop_id=%d ",$_POST['man_id'],$_SESSION['_shopid']);
		$B2cBase->del('sh_manjian',$where);
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'删除成功！']);
	}


	/**
	 * @method  编辑店铺的满减规则
	 * @author xu
	 * @copyright 2017-08-31
	 */
	public function editThisManjianRecord()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('CX02');
		$B2cBase = new B2cBase();
		// 参数
		if(empty($_POST['man_id'])||!LibFc::Int($_POST['man_id'])||empty($_POST['BTIME'])||empty($_POST['ETIME'])||!strtotime($_POST['BTIME'])||!strtotime($_POST['ETIME']) || empty($_POST['FULL_MONEY']) || empty($_POST['CUT_MONEY']))
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		$fullMoney = sprintf("%.2f",$_POST['FULL_MONEY']);
		$cutMoney = sprintf("%.2f",$_POST['CUT_MONEY']);
		if(empty($fullMoney) || empty($cutMoney) || $fullMoney<=$cutMoney) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'满减金额填写错误！']);
		// 拼接sql
		$where = sprintf(" and man_id=%d and man_shop_id=%d ",$_POST['man_id'],$_SESSION['_shopid']);
		$data = array(
				'man_full_money' => $fullMoney,
				'man_cut_money' => $cutMoney,
				'man_btime'=> strtotime($_POST['BTIME']),
				'man_etime'=> strtotime($_POST['ETIME']),
				'man_name'=> LibFc::Escape($_POST['man_name'])
			);
		// 执行
		$B2cBase->set('sh_manjian',$data,$where);
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'更改成功！']);
	}

	/**
	 * @method  保存店铺的满包邮额度设置
	 * @author xu
	 * @copyright 2017-08-31
	 */
	public function saveditShopBaoyou()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		// 参数
		if(empty($_POST['shop_baoyou'])||empty($baoyou=sprintf("%.2f",$_POST['shop_baoyou']))) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		$where = sprintf(" and shop_id=%d ",$_SESSION['_shopid']);
		$B2cBase->set('sh_shop',['shop_baoyou' => $baoyou],$where);
		// 返回
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'更改成功！']);
	}

	/**
 	* @method  店铺包邮设定
 	* @author xu
 	* @copyright 2017-09-01
 	*/
	public function shopBaoyou()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('CX04');

		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();
		// 获取当前店铺信息
		$shop = $B2cBase->get('sh_shop',['*'],sprintf(" and shop_id=%d ",$_SESSION['_shopid']),true);
		LibTpl::Set('shopData',$shop['data']);
		// meta
		$headArr = array(
			'title'=>'店铺包邮-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		// 引用datetimepicker插件
		$this->HEAD_CSSJS['plugin'][] = 'datetimepicker';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','promotion');
		LibTpl::Put();
	}


/**
 	* @method  关闭店铺包邮
 	* @author xu
 	* @copyright 2017-09-01
 	*/
	public function shutdownShopBaoyou()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('CX04');
		$B2cBase = new B2cBase();
		// sql
		$where = sprintf(" and shop_id=%d ",$_SESSION['_shopid']);
		$B2cBase->set('sh_shop',['shop_baoyou' => -1],$where);
		// 返回
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'更改成功！']);
	}

/**
 	* @method  开启店铺包邮
 	* @author xu
 	* @copyright 2017-09-01
 	*/
	public function ajaxSaveShopbaoyou()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('CX04');
		$B2cBase = new B2cBase();
		// 参数
		if(empty($_POST['number'])||empty($number=sprintf("%.2f",$_POST['number']))) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		// 更新数据
		$where = sprintf(" and shop_id = %d ",$_SESSION['_shopid']);
		$res = $B2cBase->set("sh_shop",['shop_baoyou'=>$number],$where);
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'更改成功！']);
	}

/**
 	* @method  自动完成文件夹查询
 	* @author xu
 	* @copyright 2017-09-01
 	*/
	public function ajaxAutoCompleteSearch()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();
		// 参数
		$cateGoryName = trim($_POST['cateGoryName']);
		$where = sprintf(" and pica_shop_id=%d ",$_SESSION['_shopid']);
		if(!empty($cateGoryName)){
			$add_where = " and pica_name like '%".$cateGoryName."%'";
			$where = $where.$add_where;
		}
		$allCategory = $B2cBase->get('sh_pic_category',['*'],$where);
		// json
		$allCategoryJson = array();
		if(!empty($allCategory['data']))
		{
			foreach ($allCategory['data'] as $key => $value)
			{
				// 子分类
				$allCategoryJson[$key]['id'] = $value['pica_id'].$value['pica_style'];
				$allCategoryJson[$key]['pId'] = $value['pica_pid'].$value['pica_style'];
				$allCategoryJson[$key]['name'] = $value['pica_name'];
			}
		}
		// 顶级分类
		$allCategoryJson[] = array('id'=>'00','pId'=>0,'name'=>'配件图片','open'=>'true');
		$allCategoryJson[] = array('id'=>'01','pId'=>0,'name'=>'店铺装修图片','open'=>'true');
		// json
		$array = array('status'=>true,'data'=>$allCategoryJson,'code'=>0);
		LibFc::ajaxJsonEncode($array);
	}
	/**
	 * @method    修改上传的图片的父目录
	 * @author 卢
	 * @copyright 2017-09-08
	 */
	public function updateUploadPic()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();
		$spiId=(int)$Params['spi_id'];
		$spiPicaId=(int)$Params['spi_pica_id'];
		if($spiId)
		{
			$target=['spi_pica_id'=>$spiPicaId];
			$res=$B2cBase->set('sh_pic',$target,sprintf('and spi_id=%d',$spiId));
			LibFc::ajaxJsonEncode($res);
		}
	}
	/**
	 * @method    店铺装修
	 * @author 卢
	 * @copyright 2017-09-21
	 */
	public function design()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SD00');
		$Params = mvc::$URL_PARAMS;
		$B2cBase=new B2cBase();
		if(!file_exists(mvc::$cfg['ROOT'].'home/static/shop/tplConfig.php'))
		{
			LibTpl::Error('店铺配置文件不存在');
			exit();
		}
		$allTplArr=include(mvc::$cfg['ROOT'].'home/static/shop/tplConfig.php');
		$inArr=array_column($allTplArr, 'tag');
		// print_r($Params);
		// die;
		// LibTpl::Set('param',$Params);
		$view=isset($Params['viewPage'])?$Params['viewPage']:'index';
		$view=$Params['viewPage']=in_array($view, ['item','index','search'])?$view:'index';
		if($view=='item'&&!isset($Params['proId']))
		{
			$B2cProduct=new B2cProduct();
			$pro=$B2cProduct->getProduct(['pro_id'],sprintf(' and pro_shop_id=%d order by pro_add_time desc',$_SESSION['_shopid']),true);
			// $pro=$B2cProduct->getProduct(['pro_id'],' order by pro_add_time desc',true);
			if(!count($pro['data']))
			{
				$pro=$B2cProduct->getProduct(['pro_id'],' order by pro_add_time desc',true);
				if(empty($pro['data']))
				{
					LibTpl::Error('请先添加配件','/seller/productPart');
					exit();
				}
			}
			$query=$Params;
			$path=array_merge($query,['viewPage'=>$view,'proId'=>$pro['data']['pro_id']]);
			// $url=isset($Params['dehId'])?'/seller/design?viewPage='.$view.'&proId='.$pro['data']['pro_id'].'&dehId='.$Params['dehId']:'/seller/design?viewPage='.$view.'&proId='.$pro['data']['pro_id'].'&designType='.$Params['designType'].'&isChange='.$Params['isChange'].'';
			$url='/seller/design?'.http_build_query($path);
			// die;
			LibFc::Go($url);
			exit();
		}
		if(isset($Params['dehId'])&&LibFc::Int($Params['dehId']))
		{
			//备份还原

			$dehData=$B2cBase->get('sh_design_history',['deh_config'],sprintf(' and deh_shop_id=%d and deh_id=%d',$_SESSION['_shopid'],$Params['dehId']),true);
			if(!count($dehData['data']))
			{
				LibTpl::Error('备份不存在');
				exit();
			}
			$pageConfigAll=json_decode(stripslashes($dehData['data']['deh_config']),true);
		}
		else
		{
			//默认页面
			//店铺页面配置
			if(!file_exists(mvc::$cfg['ROOT'].'shop/'.$_SESSION['_shopid'].'/page.config.php'))
			{
				LibTpl::Error('店铺配置文件不存在');
				exit();
			}
			$pageConfigAll =include(mvc::$cfg['ROOT'].'shop/'.$_SESSION['_shopid'].'/page.config.php');
		}
		$pageConfigAll =include(mvc::$cfg['ROOT'].'shop/'.$_SESSION['_shopid'].'/page.config.php');
		$pageConfing = $pageConfigAll[$view.'/index'];
		//头部和底部公共模块配置
		$pageConfing['modules']['top'] = $pageConfigAll['public']['top'];
		$pageConfing['modules']['foot'] = $pageConfigAll['public']['foot'];
		if($view!=='item')
		{
			$layout=explode('.', explode('/',$pageConfing['layout'])[1])[0];

			$Params['designType']=isset($Params['designType'])?$Params['designType']:$layout;
		}
		// print_r($Params);
		$tplName=empty($pageConfigAll['tplName'])?'tpl01':$pageConfigAll['tplName'];
		// echo $tplName;
		//如果是模板切换
		if($Params['isChange'])
		{
			$fileName=empty($Params['designType'])||$Params['designType']=='121'?'page.config.php':'page_111.config.php';
			//如果店铺的模板默认配置文件不存在，复制一份再引入
			// echo (mvc::$cfg['ROOT'].'home/static/shop/'.$Params['tplName'].$fileName);
			if(file_exists(mvc::$cfg['ROOT'].'home/static/shop/'.$Params['tplName'].'/'.$fileName))
			{
				$defaultOriTpl=include(mvc::$cfg['ROOT'].'home/static/shop/'.$Params['tplName'].'/'.$fileName);//公共模板文件
				$B2cArticle=new B2cArticle();

				if(!empty($defaultOriTpl[$view.'/index']['modules']))
				{
					// print_r($defaultOriTpl[$view.'/index']['modules']);
					foreach ($defaultOriTpl[$view.'/index']['modules'] as $location => $modules)
					{
						foreach ($modules as $k => $v)
						{
							if($v['module']=='custom')
							{
								$tag='id="'.$Params['tplName'].'"';
								$where=sprintf(' and sart_id=%d',$v['config']['articleId']);
								$res=$B2cArticle->get('sh_article',['sart_txt'],$where,true);
								$defaultOriTpl[$view.'/index']['modules'][$location][$k]['config']['articleTxt']=$res['data']['sart_txt'];
								$defaultOriTpl[$view.'/index']['modules'][$location][$k]['config']['articleId']=0;
							}
						}
					}
				}
				$pageOriConfing = $defaultOriTpl[$view.'/index'];

				//头部和底部公共模块配置
				$pageOriConfing['modules']['top'] = $defaultOriTpl['public']['top'];
				$pageOriConfing['modules']['foot'] = $defaultOriTpl['public']['foot'];
			}
			//已有配置处理
			$exitArr=['custom','banner'];
			if(!empty($pageOriConfing['modules']))
			{
				foreach ($pageOriConfing['modules'] as $location => $modules)
				{
					if(!empty($pageConfing['modules'][$location]))
					{
						$modelArr=array_column($pageConfing['modules'][$location], 'module');
						$model=array_column($pageConfing['modules'][$location],null, 'module');
						foreach ($modules as $k => $v)
						{
							// print_r($v);
							if(in_array($v['module'], $modelArr)&&!in_array($v['module'], $exitArr))
							{
								if(!empty($v['viewType'])&&$v['viewType']!=$model[$v['module']]['viewType'])
									continue;
								$pageOriConfing['modules'][$location][$k]=$model[$v['module']];
							}
						}
					}
					// print_r($modelArr);
				}
			}

			$pageConfing=$pageOriConfing;
		}

		$Params['tplName']=empty($Params['tplName'])?$tplName:$Params['tplName'];
		$Params['tplName']=in_array($Params['tplName'],$inArr)?$Params['tplName']:'tpl01';
		mvc::$cfg['tplName']=$Params['tplName'];
		// print_r($Params);
		// $layout=$Params['designType'];
		LibTpl::Set('Params',$Params);
		foreach ($allTplArr as $k=> $v)
		{
			$allTplArr[$k]['active']=$Params['tplName']==$v['tag']?1:0;
			$allTplArr[$k]['url']='/seller/design?'.http_build_query(array_merge($Params,['tplName'=>$v['tag']],['isChange'=>1],['designType'=>$v['layout']]));
		}
		// print_r($allTplArr);
		LibTpl::Set('tplList',$allTplArr);
		// print_r($pageConfing);
		//店铺基本信息、店铺名称、域名等提前加载
		$ShopBase = new ShopBase();
		$shopInfo = $ShopBase->getShopInfo($_SESSION['_shopid']);
		LibTpl::Set('shopInfoData', $shopInfo);
		//系统模快
		$sysModule=include(mvc::$cfg['ROOT_SHOP_SYS'].'module.config.php');
		//加载该店铺的模块数据
		$htmlArr = [];
		$shopCssJs = ['css'=>[], 'js'=>[]];
		foreach ($sysModule as $module)
		{
			$js=isset($module['js'])?$module['js']:[];
			$css=isset($module['css'])?$module['css']:[];
			$shopCssJs['css'] = array_merge($shopCssJs['css'], $css);
			$shopCssJs['js'] = array_merge($shopCssJs['js'], $js);
		}
		if(!empty($pageConfing['modules']))
		{
			foreach($pageConfing['modules'] as $location=>$moduleArr)
			{
				$htmlArr[$location] = [];
				//此位置的所有模块
				foreach($moduleArr as $k=> $moduleConfig)
				{
					$res = $ShopBase->getModuleHtml($_SESSION['_shopid'], $moduleConfig);

					$htmlArr[$location][] = $res['html'];
				}
			}
		}
		// print_r($htmlArr);
		LibTpl::Set('sysModule', $sysModule);
		LibTpl::Set('pageConfing', $pageConfing);
		LibTpl::Set('htmlArr',$htmlArr);

		unset($sysModule['shopInfo'],$sysModule['banner'],$sysModule['menu'],$sysModule['itemInfo'],$sysModule['itemDes'],$sysModule['foot']);
		LibTpl::Set('moduleList',$sysModule);
		$headArr = array(
			'title'=>'店铺装修-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		$this->HEAD_CSSJS['plugin'][] = 'webuploader';
		$this->HEAD_CSSJS['plugin'][] = 'ueditor';
		$this->HEAD_CSSJS['plugin'][] = 'typeahead';
		$this->HEAD_CSSJS['plugin'][] = 'zTree';
		// $this->HEAD_CSSJS['plugin'][] = 'autocomplete';
		//添加图片放大镜
		$this->HEAD_CSSJS['js'][] = 'js/jquery.imagezoom.min.js';
		// $this->HEAD_CSSJS['js'][] = 'js/ueditorImgUpload.js';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('headArr', $headArr);
		switch ($view)
		{
			case 'item':
				LibTpl::Put('/seller/designItem.php');
				break;
			default:
				if($Params['designType']=='121')
				{
					LibTpl::Put();
				}
				else
				{
					LibTpl::Put('/seller/design_111.php');
				}
				break;
		}
	}
	/**
	 * @method    放置拖动模快时获取该模快html
	 * @author 卢
	 * @copyright 2017-09-29
	 */
	public function getModule()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SD00');
		$Params = mvc::$URL_PARAMS;
		$ShopBase = new ShopBase();
		//系统模快
		$sysModule=$sysModuleArr=include(mvc::$cfg['ROOT_SHOP_SYS'].'module.config.php');
		// print_r($sysModuleArr);
		//店铺页面配置
		$pageConfigAll =include(mvc::$cfg['ROOT'].'shop/'.$_SESSION['_shopid'].'/page.config.php');
		if(isset($Params['edit']))
		{
			$config=$_POST;
		}else
		{
			$sysModule[$_POST['tag']]['config']['viewType']=$_POST['nowSize'];
			$config['config']=$sysModule[$_POST['tag']]['config'];
			$config['module']=$_POST['tag'];
		}
		// print_r($config);
		$res = $ShopBase->getModuleHtml($_SESSION['_shopid'], $config);
		$data['status']=true;
		$data['data']['config']=json_encode($config,JSON_UNESCAPED_UNICODE);
		$data['data']['html']=$res['html'];
		LibFc::ajaxJsonEncode($data);
	}
	/**
	 * @method    检查返回模快尺寸
	 * @author 卢
	 * @copyright 2017-09-29
	 */
	public function checkModuleSize()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SD00');
		$Params = mvc::$URL_PARAMS;
		//系统模快
		$sysModule=$sysModuleArr=include(mvc::$cfg['ROOT_SHOP_SYS'].'module.config.php');
		$res['data']=$sysModule[$Params['tag']]['width'];
		$res['status']=true;
		LibFc::ajaxJsonEncode($res);
	}
	/**
	 * @method    ajax获取模快修改弹窗
	 * @author 卢
	 * @copyright 2017-09-29
	 */
	public function getEditModule()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SD00');
		$Params = mvc::$URL_PARAMS;
		$config=json_decode($_POST['config'],true);
		$ShopBase = new ShopBase();
		switch ($config['module']) {
			case 'custom':
				// print_r($config);
				if(isset($config['config']['articleTxt']))
				{
					LibTpl::Set('content',$config['config']['articleTxt']);
				}
				else
				{
					// 去除当前配置信息之中显示的文章详情
					$articleId = (int)$config['config']['articleId'];
					$B2cBase = new B2cBase();
					$articleMsg = $B2cBase->get('sh_article',['sart_txt'],sprintf(" and sart_id=%d and sart_shop_id=%d ",$articleId,$_SESSION['_shopid']),true);
					// print_r($articleMsg['data']['sart_txt']);
					LibTpl::Set('content',$articleMsg['data']['sart_txt']);
				}
				// 取出当前店铺下的所有文章标题
			break;
			case 'banner':
				if($config['config']['type']=='customize')
				{
					$articleId = (int)$config['config']['data']['sartId'];
					$B2cBase = new B2cBase();
					if(isset($config['config']['data']['info']) && !empty($config['config']['data']['info']))
					{

					}
					else
					{
						$re = $B2cBase->Get('sh_article',['sart_txt'],sprintf(" and sart_id=%d and sart_shop_id=%d ",$articleId,$_SESSION['_shopid']),true);
						LibTpl::Set('customData',$re['data']);
						LibTpl::Set('init',true);
					}
				}
				// 取出当前店铺下的所有文章标题
			break;
			case 'menu':
				// 获取当前菜单栏数据
				$B2cBase = new B2cBase();
				$data = array();

				if(!empty($config['config']['sort']))
				{
					foreach($config['config']['sort'] as $arrk=>$arrv)
					{
						if(!empty($arrv))
						{
							foreach($arrv as $sk=>$sv)
							{
								if($sk === 'is_new')
								{
									$data[$arrk]['is_new']=$sv;
								}else if($sk === 'son')
								{
									foreach($sv as $sonk=>$sonv)
									{
										$res = $B2cBase->Get('sh_sort',['sort_name'],sprintf(' and sort_id=%d and sort_shop_id=%d',$sonv,$_SESSION['_shopid']),true);
										$data[$arrk]['son'][$sonv]=$res['data']['sort_name'];
									}
								}else
								{
									$re = $B2cBase->Get('sh_sort',['sort_name'],sprintf(' and sort_id=%d and sort_shop_id=%d',$sv,$_SESSION['_shopid']),true);
									$data[$arrk][$sv]=$re['data']['sort_name'];
								}
							}
						}
					}
				}
				LibTpl::Set('menuData',$data);
				break;
			case 'itemTop':
			case 'itemRecom':
				$B2cShopSort= new B2cShopSort();
				$sortArr=[$config['config']['shopSort']];
				$treeData=$B2cShopSort->getShopSortZtree($_SESSION['_shopid'],$sortArr);
				LibTpl::Set('treeArr',$treeData['data']);
				break;
			default:
				# code...
				break;
		}
		LibTpl::Set('config',$config);
		$res['data']=LibTpl::Fetch('/module/'.$config['module'].'.php');
		$res['status']=true;
		LibFc::ajaxJsonEncode($res);
	}
	/**
	 * @method    推荐模快获取配件列表
	 * @author 卢
	 * @copyright 2017-09-29
	 */
	public function getSellerProduct()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SD00');
		$Params = mvc::$URL_PARAMS;
		$B2cShopSort= new B2cShopSort();
		$B2cProduct= new B2cProduct();
		$B2cBase=new B2cBase();
		$shopId=$_SESSION['_shopid'];
		// print_r($Params);
		$nowPage=isset($Params['page']) ? $Params['page'] : 1;
		$perPage=5;
		$total=0;
		$searchSort=isset($Params['searchSort'])?$Params['searchSort']:0;
		$sortWhere='';
		$res['data']=[];
		$baseWhere=sprintf(' and pro_shop_id=%d and pro_status>0',$shopId);
		$join='';
		//分类
		if($searchSort>0)
		{
			$sortRes=$B2cShopSort->getAllShopSort($shopId);
			$cateRes=$B2cShopSort->getEndSortIds($sortRes['data'],$searchSort);
			$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)));
			}
			else
			{
				$sortWhere=' and pro_id<-1';
			}
		}
		$typeWhere='';
		//关键字
		if(!empty($Params['searchKeyword']))
		{
			$keywordArr=LibFc::keyword($Params['searchKeyword']);
			if(count($keywordArr))
			{
				$keywordStr="'".implode("','",$keywordArr)."'";
				// $keywordWhere=sprintf(' and key_txt in(%s)',$keywordStr);
				// $keywordProData=$B2cProduct->get('bc_keyword right join bc_product_keyword on prk_key_id=key_id',['prk_pro_id'],$keywordWhere);
				$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)  group by prk_pro_id having count(*)=%d",$keywordStr, count($keywordArr)));
			}
			// if(!count($keywordArr)||!count($keywordProData['data']))
			// {
			// 	//搜索为空，返回
			// 	$typeWhere=' and pro_id<-1';
			// }
			// else
			// {
			// 	$keywordPro=array_unique(array_column($keywordProData['data'],'prk_pro_id'));
			// 	$typeWhere=count($keywordPro)?sprintf(" and pro_id in (%s)",implode(',',$keywordPro)):'';
			// }
		}
		//价格
		$minPriceWhere=($Params['searchMinPrice']&&!empty($Params['searchMinPrice']))?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['searchMinPrice']):'';
		$maxPriceWhere=($Params['searchMaxPrice']&&!empty($Params['searchMaxPrice']))?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['searchMaxPrice']):'';
		$where=$baseWhere.$sortWhere.$minPriceWhere.$maxPriceWhere.$typeWhere;

		// echo $where;
		// die;
		$totalData=$B2cProduct->get('bc_product',['count(*) count'],$where,true);
		// print_r($totalData);
		$aTotal=$total=$totalData['data']['count'];
		$totalPage=ceil($total/$perPage);
		// echo $Params['tag'];
		if(isset($Params['tag'])&&$Params['tag']=='recomded')
		{
			if(!empty($Params['proId']))
			{
				$recomWhere=sprintf(' and pro_id in(%s)',$Params['proId']);
				$where=$baseWhere.$recomWhere;
				$totalPage=ceil(count(explode(',', $Params['proId']))/$perPage);
				$total=count(explode(',', $Params['proId']));
			}
			else
			{
				$where=$baseWhere.' and pro_id<-1';
			}
		}
		$res=$B2cProduct->getProductList($nowPage,$perPage,$total,'pro_sold_count desc,pro_shop_id,pro_part_id',$where,$join);
		// end:
		//集中取图片
		if(count($res['data']))
		{
			$proId=array_column($res['data'],'pro_id');
			$proPic=$B2cProduct->getProductPic($proId, false);
			foreach ($res['data'] as $k => $v)
			{
				$res['data'][$k]=isset($proPic['data'][$v['pro_id']][0])?array_merge($res['data'][$k],$proPic['data'][$v['pro_id']][0]):$res['data'][$k];
			}
		}
		// print_r($res);

		$proArr=!empty($Params['proId'])?explode(',',$Params['proId']):[];
		LibTpl::Set('proId',$proArr);
		LibTpl::Set('tag',$Params['tag']);
		unset($Params['page'],$Params['isAjax'],$Params['proId']);
		LibTpl::Set('url',http_build_query($Params));
		LibTpl::Set('nowPage',$nowPage);
		LibTpl::Set('totalPage',$totalPage);
		LibTpl::Set('total',$aTotal);
		LibTpl::Set('proList',$res['data']);
		$res['data']=LibTpl::Fetch('/module/itemRecomProduct.php');
		$res['status']=true;
		LibFc::ajaxJsonEncode($res);
	}
	/**
	 * @method    店铺装修自定义内容存数据库
	 * @author     廖
	 * @copyright 2017-10-10
	 * @return
	 */
	public function editorCus()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SD00');
		$B2cBase = new B2cBase();
		if(LibFc::Int($_POST['id']) && $_POST['id']!='0')
		{
			$re = $B2cBase->Set('sh_article',['sart_txt'=>LibFc::Escape($_POST['data']),'sart_last_time'=>time()],sprintf(' and sart_id=%d and sart_shop_id=%d',$_POST['id'],$_SESSION['_shopid']),['sart_txt']);
			LibFc::ajaxJsonEncode($re);
		}
		else if($_POST['id']=='0')
		{
			$newId = $B2cBase->Add('sh_article',['sart_shop_id'=>$_SESSION['_shopid'],'sart_name'=>LibFc::Escape($_POST['name']),'sart_txt'=>LibFc::Escape($_POST['data']),'sart_add_time'=>time()],['sart_txt']);
			LibFc::ajaxJsonEncode($newId);
		}
		LibFc::ajaxJsonEncode(['status'=>false,'data'=>'seller/editorCus 参数不正确!']);
	}
	/**
	 * @method    发布装修
	 * @author 卢
	 * @copyright 2017-11-23
	 */
	public function publishDesign()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SD00');
		$data=['status'=>false,'data'=>'发布失败，请稍后重试！'];
		if(count($_POST))
		{
			// print_r($_POST);
			// die;
			$inArr=['index','search','item'];
			$view=trim($_POST['view-page']);
			if(!in_array($view, $inArr))
			{
				LibFc::ajaxJsonEncode($data);
			}
			$B2cShop= new B2cShop();
			$res=$B2cShop->editDesignConfig($_SESSION['_shopid'],$view,$_POST);
			// print_r($res);
			// die;
			$dehInfo['bakName']='站点发布自动备份';
			$dehInfo['bakRemark']='站点发布自动备份';
			$result=$B2cShop->addShopDesign($res['data'],$_SESSION['_shopid'],$view,$dehInfo);
			$orPageConfig=require(mvc::$cfg['ROOT'].'shop/'.$_SESSION['_shopid'].'/page.config.php');
			if(!empty($_POST['change']))
			{
				$fileName=(!empty($_POST['type'])&&$_POST['type']=='111')?'page_111.config.php':'page.config.php';
				$pageConfig=require(mvc::$cfg['ROOT'].'home/static/shop/'.$_POST['tplName'].'/'.$fileName);
				$B2cArticle=new B2cArticle();
				$exitArr=['custom','banner'];
				foreach ($inArr as $v)
				{
					if($view==$v) continue;
					// 其他页面处理
					foreach ($pageConfig[$v.'/index']['modules'] as $location => $modules)
					{
						foreach ($modules as $k => $content)
						{
							if($content['module']=='custom')
							{
								$re=$B2cArticle->copyArtFromConfig([$content['config']['articleId']],$_SESSION['_shopid']);
								// print_r($re);
								$aid=$re['data'][0];
								$pageConfig[$v.'/index']['modules'][$location][$k]['config']['articleId']=$aid;
							}
						}
					}
					//已有的数据

					if(!empty($pageConfig[$v.'/index']['modules']))
					{
						//从旧文件中查找已有模快
						foreach ($pageConfig[$v.'/index']['modules'] as $location => $modules)
						{
							if(!empty($orPageConfig[$v.'/index']['modules'][$location]))
							{
								$modelArr=array_column($orPageConfig[$v.'/index']['modules'][$location], 'module');
								$model=array_column($orPageConfig[$v.'/index']['modules'][$location],null, 'module');
								foreach ($modules as $k => $content)
								{
									if(in_array($content['module'], $modelArr)&&!in_array($content['module'], $exitArr))
									{
										if(!empty($content['viewType'])&&$content['viewType']!=$model[$content['module']]['viewType'])
											continue;
										$pageConfig[$v.'/index']['modules'][$location][$k]=$model[$content['module']];
									}
								}
							}
							// print_r($modelArr);
						}
					}
					$res['data'][$v.'/index']=$pageConfig[$v.'/index'];
				}
				// die;
			}else
			{
				$pageConfig=require(mvc::$cfg['ROOT'].'shop/'.$_SESSION['_shopid'].'/page.config.php');
				foreach ($inArr as $v)
				{
					if($view==$v) continue;
					$res['data'][$v.'/index']=$pageConfig[$v.'/index'];
				}
			}
			//原来的备份

			LibFc::ArraySave($orPageConfig,mvc::$cfg['ROOT'].'shop/'.$_SESSION['_shopid'].'/orPage.config.php');
			// die;
			LibFc::ArraySave($res['data'],mvc::$cfg['ROOT'].'shop/'.$_SESSION['_shopid'].'/page.config.php');
			$data=['status'=>true,'data'=>'/seller/design?viewPage='.$view];
		}
		LibFc::ajaxJsonEncode($data);
		// LibFc::Go('/seller/design?viewPage='.$view);
	}
	/**
	 * @method    获取装修备份
	 * @author 卢
	 * @copyright 2017-11-23
	 */
	public function getBakDesignTpl()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SD00');
		$Params = mvc::$URL_PARAMS;
		$B2cShop= new B2cShop();
		if(!empty($Params['dehPage']))
		{
			//获取记录
			$dehData=$B2cShop->get('sh_design_history',['deh_id','deh_page','deh_config','deh_atime','deh_name','deh_remark'],sprintf(" and deh_shop_id=%d and deh_page='%s' order by deh_atime desc",$_SESSION['_shopid'],LibFc::Escape($Params['dehPage'])));
			if(count($dehData['data']))
			{
				LibTpl::Set('list',$dehData['data']);
			}
			$data=LibTpl::Fetch('/module/bakDesignTpl.php');
			LibFc::ajaxJsonEncode(['status'=>true,'data'=>$data]);
		}
	}
	/**
	 * @method    添加装修备份
	 * @author 卢
	 * @copyright 2017-11-23
	 */
	public function bakDesign()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SD00');
		$view=$_POST['view-page'];
		$dehInfo['bakName']	=$_POST['bakName'];
		$dehInfo['bakRemark']	=$_POST['bakRemark'];
		$B2cShop= new B2cShop();
		$res=$B2cShop->editDesignConfig($_SESSION['_shopid'],$view,$_POST);
		$result=$B2cShop->addShopDesign($res['data'],$_SESSION['_shopid'],$view,$dehInfo);
		LibFc::ajaxJsonEncode($result);
		// print_r($data);

	}
	/**
	 * @method    店铺装修自定义css
	 * @author 卢
	 * @copyright 2017-11-29
	 */
	public function editShopStyle()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SD00');
		if($_SERVER['REQUEST_METHOD']=='POST')
		{
			file_put_contents(mvc::$cfg['ROOT'].'shop/'.$_SESSION['_shopid'].'/static/css/shopSelf.css',$_POST['shopStyle']);
			$res=['status'=>true,'data'=>true];
		}
		else
		{
			$shopStyle='';
			if(file_exists(mvc::$cfg['ROOT'].'shop/'.$_SESSION['_shopid'].'/static/css/shopSelf.css'))
			{
				$shopStyle =file_get_contents(mvc::$cfg['ROOT'].'shop/'.$_SESSION['_shopid'].'/static/css/shopSelf.css');
			}
			$res=['status'=>true,'data'=>$shopStyle];
		}
		LibFc::ajaxJsonEncode($res);
	}

	/**
	 * @method   ajax获取所有的店铺分类
	 * @author xu
	 * @copyright 2017-10-10
	 */
	public function getMenuEdit()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		// 获取所有的被选中的菜单ID的数值并且传递进去
		$menuIdSel = array();
		$sonMenuIdSel = array();
		$allLink = array();
		if(!empty($_POST['config']['sort']))
		{
			foreach ($_POST['config']['sort'] as $key=>$value)
			{
				if(!empty($value))
				{
					foreach($value as $sk=>$sv)
					{
						if($sk==='son')
						{
							foreach ($sv as $sonv)
							{
								$menuIdSel[]=$sonv;
							}
						}else if($sk ==='is_new')
						{
							$allLink[$key]=$sv;
						}else
						{
							$menuIdSel[]=$sv;
						}
					}
				}
			}
		}
		$menuIdSel = LibTpl::Set('menuIdSel',$menuIdSel);
		// $menuIdSel = LibTpl::Set('sonMenuIdSel',$sonMenuIdSel);
		LibTpl::Set('allLink',$allLink);
		// 获取当前菜单栏数据
		$B2cShopSort = new B2cShopSort();
		$data = array();
		$allSort = $B2cShopSort->getShopSort($_SESSION['_shopid']);
		$allSort = $allSort['data'];
		LibTpl::Set('allSort',$allSort);
		$data=LibTpl::Fetch('/seller/getMenuEdit.php');
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$data]);
	}

	/**
	 * @method   ajax获取编辑的结果
	 * @author xu
	 * @copyright 2017-10-10
	 */
	public function getEditRes()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		// 获取当前菜单栏数据
		// 参数过滤
		$idstr = $_POST['idstr'];
		$idstr = explode(',',$idstr);
		$newidstr = array();
		foreach ($idstr as $value) {
			$newidstr[] = (int)$value;
		}
		$link = $_POST['link_array'];
		$newlink = array();
		if(!empty($link)){
			foreach ($link as $key => $value) {
				$newlink[] = array('name'=>LibFc::Escape($value[0]),'url'=>LibFc::Escape($value[1]));
			}
		}
		$order = $_POST['order'];

		// 获取旧链接
		$oldlink = $_POST['oldlink'];
		// 获取旧连接
		$oldlink = unserialize($oldlink);
		// 获取新增的链接

		// 获取删除链接的
		$B2cShopSort = new B2cShopSort();
		$data = array();
		$allSort = $B2cShopSort->getShopSortLimit($_SESSION['_shopid'],$idstr);
		$allSort = $allSort['data'];
		LibTpl::Set('allSort',$allSort);
		LibTpl::Set('newlink',$newlink);
		$data=LibTpl::Fetch('/seller/getEditRes.php');
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$data]);
	}

	/**
	 * @method   ajax保存自定义的文章
	 * @author xu
	 * @copyright 2017-10-10
	 */
	public function saveCustomArticle()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SD00');
		// 获取参数
		if(!empty($_POST['sart_id']))
		{
			$sart_id = $_POST['sart_id'];
			if(!LibFc::Int($sart_id))
			{
				$msg = array('status'=>false,'data'=>'参数错误！','code'=>0);
				LibFc::ajaxJsonEncode($msg);
			}
		}
		else
		{
			$sart_id = '';
		}
		// 过滤数据
		$sart_name = LibFc::Escape($_POST['sart_name']);
		$sart_txt = LibFc::Escape($_POST['sart_txt']);
		$B2cBase = new B2cBase();
		// 保存文章进数据库
		if(empty($sart_id))
		{
			$newdata = array(
				'sart_txt' => $sart_txt,
				'sart_name' => $sart_name,
				'sart_shop_id' => $_SESSION['_shopid'],
				'sart_add_time'=>time()
			);
			$data = $B2cBase->add('sh_article',$newdata);
			$sart_id = $data['data'];
		}
		else
		{
			$editdata = array(
				'sart_name'=>$sart_name,
				'sart_txt'=>$sart_txt,
				'sart_shop_id' => $_SESSION['_shopid'],
				'sart_last_time' => time()
			);
			$B2cBase->set('sh_article',$editdata,sprintf(" and sart_id=%d ",$sart_id));
		}
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$sart_id]);
	}


	/**
	 * @method    配件套餐
	 * @author     xu
	 * @copyright 2017-10-18
	 */
	public function proPackTpl()
	{
		// 必须已经开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('PP04');
		// 获取所有本店铺的配件套餐
		$Params = mvc::$URL_PARAMS;
		$NowPage = isset($Params['page']) && $Params['page'] > 0 ? (int) $Params['page']:1;
		// 获取当前店铺套餐总数
		$B2cBase = new B2cBase();
		$where = sprintf(" and prpa_shop_id=%d ",$_SESSION['_shopid']);
		$Res = $B2cBase->get('bc_product_pack', ['count(1) count'], $where, true);
		$Total = $Res['data']['count'];
		$PerPage = 20;
		if($Total>0)
		{
			// 获取当前店铺的套餐信息
			$Res = $B2cBase->get('bc_product_pack', ['*'], $where.sprintf(" limit %d, %d",($NowPage-1)*$PerPage, $PerPage));
			$bc_product_pack = $Res['data'];
			// 获取当前店铺的运费模板
			$Res = $B2cBase->get('sh_freight_tpl',['frt_id','frt_name'],sprintf(" and frt_shop_id=%d ",$_SESSION['_shopid']));
			$FREIGHT = $Res['data'];
			foreach ($bc_product_pack as $k=>$v)
			{
				foreach ($FREIGHT as $vv)
				{
					if($vv['frt_id']==$v['prpa_frt_id'])
					{
						$bc_product_pack[$k]['frt_name'] = $vv['frt_name'];
					}
				}
			}
			LibTpl::Set('dataArr', $bc_product_pack);
		}
		$Page = LibPage::Show($Total, $PerPage);
		LibTpl::Set('Page', $Page);
		$headArr = [
			'title'=>'配件套餐-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','proPackTpl');
		LibTpl::Put();
	}

	/**
	 * @method    配件组合
	 * @author    廖
	 * @copyright 2017-12-22
	 */
	public function group()
	{
		// 必须已经开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('PG04');
		$NowPage = isset($Params['page']) && $Params['page'] > 0 ? (int) $Params['page']:1;
		// 获取当前店铺套餐总数
		$B2cBase = new B2cBase();
		$where = sprintf(" and prg_shop_id=%d ",$_SESSION['_shopid']);
		$Res = $B2cBase->get('bc_product_group', ['count(*) count'], $where, true);
		$Total = $Res['data']['count'];
		$PerPage = 20;
		if($Total>0)
		{
			// 获取当前店铺的套餐信息
			$Res = $B2cBase->get('bc_product_group', ['*'], $where.sprintf(" limit %d, %d",($NowPage-1)*$PerPage, $PerPage));
			LibTpl::Set('dataArr', $Res['data']);
		}
		$Page = LibPage::Show($Total, $PerPage);
		LibTpl::Set('Page', $Page);
		$headArr = [
			'title'=>'配件组合-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','group');
		LibTpl::Put();
	}
	/**
	 * @method    添加配件套餐
	 * @author    liao
	 * @copyright 2017-12-22
	 */
	public function addGroup()
	{
		// 必须已经开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;

		$B2cPack = new B2cPack();
		//保存新组合
		if(!empty($_POST['group']))
		{
			$OthCheck->rule('PG01');
			$dataArr['group'] = $_POST['group'];
			$dataArr['prg_name'] = $_POST['groupName'];
			$dataArr['prg_status'] = $_POST['groupStatus']=='1'?'1':'0';
			$res = $B2cPack->saveGroup($_SESSION['_shopid'],$_POST['gId'],$dataArr,$_POST['order']);
			if($res['status'])
			{
				LibFc::Go('/seller/group');
			}
		}
		// SQLSTATE[42601]: Syntax error: 7 错误: 语法错误 在 "prg_id" 或附近的 LINE 1: ...bc_product_group where 1=1 and prg_shop_id=223009 prg_id =38 ^ [SQL]select count(*) count from bc_product_group where 1=1 and prg_shop_id=223009 prg_id =38
		//编辑组合
		if(LibFc::Int($Params['gId']))
		{
			$OthCheck->rule('PG02');
			$order = 'edit';
			$res = $B2cPack->getGroup($_SESSION['_shopid'],$Params['gId']);
			LibTpl::Set('gId', $Params['gId']);
			LibTpl::Set('name', $res['data'][0]['prg_name']);
			LibTpl::Set('status', $res['data'][0]['prg_status']);
			LibTpl::Set('dataArr', $res['data']);
		}else
		{
			$order = 'add';
			$OthCheck->rule('PG01');
		}
		LibTpl::Set('order',$order);
		$headArr = [
			'title'=>'添加配件组合-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','group');
		LibTpl::Put();
	}
	/**
	 * @method 点击获取店铺的配件
	 * @author     廖
	 * @copyright 2017-12/22
	 */
	public function clickToGroupGods()
	{
		// 必须已经开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();

		//获取当前店铺的所有分类
		$B2cShopSort = new B2cShopSort();
		$res = $B2cShopSort->getAllShopSort($_SESSION['_shopid']);
		LibTpl::Set('allShopSort',$res['data']);

		$B2cBase = new B2cBase();
		// 获取页码
		$NowPage = isset($_POST['page'])?(int)$_POST['page']:1;

		// 获取关键词
		$keyword = isset($_POST['keyword'])?LibFc::Escape($_POST['keyword']):'';

		//已经添加的配件
		$hasChosedIdArr = !empty($_POST['allProId']) ? array_filter($_POST['allProId'],'LibFc::Int') : [];
		if (!empty($hasChosedIdArr) && count($hasChosedIdArr)>50)
		{
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'只能添加 50 个配件以下的组合！']);
			exit();
		}
		$hasChosed = !empty($hasChosedIdArr) ? sprintf('and pro_id not in(%s)',implode(',', $hasChosedIdArr)) : '';

		//基本限制条件
		$basewhere = sprintf(" and pro_shop_id=%d and pro_count>0 and pro_status>0 and pro_id not in(select prgl_pro_id from bc_product_group left join bc_product_group_link on prg_id=prgl_prg_id where prg_shop_id=%d) %s ",$_SESSION['_shopid'],$_SESSION['_shopid'],$hasChosed);

		// 根据店铺分类
		$sortStr = '';
		$sortWhere = '';
		if(LibFc::Int($_POST['shopSortId']))
		{
			LibTpl::Set('shopSortId',$_POST['shopSortId']);

			// 获取所有该类以及其子类
			$sortStr = 'left join bc_product_sort on prs_pro_id=pro_id';
			$sortWhere = sprintf(' and (prs_sort_id in(select sot_sort_id from sh_sort_tree where sot_psort_id=%d) or prs_sort_id=%d)',$_POST['shopSortId'],$_POST['shopSortId']);
		}

		// 根据关键词
		$keywordStr = '';
		$keywordWhere = '';
		if(!empty($keyword))
		{
			LibTpl::Set('keyword',$keyword);
			$B2cKeyword = new B2cKeyword();
			$res = $B2cKeyword->getKeywordKeyIds(array($keyword));

			// 获取当前关键字下的配件
			$keywordWhere = !empty($res['data'])?sprintf(" and (prk_key_id in (%s) or pro_name like '%%%s%%')",implode(',', $res['data']),$keyword):sprintf(" and pro_name like '%%%s%%'",$keyword);
			$keywordStr = 'left join bc_product_keyword on prk_pro_id=pro_id';
		}

		// 计算总数
		$baseTable = sprintf('bc_product %s %s',$sortStr,$keywordStr);
		$Total = $B2cBase->get($baseTable,['count(distinct(pro_id)) count'],$basewhere.$sortWhere.$keywordWhere,true);
		$Total = $Total['data']['count'];

		$PerPage = 5;
		if($Total>0)
		{
			// 获取当前店铺的套餐信息
			$twhere = sprintf(" %s order by pro_id asc limit %d,%d",$basewhere.$sortWhere.$keywordWhere,($NowPage-1)*$PerPage, $PerPage);
			$Res = $B2cBase->get($baseTable, ['distinct(pro_id),pro_name,pro_sale_price,pro_count'], $twhere);

			$bc_product_MSG = $Res['data'];
			// 获取所有的pro_id
			$allProId = array_column($Res['data'], 'pro_id');
			// 获取该配件的主图
			$B2cProduct = new B2cProduct();
			$res = $B2cProduct->getProductPic($allProId);
			foreach ($Res['data'] as $key => $value)
			{
				if(!empty($res['data'][$value['pro_id']][0]))
				{
					$Res['data'][$key] = array_merge($value,$res['data'][$value['pro_id']][0]);
				}
			}
			LibTpl::Set('proMsg',$Res['data']);
		}
		$Page = $this->minePackPage($Total,$PerPage,$NowPage);
		LibTpl::Set('Page', $Page);
		LibTpl::Set('nowPage', $NowPage);
		// 渲染模板传递过去
		$data = LibTpl::Fetch('/seller/clickToGroupGods.php');
		$msg = array('status'=>true,'data'=>$data);
		LibFc::ajaxJsonEncode($msg);
	}
	/**
	 * @method    删除配件组合
	 * @author    liao
	 * @copyright 2017-12-22
	 */
	public function delThisProGroup()
	{
		// 必须已经开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('PG03');
		//获取表单数据,执行入库和修改操作
		$res = array('status'=>false,'data'=>'参数错误！');
		if(LibFc::Int($_POST['id']))
		{
			// 调用接口删除
			$B2cPack = new B2cPack();
			$res = $B2cPack->delGroup($_POST['id']);
		}
		LibFc::ajaxJsonEncode($res);
	}

	/**
	 * @method    添加配件套餐
	 * @author     xu
	 * @copyright 2017-10-18
	 */
	public function addProPackTpl()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('PP01');
		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();

		// 数量限制
		$res = $B2cBase->get('bc_product_pack',['count(*) packsum'],sprintf(" and prpa_shop_id=%d ",$_SESSION['_shopid']));
		$res = current($res['data']);
		if($res['packsum']>=50) LibTpl::Error('店铺套餐数量不得多于50个！','/seller/proPackTpl');


		if($_SERVER['REQUEST_METHOD']=="POST")
		{
			// 新增
			$pack = $_POST;
			$pack['shopId'] = $_SESSION['_shopid'];
			$pro = array_filter($pack['proId'],"LibFc::Int");
			//接口
			$B2cProduct = new B2cProduct();
			$res = $B2cProduct->setProductPack($pack,$pro);
			LibFc::Go('/seller/editProPackTpl?id='.$res['data']);
		}

		// 运费模板
		$res = $B2cBase->get('sh_freight_tpl',['frt_id','frt_name'],sprintf(" and frt_shop_id=%d ",$_SESSION['_shopid']));
		LibTpl::Set('freight',$res['data']);

		// meta
		$headArr = [
			'title'=>'添加配件套餐-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		$this->HEAD_CSSJS['plugin'][] = 'datetimepicker';
		$this->HEAD_CSSJS['plugin'][] = 'jqueryValidation';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','proPackTpl');
		LibTpl::Set('actmsg','新增');
		LibTpl::Put('seller/editProPackTpl.php');
	}

	/**
	 * @method    删除配件套餐
	 * @author     xu
	 * @copyright 2017-10-19
	 */
	public function delThisProPack()
	{
		// 必须已经开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('PP03');
		// 参数
		if(empty($_POST['id']) || !LibFc::Int($prpaId = $_POST['id']))
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		// 执行
		$B2cProduct = new B2cProduct();
		$B2cProduct->delProductPack($prpaId,$_SESSION['_shopid']);
		// 返回
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'删除成功！']);
	}

	/**
	 * @method    编辑配件套餐
	 * @author     xu
	 * @copyright 2017-10-19
	 */
	public function editProPackTpl()
	{
		// 必须已经开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('PP02');
		$Params = mvc::$URL_PARAMS;
		$B2cProduct = new B2cProduct();
		$B2cBase = new B2cBase();
		// 参数
		$prpaId = $Params['id'];
		if(!LibFc::Int($prpaId)) LibFc::Go('/seller/proPackTpl');


		if($_SERVER['REQUEST_METHOD']=="POST")
		{
			// 编辑
			$pack = $_POST;
			$pack['shopId'] = $_SESSION['_shopid'];
			$pack['prpaId'] = $prpaId;
			$pro = array_filter($pack['proId'],"LibFc::Int");
			//接口
			$B2cProduct = new B2cProduct();
			$B2cProduct->setProductPack($pack,$pro);
		}

		// 获取
		$res = $B2cProduct->getProductPack($prpaId,$_SESSION['_shopid']);
		LibTpl::Set('pack', $res['data']);

		// 运费模板
		$res = $B2cBase->get('sh_freight_tpl',['frt_id','frt_name'],sprintf(" and frt_shop_id=%d ",$_SESSION['_shopid']));
		LibTpl::Set('freight',$res['data']);

		// meta
		$headArr = [
			'title'=>'添加配件套餐-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		$this->HEAD_CSSJS['plugin'][] = 'jqueryValidation';
		$this->HEAD_CSSJS['plugin'][] = 'datetimepicker';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','proPackTpl');
		LibTpl::Set('actmsg','编辑');
		LibTpl::Put();
	}


	/**
	 * @method 点击获取店铺的配件
	 * @author     xu
	 * @copyright 2017-10-19
	 */
	public function clickToChoiceGods()
	{
		// 必须已经开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();

		// 获取页码
		$NowPage = isset($_POST['page'])?(int)$_POST['page']:1;
		$PerPage = 5;
		$where = sprintf(" and pro_shop_id=%d and pro_count>0 and pro_status>0",$_SESSION['_shopid']);

		// 关键词
		if(!empty($keyword = LibFc::Escape($_POST['keyword'])))
		{
			LibTpl::Set('keyword',$keyword);
			$B2cKeyword = new B2cKeyword();
			$res = $B2cKeyword->getKeywordKeyIds(array($keyword));
			// 获取当前key_id下面的god_id
			if(!empty($res['data']))
			{
				$res = $B2cBase->get(' bc_product_keyword left join bc_product on prk_pro_id=pro_id ',['pro_id'],sprintf(" and prk_key_id in (%s) and pro_shop_id=%d or pro_name like '%%%s%%'",implode(',', $res['data']),$_SESSION['_shopid'] , $keyword));
				$allId = array_column($res['data'], 'pro_id');
				if(!empty($allId)) $where .= sprintf(" and pro_id in (%s) ",implode(',',$allId));
			}
		}

		// 店铺分类
		if(!empty($_POST['shopSortId']) && ($shopSortId = LibFc::Int($_POST['shopSortId'])))
		{
			LibTpl::Set('shopSortId',$shopSortId);
			$res=$B2cBase->get('sh_sort_tree',['sot_sort_id'],' and sot_psort_id='.$shopSortId);
			$allSortId = array_column($res['data'], 'sot_sort_id');
			$allSortId[] = $shopSortId;
			if(!empty($allSortId)) $where .= sprintf(" and prs_sort_id in (%s) ",implode(',', $allSortId));
		}

		// 排除被选中的ID
		if(!empty($_POST['allProId']))
		{
			$checkProId = array_filter($_POST['allProId'],'LibFc::Int');
			if(!empty($checkProId)) $where .= sprintf(" and pro_id not in (%s) ",implode(',',$checkProId));
		}


		if(isset($allId) && empty($allId))
		{
			// 若无匹配关键字的记录
			$Total = 0;
		}
		else
		{
			// 查询是否有记录
			$table = empty($shopSortId)?'bc_product':'bc_product left join bc_product_sort on prs_pro_id=pro_id';
			$res = $B2cBase->get($table, ['count(1) count'], $where, true);
			$Total = $res['data']['count'];
		}

		if($Total>0)
		{
			// 若无分类筛选就不要连表，有时候一个商品属于两个分类
			if(!empty($shopSortId))
			{
				$table = 'bc_product left join bc_product_sort on prs_pro_id=pro_id';
			}
			else
			{
				$table = 'bc_product';
			}

			$res = $B2cBase->get($table, ['*'], $where.sprintf(" limit %d,%d",($NowPage-1)*$PerPage, $PerPage));
			$products = $res['data'];
			// 获取所有的pro_id
			$proId = array_column($res['data'], 'pro_id');

			// 获取该配件的主图
			$B2cProduct = new B2cProduct();
			$res = $B2cProduct->getProductPic($proId);
			$res = $res['data'];

			$proMsg = array();

			foreach ($products as $v) {
				// 有时候图片记录为空
				$pic =  isset($res[$v['pro_id']]) ? current($res[$v['pro_id']]):array();
				// 更新值
				$proMsg[$v['pro_id']] = array_merge($v,$pic);
			}

			LibTpl::Set('proMsg',$proMsg);
		}

		// 获取分页
		$Page = $this->minePackPage($Total,$PerPage,$NowPage);
		LibTpl::Set('Page', $Page);

		//获取当前店铺的所有分类
		$B2cShopSort = new B2cShopSort();
		$res = $B2cShopSort->getAllShopSort($_SESSION['_shopid']);
		LibTpl::Set('allShopSort',$res['data']);

		// 渲染模板传递过去
		$data = LibTpl::Fetch('/seller/clickToChoiceGods.php');
		$msg = array('status'=>true,'data'=>$data);
		LibFc::ajaxJsonEncode($msg);
	}

	/**
	 * @method 配件套餐自定义的页码
	 * @author xu
	 * @copyright 2017-10-19
	 */
	function minePackPage($Total = 0, $PerPage = 10,$NowPage)
	{
		$TotalPage = ceil($Total/$PerPage);
		// 获取当前页码,现在当前页码全部由参数传递过来
		$NowPage = $NowPage > $TotalPage? $TotalPage: $NowPage;
		$prePage = $NowPage-1;
		$nxtPage = $NowPage+1;
		// 拼接URL参数
		$PageStr = '';
		if($TotalPage > 0)
		{
			$PageStr .= $NowPage == 1 ? '<li class="page-disabled"><a href="javascript:">上一页</a></li>' : '<li><a href="javascript:;" onclick="jumpPackPage('.$prePage.')">上一页</a></li>';
		}
		if($TotalPage <= 7)
		{
			for($I = 1; $I <=$TotalPage; $I++)
			{
				if($NowPage == $I)
				{
					$PageStr .= '<li class="page-choose"><a href="javascript:">'.$I.'</a></li>';
				}
				else
				{
					$PageStr .= '<li><a href="javascript:;" onclick="jumpPackPage('.$I.')">'.$I.'</a></li>';//'.self::ReplaceUrl($Url, $I).'
				}
			}
		}
		else
		{//上一页 5 6 7 8 9 10 11 12 下一页
			//计算开始页
			if($NowPage < 4)
			{//[1] [2] 3 [4]...
				$BPage = 1;
			}
			else if(($TotalPage-$NowPage) < 3)
			{
				$BPage = $NowPage-6+($TotalPage-$NowPage);
			}
			else
			{
				$BPage = $NowPage-3;
			}
			for($I = $BPage; $I < $BPage+7; $I++)
			{
				if($I > $TotalPage)
				{
					break;
				}
				if($NowPage == $I)
				{
					$PageStr .= '<li class="page-choose"><a href="javascript:">'.$I.'</a></li>';
				}
				else
				{
					$PageStr .= '<li><a href="javascript:;" onclick="jumpPackPage('.$I.')">'.$I.'</a></li>';//'.self::ReplaceUrl($Url, $I).'
				}
			}
		}
		if($TotalPage > 0)
		{
			$PageStr .= $NowPage == $TotalPage ? '<li class="page-disabled"><a href="javascript:">下一页</a></li>' : '<li><a href="javascript:;" onclick="jumpOutherPage('.$nxtPage.')">下一页</a></li>';
		}
		//跳转到'.self::ReplaceUrl($Url, $NowPage + 1).'
		$GoHtml = '';
		if($TotalPage > 10)
		{
			$GoHtml .= '<div class="page-go">共<b>'.$TotalPage.'</b>页，到第 <input type="text" id="fastJumpOutherPage" class="to_page_txt form-control" size="2" base="" value="'.$NowPage.'"/> 页 <button type="button" onclick="fastJumpOutherPage()" class="btn btn-info btn-sm to_page_btn">跳转</button ></div>';
		}

		return '<div class="page-box"><ul class="page">'.$PageStr.'</ul>'.$GoHtml.'</div>';
	}
	/**
	 * @method    子账号管理
	 * @author 卢
	 * @copyright 2017-10-20
	 */
	public function account()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		// 权限
		$OthCheck->rule('SA01');
		$canDep=[];
		if($OthCheck->rule('SA05',false)) $canDep['add']=true;
		if($OthCheck->rule('SA06',false)) $canDep['edit']=true;
		if($OthCheck->rule('SA07',false)) $canDep['del']=true;
		LibTpl::Set('canDep', $canDep);

		$Params = mvc::$URL_PARAMS;
		$B2cShop=new B2cShop();
		//获取所有部门
		$departRes=$B2cShop->get('sh_worker_department',['wod_id','wod_pid','wod_name','wod_seq'],sprintf(' and wod_shop_id=%d order by wod_seq asc',$_SESSION['_shopid']));
		LibTpl::Set('departArr',$departRes['data']);
		//计算职员总数
		$totalData = $B2cShop->get('sh_worker',['count(*) count'],' and wor_shop_id='.$_SESSION['_shopid'],true);
		$total = $totalData['data']['count'];
		if($total>0)
		{
			$worStatus = array(1=>'启用',0=>'停用',-1=>'离职');
			$worColor = array(0=>'orange',1=>'blue',-1=>'red');
			LibTpl::Set('worColor', $worColor);
			LibTpl::Set('worStatus', $worStatus);

			//职位列表
			$res = $B2cShop->get('sh_worker_job',['woj_id','woj_name'],sprintf(' and woj_shop_id=%d order by woj_seq asc',$_SESSION['_shopid']));
			$jobArr = array_column($res['data'], 'woj_name' ,'woj_id');
			LibTpl::Set('jobList',$jobArr);
			//根据部门筛选
			$departwhere = '';
			if(!empty($Params['depart']) && LibFc::Int($Params['depart']))
			{
				$departwhere = sprintf(' and wod_id =%d',$Params['depart']);
				LibTpl::Set('depart',$Params['depart']);
			}
			//职位状态筛选
			$statustwhere = '';
			if(isset($Params['status']) && $Params['status'] !='')
			{
				if(array_key_exists($Params['status'], $worStatus)) $statustwhere = ' and wor_status='.$Params['status'];
				LibTpl::Set('status', $Params['status']);
			}
			//职位筛选
			$jobwhere = '';
			if(!empty($Params['job']) && LibFc::Int($Params['job']))
			{
				if(array_key_exists($Params['job'], $jobArr))
				{
					$jobwhere = ' and woj_id='.$Params['job'];
				}
				LibTpl::Set('job', $Params['job']);
			}
			$baseWhere = $departwhere.$statustwhere.$jobwhere;
			$nowPage = isset($Params['page'])?(int)$Params['page']:1;
			$perPage = 10;
			$res = $B2cShop->getWorker($_SESSION['_shopid'],$nowPage,$perPage,$total,$baseWhere);
			// print_r($_SESSION);
			// print_r($res);die;
			LibTpl::Set('workerList', $res);
			$Page = LibPage::Show($total, $perPage);
			LibTpl::Set('Page', $Page);
		}

		// meta
		$headArr = [
			'title'=>'子账号管理-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','account');
		$this->HEAD_CSSJS['plugin'][] = 'zTree';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Put();
	}
	/**
	 * @method    修改/添加部门
	 * @author 卢
	 * @copyright 2017-10-23
	 */
	public function editDepartment()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cShop=new B2cShop();
		$Params = mvc::$URL_PARAMS;
		$targetArr=[];
		$res=['status'=>false,'data'=>'修改失败'];
		if(!empty($_POST))
		{
			if(isset($Params['editType']))
			{
				$OthCheck->rule('SA06');
				if($Params['editType']=='drag')//修改父类
				{
					//拖拽修改父类
					if($_POST['type']=='root')
					{
						//根节点
						$targetArr['wod_pid']=$_POST['targetId'];
						$seqData=$B2cShop->get('sh_worker_department',['wod_seq'],sprintf(' and wod_pid=0 and wod_shop_id=%d order by wod_seq desc',$_SESSION['_shopid']),true);
						$targetArr['wod_seq']=$seqData['data']['wod_seq']+1;
					}
					else if($_POST['type']=='inner')
					{
						//子节点
						$targetArr['wod_pid']=$_POST['targetId'];
						$seqData=$B2cShop->get('sh_worker_department',['wod_seq'],sprintf(' and wod_pid=%d and wod_shop_id=%d order by wod_seq desc',$_POST['targetId'],$_SESSION['_shopid']),true);
						$targetArr['wod_seq']=$seqData['data']['wod_seq']+1;
					}
					else
					{
						//同级节点
						$parentNode=$B2cShop->get('sh_worker_department', ['wod_pid','wod_name','wod_seq'], sprintf(' and wod_shop_id=%d and wod_id=%d',$_SESSION['_shopid'],$_POST['targetId']),true);
						if($_POST['type']=='prev')
						{
							$targetArr['wod_seq']=$parentNode['data']['wod_seq']-1;
						}
						else if($_POST['type']=='next')
						{
							$targetArr['wod_seq']=$parentNode['data']['wod_seq']+1;
						}
						$targetArr['wod_pid']=$parentNode['data']['wod_pid'];
					}
				}
				elseif($Params['editType']=='rename')//重命名
				{
					$targetArr['wod_name']=$_POST['targetName'];
				}
				$where=sprintf(' and wod_shop_id=%d and wod_id=%d',$_SESSION['_shopid'],$_POST['departId']);
				$res=$B2cShop->editDepartment($_SESSION['_shopid'],$targetArr,$where);
			}
			else
			{
				$OthCheck->rule('SA05');
				$seqData=$B2cShop->get('sh_worker_department',['wod_seq'],sprintf(' and wod_pid=%d and wod_shop_id=%d order by wod_seq desc',$_POST['topDepart'],$_SESSION['_shopid']),true);
				$targetArr['wod_seq']=$seqData['data']['wod_seq']+1;
				$targetArr['wod_pid']=$_POST['topDepart'];
				$targetArr['wod_name']=$_POST['departName'];
				//添加
				$result=$B2cShop->addDepartment($_SESSION['_shopid'],$targetArr);
				$res=$B2cShop->get('sh_worker_department',['wod_id','wod_pid','wod_name','wod_seq'],sprintf(' and wod_id=%d',$result['data']));
			}
		}
		LibFc::ajaxJsonEncode($res);
	}
	/**
	 * @method    删除部门
	 * @author 卢
	 * @copyright 2017-10-23
	 */
	public function delDepartment()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SA07');
		$B2cShop=new B2cShop();
		$Params = mvc::$URL_PARAMS;
		if(LibFc::Int($Params['departId']))
		{
			$exitData=$B2cShop->get('sh_worker_department',['count(*) count'],sprintf(' and wod_pid=%d',$Params['departId']),true);
			if($exitData['data']['count'])
			{
				LibFc::ajaxJsonEncode(['status'=>false,'data'=>'该部门下存在子类，不允许删除']);
				exit();
			}
			$workerData=$B2cShop->get('sh_worker left join sh_worker_department on wor_wod_id=wod_id',['count(*) count'],sprintf(' and wod_id=%d and wod_shop_id=%d',$Params['departId'],$_SESSION['_shopid']),true);
			if($workerData['data']['count'])
			{
				LibFc::ajaxJsonEncode(['status'=>false,'data'=>'该部门下存在职员，不允许删除']);
				exit();
			}
			$res=$B2cShop->del('sh_worker_department',sprintf(' and wod_id=%d and wod_shop_id=%d',$Params['departId'],$_SESSION['_shopid']));
		}
		LibFc::ajaxJsonEncode($res);
	}
	/**
	 * @method  ajax保存编辑员工
	 * @author  廖
	 * @copyright 2017-10-24
	 */
	public function ajaxChangeWorker()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SA03');
		$B2cShop=new B2cShop();
		$data = '参数不正确!';
		if($_POST['order'] == 'departMent')
		{
			if(LibFc::Int($_POST['deId']) && !empty($_POST['uId']))
			{
				$arr = explode(',',trim($_POST['uId'],','));
				if(!empty($arr))
				{
					foreach ($arr as $key => $value)
					{
						if(!LibFc::Int($value))
						{
							unset($arr[$key]);
						}
					}
				}
				if(!empty($arr))
				{
					$res = $B2cShop->set('sh_worker',['wor_wod_id'=>$_POST['deId']],sprintf(' and wor_shop_id=%d and wor_uid in(%s)',$_SESSION['_shopid'],implode(',',$arr)));
					LibFc::ajaxJsonEncode($res);
				}
			}
		}
		if($_POST['order'] == 'status')
		{
			$arr = array('0','-1','1');
			if(LibFc::Int($_POST['uId']) && in_array($_POST['status'], $arr))
			{
				$res = $B2cShop->set('sh_worker',['wor_status'=>$_POST['status']],sprintf(' and wor_shop_id=%d and wor_uid in(%s)',$_SESSION['_shopid'],$_POST['uId']));
				LibFc::ajaxJsonEncode($res);
			}
		}
		LibFc::ajaxJsonEncode(['status'=>false,'data'=>$data]);
	}
	/**
	 * @method  新建员工
	 * @author  廖
	 * @copyright 2017-10-21
	 */
	public function addWorker()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		// 权限
		if(!empty($Params['orderId']) && LibFc::Int($Params['orderId']))
		{
			$OthCheck->rule('SA03');
			LibTpl::Set('actionType','编辑职员');
		}
		else
		{
			$OthCheck->rule('SA02');
			LibTpl::Set('actionType','添加职员');
		}
		//店铺职位
		$B2cBase = new B2cBase();
		$res = $B2cBase->get('sh_worker_job',['woj_id','woj_name'],sprintf(' and woj_shop_id=%d order by woj_seq asc',$_SESSION['_shopid']));
		$newArr = array_column($res['data'], 'woj_name' ,'woj_id');
		LibTpl::Set('jobList',$newArr);
		//所有部门
		$departRes = $B2cBase->get('sh_worker_department',['wod_id','wod_pid','wod_name','wod_seq'],sprintf(' and wod_shop_id=%d order by wod_seq asc',$_SESSION['_shopid']));
		LibTpl::Set('departNodes',json_encode($departRes['data'],JSON_UNESCAPED_UNICODE));
		//所有权限
		$ruleArr = $B2cBase->get('sh_rule',['rule_id','rule_name','rule_parent']);
		LibTpl::Set('rulesNodes',json_encode($ruleArr['data'],JSON_UNESCAPED_UNICODE));

		if(!empty($Params['wordId']) && LibFc::Int($Params['wordId']))
		{
			//编辑
			$editWoker = $B2cBase->get('sh_worker',['*'],sprintf(' and wor_shop_id=%d and wor_uid=%d',$_SESSION['_shopid'],$Params['wordId']),true);
			if(!empty($editWoker['data']))
			{
				//整理所有部门的名称
				$departArr = array();
				if(!empty($departRes['data']))
				{
					$departArr = array_combine(array_column($departRes['data'], 'wod_id'),$departRes['data']);
				}
				LibTpl::Set('departArr',$departArr);
				//取出它的权限
				$arr =json_encode(explode(',',trim($editWoker['data']['wor_rule_ids'],',')));
				$userwhere = ' and shop_id='.$editWoker['data']['wor_shop_id'];
				LibTpl::Set('editWoker',$editWoker['data']);
				LibTpl::Set('uId',$Params['wordId']);
				LibTpl::Set('rule',$arr);
				LibTpl::Set('edit',true);
			}
		}
		// 店主的名称
		if($_SESSION['_shopowner']) $userwhere = ' and ub_uid='.$_SESSION['_userid'];
		if(!empty($userwhere))
		{
			$res = $B2cBase->get('us_user_base left join sh_shop on ub_uid=shop_uid',['ub_username'],$userwhere,true);
			LibTpl::Set('mainName', $res['data']['ub_username']);
		}
		// meta
		$headArr = [
			'title'=>'子账号管理-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		$this->HEAD_CSSJS['plugin'][] = 'zTree';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('status', [1=>'启用',0=>'停用',-1=>'离职']);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','account');
		LibTpl::Set('order', 'department');
		LibTpl::Put();
	}
	/**
	 * @method    ajax获取职位默认权限
	 * @author    廖
	 * @copyright 2017-10-23
	 */
	public function ajaxGetDefaultRule()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		if(LibFc::Int($_POST['userId']) && (LibFc::Int($_POST['id']) == LibFc::Int($_POST['defaultWorkId'])))
		{
				$editWoker = $B2cBase->get('sh_worker',['wor_rule_ids'],sprintf(' and wor_shop_id=%d and wor_uid=%d and wor_woj_id=%d',$_SESSION['_shopid'],$_POST['userId'],$_POST['defaultWorkId']),true);
				if (!empty($editWoker['data']))
				{
					$arr = explode(',', $editWoker['data']['wor_rule_ids']);
					LibFc::ajaxJsonEncode(['status'=>true,'data'=>$arr]);
					exit;
				}
		}
		if(LibFc::Int($_POST['id']))
		{
			$res = $B2cBase->get('sh_worker_job',['woj_rule_ids'],sprintf(' and woj_id=%d and woj_shop_id=%d',$_POST['id'],$_SESSION['_shopid']),true);
			$arr = explode(',', $res['data']['woj_rule_ids']);
			LibFc::ajaxJsonEncode(['status'=>true,'data'=>$arr]);
		}
	}
	/**
	 * @method    ajax保存新增职工
	 * @author    廖
	 * @copyright 2017-10-23
	 */
	public function ajaxSaveRules()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		$status = ['1','0','-1'];
		// 参数
		if( empty($_POST['job']) || !LibFc::Int($_POST['job']) || empty($_POST['workerName']))
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数不正确!']);
		if(!isset($_POST['status']) || !in_array($_POST['status'], $status))
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'职员状态错误!']);
		// print_r($_POST);
		// die;
		if($_POST['order'] =='add')
		{
			if(empty($_POST['password']) ||  (strlen($_POST['password'])<6||strlen($_POST['password'])>20))
				LibFc::ajaxJsonEncode(['status'=>false,'data'=>'密码格式错误!']);
			// 新增
			$LibYpApi = new LibYpApi();
			$dataArr = [
				'u_name' => $_SESSION['_username'].':'.$_POST['workerName'],
				'u_password' => $_POST['password'],
				'u_b2c_shopid' => $_SESSION['_shopid']
			];
			// 新增职员
			$res = $LibYpApi->Get('user/addWorker', [], ['data'=>$dataArr]);
			$newUserId = $res['data'];
			// 职员权限
			$data = [
				'wor_shop_id'=>$_SESSION['_shopid'],
				'wor_uid'=>$newUserId,//用户ID
				'wor_status'=>$_POST['status'],//职员状态
				'wor_wod_id'=> (int)$_POST['departId'],//部门
				'wor_atime'=>time(),
				'wor_woj_id'=>$_POST['job'],//职位ID
				'wor_rule_ids'=> LibFc::Escape($_POST['defaultRule']),//权限
				'wor_name'=>$_POST['workerName'],//登录账户名,需要加店主名作前缀
				'wor_real_name'=>$_POST['wor_real_name']
			];
			$B2cBase->add('sh_worker',$data);

			// 同步用户名表
			$res = $B2cBase->get('us_user_base', ['max(ub_uid) ub_uid'], '', true);
			$maxUid = empty($res['data']['ub_uid']) ? 0: $res['data']['ub_uid'];
			$YpwBase = new YpwBase();
			while(1)
			{
				$res = $YpwBase->get('yp_user', ['u_id', 'u_name'], sprintf(" and u_id > %d order by u_id limit 1000", $maxUid));
				if(empty($res['data'])) break;
				foreach($res['data'] as $v)
				{
					$B2cBase->add('us_user_base', ['ub_uid'=>$v['u_id'], 'ub_username'=>$v['u_name']]);
					$maxUid = $v['u_id'];
				}
			}

			LibFc::ajaxJsonEncode(['status'=>true,'data'=>'操作成功！']);
		}

		if($_POST['order'] =='edit')
		{
			// 修改
			if(empty($_POST['userId'])||!LibFc::Int($_POST['userId'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数不正确!']);
			// 密码
			if(!empty($_POST['password']))
			{
				if(strlen($_POST['password'])<6||strlen($_POST['password'])>20)
					LibFc::ajaxJsonEncode(['status'=>false,'data'=>'密码格式错误!']);
				$LibYpApi = new LibYpApi();
				$temp = [
					'uid' => $_POST['userId'],
					'data' => ['u_password' => $_POST['password']]
				];
				$LibYpApi->Get('user/setUser',[],$temp);
			}
			// 更新职员信息
			$data = [
				'wor_status'=>$_POST['status'],
				'wor_wod_id'=> (!empty($_POST['departId']) && LibFc::Int($_POST['departId'])) ? $_POST['departId'] : '',//部门
				'wor_woj_id'=> $_POST['job'],//职位ID
				'wor_rule_ids'=> LibFc::Escape($_POST['defaultRule']),
				'wor_real_name'=>$_POST['wor_real_name']
			];
			$B2cBase->set('sh_worker',$data,sprintf(' and wor_shop_id=%d and wor_uid=%d',$_SESSION['_shopid'],$_POST['userId']));
			LibFc::ajaxJsonEncode(['status'=>true,'data'=>'操作成功！']);
		}


		LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数不正确!']);
	}
	/**
	 * @method    添加职位
	 * @author xu
	 * @copyright 2017-10-21
	 */
	public function addjob()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SA08');
		$B2cBase = new B2cBase();

		//入库
		if($_SERVER['REQUEST_METHOD']=="POST")
		{
			// 新职位
			$newJob = $_POST;
			if(empty($newJob['woj_name'])) LibFc::Go('/seller/job');
			$temp = array(
				'woj_name'=>$newJob['woj_name'],
				'woj_rule_ids'=>$newJob['woj_rule_ids'],
				'woj_seq'=>99,
				'woj_shop_id' => $_SESSION['_shopid']
			);
			$data = $B2cBase->add('sh_worker_job',$temp);
			LibFc::Go('/seller/job');
		}

		// ztree数据源
		$res = $B2cBase->get('sh_rule',['*'],"");
		$allRule = $res['data'];
		$parent_id = array_unique(array_column($allRule, 'rule_parent'));
		// 拼接ztree-json
		$ztree = array();
		foreach ($allRule as $k => $v)
		{
			$ztree[] = array(
				'id'=>$v['rule_id'],
				'pId'=>$v['rule_parent'],
				'name'=>$v['rule_name'],
				'open'=>true,
				'nocheck'=>in_array($v['rule_id'], $parent_id)?true:false // 父权限不可选
			);
		}
		LibTpl::Set('JSON',json_encode($ztree));
		LibTpl::Set('LeftMenu','account');
		$this->HEAD_CSSJS['plugin'][] = 'zTree';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		$headArr = [
			'title'=>'添加职位-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('LeftMenu','account');
		LibTpl::Set('headArr', $headArr);
		LibTpl::Put('seller/editjob.php');
	}



	/**
	 * @method  编辑某职位
	 * @author xu
	 * @copyright 2017-10-21
	 */
	public function editjob()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SA09');
		$B2cBase = new B2cBase();
		$Params = mvc::$URL_PARAMS;

		if(empty($Params['id'])||!LibFc::Int($getWojId = $Params['id'])) LibFc::Go('/seller/job');


		// 获取当前这个职位的信息
		$res = $B2cBase->get('sh_worker_job',['*'],sprintf(" and woj_id=%d ",$getWojId),true);
		$editjob_msg = $res['data'];
		LibTpl::Set('editjob_msg',$editjob_msg);
		LibTpl::Set('LeftMenu','account');
		// 权限
		$editingrule = explode(',',$editjob_msg['woj_rule_ids']);
		//入库
		if($_SERVER['REQUEST_METHOD']=="POST")
		{
			$newJob = $_POST;
			if(empty($newJob['woj_name'])) LibFc::Go('/seller/job');
			// 新职位

			$B2cBase->set('sh_worker_job',['woj_name'=>$newJob['woj_name'],'woj_rule_ids'=>$newJob['woj_rule_ids']],sprintf(" and woj_id=%d ",$getWojId));
			LibFc::Go('/seller/job');
		}
		// 获取所有的职位权限拼接成ztree要的json数据
		$res = $B2cBase->get('sh_rule',['*'],"");
		$allRule = $res['data'];
		// 将数据拼接为array('id','pid','name');
		$newAllRule = array();
		// 获取所有的有子权限的父权限
		$allParRuleId = array();
		foreach ($allRule as $k => $v)
		{
			$allParRuleId[] = $v['rule_parent'];
		}
		$unique_par_id = array_unique($allParRuleId);
		foreach ($allRule as $k => $v)
		{
			if(in_array($v['rule_id'],$editingrule))
			{
				$newAllRule[] = array(
					'id'=>$v['rule_id'],
					'pId'=>$v['rule_parent'],
					'name'=>$v['rule_name'],
					'open'=>true,
					'checked'=>true
				);
			}
			else
			{
				$newAllRule[] = array(
					'id'=>$v['rule_id'],
					'pId'=>$v['rule_parent'],
					'name'=>$v['rule_name'],
					'open'=>true
				);
			}
		}
		foreach ($newAllRule as $k => $v)
		{
			if(in_array($v['id'], $unique_par_id))
			{
				unset($newAllRule[$k]['checked']);
				$newAllRule[$k]['nocheck'] = true;
			}
		}

		$newAllRule[] = array(
				'id'=>'0000',
				'pId'=>"0000",
				'name'=>"所有权限",
				'open'=>true,
				"nocheck"=>true
			);
		LibTpl::Set('JSON',json_encode($newAllRule));

		$this->HEAD_CSSJS['plugin'][] = 'zTree';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);

		$headArr = [
			'title'=>'编辑职位-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Put();
	}

	/**
	 * @method  删除某职位
	 * @author xu
	 * @copyright 2017-10-21
	 */
	public function deljob()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SA10');
		$B2cBase = new B2cBase();
		// 校验参数
		if(empty($_POST['woj_id'])||!LibFc::Int($wojId=$_POST['woj_id'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		// 检测
		$res = $B2cBase->get(" sh_worker ",['count(*) wor_count'],sprintf(" and wor_woj_id=%d ",$wojId),true);
		if($res['data']['wor_count']>0) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'当前职位下还有职员，删除失败！']);
		// 删除
		$B2cBase->del('sh_worker_job',sprintf(" and woj_id=%d and woj_shop_id=%d ",$wojId,$_SESSION['_shopid']));
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>true]);
	}


	/**
	 * @method   职位管理
	 * @author xu
	 * @copyright 2017-10-20
	 */
	public function job()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SA01');
		$B2cShop = new B2cShop();
		$Params = mvc::$URL_PARAMS;
		// 获取所有的职位
		$B2cBase = new B2cBase();
		$res = $B2cBase->get("sh_worker_job",['*'],sprintf(" and woj_shop_id=%d order by woj_seq asc ",$_SESSION['_shopid']));
		$allJob = $res['data'];
		// 所有的权限
		$res = $B2cBase->get("sh_rule",['rule_id','rule_name'],"");
		$allRuleName = array_column($res['data'],'rule_name','rule_id');
		// 新增名称
		foreach ($allJob as $k => $v)
		{
			$Ar = explode(',', $v['woj_rule_ids']);
			foreach ($Ar as $vv)
			{
				$allJob[$k]['ALL_rule_name'][] = $allRuleName[$vv];
			}
		}
		// meta
		$headArr = [
			'title'=>'职位管理-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('allJob',$allJob);
		$this->HEAD_CSSJS['plugin'][] = 'zTree';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','account');
		LibTpl::Set('order', 'job');
		LibTpl::Set('LeftMenu','account');
		LibTpl::Put();
	}

	/**
	 * @method  重新排序职位
	 * @author xu
	 * @copyright 2017-10-23
	 */
	public function reSeqWojIconFunc()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SA09');
		$B2cBase = new B2cBase();
		// 参数
		if(empty($_POST['formval']) || !is_array($formval=$_POST['formval']) || empty($formval=array_filter($formval,'LibFc::Int')))
		LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		// 入库
		foreach ($formval as $k => $v)
		{
			$where = sprintf(" and woj_id=%d and woj_shop_id=%d ",$v,$_SESSION['_shopid']);
			$B2cBase->set('sh_worker_job',['woj_seq'=>$k+1],$where);
		}
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>true]);
	}
	/**
	 * @method    资金明细
	 * @author 卢
	 * @copyright 2017-10-26
	 */
	public function capital()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SM01');
		$Params = mvc::$URL_PARAMS;
		$NowPage = isset($Params['page']) && $Params['page'] > 0 ? (int) $Params['page']:1;
		$PerPage = 20;
		$TimeArr = [
			'0'=>'--请选择时间--',
			'-1 month'=>'最近1个月资金明细',
			'-3 month'=>'最近3个月资金明细',
			'-6 month'=>'最近6个月资金明细',
			'--6 month'=>'6个月以前资金明细',
		];
		LibTpl::Set('TimeArr', $TimeArr);
		$Where = sprintf(" and mon_shop_id=%d", $_SESSION['_shopid']);
		// print_r($Params);
		foreach($Params as $K=>$V)
		{
			if(trim($V) == '') continue;
			switch($K)
			{
				case 'type':
					switch ($V) {
						case 'income':
							$Where .=' and mon_stype=0';
							break;
						case 'refund':
							$Where .=' and mon_stype=1';
							break;
						case 'withdraw':
							$Where .=' and mon_stype=2';
							break;
						case 'brokerage':
							$Where .=' and mon_stype=3';
							break;
					}
				break;
				case 'time':
					if(!empty($V))
						$Where .= stripos($V, '--') !== false ? ' and mon_atime<='.strtotime(str_replace('--', '-', $V)): ' and mon_atime>='.strtotime($V);
				break;
			}
		}
		$B2cBase = new B2cBase();
		$Res = $B2cBase->get('sh_money', ['count(1) count'], $Where, true);
		$Total = $Res['data']['count'];
		if($Total > 0)
		{
			$Where .= sprintf(" order by mon_atime desc limit %d,%d", $Where, ($NowPage-1)*$PerPage, $PerPage);
			$Res = $B2cBase->get('sh_money', ['mon_id, mon_shop_id,mon_stype, mon_dataid,mon_money,mon_title,mon_des,mon_by_uid, mon_by_uname,mon_atime, mon_tyle'], $Where);
			$monPidArr=array_column($Res['data'], 'mon_id');
			$monPidArr=array_unique($monPidArr);
			$uidArr=array_column($Res['data'], 'mon_uid');
			//佣金
			$monPidArr=array_filter($monPidArr);
			/*if(count($monPidArr)>0)
			{
				$monPidData=$B2cBase->get('sh_money',['*'],sprintf(' and mon_shop_id=%d and mon_pid in(%s)',$_SESSION['_shopid'],implode(',', $monPidArr)));
				$pidArr=array_column($monPidData['data'], null,'mon_pid');
			}
			//操作人
			$userData=$B2cBase->get('us_user_base',['ub_username','ub_uid'],sprintf(' and ub_uid in(%s)',implode(',', $uidArr)));
			$userArr=array_column($userData['data'], null,'ub_uid');
			foreach ($Res['data'] as $k => $v)
			{
				if(isset($pidArr[$v['mon_id']]))
				{
					$Res['data'][$k]['monPidArr']=$pidArr[$v['mon_id']];
				}
				$Res['data'][$k]['user']=isset($userArr[$v['mon_uid']]['ub_username'])?$userArr[$v['mon_uid']]['ub_username']:'系统自动操作';
			}*/
			$ListArr = $Res['data'];
			// print_r($ListArr);
			LibTpl::Set('ListArr', $ListArr);
		}
		$B2cBase = new B2cBase();
		$B2cMoney=new B2cMoney();
		$Res=$B2cMoney->getShopMoney($_SESSION['_shopid']);
		// $Res = $B2cBase->get('sh_shop', ['shop_money'], sprintf(" and shop_id=%d", $_SESSION['_shopid']), true);
		LibTpl::Set('shopBase', $Res['data']);
		LibTpl::Set('Params', $Params);
		LibTpl::Set('LeftMenu', 'capital');
		$Page = LibPage::Show($Total, $PerPage);
		LibTpl::Set('Page', $Page);
		$headArr = [
			'title'=>'资金明细-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Put();
	}
	/**
	 * @method    tiXianList
	 * @return    提现记录列表
	 * @author 卢
	 * @copyright 2018-03-10
	 */
	function tiXianList()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SM03');
		$B2cBase = new B2cBase();
		$B2cMoney=new B2cMoney();
		$Params = mvc::$URL_PARAMS;
		LibTpl::Set('Params', $Params);
		$nowPage = isset($Params['page']) && $Params['page'] > 0 ? (int) $Params['page']:1;
		$perPage = 20;
		$TimeArr = [
			'0'=>'--请选择状态--',
			'-1'=>'已关闭',
			'-2'=>'处理中',
			'1'=>'转账完成',
		];
		LibTpl::Set('TimeArr', $TimeArr);
		$this->HEAD_CSSJS['plugin'][] = 'datetimepicker';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		//当前余额
		$Res=$B2cMoney->getShopMoney($_SESSION['_shopid']);
		LibTpl::Set('shopBase', $Res['data']);
		//取记录
		//计算总页数
		$where=sprintf(' and mow_shop_id=%d',$_SESSION['_shopid']);
		//状态筛选
		switch ($Params['status']) {
			case '-1':
				$where.=' and mow_status=-1';
				break;
			case '-2':
				$where.=' and mow_status=0';
				break;
			case '1':
				$where.=' and mow_status=1';
		}
		//日期筛选
		if(!empty($Params['time'])&&strpos($Params['time'], ' - '))
		{
			$timeArr=explode(' - ', $Params['time']);
			$startTime=strtotime(trim($timeArr[0]));
			$endTime=strtotime(trim($timeArr[1]));
			$where.=sprintf(' and mow_atime>=%d',$startTime);
			$where.=sprintf(' and mow_atime<=%d',$endTime);
		}
		$res=$B2cBase->get('sh_money_withdrawals',['count(1) total'],$where,true);
		$total=$res['data']['total'];
		$totalPage=ceil($total/$perPage);
		$where .= sprintf(" order by mow_atime desc limit %d,%d", ($nowPage-1)*$perPage, $perPage);
		$res=$B2cBase->get('sh_money_withdrawals',['mow_id','mow_status','mow_by_uname','mow_total_money','mow_real_money','mow_comm_money','mow_atime','mow_ok_time','mow_shop_commission','mow_acc_data'], $where);
		if(count($res['data']))
		{
			//取操作人和收款人信息
			foreach ($res['data'] as $k=> $v)
			{
				$accArr=json_decode($v['mow_acc_data'],true);
				$accArr['acc_weixin_info'] = json_decode(base64_decode($accArr['acc_weixin_info']), true);
				$res['data'][$k]['accName']=$accArr['acb_name'];
				$res['data'][$k]['jsonArr']=$accArr;
			}
		}
		LibTpl::Set('list',$res['data']);
		$Page = LibPage::Show($total, $perPage);
		LibTpl::Set('Page', $Page);
		LibTpl::Set('LeftMenu', 'capital');
		$res = $B2cMoney->getBank();
		LibTpl::Set('bankArr', $res['data']);
		$res = $B2cBase->get('sh_account_bind', ['*'], sprintf(" and acb_shop_id=%d", $_SESSION['_shopid']));
		$idcardArr = $res['data'];
		LibTpl::Set('idcardArr', $idcardArr);
		$headArr = [
			'title'=>'提现记录-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Put();
	}
	/**
	 * @method    提现记录详情
	 * @author 卢
	 * @copyright 2018-03-12
	 */
	function tiXianDes()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SM03');
		$B2cBase = new B2cBase();
		$B2cMoney=new B2cMoney();
		$Params = mvc::$URL_PARAMS;
		if(LibFc::Int($Params['mowId']))
		{
			$res=$B2cBase->get('sh_money_withdrawals',['mow_id','mow_status','mow_by_uname','mow_total_money','mow_real_money','mow_comm_money','mow_atime','mow_ok_time','mow_shop_commission','mow_acc_data'],sprintf(' and mow_id=%d and mow_shop_id=%d',(int)$Params['mowId'],$_SESSION['_shopid']),true);
			if(count($res['data']))
			{
				$res['data']['jsonArr']= json_decode($res['data']['mow_acc_data'],true);
				$res['data']['jsonArr']['acc_weixin_info'] = json_decode(base64_decode($res['data']['jsonArr']['acc_weixin_info']),true);
				LibTpl::Set('desArr',$res['data']);
			}
			else
			{
				LibTpl::Error('记录不存在！');
			}
			$Res=$B2cMoney->getShopMoney($_SESSION['_shopid']);
			LibTpl::Set('shopBase', $Res['data']);
		}
		else
		{
			LibTpl::Error('记录不存在！');
		}
		LibTpl::Set('LeftMenu', 'capital');
		$headArr = [
			'title'=>'提现记录-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Put();
	}
	/**
	 * @method    资金冻结记录
	 * @author 卢
	 * @copyright 2018-03-13
	 */
	function moneyUnav()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SM03');
		$B2cBase = new B2cBase();
		$B2cMoney=new B2cMoney();
		$Params = mvc::$URL_PARAMS;
		LibTpl::Set('Params', $Params);
		$Res=$B2cMoney->getShopMoney($_SESSION['_shopid']);
		LibTpl::Set('shopBase', $Res['data']);
		$nowPage = isset($Params['page']) && $Params['page'] > 0 ? (int) $Params['page']:1;
		$perPage = 20;
		$TimeArr = [
			'0'=>'--请选择状态--',
			'-1'=>'已关闭',
			'-2'=>'处理中',
			'1'=>'转账完成',
		];
		LibTpl::Set('TimeArr', $TimeArr);
		$this->HEAD_CSSJS['plugin'][] = 'datetimepicker';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		$where=sprintf(' and mou_shop_id=%d',$_SESSION['_shopid']);
		//状态筛选
		switch ($Params['status']) {
			case '-1':
				$where.=' and mou_status=-1';
				break;
			case '-2':
				$where.=' and mou_status=0';
				break;
			case '1':
				$where.=' and mou_status=1';
		}
		//日期筛选
		if(!empty($Params['time'])&&strpos($Params['time'], ' - '))
		{
			$timeArr=explode(' - ', $Params['time']);
			$startTime=strtotime(trim($timeArr[0]));
			$endTime=strtotime(trim($timeArr[1]));
			$where.=sprintf(' and mou_atime>=%d',$startTime);
			$where.=sprintf(' and mou_atime<=%d',$endTime);
		}
		//计算总数
		$res=$B2cBase->get('sh_money_unav',['count(1) total'],$where,true);
		$total=$res['data']['total'];
		$totalPage=ceil($total/$perPage);
		$where .= sprintf(" order by mou_atime desc limit %d,%d",$where, ($nowPage-1)*$perPage, $perPage);
		$res=$B2cBase->get('sh_money_unav',['mou_id','mou_status','mou_title','mou_money','mou_atime','mou_ok_time','mou_close_time'], $where);
		LibTpl::Set('list',$res['data']);
		$Page = LibPage::Show($total, $perPage);
		LibTpl::Set('Page', $Page);
		LibTpl::Set('LeftMenu', 'capital');
		$headArr = [
			'title'=>'资金冻结记录-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Put();
	}

	/**
	  * @method 提现页面
	  * @author soul
	  */
	function tiXian()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SM02');
		if(!empty($_POST['acc_id']) && !empty($_POST['money']))
		{
			$B2cMoney = new B2cMoney();
			$dataArr = [
				'mow_shop_id'=>	$_SESSION['_shopid'],
				'mow_acc_id'=>	$_POST['acc_id'],
				'mow_total_money'=>	$_POST['money'],
			];
			$res = $B2cMoney->addShopMoneyWithdrawals($dataArr);
			LibTpl::Success('提现提交成功', mvc::$cfg['HOST']['b2c'].'seller/tiXianDes?mowId='.$res['data']);
		}

		$B2cMoney = new B2cMoney();
		$res = $B2cMoney->getShopMoney($_SESSION['_shopid']);
		$shopArr = $res['data'];
		//根据佣金率算出最低提现金额
		$shopArr['minMoney'] = sprintf("%.2f", 1/(1-$shopArr['commission']/100));
		LibTpl::Set('shopArr', $shopArr);

		$LibYpApi = new LibYpApi();
		$res = $LibYpApi->get('wx/getWxUserUrl', ['app'=>'gzh_app', 'backUrl'=>mvc::$cfg['HOST']['b2c'].'seller/bingTiXianWx', 'scope'=>'snsapi_login']);
		LibTpl::Set('wxBindurl', $res['data']);

		$B2cBase = new B2cBase();
		$res = $B2cBase->get('sh_account join sh_account_bind on acc_acb_id = acb_id', ['*'], sprintf(" and acc_shop_id=%d order by acc_seq, acc_id", $_SESSION['_shopid']));
		$accArr = [];
		foreach($res['data'] as $v)
		{
			$v['acc_weixin_info'] = json_decode(base64_decode($v['acc_weixin_info']), true);
			$accArr[] = $v;
		}
		LibTpl::Set('accArr', $accArr);

		$res = $B2cBase->get('sh_account_bind', ['*'], sprintf(" and acb_shop_id=%d", $_SESSION['_shopid']));
		$idcardArr = $res['data'];
		LibTpl::Set('idcardArr', $idcardArr);

		$B2cMoney = new B2cMoney();
		$res = $B2cMoney->getBank();
		LibTpl::Set('bankArr', $res['data']);

		$headArr = [
			'title'=>'提现-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Put();
	}


	/**
	  * @method 异步绑定支付宝、银行卡
	  * @author soul
	  */
	function ajaxAddAccount()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SM02');
		$addData = [];
		switch($_POST['acc_type'])
		{
			case 1:
				$addData = [
					'acc_type'=>1,
					'acc_shop_id'=>$_SESSION['_shopid'],
					'acc_acb_id'=>$_POST['acc_acb_id'],
					'acc_alipay_account'=>$_POST['acc_alipay_account']
				];

			break;
			case 2:
				$addData = [
					'acc_type'=>2,
					'acc_shop_id'=>$_SESSION['_shopid'],
					'acc_acb_id'=>$_POST['acc_acb_id'],
					'acc_bank_name'=>$_POST['acc_bank_name'],
					'acc_bank_card'=>$_POST['acc_bank_card'],
					'acc_bank_open'=>$_POST['acc_bank_open']
				];
			break;
		}
		$B2cShop = new B2cShop();
		$res = $B2cShop->addTiXianAccount($addData);
		LibFc::ajaxJsonEncode($res);
	}


	/**
	  * @method 异步删除收款账号
	  * @author soul
	  */
	function ajaxDelAccount()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SM02');
		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();
		$res = $B2cBase->del('sh_account', sprintf(" and acc_id=%d and acc_shop_id=%d", (int) $Params['accId'], $_SESSION['_shopid']));
		LibFc::ajaxJsonEncode($res);
	}


	/**
	  * @method 检查提现限制
	  * @author soul
	  */
	function ajaxCheckTxByAccid()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SM02');
		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();
		$money = sprintf("%.2f", $Params['money']);
		$res = $B2cBase->get('sh_account', ['acc_id', 'acc_type'], sprintf(" and acc_id=%d and acc_shop_id=%d", (int) $Params['accId'], $_SESSION['_shopid']), true);
		if(empty($res['data']))
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'提现人信息不存在']);
		$accArr = $res['data'];
		$res = $B2cBase->get('sh_money_withdrawals', ['count(*) count', 'sum(mow_total_money) money'], sprintf(" and mow_acc_id=%d and mow_status > 0 and mow_atime > %d", $accArr['acc_id'], strtotime(date('Y-m-d'))), true);
		$maxArr = $res['data'];
		$xzArr = mvc::$cfg['TIXIAN'][$accArr['acc_type']];
		$maxArr['money'] = sprintf('%.2f', $maxArr['money']);
		$can = sprintf('%.2f', $xzArr['dateMax'] - $maxArr['money']);
		if($maxArr['count'] >= 10)
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'此账号今天的提现次数已用完（10次）']);
		if($can < 0.01)
		{
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'此账号今天的提现额度已用完']);
		}
		else if($money > $xzArr['perMax'])
		{
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>$xzArr['name'].'提现每笔限额为'.sprintf('%.2f', $xzArr['perMax']).'元']);
		}
		else if($money > $can)
		{
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'此账号今天剩余提现额度为'.$can.'元']);
		}
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>'']);
	}



	/**
	  * @method 添加微信提现账号
	  * @author soul
	  */
	function bingTiXianWx()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SM02');
		$Params = mvc::$URL_PARAMS;
		if(!empty($Params['udata']))
		{
			$WXUserArr = json_decode(base64_decode($Params['udata']), true);
		}

		if(empty($WXUserArr['unionid'])) LibFc::Go(mvc::$cfg['HOST']['b2c'].'seller/tiXian');
		LibTpl::Set('WXUserArr', $WXUserArr);

		$B2cBase = new B2cBase();

		$res = $B2cBase->get('sh_account', ['acc_id'], sprintf(" and acc_shop_id=%d and acc_weixin_unionid='%s'", $_SESSION['_shopid'], LibFc::Escape($WXUserArr['unionid'])), true);
		if(!empty($res['data']))
		{
			LibTpl::Error('此微信已完成绑定，请勿重复绑定！', mvc::$cfg['HOST']['b2c'].'seller/tiXian');
		}

		//通过acc_weixin_unionid 获取公众号下的oppenid
		$LibYpApi = new LibYpApi();
		$res = $LibYpApi->get('wx/getGzhByUnionid', ['unionid'=>$WXUserArr['unionid']]);
		$gzhArr = $res['data'];
		LibTpl::Set('gzhArr', $gzhArr);

		if(!empty($_POST['wxnum']) && !empty($_POST['acb_id']) && !empty($gzhArr['gu_oppenid']))
		{
			$addData = [
				'acc_type'=>0,
				'acc_shop_id'=>$_SESSION['_shopid'],
				'acc_acb_id'=>$_POST['acb_id'],
				'acc_weixin'=>$_POST['wxnum'],
				'acc_weixin_oppenid'=>$gzhArr['gu_oppenid'],
				'acc_weixin_unionid'=>$WXUserArr['unionid'],
				'acc_weixin_info'=>base64_encode(json_encode($WXUserArr))
			];
			$B2cShop = new B2cShop();
			$B2cShop->addTiXianAccount($addData);
			LibTpl::Success('提现微信绑定成功', mvc::$cfg['HOST']['b2c'].'seller/tiXian');
		}
		//店铺已绑定的收款身份证
		$res = $B2cBase->get('sh_account_bind', ['*'], sprintf(" and acb_shop_id=%d", $_SESSION['_shopid']));
		$idcardArr = $res['data'];
		LibTpl::Set('idcardArr', $idcardArr);

		$headArr = [
			'title'=>'绑定微信提现账号-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Put();
	}

	/**
	  * @method 查看退款详情
	  * @author xu 2017/10/31
	  */
	function viewRefundBySeller()
	{
		// 检测登录状态
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();

		$OthCheck->rule('OR05');
		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();
		$B2cOrder = new B2cOrder();

		// 获取当前配件订单的退款记录
		$orpId = (int)$Params['orpId'];

		$res = $B2cBase->get("or_refund_pact",['rep_id'],sprintf(" and rep_orp_id=%d and rep_shop_id=%d order by rep_apply_time desc ",$orpId,$_SESSION['_shopid']));
		$refundPact = current($res['data']);

		if(empty($refundPact)) LibTpl::Error('退款申请记录：不存在！', '/seller/order');


		// 如果当前的配件订单的退款记录有多条，则取出并显示
		$allRepHistory = array();
		if(count($res['data'])>1)
		{
			// 获取此配件订单对应当前买家所有退款日志信息
			$res = $B2cBase->get('or_refund_pact ',['rep_id','rep_reason','rep_uid','rep_atime','rep_type','rep_status','rep_instructions','rep_confirm_time','rep_refuse_time','rep_refunded_time','rep_refuse_reason','rep_money'],sprintf(" and rep_orp_id=%d and rep_shop_id=%d and rep_status in('close','refunded') order by rep_atime desc ",$orpId,$_SESSION['_shopid']));

			$allRepHistory['repLog'] = $res['data'];
			if(!empty($allRepHistory))
			{
				$uid = current($res['data']);
				$uid = $uid['rep_uid'];
				//卖家信息
				$B2cShop = new B2cShop();
				$res = $B2cShop->getShopInfo($_SESSION['_shopid']);
				$allRepHistory['shopInfo'] = $res['data'];
				// 获取买家头像
				$YpwUser = new YpwUser();
				$res = $YpwUser->Get('yp_user', array('u_logo',), ' and u_id='.$uid, true);
				$userInfo['logo'] = $res['data']['u_logo'];
				// 获取买家名称
				$res = $B2cBase->get('us_user_base',['ub_username'],sprintf(" and ub_uid=%d ",$uid),true);
				$userInfo['username'] = $res['data']['ub_username'];
				$allRepHistory['userInof'] = $userInfo;
			}
		}
		LibTpl::Set('allRepHistory',$allRepHistory);


		// 获取当前退款申请相关信息

		$repId = $refundPact['rep_id'];
		$B2cOrder->autoRefundStatus($repId);
		$Params['repId'] = $repId;

		//获取所有退款原因
		$res = $B2cOrder->getRefundType();
		LibTpl::Set('refundType',$res['data']);

		$res = $B2cOrder->getRefundkMsg($repId);
		$repArr = $res['data'];
		// 调用接口获取倒计时
		$time =$B2cOrder->getRemaintime($repArr);
		LibTpl::Set('hasHowmuchTime',$time['data']);

		// 如果有卖家退货地址
		if(!empty($repArr['rep_refund_addr']))
		{
			LibTpl::Set("RETURN_GOD_ADDRESS",json_decode($repArr['rep_refund_addr'],true));
		}
		// 如果有买家退回的物流信息
		if(!empty($repArr['rep_express_des']))
		{
			LibTpl::Set("rep_express_des",json_decode($repArr['rep_express_des'],true));
		}
		LibTpl::Set('Params',$Params);
		LibTpl::Set('repArr',$repArr);
		LibTpl::Set('allRefundHistory', $allRefundHistory);

		$headArr = [
			'title'=>'退款申请-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);

		LibTpl::Put();
	}



	/**
	  * @method 查看某一记录退款详情
	  * @author xu 2018/1/2
	  */
	function viewOneRef()
	{
		// 检测登录状态
		$OthCheck = new OthCheck();
		$OthCheck->mustLogin();
		$OthCheck->rule('OR05');
		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();
		$B2cOrder = new B2cOrder();

		// 参数
		if(empty($Params['repId']) || !LibFc::Int($repId = $Params['repId'])) LibTpl::Error('参数错误！', '/seller/order');
		// 退款信息确认
		$res = $B2cBase->get("or_refund_pact",['rep_id'],sprintf(" and rep_id=%d and rep_shop_id=%d and rep_status in('close','refunded') order by rep_apply_time desc ",$repId,$_SESSION['_shopid']),true);
		if(empty($res['data'])) LibTpl::Error('退款申请记录：不存在！', '/seller/order');
		$repId = $res['data']['rep_id'];
		// 系统自动处理申请退款状态
		$B2cOrder->autoRefundStatus($repId);

		//获取所有退款原因
		$res = $B2cOrder->getRefundType();
		LibTpl::Set('refundType',$res['data']);
		// 退款详情
		$res = $B2cOrder->getRefundkMsg($repId);
		$repArr = $res['data'];
		// 倒计时
		$time =$B2cOrder->getRemaintime($repArr);
		LibTpl::Set('hasHowmuchTime',$time['data']);

		// 如果有卖家退货地址
		if(!empty($repArr['rep_refund_addr'])) LibTpl::Set("RETURN_GOD_ADDRESS",json_decode($repArr['rep_refund_addr'],true));

		// 如果有买家退回的物流信息
		if(!empty($repArr['rep_express_des'])) LibTpl::Set("rep_express_des",json_decode($repArr['rep_express_des'],true));

		$Params['repId'] = $repId;
		LibTpl::Set('Params',$Params);
		LibTpl::Set('repArr',$repArr);

		$headArr = [
			'title'=>'退款记录-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);

		LibTpl::Put('seller/viewRefundBySeller.php');
	}







	/**
	  * @method 卖家同意退款申请
	  * @author xu 2017/10/31
	  */
	function agreOnlyMoneyRefund()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR05');
		$B2cBase = new B2cBase();
		// 参数校验
		if(empty($_POST['repId'])||!LibFc::Int($repId=$_POST['repId'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		// 退款信息确认
		$res = $B2cBase->get("or_refund_pact",['rep_id'],sprintf(" and rep_id=%d and rep_shop_id=%d and rep_status!='close' and rep_type!=2",$repId,$_SESSION['_shopid']),true);
		if(empty($res['data'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'退款申请记录不存在！']);
		// 退款完成
		$B2cOrder = new B2cOrder();
		$B2cOrder->refundCompleted($repId);
		// 退款日志
		$logArr = [
			'rel_rep_id'=>$repId,
			'rel_txt'=>'商家同意退款给买家,资金将按照原路返回。',
			'rel_utype'=>0
		];
		$B2cOrder->addRefundLog($logArr);
		// 系统日志
		$B2cLog = new B2cLog();
		$temp = [
			'log_shop_id' => $_SESSION['_shopid'],
			'log_category' => 10,
			'log_txt' => '退款ID：'.$repId.' 同意退款给买家',
			'log_dataid' => $repId,
		];
		$B2cLog->addFastLog($temp);
		// 返回
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>true]);
	}



	/**
	  * @method 卖家拒绝退货申请
	  * @author xu 2017/10/31
	  */
	function denyRefund()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR05');
		// 参数
		$Params = mvc::$URL_PARAMS;
		LibTpl::Set('Params',$Params);
		if(empty($Params['repId'])||!LibFc::Int($repId = $Params['repId'])) LibTpl::Error('参数错误！');
		// 退款信息确认
		$B2cBase = new B2cBase();
		$res = $B2cBase->get('or_refund_pact',['rep_id'],sprintf(" and rep_id=%d and rep_shop_id=%d and rep_status!='close' and rep_status!='refuse'",$repId,$_SESSION['_shopid']),true);
		if(empty($res['data'])) LibTpl::Error('退款申请记录不存在！');
		// 退款详情
		$B2cOrder = new B2cOrder();
		$res = $B2cOrder->getRefundkMsg($repId);
		LibTpl::Set('repArr',$res['data']);
		//退款原因
		$res = $B2cOrder->getRefundType();
		LibTpl::Set('refundType',$res['data']);

		$headArr = [
			'title'=>'卖家处理退款申请-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','order');
		LibTpl::Put();
	}


	/**
	  * @method 卖家允许买家退货
	  * @author xu 2017/10/31
	  */
	function agreRefund()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR05');
		$B2cBase = new B2cBase();
		// 获取GET参数
		$Params = mvc::$URL_PARAMS;
		LibTpl::Set('Params',$Params);
		if(empty($Params['repId'])||!LibFc::Int($repId = $Params['repId'])) LibTpl::Error('参数错误！');
		// 退款信息确认
		$res = $B2cBase->get('or_refund_pact',['rep_id'],sprintf(" and rep_id=%d and rep_shop_id=%d and rep_status!='close'",$repId,$_SESSION['_shopid']),true);
		if(empty($res['data'])) LibTpl::Error('退款申请记录不存在！');
		// 退款详情
		$B2cOrder = new B2cOrder();
		$res = $B2cOrder->getRefundkMsg($repId);
		LibTpl::Set('repArr',$res['data']);
		//退款原因
		$res = $B2cOrder->getRefundType();
		LibTpl::Set('refundType',$res['data']);
		// 卖家退款地址
		$B2cAddr = new B2cAddr();
		$res = $B2cAddr->getMyListSeller($_SESSION['_shopid']);
		LibTpl::Set('addrList',$res['data']);
		$headArr = [
			'title'=>'配件退款详情-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','order');
		LibTpl::Put();
	}


	/**
	 * @method  卖家同意用户的换货申请
	 * @author xu
	 * @copyright 2017-10-31
	 */
	public function agreBuyerRefund()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR05');
		$B2cBase = new B2cBase();
		$YpwAddr = new YpwAddr();
		// 参数
		if(empty($_POST['repId']) || !LibFc::Int($repId = $_POST['repId'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		// 退款信息确认
		$orRefundPact = $B2cBase->get('or_refund_pact',['rep_id','rep_orp_id'],sprintf(" and rep_id=%d and rep_shop_id=%d and rep_status!='close' ",$repId,$_SESSION['_shopid']),true);
		if(empty($orRefundPact['data'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'售后申请记录不存在！']);
		// 入库
		$addr = $B2cBase->get('sh_address',['addr_name','addr_pct_ids','addr_address','addr_tel','addr_mobile','addr_zip'],sprintf(' and addr_id=%d and addr_shop_id=%d',$_POST['addrId'],$_SESSION['_shopid']),true);
		$res = $YpwAddr->getAddrByIds($addr['data']['addr_pct_ids']);
		// print_r($res);
		// die;
		$sellerdes = empty($_POST['sellerdes'])?'':urlencode(LibFc::Escape($_POST['sellerdes']));
		// json_encode中文UNICODE转码问题
		$temp = array(
			'name'=>urlencode($addr['data']['addr_name']),
			'address'=>urlencode($addr['data']['addr_address']),
			'pathname'=>urlencode(implode('', $res['data'])),
			'mobile'=> $addr['data']['addr_mobile'],
			'sellerdes'=>$sellerdes
		);
		$tmp = array(
			'rep_confirm_time'=>time(),
			'rep_refund_addr'=>urldecode(json_encode($temp)),
			'rep_status'=>'confirm',
		);
		// print_r($tmp);
		// die;
		$B2cBase->set("or_refund_pact",$tmp,sprintf(" and rep_id=%d and rep_shop_id=%d ",$repId,$_SESSION['_shopid']));
		$B2cBase->set("or_order_product",['orp_refund_status'=>'confirm '],sprintf(" and orp_id=%d ",$orRefundPact['data']['rep_orp_id']));
		// 退款日志
		$logArr = [
			'rel_rep_id'=>$repId,
			'rel_txt'=>'商家同意申请</br>收件人：'.urldecode($temp['name']).'</br>收件地址：'.urldecode($temp['name']).'，'.urldecode($temp['mobile']).'，'.urldecode($temp['pathname']).urldecode($temp['address']).'</br>说明：'.($sellerdes ? urldecode($sellerdes):'无'),
			'rel_utype'=>0
		];
		$B2cOrder = new B2cOrder();
		$B2cOrder->addRefundLog($logArr);
		// 系统日志
		$B2cLog = new B2cLog();
		$temp = [
			'log_shop_id' => $_SESSION['_shopid'],
			'log_category' => 10,
			'log_txt' => '退款ID：'.$repId.' 同意换货申请',
			'log_dataid' => $repId,
		];
		$B2cLog->addFastLog($temp);
		// 返回true
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>true]);

	}

	/**
	 * @method 卖家拒绝用户的退款申请
	 * @author xu
	 * @copyright 2017-11-3
	 */
	public function subRejectBuyerApply()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		// 权限校验
		$OthCheck->rule('OR05');
		$B2cBase = new B2cBase();
		$B2cOrder = new B2cOrder();
		// 参数
		if(empty($_POST['repId']) || !LibFc::Int($repId=$_POST['repId']) || empty($_POST['des']) || empty($_POST['reson']))
		LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		$des = LibFc::Escape($_POST['des']);
		$reson = LibFc::Escape($_POST['reson']);
		// 退款信息确认
		$res = $B2cBase->get('or_refund_pact',['rep_orp_id'],sprintf(" and rep_id=%d and rep_shop_id=%d and rep_status!='close' ",$repId,$_SESSION['_shopid']),true);
		if(empty($res['data'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'退款申请记录不存在！']);
		$orpId = $res['data']['rep_orp_id'];
		// 入库
		$temp = array(
			'rep_status'=>'refuse',
			'rep_refuse_reason'=>'原因：'.$reson.'，说明：'.$des,
			'rep_refuse_time'=>time(),
			'rep_express_des'=>''
		);
		$B2cBase->set('or_refund_pact',$temp,sprintf(" and rep_id=%d and rep_shop_id=%d and rep_status!='close' ",$repId,$_SESSION['_shopid']));
		$B2cBase->set('or_order_product',['orp_refund_status'=>'refuse'],sprintf(" and orp_id=%d ",$orpId));
		// 退款日志
		$logArr = [
			'rel_rep_id'=>$repId,
			'rel_txt'=>'卖家拒绝了退款申请：</br>原因：'.$reson.'</br>说明：'.($des ? $des:'无'),
			'rel_utype'=>0
		];
		$B2cOrder->addRefundLog($logArr);
		// 系统日志
		$B2cLog = new B2cLog();
		$temp = [
			'log_shop_id' => $_SESSION['_shopid'],
			'log_category' => 10,
			'log_txt' => '退款ID：'.$repId.' 拒绝退款申请',
			'log_dataid' => $repId,
		];
		$B2cLog->addFastLog($temp);
		// 返回
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>true]);
	}


	/**
	 * @method 卖家同意用户的退款申请
	 * @author xu
	 * @copyright 2017-11-3
	 */
	public function refundCompleted()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR05');
		$B2cBase = new B2cBase();
		$B2cOrder = new B2cOrder();
		// 参数
		if(empty($_POST['orpId']) || !LibFc::Int($_POST['orpId']) || empty($_POST['orderId']) || !LibFc::Int($_POST['orderId'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		$orpId = $_POST['orpId'];
		$orderId = $_POST['orderId'];
		// 配件订单状态确认
		$res = $B2cBase->get("or_order_product left join or_order on orp_ord_id=ord_id ",['ord_shop_id','orp_status'],sprintf(" and orp_id=%d and ord_id=%d and ord_shop_id=%d ",$orpId,$orderId,$_SESSION['_shopid']),true);
		$res = $res['data'];
		if(empty($res) || $res['orp_status']!='refund') LibFc::ajaxJsonEncode(['status'=>false,'data'=>'配件订单不存在！']);
		// 退款信息确认
		$res = $B2cBase->get('or_refund_pact',['rep_id','rep_status'],sprintf(" and rep_ord_id=%d and rep_orp_id=%d ",$orderId,$orpId),true);
		if(empty($res['data'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'退款申请记录不存在！']);
		// 完成退款
		$B2cOrder->refundCompleted($res['data']['rep_id']);
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>true]);
	}


	/**
	 * @method 卖家留言
	 * @author xu
	 * @copyright 2017-11-8
	 */
	public function addTalkHistory()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR05');
		$B2cBase = new B2cBase();
		$B2cOrder = new B2cOrder();
		// 参数
		if(empty($_POST['repId']) || !LibFc::Int($_POST['repId']) || empty($_POST['content'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		$content = LibFc::Escape($_POST['content']);
		$repId = $_POST['repId'];

		$res = $B2cBase->get("or_refund_pact",['rep_orp_id'],sprintf(" and rep_id=%d and rep_shop_id=%d and rep_status!='close' ", $repId, $_SESSION['_shopid']),true);
		if(empty($res['data'])) LibFc::ajaxJsonEncode(['status'=>true,'data'=>'退款申请记录不存在！']);
		// 记录日志信息
		$logArr = [
			'rel_rep_id'=>$repId,
			'rel_txt'=>$content,
			'rel_utype'=>0
		];
		$B2cOrder->addRefundLog($logArr);
		// 直接返回true
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>true]);
	}
	/**
	 * @method    获取店铺的参数列表
	 * @author 卢
	 * @copyright 2017-11-14
	 */
	public function getParamTpl()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cProduct=new B2cProduct();
		$B2cBase=new B2cBase();
		$res=$B2cBase->get('bc_product_para_tpl',['ppt_id','ppt_name'],sprintf(' and ppt_shop_id=%d order by ppt_seq asc',$_SESSION['_shopid']));
		$tplArr=array_column($res['data'], 'ppt_id');
		LibTpl::Set('list',$res['data']);
		$data=LibTpl::Fetch('/seller/proParamListTpl.php');
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$data]);
	}
	/**
	 * @method    点击模板获取参数
	 * @author 卢
	 * @copyright 2017-11-27
	 */
	public function ajaxGetParams()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase=new B2cBase();
		$Params = mvc::$URL_PARAMS;
		$tplId=$Params['tplId']?(int)$Params['tplId']:0;
		$res=['status'=>false,'data'=>'获取模板参数失败'];
		if($tplId>0)
		{
			$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));
			// print_r($newlink);
			$res=['status'=>true,'data'=>$newlink['data']];
		}
		LibFc::ajaxJsonEncode($res);
	}
	/**
	 * @method    根据模板ID获取参数
	 * @author 卢
	 * @copyright 2017-11-14
	 */
	public function getParamByTplId()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$B2cBase=new B2cBase();
		$result=['status'=>false,'data'=>'参数模板错误'];
		$tplId = empty($Params['tplId']) ? 0: (int) $Params['tplId'];
		$proId = empty($Params['proId']) ? 0: (int) $Params['proId'];
		if($tplId > 0)
		{
			$oldValArr = [];
			if($proId>0)
			{
				$oriTplData=$B2cBase->get('bc_product',['pro_ppt_id'],sprintf(' and pro_id=%d and pro_shop_id=%d',$proId, $_SESSION['_shopid']),true);
				//有值的
				$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_shop_id=%d and (prpv_value is not null or prpv_value!='')", $proId, $_SESSION['_shopid']));
				// print_r($res);

				$oldValArr=array_column($res['data'], null,'prpv_prl_id');
			}
			//新的
			$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);
			// die;
			if(count($oldValArr))
			{
				foreach ($oldValArr as $k => $v)
				{
					if(isset($newArr[$k]))
					{
						$newArr[$k]=array_merge($v,$newArr[$k]);
						continue;
					}
					if($oriTplData['data']['pro_ppt_id']==$tplId)
					{
						$newArr[$k]=$v;
					}
				}
			}
			// print_r($newArr);
			LibTpl::Set('paraArr',$newArr);
			$data=LibTpl::Fetch('/seller/proTplParam.php');
			$result=['status'=>true,'data'=>$data];
		}
		LibFc::ajaxJsonEncode($result);
	}
	/**
	 * @method    ajax添加/修改模板
	 * @author 卢
	 * @copyright 2017-11-15
	 */
	public function ajaxAddParamsTpl()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cProduct=new B2cProduct();
		$params=[];
		$res=['status'=>false,'data'=>'添加失败'];
		// print_r($_POST);
		if(!empty($_POST))
		{
			if(!empty($_POST['label']))
			{
				foreach ($_POST['label'] as $k => $v)
				{
					if(empty(trim($v))) continue;
					$params[]=['name'=>$v,'seq'=>($_POST['seq'][$k]?$_POST['seq'][$k]:999),'unit'=>$_POST['unit'][$k]];
				}
				if(count($params))
				{
					if($_POST['tplId'])
					{
						$res=$B2cProduct->editProParamsTpl($_POST['tplId'],$_POST['tplName'],$params,$_SESSION['_shopid']);
					}
					else
					{
						$res=$B2cProduct->addProParamsTpl($_POST['tplName'],'999',$params,$_SESSION['_shopid']);
					}
				}
			}
		}
		LibFc::ajaxJsonEncode($res);
	}
	/**
	 * @method    ajax 管理模版/删除 /排序
	 * @author	  廖
	 * @copyright 2017-11-16
	 */
	function ajaxManegeParamsTpl()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$status = false;
		$data = '参数不正确！';
		$B2cProduct=new B2cProduct();
		//参数模版排序
		if(!empty($_POST['sort']))
		{
			$res = $B2cProduct->resetProParamsTplSort($_SESSION['_shopid'],$_POST['sort']);
			if($res['status']) $status = true;
		}
		//删除参数模版
		if(!empty(trim($_POST['delTplId'],',')))
		{
			$res = $B2cProduct->delProParamsTpl(explode(',', trim($_POST['delTplId'],',')),$_SESSION['_shopid']);
			if($res['status']) $status = true;
		}
		if($status) $data = true;
		LibFc::ajaxJsonEncode(['status'=>$status,'data'=>$data]);
	}
	/**
	 * @method 配件参数模板
	 * @author xu
	 * @copyright 2017-11-14
	 */
	public function productParms()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		// 获取所有当前配件参数模板
		$B2cBase = new B2cBase();
		$res = $B2cBase->get('bc_product_para_tpl',['*'],sprintf(" and ppt_shop_id=%d order by ppt_seq asc ",$_SESSION['_shopid']));
		LibTpl::Set('dataArr',$res['data']);

		$headArr = [
			'title'=>'配件参数模板-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','productParms');
		LibTpl::Put();
	}

	/**
	 * @method 添加配件参数模板
	 * @author xu
	 * @copyright 2017-11-14
	 */
	public function addProParms()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		$B2cProduct = new B2cProduct();
		// var_dump($_SERVER);die;REQUEST_METHOD
		if($_SERVER['REQUEST_METHOD']=='POST')
		{
			// 保存数据
			$tplName = LibFc::Escape($_POST['ppt_name']);
			$params = $_POST['params'];
			if($tplName !="" && !empty($params))
			{
				$B2cProduct->addProParamsTpl($tplName,99,$params,$_SESSION['_shopid']);
				LibFc::Go('/seller/productParms');
			}
		}
		$headArr = [
			'title'=>'添加配件参数模板-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','productParms');
		LibTpl::Put();
	}
	/**
	 * @method 商家删除自己的配件参数模板
	 * @author xu
	 * @copyright 2017-11-14
	 */
	public function delThisParmTpl()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cProduct = new B2cProduct();
		// 执行
		if(empty($_POST['pptId']) || !LibFc::Int($pptId=$_POST['pptId'])) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		$B2cProduct->delProParamsTpl($pptId,$_SESSION['_shopid']);
		// 返回true
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>true]);
	}


	/**
	 * @method 编辑配件参数模板
	 * @author xu
	 * @copyright 2017-11-15
	 */
	public function editThisParmTpl()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		$B2cProduct = new B2cProduct();
		$Params = mvc::$URL_PARAMS;
		LibTpl::Set('Params',$Params);
		if(empty($Params['pptId'])||!LibFc::Int($pptId = $Params['pptId'])) LibTpl::error('参数错误！','/seller/productParms');
		// 保存
		if($_SERVER['REQUEST_METHOD']=='POST')
		{
			$pptId = (int)$_POST['ppt_id'];
			$pptName = LibFc::Escape($_POST['ppt_name']);
			$params = $_POST['params'];
			if(empty($params) || !$pptId || $pptName=="") LibTpl::error('参数错误！','/seller/productParms');
			$B2cProduct->editProParamsTpl($pptId,$pptName,$params,$_SESSION['_shopid']);
		}


		// 获取配件参数模板的所有数据
		$res = $B2cBase->get('bc_product_para_tpl left join bc_product_para_tpl_link on pptl_ppt_id=ppt_id ',['*'],sprintf(" and ppt_shop_id=%d and ppt_id=%d order by pptl_seq asc ",$_SESSION['_shopid'],$pptId));
		$pptMsg = $res['data'];
		if(empty($pptMsg))
		{
			LibTpl::error('参数错误！','/seller/productParms');
		}
		LibTpl::Set('tpl',current($pptMsg));
		// 获取所有的参数名称以及单位名称
		$allLable = array();
		$allUnit = array();
		foreach ($pptMsg as $k => $v)
		{
			$allLable[] = $v['pptl_prl_id'];
			$allUnit[] = $v['pptl_pru_id'];
		}
		// 对单位去除空值
		foreach ($allUnit as $k => $v)
		{
			if(!$v)
			{
				unset($allUnit[$k]);
			}
		}
		$allUnitToName = array();
		// 获取所有单位
		if(!empty($allUnit))
		{
			$res = $B2cBase->get('bc_product_unit',['*'],sprintf(" and pru_id in (%s) ",implode(',', $allUnit)));
			$allUnitToName = $res['data'];
		}
		// 获取所有参数
		$res = $B2cBase->get('bc_product_label',['*'],sprintf(" and prl_id in (%s) ",implode(',', $allLable)));
		$allLableToName = $res['data'];
		// 将原数据的单位ID和参数ID换成name
		foreach ($pptMsg as $k => $v)
		{
			if(!empty($allUnitToName))
			{
				foreach ($allUnitToName as $kk => $vv)
				{
					if($v['pptl_pru_id']==$vv['pru_id'])
					{
						$pptMsg[$k]['UNIT_NAME'] = $vv['pru_name'];
					}
				}
			}
			foreach ($allLableToName as $kk => $vv)
			{
				if($v['pptl_prl_id']==$vv['prl_id'])
				{
					$pptMsg[$k]['LABEL_NAME'] = $vv['prl_name'];
				}
			}
		}

		LibTpl::Set('dataArr',$pptMsg);
		$headArr = [
			'title'=>'编辑配件参数模板-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','productParms');
		LibTpl::Put();
	}

	/**
	 * @method 更改配件参数排序
	 * @author xu
	 * @copyright 2017-11-15
	 */
	public function reSeqNum()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		// 参数
		$pptId = (int)$_POST['pptId'];
		$seq = (int)$_POST['seq'];
		if($seq<0) LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误！']);
		$B2cBase->set('bc_product_para_tpl',array('ppt_seq'=>$seq),sprintf(" and ppt_id=%d and ppt_shop_id=%d ",$pptId,$_SESSION['_shopid']));
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>true]);
	}
	/**
	 * @method    店铺配件品牌
	 * @author 卢
	 * @copyright 2017-11-17
	 */
	public function shopBrand()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('PB04');
		$B2cBrand = new B2cBrand();
		$brandData=$B2cBrand->get('sh_probrand_link left join bc_probrand on sprl_prb_id=prb_id',['prb_id','prb_name','sprl_seq'],sprintf(' and sprl_shop_id=%d order by sprl_seq asc',$_SESSION['_shopid']));
		// print_r($brandData);
		LibTpl::Set('brandList',$brandData['data']);
		$headArr = [
			'title'=>'配件品牌管理-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('LeftMenu','shopBrand');
		LibTpl::Set('headArr', $headArr);
		LibTpl::Put();
	}
	/**
	 * @method    店铺配件品牌的修改
	 * @author 卢
	 * @copyright 2017-11-17
	 */
	public function setShopBrand()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBrand = new B2cBrand();
		$Params = mvc::$URL_PARAMS;
		// print_r($_POST);
		// die;
		$res=['status'=>false,'data'=>'修改失败，请稍后重试！'];
		if($Params['type']=='seq')
		{
			$OthCheck->rule('PB02');
			//排序
			if(LibFc::Int($_POST['prbId'])&&LibFc::Int($_POST['seq']))
			{
				$res=$B2cBrand->set('sh_probrand_link',['sprl_seq'=>$_POST['seq']],sprintf(' and sprl_prb_id=%d and sprl_shop_id=%d',$_POST['prbId'],$_SESSION['_shopid']));
			}
		}
		else if($Params['type']=='add')
		{
			$OthCheck->rule('PB01');
			if(count($_POST))
			{
				foreach ($_POST['shopBrandName'] as $k => $v)
				{
					if(empty(trim($v)))
					{
						unset($_POST['shopBrandName'][$k],$_POST['prbId'][$k],$_POST['seq'][$k]);
					}
				}
				$res=$B2cBrand->setShopBrand($_SESSION['_shopid'],$_POST);
			}
			else
			{
				$res=$B2cBrand->del('sh_probrand_link',sprintf(' and sprl_shop_id=%d',$_SESSION['_shopid']));
			}
		}
		else if($Params['type']=='del')
		{
			$OthCheck->rule('PB03');
			if(count($_POST['prbCheckId']))
			{
				$res=$B2cBrand->del('sh_probrand_link',sprintf(' and sprl_prb_id in(%s) and sprl_shop_id=%d',implode(',', $_POST['prbCheckId']),$_SESSION['_shopid']));
				if($res['status']&&$res['data'])
				{
					$res=$B2cBrand->set('bc_product',['pro_prb_id'=>0],sprintf(' and pro_shop_id=%d and pro_prb_id in(%s)',$_SESSION['_shopid'],implode(',', $_POST['prbCheckId'])));
				}
			}
		}
		LibFc::ajaxJsonEncode($res);
	}




	/**
	 * @method  店铺域名设定
	 * @author xu
	 * @copyright 2017/11/23
	 */
	function domainSetting()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		LibTpl::Set('order',$order);
		$B2cBase = new B2cBase();
		//检查地区是否为空 不为空则拼接字段
		if(!empty($_POST['province']) && !empty($province=array_filter($_POST['province']))) $province = implode($province,',');
		// 店铺信息
		$res = $B2cBase->get('sh_shop',['*'],' and shop_id='.$_SESSION['_shopid'],true);
		LibTpl::Set('data',$res['data']);

		$headArr = [
			'title'=>'店铺域名设置-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('LeftMenu','shopBase');
		LibTpl::Put();
	}

	/**
	  * @method 保存用户自有域名
	  * @author xu 2017/11/23
	  */
	function saveDiyDomain()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		// 获取ajax传递过来的参数
		$domain = LibFc::Escape($_POST['name']);
		// 保存
		$B2cBase->set('sh_shop',array('shop_top_domain'=>$domain),sprintf(" and shop_id=%d ",$_SESSION['_shopid']));
		LibFc::ajaxJsonEncode(['status'=>true, 'data'=>true]);
	}


	/**
	  * @method 删除用户自有域名
	  * @author xu 2017/11/23
	  */
	function unbindDivDomain()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		// 获取ajax传递过来的参数
		$B2cBase->set('sh_shop',array('shop_top_domain'=>""),sprintf(" and shop_id=%d ",$_SESSION['_shopid']));
		LibFc::ajaxJsonEncode(['status'=>true, 'data'=>true]);
	}
	/**
	 * @method    刷新获取店铺分类
	 * @author 卢
	 * @copyright 2017-12-19
	 */
	function refreshSort()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$hasShopSortId=[];
		$B2cShopSort = new B2cShopSort();
		if((int)$Params['proId'])
		{
			$B2cBase = new B2cBase();
			//店铺分类
			$res = $B2cBase->getFieldUniVal('bc_product_sort', 'prs_sort_id', sprintf(" and prs_pro_id=%d", $Params['proId']));
			$hasShopSortId = $res['data'];
			// print_r($hasShopSortId);
			//店铺分类
		}
		$res = $B2cShopSort->getShopSortZtree($_SESSION['_shopid'], $hasShopSortId, false);
		LibFc::ajaxJsonEncode($res);
	}
	/**
	 * @method    保存草稿
	 * @author 卢
	 * @copyright 2018-01-11
	 */
	function saveDraft()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$proId=(int)$Params['proId'];
		$res=['status'=>false,'data'=>'保存失败，请稍后重试'];
		if(is_numeric($proId))
		{
			$B2cBase = new B2cBase();
			$text=json_encode($_POST,JSON_UNESCAPED_UNICODE);
			$res=$B2cBase->get('bc_product_draft',['prda_id'],sprintf(" and prda_text_md5='%s' and prda_pro_id=%d and prda_shop_id=%d",md5($text),$proId,$_SESSION['_shopid']),true);
			if(count($res['data']))
			{
				$result=$B2cBase->set('bc_product_draft',['prda_etime'=>time()],sprintf(' and prda_id=%d and prda_shop_id=%d',$res['data']['prda_id'],$_SESSION['_shopid']));
				$res=['status'=>true,'data'=>'edit'];
			}
			else
			{
				$target=[
					'prda_pro_id'=>$proId,
					'prda_shop_id'=>$_SESSION['_shopid'],
					'prda_name'=>$Params['draftName'],
					'prda_text'=>$text,
					'prda_atime'=>time(),
					'prda_text_md5'=>md5($text),
					'prda_etime'=>time()
				];
				$res = $B2cBase->add('bc_product_draft',$target,['prda_text']);
				$draftId=$res['data'];
				$res=['status'=>true,'data'=>'add'];
			}
		}
		LibFc::ajaxJsonEncode($res);
	}
	/**
	 * @method    获取草稿列表
	 * @author 卢
	 * @copyright 2018-01-11
	 */
	function getDraft()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$proId=(int)$Params['proId'];
		$result=['status'=>false,'data'=>'获取草稿列表失败，请稍后重试'];
		if(is_numeric($proId))
		{
			$B2cBase = new B2cBase();
			$result=$B2cBase->get('bc_product_draft',['prda_id','prda_name','prda_etime','prda_text'],sprintf(' and prda_pro_id=%d and prda_shop_id=%d order by prda_etime desc',$proId,$_SESSION['_shopid']));
			foreach ($result['data'] as $k => $v)
			{
				$result['data'][$k]['prda_etime']=date('Y-m-d H:i:s',$v['prda_etime']);
				$text=json_decode($v['prda_text'],true);
				$result['data'][$k]['path']=$text['pro']['part_path'];
				unset($result['data'][$k]['prda_text']);
			}
		}
		LibFc::ajaxJsonEncode($result);
	}
	/**
	 * @method    恢复草稿
	 * @author 卢
	 * @copyright 2018-01-11
	 */
	function recoveryDraft()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$proId=(int)$Params['proId'];
		$draId=(int)$Params['draId'];
		$result=['status'=>false,'data'=>'恢复配件草稿失败，请返回重试'];
		if(is_numeric($proId)&&$draId)
		{
			$B2cBase = new B2cBase();
			$B2cProduct= new B2cProduct();
			if($proId>0)
			{
				$draftWhere=sprintf(' and prda_id=%d and prda_pro_id=%d and prda_shop_id=%d',$draId,$proId,$_SESSION['_shopid']);
			}
			else
			{
				$draftWhere=sprintf(' and prda_id=%d and prda_shop_id=%d',$draId,$_SESSION['_shopid']);
			}
			$res=$B2cBase->get('bc_product_draft',['prda_id','prda_name','prda_etime','prda_text'],$draftWhere,true);
			$result['status']=true;
			$drafData=json_decode($res['data']['prda_text'],true);
			//处理图片
			if(isset($drafData['imgs']))
			{
				$imgArr=array_filter($drafData['imgs'],"LibFc::Int");
				if(count($imgArr))
				{
					$imgData=$B2cBase->get('sh_pic',['spi_id','spi_path','spi_name','spi_ext'],sprintf(' and spi_id in(%s) and spi_shop_id=%d',implode(',', $imgArr),$_SESSION['_shopid']));
					foreach ($imgData['data'] as $k => $v)
					{
						$drafData['imgInfo'][$v['spi_id']]=mvc::$cfg['FILE_CENTER']['b2c']['url_get'].'&c=product&f='.$v['spi_path'].'100/'.$v['spi_name'].'.'.$v['spi_ext'].mvc::$cfg['FILE_CENTER']['b2c']['get_uri'];
					}
				}
			}
			//处理自定义参数
			if(isset($drafData['paramLabel']))
			{
				$temp=[];
				foreach ($drafData['paramLabel'] as $k => $v)
				{
					$temp[$v]['labelId']=$v;
					isset($drafData['paramUnit'][$k]) &&($temp[$v]['unitId']=$drafData['paramUnit'][$k]);
					isset($drafData['paramVal'][$k]) &&($temp[$v]['val']=$drafData['paramVal'][$k]);
				}
				$labelArr=array_filter($drafData['paramLabel'],"LibFc::Int");
				$unitArr=array_filter($drafData['paramUnit'],"LibFc::Int");
				$label=[];
				$unit=[];
				if(count($labelArr))
				{
					$labelData=$B2cBase->get('bc_product_label',['prl_id','prl_name'],sprintf(' and prl_id in(%s)',implode(',',$labelArr)));
					$label=array_column($labelData['data'], null,'prl_id');
				}
				if(count($unitArr))
				{
					$unitData=$B2cBase->get('bc_product_unit',['pru_id','pru_name'],sprintf(' and pru_id in(%s)',implode(',',$unitArr)));
					// print_r($unitData);
					$unit=array_column($unitData['data'], null,'pru_id');
				}
				foreach ($temp as $k => $v)
				{
					$temp[$k]['label']=isset($label[$v['labelId']])?$label[$v['labelId']]['prl_name']:'';
					$temp[$k]['unit']=isset($unit[$v['unitId']])?$unit[$v['unitId']]['pru_name']:'';
				}
				$drafData['proParams']=$temp;
			}
			// 处理号码
			if(isset($drafData['num'])&&count($drafData['num']))
			{
				$res = $B2cBase->get('bc_number', ['num_id', 'num_factory', 'num_display', 'num_format', 'num_ismain'], sprintf(" and num_self=0 and num_id in(%s) order by num_factory, num_format", implode(',',array_keys($drafData['num']))));
				$res['data']=array_column($res['data'], null,'num_id');
				foreach ($drafData['num'] as $k => $v)
				{
					$drafData['num'][$k]['uninum']=isset($res['data'][$k])?strtoupper(LibFc::formatStr($v['factory'], 1).'@'.$res['data'][$k]['num_format']):'@';
					$drafData['num'][$k]['numid']=$k;
					$drafData['num'][$k]['factoryName']='num['.$k.'][factory]';
					$drafData['num'][$k]['displayName']='num['.$k.'][display]';
				}
				$drafData['num']=array_merge($drafData['num']);
			}
			//处理车型
			$ComModel = new ComModel();
			$where = 'order by brand_seq, brand_initial, make_seq, make_initial, mod1_name, mod2_name, mod3_name';
			$res = $ComModel->getModel(3, ['mod3_id'], $where);
			if(count($res['data']))
			{
				$drafData['modIdArr']=array_column($res['data'], 'mod3_id');
			}
			$result['data']=$drafData;
			// print_r($result);
		}
		LibFc::ajaxJsonEncode($result);
	}
	/**
	 * @method    店铺装修预览配置文件生成
	 * @author 卢
	 * @copyright 2018-01-03
	 */
	public function itemPreview()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SD00');
		$data=['status'=>false,'data'=>'预览失败，请稍后重试！'];
		if(count($_POST))
		{
			// print_r($_POST);
			// die;
			$view=$_POST['view-page'];
			$B2cShop= new B2cShop();
			$res=$B2cShop->editDesignConfig($_SESSION['_shopid'],$view,$_POST,true);
			// print_r($res);
			// die;
			$pageConfig=require(mvc::$cfg['ROOT'].'shop/'.$_SESSION['_shopid'].'/page.config.php');
			$inArr=['index','search','item'];
			foreach ($inArr as $v)
			{
				if($view==$v)
					continue;
				$res['data']['tplName']=$_POST['tplName'];
				$res['data'][$v.'/index']=$pageConfig[$v.'/index'];
				$res['data'][$v.'/index']['layout']=explode('/', $pageConfig['layout'])[0].'/'.$_POST['type'].'.php';
			}
			// LibFc::ArraySave($res['data'],mvc::$cfg['ROOT'].'shop/'.$_SESSION['_shopid'].'/page.config.php');
			// print_r($res['data']);
			// die;
			$result=LibFc::ArraySave($res['data'],mvc::$cfg['ROOT'].'shop/'.$_SESSION['_shopid'].'/preview.config.php');
			if($result)
			{
				$data=['status'=>true,'data'=>true];
			}
		}
		LibFc::ajaxJsonEncode($data);
	}
	/**
	 * @method    店铺装修预览模板
	 * @author 卢
	 * @copyright 2018-01-03
	 */
	public function previewTpl()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SD00');
		$Params = mvc::$URL_PARAMS;
		if(!in_array($Params['viewPage'], ['index','item','search']))
		{
			LibTpl::Error('预览信息错误');
			exit();
		}
		$view=isset($Params['viewPage'])?$Params['viewPage']:'index';
		if($view=='item'&&!isset($Params['proId']))
		{
			$B2cProduct=new B2cProduct();
			$pro=$B2cProduct->getProduct(['pro_id'],sprintf(' and pro_shop_id=%d order by pro_add_time desc',$_SESSION['_shopid']),true);
			if(!count($pro['data']))
			{
				LibTpl::Error('请先添加配件','/seller/productPart');
				exit();
			}
			$url='/seller/previewTpl?viewPage='.$view.'&proId='.$pro['data']['pro_id'];
			LibFc::Go($url);
			exit();
		}
		//系统模快
		// $sysModule=$sysModuleArr=include(mvc::$cfg['ROOT_SHOP_SYS'].'module.config.php');
		$pageConfigAll =include(mvc::$cfg['ROOT'].'shop/'.$_SESSION['_shopid'].'/preview.config.php');
		$pageConfing = $pageConfigAll[$view.'/index'];
		$tplName=empty($pageConfigAll['tplName'])?'tpl01':$pageConfigAll['tplName'];
		$Params['tplName']=empty($Params['tplName'])?$tplName:$Params['tplName'];
		mvc::$cfg['tplName']=$Params['tplName'];
		$layout=explode('.', explode('/',$pageConfing['layout'])[1])[0];
		LibTpl::Set('module',$view.'/index');
		// print_r($pageConfing);
		//头部和底部公共模块配置
		$pageConfing['modules']['top'] = $pageConfigAll['public']['top'];
		$pageConfing['modules']['foot'] = $pageConfigAll['public']['foot'];

		//模块配置
		$pageData = [];

		//店铺基本信息、店铺名称、域名等提前加载
		$ShopBase = new ShopBase();
		$shopInfo = $ShopBase->getShopInfo($_SESSION['_shopid']);
		LibTpl::Set('shopInfoData', $shopInfo);

		$sysModule = require(mvc::$cfg['ROOT_SHOP_SYS'].'module.config.php');
		//加载该店铺的模块数据
		$htmlArr = [];
		$shopCssJs = ['css'=>[], 'js'=>[]];
		foreach ($sysModule as $module)
		{
			$js=isset($module['js'])?$module['js']:[];
			$css=isset($module['css'])?$module['css']:[];
			$shopCssJs['css'] = array_merge($shopCssJs['css'], $css);
			$shopCssJs['js'] = array_merge($shopCssJs['js'], $js);
		}
		foreach($pageConfing['modules'] as $location=>$moduleArr)
		{
			$htmlArr[$location] = [];
			//此位置的所有模块
			foreach($moduleArr as $k=> $moduleConfig)
			{
				$res = $ShopBase->getModuleHtml($_SESSION['_shopid'], $moduleConfig);
				// print_r($res);
				$htmlArr[$location][] = $res['html'];
				$shopCssJs['css']=$shopCssJs['css']+$res['css'];
				$shopCssJs['js'] =$shopCssJs['js']+ $res['js'];
			}
		}
		LibTpl::Set('sysModule', $sysModule);
		LibTpl::Set('pageConfing', $pageConfing);
		LibTpl::Set('htmlArr',$htmlArr);
		// print_r($htmlArr);
		//加载模块样式和JS
		$shopCssJs['css'] = array_unique($shopCssJs['css']);
		$shopCssJs['js'] = array_unique($shopCssJs['js']);
		// print_r($shopCssJs);
		LibTpl::Set('shopCssJs', $shopCssJs);
		unset($sysModule['shopInfo'],$sysModule['banner'],$sysModule['menu'],$sysModule['itemInfo'],$sysModule['itemDes'],$sysModule['foot']);
		LibTpl::Set('moduleList',$sysModule);
		$headArr = array(
			'title'=>'店铺装修-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		$this->HEAD_CSSJS['plugin'][] = 'webuploader';
		$this->HEAD_CSSJS['plugin'][] = 'ueditor';
		$this->HEAD_CSSJS['plugin'][] = 'typeahead';
		$this->HEAD_CSSJS['plugin'][] = 'zTree';
		//添加图片放大镜
		$this->HEAD_CSSJS['js'][] = 'js/jquery.imagezoom.min.js';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('headArr', $headArr);
		switch ($view)
		{
			case 'item':
				LibTpl::Put('/seller/previewItem.php');
				break;
			default:
				if($layout=='111')
				{
					LibTpl::Put('seller/previewTpl_111.php');
				}
				else
				{
					LibTpl::Put();
				}
				break;
		}
	}






	/**
	  * @method 卖家售后历史记录 ?orpId=xxx
	  * @author xu 2018/01/08
	  */
	public function viewRefundHistory()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR05');
		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();
		$B2cOrder = new B2cOrder();
		// 参数
		if(empty($Params['orpId']) || !LibFc::Int($Params['orpId'])) LibTpl::Error('参数错误！', '/seller/order');
		// 退款记录
		$orpId = $Params['orpId'];
		$res = $B2cBase->get("or_refund_pact left join or_order_product on orp_id=rep_orp_id left join or_order on ord_id=orp_ord_id ",['*'],sprintf(" and rep_orp_id=%d and rep_shop_id=%d and rep_status in ('close','refunded') order by rep_atime desc ", $orpId, $_SESSION['_shopid']));
		$repArr = $res['data'];
		if(empty($repArr)) LibTpl::Error('参数错误！', '/seller/order');
		// 取一条即可获取买家卖家之间信息
		$firstRep = current($repArr);
		$allRepId = array_column($repArr, 'rep_id');
		// 日志
		$res = $B2cBase->get("or_refund_log",['*'],sprintf(" and rel_rep_id in(%s) order by rel_atime desc ",implode(',', $allRepId)));
		$res = $res['data'];
		// 拼接退款记录和日志
		foreach ($repArr as $k => $v)
		{
			foreach ($res as $kk => $vv)
			{
				if($vv['rel_rep_id']==$v['rep_id'])
				{
					$repArr[$k]['log'][] = $vv;
				}
			}
		}
		LibTpl::Set('repArr',$repArr);
		//所有退款原因
		$res = $B2cOrder->getRefundType();
		LibTpl::Set('refundType',$res['data']);
		//配件图片
		$B2cProduct = new B2cProduct;
		$res = $B2cProduct->getProductPic([$firstRep['orp_pro_id']]);
		$res = isset($res['data'][$firstRep['orp_pro_id']])?current($res['data'][$firstRep['orp_pro_id']]):array();
		LibTpl::Set('proPic',$res);
		//卖家信息
		$B2cShop = new B2cShop();
		$res = $B2cShop->getShopInfo($firstRep['ord_shop_id']);
		LibTpl::Set('shopInfo',$res['data']);
		// 买家头像
		$YpwUser = new YpwUser();
		$res = $YpwUser->Get('yp_user', array('u_logo',), ' and u_id='.$firstRep['ord_uid'], true);
		$userInfo['logo'] = $res['data']['u_logo'];
		// 买家名称
		$res = $B2cBase->get('us_user_base',['ub_username'],sprintf(" and ub_uid=%d ",$firstRep['ord_uid']),true);
		$userInfo['username'] = $res['data']['ub_username'];
		LibTpl::Set('userInfo',$userInfo);
		// 设置meta信息
		$headArr = [
			'title'=>'售后详情-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Put();
	}
	/**
	 * @method    删除配件草稿
	 * @author 卢
	 * @copyright 2018-03-15
	 */
	function deleteDraf()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('PC03');
		$Params = mvc::$URL_PARAMS;
		$res=['status'=>false,'data'=>'删除失败。请稍后重试！'];
		if(LibFc::Int($Params['draftId']))
		{
			$B2cBase=new B2cBase();
			$res=$B2cBase->del('bc_product_draft',sprintf(' and prda_id=%d and prda_shop_id=%d',$Params['draftId'],$_SESSION['_shopid']));
		}
		LibFc::ajaxJsonEncode($res);
	}

	/*
	 *ajax获取退货物流信息
	 */
	function ajaxGetRefundLogic()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('OR05');
		//获取最新物流信息
		if(LibFc::Int($_POST['repId']))
		{
			$B2cBase = new B2cBase();
			$res = $B2cBase->get('or_refund_pact',['rep_express_des'],sprintf('and rep_id=%d and rep_shop_id=%d and rep_type>0',$_POST['repId'],$_SESSION['_shopid']),true);
			if(!empty($res['data'])) $res = json_decode($res['data']['rep_express_des'],true);
			if(!empty($res['expcode']))
			{
				$LibYpApi = new LibYpApi();
				$dataArr = [
					'ext_exp_code'=>$res['expcode'],
					'ext_number'=>$res['number'],
					'ext_from'=>'B2C'
				];
				$resArr = $LibYpApi->Get('express/getTrack',$dataArr);
				$resArr['data']['ext_track'] = array_pop(json_decode($resArr['data']['ext_track'],true));
				LibTpl::Set('data', $resArr['data']);
				LibTpl::Set('repId', $_POST['repId']);
				$result=LibTpl::Fetch('order/ajaxGetLogisticInfo.php');
				LibFc::ajaxJsonEncode(['status'=>true,'data'=>$result]);
			}
		}else
		{
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数不正确']);
		}
	}
	/*
	 *ajax批量转移配件分类
	 */
	function ajaxChangeProSort()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('PC02');
		$proIdArr = array_filter(explode(',', trim($_POST['proId'],',')),'LibFc::Int');
		$sortIdArr = array_filter(explode(',', trim($_POST['sortId'],',')),'LibFc::Int');
		if(!empty($proIdArr) && !empty($sortIdArr))
		{
			$B2cProduct = new B2cProduct();
			$res = $B2cProduct->changeProSort($_SESSION['_shopid'],$proIdArr,$sortIdArr);
			LibFc::ajaxJsonEncode($res);
		}
		else
		{
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数不正确']);
		}
	}
	/**
	 * @method    ajax获取运费模板列表
	 * @author 卢
	 * @copyright 2018-03-27
	 */
	function ajaxGetFrtList()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cFreight=new B2cFreight();
		$res=$B2cFreight->getSellerTemplateList($_SESSION['_shopid']);
		$data=[];
		if(!empty($res['data']))
		{
			foreach ($res['data'] as $v)
			{
				$data[]=['frtid'=>$v['frt_id'],'title'=>$v['frt_name']];
			}
		}
		LibFc::ajaxJsonEncode(['status'=>true,'data'=>$data]);
	}
	/**
	 * @method    ajax修改运费
	 * @author 卢
	 * @copyright 2018-03-27
	 */
	function ajaxChangeFrt()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('PC02');
		$Params = mvc::$URL_PARAMS;
		$result=['status'=>false,'data'=>'参数错误'];
		if(LibFc::Int($Params['frtid']))
		{
			$B2cBase=new B2cBase();
			$B2cProduct=new B2cProduct();
			$res=$B2cBase->get('sh_freight_tpl',['count(1) count'],sprintf(' and frt_id=%d and frt_shop_id=%d',$Params['frtid'],$_SESSION['_shopid']),true);
			if($res['data']['count'])
			{
				$result=$B2cProduct->setProFrt($_SESSION['_shopid'],$_POST['proId'],$Params['frtid']);
			}
		}
		LibFc::ajaxJsonEncode($result);
	}


	/**
	 * @method    ajax修改配件描叙模板
	 * @author soul
	 * @copyright 2020/3/30
	 */
	function ajaxChangeDesTpl()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('PC02');
		$Params = mvc::$URL_PARAMS;
		$result=['status'=>false,'data'=>'参数错误'];
		if(LibFc::Int($Params['pdtid']))
		{
			$B2cProduct=new B2cProduct();
			$result = $B2cProduct->setProDesTpl($_SESSION['_shopid'],$_POST['proId'],$Params['pdtid']);
		}
		LibFc::ajaxJsonEncode($result);
	}


	/**
	 * @method    发布配件获取草稿列表
	 * @author 卢
	 * @copyright 2018-03-27
	 */
	function getdrafList()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		$Params = mvc::$URL_PARAMS;
		if(empty($Params['drafKeyWord']))
		{
			$where=sprintf(' and prda_shop_id=%d order by prda_pro_id asc,prda_etime desc',$_SESSION['_shopid']);
		}
		else
		{
			$where=sprintf(" and prda_shop_id=%d and prda_name like '%%%s%%' order by prda_pro_id asc,prda_etime desc",$_SESSION['_shopid'],LibFc::Escape($Params['drafKeyWord']));
		}
		// echo $where;
		$result=$B2cBase->get('bc_product_draft',['prda_id','prda_pro_id','prda_name','prda_etime','prda_text'],$where);
		if(count($result['data']))
		{
			foreach ($result['data'] as $k => $v)
			{
				$result['data'][$k]['prda_etime']=date('Y-m-d H:i:s',$v['prda_etime']);
				$text=json_decode($v['prda_text'],true);
				$result['data'][$k]['path']=$text['pro']['part_path'];
				unset($result['data'][$k]['prda_text']);
			}
		}
		LibFc::ajaxJsonEncode($result);
	}
	/**
	 * @method    校验店铺名称和社会信用代码唯一
	 * @author 卢
	 * @copyright 2018-04-04
	 */
	function checkShopUnique()
	{
		$OthCheck = new OthCheck();
		$OthCheck->mustLogin();
		$Params = mvc::$URL_PARAMS;
		if(empty($Params['name'])&&empty($Params['code'])&&empty($Params['comName']))
		{
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'店铺名称或社会信用代码/注册号不正确!']);
			exit();
		}
		$where=sprintf(' and shop_uid!=%d',$_SESSION['_userid']);
		if(isset($Params['name']))
		{
			$where.=sprintf(" and shop_name='%s'",LibFc::Escape($Params['name']));
			$error='店铺名称已被使用！';
		}elseif(isset($Params['code'])){
			$where.=sprintf(" and shop_com_code='%s'",LibFc::Escape($Params['code']));
			$error='社会信用代码/注册号已被使用！';
		}
		else if(isset($Params['comName']))
		{
			$where.=sprintf(" and shop_com_name='%s'",LibFc::Escape($Params['code']));
			$error='企业名称已被使用！';
		}
		else
		{
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数不正确']);
			exit();
		}
		$B2cBase=new B2cBase();
		$res=$B2cBase->get('sh_shop',['count(1) count'],$where,true);
		if($res['data']['count']>0)
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>$error]);
		else
			LibFc::ajaxJsonEncode(['status'=>true,'data'=>true]);
	}
	/**
	 * @method    开店申请处理
	 * @author 卢
	 * @copyright 2018-04-04
	 */
	function setOpenShopApply()
	{
		$OthCheck = new OthCheck();
		$OthCheck->mustLogin();
		if(count($_POST))
		{
			$B2cShop=new B2cShop();
			$add=$_POST['type']=='edit'?false:true;
			$res=$B2cShop->openShopApply($_POST,$_SESSION['_userid'],$add);
			LibFc::ajaxJsonEncode($res);
		}
	}
	/**
	 * @method    撤销申请
	 * @author 卢
	 * @copyright 2018-04-13
	 */
	function revokeApply()
	{
		$OthCheck = new OthCheck();
		$OthCheck->mustLogin();
		$B2cShop=new B2cShop();
		$res=$B2cShop->set('sh_shop',['shop_apply_tatus'=>-1],sprintf(' and shop_uid=%d',$_SESSION['_userid']));
		LibFc::ajaxJsonEncode($res);
	}
	/**
	 * @method    店铺企业会员设置
	 * @return    [type]        [description]
	 * @author 卢
	 * @copyright 2018-04-13
	 */
	function shopComMember()
	{
		//必须开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('CX04');

		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();
		// 获取当前店铺信息
		$shop = $B2cBase->get('sh_shop',['shop_com_discount'],sprintf(" and shop_id=%d ",$_SESSION['_shopid']),true);
		LibTpl::Set('shopData',$shop['data']);
		// meta
		$headArr = array(
			'title'=>'企业会员设置-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','promotion');
		LibTpl::Put();
	}
	/**
	 * @method    设置会员折扣
	 * @author 卢
	 * @copyright 2018-04-13
	 */
	function setComDisNum()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('CX04');
		$Params = mvc::$URL_PARAMS;
		if(empty($Params['num'])||!preg_match('/^([1-9]\d*|0)(\.\d{1,2})?$/', $Params['num'])||((int)$Params['num']>10||(int)$Params['num']<=0))
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'参数错误']);
		$B2cBase = new B2cBase();
		$res=$B2cBase->set('sh_shop',['shop_com_discount'=>$Params['num']],sprintf(' and shop_id=%d',$_SESSION['_shopid']));
		LibFc::ajaxJsonEncode($res);
	}

	//通过配件品牌和商家编码确定是否可以入库
	function checkUniItem()
	{
		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();
		$arr = [];
		if(!empty($Params['pri_code']))
		{
			$table = 'bc_product join bc_product_info on pro_id = pri_pro_id join bc_probrand on pro_prb_id=prb_id join bc_number on num_pro_id = pro_id and num_self=1';
			$where = sprintf(" and pro_id !=%d and pro_shop_id=%d and num_format='%s' and UPPER(prb_name) = UPPER('%s')", 
				$Params['pro_id'], $_SESSION['_shopid'], LibFc::FormatNum($Params['pri_code']), LibFc::Escape($Params['prb_name']));
			$res = $B2cBase->get($table, ['distinct pro_id'], $where);
			$arr = array_column($res['data'], 'pro_id');
		}
		LibFc::ajaxJsonEncode(['status'=>true, 'data'=>$arr]);
	}


	/**
	 * @method  唯一性校验
	 * @author xu
	 * @copyright 2018-04-16
	 */
	function chekCodeUnique()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cProduct = new B2cProduct();
		// 参数
		if(empty($_POST['code']))
			LibFc::ajaxJsonEncode(['status'=>true,'data'=>true]);
		// 校验
		$res = $B2cProduct->getSameProId($_SESSION['_shopid'],$_POST['code']);
		$res = empty($res['data'])?['status'=>true,'data'=>true]:['status'=>false,'data'=>'商家编码已经存在！'];
		LibFc::ajaxJsonEncode($res);
	}
	/**
	 * @method    退货天数设置
	 * @author 卢
	 * @copyright 2018-04-18
	 */
	function shopCustom()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		if(!empty($_POST))
		{
			// LibTpl::Error('错误');
			if((int)$_POST['date']>15)
			{
				LibTpl::Error('输入的天数过长，请重新输入');
			}
			$dataArr['date']=(int)$_POST['date'];
			$dataArr['text']=$_POST['remark'];
			$data['shop_service']=json_encode($dataArr,JSON_UNESCAPED_UNICODE);
			$data['shop_service_status']=0;
			$B2cBase->set('sh_shop',$data,sprintf(' and shop_id=%d',$_SESSION['_shopid']),['shop_service']);
			LibFc::Go('/seller/shopCustom');
		}
		$res=$B2cBase->get('sh_shop',['shop_service','shop_service_status','shop_money_bail'],sprintf(' and shop_id=%d',$_SESSION['_shopid']),true);
		if(!empty($res['data']))
		{
			$val=json_decode($res['data']['shop_service'],true);
			$res['data']['date']=$val['date'];
			$res['data']['text']=$val['text'];
		}
		LibTpl::Set('data',$res['data']);
		$headArr = array(
			'title'=>'退货设置-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','shopCustom');
		LibTpl::Put();
	}
	public function shopBail()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		$res=$B2cBase->get('sh_shop',['shop_money_bail'],sprintf(' and shop_id=%d',$_SESSION['_shopid']),true);
		LibTpl::Set('data',$res['data']);
		$headArr = array(
			'title'=>'退货设置-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','shopCustom');
		LibTpl::Put();
	}
	/**
	 * @method    卖家服务设置
	 * @author 卢
	 * @copyright 2018-04-18
	 */
	function shopServer()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		$headArr = array(
			'title'=>'退货设置-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		$Params = mvc::$URL_PARAMS;
		if(LibFc::Int($Params['pdtId']))
		{
			$proData = $B2cBase->get('bc_product_desc_tpl',['*'],sprintf(' and pdt_id=%d and pdt_shop_id=%d',$Params['pdtId'],$_SESSION['_shopid']),true);
			LibTpl::Set('pdtArr',$proData['data']);
		}
		$this->HEAD_CSSJS['plugin'][] = 'webuploader';
		$this->HEAD_CSSJS['plugin'][] = 'ueditor';
		$this->HEAD_CSSJS['plugin'][] = 'autocomplete';
		$this->HEAD_CSSJS['plugin'][] = 'zTree';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','shopCustom');
		LibTpl::Put();
	}
	/**
	 * @method    卖家服务模板列表
	 * @author 卢
	 * @copyright 2018-04-18
	 */
	function shopServerList()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		$proField=sprintf('(select count(1) from bc_product_info where pri_service_pdt_id=A.pdt_id) pronum');
		$proData = $B2cBase->get('bc_product_desc_tpl A',['pdt_id','pdt_name','pdt_remark','pdt_add_time',$proField],sprintf(' and pdt_shop_id=%d and pdt_type=1 order by pdt_add_time asc',$_SESSION['_shopid']));
		LibTpl::Set('pdtArr',$proData['data']);
		$headArr = [
			'title'=>'售后模板列表-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','shopCustom');
		LibTpl::Put();
	}
	/**
	 * @method    添加|修改模板
	 * @author 卢
	 * @copyright 2018-04-18
	 */
	function addShopServer()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		if(!empty($_POST))
		{
			$dataArr['pdt_shop_id']=$_SESSION['_shopid'];
			$dataArr['pdt_name']=$_POST['formatName'];
			$dataArr['pdt_remark']=$_POST['pdtRemark'];
			$dataArr['pdt_txt']=$_POST['pdtTxt'];
			$dataArr['pdt_set_time']=time();
			$dataArr['pdt_type']=1;
			if(empty($_POST['pdtId']))
			{
				$dataArr['pdt_add_time']=time();
				$res=$B2cBase->add('bc_product_desc_tpl',$dataArr,['pdt_txt']);
			}
			else
			{
				$res=$B2cBase->set('bc_product_desc_tpl',$dataArr,sprintf(' and pdt_id=%d',$_POST['pdtId']),['pdt_txt']);
				$res['data']=$_POST['pdtId'];
			}
			LibFc::ajaxJsonEncode($res);
		}
	}
	/**
	 * @method    检查正在使用模板的配件数量
	 * @author 卢
	 * @copyright 2018-04-18
	 */
	function checkPtl()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$B2cBase = new B2cBase();
		$Params = mvc::$URL_PARAMS;
		$res=['status'=>false,'data'=>'参数错误'];
		if(LibFc::Int($Params['ptdId']))
		{
			$res=$B2cBase->get('bc_product_info',['count(1) count'],sprintf(' and pri_service_pdt_id=%d',$Params['ptdId']),true);
			$res['data']=$res['data']['count'];
		}
		LibFc::ajaxJsonEncode($res);
	}
	/**
	 * @method    删除售后模板
	 * @author 卢
	 * @copyright 2018-04-18
	 */
	function deleteCustomPtl()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$res=['status'=>false,'data'=>'参数错误'];
		if(LibFc::Int($Params['ptdId']))
		{
			$B2cShop=new B2cShop();
			$res=$B2cShop->deleteCustomTpl($Params['ptdId'],$_SESSION['_shopid']);
		}
		LibFc::ajaxJsonEncode($res);
	}
	function ajaxGetCustomTpl()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$B2cBase=new B2cBase();
		$res=$B2cBase->get('bc_product_desc_tpl',['pdt_id pid','pdt_name pname'],sprintf(' and pdt_shop_id=%d and pdt_type=1',$_SESSION['_shopid']));
		LibFc::ajaxJsonEncode($res);
	}

	/**
	 * @method    收藏店铺的会员列表
	 * @author     xu
	 * @copyright 2017-07-27
	 * @return    ["status"=>true,"data"=>"xxx","code"=>0]
	 */
	public function memberColl()
	{
		// 店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SU05');
		$Params = mvc::$URL_PARAMS;

		// 参数
		$search = '';
		if(!empty($Params['userName']) && !empty($userName = LibFc::Escape($Params['userName'])))
			$search .= sprintf(" and ub_username like '%%%s%%'",$userName);
		if(!empty($Params['userId']) && LibFc::Int($Params['userId']))
			$search .= ' and ub_uid='.$Params['userId'];
		if(!empty($Params['starttime']) && strtotime($Params['starttime']))
			$search .= sprintf(" and shc_add_time >%d",strtotime($Params['starttime']));
		if(!empty($Params['endtime']) && strtotime($Params['endtime']))
			$search .= sprintf(" and shc_add_time <%d",strtotime($Params['endtime']));

		$NowPage = isset($Params['page']) && $Params['page'] > 0 ? (int) $Params['page']:1;
		$PerPage = 20;

		$table='us_shop_collection left join us_user_base on ub_uid=shc_uid  ';
		$where = ' and shc_shop_id='.$_SESSION['_shopid'].$search;
		$B2cBase = new B2cBase();
		$res = $B2cBase->get($table , ['count(1) count'], $where, true);
		$total = $res['data']['count'];
		if($total > 0)
		{
			$field = "ub_username,ub_uid,shc_add_time";
			$where .= sprintf(" order by shc_add_time desc limit %d,%d", ($NowPage-1)*$PerPage, $PerPage);
			$res = $B2cBase->get($table, $field, $where);
			LibTpl::Set('data', $res['data']);
		}

		// 页码
		$Page = LibPage::Show($total, $PerPage);
		LibTpl::Set('Page', $Page);

		$collUids = array_column($res['data'], 'ub_uid');
		// 获取收藏用户与会员的映射
		if(!empty($collUids))
		{
			$res = $B2cBase->get('sh_member_link left join sh_member on mem_id=meml_mem_id left join sh_member_level on mel_id=mem_mel_id',['meml_uid','mel_name','mem_mel_id'],sprintf("and meml_shop_id=%d and meml_uid in (%s)",$_SESSION['_shopid'],implode(',', $collUids)));
			LibTpl::Set('userLevel',array_column($res['data'], 'mel_name','meml_uid'));
		}


		// 会员级别
		$res = $B2cBase->get('sh_member_level',['mel_id','mel_name']," and mel_id > 0 order by mel_id asc ");
		LibTpl::Set('level',$res['data']);
		// meta
		$headArr = array(
			'title'=>'会员等级设置-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		$this->HEAD_CSSJS['plugin'][] = 'datetimepicker';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','member');
		LibTpl::Put();
	}

	/**
	 * @method  设置会员等级
	 * @author xu
	 * @copyright 2018-04-16
	 */
	function setColMem()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();

		if(empty($_POST['ids']) || empty($_POST['level']))
			LibFc::ajaxJsonEncode(['status'=>false, 'data'=>'设置会员等级参数错误！']);

		// 设置会员等级
		$B2cUser = new B2cUser();
		$B2cUser->setUserMemLevel(explode(',', $_POST['ids']),$_POST['level'],$_SESSION['_shopid']);
		LibFc::ajaxJsonEncode(['status'=>true, 'data'=>true]);
	}




	/**
	 * @method    广告投放
	 * @author     xu
	 * @copyright 2017-07-27
	 * @return    ["status"=>true,"data"=>"xxx","code"=>0]
	 */
	public function adsList()
	{
		// 店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();


		// 查询参数
		$Params = mvc::$URL_PARAMS;
		LibTpl::Set('Params',$Params);
		$search = '';
		$nowPage = isset($Params['page']) && $Params['page'] > 0 ? (int) $Params['page']:1;
		$perPage = 20;
		if(!empty($Params['title']))
			$search .= sprintf(" and ads_title like '%%%s%%' ",$Params['title']);
		if($Params['check']!="")
			$search .= sprintf(" and ads_check =%d ",$Params['check']);
		if(!empty($Params['place']))
			$search .= sprintf(" and pla_id=%d ",$Params['place']);
		if(!empty($Params['btime']))
			$search .= sprintf(" and pat_btime>%d ",strtotime($Params['btime']));
		if(!empty($Params['etime']))
			$search .= sprintf(" and pat_etime<%d ",strtotime($Params['etime']));
		$where = ' and ads_shop_id='.$_SESSION['_shopid'].$search;


		// 总数
		$table = 'ba_ads left join ba_ads_style on ast_id=ads_ast_id left join ba_place_ads_link on pal_ads_id=ads_id left join ba_place_link on pal_pll_id = pll_id left join ba_place on pla_id=pll_pla_id left join ba_place_ads_time on pat_pal_id=pal_id';
		$AdsBase = new AdsBase();
		$res = $AdsBase->get($table , ['count(*) count'], $where, true);
		$total = $res['data']['count'];
		$Page = LibPage::Show($total, $perPage);
		LibTpl::Set('Page', $Page);


		// 详情
		if($total > 0)
		{
			$res = $AdsBase->get($table,["*"],$where.sprintf(" order by ads_check asc,ads_last_ver desc,ads_id asc limit %d,%d",($nowPage-1)*$perPage,$perPage));
			foreach ($res['data'] as $k => $v) {
				$res['data'][$k]['ast_config'] = explode(':', $v['ast_config']);
			}
			LibTpl::Set('data', $res['data']);

			$res = $AdsBase->get($table,["*"],' and ads_shop_id='.$_SESSION['_shopid']);
			$plaIds = array_unique(array_column($res['data'], 'pla_id'));
		}
		// 广告状态
		$AdsPlace = new AdsPlace();
		$res = $AdsPlace->getAdsStat(array_column($res['data'], 'pal_id'));
		LibTpl::Set('stat',$res['data']);

		// 状态枚举
		LibTpl::Set('checkStat',['0'=>'待审','1'=>'通过','-1'=>'不通过']);

		if(!empty( $plaIds))
		{
			// 获取所有的广告组
			$res = $AdsBase->get('ba_place',['pla_id','pla_name'],sprintf("and pla_id in (%s)",implode(',', $plaIds))."order by pla_id asc");
			LibTpl::Set('place',array_column($res['data'],'pla_name','pla_id'));
		}

		// meta
		$headArr = array(
			'title'=>'广告投放-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		$this->HEAD_CSSJS['plugin'][] = 'datetimepicker';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','adsList');
		LibTpl::Put();
	}


	/**
	 * @method    广告编辑
	 * @author     xu
	 * @copyright 2017-07-27
	 * @return    ["status"=>true,"data"=>"xxx","code"=>0]
	 */
	public function adsEdit()
	{
		// 店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();


		$AdsBase = new AdsBase();
		$Params = mvc::$URL_PARAMS;
		$id  = $Params['id'];


		if($_SERVER['REQUEST_METHOD']=='POST')
		{
			$data = $_POST['data'];
			$where = sprintf("and ads_shop_id=%d and ads_id=%d",$_SESSION['_shopid'],$id);
			$AdsBase->set('ba_ads',['ads_check'=>0,'ads_check_ver'=>json_encode($data,JSON_UNESCAPED_UNICODE)],$where);
			LibFc::Go(sprintf('/seller/adsEdit?id=%d',$id));
			exit;
		}


		// 基本信息
		$data = array();
		$where = sprintf(' and ads_shop_id=%d and ads_id=%d ',$_SESSION['_shopid'],$id);
		$res = $AdsBase->get('ba_ads left join ba_ads_style on ast_id=ads_ast_id ' , ['*'], $where,true);

		if(empty($res['data']))
		{
			// 数据不存在重定向
			LibFc::Go("/seller/adsList");
			exit;
		}

		$res['data']['ast_config'] = explode(":", $res['data']['ast_config']);
		$data['base'] = $res['data'];

		// 待审广告信息
		$check = json_decode($res['data']['ads_check_ver'],true);
		LibTpl::Set('check',$check);

		// 审核结果
		if(!empty($res['data']['ads_check_res']))
		{
			LibTpl::Set('checkRes',json_decode($res['data']['ads_check_res'],true));
		}


		// 位置
		$table = 'ba_place_ads_link left join ba_place_link on pal_pll_id=pll_id left join ba_place_ads_time on pat_pal_id=pal_id ';
		$res = $AdsBase->get($table , ['*'], sprintf("and pal_ads_id=%d",$id));
		$data['place'] = $res['data'];
		LibTpl::Set('data',$data);

		// 广告位枚举
		$res = $AdsBase->get('ba_place',['pla_id','pla_name'],"");
		$pla = array_column($res['data'], 'pla_name','pla_id');
		LibTpl::Set('place',$pla);
		LibTpl::Set('stat',['0'=>'停用','1'=>'启用']);

		// 审核枚举
		LibTpl::Set('checkStat',['0'=>'待审','1'=>'通过','-1'=>"不通过"]);

		// meta
		$headArr = array(
			'title'=>'广告编辑-跑街的',
			'keyword'=>'',
			'des'=>''
		);
		$this->HEAD_CSSJS['plugin'][] = 'webuploader';
		$this->HEAD_CSSJS['plugin'][] = 'datetimepicker';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('headArr', $headArr);
		LibTpl::Set('LeftMenu','adsList');
		LibTpl::Put();
	}

	/**
	 * @method    gzhBase 公众号基本信息
	 * @author     廖
	 * @copyright 2018-07-10
	 */
	function gzhBase()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SS00');
		LibTpl::Set('order', 'gzhBase');
		$B2cShop = new B2cShop();
		//检测是否开通公众号
		$res =  $B2cShop->get('sh_shop_app',['count(*) count'],sprintf('and aps_shop_id = %s',$_SESSION['_shopid']),true);
		if ($res['data']['count']> 0)
		{
			//保存信息
			if($_SERVER['REQUEST_METHOD'] == "POST")
			{
				$postArr = [];
				$postArr['aps_shop_name'] = LibFc::Escape($_POST['shopName']);
				$postArr['aps_banner'] = $_POST['banner'];
				$postArr['aps_contact'] = $_POST['contact'];

				//接口处理
				$res = $B2cShop->saveGzhBaseInfo($postArr,$_SESSION['_shopid']);
				if ($res['status'])
				{
					LibTpl::Set('msg','保存成功!');
					//文件中心删除图片
					if (!empty($postArr['aps_banner']['imgs']))
					{
						$delImg = [];
						$OthFileCenter = new OthFileCenter();
						foreach ($postArr['aps_banner']['imgs'] as $key => $value)
						{
							if ($value != $_POST['oldimgs'][$key] && $_POST['oldimgs'][$key] != '')
							{
								//这是要删除的图片
								$delLogoArr = ['cate'=>'adorn', 'files'=>$_POST['oldimgs'][$key]];
								$OthFileCenter->del($delLogoArr);
							}
						}
					}
				}
			}
			$res =  $B2cShop->get('sh_shop_app',['*'],sprintf('and aps_shop_id = %s',$_SESSION['_shopid']),true);
			$res['data']['aps_banner'] = json_decode($res['data']['aps_banner'],true);
			$res['data']['aps_contact'] = json_decode($res['data']['aps_contact'],true);
			LibTpl::Set('data', $res['data']);
		}
		$headArr = [
			'title'=>'公众号基本设置-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		$this->HEAD_CSSJS['plugin'][] = 'webuploader';
		$this->HEAD_CSSJS['plugin'][] = 'ueditor';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Put();
	}
	/**
	 * @method    gzhBase 公众号信息
	 * @author     廖
	 * @copyright 2018-07-10
	 */
	function gzhInfo()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('SS00');
		LibTpl::Set('order', 'gzhInfo');
		$B2cBase = new B2cBase();
		//检测有没有开通公众号
		$res =  $B2cBase->get('sh_shop_app',['count(*) count'],sprintf('and aps_shop_id = %s',$_SESSION['_shopid']),true);
		if ($res['data']['count'] > 0)
		{
			LibTpl::Set('isopen',true);
			if($_SERVER['REQUEST_METHOD'] == "POST")
			{
				$res = $B2cBase->set('sh_shop_app',['aps_info' => $_POST['shopInfo']],'and aps_shop_id='.$_SESSION['_shopid']);
				if ($res['status'])
				{
					LibTpl::Set('msg','保存成功!');
				}
			}
			$res = $B2cBase->get('sh_shop_app',['aps_info'],sprintf('and aps_shop_id = %s',$_SESSION['_shopid']),true);
			LibTpl::Set('info',$res['data']['aps_info']);
		}
		$headArr = [
			'title'=>'公众号信息-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		$this->HEAD_CSSJS['plugin'][] = 'webuploader';
		$this->HEAD_CSSJS['plugin'][] = 'ueditor';
		$this->HEAD_CSSJS['plugin'][] = 'autocomplete';
		$this->HEAD_CSSJS['plugin'][] = 'zTree';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Put();
	}

	/**
	 * @method    gzhBase 公众号信息
	 * @author     廖
	 * @copyright 2018-07-10
	 * @return   {'status':true,'data':xxx...}
	 */
	function ajxCheckGzhNameUnique()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		if (!empty($_POST['name']))
		{
			$B2cBase = new B2cBase();
			$res = $B2cBase->get('sh_shop_app',['count(*) count'],sprintf(" and aps_shop_name = '%s' and aps_shop_id != %s",LibFc::Escape($_POST['name']),$_SESSION['_shopid']),true);
			LibFc::ajaxJsonEncode($res);
		}
	}

	/**
	 * @method    店铺聊天记录
	 * @author     廖
	 * @copyright 2018-07-16
	 */
	public function shopIm()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$OthCheck->rule('IM00');
		LibTpl::Set('LeftMenu', 'shopIm');
		$Params = $Params = mvc::$URL_PARAMS;
		//排序
		$Params['timeSeq'] = $Params['timeSeq'] ? 1 : 0;
		$B2cBase = new B2cBase();
		//子账号
		$workId = [];
		if (!empty($_SESSION['_shopowner']))
		{
			$res =  $B2cBase->get('sh_worker left join sh_worker_job on wor_woj_id = woj_id',['wor_uid','wor_name','woj_name'],sprintf('and wor_shop_id = %s',$_SESSION['_shopid']));
			$sonArr = [];
			if(!empty($res['data']))
			{
				foreach ($res['data'] as $key => $value)
				{
					$sonArr[$value['wor_uid']] = sprintf('%s【 %s 】', $value['wor_name'],$value['woj_name']);
				}
			}
			$workId = array_keys($sonArr);
			LibTpl::Set('account', $sonArr);
		}

		//拼接条件
		$where = '';
		$isSon = true;
		$orderBy = 'order by time desc';
		//基础条件
		if (!empty($Params))
		{
			foreach ($Params as $key => $value)
			{
				if (empty($value)) continue;
				switch ($key) {
					case 'account':
						if (LibFc::Int($value) && in_array($value, $workId))
						{
							$where .= sprintf('and (from_uid = %s or to_uid = %s)', $value, $value);
							$isSon = false;
						}
						break;
					case 'contact':
						$value = LibFc::Escape($value);
						$where .= sprintf(" and (from_uid in (select id from user where u_name like '%%%s%%' or nick like '%%%s%%') or to_uid in (select id from user where u_name like '%%%s%%' or nick like '%%%s%%'))",$value,$value,$value,$value);
						break;
					case 'btime':
						$where .= sprintf(" and time >= %s",strtotime($value));
						break;
					case 'etime':
						$where .= sprintf(" and time <= %s",strtotime($value) + 24*60*60);
						break;
					case 'timeSeq':
						if ($value)
						{
							$orderBy = 'order by time asc';
						}
						break;
				}
			}
		}


		// 限制条件
		$shopIdArr = empty($workId) ? [$_SESSION['_shopid']] : array_merge($workId,[$_SESSION['_shopid']]);


		$shopwhere = $where.sprintf(" and to_uid in (%s) and readed=0", implode(',', $shopIdArr));

		$ImBase = new ImBase();
		//获取该条件下店家所有的未读记录
		$res = $ImBase->get('msg',['count(*) count'],sprintf('%s and readed = 0',$shopwhere),true);
		LibTpl::Set('shopNorad', $res['data']['count']);

		$userwhere = $where.sprintf(" and from_uid in (%s) and readed=0", implode(',', $shopIdArr));
		//获取该条件下买家所有的未读记录
		$res = $ImBase->get('msg',['count(*) count'],sprintf('%s and readed = 0',$userwhere),true);
		LibTpl::Set('userNorad', $res['data']['count']);


		// nav 筛选条件
		switch ($Params['type'])
		{
			case 'shopNoread':
				$where = $shopwhere;
				break;
			case 'userNoread':
				$where = $userwhere;
				break;
			default:
				$where = sprintf("%s and (from_uid in (%s) or to_uid in (%s))", $where, implode(',', $shopIdArr), implode(',', $shopIdArr));
				break;
		}
		// 计算总条数
		$total = $ImBase->get('msg',['count(*) count'],$where,true);
		$total = $total['data']['count'];
		if ($total > 0)
		{
			$perPage = isset($_COOKIE['perPage'])? $_COOKIE['perPage'] : 15;
			$nowpage = isset($Params['page']) ? $Params['page'] : 1;
			//分页 && 排序
			$where = sprintf('%s %s limit %s,%s',$where,$orderBy,($nowpage-1)*$perPage,$perPage);
			$res = $ImBase->get('msg',['*'],$where);
			LibTpl::Set('list', $res['data']);

			//获取 user 信息
			$uIdArr = array_unique(array_merge(array_column($res['data'],'from_uid'),array_column($res['data'],'to_uid')));
			if (!empty($uIdArr))
			{
				$uData = $ImBase->get('user',['id','nick'],sprintf("and id in (%s)",implode(',', $uIdArr)));
				$uData = array_column($uData['data'],'nick','id');
				LibTpl::Set('userArr', $uData);
			}


			//是否有配件
			$proIdArr = [];
			foreach ($res['data'] as $value)
			{
				if (preg_match('/pro_id\[\d+\]/', $value['content'],$m) > 0)
				{
					$proIdArr[$value['msgid']] = substr($m[0],7,-1);
				}
			}
			$proId = array_filter(array_unique($proIdArr));
			if (!empty($proId))
			{
				$B2cProduct = new B2cProduct();
				$res = $B2cProduct->getAnyProductInfo($proId);
				$proArr = [];
				foreach ($proIdArr as $key => $value)
				{
					$proArr[$key] = $res['data'][$value] ? $res['data'][$value] : [];
				}
				LibTpl::Set('proArr', $proArr);
			}
		}
		if (isset($Params['type'])) unset($Params['page']);
		LibTpl::Set('Params', $Params);
		$Page = LibPage::Show($total, $perPage);
		LibTpl::Set('Page', $Page);
		LibTpl::Set('shopIdArr', $shopIdArr);
		$headArr = [
			'title'=>'聊天信息-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		$this->HEAD_CSSJS['plugin'][] = 'autocomplete';
		$this->HEAD_CSSJS['plugin'][] = 'datetimepicker';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Put();

	}

	/**
	 * @method    自动完成 ajax 获取店铺聊天人名字
	 * @return    [type]               [description]
	 * @author     廖
	 * @copyright 2018-07-16
	 * @return
	 */
	public function ajaxGetShopImContact()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();

		$name = LibFc::Escape($_GET['name']);
		if (!empty($name))
		{
			//获取子账号id
			$workId = [];
			if (!empty($_SESSION['_shopowner']))
			{
				$B2cBase = new B2cBase();
				$res =  $B2cBase->get('sh_worker',['wor_uid'],sprintf('and wor_shop_id = %s',$_SESSION['_shopid']));
				$workId = array_column($res['data'], 'wor_uid');
			}

			$uIdArr = empty($workId) ? [$_SESSION['_shopid']] : array_merge($workId,[$_SESSION['_shopid']]);
			$uidStr = implode(',', $uIdArr);

			$ImBase = new ImBase();

			$where = sprintf("and (nick like '%%%s%%' or u_name like '%%%s%%') and (id in (select to_uid from msg where from_uid in (%s)) or id in (select from_uid from msg where to_uid in (%s)))",$name,$name,$uidStr,$uidStr);
			$where .= sprintf('%s group by nick order by id asc',$where);
			$res = $ImBase->get('user',['nick','u_name'],$where);

			if (!empty($res['data']))
			{
				$newArr = [];
				foreach ($res['data'] as $key => $value)
				{
					if ($value['nick'] == $value['u_name'])
					{
						$newArr[] = ['nick'=>$value['nick'],'name'=>$value['nick']];
					} else
					{
						$newArr[] = ['nick'=>$value['nick'],'name'=>$value['nick'].' [ '.$value['u_name'].' ]'];
					}
				}
			}
			LibFc::ajaxJsonEncode(['status'=>true,'data'=>$newArr]);
		}

	}
	/**
	 * @method    店铺分类列表
	 * @return    [type]       [description]
	 * @author lu
	 * @copyright 2019-01-12
	 */
	function shopCategoty()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		// $OthCheck->rule('SS00');
		LibTpl::Set('order', 'category');
		$OthBase = new OthBase();
		$res =  $OthBase->get('cms_category',['*'],sprintf('and cat_shop_id = %s order by cat_seq asc',$_SESSION['_shopid']));
		LibTpl::Set('lists', $res['data']);
		$headArr = [
			'title'=>'文章管理-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		$this->HEAD_CSSJS['plugin'][] = 'webuploader';
		$this->HEAD_CSSJS['plugin'][] = 'ueditor';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('LeftMenu', 'shopCategoty');
		LibTpl::Put();
	}
	/**
	 * @method    修改店铺分类
	 * @return    [type]           [description]
	 * @author lu
	 * @copyright 2019-01-12
	 */
	function editShopCategoty()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$OthBase = new OthBase();
		if(LibFc::Int($Params['cateId']))
		{
			$res =  $OthBase->get('cms_category',['*'],sprintf('and cat_shop_id = %d and cat_id=%d order by cat_seq asc',$_SESSION['_shopid'],$Params['cateId']),true);
			LibTpl::Set('data', $res['data']);
		}
		if(!empty($_POST['name'])&&LibFc::Int($_POST['cateId']))
		{
			$dataArr=[
				'cat_name'=>$_POST['name'],
				'cat_seq'=>((int)$_POST['seq'])
			];
			$OthBase->set('cms_category',$dataArr,sprintf(' and cat_shop_id=%d and cat_id=%d',$_SESSION['_shopid'],$_POST['cateId']));
			LibFc::Go('/seller/shopCategoty');
		}
		LibTpl::Set('order', 'category');
		$headArr = [
			'title'=>'分类修改-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		$this->HEAD_CSSJS['plugin'][] = 'webuploader';
		$this->HEAD_CSSJS['plugin'][] = 'ueditor';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('LeftMenu', 'shopCategoty');
		LibTpl::Put();
	}
	/**
	 * @method    店铺文章列表
	 * @return    [type]      [description]
	 * @author lu
	 * @copyright 2019-01-12
	 */
	function shopArticle()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		// $OthCheck->rule('SS00');
		LibTpl::Set('order', 'artInfo');
		$Params = mvc::$URL_PARAMS;
		$OthBase = new OthBase();
		$res =  $OthBase->get('cms_category',['*'],sprintf('and cat_shop_id = %s order by cat_seq asc',$_SESSION['_shopid']));
		$cate=array_column($res['data'],null, 'cat_id');
		LibTpl::Set('cate', $cate);
		$where=sprintf(' and art_shop_id =%d',$_SESSION['_shopid']);
		$res=$OthBase->get('cms_article',['count(1) count'],$where,true);
		$total=$res['data']['count'];
		$perPage=!empty($Params['perPage'])?(int)$Params['perPage']:20;
		$page=!empty($Params['page'])?(int)$Params['page']:1;
		$Page = LibPage::Show($total, $perPage);
		LibTpl::Set('Page', $Page);
		if($total>0)
		{
			$where.=sprintf(' order by art_seq asc limit %d,%d',($page-1)*$perPage,$perPage);
			$res=$OthBase->get('cms_article',['*'],$where);
			LibTpl::Set('lists', $res['data']);
			$userRes=array_column($res['data'], 'art_add_uid');
		}
		if(!empty($userRes))
		{
			$B2cBase=new B2cBase();
			$res=$B2cBase->get('us_user_base',['ub_username','ub_uid'],sprintf(' and ub_uid in(%s)',implode(',',$userRes)));
			$uArr=array_column($res['data'], 'ub_username','ub_uid');
			LibTpl::Set('uArr', $uArr);
		}
		$headArr = [
			'title'=>'文章列表-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		$this->HEAD_CSSJS['plugin'][] = 'webuploader';
		$this->HEAD_CSSJS['plugin'][] = 'ueditor';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('LeftMenu', 'shopCategoty');
		LibTpl::Put();
	}
	/**
	 * @method    修改  添加文章
	 * @return    [type]         [description]
	 * @author lu
	 * @copyright 2019-01-12
	 */
	function shopAddArticle()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		// $OthCheck->rule('SS00');
		LibTpl::Set('order', 'artInfo');
		$Params = mvc::$URL_PARAMS;
		$OthBase = new OthBase();
		$res =  $OthBase->get('cms_category',['*'],sprintf('and cat_shop_id = %s order by cat_seq asc',$_SESSION['_shopid']));
		$cateArr=$res['data'];
		LibTpl::Set('cate', $cateArr);
		if(!empty($_POST))
		{
			$imgArr=!empty($_POST['art_imgs'])?array_filter($_POST['art_imgs']):[];
			$dataArr=[
				'art_shop_id'=>$_SESSION['_shopid'],
				'art_cat_id'=>$_POST['art_cat_id'],
				'art_name'=>$_POST['art_name'],
				'art_short_des'=>$_POST['art_short_des'],
				'art_txt'=>$_POST['art_txt'],
				'art_imgs'=>json_encode($imgArr),
				'art_etime'=>time(),
				'art_add_uid'=>mvc::$cfg['LOGUSER']['uid'],
				'art_seq'=>((int)$_POST['art_seq'])
			];
			$artId=(int)$_POST['art_id'];
			if(LibFc::Int($_POST['art_id']))
			{
				$OthBase->set('cms_article',$dataArr,sprintf(' and art_shop_id =%d and art_id=%d',$_SESSION['_shopid'],$_POST['art_id']));
			}else
			{
				$dataArr['art_atime']=time();
				$res=$OthBase->add('cms_article',$dataArr);
				$artId=$res['data'];
			}
			LibFc::Go('/seller/shopAddArticle?artId='.$artId);
		}
		if(LibFc::Int($Params['artId']))
		{
			$res=$OthBase->get('cms_article',['*'],sprintf(' and art_shop_id =%d and art_id=%d',$_SESSION['_shopid'],$Params['artId']),true);
			$data=$res['data'];
			if(!empty($data))
			{
				$data['art_imgs']=json_decode($data['art_imgs'],true);
			}
			// print_r($data);
			LibTpl::Set('data', $data);
		}
		$headArr = [
			'title'=>'添加文章-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		$this->HEAD_CSSJS['plugin'][] = 'webuploader';
		$this->HEAD_CSSJS['plugin'][] = 'ueditor';
		$this->HEAD_CSSJS['plugin'][] = 'autocomplete';
		$this->HEAD_CSSJS['plugin'][] = 'zTree';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		LibTpl::Set('LeftMenu', 'shopCategoty');
		LibTpl::Put();
	}
	/**
	 * @method    删除文章
	 * @return    [type]     [description]
	 * @author lu
	 * @copyright 2019-01-12
	 */
	function delShopArt()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		if(!LibFc::Int($_POST['artId']))
		{
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'文章ID不正确']);
		}
		$OthBase = new OthBase();
		$res=$OthBase->get('cms_article',['art_can_delete'],sprintf(' and art_shop_id =%d and art_id=%d',$_SESSION['_shopid'],$_POST['artId']),true);
		if(empty($res['data']['art_can_delete']))
		{
			LibFc::ajaxJsonEncode(['status'=>false,'data'=>'文章不允许删除，删除失败']);
		}
		$res=$OthBase->del('cms_article',sprintf(' and art_shop_id =%d and art_id=%d',$_SESSION['_shopid'],$_POST['artId']));
		LibFc::ajaxJsonEncode($res);
	}


	/**
	 * @method  新增车型
	 * @author soul
	 * @copyright 2019/11/1
	 */
	public function newModel()
	{
		//必须已开通店铺
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		$page = isset($Params['page']) && $Params['page'] > 0 ? (int) $Params['page']:1;
		$perPage = 20;
		$TimeArr = [
			'7days'=>'最近7天添加',
			'30days'=>'最近30天添加',
			'60days'=>'最近60天添加',
			'90days'=>'最近90天添加',
			'120days'=>'最近180天添加',
			'1years'=>'最近一年添加'
		];
		LibTpl::Set('TimeArr', $TimeArr);
		if(empty($TimeArr[$Params['betime']])) $Params['betime'] = '30days';

		$ComModel = new ComModel();
		$where = sprintf(" AND mod3_atime >=%d", strtotime('-'.$Params['betime']));
		$YpcModel = new YpcModel();
		$Res = $ComModel->getModel(3, array('count(*) as count'), $where, true);
		$total = $Res['data']['count'];
		$modelArr = [];
		if($total > 0)
		{
			$order = ' order by mod3_atime desc';
			$res = $ComModel->getModel(3, ['*'], sprintf("%s %s LIMIT %d,%d",$where, $order, ($page-1)*$perPage,$perPage));
			foreach($res['data'] as $v)
			{
				$v['mod2_year'] = LibFc::formatViewYear($v['mod2_start_year'], $v['mod2_end_year'], 3);
				$v['mod3_year'] = LibFc::formatViewYear($v['mod3_start_year'], $v['mod3_end_year'], 3);
				$v['pros'] = [];
				$v['numid'] = [];
				$modelArr[$v['mod3_id']] = $v;
			}
		}

		LibTpl::Set('modelArr', $modelArr);
		LibTpl::Set('Params', $Params);
		LibTpl::Set('LeftMenu', 'newModel');
		$Page = LibPage::Show($total, $perPage);
		LibTpl::Set('Page', $Page);
		$headArr = [
			'title'=>'新增车型-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Put();
	}

	/**
	  * @method 公众号产品二维码
	  * @author soul 2020/5/25
	  */
	function gzhItemEwm()
	{
		set_time_limit(0);
		ini_set('memory_limit', '512M');
		$shopIdArr = [149894, 339388];
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;
		if(!in_array($_SESSION['_shopid'], $shopIdArr)) exit('此商铺尚未开通此业务！');

		$zipName = $_SESSION['_shopid'].'.zip';
		$dir = mvc::$cfg['PATH_ROOT'].'gzhItemEwm/';
		$zipHas = 0;
		if(!empty($_POST['size']) && !empty($_POST['reset']))
		{
			$sizeArr = [];
			if(!empty($_POST['size']))
			{
				foreach($_POST['size'] as $s)
				{
					if($s > 30) $sizeArr[] = ['w'=>(int) $s, 'h'=>(int) $s];
				}
			}
			if(empty($sizeArr))
			{
				$sizeArr = [
					['w'=>'200', 'h'=>'200'],
				];
			}
			$maxW = 200;
			foreach($sizeArr as $v)
			{
				$maxW = $v['w'] > $maxW? $v['w']: $maxW;
			}

			$fontPath = mvc::$cfg['AUTOLOAD']['Oth']['path'].'lib/captcha/assets/ttfs/arial.ttf';

			$B2cBase=new B2cBase();
			$OthQrcode = new OthQrcode();
			$itemRes = $B2cBase->get('bc_product JOIN bc_product_info ON pri_pro_id = pro_id',['pro_id, pri_code'],sprintf(" and pro_shop_id =%d and pri_code != ''", $_SESSION['_shopid']));
			$zip = new ZipArchive();
			@unlink($dir.$zipName);
			if($zip->open($dir.$zipName, ZipArchive::CREATE) !==TRUE) return LibFc::ReturnData(false, '创建压缩包失败');

			$filedir = $dir.$_SESSION['_shopid'].'/';
			LibDir::ClearDir($filedir);
			@mkdir($filedir);
			foreach($itemRes['data'] as $v)
			{
				$url = mvc::$cfg['HOST']['gzh'].$_SESSION['_shopid'].'/index.php/item/info?proId='.$v['pro_id'];
				$ewmName = LibFc::FormatNum($v['pri_code']).'.png';
				$ewmDir = $filedir.$ewmName;
				$size = floor($maxW/37*100)/100 + 0.01;
				$OthQrcode->png($url, $ewmDir, 1, $size, 0);
				$ewmdata = file_get_contents($ewmDir);
				foreach($sizeArr as $sk=>$sv)
				{
					$sdir = $filedir.$sv['w'].'/';
					@mkdir($sdir);
					$sfileName = $sdir.$ewmName;
					$ewmW = $sv['w'] - 26;
					$image = ImageCreate($sv['w'], $sv['h']); //参数为宽度和高度
					$white = ImageColorAllocate($image, 255, 255, 255);
					$ewmOr = imagecreatefromstring($ewmdata);
					$ewmOrW = imagesx($ewmOr);
					$qr_size = 80;
					$pax = round($sv['w']-$ewmW)/2;
					imagecopyresampled($image, $ewmOr, $pax, $pax/2, 0, 0, $ewmW, $ewmW, $ewmOrW, $ewmOrW);
					$fontColor = ImageColorAllocate($image, 0, 0, 0);
					$fontSize = 10;
					$px = round(($sv['w']-strlen($v['pri_code'])*$fontSize*0.65)/2);
					imagettftext($image, $fontSize, 0, $px, $sv['h']-5, $fontColor, $fontPath, $v['pri_code']);
					imagepng($image, $sfileName);
					imagedestroy($image);
					$zip->addFile($sfileName, $sv['w'].'/'.$ewmName);
				}
				@unlink($ewmDir);
			}
			$zip->close();
			LibTpl::Set('build', 1);
		}
		if(file_exists($dir.$zipName))
		{
			$zipHas = 1;
		}
		LibTpl::Set('zipName', $zipName);
		LibTpl::Set('zipHas', $zipHas);
		LibTpl::Set('Params', $Params);
		LibTpl::Set('LeftMenu', 'gzhItemEwm');
		LibTpl::Set('Page', $Page);
		$headArr = [
			'title'=>'公众号产品二维码-跑街的',
			'keyword'=>'',
			'des'=>''
		];
		LibTpl::Set('headArr', $headArr);
		LibTpl::Put();
	}


	/**
	  * @method 公众号产品二维码
	  * @author soul 2020/5/25
	  */
	function anyact()
	{
		$OthCheck = new OthCheck();
		$OthCheck->hasShop();
		$Params = mvc::$URL_PARAMS;

		LibTpl::Set('Params', $Params);
		LibTpl::Set('LeftMenu', 'anyact');
		$this->HEAD_CSSJS['plugin'][] = 'layui';
		$this->HEAD_CSSJS['plugin'][] = 'webuploader';
		LibTpl::Set('HEAD_CSSJS', $this->HEAD_CSSJS);
		$headArr = [
			'title'=>'批量操作-跑街的',
			'keyword'=>'',
			'des'=>''
		];
        $B2cPart = new B2cPart();

        $res = $B2cPart->get('bc_product JOIN bc_part ON part_id = pro_part_id',['part_id','part_name'],sprintf(" and pro_shop_id=%d GROUP BY part_id order by CONVERT(part_name USING gbk)",$_SESSION['_shopid']));

        LibTpl::Set('supPartArr', $res['data']);

		LibTpl::Set('headArr', $headArr);
		LibTpl::Put();
	}



	//产品导入模板
	function importItemDemo()
	{
		$B2cProduct = new B2cProduct();
		$B2cProduct->exportB2cItem([], [], '商城配件导入模板.xls');
	}

	//检测导入产品
	function checkImportItem()
	{
		$brow = 4;
		$OthExcel = new OthExcel();
		$res = $OthExcel->read($_FILES['file']['tmp_name'], 0, [], $brow);
		$rowsArr = $res['data'];
		$proArr = [];
		foreach($rowsArr as $row=>$data)
		{
			//获取字段
			if($row == $brow)
			{
				$filedArr = $data;
			}
			else
			{
				foreach($data as $col=>$val)
				{
					if(stripos($filedArr[$col], 'para_') === 0)
					{
						$proArr[$row]['part_param'][substr($filedArr[$col], 5)] = $val;
					}
					else
					{
						$proArr[$row][$filedArr[$col]] = $val;
					}
				}
			}
		}
		$B2cProduct = new B2cProduct();
		$res = $B2cProduct->checkImportB2cItem($_SESSION['_shopid'], $proArr);
		LibFc::ajaxJsonEncode($res);
	}


	//导入产品
	function importItem()
	{
		$B2cProduct = new B2cProduct();
		$res = $B2cProduct->importB2cItem($_SESSION['_shopid'], $_POST['items']);
		LibFc::ajaxJsonEncode($res);
	}


	//获取更新车型的配件ID
	function getRefreshModelItems()
	{

        if(!empty($_POST['spartId']))
        {
            $spartIdArr = [];
            foreach(explode(',', $_POST['spartId']) as $v)
            {
                if((int) $v > 0){
                    $spartIdArr[] = (int) $v;
                }
            }
            if(!empty($spartIdArr))
            {
                $where = sprintf(" and pro_shop_id=%d and pro_part_id in (%s)", $_SESSION['_shopid'], implode(",", $spartIdArr));
                $table = 'bc_product join bc_number on pro_id = num_pro_id';
                $B2cBase = new B2cBase();
                $res = $B2cBase->get($table, ['distinct(pro_id) pro_id'], $where);
                $res['data'] = array_column($res['data'], 'pro_id');
                LibFc::ajaxJsonEncode($res);
            }
        }
        LibFc::ajaxJsonEncode(['status'=>true, 'data'=>[]]);

	}


	//刷配件适用车型
	function refreshItemModel()
	{
		$B2cProduct = new B2cProduct();
		$res = $B2cProduct->refreshItemModel($_SESSION['_shopid'], $_POST['type'], $_POST['items']);
		LibFc::ajaxJsonEncode($res);
	}



	//获取关联号码的配件ID
	function getRefreshYpItems()
	{
		$facArr = [];
		foreach(explode(',', $_POST['facs']) as $v)
		{
			$v = strtoupper(LibFc::Escape($v));
			$facArr[$v] = $v;
		}
		$arr = [];
		if(!empty($facArr))
		{
			$where = sprintf(" and pro_shop_id=%d and num_show = 1 and UPPER(num_factory) in ('%s')", $_SESSION['_shopid'], implode("','", $facArr));
			$table = 'bc_number join bc_product on pro_id = num_pro_id';
			$B2cBase = new B2cBase();
			$res = $B2cBase->get($table, ['distinct(pro_id) pro_id'], $where);
			$arr = array_column($res['data'], 'pro_id');
		}
		LibFc::ajaxJsonEncode(['status'=>true, 'data'=>$arr]);
	}


	//刷配件的宜配号码
	function refreshYpItem()
	{
		$B2cProduct = new B2cProduct();
		$res = $B2cProduct->refreshYpItem($_SESSION['_shopid'], $_POST['type'], explode(',', $_POST['facs']), $_POST['items']);
		LibFc::ajaxJsonEncode($res);
	}


	//大文件上传
	function uploadBigFile()
	{
		$OthUpload = new OthUpload();
		$res = $OthUpload->uploadBigFile($_POST);
		LibFc::ajaxJsonEncode($res);
	}

	//检测导入图片包
	function checkImportItemImgZip()
	{
		$B2cProduct = new B2cProduct();
		$optArr = $_POST;
		$res = $B2cProduct->checkImportItemImgZip($_SESSION['_shopid'], $optArr);
		LibFc::ajaxJsonEncode($res);
	}

	//导入配件图片
	function importItemImg()
	{
		$B2cProduct = new B2cProduct();
		$optArr = $_POST;
		$res = $B2cProduct->importItemImg($_SESSION['_shopid'], $optArr);
		LibFc::ajaxJsonEncode($res);
	}

	//
	public function batchImage()
    {
        if(empty($_POST['pro_id'])){
            LibFc::ajaxJsonEncode(['status' => false,'data' => '参数错误']);
        }
        if(empty($_POST['image_id'])){
            LibFc::ajaxJsonEncode(['status' => false,'data' => '参数错误']);
        }
        foreach ($_POST['pro_id'] as $proId)
        {
            $result = (new B2cProduct)->setProductPic($_SESSION['_shopid'],$proId,$_POST['image_id']);
        }
        LibFc::ajaxJsonEncode($result);
    }

    /**
     * [correctiveFeedback 纠错反馈筛选页面]
     * @Author   Yangxing
     * @DateTime 2019-10-15T10:13:54+0800
     * @return   [type]                   [description]
     */
    function correctiveFeedback()
    {
        $params = mvc::$URL_PARAMS;
        $page = isset($params['page']) ? $params['page'] : 1;
        $perPage = isset($_COOKIE['perPage']) ? $_COOKIE['perPage'] : 25;
        $othBase = new OthBase();
        $table = 'ot_jiucuo ';

        //普通index 产品item 车架号解码vin
        $jcType = [
            'index' => '普通',
            'item' => '产品',
            'vin' => '车架号解码'
        ];
        $where = sprintf(" and jc_shop_id =%d", $_SESSION['_shopid']);
        if (is_numeric($params['jc_status'])) {
            $where .= sprintf(" and jc_status = %d", $params['jc_status']);
        }
        if (!empty($params['jc_type'])) {
            $where .= sprintf(" and jc_type = %s ",'\''.$params['jc_type'].'\'');
        }
        $res = $othBase->get($table, ['count(*) as count'], $where, true);
        $total = $res['data']['count'];
        $list = [];
        $readArr = [];

        if ($total > 0) {
            $where .= sprintf(' order by jc_atime desc limit %d,%d', ($page - 1) * $perPage, $perPage);
            $res = $othBase->get($table, ['*'], $where);
            $lists = $res['data'];
            foreach ($lists as &$value){
                if(!empty($value['jc_imgs'])){
                    //var_dump($value['jc_imgs']);exit();
                    $value['jc_imgs'] = explode(';',$value['jc_imgs']);
                }
            }
            //var_dump($lists);exit;
            LibTpl::Set('proArr', $lists);
        }
        $headArr = [
            'title'=>'配件组合-跑街的',
            'keyword'=>'',
            'des'=>''
        ];

        LibTpl::Set('headArr', $headArr);
        LibTpl::Set('LeftMenu','jiucuo');
        LibTpl::set('jcType', $jcType);
        LibTpl::Set('notReadCount', $res['data']['count']);
        LibTpl::Set('Page', LibPage::Show($total, $perPage, true));
        LibTpl::Set('list', $list ?: []);
        LibTpl::Set('params', $params);
        LibTpl::Set('readArr', $readArr ?: []);
        LibTpl::Set('title', '纠错反馈');
        LibTpl::Put();

    }

    /**
     * [audit 审核接口]
     * @Author   Yangxing
     * @DateTime 2019-10-15T11:30:49+0800
     * @return   [type]                   [description]
     */
    function audit()
    {
        $params = mvc::$URL_PARAMS;
        if ($_POST['jc_id']) {
            if(!is_numeric($_POST['jc_status'])) return LibFc::ajaxJsonEncode(['status' => false, 'data' => '参数错误']);
            if (empty($_POST['content'])) return LibFc::ajaxJsonEncode(['status' => false, 'data' => '处理意见不可为空']);
            $othBase = new OthBase();
            $where = sprintf(" and jc_shop_id = %d and jc_id = %d", $_SESSION['_shopid'], $_POST['jc_id']);
            $result = $othBase->get('ot_jiucuo ', ['*'], $where, true);
            if (!$result['data']) return LibFc::ajaxJsonEncode(['status' => false, 'data' => '不存在该记录']);
            $a = time();
            //拼装需要更新的字段
            $data = [
                'jc_status' => $_POST['jc_status'] ?: 0,//更改状态
                'jc_check_time' => $a, //更改处理时间
                'jc_check_remark' => $_POST['content'], //更改处理意见
            ];
            $res = $othBase->Set('ot_jiucuo ', $data, $where);
            $res['time'] = date('Y-m-d H:i',$a);
            LibFc::ajaxJsonEncode($res);
        }
        LibFc::ajaxJsonEncode(['status'=>false,'data' => '参数错误']);
    }

    /**
     * [deleteFeedback 删除接口]
     * @Author   Yangxing
     * @DateTime 2019-10-15T18:27:31+0800
     * @return   [type]                   [description]
     */
    function deleteFeedback()
    {
        if((!$_POST['jc_id'] && $_POST['jc_id'] >=1 && is_numeric($_POST['jc_id'])) || empty($_POST['jc_id']))
        {
            LibFc::ajaxJsonEncode(['status' => false, 'data' => '参数错误']);
        }
        $othBase = new OthBase();
        $result = $othBase->del('ot_jiucuo ', sprintf(' and jc_id = %d and jc_shop_id = %d ', $_POST['jc_id'], $_SESSION['_shopid']));
        LibFc::ajaxJsonEncode($result);
    }
}
