使用thinkphp添加会员到期时间为什么对不上,向数据库添加一天时间就会自动添加3天时间
添加一个月就会自动添加三个月,
而且添加到数据库的时间过10几秒刷新一下就会自动增加一天时间,我是菜鸟,真的不知道哪里有问题,各位大佬帮忙指出一下,
关于的代码全部放在下方了,还有支付成功layer.msg 一直在闪动
IndexController.class.php控制器
<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends BaseController {
public function index(){
// 调出数据库home表内的数据显示在首页
$high = M('Home')->select();
$user = M('vipname')->where(array("id"=>$this->user["id"]))->find();
$this->assign('high',$high);
$this->assign('user',$user);
$this->assign('high',$high);
$this->display();
}
public function logout(){
unset($_SESSION['vipname_id']);
unset($_SESSION['vipname_username']);
$this->redirect("login");
}
public function pay() {
$date = $_GET["date"];
header('Content-type:text/html; Charset=utf-8');
/*** 请填写以下配置信息 ***/
$appid = '201906875648235'; //https://open.alipay.com 账户中心->密钥管理->开放平台密钥,填写添加了电脑网站支付的应用的APPID
$notifyUrl = $_SERVER['SERVER_NAME'] . U('Public/pay_success',array("date"=>$_GET["date"], "uid"=>$_SESSION['vipname_id'])); //付款成功后的异步回调地址
$outTradeNo = uniqid(); //你自己的商品订单号,不能重复
$payAmount = 0.01 * $date; //付款金额,单位:元 目前是月份*1个月多少钱,可以自己写到配置文件中灵活设置
$orderName = '支付测试'; //订单标题
$rsaPrivateKey='MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC8lYY6qb5wD+GqRnwXrg03kncGomvEZFELP9VDsOV16EygztUKyuC4xoqk/hHStkCQooI3DkhOZHV6WMbaAwkWctRa1dGpVJeGupMmssnlLiBBTImlsIhcyFNpLFeLYCyBDk9CZdgbl4qD8Po/4gNZtIJ6J4zgYylCnt3D+m+6bVAcOTy2Qh6v9M11hWXAT7eZiquqMutjRX0lWai16iEsXRaDcKfR/sDeksGePdwJu1DKT0+Lzk9HVTxfmJO+9dbWukaBPhvbq75WCgN2ZUoXd9D+A7ZKEEj6I2bo0CZdPWEiP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gadGF5jsV2pFDKM1h3yPZMjOwl++yT50ADGsFK/+e4N+JS+2WDDCBHSf5zo7rap0zvYUsvv5TlsTjQt+27GloxP4ZqxLkInS2TIJDya6X2vZ+WPTDuqeRtFHEnBqMLWGIMVOn4SuKj6wzjeVhc='; //商户私钥,填写对应签名算法类型的私钥,如何生成密钥参考:https://docs.open.alipay.com/291/105971和https://docs.open.alipay.com/200/105310
/*** 配置结束 ***/
$aliPay = new \Org\Util\QRcode();
$aliPay->setAppid($appid);
$aliPay->setNotifyUrl($notifyUrl);
$aliPay->setRsaPrivateKey($rsaPrivateKey);
$aliPay->setTotalFee($payAmount);
$aliPay->setOutTradeNo($outTradeNo);
$aliPay->setOrderName($orderName);
$result = $aliPay->doPay();
$result = $result['alipay_trade_precreate_response'];
if($result['code'] && $result['code']=='10000'){
//生成二维码
$url = 'https://api.pwmqr.com/qrcode/create?url='.$result['qr_code'];
echo "<img src='{$url}' style='width:300px;'><br>";
echo '二维码内容:'.$result['qr_code'];
}else{
echo $result['msg'].' : '.$result['sub_msg'];
}
}
public function get_success(){
$user = M('vipname')->where(array("id"=>$this->user["id"]))->find();
if (time() - strtotime($user["update_time"]) <= 15 && time()-strtotime($user["update_time"]) >0){
echo json_encode(array("code" =>200));
}else{
echo json_encode(array("code" =>400));
}
}
}
?>
PublicController.class.php控制器
<?php
namespace Home\Controller;
use Think\Controller;
class PublicController extends Controller {
public function login(){
if(IS_POST){
//检测验证码是否正确
$code = I('code');
$verify = $this->check_verify($code);
if(!$verify){
$res['status'] = 0;
$res['message'] = '验证码错误!';
$this->ajaxReturn($res);
}
//检测用户名和密码是否正确
$username = I("username",'','trim');
$password = I("password",'','trim');
$vipname = M("vipname")->where(array("username"=>$username))->find();
if(!$vipname || $vipname['password'] != $password){
$res['status'] = 0;
$res['message'] = '用户名或者密码错误!';
$this->ajaxReturn($res);
}else{
$data = array(
"loginip" =>get_client_ip(),
"logintime"=>date("Y-m-d H:i:s"),
);
M("vipname")->save($data);
session('vipname_id',$vipname["id"]);
session('vipname_username',$vipname["username"]);
$res['status'] = 1;
$res['message'] = '登录成功!';
$this->ajaxReturn($res);
}
}else{
//判断session是否存在,session存在不需登录,直接跳转
if(session('vipname_id') || session('vipname_username')){
$this->redirect("Index/Index");
}else{
$this->display();
}
}
}
/**
* 产生验证码方法
*/
public function verify(){
$config = array(
'fontSize' => 15, // 验证码字体大小
'length' => 4, // 验证码位数
'useNoise' => false, // 关闭验证码杂点
'imageW' => 108, // 图片宽度
'imageH' => 42, // 图片高度
'codeSet' => '0123456789',//随机产生0-9中的数字
);
$Verify = new \Think\Verify($config);
$Verify->entry();
}
/**
* 检验登录信息
*/
public function checkLogin(){
/**检测验证码是否正确**/
$code = I('code'); //接收验证码
$verify = $this->checkCode($code); //调用checkCode方法
if(!$verify){
$res['status'] = 0;
$res['message'] = '验证码错误!';
$this->ajaxReturn($res);
}
/**检测用户名密码是否正确**/
$username = I("username"," ","trim"); //接收用户名,并且使用trim函数去除首尾空格
$password = I("password"," ","trim"); //接收密码,并且使用md5函数加密
$return = $this->checkPassword($username,$password);
if(!$return){
$res['status'] = 0;
$res['message'] = '用户名或者密码错误!';
$this->ajaxReturn($res);
}else{
$data = array(
"login_ip" =>get_client_ip(), //获取ip地址
"login_time"=>date("Y-m-d H:i:s"), //记录登录日期
);
M("vipname")->save($data); //增加数据
session('vipname_id', $return["id"]); //将vipname_id存入session
session('vipname_username', $return["username"]); //将vipname_username存入session
session('vipname_vip_duration',$return["vip_duration"]);
session('vipname_img',$return["img"]);
$res['status'] = 1;
$res['message'] = '登录成功!';
$this->ajaxReturn($res);
}
}
/**
* 检测用户输入验证码是否正确
* @param $code :输入的验证码
* @return bool :验证码正确返回true,否则返回false
*/
public function checkCode($code){
$verify = new \Think\Verify();
return $verify->check($code); //调用检验方法
}
/***
* 检测用户名密码是否匹配
* @param $username
* @param $password
* @return bool
*/
public function checkPassword($username,$password){
$map['username'] = $username;
$vipname = M('vipname')->where($map)->find();
if($vipname['password'] === $password){
return $vipname;
}else{
return false;
}
}
/**
* 退出
*/
public function logout(){
unset($_SESSION['vipname_id']);
unset($_SESSION['vipname_username']);
$this->redirect("login");
}
public function pay_success(){
$date = $_GET["date"];
$uid = $_GET["uid"];
$vip = M('vipname')->where(array("id"=>$uid))->find();
if (empty($vip)){
dump("非法请求");
return;
}
if ($date==1){
$t = 30*24*60*60;
}elseif ($date==2){
$t = 30*24*60*60;
}else {
$t = 30*24*60*60;
}
if ($vip[vip_duration] > date('Y-m-d h:i:s', time())){
M('vipname')->where(array("id"=>$uid))->save(array("vip_duration"=>date('Y-m-d h:i:s', strtotime($vip[vip_duration]) + $t), "update_time"=>date('Y-m-d H:i:s'),time()));
}else{
M('vipname')->where(array("id"=>$uid))->save(array("vip_duration"=>date('Y-m-d h:i:s', time()+$t), "update_time"=>date('Y-m-d H:i:s'),time()));
}
}
}
index.html模板
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="__PUBLIC__/css/css.css" rel="stylesheet">
<title>荒岛斯</title>
<script src="__PUBLIC__/static/jquery-2.1.1.min.js"></script>
<script src="__PUBLIC__/static/layer/layer.js"></script>
<script type="text/javascript">
function openNav() {
document.getElementById("mySidenav").style.width = "98%";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>
<style>
body {
font-family: "Lato", sans-serif;
}
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #17202A;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
text-align:center;
}
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #7B7D7D;
display: block;
transition: 0.3s;
}
.sidenav a:hover{
color: #f1f1f1;
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 20px;
font-size: 36px;
margin-left: 50px;
}
@media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
.linear{
width:100px;
height:100px;
border-radius:50px;
}
.table {
text-align: center;
}
.table table {
font-size: 14px;
border-collapse: collapse;
width: 100%;
table-layout: fixed;
text-align: center;
line-height: 25px;
margin:0 auto;
}
.table table tr {
border: dashed 1px #a59e9e;
border-left: none;
border-right: none;
}
</style>
</head>
<body>
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<img src="__PUBLIC__/img/{$Think.session.vipname_img}" class="linear" />
</hr>
<a href="{:U('#')}">{$Think.session.vipname_username}</a>
<a href="#">会员: {$user.vip_duration} 到期</a>
</hr>
<a href="#" id="buy">开通会员</a>
</hr>
<a href="{:U('/admin/img')}">图片</a>
</hr>
<a href="{:U('Public/logout')}">退出</a>
</hr>
</div>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰</span>
<br>
<div class="sr1">
<form action="__SELF__" method="post">
<input type="text" placeholder="请输入关键词" name="keyword" value="{$keyword}" class="sr"/>
<input type="submit" name="submit" value="搜索" class="al"/>
</form>
</div>
<br>
<div class="table">
<table>
<tr>
<th>图片</th>
<th>标题</th>
<th>操作</th>
</tr>
<foreach name="high" item="vo">
<tr>
<td align="center" width="25%"><img src="__PUBLIC__/upload/{$vo.head}" class="tp"></src></td>
<td align="center" width="45%">{$vo.tbname}</td>
<td align="center" width="20%">
<a href="{$vo.href}" class="urlClick">链接</a>
</td>
</tr>
</foreach>
</table>
</div>
<script> $('.urlClick').on('click',function() {
console.log("当前URL为:", $(".urlClick").attr("href"));
if ($(".urlClick").attr("href") == ""){
layer.msg('会员!',{time:2000});
return false;
}
return true;
});
var active = {
confirmTrans: function(){
//配置一个透明的询问框
layer.msg('大部分参数都是可以公用的合理搭配,展示不一样的风格', {
time: 20000, //20s后自动关闭
btn: ['明白了', '知道了', '哦']
});
}
};
$('#buy').on('click', function(){
layer.confirm('请选择开通时长', {
time: 20000, //20s后自动关闭
btn: ['1个月', '3个月', '6个月']
}, function(){
setInterval('showUnreadNews()',50);//轮询执行,500ms一次
layer.open({
type: 2,
skin: 'layui-layer-demo', //样式类名
closeBtn: 0, //不显示关闭按钮
anim: 2,
shadeClose: true, //开启遮罩关闭
area: ['400px', '400px'], //宽高
content: "{:U('Home/index/pay?date=1')}"
});
}, function(){
layer.open({
type: 2,
skin: 'layui-layer-demo', //样式类名
closeBtn: 0, //不显示关闭按钮
anim: 2,
shadeClose: true, //开启遮罩关闭
area: ['400px', '400px'], //宽高
content: "{:U('Home/index/pay?date=2')}"
});
setInterval('showUnreadNews()',50);//轮询执行,500ms一次
}, function(){
layer.open({
type: 2,
skin: 'layui-layer-demo', //样式类名
closeBtn: 0, //不显示关闭按钮
anim: 2,
shadeClose: true, //开启遮罩关闭
area: ['400px', '400px'], //宽高
content: "{:U('Home/index/pay?date=3')}"
});
setInterval('showUnreadNews()',50);//轮询执行,500ms一次
});
});
function showUnreadNews()
{
$.ajax({
type:"post",
url :"{:U('Index/get_success')}",
data:{uid:"{$user.id}"},
dataType: "json",
success: function(res){
if(res.code == 200){
layer.msg("支付成功",);
window.location.href = "{:U('Index/index')}";
}
}
});
}
</script>
</body>
</html>