Ejemplo n.º 1
0
 public function doMobileOrder()
 {
     global $_GPC, $_W;
     $this->check_login();
     $paysetting = uni_setting($_W['uniacid'], array('payment', 'creditbehaviors'));
     $_W['account'] = array_merge($_W['account'], $paysetting);
     $isauto = $this->_user_info['isauto'];
     $hid = intval($_GPC['hid']);
     $id = intval($_GPC['id']);
     $weid = $this->_weid;
     $price = $_GPC['price'];
     if (empty($hid) || empty($id)) {
         message("参数错误1!");
     }
     $search_array = $this->getSearchArray();
     if (!$search_array || empty($search_array['btime']) || empty($search_array['day'])) {
         $url = $this->createMobileUrl('index');
         header("Location: {$url}");
     }
     $is_submit = checksubmit();
     $sql = 'SELECT `title`, `mail`, `phone`, `thumb`, `description` FROM ' . tablename('hotel2') . ' WHERE `id` = :id';
     $reply = pdo_fetch($sql, array(':id' => $hid));
     if (empty($reply)) {
         if ($is_submit) {
             die(json_encode(array("result" => 0, "error" => "酒店未找到!")));
         } else {
             message('酒店未找到, 请联系管理员!');
         }
     }
     // 设置分享信息
     $shareTitle = $reply['title'];
     $shareDesc = $reply['description'];
     $shareThumb = tomedia($reply['thumb']);
     if ($this->_set_info['is_unify'] == 1) {
         $tel = $this->_set_info['tel'];
     } else {
         $tel = $reply['phone'];
     }
     $pricefield = $this->_user_info['isauto'] == 1 ? 'cprice' : 'mprice';
     $sql = "SELECT *, {$pricefield} AS roomprice FROM " . tablename('hotel2_room') . " WHERE `id` = :id AND `hotelid` = :hotelid ";
     $room = pdo_fetch($sql, array(':id' => $id, ':hotelid' => $hid));
     if (empty($room)) {
         if ($is_submit) {
             die(json_encode(array("result" => 0, "error" => "房型未找到!")));
         } else {
             message("房型未找到, 请联系管理员!");
         }
     }
     // 入住
     $btime = $search_array['btime'];
     $bdate = $search_array['bdate'];
     // 住几天
     $days = intval($search_array['day']);
     // 离店
     $etime = $search_array['etime'];
     $edate = $search_array['edate'];
     $date_array = array();
     $date_array[0]['date'] = $bdate;
     $date_array[0]['day'] = date('j', $btime);
     $date_array[0]['time'] = $btime;
     $date_array[0]['month'] = date('m', $btime);
     if ($days > 1) {
         for ($i = 1; $i < $days; $i++) {
             $date_array[$i]['time'] = $date_array[$i - 1]['time'] + 86400;
             $date_array[$i]['date'] = date('Y-m-d', $date_array[$i]['time']);
             $date_array[$i]['day'] = date('j', $date_array[$i]['time']);
             $date_array[$i]['month'] = date('m', $date_array[$i]['time']);
         }
     }
     $sql = 'SELECT `id`, `roomdate`, `num`, `status` FROM ' . tablename('hotel2_room_price') . ' WHERE `roomid` = :roomid
             AND `roomdate` >= :btime AND `roomdate` < :etime AND `status` = :status';
     $params = array(':roomid' => $id, ':btime' => $btime, ':etime' => $etime, ':status' => '1');
     $room_date_list = pdo_fetchall($sql, $params);
     $flag = intval($room_date_list);
     $list = array();
     $max_room = 8;
     $is_order = 1;
     if ($flag == 1) {
         for ($i = 0; $i < $days; $i++) {
             $k = $date_array[$i]['time'];
             foreach ($room_date_list as $p_key => $p_value) {
                 // 判断价格表中是否有当天的数据
                 if ($p_value['roomdate'] == $k) {
                     $room_num = $p_value['num'];
                     if (empty($room_num)) {
                         $is_order = 0;
                         $max_room = 0;
                         $list['num'] = 0;
                         $list['date'] = $date_array[$i]['date'];
                     } else {
                         if ($room_num > 0 && $room_num < $max_room) {
                             $max_room = $room_num;
                             $list['num'] = $room_num;
                             $list['date'] = $date_array[$i]['date'];
                         }
                     }
                     break;
                 }
             }
         }
     }
     if ($max_room == 0) {
         $msg = $list['date'] . '当天没有空房间了,请选择其他房型。';
         $url = $this->createMobileUrl('error', array('msg' => $msg));
         header("Location: {$url}");
         exit;
     }
     $user_info = hotel_get_userinfo();
     $memberid = intval($user_info['id']);
     // 显示会员价还是普通价
     $pricefield = $isauto == 1 ? 'cprice' : 'mprice';
     $r_sql = 'SELECT `roomdate`, `num`, `status`, ' . $pricefield . ' AS `m_price` FROM ' . tablename('hotel2_room_price') . ' WHERE `roomid` = :roomid AND `weid` = :weid AND `hotelid` = :hotelid AND `roomdate` >= :btime AND ' . ' `roomdate` < :etime';
     $params = array(':roomid' => $id, ':weid' => $weid, ':hotelid' => $hid, ':btime' => $btime, ':etime' => $etime);
     $price_list = pdo_fetchall($r_sql, $params);
     $this_price = $old_price = $room['roomprice'];
     $totalprice = $old_price * $days;
     if ($price_list) {
         //价格表中存在
         $check_date = array();
         foreach ($price_list as $k => $v) {
             $new_price = $v['m_price'];
             $roomdate = $v['roomdate'];
             if ($v['status'] == 0 || $v['num'] == 0) {
                 $has = 0;
             } else {
                 if ($new_price && $roomdate) {
                     if (!in_array($roomdate, $check_date)) {
                         $check_date[] = $roomdate;
                         if ($old_price != $new_price) {
                             $totalprice = $totalprice - $old_price + $new_price;
                         }
                     }
                 }
             }
         }
         $this_price = round($totalprice / $days);
     }
     if ($is_submit) {
         $from_user = $this->_from_user;
         $name = $_GPC['uname'];
         $contact_name = $_GPC['contact_name'];
         $mobile = $_GPC['mobile'];
         if (empty($name)) {
             die(json_encode(array("result" => 0, "error" => "入住人不能为空!")));
         }
         if (empty($contact_name)) {
             die(json_encode(array("result" => 0, "error" => "联系人不能为空!")));
         }
         if (empty($mobile)) {
             die(json_encode(array("result" => 0, "error" => "手机号不能为空!")));
         }
         if ($_GPC['nums'] > $max_room) {
             die(json_encode(array("result" => 0, "error" => "您的预定数量超过最大限制!")));
         }
         $insert = array('weid' => $weid, 'ordersn' => date('md') . sprintf("%04d", $_W['fans']['id']) . random(4, 1), 'hotelid' => $hid, 'openid' => $from_user, 'roomid' => $id, 'memberid' => $memberid, 'name' => $name, 'contact_name' => $contact_name, 'mobile' => $mobile, 'btime' => $search_array['btime'], 'etime' => $search_array['etime'], 'day' => $search_array['day'], 'style' => $room['title'], 'nums' => intval($_GPC['nums']), 'oprice' => $room['oprice'], 'cprice' => $room['cprice'], 'mprice' => $room['mprice'], 'time' => TIMESTAMP, 'paytype' => $_GPC['paytype']);
         $insert[$pricefield] = $this_price;
         $insert['sum_price'] = $totalprice * $insert['nums'];
         pdo_insert('hotel2_order', $insert);
         $order_id = pdo_insertid();
         //如果有接受订单的邮件,
         if (!empty($reply['mail'])) {
             $subject = "微信公共帐号 [" . $_W['account']['name'] . "] 微酒店订单提醒.";
             $body = "您后台有一个预定订单: <br/><br/>";
             $body .= "预定酒店: " . $reply['title'] . "<br/>";
             $body .= "预定房型: " . $room['title'] . "<br/>";
             $body .= "预定数量: " . $insert['nums'] . "<br/>";
             $body .= "预定价格: " . $insert['sum_price'] . "<br/>";
             $body .= "预定人: " . $insert['name'] . "<br/>";
             $body .= "预定电话: " . $insert['mobile'] . "<br/>";
             $body .= "到店时间: " . $bdate . "<br/>";
             $body .= "离店时间: " . $edate . "<br/><br/>";
             $body .= "请您到管理后台仔细查看. <a href='" . $_W['siteroot'] . create_url('member/login') . "' target='_blank'>立即登录后台</a>";
             load()->func('communication');
             $result = ihttp_email($reply['mail'], $subject, $body);
             if ($insert['paytype'] == '3') {
                 global $_GPC, $_W;
                 $weid = $this->_weid;
                 $sql = 'SELECT * FROM ' . tablename('hotel2_order') . ' WHERE id = :id AND weid = :weid';
                 $order = pdo_fetch($sql, array(':id' => $order_id, ':weid' => $weid));
                 $sql = 'SELECT email FROM ' . tablename('hotel2_set') . ' WHERE weid = :weid';
                 $setInfo = pdo_fetch($sql, array(':weid' => $_W['uniacid']));
                 if ($setInfo['email']) {
                     $body = "<h3>酒店订单</h3> <br />";
                     $body .= '订单编号:' . $order['ordersn'] . '<br />';
                     $body .= '姓名:' . $order['name'] . '<br />';
                     $body .= '手机:' . $order['mobile'] . '<br />';
                     $body .= '房型:' . $order['style'] . '<br />';
                     $body .= '订购数量' . $order['nums'] . '<br />';
                     $body .= '原价:' . $order['oprice'] . '<br />';
                     $body .= '会员价:' . $order['mprice'] . '<br />';
                     $body .= '入住日期:' . date('Y-m-d', $order['btime']) . '<br />';
                     $body .= '退房日期:' . date('Y-m-d', $order['etime']) . '<br />';
                     $body .= '总价:' . $order['sum_price'];
                     // 发送邮件提醒
                     if (!empty($setInfo['email'])) {
                         load()->func('communication');
                         ihttp_email($setInfo['email'], '微酒店订单提醒', $body);
                     }
                 }
             }
         }
         $url = $this->createMobileUrl('orderdetail', array('id' => $order_id));
         die(json_encode(array("result" => 1, "url" => $url)));
     } else {
         $price = $totalprice;
         $member = array();
         $member['from_user'] = $this->_from_user;
         $record = hotel_member_single($member);
         if ($record) {
             $realname = $record['realname'];
             $mobile = $record['mobile'];
         } else {
             $fans = pdo_fetch("SELECT id, realname, mobile FROM " . tablename('fans') . " WHERE from_user = :from_user limit 1", array(':from_user' => $this->_from_user));
             if (!empty($fans)) {
                 $realname = $fans['realname'];
                 $mobile = $fans['mobile'];
             }
         }
         include $this->template('order');
     }
 }
Ejemplo n.º 2
0
 public function doMobileOrder()
 {
     global $_GPC, $_W;
     $this->check_login();
     $isauto = $this->_user_info['isauto'];
     $hid = $_GPC['hid'];
     $id = $_GPC['id'];
     $weid = $this->_weid;
     $price = $_GPC['price'];
     //$total_price = $_GPC['total_price'];
     if (empty($hid) || empty($id)) {
         message("参数错误1!");
     }
     $search_array = $this->getSearchArray();
     if (!$search_array || empty($search_array['btime']) || empty($search_array['day'])) {
         $url = $this->createMobileUrl('index');
         header("Location: {$url}");
     }
     $is_submit = checksubmit();
     $reply = pdo_fetch("SELECT title,mail FROM " . tablename('hotel2') . " WHERE id = :id ", array(':id' => $hid));
     if (empty($reply)) {
         if ($is_submit) {
             die(json_encode(array("result" => 0, "error" => "酒店未找到!")));
         } else {
             message("酒店未找到, 请联系管理员!");
         }
     }
     $pricefield = $this->_user_info['isauto'] == 1 ? "cprice" : "mprice";
     $room = pdo_fetch("SELECT *, {$pricefield} as roomprice FROM " . tablename('hotel2_room') . " WHERE id = :id AND hotelid = :hotelid ", array(':id' => $id, ':hotelid' => $hid));
     if (empty($room)) {
         if ($is_submit) {
             die(json_encode(array("result" => 0, "error" => "房型未找到!")));
         } else {
             message("房型未找到, 请联系管理员!");
         }
     }
     //入住
     $btime = $search_array['btime'];
     $bdate = $search_array['bdate'];
     //住几天
     $days = intval($search_array['day']);
     //离店
     $etime = $search_array['etime'];
     $edate = $search_array['edate'];
     $date_array = array();
     $date_array[0]['date'] = $bdate;
     $date_array[0]['day'] = date('j', $btime);
     $date_array[0]['time'] = $btime;
     $date_array[0]['month'] = date('m', $btime);
     if ($days > 1) {
         for ($i = 1; $i < $days; $i++) {
             $date_array[$i]['time'] = $date_array[$i - 1]['time'] + 86400;
             $date_array[$i]['date'] = date('Y-m-d', $date_array[$i]['time']);
             $date_array[$i]['day'] = date('j', $date_array[$i]['time']);
             $date_array[$i]['month'] = date('m', $date_array[$i]['time']);
         }
     }
     $sql = "SELECT id, roomdate, num, status FROM " . tablename('hotel2_room_price');
     $sql .= " WHERE 1 = 1";
     $sql .= " AND roomid = :roomid";
     $sql .= " AND roomdate >= :btime AND roomdate < :etime";
     $sql .= " AND status = 1";
     $params[':roomid'] = $id;
     $params[':btime'] = $btime;
     $params[':etime'] = $etime;
     $room_date_list = pdo_fetchall($sql, $params);
     //print_r($room_date_list);exit;
     if ($room_date_list) {
         $flag = 1;
     } else {
         $flag = 0;
     }
     $list = array();
     $max_room = 8;
     $is_order = 1;
     if ($flag == 1) {
         for ($i = 0; $i < $days; $i++) {
             $k = $date_array[$i]['time'];
             foreach ($room_date_list as $p_key => $p_value) {
                 //判断价格表中是否有当天的数据
                 if ($p_value['roomdate'] == $k) {
                     $room_num = $p_value['num'];
                     if (empty($room_num)) {
                         $is_order = 0;
                         $max_room = 0;
                         $list['num'] = 0;
                         $list['date'] = $date_array[$i]['date'];
                     } else {
                         if ($room_num > 0 && $room_num < $max_room) {
                             $max_room = $room_num;
                             $list['num'] = $room_num;
                             $list['date'] = $date_array[$i]['date'];
                         }
                     }
                     break;
                 }
             }
         }
     }
     if ($max_room == 0) {
         $msg = $list['date'] . '当天没有空房间了,请选择其他房型。';
         $url = $this->createMobileUrl('error', array('msg' => $msg));
         header("Location: {$url}");
         exit;
     }
     $user_info = hotel_get_userinfo();
     if (empty($user_info['id'])) {
         $memberid = 0;
     } else {
         $memberid = $user_info['id'];
     }
     //显示会员价还是普通价
     $pricefield = $isauto == 1 ? "cprice" : "mprice";
     $params = array(":weid" => $weid, ":hotelid" => $hid);
     $r_sql = "SELECT roomdate, num, status, " . $pricefield . " as m_price FROM " . tablename('hotel2_room_price');
     $r_sql .= " WHERE 1 = 1";
     $r_sql .= " AND roomid = " . $id;
     $r_sql .= " AND weid = :weid";
     $r_sql .= " AND hotelid = :hotelid";
     $r_sql .= " AND roomdate >=" . $btime . " AND roomdate <" . $etime;
     $price_list = pdo_fetchall($r_sql, $params);
     $this_price = $old_price = $room['roomprice'];
     $totalprice = $old_price * $days;
     if ($price_list) {
         //价格表中存在
         $check_date = array();
         foreach ($price_list as $k => $v) {
             $new_price = $v['m_price'];
             $roomdate = $v['roomdate'];
             if ($v['status'] == 0 || $v['num'] == 0) {
                 $has = 0;
             } else {
                 if ($new_price && $roomdate) {
                     if (!in_array($roomdate, $check_date)) {
                         $check_date[] = $roomdate;
                         if ($old_price != $new_price) {
                             $totalprice = $totalprice - $old_price + $new_price;
                         }
                     }
                 }
             }
         }
         $this_price = round($totalprice / $days);
     }
     //print_r($this_price);exit;
     if ($is_submit) {
         $from_user = $this->_from_user;
         $name = $_GPC['uname'];
         $contact_name = $_GPC['contact_name'];
         $mobile = $_GPC['mobile'];
         if (empty($name)) {
             die(json_encode(array("result" => 0, "error" => "入住人不能为空!")));
         }
         if (empty($contact_name)) {
             die(json_encode(array("result" => 0, "error" => "联系人不能为空!")));
         }
         if (empty($mobile)) {
             die(json_encode(array("result" => 0, "error" => "手机号不能为空!")));
         }
         if ($_GPC['nums'] > $max_room) {
             die(json_encode(array("result" => 0, "error" => "您的预定数量超过最大限制!")));
         }
         $data = array('realname' => $name, 'mobile' => $mobile);
         fans_update($from_user, $data);
         pdo_update("hotel2_member", $data, array("from_user" => $from_user));
         $insert = array('weid' => $weid, 'ordersn' => date('md') . sprintf("%04d", $_W['fans']['id']) . random(4, 1), 'hotelid' => $hid, 'openid' => $from_user, 'roomid' => $id, 'memberid' => $memberid, 'name' => $name, 'contact_name' => $contact_name, 'mobile' => $mobile, 'btime' => $search_array['btime'], 'etime' => $search_array['etime'], 'day' => $search_array['day'], 'style' => $room['title'], 'nums' => intval($_GPC['nums']), 'oprice' => $room['oprice'], 'cprice' => $room['cprice'], 'mprice' => $room['mprice'], 'time' => time(), 'paytype' => $_GPC['paytype']);
         $insert[$pricefield] = $this_price;
         $insert['sum_price'] = $totalprice * $insert['nums'];
         //            $is_repeat = check_orderinfo($insert);
         //            if ($is_repeat == 1){
         //                die(json_encode(array("result" => 0, "error" => "您已经预定成功,请不要重复提交")));
         //            }
         pdo_insert('hotel2_order', $insert);
         $order_id = pdo_insertid();
         //如果有接受订单的邮件,
         if (!empty($reply['mail'])) {
             $subject = "微信公共帐号 [" . $_W['account']['name'] . "] 微酒店订单提醒.";
             $body = "您后台有一个预定订单: <br/><br/>";
             $body .= "预定酒店: " . $reply['title'] . "<br/>";
             $body .= "预定房型: " . $room['title'] . "<br/>";
             $body .= "预定数量: " . $insert['nums'] . "<br/>";
             $body .= "预定价格: " . $insert['sum_price'] . "<br/>";
             $body .= "预定人: " . $insert['name'] . "<br/>";
             $body .= "预定电话: " . $insert['mobile'] . "<br/>";
             $body .= "到店时间: " . $bdate . "<br/>";
             $body .= "离店时间: " . $edate . "<br/><br/>";
             //$body .= "到店时间: " . $_GPC['btime'] . "<br/>";
             //$body .= "离店时间: " . $_GPC['btime'] . "<br/><br/>";
             $body .= "请您到管理后台仔细查看. <a href='" . $_W['siteroot'] . create_url('member/login') . "' target='_blank'>立即登录后台</a>";
             $result = ihttp_email($reply['mail'], $subject, $body);
         }
         //$url = $this->createMobileUrl('index');
         $url = $this->createMobileUrl('orderdetail', array('id' => $order_id));
         die(json_encode(array("result" => 1, "url" => $url)));
     } else {
         $price = $totalprice;
         $member = array();
         $member['from_user'] = $this->_from_user;
         $record = hotel_member_single($member);
         if ($record) {
             $realname = $record['realname'];
             $mobile = $record['mobile'];
         } else {
             $fans = pdo_fetch("SELECT id, realname, mobile FROM " . tablename('fans') . " WHERE from_user = :from_user limit 1", array(':from_user' => $this->_from_user));
             if (!empty($fans)) {
                 $realname = $fans['realname'];
                 $mobile = $fans['mobile'];
             }
         }
         include $this->template('order');
     }
 }