getRunInfo($run_id); if (!$run_info['flag']) { return $run_info; } $BaseService = new BaseService(); $poi_info = $BaseService->getPoiInfoArr(); $poi_info = $poi_info['poi_info']; $run['run_id'] = $run_info['data']['run_id']; $run['start_area_id'] = $start_area_id; $run['start_area_name'] = $poi_info[$start_area_id]['area_name']; $run['end_area_id'] = $end_area_id; $run['end_area_name'] = $poi_info[$end_area_id]['area_name']; $run['run_date'] = $run_info['data']['run_date']; $run['run_time'] = $run_info['data']['run_time']; //获取上车站点 $start_station = $this->getStartStation($run_id, $start_area_id); if (!$start_station['flag']) { return $start_station; } $start_res_arr = $start_station['data']; $run['start_res_arr'] = $start_res_arr; //获取默认选中的上车站 $start_res_id = $start_res_arr[0]['res_id']; $run['select_start_res']['res_id'] = $start_res_arr[0]['res_id']; $run['select_start_res']['res_name'] = $start_res_arr[0]['res_name']; $run['select_start_res']['res_time'] = $start_res_arr[0]['res_time']; //获取下车站点 $end_station = $this->getEndStation($run_id, $run_id, $start_res_id, $end_area_id); if (!$end_station['flag']) { return $end_station; } $end_res_arr = $end_station['data']; $run['end_res_arr'] = $end_res_arr; //获取默认选中的上车站 $end_res_id = $end_res_arr[0]['res_id']; $run['select_end_res']['res_id'] = $end_res_arr[0]['res_id']; $run['select_end_res']['res_name'] = $end_res_arr[0]['res_name']; $run['select_end_res']['res_time'] = $end_res_arr[0]['res_time']; //获取票种信息 $ticket_info = $this->getTicketInfo($run_id, $start_res_id, $end_res_id); if (!$ticket_info['flag']) { return $ticket_info; } $ticket_info = $ticket_info['data']; //处理票种详情 $ticket_info = $this->execTicket($ticket_info); //获取票种id $ticket_id = $ticket_info['ticket_id']; //获取优惠价 $discount_price = $this->getDiscountPrice($ticket_id, $channel_id); if (!$discount_price['flag']) { return $discount_price; } $discount_price = $discount_price['data']; if (count($discount_price) == 0) { $discount_price = '0'; } else { $discount_price = $discount_price['off_value']; } $ticket_info['discount_price'] = $discount_price; $run['ticket_info'] = $ticket_info; return Util::returnArrSu('', $run); } /** * Function Description:通过上车站点获取初始化数据 * Function Name: getRunDetailByStart * @param $run_id * @param $start_res_id * @param $end_area_id * @param $channel_id * * @return array|mixed|string * * @author 张帅 */ public function getRunDetailByStart($run_id, $start_res_id, $end_area_id, $channel_id) { //获取下车站点 $end_station = $this->getEndStation($run_id, $run_id, $start_res_id, $end_area_id); if (!$end_station['flag']) { return $end_station; } $end_res_arr = $end_station['data']; $run['end_res_arr'] = $end_res_arr; //获取默认选中的上车站 $end_res_id = $end_res_arr[0]['res_id']; $run['select_end_res']['res_id'] = $end_res_arr[0]['res_id']; $run['select_end_res']['res_name'] = $end_res_arr[0]['res_name']; $run['select_end_res']['res_time'] = $end_res_arr[0]['res_time']; //获取票种信息 $ticket_info = $this->getTicketInfo($run_id, $start_res_id, $end_res_id); if (!$ticket_info['flag']) { return $ticket_info; } $ticket_info = $ticket_info['data']; //处理票种详情 $ticket_info = $this->execTicket($ticket_info); //获取票种id $ticket_id = $ticket_info['ticket_id']; //获取优惠价 $discount_price = $this->getDiscountPrice($ticket_id, $channel_id); if (!$discount_price['flag']) { return $discount_price; } $discount_price = $discount_price['data']; if (count($discount_price) == 0) { $discount_price = '0'; } else { $discount_price = $discount_price['off_value']; } $ticket_info['discount_price'] = $discount_price; $run['ticket_info'] = $ticket_info; return Util::returnArrSu('', $run); } /** * Function Description:通过下车站点获取初始化数据 * Function Name: getRunDetailByEnd * @param $run_id * @param $start_res_id * @param $end_res_id * @param $channel_id * * @return array|mixed|string * * @author 张帅 */ public function getRunDetailByEnd($run_id, $start_res_id, $end_res_id, $channel_id) { //获取票种信息 $ticket_info = $this->getTicketInfo($run_id, $start_res_id, $end_res_id); if (!$ticket_info['flag']) { return $ticket_info; } $ticket_info = $ticket_info['data']; //处理票种详情 $ticket_info = $this->execTicket($ticket_info); //获取票种id $ticket_id = $ticket_info['ticket_id']; //获取优惠价 $discount_price = $this->getDiscountPrice($ticket_id, $channel_id); if (!$discount_price['flag']) { return $discount_price; } $discount_price = $discount_price['data']; if (count($discount_price) == 0) { $discount_price = '0'; } else { $discount_price = $discount_price['off_value']; } $ticket_info['discount_price'] = $discount_price; $run['ticket_info'] = $ticket_info; return Util::returnArrSu('', $run); } /** * Function Description:获取班次信息详情 * Function Name: getRunInfo * @param $run_id * * @return mixed * * @author 张帅 */ public function getRunInfo($run_id) { $run_main = new RunMain(); $run_info = $run_main->getRunDetail($run_id); return $run_info; } /** * Function Description:获取上车站点数据 * Function Name: getStartStation * @param $run_id * @param $start_area_id * * @return array * * @author 张帅 */ public function getStartStation($run_id, $start_area_id) { $run_main = new RunMain(); $start_station = $run_main->getStartStation($run_id, $start_area_id); return $start_station; } /** * Function Description:获取下车站点数据 * Function Name: getEndStation * @param $run_id * @param $run_id * @param $start_res_id * @param $end_area_id * * @return array * * @author 张帅 */ public function getEndStation($run_id, $run_id, $start_res_id, $end_area_id) { $run_main = new RunMain(); $end_station = $run_main->getEndStation($run_id, $start_res_id, $end_area_id); return $end_station; } /** * Function Description:获取票种信息 * Function Name: getTicketInfo * @param $run_id * @param $start_res_id * @param $end_res_id * * @return array * * @author 张帅 */ public function getTicketInfo($run_id, $start_res_id, $end_res_id) { $run_main = new RunMain(); $ticket_info = $run_main->getTicketInfo($run_id, $start_res_id, $end_res_id); return $ticket_info; } /** * Function Description:获取优惠价格 * Function Name: getDiscountPrice * @param $ticket_id * @param $channel_id * * @return array * * @author 张帅 */ public function getDiscountPrice($ticket_id, $channel_id) { $run_main = new RunMain(); $discount_price = $run_main->getDiscountPrice($ticket_id, $channel_id); return $discount_price; } /** * Function Description: * Function Name: execTicket * @param $ticket_info * * @return mixed * * @author 倪宗锋 */ public function execTicket($ticket_info) { $time_diff = strtotime($ticket_info['end_time']) - strtotime($ticket_info['start_time']); $remain = $time_diff % 86400; if ($remain <= 0) { $remain = 24 * 3600 + $remain; } $hours = intval($remain / 3600); $remain = $remain % 3600; $min = intval($remain / 60); $ticket_info['price'] = ceil($ticket_info['price']); $ticket_info['total_time'] = $hours . '时' . $min . '分'; unset($ticket_info['line_id']); unset($ticket_info['start_time']); unset($ticket_info['end_time']); return $ticket_info; } /** * Function Description:添加乘客人 * Function Name: addCustomer * @param $customer_name * @param $customer_id_card * * @return string * * @author 张帅 */ public function addCustomer($customer_name, $customer_id_card) { $we_user_id = LoginTool::$userId;//$_SESSION['we_user_id']; $wechat_customer = new WechatCustomer(); $result = $wechat_customer->addCustomer($customer_name, $customer_id_card, $we_user_id); return $result; } /** * Function Description:修改联系人信息 * Function Name: uptCustomer * @param $customer_name * @param $customer_id_card * @param $customer_id * * @return array * * @author 娄梦宁 */ public function uptCustomer($customer_name, $customer_id_card, $customer_id) { $wechat_customer = new WechatCustomer(); $result = $wechat_customer->uptCustomer($customer_name, $customer_id_card, $customer_id); return $result; } /** * Function Description:获取乘客人 * Function Name: getCustomerList * * @return string * * @author 张帅 */ public function getCustomerList() { $we_user_id = LoginTool::$userId;//$_SESSION['we_user_id']; $wechat_customer = new WechatCustomer(); $result = $wechat_customer->getCustomerList($we_user_id); return $result; } /** * Function Description:订单提交 * Function Name: submitOrder * @param $params * * @return array * * @author 倪宗锋 */ public function submitOrder($params) { //第一步 本地下单 //价格校验 // $getOrder = $this->getPrice($params['ticket_info'], $params['channel_id']); // if (!$getOrder) { // return Util::returnArrEr('订票失败'); // } $result = $this->addOrder($params); $orderId = $result['data']; if (!$result['flag'] && !empty($result['data'])) { //如果下单失败,执行退票操作 $this->cancelOrder($orderId); return Util::returnArrEr($result['msg']); } //本地下单成功后 则前往微信下单 //如果是M站 web 则跳转 if ($params['pay_type'] == '278') { //跳转地址 用于网页跳转 $url = 'http://wx.zhizhuchuxing.com/wechat/WxPay/realpay/weChatShopPay.php?order_id=' . $orderId; //记录下单日志 OrderLog::addOrder($orderId, 2); return Util::returnArrSu('', '', $url); } //否则就是app站点 则调用微信下单接口 并获取返回值` $wxPayService = new WxPayService(); $result = $wxPayService->unifiedOrderByOrderId($orderId);//去微信下单并获取返回值 if ($result['flag'] == true) {//记录下单日志 OrderLog::addOrder($orderId, 2); } return $result; } /** * Function Description:添加订单 服务器数据库添加订单信息 * Function Name: addOrder * @param $params * * @return array * * @author 张帅 */ public function addOrder($params) { $base_supplier = new BaseSupplier(); $member_id = LoginTool::$userId; //1.获取业务员 $salesman = $base_supplier->getSalesman($params['channel_id']); if (!$salesman['flag']) { return $salesman; } $params['salesman'] = $salesman['data']['sales_man']; //2.提交订单 $order_main = new OrderMain(); $order_id = $order_main->submitOrder($params); if (!$order_id['flag']) { return $order_id; } //3.获取订单号 $order_id = $order_id['data']; //4.更新订单order_book_status $order_book_status_result = $order_main->updateBookStatus($order_id); if (!$order_book_status_result['flag']) { return $order_book_status_result; } //5.如果是往返订单,把订单手机城数组 $order_id3 = explode(',', $order_id); if (count($order_id3) > 1) { $order_id1 = $order_id3[0];//去程订单 $order_id2 = $order_id3[1];//返程订单 //将往返订单连接起来 $result = $order_main->linkOrder($order_id1, $order_id2); if (!$result) { return Util::returnArrEr('订单连接失败', $order_id1); } } else { $order_id1 = $order_id3[0];//单程订单 } //6.修改订单的会员id $member_result = $order_main->updateMemberId($member_id, $order_id); if (!$member_result) { return Util::returnArrEr('插入订单失败', $order_id1); } return $result = Util::returnArrSu('', $order_id1); } /** * Function Description:验证身份证 * Function Name: isCardID * @param $sId * * @return array * * @author 张帅 */ public function isCardID($sId) { $aCity = array( 11 => "北京", 12 => "天津", 13 => "河北", 14 => "山西", 15 => "内蒙古", 21 => "辽宁", 22 => "吉林", 23 => "黑龙江", 31 => "上海", 32 => "江苏", 33 => "浙江", 34 => "安徽", 35 => "福建", 36 => "江西", 37 => "山东", 41 => "河南", 42 => "湖北", 43 => "湖南", 44 => "广东", 45 => "广西", 46 => "海南", 50 => "重庆", 51 => "四川", 52 => "贵州", 53 => "云南", 54 => "西藏", 61 => "陕西", 62 => "甘肃", 63 => "青海", 64 => "宁夏", 65 => "新疆", 71 => "台湾", 81 => "香港", 82 => "澳门", 91 => "国外" ); $iSum = 0; $result1 = Util::checkPattern('', $sId, '/^\d{17}(\d|x)$/i'); //你输入的身份证长度或格式错误 if (!$result1) { return Util::returnArrEr('你输入的身份证长度或格式错误'); } $sId = str_replace('X', 'a', $sId); $sId = str_replace('x', 'a', $sId); $city = substr($sId, 0, 2); //你的身份证地区非法 if (!isset($aCity[$city])) { return Util::returnArrEr('你的身份证地区非法'); } $sBirthday = substr($sId, 6, 4) . '-' . substr($sId, 10, 2) . '-' . substr($sId, 12, 2); $result2 = Util::checkPattern('', $sBirthday, '/^(19|20)\d{2}-(1[0-2]|0?[1-9])-(0?[1-9]|[1-2][0-9]|3[0-1])$/'); //身份证上的出生日期非法 if (!$result2) { return Util::returnArrEr('身份证上的出生日期非法'); } for ($i = 17; $i >= 0; $i--) { $pow = 1; for ($j = 1; $j <= $i; $j++) { $pow *= 2; } $charAt = 17 - $i; if ($sId[$charAt] == 'a') { $sId[$charAt] = 10; } $iSum += ($pow % 11) * $sId[$charAt]; } //你输入的身份证号非法 if ($iSum % 11 != 1) { return Util::returnArrEr('你输入的身份证号非法'); } return Util::returnArrSu(); } /** * Des:获取电子车票二维码,根据订单号生成二维码和检票信息 * Name: getETicket * @param $order_id * @return string * @author 倪宗锋 */ public function getETicket($order_id) { $qr_path = "images/temp/QrCode/$order_id.png"; $logo_qr_path = "images/temp/QrCode/logo$order_id.png"; $errorCorrectionLevel = 'L'; //容错级别 $matrixPointSize = 7; //生成图片大小 $content = $order_id; // 生成二维码图片 if (file_exists($qr_path)) unlink($qr_path); if (file_exists($logo_qr_path)) unlink($logo_qr_path); QrCode::png($content, $qr_path, $errorCorrectionLevel, $matrixPointSize, 2); $QR = $qr_path; // 输出二维码图片 return "/public/$QR"; } /** * Des:修改订单状态,插入支付凭证 * Name: updateOrderStatus * @param $order_id * @param $pay_num * @return array * @author 张帅 */ public function updateOrderStatus($order_id, $pay_num) { $order_main = new OrderMain(); //1.判断订单是否完成 $check_result = $order_main->checkStatus($order_id); //执行sql 错误 if (!$check_result['flag']) { return $check_result; } //已出票 if ($check_result['data'] == 146) { return $check_result; } $result1 = $order_main->updateOrderStatus($order_id); if (!$result1) { return $result1; } $order_group = $result1['data']; $order_group = explode(',', $order_group); $result = $order_main->insSerialNumber($order_id, $pay_num); //7.发短信 $url1='http://cs1.zhizhuchuxing.com/api/msg/order-send-msg'; $data = array('order_id' => $order_group[0], 'msg_type' => 'wx' ); $a = new CurlInterface($data, 5); $a->setBaseUrl($url1); $a->execute('', 'POST'); if (isset($order_group[1])) { $data = array('order_id' => $order_group[1]); $a = new CurlInterface($data, 5); $a->setBaseUrl($url1); $a->execute('', 'POST'); } OrderLog::addOrderStatusLog($order_id, 2);//添加订单状态变更记录 2:支付 return $result; } /** * Function Description:退票 * Function Name: cancelOrder * @param $order_id * * @return string * * @author 张帅 */ public function cancelOrder($order_id) { $order_main = new OrderMain(); $result = $order_main->cancelOrder($order_id); if (!$result) { return Util::returnJsEr('退票失败'); } else { return Util::returnJsSu('退票成功'); } } /** * Function Description:退钱 * Function Name: cancelPay * @param $order_id * * @return string * * @author 张帅 */ public function cancelPay($order_id) { //1.获取订单详情 $order_list = new OrderlistModel(); $order_detail = $order_list->getOrderall($order_id); if (!$order_detail['flag']) { return Util::returnJsEr('网络原因,退票失败'); } $order_detail = $order_detail['data']; $price = $order_detail['price']; $order_id = $order_detail['order_id']; //2.判断时间是否符合退票时间 $run_time = $order_detail[0]['run_date'] . ' ' . $order_detail[0]['start_time']; $time_check = strtotime($run_time) - time(); if ($time_check < 1800) { return Util::returnJsEr('开车前30分钟禁止退票,请刷新页面确认时间'); } $order_id_arr = explode(',', $order_id); if (count($order_id_arr) > 1) { $go_order_id = $order_id_arr[0];//去程订单号 $back_order_id = $order_id_arr[1];//返程订单号 } else { $go_order_id = $order_id_arr[0]; $back_order_id = ''; } //3.获取支付凭证 $order_main = new OrderMain(); $serial_result = $order_main->getSerialNumber($go_order_id); if (!$serial_result['flag']) { return json_encode($serial_result); } $serial_number = $serial_result['data']; //4.数据库系统退票 $cancel_result = $order_main->cancelOrderOne($go_order_id); if (!$cancel_result) { return Util::returnJsEr('去返程订单系统退票出错,请稍后重试' . $go_order_id); } if ($back_order_id != '') { $cancel_result = $order_main->cancelOrderOne($back_order_id); if (!$cancel_result) { return Util::returnJsEr('返程订单系统退票出错,请稍后重试' . $back_order_id); } } //5.将数据插入退票表 $insert_result = $order_main->insCancelWeChatOrder($go_order_id, $price, $serial_number); if (!$insert_result) { return json_encode($insert_result); } OrderLog::cancelOrder($order_id, 2); return Util::returnJsSu('退票成功'); } /** * Function Description:校验价格 * Function Name: getPrice * @param $tick_info * @param $channel_id * * @return bool * * @author 娄梦宁 */ public function getPrice($tick_info, $channel_id) { $orderMain = new OrderMain(); $runMain = new RunMain(); $count = substr_count($tick_info, '{'); if ($count == 1) {//单程票 $tick_info = ltrim($tick_info, '{'); $tick_info = rtrim($tick_info, '}'); $tick_info_arr = explode(',', $tick_info); $tick_id = $tick_info_arr[2]; $price_check = $orderMain->getPriceGo($tick_id); $price = $tick_info_arr[3]; if ($price_check == $price) { return true; } } elseif ($count == 2) {//往返票种 $tick_info = str_replace('}{', ',', $tick_info); $tick_info = ltrim($tick_info, '{'); $tick_info = rtrim($tick_info, '}'); $tick_info_arr = explode(',', $tick_info); $go_tick_id = $tick_info_arr[2]; $go_tick_price = $tick_info_arr[3]; $go_discount_price1 = $runMain->getDiscountPrice($go_tick_id, $channel_id); $go_price = $orderMain->getPriceGo($go_tick_id); if (count($go_discount_price1) == 0) { $go_discount_price = '0'; } else { $go_discount_price = $go_discount_price1['data']['off_value']; } $back_tick_id = $tick_info_arr[7]; $back_tick_price = $tick_info_arr[8]; $back_discount_price1 = $runMain->getDiscountPrice($back_tick_id, $channel_id); $back_price = $orderMain->getPriceGo($back_tick_id); if (count($back_discount_price1) == 0) { $back_discount_price = '0'; } else { $back_discount_price = $back_discount_price1['data']['off_value']; } if ($go_tick_price == ($go_price - $go_discount_price) && $back_tick_price == ($back_price - $back_discount_price)) { return true; } } return false; } }