<?php
defined('IN_TS') or die('Access Denied.');

class share{

	var $db;
	private $share_module;
	private $url;
	private $content;

	//通过URL构造获取相应的采集解析模型
	public function __construct($dbhandle)
	{
		$this->db = $dbhandle;
		$class = 'taobao';
		$file = THINKROOT."/letutao/class.share.php";
		if(file_exists($file))
		{
			require_once $file;
			$class_name = $class."_sharegoods";
			if(class_exists($class_name))
			{
				$this->share_module = new $class_name;
			}
		}
	}

	/**
	 * 返回结果为false时采集失败
	 */
	public function fetch()
	{
		if($this->share_module)
		{
			
			return $this->share_module->fetch($this->url);
		}
		else
			return false;
	}
	
	
	/**
	 * 获取页面内容
	 */
	public function get_content()
	{
	
		if($this->share_module)
		{
			$id = $this->getID($this->url);
			$taobao_url  = "http://item.taobao.com/item.htm?id=".$id;
			$tmall_url  = "http://detail.tmall.com/item.htm?id=".$id;
			$thiscontent  =  $this->share_module->gethtml($taobao_url);
			if(!$thiscontent) $thiscontent  =  $this->share_module->gethtml($tmall_url);
			$this->content = mb_convert_encoding($thiscontent,"UTF-8","gbk");
			
		}
		else
			return false;
	}
	
	
	/**
	 * 前台发布商品
	 */
	public function add_good($post,$userid=1,$publish=false)
	{
			global $DISK_YUN;
			
			$arrimg = is_array($post['imgs'])?$post['imgs']:explode(',',$post['imgs']);//多图

			if(empty($arrimg)&&!$publish)
			{
							$json['status'] = 0;
							$json['msg'] = "至少要选择一张图片吧...";
							outputJson($json);
			}

			$info = trim($post['info']);
			$arrresult  = mb_unserialize(base64_decode($info));
			$shop_info =  $arrresult['shop'];
			
			if(is_array($arrimg)){
				foreach($arrimg as $key=>$item){
				$item = str_replace('_40x40.jpg','',$item);
				$item = str_replace('_100x100.jpg','',$item);
				$item = str_replace('_50x50.jpg','',$item);
				$item = str_replace('_60x60.jpg','',$item);
				$item = str_replace('_60x60q90.jpg','',$item);
				$strimg.= $item.'|';
			}};
			
		
			$post['tags']= str_replace(',',' ',$post['tags']);
			$post['tags'] = is_array($post['tags'])?implode(' ',$post['tags']) : $post['tags'];
			$pic_url     = $arrresult['item']['pic_url'];
			$name	     = t(trim($post['title']));
			$content	 = t(trim($post['content']));
			$tags        = trim($post['tags']);
			$defaulttags =  trim($post['defaulttags']);
			$cate_id     = intval(trim($post['cate_id']));
			$salenum     = intval(trim($post['salenum']));
			$themeid     = intval(trim($post['themeid']));
			$comment     = t(trim($post['comment']));
			$catename    = t(trim($post['catename']));
			$islike      = trim($post['favor']);

			$cateData = $this->db->once_fetch_assoc("select cate_id from ".dbprefix."goods_cate where cate_name like '".$catename."'");
			$cate_id = $cateData['cate_id'];
			
			
			if(empty($tags))
			{
							$json['status'] = 0;
							$json['msg'] = "至少要选择一个标签吧...";
							outputJson($json);
			}
			
			if($catename == '发现喜欢（未找到合适分类）' || empty($cate_id))
			{
							$cate_id = 1;
			}
	
			$uptime = time();
			$fold = date('Ymd',$uptime);
			
			$random = random(14);
			$dir = "cache/thumb/index/".$fold;
			!is_dir($dir)?mkdir($dir,0777):'';
			$imgurl="cache/thumb/index/".$fold."/".$random."w210.jpg";
			$pic_url1=explode('|',$strimg);
			$pic_url1= $pic_url1[0];
			require_once 'letutao/class.image.php';
			
			$resizeimage = new tsImg("$pic_url1", "210", "", "0", "$imgurl" );
			if(!is_file($imgurl)) $resizeimage = new tsImg("$pic_url", "210", "", "0", "$imgurl" );
			
			if(!is_file($imgurl)&&$publish) return 'Cantresizeimage';
			$img_info = getimagesize($imgurl);	
			$img_h= $img_info[1];
			if($DISK_YUN['isopen']){
				if(!aac('system')->DiskYun_baidu_upload($imgurl)){
					echo '<script>alert("文件上传到云空间失败，请检查云存储配置,暂用本地图片！")</script>';
				}
			}
			$img = $imgurl;
			$bf_random = rand(1,100);
			if($arrresult['item']['coupon_price']){
				$arrData = array(
					'uid'				 => intval($userid),
					'img'				 => $img,
					'img_h'				 => $img_h,
					'oldimg'			 => $strimg?$strimg:$arrresult['item']['pic_url'],
					'name'	             => $name,
					'price'				 => intval($arrresult['item']['price']),
					'taoke_url'		     => $arrresult['item']['taoke_url'],
					'url'		         =>  str_replace('&spm=2014.12369186.0.0','',$arrresult['item']['url']),
					'seller_credit_score'=> $arrresult['item']['seller_credit_score']?$arrresult['item']['seller_credit_score']:0,
					'shop_info'		     => serialize($shop_info),
					//折扣价
					'cate_id'		     => intval($cate_id),
					'salenum'		     => intval($salenum),
					'count_like'		 => intval($salenum+$bf_random),
					'comment'		     => $comment,
					'uptime'		     => time(),
				);
				
			}else{
				$arrData = array(
					'uid'				 => intval($userid),
					'img'				 => $img,
					'img_h'				 => $img_h,
					'oldimg'			 => $strimg?$strimg:$arrresult['item']['pic_url'],
					'name'	             => $name,
					'price'				 => intval($arrresult['item']['price']),
					'taoke_url'		     => $arrresult['item']['taoke_url'],
					'url'		         =>  str_replace('&spm=2014.12369186.0.0','',$arrresult['item']['url']),
					'seller_credit_score'=> $arrresult['item']['seller_credit_score']?$arrresult['item']['seller_credit_score']:0,
					'shop_info'		     => serialize($shop_info),
					//折扣价
					'cate_id'		     => intval($cate_id),
					'salenum'		     => intval($salenum),
					'count_like'		 => intval($salenum+$bf_random),
					'comment'		     => $comment,
					'uptime'		     => time(),
				);
				
			}

		//限制发布时间 2秒内
		$limitgood = $this->db->once_fetch_assoc("select uptime from ".dbprefix."share_goods where uid='".$userid."' order by uptime desc");
		if(!$publish){
			if($uptime-$limitgood['uptime']>2) $goodsid = $this->db->insertArr($arrData,dbprefix.'share_goods');
		}else{
			$goodsid = $this->db->insertArr($arrData,dbprefix.'share_goods');
		}
		
		//添加到主题
		if($themeid){
			
			$tData = $this->db->once_fetch_assoc("select strgoodid,simg from ".dbprefix."theme where themeid='".$themeid."'");
	
			$strid = $tData['strgoodid']?$tData['strgoodid'].','.$goodsid:$goodsid;
			
			if(!$tData['simg']){
	
				$simgurl = aac('zhuti')->themesimg($goodsid);
				$this->db->query("update ".dbprefix."theme set `simg`='$simgurl',uptime='$uptime' where themeid='".$themeid."'");
				
			}
	
			$arr = explode(',',$tData['strgoodid']);
			if(!in_array($goodsid,$arr)){
			$this->db->query("update ".dbprefix."theme set `strgoodid`='$strid' where themeid='$themeid'");
			}
	
		}
	
	
		aac('sharetag')->addTag('share','goods_id',$goodsid,$tags);
		
		aac('sharetag')->addTag('default','goods_id',$goodsid,$defaulttags);
		
		if($themeid>0){
			$this->db->query("update ".dbprefix."theme set `goodsnum`=goodsnum+1,uptime=".time()." where themeid='$themeid'");
		}
		
				//更新积分
		$this->db->query("update ".dbprefix."user_info set `count_score`=count_score+2 where userid='$userid'");
		
		
		//feed开始
		//限制发布时间 2秒内
		$uptime = time();
		$limitfeed = $this->db->once_fetch_assoc("select addtime from ".dbprefix."feed where userid='".$userid."' order by addtime desc");
		if($uptime-$limitfeed['addtime']>2){;
		$feed_template = '<a href="{link}" title="{title}"><img src="{img}" width="120" alt="{title}" title="{title}"></a></div><div class="pro-info"><h3 class="ofh"><a href="{link}" target="_blank">{title}</a></h3><p class="pro-intro">{content}</p><div class="friend-comment-list">';
	
		$feed_data = array(
			'link'	=>  tsurl('baobei',$goodsid),
			'title'	=> $name,
			'ctyle' => '分享了宝贝',
			'goods_id' => $goodsid,
			'img'	=> $img,
			'content'	=> getsubstrutf8(t($comment),'0','50'),
		);
		aac('feed')->addFeed($userid,$feed_template,serialize($feed_data),'goods',$goodsid);
		}
		//feed结束
		
		//更新喜欢
		if($islike){
			$this->db->query("insert into ".dbprefix."share_goods_like (`userid`,`goods_id`,`commentType`,`addtime`) values ('".$userid."','".$goodsid."','0','".time()."')");
			$this->db->query("update ".dbprefix."share_goods set count_like='$islike' where goods_id='$goodsid'");
			
			}
	
	
		$this->url = $arrresult['item']['url'];
		$this->GetAndIntoComment($goodsid,$arrresult['item']['url']);
		$this->GetAndIntonetComment($goodsid);
		return $goodsid;
	}
	
	
	/**
	 * 发布采集商品
	 */
	public function add_publish_good($post,$userid=1,$publish=false)
	{
			global $DISK_YUN;
			if(is_array($post['imgs'])){

				foreach($post['imgs'] as $key=>$item){
				$item = str_replace('_40x40.jpg','',$item);
				$item = str_replace('_100x100.jpg','',$item);
				$item = str_replace('_60x60.jpg','',$item);
				$item = str_replace('_60x60q90.jpg','',$item);
				$strimg.= $item.'|';
			}};
			$info = trim($post['info']);
			$arrresult  = mb_unserialize(base64_decode($info));
			$shop_info =  $arrresult['shop'];
				//折扣价
			$coupon_price		 =  $arrresult['item']['coupon_price'];
			$coupon_start_time	 =  $arrresult['item']['coupon_start_time'];
			$coupon_end_time	 =  $arrresult['item']['coupon_end_time'];

			$post['tags'] = is_array($post['tags'])?implode(' ',$post['tags']) : $post['tags'];
			$pic_url     = $arrresult['item']['pic_url'];
			$name	     = t(trim($post['name']));
			$content	 = t(trim($post['content']));
			$tags        =  trim($post['tags']);
			$defaulttags =  trim($post['defaulttags']);
			$cate_id     = intval(trim($post['cate_id']));
			$themeid     = intval(trim($post['themeid']));
			$comment     = t(trim($post['comment']));
			$catename    = t(trim($post['catename']));
			$islike      = trim($post['tomyfav']);
			
			$cateData = $this->db->once_fetch_assoc("select cate_id from ".dbprefix."goods_cate where cate_name like '".$catename."'");
			$cate_id = $cateData['cate_id'];
			if($catename == '发现喜欢（未找到合适分类）' || empty($cate_id)) $cate_id = 1;
	
			$uptime = time();
			$fold = date('Ymd',$uptime);
			
			$random = random(14);
			$dir = "cache/thumb/index/".$fold;
			!is_dir($dir)?mkdir($dir,0777):'';
			$imgurl="cache/thumb/index/".$fold."/".$random."w210.jpg";
			$pic_url1=explode('|',$strimg);
			$pic_url1= str_replace('_100x100.jpg','',$pic_url1[0]);
			
			require_once 'letutao/class.image.php';
			$resizeimage = new tsImg("$pic_url1", "210", "", "0", "$imgurl" );
		
			if(!is_file($imgurl)) $resizeimage = new tsImg("$pic_url", "210", "", "0", "$imgurl" );
			
			if(!is_file($imgurl)&&$publish) return 'Cantresizeimage';
			$img_info = getimagesize($imgurl);	
			$img_h= $img_info[1];
			if($DISK_YUN['isopen']){
				if(!aac('system')->DiskYun_baidu_upload($imgurl)){
					echo '<script>alert("文件上传到云空间失败，请检查云存储配置,暂用本地图片！")</script>';
				}
			}
			$img = $imgurl;
				$arrData = array(
					'uid'				 => intval($userid),
					'img'				 => $img,
					'img_h'				 => $img_h,
					'oldimg'			 => strlen($strimg)>10?$strimg:$arrresult['item']['pic_url'],
					'name'	             => $name,
					'price'				 => intval($arrresult['item']['price']),
					'taoke_url'		     => $arrresult['item']['taoke_url'],
					'url'		         =>  str_replace('&spm=2014.12369186.0.0','',$arrresult['item']['url']),
					'seller_credit_score'=> $arrresult['item']['seller_credit_score']?$arrresult['item']['seller_credit_score']:0,
					'shop_info'		     => serialize($shop_info),
					//折扣价
					'coupon_price'		 => $coupon_price,
					'coupon_start_time'	 => $coupon_start_time,
					'coupon_end_time'	 => $coupon_end_time,
					'cate_id'		     => intval($cate_id),
					'comment'		     => $comment,
					'uptime'		     => time(),
				);

			$goodsid = $this->db->insertArr($arrData,dbprefix.'share_goods');

		aac('sharetag')->addTag('share','goods_id',$goodsid,$tags);
		
		aac('sharetag')->addTag('default','goods_id',$goodsid,$defaulttags);
		$this->url = $arrresult['item']['url'];
		$this->GetAndIntoComment($goodsid,$arrresult['item']['url']);
		$this->GetAndIntonetComment($goodsid);
		return $goodsid;
	}
	
	
	
	/**
	 * 创建采集的商品等待发布
	 */
	public function publish_good($val, $catename,$tag='', $userid=1)
	{
		$item['url']=$this->url='http://item.taobao.com/item.htm?id='.$val['auctionId'];
		$this->url = $item['url'];
		$this->get_content();
		$sNum = $this->db->once_fetch_assoc("select goods_id from ".dbprefix."share_goods where url ='".$item['url']."'");
		if(is_array($sNum)){
			
			return 'isExists';
			
		}
		$post['name']=$val['title'];
		$tagsarr = $this -> newWords() -> segment($val['title'],10);
		$arrtags = $this -> newWords() -> segment($val['title'],100);
		
		$tagsarr[0]=$tag;
		$$arrtags[0]=$tag;

		$post['tags']=$tagsarr;
		$post['defaulttags']=$arrtags;
		$post['cate_id']='';
		$post['themeid']='';
		$post['comment']=$val['title'];
		if($catename){
			$strcate = $this->db->once_fetch_assoc("select * from ".dbprefix."goods_cate where appname LIKE '%".$catename."%'");
			$post['catename']=$strcate['cate_name'];
			
			
		}else{
			
			$post['cate_id']=$this->getCateByTags($arrtags);
			$cateData = $this->db->once_fetch_assoc("select cate_name from ".dbprefix."goods_cate where cate_id='".$post['cate_id']."'");
			$post['catename']=$cateData['cate_name'];
		
		}

			$post['tomyfav']=$val['commentCount'];
		
			$item['key']='taobao_'.$val['auctionId'];
			$item['nick']=$val['nick'];
			$item['name']=$val['title'];
			$item['price']=$val['reservePrice'];
			$item['taoke_url']=str_replace(':80','',$val['auctionUrl']);
			$item['seller_credit_score']=$val['seller_credit_score'];
			$item['pic_url']=$val['pictUrl'];
				
	if($val['zkRate']!=='10'){
			$item['coupon_price']		 =  $val['zkPrice'];
			$item['coupon_start_time']	 =  0;
			$item['coupon_end_time']	 =  0;
	}
			$shop['nick']=$val['nick'];
			$shop['delivery_score']=$val['delivery_score'];
			$shop['item_score']=$val['delivery_score'];
			$shop['service_score']=$val['delivery_score'];
			
		$info = array(
			'item'=>$item,
			'shop'=>$shop
			);
			
		$post['info']=base64_encode(serialize($info));
		//抓取多图
		$getmorepic = $this->GetMorepic();
		$post['imgs'] = $getmorepic;
		$post['name']=$val['title'];
		$post['coupon_price']		 =  $val['zkPrice'];
		$goodsid =$this->add_publish_good($post,$userid,true);
		return $goodsid;
		
	}
	
	
	/**
	 * 通过url获取商品信息
	 */
	public function getyun_goodinfo_by_url($url,$get_tao_url=0)
	{
		$id = $this->getID($url);
		if($this->share_module)
			{
			$data = $this->share_module->snoopy("http://au.letushuo.com/index.php?app=share&ac=ajax&tid=".$id);

			return json_decode($data, true);

			}
	
	}
	
	
	/**
	 * 通过url获取商品信息
	 */
	public function get_goodinfo_by_url($url,$get_tao_url=0)
	{
		$this->url = $url;
		$result=$this->fetch();
		$this->get_content();
		if($result['goods_id']){
			$sNum = $this->db->once_fetch_assoc("select goods_id,name,img from ".dbprefix."share_goods where goods_id ='".$result['goods_id']."'");
			if(is_array($sNum)){
				
				$sNum['status']=2;
				$sNum['tags'] = $arrtags;
				$sNum['img'] = array(0=>$sNum['img']);
				return $sNum;
				exit;
			}
		}
	
		if($get_tao_url) return $result['item']['taoke_url'];

		$name =$result['item']['name'];
		$tagsarr = $this -> newWords() -> segment($name,10);
		$arrtags = $this -> newWords() -> segment($name,100);
		foreach($tagsarr as $key=>$item){
			$tags .= '<li>'.$item.'</li>';
		}
		foreach($tagsarr as $key=>$item){
		$defaulttags .= $item.' ';
		}
		$cate_id = $this->getCateByTags($arrtags);
		$cateData = $this->db->once_fetch_assoc("select cate_name from ".dbprefix."goods_cate where cate_id='".$cate_id."'");
		$cate_name = $cateData['cate_name'];
		if($result)
		{
			
			$json['status'] = 1;
			$json['info'] = base64_encode(serialize($result));
		
			$result['item']['url'] = str_replace('&spm=2014.12369186.0.0','',$result['item']['url']);
			
			$json['pic_url'] = $result['item']['pic_url'];
			$json['name'] = $result['item']['name'];
			$json['tags'] = $tags;
			$json['cate_name'] = $cate_name;
			$json['defaulttags'] = $defaulttags;
			$json['cate_id'] = $cate_id;
			$json['price'] = $result['item']['price'];
			$json['url'] = $result['item']['url'];
			$userid = intval($TS_USER['user']['userid']);
			return $json;
			exit;
		}
		else
		{
			return false;
		}
	}
	
	/**
	 * 通过商品标题获取标签
	 */
	public function newWords()
	{
		require_once (THINKROOT.'/plugins/words/words_class.php');
		$Words = new WordsService();
		return $Words;
	}
	
	
	
	/**
	 * 返回淘宝分类
	 */
	public function Taobaocats($cid=0)
	{
		if($this->share_module)
		{
			return $this->share_module->_GetTaobaocats($cid);
		}
		else
			return false;
	}
	
	/**
	 * 获取商品列表
	 */
	public function _get_list($map, $p)
	{

		if($this->share_module)
		{
			return $this->share_module->_get_list($map, $p);
		}
		else
			return false;
	}

	/**
	 * 获取该商品的标识，用于检测是否已经采集
	 */
	public function getKey()
	{
		if($this->share_module)
		{
			return $this->share_module->getKey($this->url);
		}
		else
			return '';
	}

	/**
	 * 检测是否已经采集过商品
	 */
	public function getExists($goods)
	{
		$key = $this->getKey();
		if(isset($goods[$key]))
			return true;
		else
			return false;
	}
	
	/**
	 * 根据标题标签判断所属类别
	 */
	
	public function getCateByTags($tags)
	{
		static $tag_cates = array();

		$tags = array_unique($tags);

		foreach($tags as $tag)
		{
			if(!empty($tag))
			{
				
		$arrttg = $this->db->fetch_all_assoc("select tag_id,tag_name from ".dbprefix."goods_tags where tag_name = '".$tag."'");
		
		foreach($arrttg as $data)
					{
						$arrcate = $this->db->fetch_all_assoc("select cate_id,weight from ".dbprefix."goods_category_tags where tag_id = '".$data['tag_id']."'");
						foreach($arrcate as $cdata)
							{
								$cateid = $cdata['cate_id'];
								$cate_id[$cateid] += $cdata['weight'];
							}
					}
			}
		}

		return array_search(max($cate_id),$cate_id);
	}
	
		//获取一条用户评论
		
		public function GetOneComment($shareid){
			
		$OneComment = $this->db->once_fetch_assoc("select userid,content from ".dbprefix."share_goods_comments where shareid=".$shareid." order by addtime desc");
		$OneComment['user'] = aac('user')->getSimpleUser($OneComment['userid']);
		
		
		$content_sub = explode('|||',$OneComment['content']);
		
		$arrShareComment[$key]['content'] = t($content_sub[1]?$content_sub[1]:$content_sub[0]);
		$OneComment['content']=t($content_sub[1]?$content_sub[1]:$content_sub[0]);
		
		if($OneComment['userid']==0) $OneComment['user']['username'] = count($content_sub)>1?$content_sub[0]:'买过的人说';
		return $OneComment;
			
	}
	
	
		//获取商品多图
		
		public function GetMorepic(){
			
			return  $this->share_module->GetMorepic($this->content);
		}
		
		//获取互联网评论
		public function GetComment($url,$showContent='1')
	{
		//获取USERID
		$this->url = $url;
		$this->get_content();
		$urlid = $this->getID($this->url);
        preg_match('/sellerId=(.*)&u=/', $this->content, $sellerId);
		
		if(!$sellerId[1]){
			  preg_match('/data-sellerid="(.*)" data-catid="/', $this->content, $sellerId);
			
		}
		if(!$sellerId[1]){
			 preg_match('/sellerId:\"(.*)\",shopId/', $this->content, $sellerId);
		}
		
		$re_url='http://rate.taobao.com/feedRateList.htm?callback=jsonp_reviews_list&userNumId='.$sellerId[1].'&auctionNumId='.$urlid.'&currentPageNum=1';

		$str= $this->share_module->snoopy($re_url);

		$str = mb_convert_encoding($str,"UTF-8","gbk");

		$str = str_replace('jsonp_reviews_list(','',$str);//去掉多余的字符串
		$str = str_replace(')','',$str);
		$arr_str = json_decode($str,TRUE);
		/*  多页评论
			if($arr_str['rateListInfo']['paginator']['lastPage']>1){
				
				for ($i = 1; $i <= $arr_str['rateListInfo']['paginator']['lastPage']; $i++) {
						$re_url = 'http://rate.taobao.com/detail_rate.htm?userNumId='.$sellerId[1].'&auctionNumId='.$urlid.'&page='.$i;
						$str_m= $this->share_module->snoopy($re_url);
		
						$str_m.= mb_convert_encoding($str,"UTF-8","gbk");
					}
				$arr_str_m =json_decode(trim(str_replace('TB.detailRate = ','',$str_m)),true);
				
			}
		*/	
		return $arr_str['comments'];
		
		
		}
		
		
		//获取并写入互联网评论
		public function GetAndIntoComment($shareid,$url,$cnum=8)
	{
				$hz = array('年','月','日');
				$arrs = $this->GetComment($url);

				foreach ($arrs as $key=>$item)
				{
					$arrData	= array(
							'shareid'			=> intval($shareid),
							'userid'			=> '0',
							'content'	        => $item['content'],
							'addtime'		    => strtotime(str_replace($hz,'',$item['date'])),
						);
						$commentid = $this->db->insertArr($arrData,dbprefix.'share_goods_comments');
						//统计评论数
						$count_comment = $this->db->once_num_rows("select * from ".dbprefix."share_goods_comments where shareid='$shareid'");
						if($count_comment == $cnum){
							break;
						}
				}
				$count_comment = intval($count_comment) > 0 ? intval($count_comment) : '0';
				$uptime = time();
				$this->db->query("update ".dbprefix."share_goods set uptime='$uptime',count_comment='$count_comment' where goods_id='$shareid'");

			
		
	}
	
	/*
	 *添加云服务器采集的商品评论
	 */
	 public function GetAndIntonetComment($shareid,$cnum=5)
	{
                
				$arrs = fileRead('data.php','data','comment');
                if($arrs['flag']==0)
				{
				 foreach ($arrs['content'] as $key=>$item)
				 {
					
					$arrData	= array(
							'shareid'			=> intval($shareid),
							'userid'			=> '0',
							'content'	        => $item['content'],
							'addtime'		    => $item['addtime'],
						);
				
						$commentid = $this->db->insertArr($arrData,dbprefix.'share_goods_comments');
						//统计评论数
						$count_comment = $this->db->once_num_rows("select * from ".dbprefix."share_goods_comments where shareid='$shareid'");
						$count_comment = intval($count_comment) > 0 ? intval($count_comment):'0';
						$uptime = time();
						$this->db->query("update ".dbprefix."share_goods set uptime='$uptime',count_comment='$count_comment' where goods_id='$shareid'");
					
				}
			}
			$arrs['flag']=1;
			fileWrite('comment_data.php','data',$arrs);
	}
	
	public function getID($url)
	{
		$id = 0;
		$parse = parse_url($url);
		if(isset($parse['query']))
		{
            parse_str($parse['query'],$params);
			if(isset($params['id']))
				$id = $params['id'];
            elseif(isset($params['item_id']))
                $id = $params['item_id'];
			elseif(isset($params['mallstItemId']))
                $id = $params['mallstItemId'];
			elseif(isset($params['default_item_id']))
                $id = $params['default_item_id'];
        }
		return $id;
	}
	
		public function getAddress($id)
	{
		
		$useraddress=$this->db->once_fetch_assoc("select * from ".dbprefix."address where aid='".$id."'");
		
		return $useraddress;
	}
	

}