/**
        * @brief 根据用户id加号订单列表
        * @author whd
        * @exampleUrl http://dev.mobile-api.haodf.com/patientapi/booking_getBookingOrderList?userId=581662815&pageId=1&pageSize=10&xdoc=1
        *
        * @Param $userId 用户id
        * @Param $pageId 当前页码
        * @Param $pageSize 每页显示数
        *
        * @Returns array('id', 'sn', 'statusDesc', 'spaceId', 'doctorName', 'hospitalName', 'hospitalFacultyName', 'schedule', 'alertMsg', 'confirmTime', 'isCallBack');
     */
    public function getBookingOrderList($userId, $pageId, $pageSize)
    {/*{{{*/
    	$user = DAL::get()->find('user', $userId);
        if ($user->isNull())
        {
            $this->setErrorCode(107);
            return 0;
        }
    	$this->_initPageInfo($pageId, $pageSize);
    	$postInfos = array();
		$pageInfo['pages'] = 1; 
		$pageInfo['total'] = 0;

        $statusType = BookingDto::QUERY_STATUS_ALL;
        $tmpAllBookingList = BookingDto::getList4UserMobile($user, $statusType);
        $allBookingList = array();
        foreach ($tmpAllBookingList as $tmpBooking)
        {
            if ($tmpBooking->space instanceof Space)
            {
                $allBookingList[] = $tmpBooking;
            }
        }
        $pageInfo['nowpage'] = $pageId; 
        $pageInfo['pagesize'] = $pageSize;
		$pageInfo['pages'] = (int)ceil(count($allBookingList)/$pageSize); 
		$pageInfo['total'] = count($allBookingList);
		$bookingList = array_slice($allBookingList, ($pageInfo['nowpage']-1)*$pageSize, $pageSize);

        $infos = array();
        foreach($bookingList as $booking) 
        { 
            $info['id'] = $booking->id; 
            $info['sn'] = $booking->id; 
            if ($booking instanceof Intention)
            {
                $info['schedule'] = strtotime(BingLiDtoHelper::create($booking)->getLastSchedule());
            }
            else
            {
                $info['schedule'] = strtotime($booking->getSchedule());
                $booking = DAL::get()->find('proposal', $booking->id);
            }
            $info['schedule'] = ($info['schedule']) ? date('Y-m-d H:i', $info['schedule']) : '';
            $info['alertMsg'] = '';
            if ($booking->space instanceof Space)
            {
                $info['spaceId'] = $booking->space->id;
                $info['doctorName'] = $booking->space->host->name;
                $info['hospitalName'] = $booking->space->host->hospitalfaculty->hospital->commonName;
                $info['hospitalFacultyName'] = $booking->space->host->hospitalfaculty->name;
            }
            else
            {
                continue;
            }
            $status = $this->getBookingOrderStatus4User($booking);
            $info['statusDesc'] = self::$BookingStatusMap[$status];
            if ($booking instanceof Proposal && $booking->isPending())
            {
                $info['statusDesc'] = "联系管理员";
            }
            $info['confirmTime'] = $info['confirmFromTime'] = $info['confirmEndTime'] = ''; 
            if ($status == self::BOOKING_SUCCESS || $status == self::BOOKING_APPLY_SUCCESS)
            {
                $before1Schedule = XDateTime::valueOf($info['schedule'])->addDay(-1)->setHour("16")->setMinute("00");
                $before2Schedule = XDateTime::valueOf($info['schedule'])->addDay(-2)->setHour("20")->setMinute("00");
                $info['confirmTime'] = date('Y-m-d H:i', strtotime($before2Schedule)).'至'.date('Y-m-d H:i', strtotime($before1Schedule)).'前领取';
                $info['confirmFromTime'] = date('Y-m-d H:i', strtotime($before2Schedule));
                $info['confirmEndTime'] = date('Y-m-d H:i', strtotime($before1Schedule));
            }
            $info['isCallBack'] = ($status == self::BOOKING_WAIT_CALLBACK) ? 1 : 0;
            $infos[] = $info;
        } 
		$this->pageInfo = $pageInfo;
    	$this->content = $infos;
    }/*}}}*/
    public function getBookingOrderListByUserId($userId, $status = 0, $pageId, $pageSize)
    {/*{{{*/
    	$user = DAL::get()->find('user', $userId);
        if ($user->isNull())
        {
            $this->setErrorCode(107);
            return 0;
        }
    	$this->_initPageInfo($pageId, $pageSize);
    	$postInfos = array();
		$pageInfo['pages'] = 1; 
		$pageInfo['total'] = 0;

        $statusType = BookingDto::QUERY_STATUS_ALL;
        if ($status == 1)
        {
            $statusType = BookingDto::QUERY_STATUS_VALID;
        } 
        else if ($status == 2)
        {
            $statusType = BookingDto::QUERY_STATUS_INVALID;
        }
        $bookingList = BookingDto::getList4UserMobile($user, $statusType);

        $orders = array();
        foreach($bookingList as $booking) 
        { 
            if ($booking instanceof Intention)
            {
                $order['schedule'] = strtotime(BingLiDtoHelper::create($booking)->schedule->last()->schedule);
            }
            else
            {
                $order['schedule'] = strtotime($booking->getSchedule());
                $booking = DAL::get()->find('proposal', $booking->id);
            }
            $order['id'] = $booking->id; 
            $order['doctorName'] = $booking->space->host->name."(".$booking->space->host->hospitalfaculty->hospital->commonName.$booking->space->host->hospitalfaculty->name.")"; 
            $order['status'] = $this->getBookingOrderStatus4User($booking);
            $isCallBack = 0;
            if ($booking instanceof Proposal)
            {
                $bookingProposal = BookingDto::createByProposalId($booking->id);
                if ($bookingProposal->execution instanceof BookingOrder)
                {
                    $isCallBack = ($bookingProposal->execution->isCallBack()) ? 1 : 0;
                }
            }
            $order['isCallBack'] = $isCallBack;
            $orders[] = $order;
        } 
        $pageInfo['nowpage'] = $pageId; $pageInfo['pagesize'] = $pageSize;
		$pageInfo['pages'] = (int)ceil(count($orders)/$pageSize); 
		$pageInfo['total'] = count($orders);
		$bookingOrderInfos = array_slice($orders, ($pageInfo['nowpage']-1)*$pageSize, $pageSize);

		$this->pageInfo = $pageInfo;
    	$this->content = $bookingOrderInfos;
    }/*}}}*/