<?php
/**
 * Created by PhpStorm.
 * User: stanley-king
 * Date: 16/4/12
 * Time: 上午12:06
 */
namespace bonus;

use \Exception;

class factory
{
    static public function make_vote_type($paramer,$rate_moneys=null)
    {
        try
        {
            $type = type::crate_by_input($paramer);
            $iGen = create_generator($type);
            $iGen->make_type();

            $money = $type->getTotal_amount();
            return array('type_sn' => $type->getType_sn(),'money' => $money);
        }
        catch (Exception $ex) {
            return false;
        }
    }

    static public function make_bonus($paramer,$rate_moneys) //数组类型的参数
    {
        try
        {
            $type = type::crate_by_input($paramer);
            $iGen = create_generator($type);
            $iGen->make_type();

            if(!$ret = $iGen->make_bonus($rate_moneys)) {
                Model('bonus_type')->delete(array('type_id' => $type->getType_id()));
                Model('user_bonus')->delete(array('type_id' => $type->getType_id()));

                return false;
            }
            $money = $type->getTotal_amount();
            return array('type_sn' => $type->getType_sn(),'money' => $money);
        }
        catch (Exception $ex) {
            return false;
        }
    }

    static public function grab_bonus($paramer) //数组类型的参数
    {
        try
        {
            $type = type::create_by_sn($paramer['type_sn']);
            $iGrab = create_grab($type);
            $bonus = $iGrab->get_bonus($paramer);
            if(empty($bonus)) {
                return false;
            } else {
                return $bonus;
            }
        } catch (Exception $ex) {
            return false;
        }
    }
}