<?php
class YpwUserTj extends YpwBase
{
	//统计入库
	public function addVinTj($dataArr)
	{
		if(empty($ip)) $ip = LibFc::GetClientIp();
		$btime = strtotime(date('Y-m-d'));
		$dataArr['v_vin'] = LibFc::FormatVin($dataArr['v_vin']);
		if(strlen($dataArr['v_vin']) == 17)
		{
			$where = sprintf(" and v_from = 'PJD' and v_uid=%d and v_atime >= %d and v_vin='%s'", $dataArr['v_uid'], $btime, LibFc::Escape($dataArr['v_vin']));
			$res = $this->Get('yt_vin', ['v_vin'], $where, true);
			if(empty($res['data']))
			{
				$this->Add('yt_vin', $dataArr);
			}
		}
		return LibFc::ReturnData(true, true);
	}

	/**
	  * @method 检查是否可以进行VIN解码（普通会员10次/天、店主、企业会员100次/天）
	  * @param  $vin  车架号
	  * @author soul
	  * @copyright 2018/4/2
	  * @return 
			成功 ["status"=>true, "data"=>] 
			失败 ["status"=>false, "data"=> 错误信息] 
	  */
	public function checkVinTj($vin)
	{
		if(strlen($vin) == 17 && !empty($_SESSION['_userid']))
		{
			if(empty($_SESSION['_vinCount'])) $_SESSION['_vinCount'] = 10;
			$YpwBase = new YpwBase();
			$res = $YpwBase->get('yt_vin', ['count(distinct v_vin) count'], sprintf(" and v_uid=%d and v_atime >= %d and v_from in ('PJD')", $_SESSION['_userid'], strtotime(date('Y-m-d'))), true);
			if(!empty($res['data']) && isset($res['data']['count']) && $res['data']['count'] < $_SESSION['_vinCount'])
			{
				return LibFc::ReturnData(true, true);
			}
		}
		return LibFc::ReturnData(true, false);
	}

}