<?php

/**
 * core\lib\growth\GrowthExp.php
 */

/**
 * 经纪人成长值类
 *
 * @author sun
 */
class GrowthBidStart {
    
    /**
     * 主数据库
     */
    private $db;

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

    /**
     * 缓存对象
     */
    private $mc;
    
    /**
     * 关联的表名
     * @var string
     */
    private $table;
    
    /**
     * 表中包含字段
     * @var array
     */
    private static $fields = array('id','way_alias','start_credit');

    public function __construct() {
        $container = Container::getInstance();
        $this->db = $container->get('db');
        $this->dbback = $container->get('dbback');
        $this->mc = $container->get('mc');
        $this->table = 'growth_bid_start';
    }
    
    /**
     * 返回
     * @return array
     */
    public function findAllData() {
        $sql = SqlCombinHelper::select_sql($this->table, self::$fields);
        return $this->dbback->getAll($sql);
    }
    
    /**
     * 
     * @param type $wayAlias
     * @return type
     */
    public function findOneByWayAlias($wayAlias) {
        $sql = SqlCombinHelper::select_sql($this->table, self::$fields, $wayAlias);
        return $this->dbback->getRow($sql);
    }
    
    /**
     * 
     * @param type $wayAlias
     * @return type
     */
    public function findScoreByWayAlias($wayAlias) {
        $arrRow = $this->findOneByWayAlias($wayAlias);
        return $arrRow['start_credit'] == '' ? 0 : $arrRow['start_credit'];
    }

    /**
     * 保存数据
     * @param array $fields 数据结构
     * @return boolean
     */
    public function saveData($fields) {
        $sql = SqlCombinHelper::replace_sql($this->table, $fields);
        return $this->db->execute($sql);
    }
    
}