<?php
/**
 * 控制帐号开通付费帐号时是否获取过成长值和积分值。
 *
 * @author sun
 */
class GrowthBrokerPayAccount {
    /**
     * 主数据库
     */
    private $db;

    /**
     * 从数据库
     */
    private $dbback;

    /**
     * 缓存对象
     */
    private $mc;
    
    /**
     * 关联的表名
     * @var string
     */
    private $table;
    
    /**
     * 表中包含字段
     * @var array
     */
    private static $fields = array('id','broker_id','get_credit','get_exp', 'is_know');
    
    public function __construct() {
        $container = Container::getInstance();
        $this->db = $container->get('db');
        $this->dbback = $container->get('dbback');
        $this->mc = $container->get('mc');
        $this->table = 'growth_broker_pay_account';
    }

    public function insertData($brokerId) {
        $arrFieldsValue = array();
        $arrFieldsValue['broker_id'] = $brokerId;
        $arrFieldsValue['get_credit'] = 1;
        $arrFieldsValue['get_exp'] = 1;
        $sql = SqlCombinHelper::insert_sql($this->table, $arrFieldsValue);
        return $this->db->execute($sql);
    }

    public function insertMutl($payAccount) {
        $sql = SqlCombinHelper::insertMutil_sql($this->table, $payAccount);
        $this->db->execute($sql);
        return $this->db->Affected_Rows();
    }

    public function findByBorkerId($brokerId) {
        $sql = SqlCombinHelper::select_sql($this->table, self::$fields, "broker_id = '$brokerId'");
        return $this->db->getRow($sql);
    }

    public function setIsKnowToOne($brokerId) {
        $fieldData = array('is_know' => 1);
        $sql = SqlCombinHelper::update_sql($this->table, $fieldData, "broker_id='$brokerId'");
        if($this->db->execute($sql)) {
            return true;
        } else {
            return false;
        }
    }
}