<?php
/*
* 作者: 离家出走
*
* Email: yzxh24@gmail.com
*
* 创建时间: 2010-12-02 17:09:35
*
* 文件名: admin/scripts/cron/floor.php
*
* 功能: 每日特殊楼层发分
* 运行时间：1 0 * * *
*/
/* vim: set ts=4 sw=4: */
require_once dirname(dirname(__FILE__)) . '/init.php';
ini_set('Memory', '750M');

$sql = 'SELECT id,uid,bookid,credits,`type` FROM '.BookFloor::table().' WHERE `status` = 0';
$result = $db->setQueryString($sql)->find();
if (empty($result))
{
    exit(0);
}

foreach ($result as $row)
{
    $status = 2;
    if ($row['credits'])
    {
        $forumInfo = getBookForum($row['bookid']);
        $iCredit = iCredits::single($row['uid'], userName($row['uid']));
        $iCredit->setUid($row['uid']);
        $iCredit->setUserName(userName($row['uid']));
        $iCredit->addMoney($row['credits']);
        $subject = '[系统消息]获得'.BookFloor::$typeMap[$row['type']].'奖励';
        $content = '恭喜您获得《'.$forumInfo['forumname'].'》书会'.BookFloor::$typeMap[$row['type']].$row['credits'].setting('creditname').'奖励';
        Members::sendMessage($subject, $content, 1, 'admin', $row['uid']);
        $status = 1;
    }
    
    $db->update(BookFloor::table())->value(array('operate_uid'=>1,'updatedate'=>date('Y-m-d H:i:s'),'status'=>$status))->where('id='.$row['id'])->q();
}