/** * initQuery * * @return void */ public function initQuery() { $pager = $query = array(); $pager['qnty'] = (int) $this->input('qnty', 'numeric'); empty($pager['qnty']) and $pager['qnty'] = 30; $pager['qnty'] = $query['qnty'] = min($pager['qnty'], 30); $pager['page'] = (int) $this->input('page', 'numeric'); empty($pager['page']) and $pager['page'] = 1; $query['bdate'] = $this->input('bdate', 'string'); Zyon_Util::isDate($query['bdate']) or $query['bdate'] = null; $query['edate'] = $this->input('edate', 'string'); Zyon_Util::isDate($query['edate']) or $query['edate'] = null; if ($query['bdate'] && $query['edate']) { $btime = strtotime($query['bdate']); $etime = strtotime($query['edate']); if ($etime < $btime) { $this->flash(0, '查询时间范围错误'); } } $pager['args'] = $query; $this->view->query = $query; $this->view->pager = $pager; }
/** * calYuDingLiang * 计算某一时段的预订量,以渠道分组 * * @param int $hid * @param date $bdate * @param date $edate * @return array */ public function calYuDingLiang($hid, $bdate, $edate) { if (!Zyon_Util::isUnsignedInt($hid) || !Zyon_Util::isDate($bdate) || !Zyon_Util::isDate($edate)) { return false; } $btime = strtotime($bdate) + 86399; $etime = strtotime($edate) + 86400; if ($etime <= $btime) { return false; } try { $sql = $this->dbase()->select()->from($this->tname('order'), 'o_cid, SUM(DATEDIFF(FROM_UNIXTIME(LEAST(o_etime, :etime)), FROM_UNIXTIME(GREATEST(o_btime, :btime))))')->where('o_hid = :hid')->where('NOT (o_btime >= :etime OR o_etime <= :btime)')->where(sprintf('o_status IN (%s, %s)', $this->quote(ORDER_STATUS_YD), $this->quote(ORDER_STATUS_BL)))->group('o_cid'); return $this->dbase()->fetchPairs($sql, array('hid' => $hid, 'btime' => $btime, 'etime' => $etime)); } catch (Exception $e) { $this->log($e); return false; } }
/** * fetchOrderPrice * * @param mixed $value * @param mixed $bdate * @param mixed $edate * @return array */ public function fetchOrderPrice($value, $bdate, $edate) { if (!Zyon_Util::isDate($bdate) || !Zyon_Util::isDate($edate)) { $this->flash(0, '订单日期错误'); } if (empty($value) || !is_array($value)) { $this->flash(0, '房费参数错误'); } $btime = strtotime($bdate); $etime = strtotime($edate) - 86400; $count = 0; while ($btime <= $etime) { if (!isset($value[$btime])) { $this->flash(0, date('Y-m-d', $btime) . '房费未定义'); } if (!Zyon_Util::isMoneyFloat($value[$btime])) { $this->flash(0, date('Y-m-d', $btime) . '房费参数错误'); } $value[$btime] = $value[$btime] * 100; if ($value[$btime] < 0) { $this->flash(0, date('Y-m-d', $btime) . '房费值太小,必须至少大于0'); } if ($value[$btime] >= 10000000) { $this->flash(0, date('Y-m-d', $btime) . '房费值太大,必须小于100000'); } $count += 1; $btime += 86400; } if ($count !== count($value)) { $this->flash(0, '房费参数错误'); } return $value; }
/** * calLiveNumByDay * * @param date $date * @return int */ public function calLiveNumByDateAndRids($date, $rids) { if (!Zyon_Util::isDate($date)) { return false; } $time = strtotime($date) + 86399; try { $sql = $this->dbase()->select()->from($this->tname('order'), 'count(o_id)')->where("o_itime <= :dtm AND (o_status = :sta OR o_otime > :dtm)"); $rids and $sql->where(sprintf("o_rid IN (%s)", is_string($rids) ? $rids : implode(',', $rids))); return $this->dbase()->fetchOne($sql, array('dtm' => $time, 'sta' => ORDER_STATUS_ZZ)); } catch (Exception $e) { $this->log($e); return false; } }
/** * fetchBillPaid * * @param string $input * @param int $total * @return array */ public function fetchBillPaid($input, &$total) { /** * 处理账单已收 */ $bill = $this->input($input, 'array'); if (empty($bill)) { $this->flash(0, '已收款项错误'); } empty($total) and $total = 0; $froms = Zyon_Array::keyto($this->model('hotel.payment')->getUsablePaymentAryByHid($this->_hostel['h_id']), 'hp_id'); empty($froms) and $froms = array(); foreach ($bill as $key => $val) { if (!is_array($val) || !isset($val['qnty']) || !is_string($val['qnty']) || trim($val['qnty']) == '') { unset($bill[$key]); continue; } if (!Zyon_Util::isUnsignedInt($val['from']) || !Zyon_Util::isMoneyFloat($val['qnty']) || $val['qnty'] < 0 || !Zyon_Util::isDate($val['date']) || !isset($val['memo']) || !is_string($val['memo'])) { $this->flash(0, '已收款项错误'); } if (!array_key_exists($val['from'], $froms)) { $this->flash(0, '已收款项渠道错误'); } $val['qnty'] = (empty($val['oper']) ? $val['qnty'] : -$val['qnty']) * 100; $val['memo'] = trim($val['memo']); if (mb_strlen($val['memo']) > 200) { $this->flash(0, '备注内容不能超过200个字符'); } $total += (int) $val['qnty']; if ($total >= 10000000) { $this->flash(0, '已收总金额超出系统限制,必须小于100000'); } if ($total <= -10000000) { $this->flash(0, '已收总金额超出系统限制,必须大于-100000'); } $bill[$key] = $this->model('bill.journal')->getNewJournal(0, $this->_hostel['h_id'], $this->_master['u_id'], $val['from'], $val['qnty'], strtotime($val['date']), $this->_master['u_realname'], $froms[$val['from']]['hp_name'], $val['memo']); } $total = (string) $total; if (empty($bill)) { $this->flash(0, '没有可用的已收款项记录'); } return array_values($bill); }
/** * 旅店房态 */ public function indexAction() { $this->checkHotelStat($hotel = $this->loadUsableHotel($this->input('hid'))); if ((!$this->_master || $this->_master['u_hid'] !== $hotel['h_id']) && !(SYSTEM_GROUPS_GSER & (int) $hotel['h_rosta_visible'])) { $this->flash(0, '旅店尚未开放该功能'); } $rosta = array('time' => time(), 'line' => array(), 'room' => array(), 'data' => array()); $date = $this->input('date'); $lgth = $this->input('lgth'); $time = strtotime(Zyon_Util::isDate($date) ? $date : ($date = date('Y-m-d', $rosta['time']))); if (!Zyon_Util::isInt($lgth)) { $lgth = 8; } $lgth = (int) $lgth; if (abs($lgth) > 30 || abs($lgth) < 2) { $this->flash(0, '入住时间和离店时间间隔最少 2天,最长 30天'); } $lgth = $lgth > 0 ? $lgth - 1 : $lgth + 1; // 令 {$time} 为左值 if ($lgth < 0) { $time = $time + $lgth * 86400; $lgth = abs($lgth); } $btime = $time; $etime = $btime + $lgth * 86400 + 86399; $rosta['line'][] = $btime; $rosta['line'][] = $etime; if ($btime > $rosta['time'] - 86400) { // 订单查询默认条件 $where = array('o_hid = ' . $this->model('order')->quote($hotel['h_id']), 'o_status <> ' . $this->model('order')->quote(ORDER_STATUS_YQX)); $rooms = Zyon_Array::keyto($this->model('room')->getRoomAryByHid($hotel['h_id']), 'r_id'); if (!empty($rooms)) { foreach ($rooms as $key => &$room) { if ($room['r_attr'] & ROOM_ATTR_YCFT) { unset($rooms[$key]); continue; } $rosta['data'][$room['r_id']] = array(); $rosta['rent'][$room['r_id']] = array(); $rosta['room'][$room['r_id']] = array('rid' => $room['r_id'], 'rnm' => $this->view->escape($room['r_name']), 'ext' => array('rtp' => $this->view->escape($room['r_type']), 'rlo' => $this->view->escape($room['r_layout']), 'rze' => $this->view->escape($room['r_zone']), 'rvw' => $this->model('room')->getViewListByCode($room['r_view']))); if ($btime < $room['r_otime']) { $_r_btime = $btime; $_r_otime = min($etime, $room['r_otime']); while ($_r_btime < $_r_otime) { $rosta['data'][$room['r_id']][($_r_btime - $btime) / 86400] = ROSTA_BL; $_r_btime += 86400; } } if ($room['r_btime']) { $_r_btime = max($btime, $room['r_btime']); $_r_etime = min($etime, $room['r_etime']); while ($_r_btime < $_r_etime) { $rosta['data'][$room['r_id']][($_r_btime - $btime) / 86400] = ROSTA_BL; $_r_btime += 86400; } } } unset($room); } if (!empty($rooms)) { // 增加查询房间限定 $where[] = sprintf('o_rid IN (%s)', implode(',', array_keys($rooms))); $orders = Zyon_Array::keyto($this->model('order')->getOrderAryByIds($this->model('order')->fetchIds(array_merge($where, array('o_bdatm < ' . $this->model('order')->quote($etime), 'o_edatm > ' . $this->model('order')->quote($btime))))), 'o_id'); if (!empty($orders)) { foreach ($orders as &$order) { switch ($order['o_status']) { case ORDER_STATUS_YD: $sta = ROSTA_YD; break; default: $sta = ROSTA_BL; break; } $_o_btime = max($btime, $order['o_bdatm']); $_o_etime = min($etime, $order['o_edatm']); while ($_o_btime < $_o_etime) { $key = ($_o_btime - $btime) / 86400; if (!isset($rosta['data'][$order['o_rid']][$key]) || $rosta['data'][$order['o_rid']][$key] !== ROSTA_BL) { $rosta['data'][$order['o_rid']][$key] = $sta; } $_o_btime += 86400; } } unset($order); } $prices = $this->model('room.price')->getPriceDotAryByHid($hotel['h_id'], $btime, $etime); if (!empty($prices)) { foreach ($prices as $rid => &$lst) { if (isset($rooms[$rid])) { foreach ($lst as $dtm => $val) { $val = (int) $val; if (($end = end($rosta['rent'][$rid])) !== false && $end === $val) { unset($rosta['rent'][$rid][$key = key($rosta['rent'][$rid])]); $key = explode(',', $key); $key[1] = ($dtm - $btime) / 86400; $rosta['rent'][$rid][implode(',', $key)] = $val; } else { $rosta['rent'][$rid][($dtm - $btime) / 86400] = $val; } } } } unset($lst); } // 合并相同状态的单元格,键 P 改为 L,R foreach ($rosta['data'] as $key => &$val) { $lst = array(); ksort($val, SORT_NUMERIC); $idx = -1; foreach ($val as $k => $v) { if ($k && isset($val[$k - 1]) && $val[$k - 1] === $v) { $lst[$idx][2] = $k; } else { ++$idx; $lst[] = array($v, $k); } } $rosta['data'][$key] = array(); foreach ($lst as $k => $v) { $rosta['data'][$key][isset($v[2]) ? $v[1] . ',' . $v[2] : $v[1]] = $v[0]; } } } } if ($this->input('ct') === 'json') { $this->flash(1, array('context' => $rosta)); } $this->view->hotel = $hotel; $this->view->rosta = $rosta; }
/** * 时间轴 */ public function indexAction() { $rosta = array('time' => time(), 'line' => array(), 'room' => array(), 'data' => array()); $date = $this->input('date'); $lgth = $this->input('lgth'); $skip = $this->input('skip'); $rids = $this->input('rids'); $time = strtotime(Zyon_Util::isDate($date) ? $date : ($date = date('Y-m-d', $rosta['time'] - 86400))); if (!Zyon_Util::isInt($lgth)) { $lgth = 8; } $lgth = (int) $lgth; if (abs($lgth) > 30 || abs($lgth) < 2) { $this->flash(0, '入住时间和离店时间间隔最少 2天,最长 30天'); } $lgth = $lgth > 0 ? $lgth - 1 : $lgth + 1; // 订单查询默认条件 $where = array('o_hid = ' . $this->model('order')->quote($this->_master['u_hid']), 'o_status <> ' . $this->model('order')->quote(ORDER_STATUS_YQX)); // 指定房间编号集合 if ($rids) { $rids = explode(',', $rids); if (empty($rids)) { $rooms = array(); } else { $rooms = Zyon_Array::keyto($this->model('room')->getRoomAryByIds($rids, $this->_master['u_hid']), 'r_id'); } } else { $rooms = Zyon_Array::keyto($this->model('room')->getRoomAryByHid($this->_master['u_hid']), 'r_id'); } if (!empty($rooms)) { foreach ($rooms as $key => &$room) { if ($room['r_attr'] & ROOM_ATTR_YCFT) { unset($rooms[$key]); } } unset($room); if (!empty($rooms)) { // 增加查询房间限定 $where[] = sprintf('o_rid IN (%s)', implode(',', array_keys($rooms))); } } // 取得上(下)一个有订单时间临界点 if (!empty($rooms) && $skip) { if ($lgth < 0) { $orders = $this->model('order')->fetch(array('where' => array_merge($where, array('o_etime < ' . $this->model('order')->quote($time))), 'order' => 'o_etime DESC', 'field' => 'o_edatm', 'limit' => 1)); if ($orders) { $time = (int) $orders[0]['o_edatm']; } } else { $orders = $this->model('order')->fetch(array('where' => array_merge($where, array('o_btime > ' . $this->model('order')->quote($time))), 'order' => 'o_btime ASC', 'field' => 'o_bdatm', 'limit' => 1)); if ($orders) { $time = (int) $orders[0]['o_bdatm']; } } } // 令 {$time} 为左值 if ($lgth < 0) { $time = $time + $lgth * 86400; $lgth = abs($lgth); } $btime = $time; $etime = $btime + $lgth * 86400 + 86399; $rosta['line'][] = $btime; $rosta['line'][] = $etime; if (!empty($rooms)) { $obnum = $this->model('order')->calNumAryByRidAryAndSta(array_keys($rooms), ORDER_STATUS_YD, $rosta['time'] - 86400 * 3); foreach ($rooms as &$room) { $rosta['data'][$room['r_id']] = array(); $rosta['room'][$room['r_id']] = array('rid' => $room['r_id'], 'sta' => $room['r_status'], 'rnm' => $this->view->escape($room['r_name']), 'ext' => array('rtp' => $this->view->escape($room['r_type']), 'rlo' => $this->view->escape($room['r_layout']), 'rze' => $this->view->escape($room['r_zone']), 'rvw' => $this->model('room')->getViewListByCode($room['r_view'])), 'ovt' => (int) $room['r_otime'], 'lvt' => (int) $room['r_btime'], 'rvt' => (int) $room['r_etime'], 'obn' => (int) (isset($obnum[$room['r_id']]) ? $obnum[$room['r_id']] : 0)); } unset($room); $orders = Zyon_Array::keyto($this->model('order')->fetchAry(array_merge($where, array('o_btime < ' . $this->model('order')->quote($etime), 'o_etime > ' . $this->model('order')->quote($btime))), 'o_id DESC'), 'o_id'); if (!empty($orders)) { $others = array(); $owhere = array(); foreach ($orders as &$order) { $rosta['data'][$order['o_rid']][$order['o_id']] = array('key' => $order['o_mtime'], 'oid' => $order['o_id'], 'bid' => $order['o_bid'], 'ats' => (int) $order['o_attr'], 'sta' => (int) $order['o_status'], 'lvt' => $order['o_btime'], 'rvt' => $order['o_etime'], 'act' => $this->model('order')->getUsableActions($order, $this->_hostel, false), 'gst' => array('bkg' => array(array('gnm' => $this->view->escape($order['o_gbker_name']), 'tel' => $this->view->escape($order['o_gbker_phone']))), 'lvg' => array(array('gnm' => $this->view->escape($order['o_glver_name']), 'tel' => $this->view->escape($order['o_glver_phone']))))); if ($order['o_memo'] == '') { $rosta['data'][$order['o_rid']][$order['o_id']]['tip'] = ''; } // 检测订单与房态的冲突 if ($order['o_btime'] <= $rooms[$order['o_rid']]['r_etime'] && $order['o_edatm'] > $rooms[$order['o_rid']]['r_btime']) { unset($rosta['data'][$order['o_rid']][$order['o_id']]['act'][ORDER_ACTION_BLDD]); unset($rosta['data'][$order['o_rid']][$order['o_id']]['act'][ORDER_ACTION_BLRZ]); } // 拆分占位和不占位订单 if ($order['o_status'] == ORDER_STATUS_YD) { $owhere = empty($owhere) ? array(min($order['o_btime'], $btime), max($order['o_etime'], $etime)) : array(min($order['o_btime'], $owhere[0]), max($order['o_etime'], $owhere[1])); } else { $others[$order['o_id']] = $order; unset($orders[$order['o_id']]); } } unset($order); // 获取扩展时间段的订单 if (!empty($owhere) && ($owhere[0] < $btime || $owhere[1] > $etime)) { $others += Zyon_Array::keyto($this->model('order')->fetch(array('where' => array_merge($where, array(sprintf('o_id NOT IN (%s)', implode(',', array_merge(array_keys($orders), array_keys($others)))), 'o_status <> ' . $this->model('order')->quote(ORDER_STATUS_YD), 'o_btime < ' . $this->model('order')->quote($owhere[1]), 'o_etime > ' . $this->model('order')->quote($owhere[0]))), 'field' => array('o_id', 'o_rid', 'o_btime', 'o_etime'))), 'o_id'); } // 检测不占位的订单冲突 foreach ($orders as &$order) { foreach ($others as &$other) { if ($other['o_rid'] === $order['o_rid'] && $other['o_btime'] < $order['o_etime'] && $other['o_etime'] > $order['o_btime']) { unset($rosta['data'][$order['o_rid']][$order['o_id']]['act'][ORDER_ACTION_BLDD]); unset($rosta['data'][$order['o_rid']][$order['o_id']]['act'][ORDER_ACTION_BLRZ]); break; } } unset($other); } unset($order, $orders, $others); } } if ($this->input('ct') === 'json') { $this->flash(1, array('context' => $rosta)); } $this->view->hotel = $this->_hostel; $this->view->rosta = $rosta; }
/** * 创建订单 */ public function doCreateAction() { if (!$this->getRequest()->isPost()) { $this->flash(0, '错误来源的表单提交'); } $captcha = new Geek_Captcha_Image('/hostel/order/do-create'); if (!$captcha->isValid($this->input('captcha'))) { $this->flash(0, '请填写正确的验证码'); } if (!Zyon_Util::isUnsignedInt($otime = $this->input('ctime')) || !is_array($order = $this->input('order', 'array')) || empty($order) || !is_array($orent = $this->input('price', 'array')) || empty($orent) || !is_array($gbker = $this->input('cuser', 'array')) || empty($gbker) || !is_array($glves = $this->input('guest', 'array')) || empty($glves) || ($count = count($order)) !== count($orent) || $count !== count($glves) || !isset($gbker['name']) || !isset($gbker['call']) || !isset($gbker['mail'])) { $this->flash(0, '提交订单的参数错误'); } $gbker = array('o_gbker_name' => $gbker['name'], 'o_gbker_email' => $gbker['mail'], 'o_gbker_phone' => $gbker['call']); if (!$this->model('order')->verify($gbker)) { $this->flash(0, '预订客人信息参数错误'); } $ctime = time(); $dtime = strtotime(date('Y-m-d', $ctime)); if ($ctime - $otime < 10 || $ctime - $otime > 1800 || $dtime !== strtotime(date('Y-m-d', $otime))) { $this->flash(0, '订单已失效,请刷新重试'); } $this->checkHotelStat($hotel = $this->loadUsableHotel($hid = $this->input('hid'))); if (!(SYSTEM_GROUPS_GSER & (int) $hotel['h_order_enabled'])) { $this->flash(0, '旅店尚未开放该功能'); } if ($count > static::ORDER_LIMIT) { $this->flash(0, __('单次预订不允许超过%d个房间', static::ORDER_LIMIT)); } $btmad = $hotel['h_checkin_time']; $etmad = $hotel['h_checkout_time']; $price_rules_conds = $other_order_conds = array(); foreach ($order as $rid => &$val) { if (!Zyon_Util::isUnsignedInt($rid) || !is_array($val) || !isset($val['date']) || !isset($val['lgth']) || !Zyon_Util::isDate($val['date']) || !Zyon_Util::isUnsignedInt($val['lgth']) || $val['lgth'] < 1 || !is_array($val['time']) || !isset($val['time'][0]) || !isset($val['time'][1]) || !Zyon_Util::isUnsignedInt($val['time'][0]) || !Zyon_Util::isUnsignedInt($val['time'][1]) || $val['time'][0] < $btmad || $val['time'][0] > 86399 || $val['time'][1] > $etmad || $val['time'][0] < 1) { $this->flash(0, '参数错误'); } if ($val['lgth'] < $hotel['h_order_minlens'] || $val['lgth'] > $hotel['h_order_maxlens']) { $this->flash(0, __('旅店仅支持创建天数介于 %d 到 %d 的订单', $hotel['h_order_minlens'], $hotel['h_order_maxlens'])); } $val['datm'] = strtotime($val['date']); if ($val['datm'] < $dtime) { $this->flash(0, '不支持创建今天之前的订单'); } $price_rules_conds[] = sprintf('(rp_rid = %d AND rp_btime <= %d AND rp_etime >= %d)', $rid, $val['datm'] + ($val['lgth'] - 1) * 86400, $val['datm']); $other_order_conds[] = sprintf('(o_rid = %d AND o_btime < %d AND o_etime > %d)', $rid, $val['datm'] + $val['lgth'] * 86400 + $val['time'][1], $val['datm'] + $val['time'][0]); } unset($val); $price_rules_conds = implode(' OR ', $price_rules_conds); $other_order_conds = implode(' OR ', $other_order_conds); $rooms = Zyon_Array::keyto($this->model('room')->getRoomAryByIds(array_keys($order)), 'r_id'); if (empty($rooms) || count($rooms) !== $count) { $this->flash(0, '找不到指定预订的房间'); } // 以下处理每个房间的启用日、停用段以及订单最长时间限制, // 整理入住客人信息 foreach ($rooms as $rid => &$val) { if ($val['r_hid'] !== $hotel['h_id']) { $this->flash(0, '找不到指定预订的房间'); } if ($val['r_attr'] & ROOM_ATTR_YCFT) { $this->flash(0, __('指定的房间 %s 不可预订', $val['r_name'])); } if (!isset($glves[$rid]) || !is_array($glves[$rid]) || !isset($glves[$rid]['name']) || !isset($glves[$rid]['mail']) || !isset($glves[$rid]['call'])) { $this->flash(0, '缺少入住客人信息'); } $glves[$rid] = array('o_glver_name' => $glves[$rid]['name'], 'o_glver_email' => $glves[$rid]['mail'], 'o_glver_phone' => $glves[$rid]['call']); if (!$this->model('order')->verify($glves[$rid])) { $this->flash(0, __('%s 房间的入住客人信息错误', $val['r_name'])); } $btime = $order[$rid]['datm']; $etime = $btime + $order[$rid]['lgth'] * 86400 - 1; for ($_btime = max($btime, $dtime + 86400 * $hotel['h_order_enddays']); $_btime < $etime; $_btime += 86400) { $this->flash(0, __('%s 的 %s 房间不可用', date('Y-m-d', $_btime), $val['r_name'])); } if ($val['r_btime']) { $_r_btime = max($btime, $val['r_btime']); $_r_etime = min($etime, $val['r_etime']); while ($_r_btime < $_r_etime) { $this->flash(0, __('%s 的 %s 房间不可用', date('Y-m-d', $_r_btime), $val['r_name'])); } } if ($btime < $val['r_otime']) { $this->flash(0, __('房间%s在%s之前尚未启用', $val['r_name'], date('Y-m-d', $val['r_otime']))); } } unset($val); // 以下检测旅店预订订单是否超出限制 if ($hotel['h_order_default_stacode'] == ORDER_STATUS_YD) { $oldes = $this->model('order')->calNumAryByRidAryAndSta(array_keys($order), ORDER_STATUS_YD, $ctime - getSysLimit('BOOKING_LIVE')); if (!empty($oldes)) { if ($count + array_sum($oldes) > getSysLimit('BOOKING_QNTY')) { $this->flash(0, '旅店预订订单数量已满'); } $per = getSysLimit('BOOKING_PERN'); foreach ($oldes as $rid => $num) { if (array_key_exists($rid, $order) && $num > $per - 1) { $this->flash(0, __('%s 房间预订订单数量已满', $rooms[$rid]['r_name'])); } } } } // 以下处理每个订单的冲突 $other = $this->model('order')->getOrderAryByIds($this->model('order')->fetchIds(array('o_hid = ' . $hotel['h_id'], 'o_status <> ' . $this->model('order')->quote(ORDER_STATUS_YQX), 'o_status <> ' . $this->model('order')->quote(ORDER_STATUS_YD), $other_order_conds), null, 1)); if (!is_array($other)) { $this->flash(0, '无法获取系统订单的信息'); } if (!empty($other)) { foreach ($other as &$val) { $rid = $val['o_rid']; $_o_btime = max($order[$rid]['datm'], $val['o_bdatm']); $_o_etime = min($order[$rid]['datm'] + $order[$rid]['lgth'] * 86400, $val['o_edatm']); while ($_o_btime < $_o_etime) { $this->flash(0, __('%s 的 %s 房间已被占用', date('Y-m-d', $_o_btime), $rooms[$rid]['r_name'])); } if ($val['o_bdatm'] == $order[$rid]['datm'] + $order[$rid]['lgth'] * 86400 && $order[$rid]['time'][1] > $val['o_btime'] - $val['o_bdatm']) { $this->flash(0, __('%s 的 %s 房间已被占用', date('Y-m-d', $val['o_bdatm']), $rooms[$rid]['r_name'])); } if ($val['o_edatm'] == $order[$rid]['datm'] && $order[$rid]['time'][0] < $val['o_etime'] - $val['o_edatm']) { $this->flash(0, __('%s 的 %s 房间已被占用', date('Y-m-d', $val['o_edatm']), $rooms[$rid]['r_name'])); } } unset($val); } unset($other); // 以下处理每个订单的房费 $basic = $this->model('room.price')->getBasicPriceByRids(array_keys($rooms)); if (!$basic || count($basic) !== $count) { $this->flash(0, '无法获取预订房间的房价'); } $rules = Zyon_Array::group($this->model('room.price')->getPriceAryByIds($this->model('room.price')->fetchIds(array('rp_hid = ' . $hotel['h_id'], $price_rules_conds))), 'rp_rid'); $price = array(); foreach (array_keys($basic) as $rid) { $price[$rid] = $this->model('room.price')->getPriceDotAry($basic[$rid], $order[$rid]['datm'], $order[$rid]['datm'] + $order[$rid]['lgth'] * 86400 - 1, isset($rules[$rid]) ? $rules[$rid] : array()); } unset($basic, $rules); // 以下校验提交订单时的房费和当前是否相同 if (count($price) !== count($orent)) { $this->flash(0, '订单价格错误'); } $obsum = 0; foreach ($price as $rid => &$val) { if (!isset($orent[$rid]) || count($val) !== count($orent[$rid])) { $this->flash(0, '订单价格错误'); } foreach ($val as $k => $v) { if (!isset($orent[$rid][$k])) { $this->flash(0, '订单价格错误'); } if ((string) ($v / 100) !== $orent[$rid][$k]) { $this->flash(0, '订单价格已失效,请刷新重试'); } $obsum += $v; } } unset($val); $sales = $this->model('user')->getUser($hotel['h_order_default_saleman']); if (!$sales) { $this->flash(0, '读取旅店销售人员信息失败'); } $otype = $this->model('hotel.typedef')->getTypedef($hotel['h_order_default_typedef']); if (!$otype) { $this->flash(0, '读取旅店预订类型信息失败'); } $cfrom = $this->model('hotel.channel')->getChannel($hotel['h_order_default_channel']); if (!$cfrom) { $this->flash(0, '读取旅店预订渠道信息失败'); } $osetm = $this->model('hotel.settlem')->getSettlem($hotel['h_obill_default_settlem']); if (!$osetm) { $this->flash(0, '读取旅店结算方式信息失败'); } $ltime = $hotel['h_attr'] & (int) HOTEL_ATTR_ZDGQ ? $ctime + $hotel['h_obill_keptime'] : null; /** * 开启事务,创建订单 */ $this->model('order')->dbase()->beginTransaction(); try { $bid = $this->model('bill')->addBill($this->model('bill')->getNewBill($hid, $osetm['hs_id'], $osetm['hs_name'], $obsum, 0, mb_substr($gbker['o_gbker_name'], 0, 10) . '-' . date('ymdHi', $ctime), $ltime)); if (!$bid) { throw new exception('创建订单相关账单信息失败'); } foreach ($order as $rid => $order) { $order = $this->model('order')->getNewOrder($rooms[$rid], $order['datm'] + $order['time'][0], $order['datm'] + 86400 * $order['lgth'] + $order['time'][1], json_encode($price[$rid]), json_encode($price[$rid]), $hotel['h_order_default_stacode']); $order['o_bid'] = $bid; $order['o_cid'] = $cfrom['hc_id']; $order['o_cnm'] = $cfrom['hc_name']; $order['o_tid'] = $otype['ht_id']; $order['o_tnm'] = $otype['ht_name']; $order['o_sid'] = $sales['u_id']; $order['o_snm'] = $sales['u_realname']; $order['o_attr'] = ORDER_ATTR_ZXDD; $order = array_merge($gbker, $glves[$rid], $order); $oid = $this->model('order')->addOrder($order); if (!$oid) { throw new exception('创建订单失败'); } if ($order = $this->model('order')->getOrder($oid)) { $this->model('log.order')->addLog($this->model('log.order')->getNewCreateByGserLog($gbker, $order)); } } if ($bill = $this->model('bill')->getBill($bid)) { $this->model('log.bill')->addLog($this->model('log.bill')->getNewCreateByGserLog($gbker, $bill)); } $this->model('order')->dbase()->commit(); $this->flash(1, array('forward' => "/hostel/rosta?hid={$hid}")); } catch (Exception $e) { $this->model('order')->dbase()->rollBack(); $this->error($e); } $this->flash(0); }
/** * getJournalAryByHidAndDay * * @param int $hid * @param string $day * @return array */ public function getJournalAryByHidAndDay($hid, $day) { if (!is_numeric($hid) || !Zyon_Util::isDate($day)) { return false; } $dtm = strtotime($day); return $this->getJournalAryByIds($this->fetchIds(array('bj_hid = ' . $this->quote($hid), 'bj_time >= ' . $dtm, 'bj_time < ' . ($dtm + 86400)))); }
/** * 执行停用、启用房间操作 */ public function doRetainAction() { $room = $this->loadUsableRoom($this->input('rid')); $oper = $this->input('pause'); $desc = $this->input('desc'); if (!$oper) { if (!$this->model('room')->modRoom($room['r_id'], array('r_btime' => 0, 'r_etime' => 0))) { $this->flash(0); } $log = $this->model('log.room')->getNewRetainToLiveLog($this->_master, $room, $this->model('room')->getRoom($room['r_id'])); $log['lr_memo'] = $desc; $this->model('log.room')->addLog($log); $this->flash(1); } /** * 处理停用起始时间 */ if (!Zyon_Util::isDate($bdate = $this->input('bdate'))) { $this->flash(0, ' 停用起始时间必须是合法的日期格式'); } $btime = strtotime($bdate); /** * 处理停用结束时间 */ if (!Zyon_Util::isDate($edate = $this->input('edate'))) { $this->flash(0, '停用结束时间必须是合法的日期格式'); } $etime = strtotime($edate) + 86399; if ($etime < $btime) { $this->flash(0, '停用结束时间不能早于停用起始时间'); } if (!$this->model('room')->modRoom($room['r_id'], array('r_btime' => $btime, 'r_etime' => $etime))) { $this->flash(0); } $log = $this->model('log.room')->getNewRetainToStopLog($this->_master, $room, $this->model('room')->getRoom($room['r_id'])); $log['lr_memo'] = $desc; $this->model('log.room')->addLog($log); $this->flash(1); }
/** * calRoomNumByDay * * @param date $date * @return array {$hid: $num, ...} */ public function calRoomNumByDay($date, $hids = null) { if (!Zyon_Util::isDate($date)) { return false; } $time = strtotime($date) + 86399; try { $sql = $this->dbase()->select()->from($this->tname('hotel'), 'h_id')->joinLeft($this->tname('room'), 'h_id=r_hid AND r_otime <= :dtm', 'count(r_id)')->group('h_id'); $hids and $sql->where(sprintf("h_id IN (%s)", is_string($hids) ? $hids : implode(',', $hids))); return $this->dbase()->fetchPairs($sql, array('dtm' => $time)); } catch (Exception $e) { $this->log($e); return false; } }
/** * 结算报表 - 预订客人对账明细 */ public function jsbbYdkrdzmxAction() { if (!($date = $this->input('date', 'array'))) { $this->_forward('jsbb-ydkrdzmx-form', 'stat', 'master'); return; } if (!isset($date[0]) || !isset($date[1]) || !Zyon_Util::isDate($date[0]) || !Zyon_Util::isDate($date[1])) { $this->flash(0, '查询的日期格式错误'); } $tmln = array(); $tmln[0] = strtotime($date[0]); $tmln[1] = strtotime($date[1]) + 86400; $lgth = ($tmln[1] - $tmln[0]) / 86400; if (!Zyon_Util::isUnsignedInt($lgth) || $lgth > 31 || $lgth < 1) { $this->flash(0, '选择的日期超出了可查询的范围'); } $tmln[1] -= 1; if (($bknm = $this->input('bknm')) == '') { $this->flash(0, '预订客人姓名不能为空'); } $time = time(); $ydkr = $this->model('order')->getIndexOrderAry(array('o_hid = ' . (int) $this->_hostel['h_id'], 'o_etime >= ' . (int) $tmln[0], 'o_etime <= ' . (int) $tmln[1], 'o_status = ' . (int) ORDER_STATUS_YJS), array('type' => HOTEL_GUEST_TYPE_BOOK, 'name' => $bknm)); $this->view->time = $time; $this->view->tmln = $tmln; $this->view->bknm = $bknm; $this->view->ydkr = $ydkr; }