<?php


namespace Home\Controller;
use Think\Controller;
class AuctionController extends CommonController {
	
    public function index(){
    	
    	
    	
    	
    	
      
      
      
      $gt = explode('-', I('get.gt'));
      $gtCount = count($gt);
      if($gtCount==1){
        if($gt[0]!=''){
          $gt = array($gt[0],'12','0','0_0_0',getTopField($gt[0]),'i','a');
        }else{
          $gt = array('1','12','0','0_0_0',getTopField(1),'i','a');
        }
      }elseif ($gtCount!=7) {
        $this->error('页面不存在');
      }
      $bidMap = D('Auction');
      
      $bid_yn = array();
      if($gt[6]=='y'){
        $bid_yn = array('uid'=>array('neq',0));
      }elseif ($gt[6]=='n') {
        $bid_yn = array('uid'=>array('eq',0));
      }
      
    	$section = bidSection($gt[2]); 
      
      $reg_where=bidRegion($gt[3]);
      
      $bC = bidChannel($gt[0]);
      
      $this->set_page=$bidMap->set_page($gt);
      
      $this->end_section=$bidMap->end_section($gt,$bC['gt0'],array_merge($bC['cat_inCid'],$bid_yn));

    	
    	
    	
      
      
    	$filt_where = array_merge($section,$bC['bid_inCid']); 
      $filtParMap=$bidMap->where($filt_where)->field('pid,filtrate')->select();
      $filtSear =explode('_', $gt[4]);
      $unlimited = getTopField($gt[0],'arr'); 
      
      $newFiltSear = array_unique(array_merge($unlimited,$filtSear)); 
      foreach ($filtParMap as $fpk => $fpv) {
        
        $newFilt = array_unique(array_merge($unlimited,explode('_', $fpv['filtrate']))); 
        if($newFiltSear == array_intersect($newFilt,$newFiltSear)){
          $inSuitFiltPid[]=$fpv['pid']; 
        }
      }
      $bid_inFilt = array('pid'=>array('in',$inSuitFiltPid)); 

      
      $bid_type = $gt[5]!='i' ? array('type'=>$gt[5]) : array();

      $bid_where = array_merge($filt_where,$bid_inFilt,$reg_where,$bid_type,$bid_yn); 
    	
    	$count = $bidMap->where($bid_where)->count();
      $pConf = page($count,$gt[1]);
      $bidArr[0]['bid_list'] = $bidMap->where($bid_where)->limit($pConf['first'].','.$pConf['list'])->select();
      $bidArr[0]['abc'] = 0;
      
      $this->page = $pConf['show']; 
      
      $this->bidArr=$bidArr;


      $slist[0]['slistA'] = $bidMap->where($bC['bid_inCid'])->where(foreshow(0))->order('starttime')->limit(4)->select();
      $slist[0]['slistJ'] = $bidMap->where($bC['bid_inCid'])->where(foreshow(1))->order('starttime')->limit(4)->select();
      $slist[0]['slistM'] = $bidMap->where($bC['bid_inCid'])->where(foreshow(2))->order('starttime')->limit(4)->select();
      $slist[0]['slistH'] = $bidMap->where($bC['bid_inCid'])->where(foreshow(3))->order('starttime')->limit(4)->select();
      $slist[0]['slistQ'] = $bidMap->where($bC['bid_inCid'])->where(foreshow(4))->order('starttime')->limit(4)->select();
      $slist[0]['abc']=1;
      $this->slist=$slist;


      $eWstr = 'Auction.nowprice>Auction.price';
      $elist[0]['elistA'] = $bidMap->where($eWstr)->where($bC['bid_inCid'])->where(endbid(0))->order('endtime desc')->limit(4)->select();
      $elist[0]['elistJ'] = $bidMap->where($eWstr)->where($bC['bid_inCid'])->where(endbid(1))->order('endtime desc')->limit(4)->select();
      $elist[0]['elistZ'] = $bidMap->where($eWstr)->where($bC['bid_inCid'])->where(endbid(2))->order('endtime desc')->limit(4)->select();
      $elist[0]['elistQ'] = $bidMap->where($eWstr)->where($bC['bid_inCid'])->where(endbid(3))->order('endtime desc')->limit(4)->select();
      $elist[0]['abc'] = 2;
      $this->elist=$elist;

      
      $this->region=D('Auction')->regionList($gt,array_merge($filt_where,$bid_inFilt,$bid_yn));
      
    	$this->clist=$bidMap->catList($gt,array_merge($bC['cat_inCid'],$bid_yn)); 
      
    	$this->filt_html=getFiltrateHtml($gt[0],$gt);
      
      $this->gt=$gt;	

      
      $this->reg_gt = explode('_', $gt[3]);
      
      $this->gt0=$bC['gt0'];
      
      $this->ynUrl = array(
        'y'=>U('index',array('gt'=>$bC['gt0'].'-12'.'-0'.'-0_0_0'.'-'.getTopField($gt[0]).'-i'.'-y')),
        'n'=>U('index',array('gt'=>$bC['gt0'].'-12'.'-0'.'-0_0_0'.'-'.getTopField($gt[0]).'-i'.'-n'))
        );
      
      $this->typeUrl = array(
        'pai'=>U('index',array('gt'=>$bC['gt0'].'-12'.'-0'.'-0_0_0'.'-'.getTopField($gt[0]).'-0'.'-a')),
        'biao'=>U('index',array('gt'=>$bC['gt0'].'-12'.'-0'.'-0_0_0'.'-'.getTopField($gt[0]).'-1'.'-a'))
        );
      
      $this->channelName = M('Goods_category')->where('cid='.$gt[0])->getField('name');
    	$this->display();
     }
     
     public function waitbid(){
      
      
      
      
      
      
      
      
      $gt = explode('-', I('get.gt'));
      $gtCount = count($gt);
      if($gtCount==1){
        if($gt[0]!=''){
          $gt = array($gt[0],'12','0','0_0_0',getTopField($gt[0]),'i','a');
        }else{
          $gt = array('1','12','0','0_0_0',getTopField(1),'i','a');
        }
      }elseif ($gtCount!=7) {
        $this->error('页面不存在');
      }
      $bidMap = D('Auction');
      
      $bid_yn = array();
      if($gt[6]=='y'){
        $bid_yn = array('uid'=>array('neq',0));
      }elseif ($gt[6]=='n') {
        $bid_yn = array('uid'=>array('eq',0));
      }
      
      $section = foreshow($gt[2]); 
      
      $reg_where=bidRegion($gt[3]);
      
      $bC = bidChannel($gt[0]);
      
      $this->set_page=$bidMap->set_page($gt);
      
      $this->end_section=$bidMap->wait_section($gt,$bC['gt0'],$bC['cat_inCid']);

        
        
        
      

      
        $filt_where = array_merge($section,$bC['bid_inCid']); 
      $filtParMap=$bidMap->where($filt_where)->field('pid,filtrate')->select();
      $filtSear =explode('_', $gt[4]);
      $unlimited = getTopField($gt[0],'arr'); 
      
      $newFiltSear = array_unique(array_merge($unlimited,$filtSear)); 
      foreach ($filtParMap as $fpk => $fpv) {
        
        $newFilt = array_unique(array_merge($unlimited,explode('_', $fpv['filtrate']))); 
        if($newFiltSear == array_intersect($newFilt,$newFiltSear)){
          $inSuitFiltPid[]=$fpv['pid']; 
        }
      }
      $bid_inFilt = array('pid'=>array('in',$inSuitFiltPid)); 
      
      $bid_type = $gt[5]!='i' ? array('type'=>$gt[5]) : array();

      $bid_where = array_merge($filt_where,$bid_inFilt,$reg_where,$bid_type); 
        
        $count = $bidMap->where($bid_where)->count();
      $pConf = page($count,$gt[1]);
      $bidArr[0]['bid_list'] = $bidMap->where($bid_where)->limit($pConf['first'].','.$pConf['list'])->select();
      $bidArr[0]['abc'] = 1;
      
      $this->page = $pConf['show']; 
      
      $this->bidArr=$bidArr;


      $slist[0]['slistA'] = $bidMap->where($bC['bid_inCid'])->where(bidSection(0))->order('starttime')->limit(4)->select();
      $slist[0]['slistJ'] = $bidMap->where($bC['bid_inCid'])->where(bidSection(1))->order('starttime')->limit(4)->select();
      $slist[0]['slistM'] = $bidMap->where($bC['bid_inCid'])->where(bidSection(2))->order('starttime')->limit(4)->select();
      $slist[0]['slistH'] = $bidMap->where($bC['bid_inCid'])->where(bidSection(3))->order('starttime')->limit(4)->select();
      $slist[0]['slistQ'] = $bidMap->where($bC['bid_inCid'])->where(bidSection(4))->order('starttime')->limit(4)->select();
      $slist[0]['abc']=0;
      $this->slist=$slist;


      $eWstr = 'Auction.nowprice>Auction.price';
      $elist[0]['elistA'] = $bidMap->where($bC['bid_inCid'])->where($eWstr)->where(endbid(0))->order('endtime desc')->limit(4)->select();
      $elist[0]['elistJ'] = $bidMap->where($bC['bid_inCid'])->where($eWstr)->where(endbid(1))->order('endtime desc')->limit(4)->select();
      $elist[0]['elistZ'] = $bidMap->where($bC['bid_inCid'])->where($eWstr)->where(endbid(2))->order('endtime desc')->limit(4)->select();
      $elist[0]['elistQ'] = $bidMap->where($bC['bid_inCid'])->where($eWstr)->where(endbid(3))->order('endtime desc')->limit(4)->select();
      $elist[0]['abc'] = 2;
      $this->elist=$elist;

      
      $this->region=D('Auction')->regionList($gt,array_merge($filt_where,$bid_inFilt));
      
        $this->clist=$bidMap->catList($gt,$bC['cat_inCid'],'wait'); 
      
        $this->filt_html=getFiltrateHtml($gt[0],$gt);
      
      $this->gt=$gt;    
      
      $this->reg_gt = explode('_', $gt[3]);
      
      $this->gt0=$bC['gt0'];
      
      $this->ynUrl = array(
        'y'=>U('index',array('gt'=>$bC['gt0'].'-12'.'-0'.'-0_0_0'.'-'.getTopField($gt[0]).'-i'.'-y')),
        'n'=>U('index',array('gt'=>$bC['gt0'].'-12'.'-0'.'-0_0_0'.'-'.getTopField($gt[0]).'-i'.'-n'))
        );
      
      $this->typeUrl = array(
        'pai'=>U('index',array('gt'=>$bC['gt0'].'-12'.'-0'.'-0_0_0'.'-'.getTopField($gt[0]).'-0'.'-a')),
        'biao'=>U('index',array('gt'=>$bC['gt0'].'-12'.'-0'.'-0_0_0'.'-'.getTopField($gt[0]).'-1'.'-a'))
        );
        
        $this->channelName = M('Goods_category')->where('cid='.$gt[0])->getField('name');
        $this->display();
     }
     
     public function endbid(){
      
      
      
      
      
      
      
      
      $gt = explode('-', I('get.gt'));
      $gtCount = count($gt);
      if($gtCount==1){
        if($gt[0]!=''){
          $gt = array($gt[0],'12','0','0_0_0',getTopField($gt[0]),'i','a');
        }else{
          $gt = array('1','12','0','0_0_0',getTopField(1),'i','a');
        }
      }elseif ($gtCount!=7) {
        $this->error('页面不存在');
      }
      $bidMap = D('Auction');
      
      $bid_yn = array();
      if($gt[6]=='y'){
        $bid_yn = array('uid'=>array('neq',0));
      }elseif ($gt[6]=='n') {
        $bid_yn = array('uid'=>array('eq',0));
      }
      
      $section = endbid($gt[2]); 
      
      $reg_where=bidRegion($gt[3]);
      
      $bC = bidChannel($gt[0]);
      
      $this->set_page=$bidMap->set_page($gt);
      
      $this->end_section=$bidMap->endbid_section($gt,$bC['gt0'],$bC['cat_inCid']);

        
        
        
      

      
        $filt_where = array_merge($section,$bC['bid_inCid']); 
      $filtParMap=$bidMap->where($filt_where)->field('pid,filtrate')->select();
      $filtSear =explode('_', $gt[4]);
      $unlimited = getTopField($gt[0],'arr'); 
      
      $newFiltSear = array_unique(array_merge($unlimited,$filtSear)); 
      foreach ($filtParMap as $fpk => $fpv) {
        
        $newFilt = array_unique(array_merge($unlimited,explode('_', $fpv['filtrate']))); 
        if($newFiltSear == array_intersect($newFilt,$newFiltSear)){
          $inSuitFiltPid[]=$fpv['pid']; 
        }
      }
      $bid_inFilt = array('pid'=>array('in',$inSuitFiltPid)); 
      
      $bid_type = $gt[5]!='i' ? array('type'=>$gt[5]) : array();

      $bid_where = array_merge($filt_where,$bid_inFilt,$reg_where); 
      $eWstr = 'Auction.nowprice>Auction.price';
        
        $count = $bidMap->where($eWstr)->where($bid_where)->count();
      $pConf = page($count,$gt[1]);

      $bidArr[0]['bid_list'] = $bidMap->where($eWstr)->where($bid_where)->limit($pConf['first'].','.$pConf['list'])->order('endtime desc')->select();
      $bidArr[0]['abc'] = 2;
      
      $this->page = $pConf['show']; 
      
      $this->bidArr=$bidArr;


      $zlist[0]['zlistA'] = $bidMap->where($bC['bid_inCid'])->where(bidSection(0))->order('endtime')->limit(4)->select();
      $zlist[0]['zlistJ'] = $bidMap->where($bC['bid_inCid'])->where(bidSection(1))->order('endtime')->limit(4)->select();
      $zlist[0]['zlistM'] = $bidMap->where($bC['bid_inCid'])->where(bidSection(2))->order('endtime')->limit(4)->select();
      $zlist[0]['zlistH'] = $bidMap->where($bC['bid_inCid'])->where(bidSection(3))->order('endtime')->limit(4)->select();
      $zlist[0]['zlistQ'] = $bidMap->where($bC['bid_inCid'])->where(bidSection(4))->order('endtime')->limit(4)->select();
      $zlist[0]['abc']=0;
      $this->zlist=$zlist;


      $slist[0]['slistA'] = $bidMap->where($bC['bid_inCid'])->where(foreshow(0))->order('starttime')->limit(4)->select();
      $slist[0]['slistJ'] = $bidMap->where($bC['bid_inCid'])->where(foreshow(1))->order('starttime')->limit(4)->select();
      $slist[0]['slistM'] = $bidMap->where($bC['bid_inCid'])->where(foreshow(2))->order('starttime')->limit(4)->select();
      $slist[0]['slistH'] = $bidMap->where($bC['bid_inCid'])->where(foreshow(3))->order('starttime')->limit(4)->select();
      $slist[0]['slistQ'] = $bidMap->where($bC['bid_inCid'])->where(foreshow(4))->order('starttime')->limit(4)->select();
      $slist[0]['abc']=1;
      $this->slist=$slist;

      
      $this->region=D('Auction')->regionList($gt,array_merge($filt_where,$bid_inFilt));
      
        $this->clist=$bidMap->catList($gt,$bC['cat_inCid'],'end'); 
      
        $this->filt_html=getFiltrateHtml($gt[0],$gt);
      
      $this->gt=$gt;    
      
      $this->reg_gt = explode('_', $gt[3]);
      
      $this->gt0=$bC['gt0'];
      
      $this->ynUrl = array(
        'y'=>U('index',array('gt'=>$bC['gt0'].'-12'.'-0'.'-0_0_0'.'-'.getTopField($gt[0]).'-i'.'-y')),
        'n'=>U('index',array('gt'=>$bC['gt0'].'-12'.'-0'.'-0_0_0'.'-'.getTopField($gt[0]).'-i'.'-n'))
        );
      
      $this->typeUrl = array(
        'pai'=>U('index',array('gt'=>$bC['gt0'].'-12'.'-0'.'-0_0_0'.'-'.getTopField($gt[0]).'-0'.'-a')),
        'biao'=>U('index',array('gt'=>$bC['gt0'].'-12'.'-0'.'-0_0_0'.'-'.getTopField($gt[0]).'-1'.'-a'))
        );
      
        $this->channelName = M('Goods_category')->where('cid='.$gt[0])->getField('name');
        $this->display();
     }
     
     public function allend(){
        $bidMap=D('Auction');
        $endwhere=array('endtime'=>array('elt',time()),'endstatus'=>1);
        if(I('get.type')!=''){
            $endwhere['type']=I('get.type');
            $this->type = I('get.type');
        }
        $count = $bidMap->where($endwhere)->count();
        $pConf = page($count,20);
        $endlist = $bidMap->where($endwhere)->limit($pConf['first'].','.$pConf['list'])->order('endtime desc')->select();
        
        $this->endlist=$endlist;
        $this->page = $pConf['show'];
        $this->display();
     }
     
     public function details(){
      
      $member = M('Member');
      $aRecord = M('Auction_record');
      $goods_user = M('Goods_user');
      $uid = $this->cUid;
      $info = D('Auction')->where('pid='.I('get.pid'))->find();
      
      
      creatS($info);
      
      if($info['endtime']<time()&&$info['endstatus']==0){
          $order = M('Goods_order');
          $auction = M('Auction');
        if($info['nowprice']>$info['price']){
          
          $aData = array(
            'pid'=>$info['pid'],
            'endstatus'=>1
          );
          $info['endstatus']=1;
          $auction->save($aData);
          
          $oData = array(
            'order_no'=>createNo('BID'),
            'type'=>$info['type'],
            'gid'=>$info['pid'],
            'uid'=>$info['uid'],
            'time'=>time(),
            'status'=>0,
            'remark'=>'竞拍成功，请在订单有效期内进行支付！'
          );
          
          if(C('Order')==0||C('Order')==''){
            $oData['losetime'] = 0;
          }else{
            $loseConf=C('Order');
            $oData['losetime'] = time()+(60*60*24*$loseConf['btime']);
          }
          
          if($order->add($oData)){
            
            D('Auction')->return_pledge($info['pid'],$info['uid'],'p-u');
            
            $nickname = M('Member')->where('uid ='.$info['uid'])->getField('nickname');
            
            sendSms($info['uid'],'系统提示','恭喜您以'.$info['nowprice'].'元拍到[【<a target="_blank" href="'.U('Auction/details',array('pid'=>$info['pid'])).'">'.$info['pname'].'</a>】请在'.date('Y-m-d H:i',$oData['losetime']).'之前支付完成支付。否则将扣除您参与该拍卖所缴纳的保证金或信用额度！');
          }
        
        }else{
          
          $aData['pid']=$info['pid'];
          if($info['uid']){
            
            $aData['endstatus']=2;
            $info['endstatus']=2;
            D('Auction')->return_pledge($info['pid'],0,'p-u');
          }else{
            
            $aData['endstatus']=3;
            $info['endstatus']=3;
          }
          $auction->save($aData);
          
        }
      }

      
      if ($info['pictures']) {
          $info['pictures'] = explode('|', $info['pictures']);
      }
      
      $info['nickname']= $member->where('uid='. $info['uid'])->getField('nickname');
      
      $retHtml =getExtendsCon($info['cid'],$info['gid']);
      $retHtml['eDivHtml']=htmlspecialchars_decode($retHtml['eDivHtml']);
      
      $recWhere = array('pid'=>I('get.pid'));
      $bidRecord = $aRecord->where($recWhere)->order('time desc,bided desc')->select();
      foreach ($bidRecord as $mk => $mv) {
        $bidRecord[$mk]['nickname'] = $member->where('uid='.$mv['uid'])->getField('nickname');
      }

      

      $this->bidRecord=$bidRecord;

      
      $p_l_w = array('gid'=>$info['pid'],'uid'=>$uid,'g-u'=>'p-u');
      $uFrezze = $goods_user->where($p_l_w)->field('pledge , limsum')->find();
      

      
      
      if(!$uFrezze){
          
        $ufield=array('uid','wallet_pledge','wallet_pledge_freeze','wallet_limsum','wallet_limsum_freeze');
        $uLimit = M('Member')->where('uid='.$uid)->field($ufield)->find();
        
        $uLimit['pledge'] = $uLimit['wallet_pledge']-$uLimit['wallet_pledge_freeze'];
        $uLimit['pledge'] = $uLimit['pledge']>0?$uLimit['pledge']:0;
        
        $uLimit['limsum'] = $uLimit['wallet_limsum']-$uLimit['wallet_limsum_freeze'];
        $uLimit['limsum'] = $uLimit['limsum']>0?$uLimit['limsum']:0;
        
        $uLimit['count'] = $uLimit['pledge']+$uLimit['limsum'];
        $uLimit['yn']=0;
        if($info['pledge_type']==0){
            if(percent($info['onset'],$info['pledge']) <= $uLimit['count']){
                $uLimit['yn']=1;
            }else{
              
              $uLimit['diff'] = percent($info['onset'],$info['pledge']) - $uLimit['count'];
            }
        }else{
            if($pledge <= $nowLimit){
                $uLimit['diff'] = $pledge - $uLimit['count'];
                $uLimit['yn']=1;
            }else{
              
              $uLimit['diff'] = percent($info['onset'],$info['pledge']) - $uLimit['count'];
            }
        }
      
      }else{
        $this->uFrezze=$uFrezze;
        
        $recWhere['uid'] = $uid;
        $myRecord = $aRecord->where($recWhere)->limit('10')->order('time desc,bided desc')->select();
        $this->myRecord=$myRecord;
        
        $myCount=$aRecord->where(array('pid'=>$info['pid'],'uid'=>$uid))->count();
        $this->myCount=$myCount;
        $uLimit['yn']=1;
      }

      $this->uid=$uid;
      
      $this->uLimit=$uLimit;
      
      $cat = new \Org\Util\Category('Goods_category', array('cid', 'pid', 'name'));
      $chalist = $cat->getPath($info['cid']);

      $this->chalist=$chalist;
      $gt[0]=$chalist[0]['cid'];
      $this->gt=$gt;
      
      $info['extend']=$retHtml;
      $info['content']=stripslashes($info['content']);
      $info['steptime']=conversionM_S($info['steptime']);
      $info['deferred']=conversionM_S($info['deferred']);
      $this->info=$info;
      $this->display();
     }
     
     public function bid(){
        if (IS_POST) {
          $bidMap = M('Auction');
          $m = M('Member');
          $postData = I('post.');
          $postData['uid']=$this->cUid;
          $uid = $this->cUid;
          $bidObj=$bidMap->where(array('pid'=>$postData['pid']))->find();
          $bidUrl = U("Auction/details",array('pid'=>$postData['pid']));
          
          $g_uMap=M('Goods_user');
          $g_uW = array(
            'g-u'=>'p-u',
            'gid'=>$postData['pid'],
            'uid'=>$uid
            );
          
          if(!$g_uMap->where($g_uW)->count()){
            
            
            if($bidObj['pledge_type']==0){
              $freeze = percent($bidObj['onset'],$bidObj['pledge']);
            }else{
              $freeze = $bidObj['pledge'];
            }
            
            $ufield=array('uid','wallet_pledge','wallet_pledge_freeze','wallet_limsum','wallet_limsum_freeze');
            $uLimit = $m->where('uid='.$uid)->field($ufield)->find();
            
            $live_limsum = $uLimit['wallet_limsum']-$uLimit['wallet_limsum_freeze'];
            $chazhi = $live_limsum - $freeze;
            if($chazhi>=0){
              if($m->where('uid='.$uid)->setInc('wallet_limsum_freeze',$freeze)||$freeze==0){
                  $matter=array(
                      'type'=>'freeze', 
                      'tid'=>1, 
                      'paytype' =>'冻结', 
                      'remark' => '参与<a href="'.$bidUrl.'">'.$bidObj['pname'].'</a>出价'
                      );
                  $data = array(
                      'order_no'=> createNo('BID'),
                      'uid'=> $uid,
                      'time'=> time(),
                      'matter' => serialize($matter),
                      'expend' => $freeze
                      );
                  if(M('member_limsum_bill')->add($data)){
                    
                      $g_uW['time']=time();
                      $g_uW['limsum'] = $freeze;
                      $g_uW['pledge'] = 0;
                      $g_uMap->add($g_uW);
                      
                      sendSms($uid,'系统提示','系统'.$matter['paytype'].'信用额度'.$data['expend'].'元！备注：'.$matter['remark']);
                      echo json_encode(D('Auction')->bidprc($postData));
                  } 
              }
            
            }else{
              
              if($live_limsum>0){
                if($m->where('uid='.$uid)->setInc('wallet_limsum_freeze',$live_limsum)){
                    $sumMatter=array(
                        'type'=>'freeze', 
                        'tid'=>1, 
                        'paytype' =>'冻结', 
                        'remark' => '参与<a href="'.$bidUrl.'">'.$bidObj['pname'].'</a>出价'
                        );
                    $sumData = array(
                        'order_no'=> createNo('BID'),
                        'uid'=> $uid,
                        'time'=> time(),
                        'matter' => serialize($sumMatter),
                        'expend' => $live_limsum
                        );
                    M('member_limsum_bill')->add($sumData);
                }
                
                if($m->where('uid='.$uid)->setInc('wallet_pledge_freeze',abs($chazhi))){
                    $matter=array(
                        'type'=>'freeze', 
                        'tid'=>1, 
                        'paytype' =>'冻结', 
                        'remark' => '参与<a href="'.$bidUrl.'">'.$bidObj['pname'].'</a>出价'
                        );
                    $data = array(
                        'order_no'=> createNo('BID'),
                        'uid'=> $uid,
                        'time'=> time(),
                        'matter' => serialize($matter),
                        'expend' => abs($chazhi)
                        );
                    if(M('member_pledge_bill')->add($data)){
                      
                      $g_uW['time']=time();
                      $g_uW['limsum'] = $live_limsum;
                      $g_uW['pledge'] = abs($chazhi);
                      $g_uMap->add($g_uW);
                      
                      sendSms($uid,'系统提示','系统'.$matter['paytype'].'信用额度'.$g_uW['limsum'].'元，保证金'.$g_uW['pledge'].'元备注：'.$matter['remark']);
                      echo json_encode(D('Auction')->bidprc($postData)); 
                    } 
                }
              
              }else{
                if($m->where('uid='.$uid)->setInc('wallet_pledge_freeze',$freeze)){
                    $matter=array(
                        'type'=>'freeze', 
                        'tid'=>1, 
                        'paytype' =>'冻结', 
                        'remark' => '参与<a href="'.$bidUrl.'">'.$bidObj['pname'].'</a>出价'
                        );
                    $data = array(
                        'order_no'=> createNo('BID'),
                        'uid'=> $uid,
                        'time'=> time(),
                        'matter' => serialize($matter),
                        'expend' => $freeze
                        );
                    if(M('member_pledge_bill')->add($data)){
                      
                      $g_uW['time']=time();
                      $g_uW['limsum'] = $live_limsum;
                      $g_uW['pledge'] = $freeze;
                      $g_uMap->add($g_uW);
                      
                      sendSms($uid,'系统提示','系统'.$matter['paytype'].'保证金'.$g_uW['pledge'].'元备注：'.$matter['remark']);
                      echo json_encode(D('Auction')->bidprc($postData));
                    } 
                }
              }

            }
          
          }else{
            echo json_encode(D('Auction')->bidprc($postData));
          }
        }
     }
     
     public function ajaxgettime(){
      $rtime = D('Auction')->where(array('pid'=>I('post.pid')))->field(array('starttime','endtime'))->find();
      $rtime['nowtime'] = time();
      echo json_encode($rtime);
     }
     
    public function ajaxget(){
      session_write_close();
      $itim = I('post.second');
      $pid = I('post.pid');
      $pcount = I('post.bidcount');
      for ($i=0; $i < $itim; $i++) {
        $bidS = S('bid'.$pid);
        if($bidS['bidcount']>I('post.bidcount')){
          echo json_encode(array('status'=>1,'itimt'=>$itim,'bidinfo'=>$bidS));
          exit;
        }else{
          sleep(1);
        }
        $itim-=1;
      }
      echo json_encode(array('status'=>0,'itimt'=>I('post.second'),'count'=>$bidS['bidcount']));
    }
    
    public function checksucc(){
      session_write_close();
      $pai = M('Auction')->where('pid ='.I('post.pid'))->find();
      if($pai['endtime']<time()){
        if($pai['nowprice']>$pai['price']){
          $nickname = M('Member')->where('uid ='.$pai['uid'])->getField('nickname');
          echo json_encode(array('status'=>1,'uid'=>$pai['uid'],'nickname'=>$nickname,'money'=>$pai['nowprice'],'pname'=>$pai['pname']));
        
        }else{
          echo json_encode(array('status'=>2,'pname'=>$pai['pname']));
        }
      }else{
        echo json_encode(array('status'=>0,'now_time'=>time(),'end_time'=>$pai['endtime']));
      }


    }

}?>
