<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "order_caiwu_t".
 *
 * @property integer $id
 * @property integer $order_id
 * @property string $money_man
 * @property string $money_no
 * @property string $money_bank
 * @property string $transfer_date
 * @property string $transfer_money
 * @property integer $transfer_bank_id
 * @property string $transfer_bank_no
 * @property string $rate1
 * @property string $money1
 * @property string $rate2
 * @property string $money2
 * @property string $rate3
 * @property string $money3
 * @property string $rate4
 * @property string $money4
 * @property string $rate5
 * @property string $money5
 * @property string $send_rate
 * @property string $send_money
 * @property string $send_price
 * @property integer $status_id
 * @property integer $lock_id
 * @property string $caiwu_no
 * @property string $budian_rate
 * @property string $budian_money
 * @property string $business_back_money
 * @property string $business_back_rate
 * @property string $business_back_routine
 * @property string $business_back_date
 * @property string $force_back_money
 * @property string $force_back_rate
 * @property string $force_back_routine
 * @property string $force_back_date
 * @property integer $caiwu_status_id
 * @property string $remark
 * @property string $pay_date
 * @property string $created_at
 * @property string $updated_at
 */
class OrderCaiwuT extends \common\models\Base
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'order_caiwu_t';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['order_id', 'status_id'], 'required'],
            [['order_id', 'transfer_bank_id', 'status_id', 'lock_id', 'caiwu_status_id'], 'integer'],
            [['transfer_date', 'created_at', 'updated_at'], 'safe'],
            [['transfer_money', 'rate1', 'money1', 'rate2', 'money2', 'rate3', 'money3', 'rate4', 'money4', 'rate5', 'money5', 'send_rate', 'send_money', 'send_price', 'budian_rate', 'budian_money', 'business_back_money', 'business_back_rate', 'business_back_routine', 'force_back_money', 'force_back_rate', 'force_back_routine'], 'number'],
            [['money_man', 'money_no', 'money_bank', 'transfer_bank_no', 'caiwu_no', 'remark','pay_date', 'business_back_date','force_back_date'], 'string', 'max' => 100],
            [['order_id'], 'unique'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'order_id' => 'Order ID',
            'money_man' => 'Money Man',
            'money_no' => 'Money No',
            'money_bank' => 'Money Bank',
            'transfer_date' => 'Transfer Date',
            'transfer_money' => 'Transfer Money',
            'transfer_bank_id' => 'Transfer Bank ID',
            'transfer_bank_no' => 'Transfer Bank No',
            'rate1' => 'Rate1',
            'money1' => 'Money1',
            'rate2' => 'Rate2',
            'money2' => 'Money2',
            'rate3' => 'Rate3',
            'money3' => 'Money3',
            'rate4' => 'Rate4',
            'money4' => 'Money4',
            'rate5' => 'Rate5',
            'money5' => 'Money5',
            'send_rate' => 'Send Rate',
            'send_money' => 'Send Money',
            'send_price' => 'Send Price',
            'status_id' => 'Status ID',
            'lock_id' => 'Lock ID',
            'caiwu_no' => 'Caiwu No',
            'budian_rate' => 'Budian Rate',
            'budian_money' => 'Budian Money',
            'business_back_money' => 'Business Back Money',
            'business_back_rate' => 'Business Back Rate',
            'business_back_routine' => 'Business Back Routine',
            'business_back_date' => 'Business Back Date',
            'force_back_money' => 'Force Back Money',
            'force_back_rate' => 'Force Back Rate',
            'force_back_routine' => 'Force Back Routine',
            'force_back_date' => 'Force Back Date',
            'caiwu_status_id' => 'Caiwu Status ID',
            'remark' => 'Remark',
            'pay_date' => 'Pay Date',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
        ];
    }

    public function getOrder()
    {
        return $this->hasOne(OrderT::className(),['id'=>'order_id']);
    }

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

    public function getBank()
    {
        return $this->hasOne(BankT::className(),['id'=>'transfer_bank_id']);
    }

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

    public function getCaiwuStatus()
    {
        return $this->hasOne(CaiwuStatusT::className(),['id'=>'caiwu_status_id']);
    }

    public function getPay($rate) {
        $pay_money = 0;
        $order_info = $this->order;
        if($rate > 0) {
            $pay_money = round($order_info->total1_clear * $rate/100,2);
        }
        return $pay_money;
    }
    //非车险的钱计算
    public function getNonPay($rate) {
        $pay_money = 0;
        $order_info = $this->order;
        if($rate > 0) {
            $pay_money = round($order_info->non_baofei * $rate/100,2);
        }
        return $pay_money;
    }
}
