<?php
/**
 * @link      http://www.u-bo.com
 * @copyright 南京友博网络科技有限公司 
 * @license   http://www.u-bo.com/license/
 */

namespace home\models;

use Yii;

/**
 * This is the model class for table "qc_payment_method".
 *
 * 付款方式模型
 *
 * @property integer $method_id  (付款方式ID)
 * @property string $name  (合同名称)
 * @property integer $user_id  (创建人，关联表qc_user)
 * @property integer $create_time  (创建时间)
 * @property integer $update_time  (更新时间)
 * @property integer $sort  (排序)
 * @property smallint $status  (状态：0 禁用 1开启 99逻辑删除 默认开启)
 * @property string $ip  (创建人IP)
 *
 * @author zealxd http://blog.u-bo.com
 * @since 0.1
 */
class PaymentMethod extends \yii\db\ActiveRecord
{

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%payment_method}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'create_time', 'update_time', 'sort', 'status'], 'integer'],
            [['name'], 'string', 'max' => 100],
            [['ip'], 'string', 'max' => 15]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'method_id' => 'Method ID',
            'name' => 'Name',
            'user_id' => 'User ID',
            'create_time' => 'Create Time',
            'update_time' => 'Update Time',
            'sort' => 'Sort',
            'status' => 'Status',
            'ip' => 'Ip',
        ];
    }

    /**
     * 付款方式下拉框
     *
     * @return array $data
     */
    public static function getMethodList()
    {
        $MethodList = static::find()->where(['status' => 1])->orderBy(['sort' => SORT_DESC, 'method_id' => SORT_DESC])->asArray()->all();
        foreach ($MethodList as $item) {
            $data[$item['method_id']] = $item['name'];
        }
        return $data;
    }

}