<?php

/**
 * Description of M
 *
 * @author zongheng
 */
class ActivityController extends DooController {

    public $data;

    function __construct() {
        $this->data['rootUrl'] = Doo::conf()->APP_URL;
    }

    // 新版上线活动
    public function online() {
        $strdate = date('Y-m-d', time());
        if ($strdate == '2012-12-27') {
            $this->render('activity/20121212/eindex', $this->data, TRUE);
            exit();
        }
        if ($strdate == '2012-12-20') {
            $this->data['curday'] = 'day01';
        } elseif ($strdate == '2012-12-21') {
            $this->data['curday'] = 'day02';
        } elseif ($strdate == '2012-12-22') {
            $this->data['curday'] = 'day03';
        } elseif ($strdate == '2012-12-23') {
            $this->data['curday'] = 'day04';
        } elseif ($strdate == '2012-12-24') {
            $this->data['curday'] = 'day05';
        } elseif ($strdate == '2012-12-25') {
            $this->data['curday'] = 'day06';
        } elseif ($strdate == '2012-12-26') {
            $this->data['curday'] = 'day07';
        } else {
            $this->render('activity/20121212/rindex', $this->data, TRUE);
            exit();
        }
        $this->render('activity/20121212/index', $this->data, TRUE);
    }

    // 新版上线活动
    public function onlinedo() {
        if (!$this->isAjax())
            return Doo::conf()->APP_URL . 'online';
        $strdate = date('Y-m-d', time());
        if (!in_array($strdate, array('2012-12-20', '2012-12-21', '2012-12-22', '2012-12-23', '2012-12-24', '2012-12-25', '2012-12-26')))
            exit(json_encode(array('data' => 4)));
        $session = Doo::session("sso");
        if (empty($session->user['id'])) {
            exit(json_encode(array('data' => 2)));
        }
        $userid = intval($session->user['id']);

        Doo::loadClass('client');
        $client = new client('http://sso.smartcost.com.cn/');
        $act = Doo::loadModel('UsersActivity', TRUE);
        if ($strdate == '2012-12-20') {
            $rtn = $act->getOne(array('where' => 'userid=? AND FROM_UNIXTIME( joindate, "%Y-%m-%d")=?', 'param' => array($userid, $strdate), 'asArray' => TRUE));
            if (empty($rtn)) {
                $madd = $client->zhsso_member_madd($userid, 1, 'wenku');
                if ($madd == '1') {
                    $act->userAdd($userid, 1);
                    exit(json_encode(array('data' => 1)));
                }
            } else {
                exit(json_encode(array('data' => 3)));
            }
        } elseif ($strdate == '2012-12-21') {
            $rtn = $act->getOne(array('where' => 'userid=? AND FROM_UNIXTIME( joindate, "%Y-%m-%d")=?', 'param' => array($userid, $strdate), 'asArray' => TRUE));
            if (empty($rtn)) {
                $madd = $client->zhsso_member_madd($userid, 2, 'wenku');
                if ($madd == '1') {
                    $act->userAdd($userid, 2);
                    exit(json_encode(array('data' => 1)));
                }
            } else {
                exit(json_encode(array('data' => 3)));
            }
        } elseif ($strdate == '2012-12-22') {
            $rtn = $act->getOne(array('where' => 'userid=? AND FROM_UNIXTIME( joindate, "%Y-%m-%d")=?', 'param' => array($userid, $strdate), 'asArray' => TRUE));
            if (empty($rtn)) {
                $madd = $client->zhsso_member_madd($userid, 3, 'wenku');
                if ($madd == '1') {
                    $act->userAdd($userid, 3);
                    exit(json_encode(array('data' => 1)));
                }
            } else {
                exit(json_encode(array('data' => 3)));
            }
        } elseif ($strdate == '2012-12-23') {
            $rtn = $act->getOne(array('where' => 'userid=? AND FROM_UNIXTIME( joindate, "%Y-%m-%d")=?', 'param' => array($userid, $strdate), 'asArray' => TRUE));
            if (empty($rtn)) {
                $madd = $client->zhsso_member_madd($userid, 4, 'wenku');
                if ($madd == '1') {
                    $act->userAdd($userid, 4);
                    exit(json_encode(array('data' => 1)));
                }
            } else {
                exit(json_encode(array('data' => 3)));
            }
        } elseif ($strdate == '2012-12-24') {
            $rtn = $act->getOne(array('where' => 'userid=? AND FROM_UNIXTIME( joindate, "%Y-%m-%d")=?', 'param' => array($userid, $strdate), 'asArray' => TRUE));
            if (empty($rtn)) {
                $madd = $client->zhsso_member_madd($userid, 5, 'wenku');
                if ($madd == '1') {
                    $act->userAdd($userid, 5);
                    exit(json_encode(array('data' => 1)));
                }
            } else {
                exit(json_encode(array('data' => 3)));
            }
        } elseif ($strdate == '2012-12-25') {
            $rtn = $act->getOne(array('where' => 'userid=? AND FROM_UNIXTIME( joindate, "%Y-%m-%d")=?', 'param' => array($userid, $strdate), 'asArray' => TRUE));
            if (empty($rtn)) {
                $madd = $client->zhsso_member_madd($userid, 7, 'wenku');
                if ($madd == '1') {
                    $act->userAdd($userid, 7);
                    exit(json_encode(array('data' => 1)));
                }
            } else {
                exit(json_encode(array('data' => 3)));
            }
        } elseif ($strdate == '2012-12-26') {
            $rtn = $act->getOne(array('where' => 'userid=? AND FROM_UNIXTIME( joindate, "%Y-%m-%d")=?', 'param' => array($userid, $strdate), 'asArray' => TRUE));
            if (empty($rtn)) {
                $madd = $client->zhsso_member_madd($userid, 8, 'wenku');
                if ($madd == '1') {
                    $act->userAdd($userid, 8);
                    exit(json_encode(array('data' => 1)));
                }
            } else {
                exit(json_encode(array('data' => 3)));
            }
        } else {
            exit(json_encode(array('data' => 0)));
        }
    }

    // 新版上线活动
    public function test() {
//        $strdate = date('Y-m-d', time());
//        if ($strdate == '2012-12-14') {
//            $this->data['curday'] = 'day01';
//        } elseif ($strdate == '2012-12-15') {
//            $this->data['curday'] = 'day02';
//        } elseif ($strdate == '2012-12-16') {
//            $this->data['curday'] = 'day03';
//        } else {
//            $this->render('activity/20121212/rindex', $this->data, TRUE);
//            exit();
//        }
        $this->render('activity/20121212/eindex', $this->data, TRUE);
    }

// 新版上线活动
    public function testdo() {
        if (!$this->isAjax())
            return Doo::conf()->APP_URL . 'online';
        $strdate = date('Y-m-d', time());
        if (!in_array($strdate, array('2012-12-14', '2012-12-15', '2012-12-16')))
            exit(json_encode(array('data' => 4)));
        $session = Doo::session("sso");
        if (empty($session->user['id'])) {
            exit(json_encode(array('data' => 2)));
        }
        $userid = intval($session->user['id']);
        if ($userid != 2373)
            exit();
        Doo::loadClass('client');
        $client = new client('http://sso.smartcost.com.cn/');
        $act = Doo::loadModel('UsersActivity', TRUE);
        if ($strdate == '2012-12-14') {
            $rtn = $act->getOne(array('where' => 'userid=? AND FROM_UNIXTIME( joindate, "%Y-%m-%d")=?', 'param' => array($userid, $strdate), 'asArray' => TRUE));
            if (empty($rtn)) {
                $madd = $client->zhsso_member_madd($userid, 1, 'wenku');
                if ($madd == '1') {
                    $act->userAdd($userid, 1);
                    exit(json_encode(array('data' => 1)));
                }
            } else {
                exit(json_encode(array('data' => 3)));
            }
        } elseif ($strdate == '2012-12-15') {
            $rtn = $act->getOne(array('where' => 'userid=? AND FROM_UNIXTIME( joindate, "%Y-%m-%d")=?', 'param' => array($userid, $strdate), 'asArray' => TRUE));
            if (empty($rtn)) {
                $madd = $client->zhsso_member_madd($userid, 2, 'wenku');
                if ($madd == '1') {
                    $act->userAdd($userid, 2);
                    exit(json_encode(array('data' => 1)));
                }
            } else {
                exit(json_encode(array('data' => 3)));
            }
        } elseif ($strdate == '2012-12-16') {
            $rtn = $act->getOne(array('where' => 'userid=? AND FROM_UNIXTIME( joindate, "%Y-%m-%d")=?', 'param' => array($userid, $strdate), 'asArray' => TRUE));
            if (empty($rtn)) {
                $madd = $client->zhsso_member_madd($userid, 3, 'wenku');
                if ($madd == '1') {
                    $act->userAdd($userid, 3);
                    exit(json_encode(array('data' => 1)));
                }
            } else {
                exit(json_encode(array('data' => 3)));
            }
        } else {
            exit(json_encode(array('data' => 0)));
        }
    }

}

?>
