<?php
define('IN_PHPMPS', true);
require dirname(__FILE__) . '/include/common.php';
require PHPMPS_ROOT . 'include/json.class.php';
require PHPMPS_ROOT . 'include/pay.fun.php';
$act = $_REQUEST['act'] ? trim($_REQUEST['act']) : 'index';

$not_login = array('login','act_login','register','act_register','logout',  'ajax', 'get_password', 'reset_password', 'send_pwd_email', 'email_edit_password','receive',  'report', 'comment','check_email','welogin');

$must_login = array('index','com_index','modify','act_modify','com','edit_password', 'act_edit_password', 'payonline','paycard', 'send', 'exchange', 'com_comment', 'com_list', 'editcom', 'updatecom', 'delcom', 'send_info_mail','send_check_phone','send_check_email','mycard','shop_card','shop_card_list','exchange_pay','saleedit','com_jifen','com_exchange','com_sms','com_addma','com_mainfo','shop_credit','shop_money','com_credit','buysend','shop_list','money_tea','user_money_tea','com_user_comment','com_repost','credit_money','credit_list','user_money','pay_lejuan','com_compay','act_addpay','com_user','com_useradd','com_user_fclist','act_modify_face','modify_face');

if(empty($_userid)) {
    if (!in_array($act, $not_login)) {
        if (in_array($act, $must_login)) {
            showmsg('请先登录', 'member.php?act=login&refer='.$PHP_URL);
        } else {
			showmsg('请不要提交非法请求！');
		}
    }
}

switch($act)
{
	case 'index':
		$seo['title'] = "会员中心";
		$userinfo = member_info($_userid);
		extract($userinfo);
		$registertime = date('Y年m月d日', $registertime);
		$money = number_format($money,2);
		$face = empty($face) ? $CFG['thumbs'] : $face;
		$smoney = $db->getOne("SELECT sum(value) FROM {$table}pay_exchange WHERE userid='$_userid'");
		$smoney = $smoney ? number_format(str_replace('-','', $smoney),2) : '0';
		$juannum = $db->getOne("SELECT count(*) FROM {$table}juan_pay WHERE userid='$_userid' and acttime=0");
		$nodp = $db->getOne("SELECT count(*) FROM {$table}pay_exchange WHERE userid='$_userid' and dp=1");
		$repost = $db->getOne("SELECT count(*) FROM {$table}com_comment WHERE userid='$_userid' and repost!=''");
		if(empty($email) || empty($qq) || empty($phone))$notice=1;
		include template('member');
	break;

	case 'login':
		if(!empty($_userid)) {
			showmsg("你已经登录了", "member.php");
		}
		$refer = trim(htmlspecialchars_deep($_SERVER['HTTP_REFERER']));
		$seo['title'] = "用户登录";
		include template('login');
	break;

	case 'act_login':
		$username = $_POST['username'] ? htmlspecialchars_deep(trim($_POST['username'])) : '';
		$password = $_POST['password'] ? trim($_POST['password']) : '';
		$md5_password = MD5($password);
		if(empty($username))showmsg("帐号不能为空");
		if(empty($password))showmsg("密码不能为空");
		//$userid = $db->getOne("SELECT userid FROM {$table}member WHERE username='$username'");

		if(login($username,$md5_password)) {
			$url= $_REQUEST['refer'] ? rawurldecode($_REQUEST['refer']) : 'member.php';
			showmsg("登陆成功", $url);
		} else {
			showmsg("登录失败",'member.php?act=login');
		}
	break;
	
	case 'logout':
		logout();
		$link = "index.php";
		showmsg("退出成功",$link);
	break;

	case 'register':
		if($CFG['close_register'] == '1') showmsg('本站已关闭用户注册。');
		if(!empty($_userid)) {
			$link = "member.php?act=index";
			showmsg("请退出后再进行该操作", $link);
		}
		$ip = get_ip();
		$mappoint = explode(',',$CFG[map]);

		$seo['title'] = "会员注册";
		include template('register');
	break;

	case 'act_register':
		$ip = get_ip();
		
		if(!submitcheck('submit')) showmsg('提交错误');

		$username   = $_POST['username'] ? htmlspecialchars_deep(trim($_POST['username'])) : '';
		$password   = $_POST['password'] ? trim($_POST['password']) : '';
		$repassword = $_POST['repassword'] ? trim($_POST['repassword']) : '';
		$checkcode  = $_POST['checkcode']?trim($_POST['checkcode']):'';
		$md5_password = MD5($password);
		$answer    = $_POST['answer'] ? intval($_POST['answer']) : '';
		if(!empty($_POST['email']))showmsg('参数错误！');
		$email = time().'@qq.com';
		if(empty($username))showmsg("用户名不能为空");
		if(!check_name($username))showmsg("用户名仅可使用汉字、字母、数字、中划线或下划线。");
		if(empty($password))showmsg("密码不能为空");
		if(empty($repassword))showmsg("重复密码不能为空");
		if($password != $repassword)showmsg("两次输入的密码不相同");
		if($answer!=$_SESSION['milistvip_maths'])showmsg("您的验证码输入错误！");

		if(register($username,$md5_password)) {
			pay_juan(1,$_SESSION['usid']);
			$_SESSION['usid']="";
			$link='member.php';
			showmsg("注册成功",$link);
		} else {
			$link = "member.php?act=register";
			showmsg("注册失败",$link);
		}
		login($username, $md5_password);
		showmsg('注册成功', 'member.php');
	break;

	case 'modify':
		$mappoint = explode(',',$CFG['map']);
		$userinfo = member_info($_userid);
		$timenew = date('Y');
		$seo['title'] = "修改会员资料";
		include template('modify');
	break;

	case 'act_modify':
		$qq       = $_POST['qq'] ? intval($_POST['qq']) : '';
		$address  = $_POST['address'] ? htmlspecialchars_deep($_POST['address']) : '';
		$xingming  = $_POST['xingming'] ? htmlspecialchars_deep($_POST['xingming']) : '';
		$userid   = $_SESSION['userid'];
		$shengri  = intval($_POST['years']).'-'.intval($_POST['months']).'-'.intval($_POST['days']);
		$shengri = strtotime($shengri);
		$username = $_SESSION['username'] ? htmlspecialchars_deep($_SESSION['username']) : '';

		$sql = "update {$table}member set 
				qq = '$qq',
				xingming = '$xingming',
				shengri = '$shengri',
				address = '$address'
				where userid='$_userid' and username='$username' ";
		$res = $db->query($sql);

		showmsg('修改资料成功', 'member.php?act=modify');
	break;

	case 'modify_face':
		$userinfo = member_info($_userid);
		$userinfo['face'] = empty($userinfo['face']) ? $CFG['thumbs'] : $userinfo['face'];
		$seo['title'] = "修改会员头像";
		include template('modify_face');
	break;

	case 'act_modify_face':
		foreach($_FILES as $key=>$val) {
		$alled = array('png','jpg','gif','jpeg');
		$exname = strtolower(trim(substr(strrchr($val['name'], '.'), 1)));
		if(!checkupfile($val['tmp_name']) || !($val['tmp_name'] != 'none' && $val['tmp_name'] && $val['name']) || $val['size']>'523298' || !in_array($exname,$alled)){
			continue;
		}
		$name = $_userid;
		$thumb_name = $_userid. '.' . end(explode('.', $val['name']));
	    $name .= '.' . end(explode('.', $val['name']));
		$dir = PHPMPS_ROOT . 'data/upload/face/';
		if(!is_dir($dir)) {
			if(@mkdir(rtrim($dir,'/'), 0777))@chmod($dir, 0777);
		}
		$to = $dir.'/'. $name;
		if(move_uploaded_file($val['tmp_name'], $to)) {
		$image = 'data/upload/face/' . $thumb_name;
		@chmod(PHPMPS_ROOT.$image, 0777);
		}
		
		$thumbimg = 'data/upload/face/'.$thumb_name;
		$thumb = CreateSmallImage( $image, $thumbimg, 150, 150);
		@chmod(PHPMPS_ROOT.$thumbimg, 0777);
		$db->query("UPDATE {$table}member SET face='$thumbimg' WHERE userid='$_userid' ");
	}

		showmsg('修改头像成功', 'member.php?act=modify_face');
	break;

	case 'edit_password':
		$seo['title'] = '修改密码';
		include template('edit_password');
	break;

	case 'act_edit_password':
		$oldpassword = $_POST['oldpassword'] ? trim($_POST['oldpassword']) : '';
		$password = $_POST['password'] ? trim($_POST['password']) : '';
		$repassword = $_POST['repassword'] ? trim($_POST['repassword']) : '';
		
		if(empty($oldpassword) && !empty($password))showmsg('请输入旧密码！');
		if($password && $repassword && $password!=$repassword)showmsg('两次输入的密码不一致！');

		$sql = "SELECT password FROM {$table}member WHERE userid='$_userid' LIMIT 1";
		if(MD5($oldpassword) != $db->getOne($sql))showmsg('旧密码输入错误');

		$password = MD5($password);
		$query = $db->query("UPDATE {$table}member SET password='$password' WHERE userid='$_userid' ");

		showmsg('密码修改成功!','member.php?act=edit_password');
	break;

	case 'ajax':
		$json = new Services_JSON;
		switch($_REQUEST['type'])
		{
			case 'username':
				$username = trim($_REQUEST['username']);
				$sql = "SELECT count(*) FROM {$table}member WHERE username='$username'";
				$count = $db->getOne($sql);

				if($count>0) {
					echo $json->encode(false);
					exit;
				} else {
					echo $json->encode(true);
					exit;
				}
			break;
			
			case 'phone':
				$phone = trim($_REQUEST['phone']);
				$sql = "SELECT count(*) FROM {$table}member WHERE phone='$phone'";
				$count = $db->getOne($sql);
				if($count>0) {
					echo $json->encode(false);
					exit;
				} else {
					echo $json->encode(true);
					exit;
				}
			break;

			case 'email':
				$count = $uc_count = 0;
				$email = trim($_REQUEST['email']);
				$sql = "SELECT userid FROM {$table}member WHERE email='$email'";
				$count = $db->getOne($sql);


				if($count>0) {
					echo $json->encode(false);
					exit;
				} else {
					echo $json->encode(true);
					exit;
				}
			break;
		}
	break;

	case 'payonline':
		$payonline_setting = get_pay_setting();
		$paycenter = $_COOKIE['paycenter'];
		if($paycenter) $selected[$paycenter] = 'selected';
		if(!isset($amount)) $amount = '';

		$memberinfo = member_info($_userid);
		$memberinfo['money'] = sprintf("%0.2f", $memberinfo['money']);
		$telephone = $memberinfo['telephone'];
		$email = $memberinfo['email'];
		$seo['title'] = '在线充值';
		include template('payonline');
	break;
	
	case 'paycard':
		$seo['title'] = '充值卡支付';
		include template('payonline_card');
	break;
	
	case 'money_tea':
	    $comid = com_info('comid','',3);
		chkcom($comid);
	    $txfss = array('alipay'=>'支付宝');
		$zttxt = array('0'=>'<span class="fe43">审核中</span>','1'=>'成功','2'=>'<span class="fe43">失败</span>');
		$page = intval($_GET['page']);
		$type = intval($_GET['type']);
		$begindate = htmlspecialchars_deep($_GET['begindate']);
		$enddate = htmlspecialchars_deep($_GET['enddate']);

		$page = isset($page) ? intval($page) : 1;
		$pagesize = 20;

		$sql = '';
		if($type) $sql .= " AND type='$type' ";
		if($begindate) {
			$begintime = strtotime($begindate.' 00:00:00');
			$sql .= " AND txtime>=$begintime ";
		}
		if($enddate) {
			$endtime = strtotime($enddate.' 23:59:59');
			$sql .= " AND txtime<=$endtime";
		}
		$_username = addslashes(stripslashes($_username));
		$r = $db->getRow("SELECT count(*) as number,sum(binary money) as moneys FROM {$table}pay_tx WHERE tid=1 and comid='$comid' $sql");
		$pager['search'] = array('act' => 'money_tea');
		$pager = get_pager('member.php', $pager['search'], $r['number'], $page, $pagesize);
        $moneys = number_format($r['moneys'],2);
		$exchanges = array();
		$result = $db->query("SELECT * FROM {$table}pay_tx WHERE tid=1 and comid='$comid' $sql ORDER BY txtime DESC LIMIT $pager[start],$pager[size]");
		while($r = $db->fetchrow($result)) {
			$r['txtime'] = date('Y-m-d h:i:s', $r['txtime']);
			$r['txfs'] = $txfss[$r['txfs']];
			$r['zuangtai'] = $zttxt[$r['zuangtai']];
			$r['siti'] = $r['money']-($r['money']*$r['soxu']/100);
			$exchanges[] = $r;
		}
		$furl = 'money_tea';
		$ftxt = '提现总额';
		$seo['title'] = '店铺提现记录';
		include template('member_com_tx');
	break;
	
	case 'user_money_tea':
	    $txfss = array('alipay'=>'支付宝');
		$zttxt = array('0'=>'<span class="f3f">审核中</span>','1'=>'成功','2'=>'<span class="fe43">失败</span>');
		$page = intval($_GET['page']);
		$type = intval($_GET['type']);
		$begindate = htmlspecialchars_deep($_GET['begindate']);
		$enddate = htmlspecialchars_deep($_GET['enddate']);

		$page = isset($page) ? intval($page) : 1;
		$pagesize = 20;

		$sql = '';
		if($type) $sql .= " AND type='$type' ";
		if($begindate) {
			$begintime = strtotime($begindate.' 00:00:00');
			$sql .= " AND txtime>=$begintime ";
		}
		if($enddate) {
			$endtime = strtotime($enddate.' 23:59:59');
			$sql .= " AND txtime<=$endtime";
		}
		$_username = addslashes(stripslashes($_username));
		$r = $db->getRow("SELECT count(*) as number,sum(binary money) as moneys FROM {$table}pay_tx WHERE tid=2 and userid='$_userid' $sql");
		$pager['search'] = array('act' => 'user_money_tea');
		$pager = get_pager('member.php', $pager['search'], $r['number'], $page, $pagesize);
        $moneys = number_format($r['moneys'],2);
		$exchanges = array();
		$result = $db->query("SELECT * FROM {$table}pay_tx WHERE tid=2 and userid='$_userid' $sql ORDER BY id DESC LIMIT $pager[start],$pager[size]");
		while($r = $db->fetchrow($result)) {
			$r['txtime'] = date('Y-m-d h:i', $r['txtime']);
			$r['txfs'] = $txfss[$r['txfs']];
			$r['zuangtai'] = $zttxt[$r['zuangtai']];
			$r['siti'] = $r['money']-($r['money']*$r['soxu']/100);
			$exchanges[] = $r;
		}
		$furl = 'user_money_tea';
		$ftxt = '提现总额';
		$seo['title'] = '帐户提现记录';
		include template('member_user_tx');
	break;

	case 'confirm':
		$type = trim($_REQUEST['type']);
		if($type == "moneynet"){
		$payonline_setting = get_pay_setting();
		$paycenter = trim($_POST['paycenter']);

		$amount = round(floatval($_POST['amount']), 2);
		if($amount < 1) showmsg('不能小1元');
		array_key_exists($paycenter, $payonline_setting) or showmsg('不存在此支付方式');
		@extract($payonline_setting[$paycenter]);

		if($percent) {
			$percent = round(floatval($percent), 2);
			$trade_fee = round($amount*$percent/100, 2);
			if($trade_fee < 0.01) $trade_fee = 0.01;
		} else {
			$trade_fee = 0;
		}
		$total_amount = $amount + $trade_fee;
		require PHPMPS_ROOT.'include/payonline/'.$paycenter.'/confirm.php';

		$seo['title'] = '在线支付-确认订单';
		include template('payconfirm');
		}elseif($type == "moneycard"){
			
		}else{
			showmsg("正在为您转向中……","index.php");
		}
	break;

    case 'buysend':
		$comid = com_info("comid",'',3);
		$moneytypes = array('1'=>'CRE', '2'=>'SMS');
		$paycenter = htmlspecialchars_deep($_POST['paycenter']);
		$amount = intval($_POST['amount']);
		$shoptype = intval($_POST['shoptype']);
		if($amount<1) showmsg('请输入购买数量');
        if($amount>100000) showmsg('超出购买数量，请重新选择！');
		$orderid = date('ymd').$comid.random(8,1);
		$time = time();
		$ip = get_ip();
		$memberinfo = member_info($_userid);
		$payonline_setting = get_pay_setting();
		array_key_exists($paycenter, $payonline_setting) or showmsg('不存在此支付方式');
		@extract($payonline_setting[$paycenter]);
		setcookie('paycenter', $paycenter, time() + 3600*24*365);
		$r = $db->getOne("SELECT payid FROM {$table}pay_online WHERE `orderid`='$orderid'");
		if($r) showmsg('不要刷新');
		$moneytype = $moneytypes[intval($_POST['shoptype'])];
		if($shoptype==1){
		$moneys = $amount * $CFG['creditnum'];
		}elseif($shoptype==2){
		$moneys = $amount * $CFG['smsnum'];
		}
		$db->query("INSERT INTO {$table}pay_online (`paycenter`,`userid`,`comid`,`orderid`,`moneytype`,`amount`,`nums`,`trade_fee`,`sendtime`,`ip`) VALUES('$paycenter','$_userid','$comid','$orderid','$moneytype','$moneys','$amount','$trade_fee','$time','$ip')");
        $ids = $db->insert_id();
		require PHPMPS_ROOT.'include/payonline/'.$paycenter.'/send.php';
	break;

	case 'send':
		$paycenter = htmlspecialchars_deep($_POST['paycenter']);
		$contactname = htmlspecialchars_deep($_POST['contactname']);
		$orderid = htmlspecialchars_deep($_POST['orderid']);
		echo $orderid;
		$time = time();
		$ip = get_ip();
		$payonline_setting = get_pay_setting();
		array_key_exists($paycenter, $payonline_setting) or showmsg('不存在此支付方式');
		@extract($payonline_setting[$paycenter]);
		setcookie('paycenter', $paycenter, time() + 3600*24*365);

		$r = $db->getOne("SELECT payid FROM {$table}pay_online WHERE `orderid`='$orderid'");
		if($r) showmsg('不要刷新');
		$moneytype = 'CNY';
		$amount = floatval($_POST['amount']);
		$trade_fee = floatval($_POST['trade_fee']);
		
		$db->query("INSERT INTO {$table}pay_online (`paycenter`,`userid`,`orderid`,`moneytype`,`amount`,`trade_fee`,`contactname`,`telephone`,`email`,`sendtime`,`ip`) VALUES('$paycenter','$_userid','$orderid','$moneytype','$amount','$trade_fee','$contactname','$telephone','$email','$time','$ip')");

		$amount = $amount + $trade_fee;
		require PHPMPS_ROOT.'include/payonline/'.$paycenter.'/send.php';
	break;

	case 'receive':
		$paycenter = htmlspecialchars_deep($_GET[paycenter]);
		$payonline_setting = get_pay_setting();
		array_key_exists($paycenter, $payonline_setting) or showmsg('支付错误');
		@extract($payonline_setting[$paycenter]);
		require PHPMPS_ROOT.'include/payonline/'.$paycenter.'/receive.php';
		
		$total_amount = $amount + $trade_fee;
		$seo['title'] = '支付返回信息';
		include template('payreceive');
	break;

	case 'exchange':
		$cid = intval($_REQUEST['cid']);
		if(!empty($cid)){
			$sqls = " AND comid='$cid'";
		}
		unset($_REQUEST['_username']);
		$dps = !empty($_REQUEST['dps']) ? intval($_REQUEST['dps']) : '';
		if($dps=='1'){
			$dpsql = 'and dp=1';
		}elseif($dps=='2'){
			$dpsql = 'and dp=""';
		}
		$page = intval($_GET['page']);
		$type = 'money';
		$begindate = htmlspecialchars_deep($_GET['begindate']);
		$enddate = htmlspecialchars_deep($_GET['enddate']);

		$page = isset($page) ? intval($page) : 1;
		$pagesize = 15;

		$sql = '';
		if($type) $sql .= " AND type='$type' ";
		if($begindate) {
			$begintime = strtotime($begindate.' 00:00:00');
			$sql .= " AND addtime>=$begintime ";
		}
		if($enddate) {
			$endtime = strtotime($enddate.' 23:59:59');
			$sql .= " AND addtime<=$endtime";
		}
		$_username = addslashes(stripslashes($_username));
		$r = $db->getRow("SELECT count(*) as number,sum(value) as moneys FROM {$table}pay_exchange WHERE userid='$_userid' $sql $dpsql $sqls");
		$pager['search'] = array('act' => 'exchange','dps'=>$dps,'cid'=>$cid);
		$pager = get_pager('member.php', $pager['search'], $r['number'], $page, $pagesize);
        $moneys = $r['moneys'] ? number_format($r['moneys'],2) : '0';
		$exchanges = array();
		$result = $db->query("SELECT * FROM {$table}pay_exchange WHERE userid='$_userid' $sql $dpsql $sqls ORDER BY exchangeid DESC LIMIT $pager[start],$pager[size]");
		while($r = $db->fetchrow($result)) {
			$r['payid'] = $paynames[$r['payid']];
			$r['unit'] = $units[$r['type']];
			$r['type'] = $r['type'];
			$r['soj'] = $r['soj']!=0 ? "-￥".$r['soj'] : '0';
			$r['lej'] = $r['lej']!=0 ? "-￥".$r['lej'] : '0';
			$r['yjia'] = number_format($r['yjia'],2);
			$r['value'] = number_format($r['value'],2);
			$r['comname'] = com_info("comname",$r['comid'],1);
			$r['note'] = (!empty($r['note']) || str_len($r['note'])>4) ? cut_str($r['note'],'2')."<a href=### title=".$r['note']."><img src=images/more.png alt=".$r['note']."></a>" : $r['note'];
			$r['addtime'] = date('Y-m-d', $r['addtime']);
			$r['dp'] = $r['dp']=='1' ? '已点评' : '<a href="javascript:vod(0);" name="'.$r['comid'].'" id="'.$r['exchangeid'].'" class="fe43" target="_blank">未点评</a>';
			$exchanges[] = $r;
		}
		$furl = 'exchange';
		$ftxt = '消费总额';
		$seo['title'] = '消费明细';
		include template('member_exchange');
	break;

	case 'get_password':
		if(!$CFG['sendmailtype'])showmsg('尚未设置邮件服务器，请与管理员联系。');
		if (isset($_GET['code']) && isset($_GET['userid'])) {
			$code = trim($_GET['code']);
			$userid  = intval($_GET['userid']);
			/* 判断链接的合法性 */
			$user_info = member_info($userid);
			if (empty($user_info) || ($user_info && md5($user_info['userid'] . $CFG['crypt'] . $user_info['registertime']) != $code)) {
				showmsg('参数错误');
			}
			$seo['title'] = '重置密码';
			include template('reset_password');
		} else {
			$seo['title'] = '找回密码';
			include template('get_password');
		}
	break;

	case 'send_pwd_email':
		$username = !empty($_POST['username']) ? trim($_POST['username']) : '';
		$email     = !empty($_POST['email'])     ? trim($_POST['email'])     : '';
		$user_info = member_info($username,'2');

		if ($user_info && $user_info['email'] == $email) {
			$code = md5($user_info['userid'] . $CFG['crypt'] . $user_info['registertime']);
			include PHPMPS_ROOT.'include/mail.inc.php';
			if (send_pwd_email($user_info['userid'], $username, $email, $code)) {
				showmsg('发送成功' , 'index.php');
			} else {
				showmsg('发送失败' , 'index.php');
			}
		} else {
			showmsg('用户名和邮件地址不匹配');
		}
	break;

	case 'email_edit_password':
		$new_password = isset($_POST['new_password']) ? trim($_POST['new_password']) : '';
		$confirm_password = isset($_POST['confirm_password']) ? trim($_POST['confirm_password']) : '';
		$userid  = isset($_POST['userid']) ? intval($_POST['userid']) : $userid;
		$code = isset($_POST['code']) ? trim($_POST['code'])  : '';

		if (strlen($new_password) < 6)showmsg('密码不能少于6位');
		if($new_password != $confirm_password)showmsg('两次输入的密码不一致');
		$user_info = member_info($userid);

		if (($user_info && (!empty($code) && md5($user_info['userid'] . $CFG['crypt'] . $user_info['registertime']) == $code))) {
			$password = MD5($new_password);
			$sql = "UPDATE {$table}member SET password='$password' WHERE userid='$userid' ";
			$query = $db->query($sql);
			showmsg('密码修改成功', 'index.php');
		} else {
			showmsg('密码修改失败', 'index.php');
		}
	break;

	case 'com_comment':
		$page = empty($_REQUEST['page'])? 1 : intval($_REQUEST['page']);
		$view = !empty($_REQUEST['view']) ? intval($_REQUEST['view']) : '';
		if($view=='1'){
			$views = 'and a.is_check=1';
			$views1 = 'and is_check=1';
		}elseif($view=='2'){
			$views = 'and a.is_check=0';
			$views1 = 'and is_check=0';
		}
		$count = $db->getOne("SELECT COUNT(*) FROM {$table}com_comment where userid='$_userid' $views1");
		$pager = get_pager('member.php',array('act'=>'com_comment','view'=>$view),$count,$page,'15');
		$sql = "SELECT a.*,b.comid,b.comname FROM {$table}com_comment as a left join {$table}com as b on a.comid=b.comid where a.userid='$_userid' $views ORDER BY a.id DESC LIMIT $pager[start],$pager[size]";
		$res = $db->query($sql);
		$comments = array();
		while($row=$db->fetchRow($res)) {
			$row['postdate'] = date('Y-m-d', $row['postdate']);
			$row['is_check'] = $row['is_check'] == '1' ? '是' : '否' ;
			$row['title']    = cut_str($row['content'], 15);
			$row['reposts']    = cut_str($row['repost'], 10);
			$row['url']      = url_rewrite('com',array('act'=>'view','comid'=>$row['comid']));
			$comments[] = $row;
		}
		$seo['title'] = "我的消费点评";
		include template('member_com_comment');
	break;
	
	case 'com_user_comment': 
	  if($_POST){
		$comid = intval($_POST['cid']);
		$eid  = intval($_POST['eid']);
		$cm_fw  = intval($_POST['star_fw']);
		$cm_hj  = intval($_POST['star_hj']);
		$cm_pz  = intval($_POST['star_pz']);
		$content = htmlspecialchars(trim($_POST['content']));
		if(empty($comid) || empty($eid)) {
			header("Location: ./\n");
			exit;
		}
		$count_eid = $db->getOne("SELECT count(*) FROM {$table}com_comment WHERE comid='$comid' and userid='$_userid' and eid='$eid'");
        if($count_eid>0)showmsg('你已点评过本次消费了！');
		if(strlen($content>1000))showmsg('你的点评太长了！');
		$ip = get_ip();
		if(($cm_fw+$cm_hj+$cm_pz)<=0)showmsg('一分都不给?最少给1分吧！');
		if(empty($content))showmsg('评价就说点什么吧！');
		check_words($who=array('content'));
		$postdate = time();
		$ip = get_ip();
		$check = $CFG['comment_check'] == '0' ? '1' : '0' ;
		$sql = "INSERT INTO {$table}com_comment (eid,comid,userid,username,cm_pz,cm_fw,cm_hj,content,postdate,is_check,ip) VALUES ('$eid','$comid','$_userid','$_username','$cm_pz','$cm_fw','$cm_hj','$content','$postdate','$check','$ip')";
		$res = $db->query($sql);
		$db->query("update {$table}pay_exchange set dp='1' where comid='$comid' and userid='$_userid' and exchangeid='$eid'");
		if($CFG['comment_check'] == '1')$msg = "点评审核后才能显示";
		$link = url_rewrite('com',array('act'=>'view', 'comid'=>$comid));
        myshowmsg('点评发布成功！'.$msg);
	  }else{
		$comid     = intval($_REQUEST['cid']);
		$commentid = intval($_REQUEST['eid']);
		$dpid = $db->getOne("SELECT dp FROM {$table}pay_exchange WHERE comid='$comid' and userid='$_userid' and exchangeid='$commentid'");
        if($dpid!=0)showmsg('本次消费你已经点评过了！');
        $com_name = com_info("comname",$comid);
		$seo['title'] = '发布店铺点评信息';
		include template('member_post_comment');  
	  }
	break;
	

	case 'editcom':
		$area_array = get_area_array();
		$sql = "SELECT c.*,cc.catname FROM {$table}com as c left join {$table}com_cat as cc on c.catid=cc.catid WHERE userid = '$_userid'";
		$com = $db->getRow($sql);
		$com['comuid'] = $com['userid'];
		unset($com['userid']);
		if(empty($com))showmsg('信息不存在','index.php');
		if($com['comuid']!=$_userid)showmsg('店铺不是您的，不能修改');
		extract($com);
		$postdate = date('Y-m-d', $postdate);
		$hours = explode(',',$hours);
		$icon = explode(',',$icon);
		$areaname = $area_array[$areaid];
		$thumbs    = PHPMPS_PATH.$thumb;

		if(!empty($mappoint)) {
			$mappoints = explode(',', $mappoint);
		}
		$com_area = area_options_zl($areaid);
		$seo['title'] = '修改店铺信息';
		include template('member_editcom','com');
	break;

	case 'updatecom':
		$comid    = intval($_POST['id']);
		$comname  = $_POST['comname'] ? htmlspecialchars_deep(trim($_POST['comname'])) : '';
		$areaid   = $_POST['areaid'] ? intval($_POST['areaid']) : '';
		$introduce  = $_POST['introduce'] ? htmlspecialchars_deep(trim($_POST['introduce'])) : '';
		$shoptip  = $_POST['shoptip'] ? htmlspecialchars_deep(trim($_POST['shoptip'])) : '';
		$phone    = $_POST['phone'] ? trim($_POST['phone']) : '';
		$address  = $_POST['address'] ? trim($_POST['address']) : '';
		$hours     = htmlspecialchars(trim($_POST['starhour'])).':00,'.htmlspecialchars(trim($_POST['endhour'])).':00';
		$icon_wifi = $_POST['icon_wifi'] ? htmlspecialchars_deep(trim($_POST['icon_wifi'])) : '';
		$icon_p = $_POST['icon_p'] ? htmlspecialchars_deep(trim($_POST['icon_p'])) : '';
		if(empty($icon_wifi) && empty($icon_p)){
			$icon = '';
		}else{
		    $icon .= $icon_wifi ? $icon_wifi.',' : '';
			$icon .= $icon_p ? $icon_p.',' : '';
		}
		$sql = "SELECT * FROM {$table}com WHERE comid = '$comid'";
		$com = $db->getRow($sql);
		$com['comuid'] = $com['userid'];
		unset($com['userid']);
		if(empty($com))showmsg('店铺不存在','index.php');
		if($com['comuid']!=$_userid)showmsg('店铺不是您发布的，不能修改');

		if(strlen($introduce)>1000)showmsg("商家介绍字数太多了，请小于1000字符！");
		if(strlen($shoptip)>100)showmsg("会员消费提示不超过100字符！");
		if(empty($phone))showmsg("电话必须填写");
		if(!preg_match("/^1[34578]\d{9}$|^(0\d{2,4}-)?[2-9]\d{6,7}(-\d{2,5})?$|^[48]00(-?\d){7,10}$/",$phone))showmsg("联系电话格式错误");
		if($areaid<=0) showmsg('请选择地区');
		
		check_words($who=array('comname','content'));

		if(!empty($_FILES['thumb']['name']))
		{
			
			$alled = array('png','jpg','gif','jpeg');
			$exname = strtolower(trim(substr(strrchr($_FILES['thumb']['name'], '.'), 1)));
			if(checkupfile($_FILES['thumb']['tmp_name']) && $_FILES['thumb']['tmp_name'] != 'none' && $_FILES['thumb']['tmp_name'] && $_FILES['thumb']['name'] && $_FILES['thumb']['size']<'523298' && in_array($exname,$alled))
			{
				$sql = "SELECT thumb FROM {$table}com WHERE comid IN ($comid)";
				$image = $db->getAll($sql);
				foreach((array)$image AS $val) {
					if($val['thumb'] != '' && is_file(PHPMPS_ROOT.$val['thumb'])) {
						@unlink(PHPMPS_ROOT . $val['thumb']);
					}
				}

				$thumb_name = $comid.'_thumb'. '.' . end(explode('.', $_FILES['thumb']['name']));
				$dir = PHPMPS_ROOT . 'data/com/thumb/';
				if(!is_dir($dir)) {
					if(@mkdir(rtrim($dir,'/'), 0777))@chmod($dir, 0777);
				}
				$to = $dir.'/'. $thumb_name;
				CreateSmallImage( $_FILES['thumb']['tmp_name'], $to, 200, 80);
				$image = 'data/com/thumb/'. $thumb_name;
				$sql = "update {$table}com set thumb='$image' where comid='$comid' ";
				$db->query($sql);
			}
		}
		$sql = "UPDATE {$table}com SET
				areaid='$areaid',
				introduce='$introduce',
				shoptip='$shoptip',
				phone='$phone',
				address='$address',
				hours='$hours',
				icon='$icon'
				where comid = '$comid' ";
		$res = $db->query($sql);
		
		$msg="恭喜您，修改成功！";
		$link = url_rewrite('com',array('act'=>'view', 'comid'=>$comid));
		showmsg($msg, $link);
	break;

	case 'delcom':
		$comid = intval($_REQUEST['id']);
		$sql = "select userid from {$table}com where comid='$comid' ";
		$comuserid = $db->getOne($sql);
		if($comuserid!=$_userid)showmsg('此信息不是您发布的，您不能修改');
		
		$sql = "SELECT thumb FROM {$table}com WHERE comid IN ($comid)";
		$image = $db->getOne($sql);
		if($image != '' && is_file(PHPMPS_ROOT.$image)) {
			@unlink(PHPMPS_ROOT.$image);
		}

		$sql = "SELECT path FROM {$table}com_image WHERE comid IN ($comid)";
		$image = $db->getAll($sql);
		foreach((array)$image AS $val) {
			if($val[path] != '' && is_file(PHPMPS_ROOT.$val[path])) {
				@unlink(PHPMPS_ROOT.$val[path]);
			}
		}

		$db->query("DELETE FROM {$table}com_image WHERE comid IN ($comid)");
		$db->query("DELETE FROM {$table}com WHERE comid IN ($comid)");

		showmsg('删除信息成功',$_SERVER['HTTP_REFERER']);
	break;


	case 'send_check_email':
		if($_POST) 
		{
			$email = trim($_POST['email']);
			$user_info = member_info($_userid);
			$code = md5($user_info['userid'] . $CFG['crypt'] . $user_info['registertime']);
			$reset_email = $CFG['weburl'].'/member.php?act=check_email&userid='.$_userid.'&code=' . $code;
			
			$send_date = date('Y-m-d', time());
			$content = "{$username}您好！<br><br>请点击以下链接(或者复制到您的浏览器):<br><br><a href=".$reset_email." target=\"_blank\">".$reset_email."</a><br><br>以进行您的邮件验证！<br><br>".$send_date;

			$code = md5($user_info['userid'] . $CFG['crypt'] . $user_info['registertime']);
			include PHPMPS_ROOT.'include/mail.inc.php';
			if (sendmail($email, $CFG['webname'].'-邮件验证', $content)) {
				$sql = "update {$table}member set temp_mail='".$email."' where userid=".$user_info['userid'];
			    $db->query($sql);
				showmsg('发送成功,请登录邮箱进行验证' , 'member.php?act=send_check_email');
			} else {
				showmsg('发送失败' , 'member.php?act=send_check_email');
			}
		} else {
			$userinfo = member_info($_userid);
			$seo['title'] = '验证邮件';
			include template('member_check_email');
		}
	break;

	case 'check_email':
		$code = isset($_GET['code']) ? trim($_GET['code'])  : '';
		$user_info = member_info(intval($_REQUEST['userid']));

		if ($user_info && (!empty($code) && md5($user_info['userid'] . $CFG['crypt'] . $user_info['registertime']) == $code)) {
			$sql = "update {$table}member set status='1',email=temp_mail,temp_mail='' where userid='$_userid' ";
			$query = $db->query($sql);
			showmsg('邮件验证成功', 'member.php');
		} else {
			showmsg('邮件验证失败', '?send_check_email');
		}
	break;

	case 'send_check_phone':
	    if($_POST) 
		{
		  $phone = !empty($_POST['phone']) ? trim($_POST['phone']) : '';
		  $phonekey = !empty($_POST['phonekey']) ? trim($_POST['phonekey']) : '';
		  if(empty($phone) || empty($phonekey))showmsg("手机号或验证都要填写！");
		  if(!preg_match("/^1[34578]\d{9}$|^(0\d{2,4}-)?[2-9]\d{6,7}(-\d{2,5})?$|^[48]00(-?\d){7,10}$/",$phone))showmsg("手机号格式错误");
		  if($phonekey==$_COOKIE['codes'] && $phone==$_SESSION['phones']){
			 $sql = "update {$table}member set phone='$phone' where userid='$_userid' ";
			 $query = $db->query($sql);
			 pay_juan(2);
			 setcookie("codes","");
			 unset($_SESSION['phones']);
			 showmsg('手机绑定成功！', 'member.php');
		  }else{
			 showmsg('手机绑定失败，请重新绑定！');  
		  }
		}else{
		$userinfo = member_info($_userid);
		$seo['title'] = '手机号绑定';
		include template('member_check_phone');
		}
	break;
	
	case 'mycard':
	    if($_POST) 
		{
			pay_juan(4);
			$card = intval($_POST['card']);
			$cardkey = trim($_POST['phonekey']);
			$r = $db->getRow("SELECT cardnum,cardkey FROM {$table}card WHERE cardnum='$card' and userid='' and acttime=''");
			if(!$r)showmsg("卡号不存在!");
			$times = time();
			if($r['cardkey']!=$cardkey)showmsg("卡号激活码错误!");
			$db->query("UPDATE {$table}card SET userid='$_userid',acttime='$times' where cardnum =".$r['cardnum']);
			$db->query("UPDATE {$table}member SET cardnum=".$r['cardnum']." where userid ='$_userid'");
            
			showmsg($CFG['cardname']."绑定成功！","member.php?act=mycard");
		}else{
		    $re = $db->getRow("SELECT a.cardnum,a.userid,c.userid,c.acttime FROM {$table}member as a left join {$table}card as c on a.cardnum=c.cardnum where a.userid=$_userid");
			$re['acttime'] = date("Y-m-d",$re['acttime']);
			$endtimes = round($re['acttime']+3600*24*365);
			$re['endtime'] = date("Y-m-d",$endtimes);	
		}
	    $seo['title'] = $CFG['cardname'].'绑定';
		include template('member_mycard');
	break;
	
	case 'shop_card':
	    if($_POST) 
		{
			$cardnum    = $_POST['card_num'] ? intval($_POST['card_num']) : '';
			$username   = $_POST['names'] ? htmlspecialchars_deep(trim($_POST['names'])) : '';
			$phone      = $_POST['phone'] ? htmlspecialchars($_POST['phone']) : '';
			$address   = $_POST['address'] ? htmlspecialchars_deep($_POST['address']) : '';
			if(empty($cardnum))showmsg("购卡数量必须填写");
			if(empty($username))showmsg("购卡人姓名必须填写");
            if(empty($phone))showmsg("联系电话必须填写");
			if(empty($address))showmsg("配送地址必须填写");
	        if(!preg_match("/^1[34578]\d{9}$|^(0\d{2,4}-)?[2-9]\d{6,7}(-\d{2,5})?$|^[48]00(-?\d){7,10}$/",$phone))showmsg("联系电话格式错误");
			$money = $CFG['cardmoney']*$cardnum;
			$times = time();
			$sql = "insert into {$table}shop_card (userid,username,phone,address,cardnum,money,addtime) values ('$_userid','$username','$phone','$address','$cardnum','$money','$times')";
            $res = $db->query($sql);
			showmsg("申请成功，我们会24小时内与你联系！","member.php?act=shop_card");
		}else{
		    $re = member_info($_userid);
		}
	    $seo['title'] = $CFG['cardname'].'购买';
		include template('member_shop_card');
	break;
	
	case 'shop_card_list':
		$page = empty($_REQUEST['page'])? 1 : intval($_REQUEST['page']);
		$count = $db->getOne("SELECT COUNT(*) FROM {$table}shop_card where userid='$_userid'");
		$pager = get_pager('member.php',array('act'=>'shop_card_list'),$count,$page,'15');
		$sql = "SELECT * FROM {$table}shop_card where userid='$_userid' ORDER BY addtime DESC LIMIT $pager[start],$pager[size]";
		$res = $db->query($sql);
		$cardlists = array();
		while($row=$db->fetchRow($res)) {
			$row['addresss'] = cut_str($row['address'], 10).'...';
			$row['payid'] = $row['payid']==0 ? '货到付款' : '';
			$row['zt'] = $row['zt']==0 ? '配送中' : '已配送';
			$row['addtime'] = date('Y-m-d', $row['addtime']);
			$cardlists[] = $row;
		}
		$seo['title'] = "我的购卡记录";
		include template('member_shop_card_list');
	break;
	
	case 'exchange_pay':
		unset($_REQUEST['_username']);
		$page = intval($_GET['page']);
		$type = '';
		$begindate = htmlspecialchars_deep($_GET['begindate']);
		$enddate = htmlspecialchars_deep($_GET['enddate']);

		$page = isset($page) ? intval($page) : 1;
		$pagesize = 20;

		$sql = '';
		if($type) $sql .= " AND type='$type' ";
		if($begindate) {
			$begintime = strtotime($begindate.' 00:00:00');
			$sql .= " AND addtime>=$begintime ";
		}
		if($enddate) {
			$endtime = strtotime($enddate.' 23:59:59');
			$sql .= " AND addtime<=$endtime";
		}
		$_userid = intval($_userid);
		$r = $db->getRow("SELECT count(*) as number,sum(binary value) as moneys FROM {$table}pay_add WHERE userid='$_userid'  $sql");
		$moneys = number_format($r['moneys'],2);
		$pager['search'] = array('act' => 'exchange_pay');
		$pager = get_pager('member.php', $pager['search'], $r['number'], $page, $pagesize);

		$exchanges = array();
		$result = $db->query("SELECT * FROM {$table}pay_add WHERE userid='$_userid'  $sql ORDER BY pid DESC LIMIT $pager[start],$pager[size]");
		while($r = $db->fetchrow($result)) {
			$r['payid'] = $paynames[$r['payid']];
			$r['value'] = sprintf("%0.2f", $r['value']);
			$r['addtime'] = date('Y-m-d h:i:s', $r['addtime']);
			$exchanges[] = $r;
		}
		$furl = 'exchange_pay';
		$ftxt = '充值总额';
		$seo['title'] = '帐户充值记录';
		include template('member_exchange_pay');
	break;
	
	case 'pay_lejuan':
		$page = intval($_GET['page']);
        $sids = array('1'=>'会员注册','2'=>'绑定手机','3'=>'消费满￥','4'=>'绑定卡');
		$page = isset($page) ? intval($page) : 1;
		$pagesize = 20;
		$r = $db->getOne("SELECT count(*) FROM {$table}juan_pay WHERE userid='$_userid'");
		$pager['search'] = array('act' => 'pay_lejuan');
		$pager = get_pager('member.php', $pager['search'], $r, $page, $pagesize);
		$exchanges = array();
		$result = $db->query("SELECT * FROM {$table}juan_pay as a left join {$table}com as b on a.comid=b.comid WHERE  a.userid='$_userid' ORDER BY a.id DESC LIMIT $pager[start],$pager[size]");
		while($row = $db->fetchrow($result)) {
			$row['smoney'] = $row['ssid']=='3' ? $row['smoney'] : '';
			$row['ssid'] = $sids[$row['ssid']].$row['smoney'];
			$row['comname'] = !empty($row['comname']) ? "<a href=".url_rewrite('com',array('act'=>'view','comid'=>$row['comid']))." target='_blank'>".$row['comname']."</a>" : '全部商家';
			$row['paytimes'] = date('Y-m-d',$row['paytime']);
			$row['yxday'] = $row['paytime']+(3600*24*$row['yxday'])>=time() ? date('Y-m-d',($row['paytime']+(3600*24*$row['yxday']))) : '已过期';
            $row['acttime'] = $row['acttime']>0 ? "<span class=fe43>".date('Y-m-d',$row['acttime'])."</span>" : '未使用';
			$exchanges[] = $row;
		}
		$seo['title'] = "我的".$CFG['lejuan'];
		include template('member_pay_lejuan');
	break;
	
	case 'com_index':
	    $comid = com_info('comid','',3);
		chkcom($comid);
		$row = $db->getRow("SELECT sms_num,jf_num FROM {$table}com WHERE comid='$comid' and userid='$_userid'");
		$nodp = $db->getOne("SELECT count(*) FROM {$table}com_comment WHERE comid='$comid' and eid!=0 and repost=''");
		$moneyall = member_info("gold",3);
		$seo['title'] = "店铺概况";
		include template('member_com_index');
	break;
	
	case 'saleedit':
	    if($_POST) 
		{
			$comid = intval($_POST['id']);
			chkcom($comid);
			$zk_sojian  = intval(numzh($_POST['sojian']));
			for($i = 1; $i <= $CFG['max_zklist']; $i ++) {
		      $zk_list .= (intval(numzh($_POST['zkl'.$i]))!=0 && intval(numzh($_POST['money'.$i]))>0) ? intval(numzh($_POST['money'.$i])).','.intval(numzh($_POST['zkl'.$i])).intval(numzh($_POST['zkr'.$i])).'|' :'';
	        }
			$zk_list = substr($zk_list,0,strlen($zk_list)-1);
			$sql = "UPDATE {$table}com_config SET zk_sojian='$zk_sojian',zk_list='$zk_list' where comid = '$comid' ";
            $res = $db->query($sql);
			showmsg('折扣设置成功','member.php?act=saleedit');			
		}else{
		   $sql = "select comid,zk_sojian,zk_list from {$table}com_config where userid='$_userid'";
		   $cominfo = $db->getRow($sql);
		   chkcom($cominfo['comid']);
		   $cominfo['zk_list_count']  = count(explode('|',$cominfo['zk_list']));
		   $cominfo['zk_lists']  = explode('|',$cominfo['zk_list']);
		   $zk_list = array();
		   foreach (explode('|',$cominfo['zk_list']) as $row){
			 $zk_list[] = explode(',',$row);
           }
		   
		}
		$seo['title'] = '店铺优惠设置';
		include template('member_saleedit');
	break;
	
	case 'com_exchange':
		$comid = com_info('comid','',3);
		chkcom($comid);
		$page = intval($_GET['page']);
		$type = intval($_GET['type']);
		$begindate = htmlspecialchars_deep($_GET['begindate']);
		$enddate = htmlspecialchars_deep($_GET['enddate']);

		$page = isset($page) ? intval($page) : 1;
		$pagesize = 20;

		$sql = '';
		if($type) $sql .= " AND type='$type' ";
		if($begindate) {
			$begintime = strtotime($begindate.' 00:00:00');
			$sql .= " AND addtime>=$begintime ";
		}
		if($enddate) {
			$endtime = strtotime($enddate.' 23:59:59');
			$sql .= " AND addtime<=$endtime";
		}
		$_userid = intval($_userid);
		$r = $db->getRow("SELECT count(*) as number,sum(binary (value)) as moneys FROM {$table}pay_exchange WHERE comid='$comid' and type='money' $sql");
		$moneys = number_format($r['moneys'],2);
		$pager['search'] = array('act' => 'com_exchange');
		$pager = get_pager('member.php', $pager['search'], $r['number'], $page, $pagesize);
		
		$exchanges = array();
		$result = $db->query("SELECT a.*,c.id,c.eid,c.repost FROM {$table}pay_exchange as a left join {$table}com_comment as c on a.exchangeid=c.eid WHERE type='money' and a.comid='$comid' $sql ORDER BY exchangeid DESC LIMIT $pager[start],$pager[size]");
		while($r = $db->fetchrow($result)) {
			$r['payid'] = $paynames[$r['payid']];
			$r['unit'] = $units[$r['type']];
			$r['type'] = $types[$r['type']];
			$r['yjia'] = number_format($r['yjia'],2);
			$r['soj'] = $r['soj']!=0 ? "-￥".$r['soj'] : '0';
			$r['lej'] = $r['lej']!=0 ? "-￥".$r['lej'] : '0';
			$r['value'] = number_format($r['value'],2);
			$r['siso'] = number_format($r['value']-$r['fc'],2);
			$r['comname'] = com_info("comname",$r['comid'],1);
			$r['note'] = (!empty($r['note']) || str_len($r['note'])>5) ? cut_str($r['note'],'2')."<a href=### title=".$r['note']."><img src=images/more.png alt=".$r['note']."></a>" : $r['note'];
            $r['repostid'] = (!empty($r['eid'])) ? '<a href="javascript:vod(0);" id="'.$r['id'].'" class="fe43" target="_blank">回复</a>': '';
			$r['addtime'] = date('Y-m-d', $r['addtime']);
			$exchanges[] = $r;
		}
		$furl = 'com_exchange';
		$ftxt = '入帐总额';
	    $seo['title'] = '店铺收入明细';
		include template('member_com_exchange');
	break;
	
	case 'com_smslist':
		$comid = com_info('comid','',3);
		chkcom($comid);
		$stars = array('0'=>'成功', '1'=>'<font class="fe43">失败</a>');
		$notes = array('991'=>'消费', '992'=>'收款');
		$page = intval($_GET['page']);
		$begindate = htmlspecialchars_deep($_GET['begindate']);
		$enddate = htmlspecialchars_deep($_GET['enddate']);

		$page = isset($page) ? intval($page) : 1;
		$pagesize = 20;

		$sql = '';
		if($type) $sql .= " AND type='$type' ";
		if($begindate) {
			$begintime = strtotime($begindate.' 00:00:00');
			$sql .= " AND sendtime>=$begintime ";
		}
		if($enddate) {
			$endtime = strtotime($enddate.' 23:59:59');
			$sql .= " AND sendtime<=$endtime";
		}
		$_userid = intval($_userid);
		$r = $db->getRow("SELECT count(*) as number FROM {$table}com_sms WHERE comid='$comid' and note!='999' $sql");
		$sendsmsid = $db->getOne("SELECT count(*) FROM {$table}com_sms WHERE comid='$comid' and star=0 and note!='999' $sql");
		$pager['search'] = array('act' => 'com_smslist');
		$pager = get_pager('member.php', $pager['search'], $r['number'], $page, $pagesize);
		$exchanges = array();
		$result = $db->query("SELECT * FROM {$table}com_sms WHERE comid='$comid' and note!='999' $sql ORDER BY sid DESC LIMIT $pager[start],$pager[size]");
		while($r = $db->fetchrow($result)) {
			$r['note']  = $notes[$r['note']];
			$r['star']  = $stars[$r['star']];
			$r['phone'] = preg_replace("/(1\d{1,2})\d\d(\d{0,2})/", "\$1****\$3", $r['phone']);
			$r['sendtime'] = date('Y-m-d h:i:s', $r['sendtime']);
			$exchanges[] = $r;
		}
		$furl = 'com_smslist';
		$ftxt = '成功发送';
	    $seo['title'] = '店铺短信发送记录';
		include template('member_com_smslist');
	break;
	
	case 'com_credit':
	    if($_POST) 
		{
			$comid = intval($_POST['id']);
			chkcom($comid);
			$money  = $_POST['money']>=1 ? intval($_POST['money']) : '';
			$jifen  = $_POST['jifen']>=1 ? intval($_POST['jifen']) : '';
			if(empty($money) || empty($jifen)){
				$jf = '';
			}else{
				$jf   = $money.'|'.$jifen;
			}
			$did  = is_array($_POST['did']) ? join(',', $_POST['did']) : intval($_POST['did']);
			$didx = ','.$did.',|'.intval($_POST['cx']);
			$sql = "UPDATE {$table}com_config SET jf_bl='$jf',jf_day='$didx' where comid = '$comid' ";
            $res = $db->query($sql);
			showmsg('积分设置成功','member.php?act=com_credit');			
		}else{
		   $sql = "select comid,jf_bl,jf_day from {$table}com_config where userid='$_userid'";
		   $cominfo = $db->getRow($sql);
		   chkcom($cominfo['comid']);
		   $cominfo['jf'] = explode('|',$cominfo['jf_bl']);
		   $cominfo['jd'] = explode('|',$cominfo['jf_day']);
		   $cominfo['jfyuer'] = com_info("jf_num",'',3);
		}
		$seo['title'] = '店铺积分设置';
		include template('member_com_jifen');
	break;
	
	case 'com_sms':
	    if($_POST) 
		{
			$comid = intval($_POST['id']);
			chkcom($comid);
			$sms_xf  = $_POST['sms_xf'] ? intval($_POST['sms_xf']) : '';
			$sms_sk  = $_POST['sms_sk'] ? intval($_POST['sms_sk']) : '';
			$sms_key   = $sms_xf.'|'.$sms_sk;
			$sql = "UPDATE {$table}com_config SET sms_key='$sms_key' where comid = '$comid' ";
            $res = $db->query($sql);
			showmsg('短信设置成功','member.php?act=com_sms');			
		}else{
		   $sql = "select comid,sms_key from {$table}com_config where userid='$_userid'";
		   $cominfo = $db->getRow($sql);
		   chkcom($cominfo['comid']);
		   $cominfo['sms_key'] = explode('|',$cominfo['sms_key']);
		   $cominfo['smsyuer'] = com_info("sms_num",'',3);
		}
		$seo['title'] = '短信发送设置';
		include template('member_com_sms');
	break;
	
	case 'com_addma':
	    $sql = "select * from {$table}com_config where userid='$_userid'";
		$cominfo = $db->getRow($sql);
		chkcom($cominfo['comid']);
		$cominfo['jf_day']  = explode('|',$cominfo['jf_day']);
		$cominfo['jf_bl']  = explode('|',$cominfo['jf_bl']);
	    $zk_list = array();
		foreach (explode('|',$cominfo['zk_list']) as $row){
			 $zk_list[] = $row ? explode(',',$row) : '0';
        }
		$todays  = date('j', time());
		$seo['title'] = '扫描二维码收费';
		include template('member_com_addma');
	break;
	
	case 'com_mainfo':
	    $money = numzh($_REQUEST['m']);
		$id    = intval($_REQUEST['id']);
		chkcom($id);
		if(!is_numeric($money))showmsg('金额错误！');
		$sql = "select * from {$table}com_config where comid='$id'";
        $cominfo = $db->getRow($sql);
		$cominfo['jf_day']  = explode('|',$cominfo['jf_day']);
		$todays  = date('j', time());
		$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($money/$cominfo['jf_bl'][0]*$cominfo['jf_bl'][1]*$cominfo['jf_day'][1]);
		  }else{
			$cominfo['jifen'] = floor($money/$cominfo['jf_bl'][0]*$cominfo['jf_bl'][1]);
		  }
		}else{
			$cominfo['jifen'] = '0';
		}
        $sql = "SELECT jf_num FROM {$table}com WHERE comid='$id'";
        $coms = $db->getOne($sql);
        if($coms < $cominfo['jifen'])showmsg('商家积分余额不足！');
		include template('member_com_mainfo');
	break;
	
	case 'com_compay':
	    $sql = "select * from {$table}com_config where userid='$_userid'";
		$cominfo = $db->getRow($sql);
		chkcom($cominfo['comid']);
		$card = $_REQUEST['card'] ? intval($_REQUEST['card']) : '';
	if(!empty($card)){
		$sql = "select * from {$table}com_config where userid='$_userid'";
		$cominfo = $db->getRow($sql);
		$cardinfo = $db->getRow("select count(*) as cardnum,phone from {$table}member where cardnum='$card'");
		$xf = $db->getRow("select count(*) as xf1,sum(value) as xf2 from {$table}pay_exchange where cardnum='$card'");
		$xf['xf2'] = number_format($xf['xf2'],2);
		$cardname = $cardinfo['cardnum'];
		if($cardname==0)showmsg("卡号不存在，请核对后输入！");
		$cardinfo['phone'] = $cardinfo['phone'] ? preg_replace("/(1\d{1,2})\d\d(\d{0,2})/", "\$1****\$3", $cardinfo['phone']) : '会员未绑定手机';
		$cominfo['jf_day']  = explode('|',$cominfo['jf_day']);
		$cominfo['jf_bl']  = explode('|',$cominfo['jf_bl']);
	    $zk_list = array();
		foreach (explode('|',$cominfo['zk_list']) as $row){
			 $zk_list[] = explode(',',$row);
        }
		$todays  = date('j', time());
	}
		$seo['title'] = '店内直接付款';
		include template('member_com_addpay');
	break;
	
	case 'act_addpay':
      $sql = "select * from {$table}com_config where userid='$_userid'"; 
      $cominfo = $db->getRow($sql);
      chkcom($cominfo['comid']);
	  $comid  = $cominfo['comid'];
	  $code = $_POST['money'] ? trim($_POST['money']) : '';
	  $cardid = $_POST['cardid'] ? intval($_POST['cardid']) : '';
	  if($code <= 0)showmsg('支付金额必须大于0');
	  $act_time = time();
	  if(empty($cominfo))showmsg('错误，未知店铺！');
	  $cominfo['jf_bl']   = explode('|',$cominfo['jf_bl']);
	  $cominfo['sms_key']   = explode('|',$cominfo['sms_key']);
	  $userinfos = member_info($cardid,'4');
	if(!empty($userinfos['cardnum'])){ 
	  $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  = $code;	
		  }
		}
		if($code >= $val[0]){
		  $zekou = $val[1];
		  $siso  = number_format($code*($val[1]/100),2);
		}
	   }else{
		  $zekou = '无';
		  $siso  = $code; 
	   }
	  }
	  $cominfo['jf_day']  = explode('|',$cominfo['jf_day']);
	  $todays  = date('j', time());
	  if(!empty($cominfo[jf_bl][0]) && !empty($cominfo[jf_bl][1])){
	   if(strpos($cominfo['jf_day'][0],strval(",".$todays.","))!==false){
		$cominfo['jifen']   = floor($code/$cominfo['jf_bl'][0]*$cominfo['jf_bl'][1]*$cominfo['jf_day'][1]);
		$notemsg.= '-优惠日'.$cominfo['jf_day'][1].'倍积分';
	   }else{
		$cominfo['jifen']   = floor($code/$cominfo['jf_bl'][0]*$cominfo['jf_bl'][1]);
	   }
	  }else{
		$cominfo['jifen'] = '0';
	  }

	  $sql = "SELECT userid,comname,jf_num,sms_num FROM {$table}com WHERE comid='$comid'";
	  $coms = $db->getRow($sql);
	  if($coms['jf_num'] < $cominfo['jifen'])showmsg('商家积分不足，终止付款！');
	  $db->query("UPDATE {$table}com SET jf_num=jf_num-".$cominfo['jifen']." WHERE comid='$comid'");
	  $db->query("UPDATE {$table}member SET credit=credit+".$cominfo['jifen']." WHERE userid=".$userinfos['userid']);
	  $card_comid = $db->getOne("select comid from {$table}card where cardnum='".$userinfos['cardnum']."'");
	}else{
		$siso = $code;
		$cominfo['jifen'] = '0';	
	}
	  $sisos = number_format($siso-($siso*($cominfo['fc']/100)),2);
	  $fc    = number_format($siso*($cominfo['fc']/100),2);
	  if($card_comid>0 && $card_comid!=$comid){
		$shop_card_fc = number_format($siso*($CFG['com_shop_card']/100),2);
		card_gold_add($userinfos['cardnum'],$siso,$shop_card_fc,$card_comid);
	  }
	  $ip = get_ip();
	  $orderid = date('ymd').$comid.random(8,1); //订单号
	  $db->query("INSERT INTO {$table}pay_exchange (`userid`,`orderid`,`cardnum`,`type`,`value`,`zekou`,`yjia`,`jifen`,`fc`,`comid`,`note`,`addtime`,`ip`,`payid`) VALUES('".$userinfos['userid']."','$orderid','".$userinfos['cardnum']."','money','$siso','$zekou','$code','".$cominfo['jifen']."','$fc','$comid','消费'".$notemsg."'','$act_time','$ip','1')");

	SendSMS($CFG['sms_ming'],$CFG['sms_msg_tplid'],'{"comname":"'.$coms['comname'].'","money":"'.$siso.'","jifen":"'.$cominfo['jifen'].'","yuer":"'.$userinfos['money'].'"}',$userinfos['phone'],'991',$comid);
	showmsg("支付完成","member.php?act=com_compay");
	break;
	
	case 'com':
		$comid = com_info("comid",'',3);
		if(!$comid)showmsg('您还未添加店铺，为你转向店铺添加页！','postcom.php');
		$begindate = htmlspecialchars_deep($_REQUEST['begindate']);
		$enddate = htmlspecialchars_deep($_REQUEST['enddate']);
		if($begindate) {
			$begintime = strtotime($begindate.' 00:00:00');
			$sql .= " AND addtime>=$begintime ";
		}
		if($enddate) {
			$endtime = strtotime($enddate.' 23:59:59');
			$sql .= " AND addtime<=$endtime";
		}
		$re = $db->getRow("SELECT count(*) as jyl,sum(yjia) as zje,sum(value) as zkj,sum(soj) as soj,sum(lej) as lej,sum(jifen) as jifen,sum(fc) as fc,sum(value-fc) as siso FROM {$table}pay_exchange where comid='$comid' $sql");
		$card_fc = $db->getOne("SELECT sum(fc) FROM {$table}card_fc where comid='$comid' $sql");
		$seo['title'] = "店铺概况";
		include template('member_com','com');
	break;
	
	case 'shop_credit':
	    $comid = com_info('comid','',3);
		chkcom($comid);
		$payonline_setting = get_pay_setting();
		$paycenter = $_COOKIE['paycenter'];
		if($paycenter) $selected[$paycenter] = 'selected';
		if(!isset($amount)) $amount = '';
		$seo['title'] = "商家增值服务";
		include template('member_shop_credit');
	break;
	
	case 'shop_money':
	    $comid = com_info('comid','',3);
		chkcom($comid);
		$userinfo = member_info($_userid);
		if(empty($userinfo['phone']))showmsg("操作本页前，请先绑定您的手机号码","member.php?act=send_check_phone");	
	if($_POST) 
		{
		$amount  = $_POST['amount'] ? trim($_POST['amount']) : '';//intval
		$paycenter = $_POST['paycenter'] ? trim($_POST['paycenter']) : '';
		$moneyid = $_POST['moneyid'] ? trim($_POST['moneyid']) : '';
		$times = time();
		if(!$amount)showmsg('提现金额不能为空！');
		if(!$moneyid)showmsg('收款帐号不能为空！');
		if($userinfo['gold']<$amount)showmsg('你的店铺余额没有这么多啊~~');
		if($userinfo['gold']<=$CFG['com_money_off'])showmsg('你的店铺余额少于服务保证金冻结金额，无法提现');
		if(($userinfo['gold']-$amount)<=$CFG['com_money_off'])showmsg('你提现后店铺余额小于服务保证金冻结金额，无法提现');
		$sql = "insert into {$table}pay_tx (tid,money,txfs,zanghao,soxu,comid,userid,txtime) values ('1','$amount','$paycenter','$moneyid','$CFG[com_money_tea]','$comid','$_userid','$times')"; //tid:1店铺提现
		$db->query($sql);
		$db->query("update {$table}member set gold=gold-'$amount' where userid='$_userid'");
		showmsg('提交成功，会在1~2个工作日审核你的申请！','member.php?act=shop_money');
	}else{
		$r = $db->getOne("SELECT count(*) FROM {$table}pay_tx WHERE comid='$comid' and zuangtai=0 and tid=1 and txtime>=".mktime(0, 0, 0, date('m'), date('d'), date('Y'))." and txtime<=".mktime(23, 59, 59, date('m'), date('d'), date('Y')));
		$payonline_setting = get_pay_setting();
		$paycenter = $_COOKIE['paycenter'];
		if($paycenter) $selected[$paycenter] = 'selected';
		if(!isset($amount)) $amount = '';
		$seo['title'] = "店铺余额提现";
		include template('member_shop_money');
	}
	break;
	
	case 'user_money':
		$userinfo = member_info($_userid);
		if(empty($userinfo['phone']))showmsg("操作本页前，请先绑定您的手机号码","member.php?act=send_check_phone");		
	if($_POST) 
		{
		$amount  = $_POST['amount'] ? trim($_POST['amount']) : '';//intval
		$paycenter = $_POST['paycenter'] ? trim($_POST['paycenter']) : '';
		$moneyid = $_POST['moneyid'] ? trim($_POST['moneyid']) : '';
		$times = time();
		if(!$amount)showmsg('提现金额不能为空！');
		if(!$moneyid)showmsg('收款帐号不能为空！');
		if($userinfo['money']<$amount)showmsg('你的帐户余额没有这么多啊~~');
		$sql = "insert into {$table}pay_tx (tid,money,txfs,zanghao,soxu,comid,userid,txtime) values ('2','$amount','$paycenter','$moneyid','$CFG[user_money_tea]','$comid','$_userid','$times')"; //tid:2会员提现
		$db->query($sql);
		$db->query("update {$table}member set money=money-'$amount' where userid='$_userid'");
		showmsg('提交成功，会在1~2个工作日审核你的申请！','member.php?act=user_money');
	}else{
		$r = $db->getOne("SELECT count(*) FROM {$table}pay_tx WHERE comid='$comid' and zuangtai=0 and tid=2 and txtime>=".mktime(0, 0, 0, date('m'), date('d'), date('Y'))." and txtime<=".mktime(23, 59, 59, date('m'), date('d'), date('Y')));
		$payonline_setting = get_pay_setting();
		$paycenter = $_COOKIE['paycenter'];
		if($paycenter) $selected[$paycenter] = 'selected';
		if(!isset($amount)) $amount = '';
		$seo['title'] = "帐户余额提现";
		include template('member_user_money');
	}
	break;
	
	case 'credit_money':
		$userinfo = member_info($_userid);
	if($_POST) 
		{
		$amount  = $_POST['amount'] ? intval($_POST['amount']) : '';
		$money   = number_format($CFG['usercreditnum']*$amount,2);
		if(!$amount)showmsg('要兑现的积分数量不能为空！');
		if($userinfo['credit']<$amount)showmsg('你的积分没有这么多啊~~');
		credit_diff($_userid,$amount,'自助积分兑现',$money,'0');	
		showmsg('积分兑现成功！');	
	}else{
		if(!isset($amount)) $amount = '';
		$seo['title'] = "积分兑现";
		include template('member_credittomoney');
	}
	break;
	
	case 'credit_list':
		$page = intval($_GET['page']);
		$begindate = htmlspecialchars_deep($_GET['begindate']);
		$enddate = htmlspecialchars_deep($_GET['enddate']);

		$page = isset($page) ? intval($page) : 1;
		$pagesize = 20;

		$sql = '';
		if($type) $sql .= " AND type='$type' ";
		if($begindate) {
			$begintime = strtotime($begindate.' 00:00:00');
			$sql .= " AND addtime>=$begintime ";
		}
		if($enddate) {
			$endtime = strtotime($enddate.' 23:59:59');
			$sql .= " AND addtime<=$endtime";
		}
		$_username = addslashes(stripslashes($_username));
		$r = $db->getRow("SELECT count(*) as number,sum(value) as moneys FROM {$table}pay_credit WHERE userid='$_userid' $sql");
		$pager['search'] = array('act' => 'credit_list');
		$pager = get_pager('member.php', $pager['search'], $r['number'], $page, $pagesize);
        $moneys = number_format($r['moneys'],2);
		$exchanges = array();
		$result = $db->query("SELECT * FROM {$table}pay_credit WHERE userid='$_userid' $sql ORDER BY cid DESC LIMIT $pager[start],$pager[size]");
		while($r = $db->fetchrow($result)) {
			$r['tid'] = $creditname[$r['tid']];
			$r['addtime'] = date('Y-m-d h:i', $r['addtime']);
			$r['value']  = number_format($r['value'],2);
			$exchanges[] = $r;
		}
		$furl = 'credit_list';
		$ftxt = '兑现总额';
		$seo['title'] = '积分兑现记录';
		include template('member_credit_list');
	break;
	
	case 'shop_list':
	    $comid = com_info('comid','',3);
		chkcom($comid);
		$status = array('0'=>'<font class="fe43">失败</a>','1'=>'成功');
		$paycen = array('alipay'=>'支付宝','yuer'=>'店铺余额','system'=>'系统发放');
		$moneyts= array('CNY'=>'充值余额','CRE'=>'积分','SMS'=>'短信');
		$page = intval($_GET['page']);
		//$type = intval($_GET['type']);
		$begindate = htmlspecialchars_deep($_GET['begindate']);
		$enddate = htmlspecialchars_deep($_GET['enddate']);

		$page = isset($page) ? intval($page) : 1;
		$pagesize = 20;

		$sql = '';
		if($type) $sql .= " AND type='$type' ";
		if($begindate) {
			$begintime = strtotime($begindate.' 00:00:00');
			$sql .= " AND sendtime>=$begintime ";
		}
		if($enddate) {
			$endtime = strtotime($enddate.' 23:59:59');
			$sql .= " AND sendtime<=$endtime";
		}
		$_userid = intval($_userid);
		$paynum = $db->getRow("SELECT count(*) as nums,sum(binary amount) as moneys FROM {$table}pay_online WHERE userid='$_userid' or (comid=$comid and orderid='99999') $sql");
		$moneys = number_format($paynum['moneys'],2);
		$pager['search'] = array('act' => 'shop_list');
		$pager = get_pager('member.php', $pager['search'], $paynum['nums'], $page, $pagesize);
		$exchanges = array();
		$result = $db->query("SELECT * FROM {$table}pay_online WHERE userid='$_userid' or (comid=$comid and orderid='99999') $sql ORDER BY payid DESC LIMIT $pager[start],$pager[size]");
		while($r = $db->fetchrow($result)) {
			$r['status']      = $status[$r['status']];
			$r['paycenter']   = $paycen[$r['paycenter']];
			$r['moneytype']   = $moneyts[$r['moneytype']];
			$r['sendtime']    = date('Y-m-d h:i:s', $r['sendtime']);
			$exchanges[] = $r;
		}
		$furl = 'shop_list';
		$ftxt = '已消费';
	    $seo['title'] = '商家服务购买记录';
		include template('member_shop_list');
	break;
	
	case 'com_repost': 
	$comid = com_info('comid','',3);
	chkcom($comid);
	  if($_POST){
		$id = intval($_POST['id']);
		$content = htmlspecialchars(trim($_POST['content']));
		if(empty($id))showmsg('参数错误！');
		if(strlen($content>1000))showmsg('你的点评太长了！');
		if(empty($content))showmsg('回复就说点什么吧！');
		check_words($who=array('content'));
		$retime = time();
		$db->query("update {$table}com_comment set repost='$content',retime='$retime' where id='$id'");
        myshowmsg('回复成功！');
	  }else{
		$cid = intval($_REQUEST['id']);
		$re = $db->getRow("SELECT * FROM {$table}com_comment WHERE id='$cid'");
		if($re['comid']!=$comid)showmsg('非法操作！');
		include template('member_repost_comment');  
	  }
	break;
	
	case 'com_user':
	    $comid = com_info('comid','',3);
	    chkcom($comid);
		$page = empty($_REQUEST['page'])? 1 : intval($_REQUEST['page']);
		$count = $db->getOne("SELECT COUNT(*) FROM {$table}member as a left join {$table}card as b on a.cardnum=b.cardnum where b.comid='$comid'");
		$pager = get_pager('member.php',array('act'=>'com_user'),$count,$page,'15');
		$sql = "SELECT a.*,b.cardnum,b.acttime,sum(c.value) as xfze FROM {$table}member as a left join {$table}card as b on a.cardnum=b.cardnum left join {$table}pay_exchange as c on a.cardnum=c.cardnum where b.comid='$comid' group by c.cardnum ORDER BY b.acttime DESC LIMIT $pager[start],$pager[size]";
		$res = $db->query($sql);
		$cardlists = array();
		while($row=$db->fetchRow($res)) {
			$row['xfze'] = number_format($row['xfze'],2);
			$row['acttime'] = date('Y-m-d', $row['acttime']);
			$row['shengri'] = !empty($row['shengri']) ? date('Y-m-d', $row['shengri']) : '未填';
			$cardlists[] = $row;
		}
		$seo['title'] = "会员列表";
		include template('member_com_user');
	break;
	
	case 'com_useradd':
	    $comid = com_info('comid','',3);
	    chkcom($comid);
	if($_POST){
		$username = $_POST['username'] ? htmlspecialchars_deep(trim($_POST['username'])) : '';
		$phone = $_POST['phone'] ? htmlspecialchars_deep(trim($_POST['phone'])) : '';
		$card = $_POST['card'] ? htmlspecialchars_deep(trim($_POST['card'])) : '';
		if(empty($username) || empty($phone) || empty($card))showmsg("开户信息必须填写完整!");
		$uinfo = $db->getOne("SELECT COUNT(*) FROM {$table}member where username='$username' or phone='$phone'");
		if($uinfo>0)showmsg("用户名或手机号码已被注册或绑定!");
		$cardcomid = $db->getOne("SELECT comid FROM {$table}card where comid='$comid' and cardnum='$card' and acttime=''");
		if($cardcomid!=$comid)showmsg("卡号不属于您的商家号码库，请核对!");
		$time = time();
	    $ip = get_ip();
	    $sql = "INSERT INTO {$table}member (username,password,phone,cardnum,registertime,registerip,formid,status) VALUES ('$username','".MD5($phone)."','$phone','$card','$time','$ip','$comid', '1')";
		$res = $db->query($sql);
	    $userid = $db->insert_id();
		$db->query("UPDATE {$table}card SET userid='$userid',acttime='$time' where cardnum ='$card'");
		showmsg("开户成功！","member.php?act=com_useradd");
	}else{
		$page = empty($_REQUEST['page'])? 1 : intval($_REQUEST['page']);
		$count = $db->getOne("SELECT COUNT(*) FROM {$table}card where comid='$comid' and acttime=''");
		//$pager = get_pager('member.php',array('act'=>'com_useradd'),$count,$page,'100');
		$sql = "SELECT * FROM {$table}card where comid='$comid' and acttime='' ORDER BY id ASC";
		$res = $db->query($sql);
		$cardlists = array();
		while($row=$db->fetchRow($res)) {
			$cardlists[] = $row;
		}
		$seo['title'] = "在线新开户";
		include template('member_com_useradd');
	}
	break;
	
	case 'com_user_fclist':
	    $comid = com_info('comid','',3);
		chkcom($comid);
		$page = intval($_GET['page']);
		//$type = intval($_GET['type']);
		$begindate = htmlspecialchars_deep($_GET['begindate']);
		$enddate = htmlspecialchars_deep($_GET['enddate']);

		$page = isset($page) ? intval($page) : 1;
		$pagesize = 20;

		$sql = '';
		if($type) $sql .= " AND type='$type' ";
		if($begindate) {
			$begintime = strtotime($begindate.' 00:00:00');
			$sql .= " AND addtime>=$begintime ";
		}
		if($enddate) {
			$endtime = strtotime($enddate.' 23:59:59');
			$sql .= " AND addtime<=$endtime";
		}
		$_userid = intval($_userid);
		$r = $db->getRow("SELECT count(*) as number FROM {$table}card_fc WHERE comid='$comid' $sql");
		$moneys = $db->getOne("SELECT sum(fc) FROM {$table}card_fc WHERE comid='$comid' $sql");
		$pager['search'] = array('act' => 'com_user_fclist');
		$pager = get_pager('member.php', $pager['search'], $r['number'], $page, $pagesize);
		$exchanges = array();
		$result = $db->query("SELECT * FROM {$table}card_fc WHERE comid='$comid' $sql ORDER BY addtime DESC LIMIT $pager[start],$pager[size]");
		while($r = $db->fetchrow($result)) {
			//$r['cardnum'] = preg_replace("/(1\d{1})\d\d(\d{1})/", "\$1****\$3", $r['cardnum']);
			$r['addtime'] = date('Y-m-d', $r['addtime']);
			$exchanges[] = $r;
		}
		$furl = 'com_user_fclist';
		$ftxt = '获取消费提成';
	    $seo['title'] = '商家售卡消费提成';
		include template('member_com_user_fclist');
	break;
}
?>