<?php
require_once dirname(dirname(__FILE__)) . '/init.php';

$tid = $argv[1];
$credit = $argv[2];

if (empty($tid) || empty($credit))
{
    echo "用法：php FloorAward tid 帖子ID 奖励积分\n";
    exit(0);
}

$sql = 'SELECT floor,uid FROM '.RobBuildFloor::table().' WHERE tid = '.$tid;
$result = $db->setQueryString($sql)->find();
if (empty($result))
{
    echo "没有找到相应楼层\n";
    exit(0);
}

foreach ($result as $row)
{
    $floor = $row['floor'];
    $uid = $row['uid'];
    $userName = userName($uid);
    $iCreditObj = iCredits::single($uid, $userName);
    $iCreditObj->setUid($uid);
    $iCreditObj->setUserName($userName);
    $iCreditObj->addMoney($credit);

    $subject = '[系统消息]踢楼活动奖励';
    $message = '感谢您对社区活动的支持，在此次踢楼活动中您踢中了'.$floor.'楼，获得'.$credit.setting('creditname').'奖励';
    Members::sendMessage($subject, $message, 1, 'admin', $uid);
}