<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "order_t".
 *
 * @property integer $id
 * @property integer $car_id
 * @property integer $user_id
 * @property string $car_no
 * @property string $engine_no
 * @property string $car_frame_no
 * @property string $car_man
 * @property string $gift_other
 * @property integer $company_id
 * @property integer $status_id
 * @property string $submit_date
 * @property string $id_man
 * @property string $id_number
 * @property string $link_man
 * @property string $link_phone
 * @property string $insurer1_begin_date
 * @property string $insurer1_end_date
 * @property string $insurer2_begin_date
 * @property string $insurer2_end_date
 * @property string $send_date
 * @property string $direction1_id
 * @property string $range1_id
 * @property string $city1_id
 * @property string $district1_id
 * @property string $send_address1
 * @property string $direction2_id
 * @property string $range2_id
 * @property string $city2_id
 * @property string $district2_id
 * @property string $send_address2
 * @property integer $pay_type_id
 * @property string $pay_no
 * @property string $remark
 * @property string $total1
 * @property string $total1_clear
 * @property string $total1_real
 * @property string $total1_dis
 * @property string $total1_percent
 * @property string $total1_rate
 * @property string $total2
 * @property string $total2_clear
 * @property string $total2_rate
 * @property string $total3
 * @property string $total_all
 * @property string $total_real
 * @property string $price_remark
 * @property string $insurer1_no
 * @property string $insurer2_no
 * @property string $identifying_code
 * @property integer $lock_id
 * @property string $money_man
 * @property string $money_no
 * @property string $money_bank
 * @property string $email
 * @property integer $success_id
 * @property integer $return_status_id
 * @property integer $return_time
 * @property string $return_remark
 * @property string $print_date
 * @property string $piao_header
 * @property integer $first_send
 * @property integer $send_times
 * @property integer $check_gift
 * @property string $created_at
 * @property string $updated_at
 */
class Order2T extends \common\models\Base
{
    public static function getDb()
    {
        // use the "db2" application component
        return \Yii::$app->db3;
    }
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'order_t';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['car_id', 'user_id', 'company_id', 'status_id', 'pay_type_id','lock_id','direction1_id','range1_id','city1_id','district1_id','direction2_id','range2_id','city2_id','district2_id','success_id','return_status_id','return_time','first_send','send_times','check_gift'], 'integer'],
            [['submit_date', 'insurer1_begin_date', 'insurer1_end_date', 'insurer2_begin_date', 'insurer2_end_date', 'send_date','print_date', 'created_at', 'updated_at'], 'safe'],
            [['gift_other', 'id_man', 'id_number', 'link_man', 'send_address1','send_address2','car_frame_no','car_man','total1','total1_clear','total1_real','total1_dis','total1_percent','total1_rate','total2','total2_clear','total2_rate','total3','total_all','total_real','price_remark','money_no','money_bank','email','return_remark','piao_header'], 'string', 'max' => 100],
            [['link_phone','car_no','engine_no','pay_no','insurer1_no','insurer2_no','identifying_code','money_man'], 'string', 'max' => 50],
            [['remark'], 'string', 'max' => 200],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'car_id' => 'Car ID',
            'user_id' => 'User ID',
            'car_no' => 'Car No',
            'engine_no' => 'Engine No',
            'car_frame_no' => 'Car Frame No',
            'car_man' => 'Car Man',
            'gift_other' => 'Gift Other',
            'company_id' => 'Company ID',
            'status_id' => 'Status ID',
            'submit_date' => 'Submit Date',
            'id_man' => 'Id Man',
            'id_number' => 'Id Number',
            'link_man' => 'Link Man',
            'link_phone' => 'Link Phone',
            'insurer1_begin_date' => 'Insurer1 Begin Date',
            'insurer1_end_date' => 'Insurer1 End Date',
            'insurer2_begin_date' => 'Insurer2 Begin Date',
            'insurer2_end_date' => 'Insurer2 End Date',
            'send_date' => 'Send Date',
            'direction1_id' => 'Direction 1 ID',
            'range1_id' => 'Range 1 ID',
            'city1_id' => 'City 1 ID',
            'district1_id' => 'District 1 ID',
            'send_address1' => 'Send Address 1',
            'direction2_id' => 'Direction 2 ID',
            'range2_id' => 'Range 2 ID',
            'city2_id' => 'City 2 ID',
            'district2_id' => 'District 2 ID',
            'send_address2' => 'Send Address 2',
            'pay_type_id' => 'Pay Type ID',
            'pay_no' => 'Pay No',
            'remark' => 'Remark',
            'total1' => 'Total 1',
            'total1_clear' => 'Total 1 Clear',
            'total1_real' => 'Total 1 Real',
            'total1_dis' => 'Total 1 Dis',
            'total1_percent' => 'Total 1 Percent',
            'total1_rate' => 'Total 1 Rate',
            'total2' => 'Total 2',
            'total2_clear' => 'Total 2 Clear',
            'total2_rate' => 'Total 2 Rate',
            'total3' => 'Total 3',
            'total_all' => 'Total all',
            'total_real' => 'Total Real',
            'price_remark' => 'Price Remark',
            'lock_id' => 'Lock ID',
            'insurer1_no' => 'Insurer 1 No',
            'insurer2_no' => 'Insurer 2 No',
            'identifying_code' => 'Identifying Code',
            'money_man' => 'Money Man',
            'money_no' => 'Money No',
            'money_bank' => 'Money Bank',
            'email' => 'email',
            'success_id' => 'Success ID',
            'return_status_id' => 'Return Status ID',
            'return_time' => 'Return Time',
            'return_remark' => 'Return Remark',
            'print_date' => 'Print Date',
            'piao_header' => 'Piao Header',
            'first_send' => 'First Send',
            'send_times' => 'Send Times',
            'check_gift' => 'Check Gift',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
        ];
    }

    public function getUser()
    {
        return $this->hasOne(UserT::className(),['id'=>'user_id']);
    }

    public function getLock()
    {
        return $this->hasOne(UserT::className(),['id'=>'lock_id']);
    }

    public function getPayType()
    {
        return $this->hasOne(PayTypeT::className(),['id'=>'pay_type_id']);
    }

    public function getCar()
    {
        return $this->hasOne(CarT::className(),['id'=>'car_id']);
    }

    public function getStatus()
    {
        return $this->hasOne(StatusT::className(),['id'=>'status_id']);
    }

    public function getCompany()
    {
        return $this->hasOne(InsurerCompanyT::className(),['id'=>'company_id']);
    }

    public function getPrices()
    {
        return $this->hasMany(PriceT::className(),['order_id'=>'id']);
    }

    public function getRange1()
    {
        return $this->hasOne(RangeT::className(),['id'=>'range1_id']);
    }

    public function getDirection1()
    {
        return $this->hasOne(DirectionT::className(),['id'=>'direction1_id']);
    }

    public function getCity1()
    {
        return $this->hasOne(CityT::className(),['id'=>'city1_id']);
    }

    public function getDistrict1()
    {
        return $this->hasOne(DistrictT::className(),['id'=>'district1_id']);
    }

    public function getRange2()
    {
        return $this->hasOne(RangeT::className(),['id'=>'range2_id']);
    }

    public function getDirection2()
    {
        return $this->hasOne(DirectionT::className(),['id'=>'direction2_id']);
    }

    public function getCity2()
    {
        return $this->hasOne(CityT::className(),['id'=>'city2_id']);
    }

    public function getDistrict2()
    {
        return $this->hasOne(DistrictT::className(),['id'=>'district2_id']);
    }

    public function getGifts()
    {
        return $this->hasMany(GiftT::className(),['id'=>'gift_id'])
            ->viaTable('car_gift_t',['order_id'=>'id']);
    }
}
