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

namespace home\modules\contract\models;

use Yii;

/**
 * This is the model class for table "qc_collate_log".
 *
 * 信息核对记录
 *
 * @property string $link_type  (类型)
 * @property string $link_id  (编号)
 * @property integer $user_id  (核对人)
 * @property string $ip  (核对人IP)
 * @property integer $collate_time  (核对时间)
 * @property string $collate_info  (核对信息)
 * @property string $remark  (备注)
 *
 * @author HuLimin http://blog.u-bo.com
 * @since 0.1
 */
class CollateLog extends \yii\db\ActiveRecord
{

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

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'collate_time'], 'integer'],
            [['link_type', 'link_id'], 'string', 'max' => 64],
            [['ip'], 'string', 'max' => 15],
            [['collate_info', 'remark'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'link_type' => '类型',
            'link_id' => '编号',
            'user_id' => '核对人IP',
            'collate_time' => '核对时间',
            'collate_info' => '核对信息',
            'remark' => '备注',
        ];
    }

    /**
     * 核对记录
     *
     * @param string $linkType  类型
     * @param string $linkId    编号
     * @param string $collateInfo 信息
     * @param string $remark    备注
     */
    public function CollateLog($linkType = '', $linkId = '', $collateInfo = '', $remark = '')
    {
        if (empty($linkType) && empty($linkId)) {
            return FALSE;
        }
        $model = new CollateLog();
        $model->link_type = trim($linkType);
        $model->link_id = trim($linkId);
        $model->user_id = Yii::$app->user->id;
        $model->ip = Yii::$app->getRequest()->getUserIP();
        $model->collate_info = trim($collateInfo);
        $model->remark = trim($remark);
        if ($model->validate() && $model->save()) {
            return TRUE;
        } else {
            return FALSE;
        }
    }
}