<?php 

namespace backend\models;

use Yii;

/**
 * This is the model class for table "crm_modify_lever".
 *
 * @property string $id
 * @property integer $type
 * @property string $member_id
 * @property integer $login
 * @property integer $lever
 * @property string $in_time
 * @property string $memo
 */
class ModifyLever extends \yii\db\ActiveRecord
{
    
    /**
     * @var array
     */
    public static $typeTextMap = [
        0 => '待审核',
        1 => '审核不通过',
        2 => '已修改',
    ];
    
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'crm_modify_lever';
    }

    /**
     * @return \yii\db\Connection the database connection used by this AR class.
     */
    public static function getDb()
    {
        return Yii::$app->get('dbXcrm');
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['type', 'member_id', 'login', 'lever', 'in_time'], 'required'],
            [['type', 'member_id', 'login', 'lever', 'in_time'], 'integer'],
            [['memo'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'type' => 'Type',
            'member_id' => 'Member ID',
            'login' => 'Login',
            'lever' => 'Lever',
            'in_time' => 'In Time',
            'memo' => 'Memo',
        ];
    }

    /**
     * 修改杠杆数量
     * @param int $type 0等待审核，1审核不通过，2已修改
     * @return int
     */
    public static function countByType($type)
    {
        if (!is_numeric($type)) {
            return 0;
        }
        return static::find()->where(['type' => $type])->count();
    }
    
}
