<?php
namespace backendApi\modules\v1\models\exportForms;

use common\libs\export\module\UserExport;
use Yii;
use common\components\Model;
use yii\base\Exception;

class BaseExportForm extends Model
{
    /**
     * @var \common\libs\export\BaseExport
     */
    public $exportObj;

    /**
     * 导出
     * @param $filter
     * @param $listName
     * @param null $consoleRouter
     * @param null $remark
     * 不传值默认导出controller、action和console里面的controller、action一致
     * @return bool
     * @throws \yii\db\Exception
     */
    public function export($filter, $listName, $consoleRouter = null,$remark = null){
        $transaction = \Yii::$app->db->beginTransaction();
        try {
            $this->exportObj->exportHandle($filter, $listName, $consoleRouter,$remark);
            $transaction->commit();
            return true;
        } catch (Exception $e) {
            $transaction->rollBack();
            $this->addError('export', $e->getMessage());
            return false;
        }
    }


}
