<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "base_category".
 *
 * @property integer $category_id
 * @property string $category_name
 * @property integer $parent_id
 * @property integer $delete_flag
 * @property string $create_time
 * @property string $update_time
 * @property string $update_user
 */
class BaseCategory extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'base_category';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['category_name'], 'required'],
            [['parent_id', 'delete_flag'], 'integer'],
            [['create_time', 'update_time'], 'safe'],
            [['category_name'], 'string', 'max' => 255],
            [['update_user'], 'string', 'max' => 50],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'category_id' => 'Category ID',
            'category_name' => 'Category Name',
            'parent_id' => 'Parent ID',
            'delete_flag' => 'Delete Flag',
            'create_time' => 'Create Time',
            'update_time' => 'Update Time',
            'update_user' => 'Update User',
        ];
    }

    /**
     * Function Description:获取基础数组信息
     * Function Name: getTypeArr
     *
     * @return array|\yii\db\ActiveRecord[]
     *
     * @author 娄梦宁
     */
    public function getTypeArr(){
        $result=$this::find()->select(['category_id','category_name'])
            ->from(self::tableName())
            ->where(['=','delete_flag',0])
            ->asArray()
            ->all();
        return $result;
    }

    /**
     * Des:获取
     * Name: getAllList
     * @return array|\yii\db\ActiveRecord[]
     * @author 倪宗锋
     */
    public function getAllList()
    {
        $result = self::find()
            ->from(self::tableName())
            ->asArray()
            ->all();
        return $result;
    }

    /**
     * Des:获取页面展示的订单类型
     * Name: getShowList
     * @return array
     * @author 倪宗锋
     */
    public function getShowList()
    {
        $result = self::find()->select(['category_id as order_type_id','category_name as order_type_des'])
            ->from(self::tableName())
            ->asArray()
            ->all();
        return $result;
    }
}
