<?php
require "./config.php";
require "./function/function.php";
header("content-type:text/html;charset=utf-8");
ignore_user_abort();//关闭浏览器仍然执行
set_time_limit(0);//让程序一直执行下去
$interval=24*3600;//每隔一天时间运行
$yier = 12*24*3600;
$yue = 30*24*3600;
$date_time = date("Y-m-d H:i:s");
$time = time(); //当前时间
do{
sleep($interval);//等待时间,进行下一次操作。
$sql = "select * from ims_shop_jichang_vip where ji_num > 0 or dan_num > 0"; //会员卡vip表
$arr = query($sql);
if($arr != null)
{
foreach($arr as $key => $value)
{
$openid = $value['open_id'];
$sql = "select * from ims_ewei_shop_vip where jihuo_users = '{$openid}' order by jihuotime desc limit 0,1";
$jihuo_arr = find_query($sql);
if($value['ji_num'] > 0)
{
$get_ji_num = $value['ji_num'];
}
else
{
$get_ji_num = 0;
}
if($value['dan_num'] > 12)
{
$get_dan_num = 12;
}
else
{
$get_dan_num = $value['dan_num'];
}
$ji_cha_time = $time - $value['top_ji_time'];
$dan_cha_time = $time - $value['top_dan_time'];
$moxing_id = $jihuo_arr['moxing_id'];
$sql = "select id from ims_ewei_shop_goods where moxing_id = {$moxing_id} order by id desc limit 0,1";
$goods_arr = find_query($sql);
$goods_id = $goods_arr['id'];
$uniacid = 2;
file_put_contents("log.txt", 'openid:'.$openid.' ---top_ji_time:'.date("Y-m-d H:i:s",$value['top_ji_time']).' ---top_dan_time:'.date("Y-m-d H:i:s",$value['top_dan_time']).' ---运行时间:'.$date_time."\r\n", FILE_APPEND); //日志记录
if($dan_cha_time > $yier && $dan_num > 0) //鸡蛋定时发货
{
$sql = "select * from ims_ewei_shop_member_address where openid = '{$openid}' and uniacid = {$uniacid} and isdefault = 1"; //收货地址
$address_arr = find_query($sql);
$address_id = $address_arr['id'];
$address = serialize($address_arr);
$ordersn = 'SH'.date("Ymd").rand(000000,999999);
file_put_contents("dan.txt", 'openid:'.$openid.' ---订单号:'.$ordersn.' ---时间:'.$date_time."\r\n", FILE_APPEND); //日志记录
$sql = "insert into ims_ewei_shop_order (status,paytype,uniacid,openid,ordersn,price,remark,addressid,address,createtime,paytime,oldprice,grprice) values (1,1,{$uniacid},'{$openid}','{$ordersn}',0,'默认蛋发货',{$address_id},'{$address}','{$time}','{$time}',0,0)";
mysql_query($sql);
$insert_id = mysql_insert_id();
if($insert_id > 0)
{
$sql = "insert into ims_ewei_shop_order_goods (uniacid,orderid,goodsid,price,total,createtime,realprice,oldprice,openid,ji_num,optionname) values ({$uniacid},{$insert_id},$goods_id,0,{$dan_num},'{$time}',0,0,'{$openid}',{$dan_num},'默认蛋发货')";
mysql_query($sql);
$sql = "update ims_shop_jichang_vip set dan_num = dan_num - {$dan_num}, top_dan_time = {$time} where open_id = '{$openid}' and uniacid = {$uniacid}";
mysql_query($sql);
}
}
if($ji_cha_time > $yue && $ji_num > 0) //鸡定时发货
{
$sql = "select * from ims_ewei_shop_member_address where openid = '{$openid}' and uniacid = {$uniacid} and isdefault = 1"; //收货地址
$address_arr = find_query($sql);
$address_id = $address_arr['id'];
$address = serialize($address_arr);
$ordersn = 'SH'.date("Ymd").rand(000000,999999);
file_put_contents("ji.txt", 'openid:'.$openid.' ---订单号:'.$ordersn.' ---时间:'.$date_time."\r\n", FILE_APPEND); //日志记录
$sql = "insert into ims_ewei_shop_order (status,paytype,uniacid,openid,ordersn,price,remark,addressid,address,createtime,paytime,oldprice,grprice) values (1,1,{$uniacid},'{$openid}','{$ordersn}',0,'默认鸡发货',{$address_id},'{$address}','{$time}','{$time}',0,0)";
mysql_query($sql);
$insert_id = mysql_insert_id();
if($insert_id > 0)
{
$sql = "insert into ims_ewei_shop_order_goods (uniacid,orderid,goodsid,price,total,createtime,realprice,oldprice,openid,ji_num,optionname) values ({$uniacid},{$insert_id},$goods_id,0,{$ji_num},'{$time}',0,0,'{$openid}',{$ji_num},'默认鸡发货')";
mysql_query($sql);
$sql = "update ims_shop_jichang_vip set ji_num = ji_num - {$ji_num}, top_ji_time = {$time} where open_id = '{$openid}' and uniacid = {$uniacid}";
mysql_query($sql);
}
}
}
}
}while(true);
?>
PHP 使用do while 实现定时器功能
猜你喜欢
转载自blog.csdn.net/weixin_40896800/article/details/83007100
今日推荐
周排行