ImportLogic.php 1.4 KB
<?php

namespace App\Http\Logic\Bside\Import;

use App\Http\Logic\Bside\BaseLogic;
use App\Models\Import\ImportTask;


class ImportLogic extends BaseLogic
{
    public function __construct()
    {
        parent::__construct();
        $this->param = $this->requestAll;
        $this->model = new ImportTask();
    }

    /**
     * 新增导入任务
     * @return array
     * @throws \App\Exceptions\AsideGlobalException
     * @throws \App\Exceptions\BsideGlobalException
     * @author Akun
     * @date 2023/09/20 11:17
     */
    public function addImportTask()
    {
        $ext = explode('.', $this->param['file_url']);
        if (end($ext) != 'csv') {
            $this->fail('导入文件格式必须为csv');
        }
        $domain = $this->param['domain'];
        if (strpos($domain, 'https') === false && strpos($domain, 'http') == false) {
            $this->fail('请输入完整的采集页面地址');
        }
        $domain_arr = parse_url($domain);
        if (!isset($domain_arr['host'])) {
            $this->fail('采集页面地址输入有误');
        }

        $this->param['domain'] = $domain_arr['host'];
        $this->param['project_id'] = $this->user['project_id'];
        $this->param['user_id'] = $this->user['id'];
        $rs = $this->model->add($this->param);
        if ($rs === false) {
            $this->fail('error');
        }
        return $this->success();
    }
}