本文介绍了如何编辑我现有的php函数并添加另一个检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为高级帐户添加另一个选项。目前,你可以每两天改变一次角色,但是我希望再添加一次支票,以保证优质用户每12小时一次。它们由 PREMIUM 中的另一个表确定,它们的 strAccountID 如果它们不是溢价,那么将不会有行为他们的帐户。

I'd like to add another option for premium accounts. At the moment you can class change your character every 2 days but I want to add another check to allow every 12 hours for premium users. They are determined from another table in PREMIUM there is their strAccountID If they are not premium there will be no rows in that table for their account.

这是我目前的PHP功能,适用于所有用户,并允许他们每两天完成一次。

That's my current PHP function which works for all users and allows them to do it every 2 days.

private function doProcessClassChangeFormD()
{
    $db = $this->database[GDB];
    $character = $this->site->SanitizeName($_POST['character']);
    $num_rows = $db->doQuery('SELECT bNation FROM ACCOUNT_CHAR WHERE strAccountID = ? AND ? IN(strCharID1, strCharID2, strCharID3)', $_SESSION['strAccountID'], $character);
    if ($num_rows == -1)
    {
        $db->GetError(__file__, __line__);
        $this->m_ccError = Template::GetLangVar('DB_ERROR');
        return false;
    }
    else if ($num_rows == 0)
    {
        $this->m_ccError = Template::GetLangVar('CC_INVALID_ACCOUNT');
        return false;
    }

    $row = $db->doRead();
    $nation = $row['bNation'];

    $num_rows = $db->doQuery('SELECT Class, Race, Strong, Sta, Dex, Intel, Cha, Points, TransferTime FROM USERDATA WHERE strUserId = ? AND (TransferTime < DATEADD(DAY,-2,GETDATE()) OR TransferTime IS NULL) and zone<>199 and authority<>255', $character);
    if ($num_rows == -1)
    {
        $db->GetError(__file__, __line__);
        $this->m_ccError = Template::GetLangVar('DB_ERROR');
        return false;
    }
    else if ($num_rows == 0)
    {
        $this->m_ccError = Template::GetLangVar('CC_RECENT_TRANSFER');
        return false;
    }

    $row = $db->doRead();

    $oldRace = $row['Race'];
    $oldClass = $row['Class'];
    $newRace = intval($_POST['race']);
    $newClass = intval($_POST['class']);

    $pCT = new ClassTransfer($nation, $oldClass, $oldRace, $newClass, $newRace);
    if (!($res = $pCT->canChangeClass()))
    {   
        $this->m_ccError = $pCT->GetError(__file__, __line__);
        return false;
    }

    $newClass = $res[0];
    $newRace = $res[1];

    $free = $row['Points'] + $row['Strong'] + $row['Sta'] + $row['Dex'] + $row['Intel'] + $row['Cha'];
    $newStats = $pCT->getStarterStats($newClass, $newRace);

    for ($i = 0; $i < 5; $i++)
        $free -= $newStats[$i];

    if ($free > 255)
    {
        $_SESSION['bClassTransfer'] = true;
        $_SESSION['strUserId'] = $character;
        $_SESSION['bNewRace'] = $newRace;
        $_SESSION['bNewClass'] = $newClass;
        $_SESSION['bStrong'] = $newStats[KO_STR];
        $_SESSION['bStamina'] = $newStats[KO_STA];
        $_SESSION['bDexterity'] = $newStats[KO_DEX];
        $_SESSION['bIntelligence'] = $newStats[KO_INT];
        $_SESSION['bCharisma'] = $newStats[KO_CHA];
        $_SESSION['bAvailable'] = $free;

        $this->m_bSelectPoints = true;
        return false;
    }

    $newStats[5] = $free;
    return $this->doExecuteClassChangeD($character, $newClass, $newRace, $newStats);
}

我尝试了几种方法,但没有成功。如何才能实现这一目标?

I've tried several ways but no success. How I can achieve this?

推荐答案

使用 LEFT JOIN PREMIUM 在您的查询中检查传输时间。然后使用该表中的一个匹配来限制您与之比较的时间。

Use a LEFT JOIN with the PREMIUM table in your query that checks the transfer time. Then use a match in that table to conditionalize the time that you compare with.

$num_rows = $db->doQuery('
    SELECT Class, Race, Strong, Sta, Dex, Intel, Cha, Points, TransferTime
    FROM USERDATA u
    LEFT JOIN PREMIUM p ON p.strAccountID = u.strUserId
    WHERE strUserId = ?
      AND (TransferTime < IF(p.strAccountId IS NULL,
                             DATEADD(DAY,-2,GETDATE()),
                             DATE_SUB(NOW(), INTERVAL 12 HOUR)))
           OR TransferTime IS NULL)
      AND zone<>199 and authority<>255', $character);

这篇关于如何编辑我现有的php函数并添加另一个检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 17:50