public function book()
 {
     if ($_POST) {
         $token = $this->_get('token');
         // 检查是否需要短信验证码
         $enable_vcode = 0;
         $smsset = M('sms_set')->where(array('token' => $token))->find();
         if (!empty($smsset)) {
             if (strpos($smsset['function'], 'vchotel') !== FALSE) {
                 $enable_vcode = 1;
             }
         }
         $tel = $this->_post('tel');
         $smsvcode = $this->_post('smsvcode');
         if ($enable_vcode) {
             if (!SmsvcodeAction::verifyVCode($token, $tel, $smsvcode)) {
                 // 验证码不匹配
                 echo '{"success":0,"msg":"请输入正确的短信验证码。"}';
                 exit;
             }
         }
         $data['wecha_id'] = $this->_post('wecha_id');
         $data['book_people'] = $this->_post('truename');
         $data['remarks'] = $this->_post('remarks');
         $data['tel'] = $this->_post('tel');
         $data['book_num'] = $this->_post('nums');
         $data['book_time'] = strtotime($this->_post('dateline'));
         $data['book_lefttime'] = strtotime($this->_post('leftdateline'));
         $id = $this->_post('id');
         $data['room_type'] = $this->_post('roomtype');
         $data['order_status'] = 3;
         $data['hid'] = $this->_get('hid');
         $data['token'] = $this->_get('token');
         $data['submit_time'] = time();
         $data['sn'] = $this->get_order_sn();
         $data['room_id'] = $_POST['room_id'];
         // $data['payment']        = $_POST['payment'];
         $price = M('Hotel_room')->where(array('id' => $id, 'token' => $data['token'], 'hid' => $data['hid'], 'status' => 1))->find();
         //判断库存
         if ($price['open_inventory'] == 1 && $price['inventory'] < $data['book_num']) {
             echo '{"success":0,"msg":"库存不足,请联系商家!"}';
             exit;
         }
         $day = round(($data['leftbook_time'] - $data['book_time']) / 3600 / 24);
         if ($day <= 0) {
             $day = 1;
         }
         $data['price'] = $day * $price['yhprice'] * $data['book_num'];
         // $data['prepayment'] = $day* $price['sale_price'] * $data['book_num'];
         $data['text_cols'] = serialize($this->_post('text_cols'));
         $data['select_cols'] = serialize($this->_post('select_cols'));
         $order = M('Hotel_order')->data($data)->add();
         //若下单成功则减库存
         if ($order) {
             $booking['inventory'] = $price['inventory'] - $data['book_num'];
             M('Hotel_room')->where(array('id' => $id, 'token' => $data['token']))->data($booking)->save();
         }
         if ($order) {
             include LIB_PATH . 'Action/SmsSender.class.php';
             $smsSender = new SmsSender();
             $re = $smsSender->notify($this->_get('token'), "dingdan", "您有一个新的微预订:来自" . $data['book_people'] . ",预订商品:" . $data['room_type'] . ",预订时间:" . $this->_post('dateline'));
             echo '{"success":1,"msg":"恭喜,预定成功。"}';
         } else {
             echo '{"success":0,"msg":"请从新预定。"}';
         }
         exit;
     }
 }
 public function book()
 {
     // 检查是否需要短信验证码
     $token = $this->token;
     $enable_vcode = 0;
     $smsset = M('sms_set')->where(array('token' => $token))->find();
     if (!empty($smsset)) {
         if (strpos($smsset['function'], 'vccanyin') !== FALSE) {
             $enable_vcode = 1;
         }
     }
     $tel = $this->_post('tel');
     $smsvcode = $this->_post('smsvcode');
     if ($enable_vcode) {
         if (!SmsvcodeAction::verifyVCode($token, $tel, $smsvcode)) {
             // 验证码不匹配
             Log::save();
             $this->ajaxReturn("请输入正确的短信验证码!", "ERROR", 0);
         }
     }
     $menus = $this->_post('menus');
     $cart_id = $this->_post('cart_id');
     $username = $this->_post('username');
     $guestnum = $this->_post('guestnum');
     $note = $this->_post('note');
     $dinetime = $this->_post('dinetime');
     $where['id'] = $cart_id;
     //获取token以便发送短信提醒
     $order_info = M('dine_order')->join('tp_dine_rest on tp_dine_order.rest_id = tp_dine_rest.id')->where(array('tp_dine_order.id' => $cart_id))->field('tp_dine_rest.token,tp_dine_order.sn')->order('createtime desc')->find();
     $menus = htmlspecialchars_decode($menus);
     $menus = htmlspecialchars_decode($menus);
     $jmenus = json_decode($menus, true);
     $price = 0;
     $dishnum = count($jmenus);
     $dishname = '';
     for ($j = 0; $j < count($jmenus); $j++) {
         $price += (double) $jmenus[$j]['price'] * (int) $jmenus[$j]['nums'];
         $dishname .= $jmenus[$j]['name'] . ' ';
     }
     $data['price'] = $price;
     $data['tel'] = $tel;
     $data['username'] = $username;
     $data['menus'] = $menus;
     $data['status'] = 2;
     $data['submittime'] = time();
     $data['guestnum'] = $guestnum;
     $data['note'] = $note;
     $data['dinetime'] = $dinetime;
     $data['dishnum'] = $dishnum;
     $data['table'] = $this->_post('table');
     $order = M('dine_order')->where($where)->save($data);
     if ($order) {
         include LIB_PATH . 'Action/SmsSender.class.php';
         // 获得公司名字, 作为短信落款
         $company = '';
         $merchant = M('wxuser')->where(array('token' => $this->token, 'status' => 1))->field('company')->find();
         if (empty($merchant['company'])) {
             $company = "领众科技";
         } else {
             $company = $merchant['company'];
         }
         $smsSender = new SmsSender();
         $notify_tmpl = C('dine_notify');
         if (isset($notify_tmpl)) {
             $smsContent = str_replace("#merchant#", $company, $notify_tmpl);
             $smsContent = str_replace("#username#", $data['username'], $smsContent);
             $smsContent = str_replace("#tel#", $data['tel'], $smsContent);
             $smsContent = str_replace("#dinetime#", $data['dinetime'], $smsContent);
             $smsContent = str_replace("#guestnum#", $data['guestnum'], $smsContent);
             $smsContent = str_replace("#dishnum#", $data['dishnum'], $smsContent);
             $smsContent = str_replace("#sn#", $order_info['sn'], $smsContent);
             $smsContent = str_replace("#menus#", $dishname, $smsContent);
             if ($data['table']) {
                 $table_info = $data['table'] . "号桌";
                 $smsContent = str_replace("#table#", $table_info, $smsContent);
             } else {
                 $smsContent = str_replace("#table#", '桌号无', $smsContent);
             }
             $res = $smsSender->notify($order_info['token'], "canyin_order", $smsContent);
             $this->ajaxReturn($order, "OK", 1);
         }
     } else {
         $this->ajaxReturn("服务器繁忙,订单生成失败,请稍后再试!", "ERROR", 0);
     }
 }
 public function book()
 {
     if ($_POST['action'] == 'book') {
         $token = $this->_get('token');
         // 检查是否需要短信验证码
         $enable_vcode = 0;
         $smsset = M('sms_set')->where(array('token' => $token))->find();
         if (!empty($smsset)) {
             if (strpos($smsset['function'], 'vcdindan') !== FALSE) {
                 $enable_vcode = 1;
             }
         }
         $tel = $this->_post('tel');
         $smsvcode = $this->_post('smsvcode');
         if ($enable_vcode) {
             if (!SmsvcodeAction::verifyVCode($token, $tel, $smsvcode)) {
                 // 验证码不匹配
                 echo '{"success":0,"msg":"请输入正确的短信验证码。"}';
                 exit;
             }
         }
         $data['wecha_id'] = $this->_post('wecha_id');
         $data['book_people'] = $this->_post('truename');
         $data['remarks'] = $this->_post('remarks');
         $data['tel'] = $this->_post('tel');
         $data['book_num'] = $this->_post('nums');
         $data['book_time'] = strtotime($this->_post('dateline'));
         $id = $this->_post('id');
         $data['room_type'] = $this->_post('roomtype');
         $data['order_status'] = 3;
         $data['hid'] = $this->_get('hid');
         $data['booking_id'] = $this->_post('id');
         $data['token'] = $this->_get('token');
         $data['submit_time'] = time();
         $data['sn'] = $this->get_order_sn();
         $price = M('Host_list_add')->where(array('id' => $id, 'token' => $data['token'], 'hid' => $data['hid'], 'status' => 1))->find();
         //判断库存
         if ($price['open_inventory'] == 1 && $price['inventory'] < $data['book_num']) {
             echo '{"success":0,"msg":"库存不足,请联系商家!"}';
             exit;
         }
         $data['price'] = $price['yhprice'] * $data['book_num'];
         $data['text_cols'] = serialize($this->_post('text_cols'));
         $data['select_cols'] = serialize($this->_post('select_cols'));
         $order = M('Host_order')->data($data)->add();
         //若下单成功则减库存
         if ($price['open_inventory'] == 1 && $order) {
             $booking['inventory'] = $price['inventory'] - $data['book_num'];
             M('host_list_add')->where(array('id' => $id, 'token' => $data['token']))->data($booking)->save();
         }
         if ($order) {
             include LIB_PATH . 'Action/SmsSender.class.php';
             $smsSender = new SmsSender();
             $notify_tmpl = C('host_notify');
             $smsContent = '';
             if (isset($notify_tmpl)) {
                 $smsContent = str_replace("#merchant#", '领众科技', $notify_tmpl);
                 $smsContent = str_replace("#book_people#", $data['book_people'], $smsContent);
                 $smsContent = str_replace("#tel#", $data['tel'], $smsContent);
                 $smsContent = str_replace("#room_type#", $data['room_type'], $smsContent);
                 $smsContent = str_replace("#book_num#", $data['book_num'], $smsContent);
                 $smsContent = str_replace("#dateline#", $this->_post('dateline'), $smsContent);
                 $smsContent = str_replace("#price#", $data['price'], $smsContent);
                 $smsContent = str_replace("#sn#", $data['sn'], $smsContent);
             }
             if ($smsContent != '') {
                 $re = $smsSender->notify($this->_get('token'), "dingdan", $smsContent);
             }
             echo '{"success":1,"msg":"恭喜,预定成功。"}';
         } else {
             echo '{"success":0,"msg":"系统忙,请稍后预定。"}';
         }
         exit;
     }
 }