<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%ORDER}}".
 *
 * @property string $ID
 * @property string $USER_ID 用户ID
 * @property string $ORDER_TYPE 订单类型：BD, FX
 * @property string $STAGE 分期阶段
 * @property int $UPDATE_TIME 修改时间
 */
class Instalment extends \common\components\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%INSTALMENT}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
        ];
    }

    /**
     * @param $userId
     * @return integer
     */
    public static function getStage($userId) {
        $user = static::findOneAsArray("USER_ID = :USER_ID", [':USER_ID' => $userId]);
        if(!$user){
            return 0;
        }
        return $user['STAGE'];
    }

    /**
     * @param $userId
     * @param $orderType
     * @return integer
     */
    public static function getOneStage($userId, $orderType) {
        $user = static::findOneAsArray("USER_ID = :USER_ID AND ORDER_TYPE=:ORDER_TYPE", [':USER_ID' => $userId, ':ORDER_TYPE' => $orderType]);
        if(!$user){
            return 0;
        }
        return $user['STAGE'];
    }

    public static function getInfo($userId) {
        $userInfo = static::findOneAsArray("USER_ID = :USER_ID", [':USER_ID' => $userId]);
        if(!$userInfo){
            return [
            ];
        }
        return $userInfo;
    }
}
