Пример #1
0
 /**
  * _prepare
  * 
  * @return void
  */
 protected function _prepare()
 {
     if (empty(static::$_oattrs)) {
         static::$_oattrs[getOrderAttrNameByCode(ORDER_ATTR_YXHF)] = ORDER_ATTR_YXHF;
     }
     if (empty(static::$_status)) {
         static::$_status[getOrderStatusNameByCode(ORDER_STATUS_YD)] = ORDER_STATUS_YD;
         static::$_status[getOrderStatusNameByCode(ORDER_STATUS_BL)] = ORDER_STATUS_BL;
         static::$_status[getOrderStatusNameByCode(ORDER_STATUS_ZZ)] = ORDER_STATUS_ZZ;
         static::$_status[getOrderStatusNameByCode(ORDER_STATUS_YJS)] = ORDER_STATUS_YJS;
         static::$_status[getOrderStatusNameByCode(ORDER_STATUS_YQX)] = ORDER_STATUS_YQX;
     }
     if (empty(static::$_rtstat)) {
         static::$_rtstat[getOrderRealTimeStatusNameByCode(ORDER_REALTIME_STATUS_YRZ)] = ORDER_REALTIME_STATUS_YRZ;
         static::$_rtstat[getOrderRealTimeStatusNameByCode(ORDER_REALTIME_STATUS_YTF)] = ORDER_REALTIME_STATUS_YTF;
         static::$_rtstat[getOrderRealTimeStatusNameByCode(ORDER_REALTIME_STATUS_YZWZ)] = ORDER_REALTIME_STATUS_YZWZ;
         static::$_rtstat[getOrderRealTimeStatusNameByCode(ORDER_REALTIME_STATUS_YTWT)] = ORDER_REALTIME_STATUS_YTWT;
         static::$_rtstat[getOrderRealTimeStatusNameByCode(ORDER_REALTIME_STATUS_GQWZ)] = ORDER_REALTIME_STATUS_GQWZ;
         static::$_rtstat[getOrderRealTimeStatusNameByCode(ORDER_REALTIME_STATUS_FTCT)] = ORDER_REALTIME_STATUS_FTCT;
     }
     if (empty(static::$_action)) {
         static::$_action[ORDER_ACTION_BLDD] = array('name' => getOrderActionNameByCode(ORDER_ACTION_BLDD), 'code' => ORDER_ACTION_BLDD);
         static::$_action[ORDER_ACTION_QXDD] = array('name' => getOrderActionNameByCode(ORDER_ACTION_QXDD), 'code' => ORDER_ACTION_QXDD);
         static::$_action[ORDER_ACTION_BLRZ] = array('name' => getOrderActionNameByCode(ORDER_ACTION_BLRZ), 'code' => ORDER_ACTION_BLRZ);
         static::$_action[ORDER_ACTION_BLTF] = array('name' => getOrderActionNameByCode(ORDER_ACTION_BLTF), 'code' => ORDER_ACTION_BLTF);
         static::$_action[ORDER_ACTION_BLHF] = array('name' => getOrderActionNameByCode(ORDER_ACTION_BLHF), 'code' => ORDER_ACTION_BLHF);
     }
 }
Пример #2
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;
     }
 }