<?php
/**
 * 分销体现记录Model
 * Created by PhpStorm.
 * User: phperstar
 * Date: 2020/07/22
 * Time: 15:00
 */
namespace JinDouYun\Controller\Commission;

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

use JinDouYun\Controller\BaseController;

use JinDouYun\Model\Commission\MCommissionWithdrawals;

class CommissionWithdrawals extends BaseController
{
    private $objMCommissionWithdrawals;

    public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken = true)
    {
        parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
        $this->objMCommissionWithdrawals = new MCommissionWithdrawals($this->onlineUserId, $this->onlineEnterpriseId);
    }

    /**
     * 获取所有的提现记录
     */
    public function getAll()
    {
        $paramsData = $this->request->getRawJson();

        $selectParams = [
            'page'     => isset($paramsData['page']) ? $paramsData['page'] : 1,
            'pageSize' => isset($paramsData['pageSize']) ? $paramsData['pageSize'] : 10,
            'keyword'  => isset($paramsData['keyword']) ? $paramsData['keyword'] : 0,
            'grade'    => isset($paramsData['grade']) ? $paramsData['grade'] : 0,
            'type'     => isset($paramsData['type']) ? $paramsData['type'] : 0,
            'startTime' => isset($paramsData['startTime']) ? $paramsData['startTime'] : 0,
            'endTime' => isset($paramsData['endTime']) ? $paramsData['endTime'] : 0,
            'auditStatus' => isset($paramsData['auditStatus']) ? $paramsData['auditStatus'] : '',
        ];

        $pageParams = pageToOffset($selectParams['page'], $selectParams['pageSize']);
        $selectParams['limit'] = $pageParams['limit'];
        $selectParams['offset'] = $pageParams['offset'];

        $result = $this->objMCommissionWithdrawals->getAll($selectParams);

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

    /**
     * 修改提现记录状态
     */
    public function updateAuditStatus()
    {
        $id = $this->request->param('request_id');
        if (!$id) {
            parent::sendOutput('请指定要审核的数据id', ErrorCode::$paramError);
        }

        $status = $this->request->param('status');
        if(!$status){
            parent::sendOutput('请指定要修改的状态', ErrorCode::$paramError);
        }

        $result = $this->objMCommissionWithdrawals->updateAuditStatus($id,$status);
        if ($result->isSuccess()) {
            parent::sendOutput($result->getData());
        } else {
            parent::sendOutput($result->getData(), ErrorCode::$dberror);
        }
    }
}