首页 新闻 搜索 专区 学院

有没有大神能帮我运行周期每天调成每小时的吗?感激不尽

0
悬赏园豆:30 [待解决问题]

<?php
function web_top_main_menu()
{
global $db;
$location = '网站主栏目';
$query = "select * from h_menu where h_location = '$location' and h_isPass = 1 order by h_order asc,id asc";
$result = $db->query($query);
while($list = $db->fetch_array($result))
{
$rs_list[]=$list;
}

$ci = 0;
foreach ($rs_list as $key=>$val)
{
    $ci++;
    
    if($val['h_type'] == 'link')
    {
        echo '<p>';
        echo '<a href="' . $val['h_href'] . '" target="' . $val['h_target'] . '" id="menu_' . $ci . '">' . $val['h_title']. '</a>';
        echo '</p>';
    }
    else
    {
        echo '<p>';
        echo '<a href="' . create_page_url_htaccess_or_not('menu',$val['h_type'],$val['id'],$val['h_pageKey'],0,'',0,'') . '" id="menu_' . $ci . '">' . $val['h_title'] . '</a>';
        echo "</p>";
    }
}

}

function web_left_sub_menu($mType,$mid,$mPageKey,$mTitle,$cid,$cPageKey)
{
global $db;

switch($mType)
{
    case 'articles':
    case 'pics':
        $urlType = 'detail';
        $sql = 'select id,h_title,h_pageKey from `h_article` where h_menuId = ' . $mid . ' order by h_order asc,id asc';
        break;
    case 'news':
    case 'album':
    case 'photos':
        $urlType = 'category';
        $sql = 'select id,h_title,h_pageKey from `h_category` where h_menuId = ' . $mid . ' order by h_order asc,id asc';
        break;
    default:
        return;
}
$result = $db->query($sql);
while($list = $db->fetch_array($result))
{
    $rs_list[]=$list;
}

if(count($rs_list) > 0)
{
    echo '<div class="lBox">';
    echo '  <div class="t"><span class="l">' . $mTitle . '</span></div>';
    echo '  <div class="clear"></div>';
    echo '  <div class="i list">';

    foreach ($rs_list as $key=>$val)
    {
        if($urlType == 'detail')
            echo '<a href="' . create_page_url_htaccess_or_not($urlType,$mType,$mid,$mPageKey,$cid,$cPageKey,$val['id'],$val['h_pageKey']) . '">' . $val['h_title'] . '</a>';
        else
            echo '<a href="' . create_page_url_htaccess_or_not($urlType,$mType,$mid,$mPageKey,$val['id'],$val['h_pageKey'],0,'') . '">' . $val['h_title'] . '</a>';
    }
    
    echo '</div>';
    echo '  <div class="b"></div>';
    echo '</div>';
}

}

function web_bottom_footer_menu()
{
global $db;
$location = '底部栏目';
$query = "select * from h_menu where h_location = '$location' and h_isPass = 1 order by h_order asc,id asc";
$result = $db->query($query);
while($list = $db->fetch_array($result))
{
$rs_list[]=$list;
}

$ci = 0;
if(count($rs_list) > 0)
{
    foreach ($rs_list as $key=>$val)
    {
        $ci++;
        
        if($ci > 1)
            echo ' | ';

        if($val['h_type'] == 'link')
        {
            echo '<a href="' . $val['h_href'] . '" target="' . $val['h_target'] . '" id="menu_footer_' . $ci . '">' . $val['h_title']. '</a>';
        }
        else
        {
            echo '<a href="' . create_page_url_htaccess_or_not('menu',$val['h_type'],$val['id'],$val['h_pageKey'],0,'',0,'') . '" id="menu_footer_' . $ci . '">' . $val['h_title'] . '</a>';
        }
    }
}

}

function create_page_url_htaccess_or_not($urlType,$mType,$mid,$mPageKey,$cid,$cPageKey,$id,$iPageKey)
{
global $rewriteOpen;
$temp = '';

if($rewriteOpen == 1)
{
    $temp = '/' . $mPageKey . '/';
    switch($urlType)
    {
        case 'menu':
            break;
        case 'category':
            if($cPageKey != '')
                $temp .= $cPageKey . '/';
            elseif($cid > 0)
                $temp .= $cid . '/';
                
            break;
        case 'detail':
            //有子分类的,要加上子分类的路径
            switch($mType)
            {
                case 'news':
                case 'album':
                case 'photos':
                    if($cPageKey != '')
                        $temp .= $cPageKey . '/';
                    elseif($cid > 0)
                        $temp .= $cid . '/';

                    break;
            }
                
            if($iPageKey != '')
                $temp .= $iPageKey . '.html';
            elseif($id > 0)
                $temp .= $id . '.html';
                
            break;
    }
}
else
{
    $temp = '/web/' . $mType . '.php';
    switch($urlType)
    {
        case 'menu':
            $temp .= '?mkey=' . $mPageKey;
                
            break;
        case 'category':
            if($cPageKey != '')
                $temp .= '?ckey=' . $cPageKey;
            elseif($cid > 0)
                $temp .= '?cid=' . $cid;
                
            break;
        case 'detail':
            if($iPageKey != '')
                $temp .= '?ikey=' . $iPageKey;
            elseif($id > 0)
                $temp .= '?id=' . $id;
                
            break;
    }
}

return $temp;

}

function web_create_record_and_url_for_pic($isLink,$href,$target,$id,$title,$img,$pageKey,$cTarget,$mType,$mid,$mPageKey,$cid,$cPageKey,$shortNum,$w,$h,$pageUrl = '')
{
if($isLink == 1)
{
$href_ = $href;
$target_ = $target;
}
else
{
$href_ = create_page_url_htaccess_or_not('detail',$mType,$mid,$mPageKey,$cid,$cPageKey,$id,$pageKey);
$target_ = $cTarget;
}

echo '<div class="pic">';
    echo '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="middle" align="center" class="i">';
        echo '<a href="' . $pageUrl . '" target="' . $target_ . '">';
        echo '<img src="' . $img . '" alt="' . $title . '" onload="imgSizeReSet(this,' . $w . ',' . $h . ')" />';
        echo '</a>';
    echo '</td></tr></table>';
    echo '<div class="t">';
        echo '<a href="' . $pageUrl . '" target="' . $target_ . '">';
        if($shortNum > 0)
            echo shortStringCn($title,$shortNum);
        else
            echo $title;
        echo '</a>';
    echo '</div>';
echo '</div>';

}

function web_create_record_and_url_for_news($isLink,$href,$target,$id,$title,$pageKey,$time,$cTarget,$mType,$mid,$mPageKey,$cid,$cPageKey,$shortNum)
{
if($isLink == 1)
{
$href_ = $href;
$target_ = $target;
}
else
{
$href_ = create_page_url_htaccess_or_not('detail',$mType,$mid,$mPageKey,$cid,$cPageKey,$id,$pageKey);
$target_ = $cTarget;
}

echo '<a href="' . $href_ . '" target="' . $target_ . '">';
if($shortNum > 0)
    echo shortStringCn($title,$shortNum);
else
    echo $title;
if($time != ''){echo '<span>' . $time . '</span>';}
echo '</a>';

}

function replace_menu_type_key_to_name($key)
{
$temp = $key;
$temp = replace($temp,'articles','无子分类,多篇文章');
$temp = replace($temp,'article','一篇文章');
$temp = replace($temp,'news','有子分类,多篇文章');
$temp = replace($temp,'pics','无子分类,多张图片');
$temp = replace($temp,'album','有子分类,多张图片');
$temp = replace($temp,'imgs','无子分类,多张纯图片');
$temp = replace($temp,'photos','有子分类,多张纯图片');
$temp = replace($temp,'links','友情链接');
$temp = replace($temp,'link','外部链接');
return $temp;
}

//会员等级
function set_hydj($userName){

global $db;
global $webInfo;

$rs = $db->get_one("select * from h_member where h_userName = '{$userName}'");
$rs3 = $db->get_one("select sum(h_money) as sumP from h_member_farm where h_parentUserName = '{$userName}'");

if(strlen($rs3['sumP']) <= 0){
$rs3['sumP'] = 0;
}

$ztyj = $rs3['sumP'];

if($rs3['sumP']< $webInfo['h_levelUpTo6']){

$dj = 1;

}

if($rs3['sumP'] >= $webInfo['h_levelUpTo6'] && $rs3['sumP']< $webInfo['h_levelUpTo7']){

$dj = 2;

}

if($rs3['sumP'] >= $webInfo['h_levelUpTo7'] && $rs3['sumP']< $webInfo['h_levelUpTo8']){

$dj = 3;

}

if($rs3['sumP'] >= $webInfo['h_levelUpTo8']){

$dj = 4;

}

$sql = "update `h_member` set ";
$sql .= "h_level = {$dj} ";
$sql .= "where h_userName = '" . $userName . "' ";
$db->query($sql);
    
$sql = "update `h_member` set ";
$sql .= "bogy = {$ztyj}  ";
$sql .= "where h_userName = '" . $userName . "' ";
$db->query($sql);

if($rs3['sumP'] >= $webInfo['h_levelUpTo9']){

if($rs['dog'] == 0){

$sql = "update `h_member` set ";
$sql .= "dog = 1  ";
$sql .= "where h_userName = '" . $userName . "' ";
$db->query($sql);

    $tdj = $webInfo['h_levelUpTo10'];

    $sql = "update `h_member` set ";
    $sql .= "h_point2 = h_point2 + {$tdj} ";
    $sql .= "where h_userName = '" . $userName . "' ";
    $db->query($sql);
    
    //记录
    $sql = "insert into `h_log_point2` set ";
    $sql .= "h_userName = '" . $userName . "', ";
    $sql .= "h_price = '" . $tdj . "', ";
    $sql .= "h_type = '直推团队奖', ";
    $sql .= "h_about = '完成直推团队业绩目标的奖励', ";
    $sql .= "h_addTime = '" . date('Y-m-d H:i:s') . "', ";
    $sql .= "h_actIP = '" . getUserIP() . "' ";
    $db->query($sql);

}

}

}

//结算会员的收益
function settle_farm_day($userName){
global $db;

$bonusAll = 0;
$now = date('Y-m-d H:i:s');

$sql = "select *,DATEDIFF(sysdate(),h_lastSettleTime) as diffDaysS,DATEDIFF(sysdate(),h_addTime) as diffDaysA from `h_member_farm` where h_userName = '{$userName}' and h_isEnd = 0 and DATEDIFF(sysdate(),h_addTime) > 0 and (DATEDIFF(sysdate(),h_lastSettleTime) <> 0 or h_lastSettleTime is null)";
$query = $db->query($sql);
//遍历
while($rs = $db->fetch_array($query)){
    //计算上次结算与今天的时间差(天数)
    //如果上次未结算,默认为购买时便已结算(虚拟)
    $dateDiffDay = $rs['diffDaysS'];
    if(is_null($dateDiffDay)){
        $dateDiffDay = $rs['diffDaysA'];
    }
    $dateDiffDay = intval($dateDiffDay);
    if($dateDiffDay <= 0){
        $dateDiffDay = intval($rs['diffDaysA']);
    }
    //echo $mustSettleDay , '|' ,  $rs['id'];
    //exit;
    if($dateDiffDay <= 0){
        continue;
    }
    
    //需要结算的天数
    //如果超出生存周期,最多是生存周期
    $mustSettleDay = $dateDiffDay;
    if(($mustSettleDay + $rs['h_settleLen']) > $rs['h_life']){
        $mustSettleDay = $rs['h_life'] - $rs['h_settleLen'];
    }
    
    
    if($mustSettleDay > 0){
        //是否死亡
        if(($mustSettleDay + $rs['h_settleLen']) >= $rs['h_life']){
            $isEnd = 1;
        }else{
            $isEnd = 0;
        }
        
        //需要结算的收益
        $mustSettleMoney = $mustSettleDay * $rs['h_point2Day'] * intval($rs['h_num']);
        
        //累加,最后一次性发放
        $bonusAll += $mustSettleMoney;
        
        //更新为已发放
        $sql = "update `h_member_farm` set h_settleLen = h_settleLen + ({$mustSettleDay}),h_lastSettleTime = '{$now}',h_isEnd = '{$isEnd}' where id = '{$rs['id']}'";
        $db->query($sql);
    }

    //echo $rs['h_lastSettleTime'] . '|';
    //echo $dateDiffDay . '|';
    //echo $mustSettleDay . '|';
    //echo $mustSettleMoney . '|';
    //echo $isEnd . '|';
    //echo '<br />';
}

//echo '总额:';
//echo $bonusAll . '|';
//echo '<br />';

//一次性发放
if($bonusAll > 0){
    //加款
    $sql = "update `h_member` set ";
    $sql .= "h_point2 = h_point2 + ({$bonusAll}) ";
    $sql .= "where h_userName = '" . $userName . "' ";
    $db->query($sql);
    
    //记录
    $sql = "insert into `h_log_point2` set ";
    $sql .= "h_userName = '" . $userName . "', ";
    $sql .= "h_price = '" . $bonusAll . "', ";
    $sql .= "h_type = '每日收益', ";
    $sql .= "h_about = '登录,系统自动收入每日收益', ";
    $sql .= "h_addTime = '" . date('Y-m-d H:i:s') . "', ";
    $sql .= "h_actIP = '" . getUserIP() . "' ";
    $db->query($sql);
    
    //发放奖金
    bonus_farm_day($userName,$bonusAll,$userName);
}

}

//下级会员产生收益时的提成,8级
function bonus_farm_day($buyUserName,$bonusAll,$currUserName,$floorIndex = 1){
global $db;
global $webInfo;

if($floorIndex > 8){
    return;
}

//奖金
$bonus = floatval($bonusAll) * floatval($webInfo['h_point2Com' . $floorIndex]);

$rs = $db->get_one("select * from `h_member` where h_userName = '{$currUserName}'");
//会员存在
if($rs){
    //推荐人存在,结算给推荐人
    if(strlen($rs['h_parentUserName']) > 0){
        //奖金 > 0 才发放和记录
        if($bonus > 0){
            //加款
            $sql = "update `h_member` set ";
            $sql .= "h_point2 = h_point2 + ({$bonus}) ";
            $sql .= "where h_userName = '" . $rs['h_parentUserName'] . "' ";
            $db->query($sql);
            
            //记录
            $sql = "insert into `h_log_point2` set ";
            $sql .= "h_userName = '" . $rs['h_parentUserName'] . "', ";
            $sql .= "h_price = '" . $bonus . "', ";
            $sql .= "h_type = '推广收益', ";
            $sql .= "h_about = '第" . $floorIndex . "代会员" . $buyUserName . "登录,系统自动收入推广收益', ";
            $sql .= "h_addTime = '" . date('Y-m-d H:i:s') . "', ";
            $sql .= "h_actIP = '" . getUserIP() . "' ";
            $db->query($sql);
            //echo $sql . '<br />';
        }
        
        //下一轮
        bonus_farm_day($buyUserName,$bonusAll,$rs['h_parentUserName'],$floorIndex + 1);
    }
}

}

//注册赠送
function bonus_member_reg($regUserName,$parentUserName){
global $db;
global $webInfo;

if($webInfo['h_point2ComRegAct'] > 0){
    $bonus = $webInfo['h_point2ComRegAct'];
    
    //加款
    $sql = "update `h_member` set ";
    $sql .= "h_point2 = h_point2 + ({$bonus}) ";
    $sql .= "where h_userName = '" . $parentUserName . "' ";
    $db->query($sql);
    
    //记录
    $sql = "insert into `h_log_point2` set ";
    $sql .= "h_userName = '" . $parentUserName . "', ";
    $sql .= "h_price = '" . $bonus . "', ";
    $sql .= "h_type = '推广注册奖', ";
    $sql .= "h_about = '直接推荐会员" . $regUserName . "注册', ";
    $sql .= "h_addTime = '" . date('Y-m-d H:i:s') . "', ";
    $sql .= "h_actIP = '" . getUserIP() . "' ";
    $db->query($sql);
    //echo $sql . '<br />';
}
    if($webInfo['h_point2ComReg'] > 0){
    $bonus = $webInfo['h_point2ComReg'];

   //新用户注册奖励
    $sql = "update `h_member` set ";
    $sql .= "h_point1 = h_point1 + ({$bonus}) ";
    $sql .= "where h_userName = '" . $regUserName . "' ";
    $db->query($sql);
    
    //新用户注册奖励
    $sql = "insert into `h_log_point1` set ";
    $sql .= "h_userName = '" . $regUserName . "', ";
    $sql .= "h_price = '" . $bonus . "', ";
    $sql .= "h_type = '新用户注册', ";
    $sql .= "h_about = '新用户注册奖励" . $bonus . "元', ";
    $sql .= "h_addTime = '" . date('Y-m-d H:i:s') . "', ";
    $sql .= "h_actIP = '" . getUserIP() . "' ";
    $db->query($sql);

}


if($webInfo['h_point2ComRegAct2'] > 0){
    $bonus = $webInfo['h_point2ComRegAct2'];
    
    //新用户注册奖励
    $sql = "update `h_member` set ";
    $sql .= "h_point2 = h_point2 + ({$bonus}) ";
    $sql .= "where h_userName = '" . $regUserName . "' ";
    $db->query($sql);


    //新用户注册奖励
    $sql = "insert into `h_log_point2` set ";
    $sql .= "h_userName = '" . $regUserName . "', ";
    $sql .= "h_price = '" . $bonus . "', ";
    $sql .= "h_type = '新用户注册', ";
    $sql .= "h_about = '新用户注册奖励" . $bonus . "元', ";
    $sql .= "h_addTime = '" . date('Y-m-d H:i:s') . "', ";
    $sql .= "h_actIP = '" . getUserIP() . "' ";
    $db->query($sql);

}

}

小白的苦的主页 小白的苦 | 初学一级 | 园豆:131
提问于:2020-03-20 05:34
< >
分享
所有回答(3)
0

你直接把业务代码贴出来好吗?

Tom.汤 | 园豆:1977 (小虾三级) | 2020-03-20 08:35
0

你这代码太长了也

风行天下12 | 园豆:3302 (老鸟四级) | 2020-03-20 09:32
0

你把GitHub地址贴出来吧,这样看不出来

DNLi | 园豆:306 (菜鸟二级) | 2020-03-20 18:09

我是本地塔建的 就是每天结算一次,我想把代码改成每小时结算一次的。

支持(0) 反对(0) 小白的苦 | 园豆:131 (初学一级) | 2020-03-20 18:26
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册