ConcurrentController.class.php 2.08 KB
<?php
/**
 * User: zoulongbo
 * Date: 2018/7/26
 * Time: 11:18
 */

namespace Apicp\Controller\Export;

use Com\PythonExcel;
use Common\Common\ExportDownload;
use Common\Common\Vhall;

class ConcurrentController extends AbstractController
{
    public function Index_post()
    {
        $params = I('post.');

        if (!$params) {
            E('_ERR_PARAMS_CAN_NOT_EMPTY');
        }

        $params['orderList'] = [
            [
                "column" => "onTime",
                "orderType" => "DESC"
            ]
        ];

        // 获取当前直播数据全部列表
        $concurrentTotals = Vhall::instance()->concurrencyNum($params);

        $this->_download($concurrentTotals, $params);

        return true;
    }


    /**
     * 导出模板
     * @param array $watchTotals 详情
     * @param array $params 请求参数
     * @return bool
     */
    private function _download($concurrentTotals = [], $params = [])
    {
        // 初始化导出数据
        $file_name = '';
        $row_data = [];


        $file_name = $params['title'] . '_并发数' . date('_YmdHi');
        $title = [
            '直播名称',
            '时间点',
            '人数',
        ];

        //组装直播用户数据,添加title
        foreach ($concurrentTotals as $key => $value) {

            $row_data[] = [
                $params['title'],
                rgmdate($value['onTime'], 'Y-m-d H:i'),
                $value['onNum'],
            ];
        }

        // Python导出excel
        $realpath = ExportDownload::get_down_dir($this->_login->user['eaId'] . microtime(true)) . $file_name . ".xls";
        $ret = PythonExcel::instance()->write($realpath, $title, $row_data);
        if ($ret) {

            $conditon = [
                'title' => $file_name,
                'ea_id' => $this->_login->user['eaId'],
                'username' => $this->_login->user['eaRealname'],
                'type' => ExportDownload::EXCEL_TYPE,
                'url' => $realpath
            ];

            ExportDownload::insert_down_load($conditon);
        }

        return true;
    }

}