DeleteController.class.php 1.28 KB
<?php
/**
 * 【下载中心-后台】批量删除文件
 * @author: heyuelong
 * @email:  271608475@qq.com
 * @date :  2018年4月18日11:12:18
 * @version $Id$
 */

namespace Apicp\Controller\Down;

use Common\Common\ExportDownload;
use Common\Service\DownloadService;

class DeleteController extends \Apicp\Controller\AbstractController
{

    public function Index_post()
    {
        $params = I('post.');

        // 获取传递的ID集合
        $ids = array_column($params['ids'], 'id');

        // 如果IDS为空
        if (empty($ids)) {
            E('_EMPTY_DOWNLOAD_ID');
        }

        // 实例化DownLoadService
        $service = new DownloadService();

        // 组装查询条件
        $conds = [
            'id' => $ids,
            'ea_id' => $this->_login->user['eaId']
        ];

        // 未生成文件状态
        $wait_status = ['file_status' => ExportDownload::FILE_STATUS_FALSE];

        // 合并数据
        $condition = array_merge($conds, $wait_status);

        // 查询是否存在为生成文件
        $total = $service->count_by_conds($condition);

        if ($total) {
            E('_ERR_NOT_MAKE_FILE_ID');
        }

        // 删除下载
        $service->delete_by_conds($conds);

        $this->_result = [];

        return true;
    }
}