/** * 创建订单 */ 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); }
/** * 变更订单操作(换房、移动) */ public function doModifyAction() { $older = $this->loadUsableOrder($this->input('oid')); if ($this->input('key') !== $older['o_mtime']) { $this->flash(0, '表单已过期,请刷新重试'); } if ($this->input('sta', 'numeric') !== $older['o_status']) { $this->flash(0, '订单状态错误或者有冲突'); } $ctime = $_SERVER['REQUEST_TIME']; $dtime = strtotime(date('Y-m-d', $ctime)); if ($older['o_edatm'] <= $dtime || !($older['o_attr'] & (int) ORDER_ATTR_YXHF) || $older['o_status'] === ORDER_STATUS_YQX || $older['o_status'] === ORDER_STATUS_YJS) { $this->flash(0, '指定的订单不可以换房'); } $order = $this->input('order', 'array'); if (empty($order)) { $this->flash(0, '没有选择需更换的房间'); } $price = $this->input('price', 'array'); if (empty($price)) { $this->flash(0, '没有指定成交房费明细'); } $brice = $this->input('brice', 'array'); if (empty($brice)) { $this->flash(0, '没有指定账单房费明细'); } $osize = count($order); if ($osize !== count($price) || $osize !== count($brice)) { $this->flash(0, '订单和房费明细不匹配'); } $obval = json_decode($older['o_brices'], true); $opval = json_decode($older['o_prices'], true); $obill = $this->loadUsableBill($older['o_bid']); if (isset($obill['b_status']) && $obill['b_status'] !== BILL_STATUS_KF) { $this->flash(0, '账单已关闭,不允许新的订单与其关联'); } $oroom = $this->loadUsableRoom($older['o_rid']); $ostat = $older['o_status'] == ORDER_STATUS_YD ? ORDER_STATUS_YD : ORDER_STATUS_BL; // 以下处理订单集合 $newid = 0; $order = array_values($order); $other_order_conds = array(); foreach ($order as $idx => &$val) { if (!is_array($val) || !isset($val['room']) || !isset($val['date']) || !isset($val['lgth']) || !Zyon_Util::isUnsignedInt($val['room']) || !Zyon_Util::isDate($val['date']) || !Zyon_Util::isUnsignedInt($val['lgth']) || $val['room'] < 1 || $val['lgth'] < 1 || !isset($price[$idx]) || !is_array($price[$idx]) || !isset($brice[$idx]) || !is_array($brice[$idx])) { $this->flash(0, '参数错误'); } if ($val['room'] == $older['o_rid']) { $this->flash(0, '调换的房间和当前房间相同'); } $val['date'] = array($val['date'], date('Y-m-d', strtotime($val['date']) + $val['lgth'] * 86400)); $val['datm'] = array(strtotime($val['date'][0]), strtotime($val['date'][1])); if ($val['datm'][0] < $dtime) { $this->flash(0, '调房的间夜不能在今天之前'); } $oldot = $val['datm'][0]; while ($oldot < $val['datm'][1]) { if (!isset($obval[$oldot]) || !isset($opval[$oldot])) { $this->flash(0, '目标订单间夜重叠或者超出原订单范围'); } unset($obval[$oldot], $opval[$oldot]); $oldot += 86400; } if ($val['lgth'] < $this->_hostel['h_order_minlens'] || $val['lgth'] > $this->_hostel['h_order_maxlens']) { $this->flash(0, __('旅店仅支持创建天数介于 %d 到 %d 的订单', $this->_hostel['h_order_minlens'], $this->_hostel['h_order_maxlens'])); } $val['pval'] = $this->fetchOrderPrice($price[$idx], $val['date'][0], $val['date'][1]); $val['bval'] = $this->fetchOrderPrice($brice[$idx], $val['date'][0], $val['date'][1]); $val['time'][0] = max($val['datm'][0] + $this->_hostel['h_checkin_time'], $older['o_btime']); $val['time'][1] = min($val['datm'][1] + $this->_hostel['h_checkout_time'], $older['o_etime']); $other_order_conds[] = sprintf('(o_rid = %d AND o_bdatm <= %d AND o_edatm >= %d)', $val['room'], $val['datm'][1], $val['datm'][0]); if ($val['datm'][0] < $order[$newid]['datm'][0]) { $newid = $idx; } } unset($val); $other_order_conds = implode(' OR ', $other_order_conds); if (!empty($obval)) { // 有剩余订单间夜,构造新的订单 $datms = array_keys($obval); for ($idx = 0, $len = count($datms); $idx < $len; $idx++) { $oitem = array('room' => $older['o_rid'], 'lgth' => 1, 'datm' => array($datms[$idx]), 'date' => array(), 'time' => array(), 'pval' => array($datms[$idx] => $opval[$datms[$idx]]), 'bval' => array($datms[$idx] => $obval[$datms[$idx]])); while ($idx + 1 < $len && $datms[$idx] + 86400 == $datms[$idx + 1]) { $idx++; $oitem['lgth']++; $oitem['pval'][$datms[$idx]] = $opval[$datms[$idx]]; $oitem['bval'][$datms[$idx]] = $obval[$datms[$idx]]; } $oitem['datm'][1] = $oitem['datm'][0] + $oitem['lgth'] * 86400; $oitem['date'][0] = date('Y-m-d', $oitem['datm'][0]); $oitem['date'][1] = date('Y-m-d', $oitem['datm'][1]); $oitem['time'][0] = max($oitem['datm'][0] + $this->_hostel['h_checkin_time'], $older['o_btime']); $oitem['time'][1] = min($oitem['datm'][1] + $this->_hostel['h_checkout_time'], $older['o_etime']); if ($oitem['lgth'] < $this->_hostel['h_order_minlens']) { $this->flash(0, __('旅店仅支持创建天数介于 %d 到 %d 的订单', $this->_hostel['h_order_minlens'], $this->_hostel['h_order_maxlens'])); } $order[$osize] = $oitem; if ($oitem['datm'][0] <= $order[$newid]['datm'][0]) { $newid = $osize; } ++$osize; } } $oitem = $order[$newid]; $order = Zyon_Array::group($order, 'room'); $rooms = Zyon_Array::keyto($this->model('room')->getRoomAryByIds(array_keys($order)), 'r_id'); if (empty($rooms) || count($rooms) !== count($order)) { $this->flash(0, '找不到指定预订的房间'); } // 以下处理每个房间的停用段以及订单最长时间限制 foreach ($rooms as $rid => &$val) { if ($val['r_hid'] !== $this->_hostel['h_id']) { $this->flash(0, '找不到指定预订的房间'); } foreach ($order[$rid] as &$v) { $btime = $v['datm'][0]; $etime = $v['datm'][1] - 1; if ($btime < $val['r_otime']) { $this->flash(0, __('房间%s在%s之前尚未启用', $val['r_name'], date('Y-m-d', $val['r_otime']))); } for ($_btime = max($btime, $dtime + 86400 * $this->_hostel['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'])); } } } unset($v); } unset($val); // 加入原订单房间至房间集合 $rooms[$oroom['r_id']] = $oroom; // 以下处理订单集合内的冲突 foreach ($order as &$val) { foreach ($val as $k => &$v) { foreach ($val as $i => &$o) { if ($k !== $i && $k['time'][0] < $o['time'][1] && $k['time'][1] > $o['time'][0]) { $this->flash(0, __('房间%s的订单时间冲突,不能同时创建', $rooms[$v['room']]['r_name'])); } } unset($o); } unset($v); } unset($val); // 以下处理与系统订单的冲突 $other = $this->model('order')->getOrderAryByIds($this->model('order')->fetchIds(array('o_hid = ' . $this->_hostel['h_id'], 'o_id <> ' . $older['o_id'], 'o_status <> ' . $this->model('order')->quote(ORDER_STATUS_YQX), 'o_status <> ' . $this->model('order')->quote(ORDER_STATUS_YD), $other_order_conds))); if (!is_array($other)) { $this->flash(0, '无法获取系统订单的信息'); } if (!empty($other)) { foreach ($other as &$val) { $rid = $val['o_rid']; foreach ($order[$rid] as &$v) { if ($val['o_edatm'] == $v['datm'][0]) { $v['time'][0] = max($v['time'][0], $val['o_etime']); } if ($val['o_bdatm'] == $v['datm'][1]) { $v['time'][1] = min($v['time'][1], $val['o_btime']); } $_o_btime = max($v['datm'][0], $val['o_bdatm']); $_o_etime = min($v['datm'][1], $val['o_edatm']); while ($_o_btime < $_o_etime) { $this->flash(0, __('%s的房间%s已被其它订单占用', date('Y-m-d', $_o_btime), $rooms[$rid]['r_name'])); } } unset($v); } unset($val); } unset($other); // 从新订单中移除最靠近原订单入住时间的订单,以更改原订单时间实现 $oitem = $order[$oitem['room']][$newid]; unset($order[$oitem['room']][$newid]); --$osize; /** * 开启事务,创建订单 */ $this->model('order')->dbase()->beginTransaction(); try { $bvsum = array_sum($oitem['bval']); $pvsum = array_sum($oitem['pval']); // 缩短或者取消原订单,更新账单房费 if (!$this->model('order')->modOrder($older['o_id'], array('o_rid' => $oitem['room'], 'o_room' => $rooms[$oitem['room']]['r_name'], 'o_bdatm' => $oitem['datm'][0], 'o_edatm' => $oitem['datm'][1], 'o_btime' => $oitem['time'][0], 'o_etime' => $oitem['time'][1], 'o_brice' => $bvsum, 'o_price' => $pvsum, 'o_brices' => json_encode($oitem['bval']), 'o_prices' => json_encode($oitem['pval'])))) { throw new exception('更新原订单失败'); } if ($bvsum != $older['o_brice']) { if (!$this->model('bill')->modBill($older['o_bid'], array('b_cost' => $this->model('bill')->expr('b_cost + ' . ($bvsum - $older['o_brice']))))) { throw new exception('更新账单信息失败'); } $bill_old = $obill; if (!($obill = $this->model('bill')->getBill($older['o_bid']))) { throw new exception('读取账单信息失败'); } $this->model('log.bill')->addLog($this->model('log.bill')->getNewUpdateLog($this->_master, $bill_old, $obill, __('%d号订单房费 %d=>%d', $older['o_id'], $older['o_brice'] / 100, $bvsum / 100))); } $this->model('log.order')->addLog($this->model('log.order')->getNewUpdateLog($this->_master, $older, $older_new = $this->model('order')->getOrder($older['o_id']), __("房费明细\n[预计入住 %s=>%s, 间夜 %d=>%d, 成交房费 %d=>%d, 账单房费 %d=>%d]", date('Y-m-d H:i', $older['o_btime']), date('Y-m-d H:i', $oitem['time'][0]), ($older['o_edatm'] - $older['o_bdatm']) / 86400, ($oitem['datm'][1] - $oitem['datm'][0]) / 86400, $older['o_price'] / 100, $pvsum / 100, $older['o_brice'] / 100, $bvsum / 100))); // 如果原订单在住且更换房间,则更新房间状态 if ($older['o_rid'] != $oitem['room']) { $this->model('log.order')->addLog($this->model('log.order')->getNewChangeRoomLog($this->_master, $older, $this->model('order')->getOrder($older['o_id']))); if ($older['o_status'] == ORDER_STATUS_ZZ) { if ($rooms[$oitem['room']]['r_status'] != ROOM_STATUS_GJKF) { throw new exception('入住的目标房间状态不是干净空房'); } if (!$this->model('room')->modRoom($older['o_rid'], array('r_status' => ROOM_STATUS_GJKF)) || !$this->model('room')->modRoom($oitem['room'], array('r_status' => $rooms[$older['o_rid']]['r_status']))) { throw new exception('更新房间状态失败'); } $this->model('log.room')->addLog($this->model('log.room')->getNewUpdateStatusLog($this->_master, $rooms[$older['o_rid']], $this->model('room')->getRoom($older['o_rid']))); $this->model('log.room')->addLog($this->model('log.room')->getNewUpdateStatusLog($this->_master, $rooms[$oitem['room']], $this->model('room')->getRoom($oitem['room']))); } } if ($osize > 0) { // 获取原订单中的客人有效信息 $guest = array(); $guest['o_gbker_name'] = (string) $older['o_gbker_name']; $guest['o_gbker_phone'] = (string) $older['o_gbker_phone']; $guest['o_gbker_idtype'] = (string) $older['o_gbker_idtype']; $older['o_gbker_idno'] == '' or $guest['o_gbker_idno'] = $older['o_gbker_idno']; $older['o_gbker_email'] == '' or $guest['o_gbker_email'] = $older['o_gbker_email']; $guest['o_glver_name'] = (string) $older['o_glver_name']; $guest['o_glver_phone'] = (string) $older['o_glver_phone']; $guest['o_glver_idtype'] = (string) $older['o_glver_idtype']; $older['o_glver_idno'] == '' or $guest['o_glver_idno'] = $older['o_glver_idno']; $older['o_glver_email'] == '' or $guest['o_glver_email'] = $older['o_glver_email']; $obval = array(); foreach (array_keys($order) as $rid) { foreach ($order[$rid] as &$val) { $map = $this->model('order')->getNewOrder($rooms[$rid], $val['time'][0], $val['time'][1], json_encode($val['pval']), json_encode($val['bval']), $ostat); $map['o_bid'] = $older['o_bid']; $map['o_sid'] = $older['o_sid']; $map['o_snm'] = $older['o_snm']; $map['o_cid'] = $older['o_cid']; $map['o_cnm'] = $older['o_cnm']; $map['o_tid'] = $older['o_tid']; $map['o_tnm'] = $older['o_tnm']; $map['o_attr'] = $older['o_attr']; $map['o_memo'] = (string) $older['o_memo']; // 加入旅客信息 $map = array_merge($guest, $map); $oid = $this->model('order')->addOrder($map); if (!$oid) { throw new exception('创建订单记录失败'); } if ($map = $this->model('order')->getOrder($oid)) { $this->model('log.order')->addLog($this->model('log.order')->getNewCreateLog($this->_master, $map)); } $obval[$oid] = $map['o_brice']; } unset($val); } if (!$this->model('bill')->modBill($obill['b_id'], array('b_cost' => $this->model('bill')->expr('b_cost + ' . array_sum($obval))))) { throw new exception('更新账单信息失败'); } foreach ($obval as $idx => $val) { $obval[$idx] = __('%d号订单的账单房费 %d', $idx, $val / 100); } $this->model('log.bill')->addLog($this->model('log.bill')->getNewUpdateLog($this->_master, $obill, $this->model('bill')->getBill($obill['b_id']), implode(",\n", $obval))); } $this->model('order')->dbase()->commit(); $this->flash(1, array('forward' => "/master/bill/detail?bid={$obill['b_id']}")); } catch (Exception $e) { $this->model('order')->dbase()->rollBack(); $this->error($e); } $this->flash(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; }