<?php
namespace JinDouYun\Controller\Charts;

use App\Tools\ErrorCode;
use JinDouYun\Controller\BaseController;
use JinDouYun\Model\Charts\MCharts;

/**
 * @copyright   Copyright (c) https://www.qianniaovip.com All rights reserved
 * Description: 报表
 * Class Charts
 * @package JinDouYun\Controller\Charts
 */
class Charts extends BaseController
{

    private $objMCharts;

    public function __construct($isCheckAcl = true, $isMustLogin = true, $checkToken = true, $getAreaCode = false, $checkShopToken = true, $checkSupplierToken = true)
    {
        parent::__construct($isCheckAcl, $isMustLogin, $checkToken, $getAreaCode, $checkShopToken, $checkSupplierToken);
        $this->objMCharts = new MCharts($this->onlineUserId,$this->onlineEnterpriseId);
    }

    /**
     * Doc: (des="商品销售报表")
     * User: XMing
     * Date: 2021/3/29
     * Time: 10:49 上午
     * @throws \Exception
     */
    public function goods()
    {
        $params = $this->request->getRawJson();
        if (empty($params)){
            parent::sendOutput("参数为空",ErrorCode::$paramError);
        }
        $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
        $params['limit'] = $pageParams['limit'];
        $params['offset'] = $pageParams['offset'];
        $result = $this->objMCharts->goods($params);
        if(!$result->isSuccess()){
            parent::sendOutput($result->getData(), $result->getErrorCode());
        }
        $returnData = $result->getData();
        $pageData = [
            'pageIndex' => $params['page'],
            'pageSize' => $params['pageSize'],
            'pageTotal' => $returnData['total'],
        ];
        parent::sendOutput($returnData['data'], 0, $pageData);
    }

    /**
     * Doc: (des="客户商品报表")
     * User: XMing
     * Date: 2021/3/29
     * Time: 2:22 下午
     * @throws \Exception
     */
    public function customerGoods()
    {
        $params = $this->request->getRawJson();
        if (empty($params)){
            parent::sendOutput("参数为空",ErrorCode::$paramError);
        }
        $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
        $params['limit'] = $pageParams['limit'];
        $params['offset'] = $pageParams['offset'];
        $result = $this->objMCharts->customerGoods($params);
        if(!$result->isSuccess()){
            parent::sendOutput($result->getData(), $result->getErrorCode());
        }
        $returnData = $result->getData();
        $pageData = [
            'pageIndex' => $params['page'],
            'pageSize' => $params['pageSize'],
            'pageTotal' => $returnData['total'],
        ];
        parent::sendOutput($returnData['data'], 0, $pageData);
    }

    /**
     * Doc: (des="订单数据表表")
     * User: XMing
     * Date: 2021/3/29
     * Time: 3:11 下午
     */
    public function order()
    {
        $params = $this->request->getRawJson();
        if (empty($params)){
            parent::sendOutput("参数为空",ErrorCode::$paramError);
        }
        $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
        $params['limit'] = $pageParams['limit'];
        $params['offset'] = $pageParams['offset'];
        $result = $this->objMCharts->order($params);
        if(!$result->isSuccess()){
            parent::sendOutput($result->getData(), $result->getErrorCode());
        }
        $returnData = $result->getData();
        $pageData = [
            'pageIndex' => $params['page'],
            'pageSize' => $params['pageSize'],
            'pageTotal' => $returnData['total'],
        ];
        parent::sendOutput($returnData['data'], 0, $pageData);
    }

    /**
     * Doc: (des="客户订单报表")
     * User: XMing
     * Date: 2021/3/29
     * Time: 4:01 下午
     * @throws \Exception
     */
    public function customerOrder()
    {
        $params = $this->request->getRawJson();
        if (empty($params)){
            parent::sendOutput("参数为空",ErrorCode::$paramError);
        }
        $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
        $params['limit'] = $pageParams['limit'];
        $params['offset'] = $pageParams['offset'];
        $result = $this->objMCharts->customerOrder($params);
        if(!$result->isSuccess()){
            parent::sendOutput($result->getData(), $result->getErrorCode());
        }
        $returnData = $result->getData();
        $pageData = [
            'pageIndex' => $params['page'],
            'pageSize' => $params['pageSize'],
            'pageTotal' => $returnData['total'],
        ];
        parent::sendOutput($returnData['data'], 0, $pageData);
    }

    /**
     * Doc: (des="业务员订单报表")
     * User: XMing
     * Date: 2021/3/29
     * Time: 4:01 下午
     * @throws \Exception
     */
    public function salesManOrder()
    {
        $params = $this->request->getRawJson();
        if (empty($params)){
            parent::sendOutput("参数为空",ErrorCode::$paramError);
        }
        $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
        $params['limit'] = $pageParams['limit'];
        $params['offset'] = $pageParams['offset'];
        $result = $this->objMCharts->salesManOrder($params);
        if(!$result->isSuccess()){
            parent::sendOutput($result->getData(), $result->getErrorCode());
        }
        $returnData = $result->getData();
        $pageData = [
            'pageIndex' => $params['page'],
            'pageSize' => $params['pageSize'],
            'pageTotal' => $returnData['total'],
        ];
        parent::sendOutput($returnData['data'], 0, $pageData);
    }

    /**
     * Doc: (des="地区订单报表")
     * User: XMing
     * Date: 2021/3/30
     * Time: 10:08 上午
     * @throws \Exception
     */
    public function areaOrder()
    {
        $params = $this->request->getRawJson();
        if (empty($params)){
            parent::sendOutput("参数为空",ErrorCode::$paramError);
        }
        $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
        $params['limit'] = $pageParams['limit'];
        $params['offset'] = $pageParams['offset'];
        $result = $this->objMCharts->areaOrder($params);
        if(!$result->isSuccess()){
            parent::sendOutput($result->getData(), $result->getErrorCode());
        }
        $returnData = $result->getData();
        $pageData = [
            'pageIndex' => $params['page'],
            'pageSize' => $params['pageSize'],
            'pageTotal' => $returnData['total'],
        ];
        parent::sendOutput($returnData['data'], 0, $pageData);
    }

}