<?php
namespace app\adminapi\controller\master_worker;

use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\master_commission\MasterWorkerCommissionNoticeLists;
use app\adminapi\lists\master_worker\MasterWorkerServiceOrderLists;
use app\adminapi\logic\export\ExportLogic;
use app\common\service\ExcelExportService;

/**
 * MasterWorkerServiceOrder控制器
 * Class MasterWorkerServiceOrderController
 * @package app\adminapi\controller
 */
class MasterWorkerServiceOrderController extends BaseAdminController
{
    /**
     * @notes 获取列表
     */
    public function lists()
    {
        return $this->dataLists(new MasterWorkerServiceOrderLists());
    }
    public function download()
    {
        $params = $this->request->get();
        $tmp_filename = '';
        if($params['start_time'] && $params['end_time']) $tmp_filename = date('Y-m-d',strtotime($params['start_time']))."-至-".date('Y-m-d',strtotime($params['end_time']));
        $filename = $tmp_filename."工单统计";
        $result = ExportLogic::add([
            'download_type' => 2,
            'params' => $params,
            'name' => $filename,
            'admin_id' => $this->adminId,
        ]);
        if (false === $result) {
            return $this->fail(ExportLogic::getError());
        }
        // 暂时 - 立即生成导出文件
        (new ExcelExportService)->download($result);
        return $this->success('添加成功-'.$result, [], 1, 1);
    }

    public function freeNotice()
    {
        return $this->dataLists(new MasterWorkerCommissionNoticeLists());
    }


}