Пример #1
0
 /**
  * 会员帐号列表
  */
 public function indexAction()
 {
     $where = array('m_hid = ' . $this->model('mber')->quote($this->_master['u_hid']));
     $mbers = array();
     $pager = array();
     $pager['qnty'] = (int) $this->input('qnty', 'numeric');
     empty($pager['qnty']) and $pager['qnty'] = 25;
     $pager['qnty'] = min($pager['qnty'], 30);
     $pager['page'] = (int) $this->input('page', 'numeric');
     empty($pager['page']) and $pager['page'] = 1;
     $query = array();
     $query['qnty'] = $pager['qnty'];
     $query['name'] = $this->input('name');
     $query['type'] = $this->input('type');
     in_array($query['type'], array('uqid', 'uqno', 'idno', 'name', 'mail', 'call'), true) or $query['type'] = $query['name'] = null;
     $query['state'] = $this->input('state', 'array');
     $query['state'] or $query['state'] = array();
     $query['state'] = array_unique($query['state']);
     if (!empty($query['state'])) {
         $where[] = 'm_status IN (' . implode(',', array_map(array($this->model('mber'), 'quote'), $query['state'])) . ')';
     }
     $query['types'] = $this->input('types', 'array');
     $query['types'] or $query['types'] = array();
     $query['types'] = array_unique($query['types']);
     if (!empty($query['types'])) {
         $where[] = 'm_type IN (' . implode(',', array_map(array($this->model('mber'), 'quote'), $query['types'])) . ')';
     }
     if ($query['name'] != '' && $query['type'] != '') {
         if ($query['type'] == 'uqid') {
             $where[] = 'm_id = ' . $this->model('mber')->quote($query['name']);
         }
         if ($query['type'] == 'uqno') {
             $where[] = 'm_no = ' . $this->model('mber')->quote($query['name']);
         }
         if ($query['type'] == 'idno') {
             $where[] = 'm_idno = ' . $this->model('mber')->quote($query['name']);
         } else {
             if ($query['type'] == 'name') {
                 $where[] = 'm_name = ' . $this->model('mber')->quote($query['name']);
             } else {
                 if ($query['type'] == 'mail') {
                     $where[] = 'm_email = ' . $this->model('mber')->quote($query['name']);
                 } else {
                     if ($query['type'] == 'call') {
                         $where[] = 'm_phone = ' . $this->model('mber')->quote($query['name']);
                     }
                 }
             }
         }
     }
     $mbers = Zyon_Array::keyto($this->model('mber')->fetchAry($where, 'm_id DESC', array($pager['qnty'], $pager['qnty'] * ($pager['page'] - 1))), 'm_id');
     empty($mbers) and $mbers = array();
     $types = $this->model('mber')->getMberTypeAryByHid($this->_hostel['h_id']);
     $pager['list'] = count($mbers);
     $pager['args'] = $query;
     $this->view->pager = $pager;
     $this->view->query = $query;
     $this->view->mbers = $mbers;
     $this->view->types = $types;
 }
Пример #2
0
 /**
  * 获取可用预订渠道列表
  */
 public function fetchAbledIndexAction()
 {
     if ($index = Zyon_Array::keyto($this->model('hotel.channel')->getUsableChannelAryByHid($this->_hostel['h_id']), 'hc_id')) {
         foreach ($index as $key => $val) {
             $index[$key] = $val['hc_name'];
         }
         $this->flash(1, array('context' => $index));
     }
     $this->flash(1, array('context' => array()));
 }
Пример #3
0
 /**
  * 更新预订状态的订单
  */
 public function doUpdateYD($order)
 {
     switch ($this->input('tab')) {
         case 'hfsx':
             if (!$this->hasUserPerm('/master/order/do-update-attr-yxhf')) {
                 $this->flash(0, '没有更改该属性的权限');
             }
             if ($this->model('order')->modOrder($order['o_id'], array('o_attr' => $this->model('order')->expr('o_attr ^ ' . ORDER_ATTR_YXHF)))) {
                 $this->model('log.order')->addLog($this->model('log.order')->getNewUpdateLog($this->_master, $order, $this->model('order')->getOrder($order['o_id']), __('更改订单%s属性', getOrderAttrNameByCode(ORDER_ATTR_YXHF))));
                 $this->flash(1);
             }
             break;
         case 'jbxx':
             if ($order['o_memo'] === $this->input('memo')) {
                 $this->flash(1);
             }
             if ($this->model('order')->modOrder($order['o_id'], array('o_memo' => $this->input('memo')))) {
                 $this->model('log.order')->addLog($this->model('log.order')->getNewUpdateLog($this->_master, $order, $this->model('order')->getOrder($order['o_id']), __('基本信息')));
                 $this->flash(1);
             }
             break;
         case 'ffmx':
             if (!$this->hasUserPerm('/master/order/do-update-info-fxmx')) {
                 $this->flash(0, '没有权限');
             }
             $bdate = $this->input('bdate');
             $bhour = $this->input('bhour', 'numeric');
             $bminu = $this->input('bminu', 'numeric');
             isset($bhour[1]) or $bhour = '0' . $bhour;
             isset($bminu[1]) or $bminu = '0' . $bminu;
             $edate = $this->input('edate');
             $ehour = $this->input('ehour', 'numeric');
             $eminu = $this->input('eminu', 'numeric');
             isset($ehour[1]) or $ehour = '0' . $ehour;
             isset($eminu[1]) or $eminu = '0' . $eminu;
             if (!Zyon_Util::isDate($bdate) || !Zyon_Util::isDate($edate) || !Zyon_Util::isTime($bhour . ':' . $bminu) || !Zyon_Util::isTime($ehour . ':' . $eminu)) {
                 $this->flash(0, '预订时间格式错误');
             }
             $bdatm = strtotime($bdate);
             $edatm = strtotime($edate);
             $btime = $bdatm + Zyon_Util::timeToSecs($bhour . ':' . $bminu);
             $etime = $edatm + Zyon_Util::timeToSecs($ehour . ':' . $eminu);
             if ($edatm <= $bdatm) {
                 $this->flash(0, '离店日期必须晚于入住日期');
             }
             if ($edatm < strtotime(date('Y-m-d', $order['o_ctime']))) {
                 $this->flash(0, '离店日期不能在订单创建日期之前');
             }
             if (($edatm - $bdatm) / 86400 < $this->_hostel['h_order_minlens'] || ($edatm - $bdatm) / 86400 > $this->_hostel['h_order_maxlens']) {
                 $this->flash(0, __('旅店仅支持天数介于 %d 到 %d 的订单', $this->_hostel['h_order_minlens'], $this->_hostel['h_order_maxlens']));
             }
             for ($_btime = max($bdatm, strtotime(date('Y-m-d')) + 86400 * $this->_hostel['h_order_enddays']); $_btime < $etime; $_btime += 86400) {
                 $this->flash(0, __('%s 超出旅店允许建立最多%d天内的订单规则', date('Y-m-d', $_btime), $this->_hostel['h_order_enddays']));
             }
             $oroom = $this->loadUsableRoom($order['o_rid']);
             $flash = array();
             if ($etime > $order['o_etime'] || $btime < $order['o_btime']) {
                 if ($oroom['r_btime']) {
                     $_r_btime = max($bdatm, $oroom['r_btime']);
                     $_r_etime = min($edatm - 1, $oroom['r_etime']);
                     while ($_r_btime < $_r_etime) {
                         $flash[] = __('%s 该房间已被停用', date('Y-m-d', $_r_btime));
                         $_r_btime += 86400;
                     }
                 }
                 $other = Zyon_Array::keyto($this->model('order')->getOrderAryByIds($this->model('order')->fetchIds(array('o_id <> ' . (int) $order['o_id'], 'o_hid = ' . (int) $order['o_hid'], 'o_rid = ' . (int) $order['o_rid'], 'o_status <> ' . (int) ORDER_STATUS_YQX, 'o_status <> ' . (int) ORDER_STATUS_YD, 'o_bdatm <= ' . (int) $edatm, 'o_edatm >= ' . (int) $bdatm))), 'o_id');
                 if (!empty($other)) {
                     foreach ($other as $other) {
                         if ($other['o_edatm'] == $bdatm && $other['o_etime'] > $btime) {
                             $flash[] = __('%s 该房间已被其它订单占用', date('Y-m-d H:i', $btime));
                         }
                         if ($other['o_bdatm'] == $edatm && $other['o_btime'] < $etime) {
                             $flash[] = __('%s 该房间已被其它订单占用', date('Y-m-d H:i', $etime));
                         }
                         $_o_btime = max($bdatm, $other['o_bdatm']);
                         $_o_etime = min($edatm, $other['o_edatm']);
                         while ($_o_btime < $_o_etime) {
                             $flash[] = __('%s 该房间已被其它订单占用', date('Y-m-d', $_o_btime));
                             $_o_btime += 86400;
                         }
                     }
                     unset($other);
                 }
             }
             if (!empty($flash)) {
                 $this->flash(0, array('content' => $flash));
             }
             $price_array = $this->fetchOrderPrice($this->input('price', 'array'), $bdate, $edate);
             $brice_array = $this->fetchOrderPrice($this->input('brice', 'array'), $bdate, $edate);
             if (!$this->model('order')->chkCanUpdateOrder($this->_hostel, $oroom, $order, $btime, $etime)) {
                 $this->flash(0, '无法更新订单至指定时间段');
             }
             /**
              * 开启事务,更新订单
              */
             $this->model('order')->dbase()->beginTransaction();
             try {
                 $price = array_sum($price_array);
                 $brice = array_sum($brice_array);
                 if ((int) $order['o_brice'] !== $brice) {
                     $bill_old = $this->loadUsableBill($order['o_bid']);
                     if (!$this->model('bill')->modBill($order['o_bid'], array('b_cost' => $this->model('bill')->expr('b_cost + ' . ($brice - $order['o_brice']))))) {
                         throw new exception('更新账单信息失败');
                     }
                     if ($bill = $this->model('bill')->getBill($order['o_bid'])) {
                         $this->model('log.bill')->addLog($this->model('log.bill')->getNewUpdateLog($this->_master, $bill_old, $bill, __('%d号订单房费 %d=>%d', $order['o_id'], $order['o_brice'] / 100, $brice / 100)));
                     }
                 }
                 if (!$this->model('order')->modOrder($order['o_id'], array('o_btime' => $btime, 'o_etime' => $etime, 'o_price' => $price, 'o_brice' => $brice, 'o_prices' => json_encode($price_array), 'o_brices' => json_encode($brice_array)))) {
                     throw new exception('更新房费明细失败');
                 }
                 $this->model('order')->dbase()->commit();
                 $this->model('log.order')->addLog($this->model('log.order')->getNewUpdateLog($this->_master, $order, $this->model('order')->getOrder($order['o_id']), __("房费明细\n[预计入住 %s=>%s, 间夜 %d=>%d, 成交房费 %d=>%d, 账单房费 %d=>%d]", date('Y-m-d H:i', $order['o_btime']), date('Y-m-d H:i', $btime), ($order['o_edatm'] - $order['o_bdatm']) / 86400, ($edatm - $bdatm) / 86400, $order['o_price'] / 100, $price / 100, $order['o_brice'] / 100, $brice / 100)));
             } catch (Exception $e) {
                 $this->model('order')->dbase()->rollBack();
                 $this->error($e);
                 $this->flash(0);
             }
             $this->flash(1);
             break;
         case 'krxx':
             $gbker = $this->fetchOrderGuest($this->input('gbker', 'array'), HOTEL_GUEST_TYPE_BOOK);
             $glver = $this->fetchOrderGuest($this->input('glver', 'array'), HOTEL_GUEST_TYPE_LIVE);
             if ($this->model('order')->modOrder($order['o_id'], array_merge($gbker, $glver))) {
                 $this->model('log.order')->addLog($this->model('log.order')->getNewUpdateGuestLog($this->_master, $order, $this->model('order')->getOrder($order['o_id'])));
                 $this->flash(1);
             }
             break;
         default:
             $this->flash(0);
             break;
     }
 }
Пример #4
0
 /**
  * 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);
 }
Пример #5
0
 /**
  * 时间轴
  */
 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;
 }
Пример #6
0
 /**
  * 旅店房态
  */
 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;
 }
Пример #7
0
 /**
  * 创建订单
  */
 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);
 }
Пример #8
0
 /**
  * 批量更新基础房价
  */
 public function doUpdateBasicPricesAction()
 {
     if ($this->cache()->load($hash = md5(__METHOD__ . '@' . $this->_hostel['h_id'] . '#'))) {
         $this->flash(0, '操作太过频繁,请稍侯再试!');
     }
     $this->cache()->save(1, $hash, array(), 5);
     $price = $this->input('price');
     if (!Zyon_Util::isMoneyFloat($price)) {
         $this->flash(0, '价格错误');
     }
     if ($price < 0) {
         $this->flash(0, '价格不能小于0');
     }
     $price = $price * 100;
     if ($price >= 10000000) {
         $this->flash(0, '价格超出系统限制范围,必须小于100000');
     }
     $rids = $this->input('rids', 'array');
     if (empty($rids)) {
         $this->flash(0, '没有选中任何房间');
     }
     foreach ($rids as &$val) {
         if (!Zyon_Util::isUnsignedInt($val)) {
             $this->flash(0, '指定的房间列表错误');
         }
     }
     unset($val);
     $count = count($rids);
     $rooms = Zyon_Array::keyto($this->model('room')->getRoomAryByIds($rids), 'r_id');
     if (empty($rooms) || count($rooms) !== $count) {
         $this->flash(0, '指定的房间列表错误');
     }
     foreach ($rooms as $rid => &$room) {
         if ($room['r_hid'] !== $this->_hostel['h_id']) {
             $this->flash(0, '指定的房间列表错误');
         }
         if ($room['r_price'] === $price) {
             unset($rooms[$rid]);
         }
     }
     unset($room);
     $rids = array_keys($rooms);
     if (empty($rids)) {
         $this->flash(1);
     }
     if ($this->model('room')->modRoomByIds($rids, array('r_price' => $price))) {
         if ($newRooms = Zyon_Array::keyto($this->model('room')->getRoomAryByIds($rids), 'r_id')) {
             foreach ($rooms as &$room) {
                 $this->model('log.room')->addLog($this->model('log.room')->getNewUpdateBasicPriceLog($this->_master, $room, $newRooms[$room['r_id']]));
             }
             unset($room);
         }
         $this->flash(1);
     }
     $this->flash(0);
 }
Пример #9
0
 /**
  * getPriceDotAryByHid
  * 
  * @param int $hid
  * @param int $btime
  * @param int $etime
  * @return array
  */
 public function getPriceDotAryByHid($hid, $btime, $etime)
 {
     if (!is_array($bas = $this->getBasicPriceByHid($hid))) {
         return false;
     }
     $rps = Zyon_Array::group($this->getPriceAryByHidAndTimeLine($hid, $btime, $etime), 'rp_rid');
     $ret = array();
     if (!empty($bas)) {
         foreach (array_keys($bas) as $key) {
             $ret[$key] = $this->getPriceDotAry($bas[$key], $btime, $etime, isset($rps[$key]) ? $rps[$key] : array());
         }
     }
     return $ret;
 }
Пример #10
0
 /**
  * 结算报表 - 预订渠道对账明细
  */
 public function jsbbYdqddzmxAction()
 {
     if (!($date = $this->input('date', 'array'))) {
         $this->_forward('jsbb-ydqddzmx-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;
     $cnid = $this->input('cnid');
     $cnid == '' and $cnid = $this->_hostel['h_order_default_channel'];
     $cnls = Zyon_Array::keyto($this->model('hotel.channel')->getChannelAryByHid($this->_hostel['h_id']), 'hc_id');
     empty($cnls) and $cnls = array();
     if (!array_key_exists($cnid, $cnls)) {
         $this->flash(0, '找不到指定的预订渠道');
     }
     $time = time();
     $ydqd = $this->model('order')->fetchAry(array('o_hid = ' . (int) $this->_hostel['h_id'], 'o_cid = ' . (int) $cnid, 'o_etime >= ' . (int) $tmln[0], 'o_etime <= ' . (int) $tmln[1], 'o_status = ' . (int) ORDER_STATUS_YJS));
     $this->view->time = $time;
     $this->view->tmln = $tmln;
     $this->view->cnid = $cnid;
     $this->view->cnls = $cnls;
     $this->view->ydqd = $ydqd;
 }