<?php
/**
 * Created by PhpStorm.
 * User: Gss
 * Date: 2021/5/19 0019
 * Time: 10:53
 */

namespace JinDouYun\Controller\Order;

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

use JinDouYun\Controller\BaseController;

use JinDouYun\Model\Order\MOrderPicking;

class OrderPicking extends BaseController
{
    private $objMOrderPincking;


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

    //重写订单列表
    public function getAllOrderPicking()
    {
        $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'];
        //根据订单编号查找商品
        $selectParams['no'] = getArrayItem($params, 'no','');
        if( isset($selectParams['no']) || !empty($selectParams['no']) ){
            $tmpSelectParams['no'] = explode('-',$selectParams['no']);
            if(count($tmpSelectParams['no'])==3){
                $selectParams['no'] = $tmpSelectParams['no'][1].'-'.$tmpSelectParams['no'][2];
            }
        }
        $selectParams['timeName'] = getArrayItem($params,'timeName',''); //时间判断
        $selectParams['startTime'] = getArrayItem($params, 'startTime','');
        $selectParams['endTime'] = getArrayItem($params, 'endTime','');

        $result = $this->objMOrderPincking->getAllOrderPicking($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());
        }
    }


    //订单拣货详情
    public function getOrderPickingInfo()
    {
        $pickingId  = $this->request->param('request_id');
        if(empty($pickingId)){
            $this->sendOutput('参数错误', ErrorCode::$paramError);
        }

        $result = $this->objMOrderPincking->getOrderPickingInfo($pickingId);

        if ($result->isSuccess()) {
            $this->sendOutput($result->getData());
        } else {
            $this->sendOutput($result->getData(), $result->getErrorCode());
        }
    }

    /**
     * 待拣货明细
     */
    public function getAllPickingGoodsDetail()
    {
        $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'];
        //根据订单编号查找商品
        $selectParams['no'] = getArrayItem($params, 'no','');
        $selectParams['goodsName'] = getArrayItem($params, 'goodsName','');
        $selectParams['operatorId'] = getArrayItem($params, 'operatorId','');
        $selectParams['start'] = getArrayItem($params, 'start','');
        $selectParams['end'] = getArrayItem($params, 'end','');

        $result = $this->objMOrderPincking->getAllPickingGoodsDetail($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());
        }
    }

}