<?php
/**
 * 账户明细管理模块
 * Created by PhpStorm.
 * User: tpl
 * Date: 2019/10/30
 * Time: 13:54
 */
namespace JinDouYun\Controller\Finance;

use Mall\Framework\Core\ErrorCode;
use Mall\Framework\Core\StatusCode;

use JinDouYun\Controller\BaseController;
use JinDouYun\Model\Finance\MAccountDetail;

class AccountDetail extends BaseController
{
    private $objMAccountDetail;

    public function __construct($isCheckAcl = true, $isMustLogin = true)
    {
        parent::__construct($isCheckAcl, $isMustLogin);
        $this->objMAccountDetail = new MAccountDetail($this->onlineEnterpriseId, $this->onlineUserId);
    }

    /**
     * 后台所有账户明细列表
     */
    public function getAllAccountDetail()
    {
        $params = $this->request->getRawJson();
        if( empty($params) ){
            $this->sendOutput('参数为空', ErrorCode::$paramError );
        }

        $selectParams = [
            'accountId' => isset($params['accountId']) ? $params['accountId'] : '',
        ];

        foreach ($selectParams as $key => $value) {
            if (empty($value) && $value !== 0) {
                $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
            }
        }

        $selectParams['shopId'] = !empty($params['shopId']) ? $params['shopId'] : 0;
        $selectParams['start'] = !empty($params['start']) ? $params['start'] : 0;
        $selectParams['end'] = !empty($params['end']) ? $params['end'] : time();

        $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
        $selectParams['limit'] = $pageParams['limit'];
        $selectParams['offset'] = $pageParams['offset'];
        $result = $this->objMAccountDetail->getAllAccountDetail($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(), $result->getErrorCode());
        }
    }
}