<?php
define('IN_PHPMPS', true);
require dirname(__FILE__) . '/include/common.inc.php';
get_login();
  $id = $_REQUEST['id'] ? intval($_REQUEST['id']) : '';
  $code = $_REQUEST['money'] ? trim($_REQUEST['money']) : '';
  $sid = $_REQUEST['sid'] ? trim($_REQUEST['sid']) : '';
  $times1 = date("Ymd");
  if($sid != MD5($times1*$times1))showmsg('错误！请重新生成二维码！');
  if(empty($id) || empty($code))showmsg('系统未知错误，请联系管理员！');
  $act_time = time();
  $sql = "select * from {$table}com_config where comid='$id'";
  $cominfo = $db->getRow($sql);
  $countcom = $db->getOne("select count(*) from {$table}pay_exchange where userid='$_userid' and comid='$id'");
  $cominfo['jf_day']  = explode('|',$cominfo['jf_day']);
  $todays  = date('j', time());
  $cominfo['comname'] = com_info("comname",$id,1);
  $cominfo['zk_sojians']  = number_format($cominfo['zk_sojian'],2);
  $cominfo['card']    = member_info("cardnum,money",3);
  $cominfo['cards']   = $cominfo['card']['cardnum'];
  $cominfo['jf_bl']   = explode('|',$cominfo['jf_bl']);
  if(!empty($cominfo[jf_bl][0]) && !empty($cominfo[jf_bl][1])){
		  if(strpos($cominfo['jf_day'][0],strval(",".$todays.","))!==false){
		    $cominfo['jifen'] = floor(floor((int)($code*100)/100/$cominfo['jf_bl'][0])*$cominfo['jf_bl'][1]*$cominfo['jf_day'][1]);
		  }else{
			$cominfo['jifen'] = floor(floor((int)($code*100)/100/$cominfo['jf_bl'][0])*$cominfo['jf_bl'][1]);
		  }
   }else{
			$cominfo['jifen'] = '0';
   }
 
if($cominfo['cards']){
  $zk_list = array();
  foreach (explode('|',$cominfo['zk_list']) as $row){
	 $zk_list[] = explode(',',$row);
  }
  foreach($zk_list as $key=>$val){
  if($val[0]!=0){
	if($key==0){
	  if($code < $val[0]){
	   $zekou = '无';
	   $siso  = number_format($code,2);	
	  }
	}
	if($code >= $val[0]){
	  $zekou = $val[1];
	  $siso  = number_format($code*($val[1]/100),2);
	}
  }else{
	  $zekou = '无';
	  $siso  = number_format($code,2);	
  }
  }
  if($cominfo['zk_sojians']>0 && $cominfo['zk_sojians']<$code && $countcom<1){
	 $siso = number_format($siso-$cominfo['zk_sojians'],2);
  }
}else{
	 $siso = number_format($code,2);
}
   //代金券
   $juanlist = array();
   $times = time();
   $result = $db->query("SELECT * FROM {$table}juan_pay WHERE userid='$_userid' and money<'$code' and paytime+(3600*24*yxday)>='$act_time' and acttime='' and '$code'>=xfmy and comid=(case when comid!=0 then '$id' else '' end) group by money");
   while($r = $db->fetchrow($result)) {
	$juanlist[] = $r;
   }
  //
  $paycode = MD5(random(6));
  $seo['title'] = $CFG['webname'] . '－扫码付款';
  include tpl('com_pay');

?>