<?php
include("./includes/common.php");
$path = dirname(__FILE__).'/conf.php';
if (!is_file($path)) exit('站长未开启换钱');
include("./conf.php");
if ($_POST) {
	if (!isset($_POST['type']) || !isset($_POST['money']) || !isset($_POST['account'])) exit(json_encode(['code'=>0,'msg'=>'请填写完整']));
	if (!($_POST['money']) || !($_POST['account'])) exit(json_encode(['code'=>0,'msg'=>'请填写完整']));
	if ($conf['ds_check'] == 'FORCE_CHECK' && !isset($_POST['name'])) exit(json_encode(['code'=>0,'msg'=>'请填写完整']));
	if ($conf['ds_check'] == 'FORCE_CHECK' && empty($_POST['name'])) exit(json_encode(['code'=>0,'msg'=>'请填写完整']));
	if (!is_numeric($_POST['money'])) exit(json_encode(['code'=>0,'msg'=>'金额格式错误']));
	if ($_POST['money'].''<''.$conf['money'].'') exit(json_encode(['code'=>0,'msg'=>'最低换钱提交金额：'.$conf['money'].'元']));
	$type = (int)$_POST['type'];
	if ($type == 0) {
	    $type = 'qqpay';
	    $payee_type = 'wxpay';
	}elseif ($type == 1) {
	    $type = 'qqpay';
	    $payee_type = 'alipay';
	}elseif ($type == 2) {
	    $type = 'wxpay';
	    $payee_type = 'qqpay';
	}elseif ($type == 3) {
	    $type = 'wxpay';
	    $payee_type = 'alipay';
	}elseif ($type == 4) {
	    $type = 'alipay';
	    $payee_type = 'qqpay';
	}elseif ($type == 5) {
	    $type = 'alipay';
	    $payee_type = 'wxpay';
	}else{
	    exit(json_encode(['code'=>0,'msg'=>'mgj']));
	}
	$sxf = isset($conf['jy_sxf'])?$conf['jy_sxf']:3;
	$_POST['money'] = round($_POST['money'],2);
	$realmoney = round($_POST['money']+($_POST['money']*$sxf/100),2);
	$trade_no=date("YmdHis").rand(111,999);
	$accounts = $_POST['account'];
	$moneys = $_POST['money'];
	$c = '{"money":'.$_POST['money'].',"account":"'.trim(daddslashes($_POST['account'])).'","type":"'.$payee_type.'","name":"'.$_POST['name'].'"}';
	
	$sql="insert into `ds_pay` (`trade_no`,`tid`,`zid`,`input`,`num`,`name`,`money`,`ip`,`userid`,`inviteid`,`addtime`,`status`,`accounts`,`moneys`) values ('".$trade_no."','0','1','".$c."','0','哆咪在线换钱系统','".$realmoney."',' ','".$cookiesid."','0','".$date."','0','".$accounts."','".$moneys."')";
	if($DB->query($sql)){
		exit(json_encode(['code'=>1,'msg'=>'OK','url'=>'./other/submit.php?type='.$type.'&orderid='.$trade_no]));
	}else{
		exit(json_encode(['code'=>0,'msg'=>'提交失败']));
	}
}
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="Responsive Admin Dashboard Template">
        <meta name="keywords" content="admin,dashboard">
        <meta name="author" content="stacks">
        <title><?php echo $conf['title']?> - 在线换钱_一键换钱 - 哆咪付（DMF.CN）</title>
        <link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
        <link href="../../assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
        <link href="../../assets/plugins/font-awesome/css/all.min.css" rel="stylesheet">
        <link href="../../assets/css/lime.min.css" rel="stylesheet">
        <link href="../../assets/css/custom.css" rel="stylesheet">
        <script crossorigin="anonymous" src="https://lib.baomitu.com/jquery/2.2.4/jquery.min.js"></script>
        <link crossorigin="anonymous" href="https://lib.baomitu.com/layer/3.1.1/theme/default/layer.css" rel="stylesheet">
        <script crossorigin="anonymous" src="https://lib.baomitu.com/layer/3.1.1/layer.js"></script>
        <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
    </head>
    <body><br>
    
    <?php include 'http://'; ?>
    
        <div class="lime-container">
            <div class="lime-body">
                <div class="container">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="card bg-info text-white">
                                <div class="card-body">
                                    <div class="dashboard-info row">
                                        <div class="info-text col-md-6">
                                            <h5 class="card-title">温馨提示~必看</h5>
                                            <ul>
                                                <li>换钱到微信必须使用获取的OPENID，不然不能正常换成功；</li>
                                                <li>信息请填写真实，否则出问题不予负责！</li>
                                                <li>诺换钱未到账等其他问题请联系平台客服。</li>
                                                <li>提交换钱我们会收取一定手续费，系统会自动增加手续费，提交支付会加入手续费，如：交换100元，手续费：<?php echo $conf['jy_sxf']?>%，将付款<?php echo '100' + $conf['jy_sxf']; ?>元，请悉知！</li>
                                            </ul>
                                            <a href="http://wpa.qq.com/msgrd?v=3&uin=<?php echo $conf['kfqq']?>&site=qq&menu=yes" target="_blank" class="btn btn-warning m-t-xs"><span class="badge badge-light"><i class="fab fa-qq"></i></span>　<code class="alert-link">联系客服QQ：<?php echo $conf['kfqq']?></code></a>　
                                            <a href="<?php echo $conf['url']?>" target="_blank" class="btn btn-warning m-t-xs"><span class="badge badge-light">Q</span>　<code class="alert-link">官方交流群：<?php echo $conf['qun']?></code></a>
                                        </div>
                                        <div class="info-image col-md-6"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-xl">
                            <div class="card">
                                <div class="card-body">
                                    <form action="" method="post">
                                        <div class="form-row">
                                        	<div class="col-md-6 mb-3">
                                            	<div class="input-group">
                                            		<div class="input-group-prepend">
                                            			<span class="input-group-text">换钱方式</span>
                                            		</div>
                                            		<select class="custom-select form-control" name="type">
                                            			<option value="0">ＱＱ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<———— 换 ————>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;微信</option>
                                            			<option value="1">ＱＱ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<———— 换 ————>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;支付宝</option>
                                            			<option value="2">微信&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<———— 换 ————>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ＱＱ</option>
                                            			<option value="3">微信&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<———— 换 ————>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;支付宝</option>
                                            			<option value="4">支付宝&nbsp;&nbsp;&nbsp;<———— 换 ————>&nbsp;&nbsp;&nbsp;ＱＱ</option>
                                            			<option value="5">支付宝&nbsp;&nbsp;&nbsp;<———— 换 ————>&nbsp;&nbsp;&nbsp;微信</option>
                                            		</select>
                                            	</div>
                                            </div>
                                            <div class="col-md-6 mb-3">
                                            	<div class="input-group">
                                            		<div class="input-group-prepend">
                                            			<span class="input-group-text" id="inputGroupPrepend">交换金额</span>
                                            		</div>
                                            		<input type="text" class="form-control" name="money" id="input_money" required placeholder="最低交换金额：<?php echo $conf['money']?>元以上" aria-describedby="inputGroupPrepend" required="">
                                            	</div>
                                            </div>
                                            <div class="col-md-6 mb-3">
                                                <div class="input-group">
                                                	<div class="input-group-prepend">
                                                		<span class="input-group-text" id="s">收款账号（微信Openid）</span>
                                                	</div>
                                                	<input type="text" class="form-control" name="account" id="input_account"  placeholder="要换到的支付宝/QQ/微信（请获取OPENID）" aria-describedby="inputGroupPrepend" required>
                                                	<div class="input-group-append auto">
                                                		<button type="button" class="btn btn-info" data-toggle="modal" data-target="#exampleModalCenter">获取OPENID</button>
                                                	</div>
                                                </div>
                                            </div>
                                            <?php if($conf['ds_check'] == 'FORCE_CHECK'): ?>
                                            <div class="col-md-6 mb-3">
                                                <div class="input-group">
                                                	<div class="input-group-prepend">
                                                		<span class="input-group-text">真实姓名</span>
                                                	</div>
                                                	<input type="text" class="form-control" name="name" id="input_name" required placeholder="要换到的支付宝/QQ/微信真实姓名" aria-describedby="inputGroupPrepend" required>
                                                </div>
                                            </div>
                                            <?php endif; ?>
                                        </div><hr>
                                        <div class="text-center">
                                        	<input type="button" value="立即提交换钱~" onclick="vb();" class="btn btn-primary"/>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                    <?php if($conf['jl'] == '1'): ?>
                    <div class="row">
                        <div class="col-xl">
                            <div class="card">
                                <div class="card-body">
                                	<h5 class="card-title">最新换钱记录（显示最新50条）</h5>
                                    <div class="email-list">
                                    	<table class="table">
                                    		<thead class="thead-dark">
                                            <tr>
                                                <th scope="col">订单号</th>
                                                <th scope="col">换钱账号</th>
                                                <th scope="col">换钱方式</th>
                                                <th scope="col">换钱金额</th>
                                                <th scope="col">提交时间</th>
                                                <th scope="col">交换状态</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        	<?php
                                        	$rs=$DB->query("SELECT * FROM ds_pay WHERE 1 ORDER BY addtime DESC LIMIT 500");
                                        	foreach($rs as $res){
                                        	$types = $res['type'];
                                        	if ($types == 'alipay') {
                                        		$types = '支付宝';
                                        		} else if($types == 'wxpay'){
                                        			$types = '微信';
                                        			}else if($types == 'qqpay'){
                                        				$types = 'QQ钱包';
                                        				}
                                        		echo '<tr>
                                        		<td>'.$res['trade_no'].'</td>
                                        		<td>'.$str = substr_replace($res['accounts'],'***',2,3).'</td>
                                        		<td>'.$types.'</td>
                                        		<td>'.$res['moneys'].'</td>
                                        		<td>'.$res['addtime'].'</td>
                                        		<td>'.($res['status']== '1'?'<span class="badge badge-success">交换成功</span>':'<span class="badge badge-danger">未付款</span>').'</td>
                                        		</tr>';
                                        		}?>

                                        </tbody>
                                    </table>
                                    </div>
                                </div> 
                            </div>
                        </div>
                    </div>
                    <?php endif; ?>
                </div>
            </div>
            <div class="lime-footer">
                <div class="container">
                    <div class="row">
                        <div class="col-md-12">
                            <span class="footer-text"><?php echo $conf['foot'] ?></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- Modal -->
        <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalCenterTitle">请使用微信扫一扫</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <i class="material-icons">close</i>
                        </button>
                    </div>
                    <div class="alert alert-warning m-b-lg text-center" role="alert">将获取的微信OPENID，复制后粘贴到收款账号内即可！</div>
                    <div class="modal-body text-center">
                        <img src="http://qr.liantu.com/api.php?text=http://www.dmf.cn/openid.php">
                    </div>
                </div>
            </div>
        </div>
        <!-- Javascripts -->
        <script src="../../assets/plugins/jquery/jquery-3.1.0.min.js"></script>
        <script src="../../assets/plugins/bootstrap/popper.min.js"></script>
        <script src="../../assets/plugins/bootstrap/js/bootstrap.min.js"></script>
        <script src="../../assets/plugins/jquery-slimscroll/jquery.slimscroll.min.js"></script>
        <script src="../../assets/plugins/chartjs/chart.min.js"></script>
        <script src="../../assets/plugins/apexcharts/dist/apexcharts.min.js"></script>
        <script src="../../assets/js/lime.min.js"></script>
        <script src="../../assets/js/pages/dashboard.js"></script>
<script type="text/javascript">
	$(document).on("change", "select[name=type]", function () {
        var type = $(this).val();
        if (type == '0' || type == '5') {
            $(".auto").show();
            $("#s").text('收款账号（微信Openid）');
        }else{
            $(".auto").hide();
            $("#s").text('收款账号');
        }
    });
	function vb(){
		if (!$("#input_money").val()) { layer.msg('请填写完整');return false; }
		if (!$("#input_account").val()) { layer.msg('请填写完整');return false; }
		var load  = layer.load();
		$.ajax({
			type: "POST",
			url : "./index.php",
			data: $("form").serialize(),
			dataType: "json",
			success: function(res){
				layer.close(load);
				if (res.code) {
					$("body").html("正在跳转支付....");
					window.location.href=res.url;
				} else {
					layer.msg(res.msg);
				}
			}
		});
	}
</script>
        
    </body>
</html>