<?php

namespace common\models;

use Yii;
use yii\db\Expression;

/**
 * This is the model class for table "fx_user_area".
 *
 * @property integer $area_id
 * @property string $area_name
 */
class FxUserArea extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'fx_user_area';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['area_name'], 'required'],
            [['area_name'], 'string', 'max' => 100],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'area_id' => 'Area ID',
            'area_name' => 'Area Name',
        ];
    }

    /**
     * Des:获取用户所属区域列表
     * Name: getUserAreaList
     * @param string $user_area
     * @return array
     * @author 倪宗锋
     */
    public function getUserAreaList($user_area = '')
    {
        $select = [
            'is_bind' => empty($user_area) ?  new Expression("0") : new Expression("if(area_id in ($user_area),1,0)"),
            'area_id',
            'area_name'
        ];
        $getList = self::find()->select($select)
            ->asArray()
            ->all();
        return $getList;
    }
}
