<?php
/**
 * 商品基础信息管理
 * Created by PhpStorm.
 * User: XiaoMing
 * Date: 2019/10/30
 * Time: 14:17
 */

namespace JinDouYun\Controller\Log;

use Mall\Framework\Core\ErrorCode;
use JinDouYun\Controller\BaseController;

use JinDouYun\Model\Log\MLoginLog;

class LoginLog extends BaseController
{
    private $objMLoginLog;

    /**
     * GoodsBasic constructor.
     * @param bool $isCheckAcl
     * @param bool $isMustLogin
     * @param bool $checkToken
     * @throws \Exception
     */
    public function __construct($isCheckAcl = true, $isMustLogin = true, $checkToken=true)
    {
        parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
        $this->objMLoginLog = new MLoginLog($this->onlineEnterpriseId);
    }

    /**
     * 获取全部日志
     * @throws \Exception
     */
    public function getAllLog()
    {
        $params = $this->request->getRawJson();
        if( empty($params) ){
            $this->sendOutput('参数为空', ErrorCode::$paramError );
        }

        $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
        $selectParams['limit'] = $pageParams['limit'];
        $selectParams['offset'] = $pageParams['offset'];

        $result = $this->objMLoginLog->getAllLoginLog($selectParams);

        if ($result->isSuccess()) {
            $returnData = $result->getData();
            $pageData = [
                'pageIndex' => $params['page'],
                'pageSize'  => $params['pageSize'],
                'pageTotal' => $returnData['total'],
            ];
            parent::sendOutput($returnData['data'], 0, $pageData);
        } else {
            parent::sendOutput($result->getData(), ErrorCode::$dberror);
        }
    }

}