query($sql); if (count($line_info) == 0) { $json['code'] = '1'; $json['info'] = '该产品已不存在'; return $json; } //机场接驳,出发时间自由选择 // if(in_array($line_info[0]['line_id'], array('450916', '450917'))){ // $line_id = $line_info[0]['line_id']; // $run_date = $line_info[0]['run_date']; // $sql = "select prod_id line_id, run_time from run_main r where r.prod_id = $line_id and r.run_date = '$run_date' and r.run_status = 138 group by run_time"; // $res = $this->query($sql); // if($res && !empty($res)){ // $line_info[0]['run_time'] = $res; // } // } //在这里得到该班次的站点区域数量,如果大于0则隐藏返程选择 $res = $this->judgeArea($param); if ($res['code'] != '0') { $json['code'] = '2'; $json['info'] = $res['info']; } else { $area_num = $res['num']; } $json['code'] = '0'; $json['info'] = '返回产品数据成功'; $json['area_num'] = $area_num; $json['list'] = $line_info[0]; return $json; } /** * 上车下车站点为区域,获取该区域内的站点信息 * 温依莅 * @param $param */ public function getDetailStation($param) { //根据传过来的区域res_id,得到下属的站点信息列表 $valid = zzcsUtils::validateParams( array('res_id' => 'amount'), $param); //参数验证 $res_id = trim($param['res_id']); if (!$valid['status']) { $json['code'] = (string)$valid['status']; $json['info'] = $json['info']; return $json; } $sql = "select res_id as sub_res_id,parent_id as parent_res_id,res_name as sub_res_name from base_resource where parent_id=$res_id and CANCEL_FLAG=0 and ZONE_MARK=0;"; $res = $this->query($sql); if (false === $res) { $json['code'] = '1'; $json['info'] = '获取失败' . $sql; return $json; } else if (count($res) == 0) { $json['code'] = '2'; $json['info'] = '此区域无站点信息'; $json['list'] = array(); return $json; } else { $json['code'] = '0'; $json['info'] = '返回区域站点信息成功'; $json['list'] = $res; return $json; } } /** * Function Description:根据user_id获取所属的运营主体main_corp_id * Function Name: getMainCorpId * @param int $user_id 用户id * * @return int 运营主体id * * @author 温依莅 */ public function getMainCorpId($user_id=-1) { //如果未传user_id,使用cookie中的user_id if($user_id==-1){ $user_id=$this->user_id; } $user_id=$user_id+0; //如果根据user_id未查到相应的main_corp_id,则使用cookie中的main_corp_id,如果cookie中没有,返回-1 $sql = 'select id,main_corp_id from base_user where id=' . $user_id . ' limit 1'; $res = $this->query($sql); if (count($res) == 0) { $real_main_corp_id=isset($_COOKIE['user_main_corp'])?$_COOKIE['user_main_corp']:-1; }else{ $real_main_corp_id = $res[0]['main_corp_id']; } return $real_main_corp_id; } /** * Function Description:根据运营主体获取班次可售票种信息(判断是自营还是代收) * Function Name: getAgentTicket * @param int $run_id * @param int $main_corp_id * * @return array * * @author 温依莅 */ public function getAgentTicket($run_id, $main_corp_id = -1) { $user_id = $this->user_id + 0; //如果未传main_corp_id,则使用user_id所属的main_corp_id if ($main_corp_id == -1) { $sql = 'select id,main_corp_id from base_user where id=' . $user_id . ' limit 1'; $res = $this->query($sql); if (count($res) == 0) { $json['code'] = '1'; $json['info'] = '用户信息错误'; return $json; } $real_main_corp_id = $res[0]['main_corp_id']; } else { $real_main_corp_id = $main_corp_id; } if($real_main_corp_id==0){ $real_main_corp_id=1;//main_corp_id是0的视为 蜘蛛国旅运营主体 } //根据线路的运营主体判断是自营线路还是代售线路,根据运营主体,和班次得到该线路可售票种(自营线路或代收线路的票种) $sql = 'select a.line_id,b.run_id,b.run_date,a.main_corp_id from opera_line a left join run_main b on a.line_id=b.prod_id where b.run_id=' . $run_id . ' limit 1'; $res2 = $this->query($sql); if (count($res) == 0) { $json['code'] = '2'; $json['info'] = '班次信息错误'; return $json; } #如果是自营线路->opera_tickets,代售->opera_tickets_agent $is_agent = 0; if ($res2[0]['main_corp_id'] == $real_main_corp_id) { $sql_alt = 'select group_concat(ticket_id) as tickets from opera_tickets where cancel_flag=0 and is_onsale=1 and line_id=' . $res2[0]['line_id']; //$res_self = $this->query($sql_self); } else { $is_agent = 1; $sql_alt = 'select group_concat(ticket_id) as tickets from opera_tickets_agent where cancel_flag=0 and authority_status=1 and is_onsale=1 and line_id=' . $res2[0]['line_id'] . ' and to_main_corp_id=' . $real_main_corp_id; //$res_self = $this->query($sql_agent); } $res3 = $this->query($sql_alt); if (!$res3[0]['tickets']) { $json['code'] = '3'; $json['info'] = '该班次无有效票种'; return $json; } $json['code'] = '0'; $json['info'] = '返回可用票种成功'; $json['is_agent'] = $is_agent; $json['tickets'] = $res3[0]['tickets']; return $json; } /** * 获取上车站点 * @param $param */ public function getStartStation($param) { $run_id = isset($param['run_id']) ? trim($param['run_id']) : false;//班次id; $start_area_id = isset($param['start_area_id']) ? trim($param['start_area_id']) : false;//出发地id; if (!$run_id || !$start_area_id) { $json['code'] = '2'; $json['info'] = '缺少必要参数'; return $json; } //根据run_id,和main_corp_id得到,可售票种(自营或代售的票种) $arr = $this->getAgentTicket($run_id); if ($arr['code'] != '0') { $json['code'] = '2'; $json['info'] = $arr['info']; return $json; } $tickets = $arr['tickets']; $tickets_str = '(' . $tickets . ')'; $sql = "SELECT a.start_station_res_id as res_id, (SELECT res_name FROM base_resource WHERE res_id = a.start_station_res_id LIMIT 1) as res_name, (SELECT start_time from run_station where run_id = a.run_id and station_res_id = a.start_station_res_id LIMIT 1) as res_time FROM run_prod a LEFT JOIN run_station b ON a.run_id=b.run_id and a.start_station_res_id=b.station_res_id WHERE a.run_id = " . $run_id . " AND a.start_station_area_id = " . $start_area_id . " AND a.cancel_flag = 0 AND b.station_inout_type in (108,109) AND a.prod_id in $tickets_str GROUP BY a.start_station_res_id"; $start_station = $this->query($sql); if (count($start_station) == 0) { $json['code'] = '1'; $json['info'] = '没有上车站'; return $json; } $json['code'] = '0'; $json['info'] = '返回上车站点数据成功'; $json['list'] = $start_station; return $json; } /** * 根据班次id得到该班次是否有站点是区域 * 温依莅 * @param $param */ public function judgeArea($param) { //判断参数 $valid = zzcsUtils::validateParams( array( 'run_id' => 'number', ), $param); //参数验证 if (!$valid['status']) { $result['code'] = (string)$valid['status']; $result['info'] = $valid['info']; return $result; } //获取该班次的站点中站点为区域的数量 $sql = 'SELECT sum(b.ZONE_MARK) as area_num FROM `run_station` a left join base_resource b on a.STATION_RES_ID=b.RES_ID where run_id=' . $param['run_id']; $res = $this->query($sql); if (false === $res) { $json['code'] = '1'; $json['info'] = '获取数据失败'; return $json; } $total_num = $res[0]['area_num']; $json['code'] = '0'; $json['info'] = '返回班次区域数量成功'; $json['num'] = $total_num; return $json; } /** * 获取下车站点(在该接口里加入获取上车区域具体站点功能--温依莅) * @param $param */ public function getEndStation($param) { $run_id = isset($param['run_id']) ? trim($param['run_id']) : false;//班次id; $start_res_id = isset($param['start_res_id']) ? trim($param['start_res_id']) : false;//出发站点id; $end_area_id = isset($param['end_area_id']) ? trim($param['end_area_id']) : false;//目的地id; if (!$run_id || !$start_res_id || !$end_area_id) { $json['code'] = '2'; $json['info'] = '缺少必要参数'; return $json; } //根据run_id,和main_corp_id得到,可售票种(自营或代售的票种) $arr = $this->getAgentTicket($run_id); if ($arr['code'] != '0') { $json['code'] = '2'; $json['info'] = $arr['info']; return $json; } $tickets = $arr['tickets']; $tickets_str = '(' . $tickets . ')'; $sql = "SELECT a.end_station_res_id as res_id, (SELECT zone_mark FROM base_resource WHERE res_id = a.end_station_res_id LIMIT 1) as zone_mark, (SELECT res_name FROM base_resource WHERE res_id = a.end_station_res_id LIMIT 1) as res_name, (SELECT start_time from run_station where run_id = a.run_id and station_res_id = a.end_station_res_id LIMIT 1) as res_time FROM run_prod a LEFT JOIN run_station b ON a.run_id=b.run_id and a.end_station_res_id=b.station_res_id WHERE a.run_id = " . $run_id . " AND a.end_station_area_id = " . $end_area_id . " AND a.cancel_flag = 0 AND b.station_inout_type in (109,110) AND a.start_station_res_id = " . $start_res_id . " AND a.prod_id in $tickets_str GROUP BY a.end_station_res_id"; $end_station = $this->query($sql); if (count($end_station) == 0) { $json['code'] = '1'; $json['info'] = '没有下车站'; return $json; } //以下加入 得到(上车站点若为区域时)的具体站点信息功能---温依莅 #上车区域附属站点信息 $par['res_id'] = $start_res_id; $res = $this->getDetailStation($par); if ($res['code'] == '1') { //数据库错误直接返回 $json['code'] = '1'; $json['info'] = '获取失败'; return $json; } else { $start_detail = $res['list']; //返回区域下属站点信息 } //以上,得到区域站点信息结束 //返回信息 $json['code'] = '0'; $json['info'] = '返回下车站点数据成功'; $json['list'] = $end_station; $json['start_detail'] = '';//$start_detail; return $json; } /** * 获取票种信息 * @param $param */ public function getTicketInfo($param) { $channel_id = isset($param['channel_id']) ? trim($param['channel_id']) : false;//渠道商id; $run_id = isset($param['run_id']) ? trim($param['run_id']) : false;//班次id; $start_res_id = isset($param['start_res_id']) ? trim($param['start_res_id']) : false;//出发站点id; $end_res_id = isset($param['end_res_id']) ? trim($param['end_res_id']) : false;//目的站点id; $line_type = isset($param['line_type']) ? trim($param['line_type']) : false;//线路类型; if (!$run_id || !$start_res_id || !$end_res_id || !$channel_id || !$line_type) { $json['code'] = '2'; $json['info'] = '缺少必要参数'; return $json; } //判断是否是代售 $arr = $this->getAgentTicket($run_id); if ($arr['code'] != '0') { $json['code'] = '2'; $json['info'] = $arr['info']; return $json; } $is_agent = $arr['is_agent']; $opera_ticket_name = $is_agent ? 'opera_tickets_agent' : 'opera_tickets'; $main_corp_id=$this->getMainCorpId(); if($main_corp_id==0){ $main_corp_id=1; } $agent_condition=$is_agent?"and a.to_main_corp_id=$main_corp_id":''; $sql = "SELECT a.ticket_id,a.seat_type, (SELECT type_name FROM dict_type WHERE id = a.seat_type LIMIT 1) AS seat_type_name, a.human_type, (SELECT type_name FROM dict_type WHERE id = a.human_type LIMIT 1) AS human_type_name, a.prod_price, a.cus_price, ( SELECT min(total_count - saled_count) FROM run_stock WHERE run_id = " . $run_id . " AND cancel_flag = 0 AND seq_id >= (SELECT seq_id FROM run_stock WHERE run_id = " . $run_id . " AND cancel_flag = 0 AND res_id = " . $start_res_id . " AND seat_type = a.seat_type limit 1) AND seq_id < (SELECT seq_id FROM run_stock WHERE run_id = " . $run_id . " AND cancel_flag = 0 AND res_id = " . $end_res_id . " AND seat_type = a.seat_type limit 1) AND seat_type = a.seat_type ) AS stock FROM $opera_ticket_name as a WHERE ticket_type = 1 and cancel_flag=0 $agent_condition AND ticket_id IN ( SELECT prod_id FROM run_prod WHERE run_id = " . $run_id . " AND start_station_res_id = " . $start_res_id . " AND end_station_res_id = " . $end_res_id . " )"; //zzcsUtils::writeLog($sql); $ticket_info = $this->query($sql); if (false === $ticket_info) { $json['code'] = '2'; $json['info'] = '获取该渠道票种失败'; return $json; } if (count($ticket_info) == 0) { $json['code'] = '1'; $json['info'] = '该渠道无可销售的票种'; return $json; } foreach ($ticket_info as $k => $v) { $sale_type = $this->getTicketChannelSaleType($channel_id, $v['ticket_id'], $line_type);//获取销售类型 if ($sale_type)//如果该销售方式被关掉 { if ($sale_type['sale_type'] == "177") { if ($sale_type['price'] == '0') { $ticket_info[$k]['price'] = $v['prod_price']; } else { $ticket_info[$k]['price'] = $sale_type['price']; } } else { $ticket_info[$k]['price'] = $v['cus_price']; } } else { unset($ticket_info[$k]); } } $json['code'] = '0'; $json['info'] = '返回票种信息成功'; $json['list'] = $ticket_info; return $json; } /** * 获取返程的班次情况 * @param $param * @return mixed */ public function getBackProductList($param) { $run_date = isset($param['run_date']) ? (empty($param['run_date']) ? date('Y-m-d', time()) : trim($param['run_date'])) : false;//返程出发日期 $start_area = isset($param['start_area']) ? (empty($param['start_area']) ? "''" : "'" . trim($param['start_area']) . "'") : false;//出发地 $end_area = isset($param['end_area']) ? (empty($param['end_area']) ? "''" : "'" . trim($param['end_area']) . "'") : false;//目的地 $line_type = isset($param['line_type']) ? trim($param['line_type']) : false;//线路类型; $now_date = date('Y-m-d', time()); if (!$run_date || !$start_area || !$end_area || !$line_type) { $json['code'] = '2'; $json['info'] = '缺少必要参数'; return $json; } $sql = "SELECT m.run_id, m.run_time FROM run_main AS m, run_prod AS p, opera_line AS l WHERE m.run_id = p.run_id AND m.prod_id = l.line_id AND p.start_station_area_id = " . $start_area . " AND p.end_station_area_id = " . $end_area . " AND m.run_date = '" . $run_date . "' AND m.run_status not in(137,142) AND l.line_type = " . $line_type . " GROUP BY m.run_id order by m.run_time ASC"; $run_list = $this->query($sql); if (count($run_list) == 0) { $json['code'] = '1'; $json['info'] = '没有符合的班次情况'; return $json; } $json['code'] = '0'; $json['info'] = '返回班次列表成功'; $json['run_list'] = $run_list; return $json; } /** * 获取去程票种的订单渠道 */ public function getGoChannel($param) { $run_id = isset($param['run_id']) ? trim($param['run_id']) : false;//班次id; $start_res_id = isset($param['start_res_id']) ? trim($param['start_res_id']) : false;//出发站点id; $end_res_id = isset($param['end_res_id']) ? trim($param['end_res_id']) : false;//目的站点id; $line_type = isset($param['line_type']) ? trim($param['line_type']) : false;//线路类型; if (!$run_id || !$start_res_id || !$end_res_id || !$line_type) { $json['code'] = '2'; $json['info'] = '缺少必要参数'; return $json; } $date_month = date('Y-m', strtotime("-1 month ")); //$main_corp_id = isset($_COOKIE["user_main_corp"]) ? $_COOKIE["user_main_corp"] : 0; $main_corp_id=$this->getMainCorpId($this->user_id); $extra_sql = ""; if ($main_corp_id > 0) { $extra_sql = $main_corp_id == 1 ? " AND b.MAIN_CORP_ID = $main_corp_id " : " AND b.MAIN_CORP_ID IN(0,{$main_corp_id}) "; } //原厦门渠道,暂不再虑 /*if ($main_corp_id != 3) { $extra_sql = " AND b.MAIN_CORP_ID NOT IN(3) "; }*/ //如果只需要一个渠道商信息 $where_supplier = isset($param['supplier_id']) ? " and a.supplier_id = " . $param['supplier_id'] : ""; $sql = "SELECT a.supplier_id,b.supplier_name,b.sales_man FROM base_supplier_sale AS a INNER JOIN base_supplier AS b ON a.supplier_id = b.id LEFT JOIN base_supplier_sequence AS s ON b.id = s.supplier_id and s.date_month = '" . $date_month . "' WHERE a.parent_type = 310 $where_supplier AND a.product_type in (" . $line_type . ",0) AND a.cancel_flag = 0 AND b.cancel_flag = 0 {$extra_sql} AND b.is_disabled = 0 AND a.supplier_id NOT IN ( SELECT supplier_id FROM opera_tickets_distrib WHERE cancel_flag = 0 AND authority_status = 0 AND ticket_id IN ( SELECT prod_id FROM run_prod WHERE run_id = " . $run_id . " AND start_station_res_id = " . $start_res_id . " AND end_station_res_id = " . $end_res_id . " ) ) GROUP BY a.supplier_id ORDER BY s.order_num DESC,s.person_trip DESC,s.sales DESC"; $channel_list = $this->query($sql); if (count($channel_list) == 0) { $json['code'] = '0'; $json['info'] = '无销售渠道'; $json['list'] = array(); return $json; } //以下加入 得到(下车站点若为区域时)的具体站点信息功能---温依莅 #下车区域附属站点信息 $par['res_id'] = $end_res_id; $res = $this->getDetailStation($par); if ($res['code'] == '1') { //数据库错误直接返回 $json['code'] = '1'; $json['info'] = $res['info']; return $json; } else { $end_detail = $res['list']; //返回区域下属站点信息 } //以上,得到区域站点信息结束 /*$end_detail=array( '0'=>array('parent_res_id'=>'10368','sub_res_id'=>'10369','sub_res_name'=>'厦门安兜'), '1'=>array('parent_res_id'=>'10368','sub_res_id'=>'10370','sub_res_name'=>'厦门车管所车站'), '2'=>array('parent_res_id'=>'10368','sub_res_id'=>'10371','sub_res_name'=>'厦门大唐世家') );*/ $json['code'] = '0'; $json['info'] = '返回渠道商信息成功'; $json['list'] = $channel_list; $json['end_detail'] = $end_detail; return $json; } /** * 获取返程票种和去程票种清单渠道的交集 * @param $param */ public function getBackChannel($param) { $go_run_id = isset($param['go_run_id']) ? trim($param['go_run_id']) : false;//去程班次id; $go_start_res_id = isset($param['go_start_res_id']) ? trim($param['go_start_res_id']) : false;//去程出发站点id; $go_end_res_id = isset($param['go_end_res_id']) ? trim($param['go_end_res_id']) : false;//去程目的站点id; $back_run_id = isset($param['back_run_id']) ? trim($param['back_run_id']) : false;//反程班次id; $back_start_res_id = isset($param['back_start_res_id']) ? trim($param['back_start_res_id']) : false;//反程出发站点id; $back_end_res_id = isset($param['back_end_res_id']) ? trim($param['back_end_res_id']) : false;//反程目的站点id; $line_type = isset($param['line_type']) ? trim($param['line_type']) : false;//线路类型; if (!$go_run_id || !$go_start_res_id || !$go_end_res_id || !$line_type || !$back_run_id || !$back_start_res_id || !$back_end_res_id) { $json['code'] = '2'; $json['info'] = '缺少必要参数'; return $json; } $go_array = array( 'run_id' => $go_run_id, 'start_res_id' => $go_start_res_id, 'end_res_id' => $go_end_res_id, 'line_type' => $line_type ); $back_array = array( 'run_id' => $back_run_id, 'start_res_id' => $back_start_res_id, 'end_res_id' => $back_end_res_id, 'line_type' => $line_type ); $go_channel_list = $this->getGoChannel($go_array); $back_channel_list = $this->getGoChannel($back_array); $go_channel_list = $go_channel_list['list']; $back_channel_list = $back_channel_list['list']; $channel_list = array(); if (count($go_channel_list) > 0 && count($back_channel_list) > 0) { foreach ($go_channel_list as $k => $v) { $channel_list1[$v['supplier_id']] = $v; } foreach ($back_channel_list as $k => $v) { $channel_list2[$v['supplier_id']] = $v; } foreach ($channel_list1 as $k => $v) { if (isset($channel_list2[$k])) { $channel_list[] = $v; } } } $json['code'] = '0'; $json['info'] = '返回渠道列表信息成功'; $json['list'] = $channel_list; return $json; } /** * 获取返程的票种详情 * @param $param */ public function getBackTicketInfo($param) { $channel_id = isset($param['channel_id']) ? trim($param['channel_id']) : false;//渠道商id; $go_run_id = isset($param['go_run_id']) ? trim($param['go_run_id']) : false;//去程班次id; $go_start_res_id = isset($param['go_start_res_id']) ? trim($param['go_start_res_id']) : false;//去程出发站点id; $go_end_res_id = isset($param['go_end_res_id']) ? trim($param['go_end_res_id']) : false;//去程目的站点id; $back_run_id = isset($param['back_run_id']) ? trim($param['back_run_id']) : false;//反程班次id; $back_start_res_id = isset($param['back_start_res_id']) ? trim($param['back_start_res_id']) : false;//反程出发站点id; $back_end_res_id = isset($param['back_end_res_id']) ? trim($param['back_end_res_id']) : false;//反程目的站点id; $line_type = isset($param['line_type']) ? trim($param['line_type']) : false;//线路类型; if (!$channel_id || !$go_run_id || !$go_start_res_id || !$go_end_res_id || !$line_type || !$back_run_id || !$back_start_res_id || !$back_end_res_id) { $json['code'] = '2'; $json['info'] = '缺少必要参数'; return $json; } $go_array = array( 'channel_id' => $channel_id, 'run_id' => $go_run_id, 'start_res_id' => $go_start_res_id, 'end_res_id' => $go_end_res_id, 'line_type' => $line_type ); $back_array = array( 'channel_id' => $channel_id, 'run_id' => $back_run_id, 'start_res_id' => $back_start_res_id, 'end_res_id' => $back_end_res_id, 'line_type' => $line_type ); //获取去程票种详情 $go_ticket_info = $this->getTicketInfo($go_array); if ($go_ticket_info['code'] != '0') { $json['code'] = '1'; $json['info'] = '去程有问题'; return $json; } $go_ticket_info = $go_ticket_info['list']; //获取返程票种详情 $back_ticket_info = $this->getTicketInfo($back_array); if ($back_ticket_info['code'] != '0') { $json['code'] = '1'; $json['info'] = '返程有问题'; return $json; } $back_ticket_info = $back_ticket_info['list']; foreach ($go_ticket_info as $k => $v) { $go_ticket_array[$v['seat_type'] . "-" . $v['human_type']] = $v; $ticket_array_id[] = $v['ticket_id']; } foreach ($back_ticket_info as $k => $v) { $back_ticket_array[$v['seat_type'] . "-" . $v['human_type']] = $v; $ticket_array_id[] = $v['ticket_id']; } //获取促销优惠 $sql = "SELECT ticket_id, off_value FROM opera_tickets_discount WHERE ticket_id IN (" . implode(",", $ticket_array_id) . ") AND supplier_id = " . $channel_id . " AND is_onsale = 1 AND cancel_flag = 0 AND discount_type = 332 AND discount_day_type = 0 GROUP BY ticket_id"; //zzcsUtils::writeLog($sql); $discount_info = $this->query($sql); if (false === $discount_info) { $json['code'] = '1'; $json['info'] = '获取促销优惠失败'; return $json; } $discount_info_array = array(); if (count($discount_info) > 0) { foreach ($discount_info as $k => $v) { $discount_info_array[$v['ticket_id']] = $v['off_value']; } } foreach ($go_ticket_array as $k => $v) { if (isset($back_ticket_array[$k])) { $go_discount = '0'; if (isset($discount_info_array[$go_ticket_array[$k]['ticket_id']])) { $go_discount = $discount_info_array[$go_ticket_array[$k]['ticket_id']]; } $back_discount = '0'; if (isset($discount_info_array[$back_ticket_array[$k]['ticket_id']])) { $back_discount = $discount_info_array[$back_ticket_array[$k]['ticket_id']]; } $ticket_one = array( 'go_run_id' => $go_run_id, 'go_ticket_id' => $go_ticket_array[$k]['ticket_id'], 'go_price' => $go_ticket_array[$k]['price'], 'go_discount_price' => $go_ticket_array[$k]['price'] - $go_discount, 'go_discount' => $go_discount, 'go_stock' => $go_ticket_array[$k]['stock'], 'back_run_id' => $back_run_id, 'back_ticket_id' => $back_ticket_array[$k]['ticket_id'], 'back_price' => $back_ticket_array[$k]['price'], 'back_discount_price' => $back_ticket_array[$k]['price'] - $back_discount, 'back_discount' => $back_discount, 'back_stock' => $back_ticket_array[$k]['stock'], 'seat_type' => $go_ticket_array[$k]['seat_type'], 'seat_type_name' => $go_ticket_array[$k]['seat_type_name'], 'human_type' => $go_ticket_array[$k]['human_type'], 'human_type_name' => $go_ticket_array[$k]['human_type_name'], 'price' => $go_ticket_array[$k]['price'] + $back_ticket_array[$k]['price'] - $go_discount - $back_discount, 'stock' => min($go_ticket_array[$k]['stock'], $back_ticket_array[$k]['stock']) ); $ticket_array[] = $ticket_one; } } $json['code'] = '0'; $json['info'] = '成功'; $json['list'] = $ticket_array; return $json; } /** * 提交单一线路订单(统一cs系统和厦门的单一线路下单) */ public function submitOrder($param) { $valid = zzcsUtils::validateParams( array( 'channel_id,ticket_info,customer_info,travel_peoples,sub_start_res_id,sub_end_res_id,count_num' => 'empty', 'receive_value' => 'amount' ), $param); //参数验证 if (!$valid['status']) { $result['code'] = (string)$valid['status']; $result['info'] = $valid['info']; return $result; } $channel_id = $param['channel_id'];//渠道商id; $channel_order_id = isset($param['channel_order_id']) ? $param['channel_order_id'] : ''; $salesman = isset($param['salesman']) ? $param['salesman'] : ''; $ticket_info = $param['ticket_info']; $customer_info = $param['customer_info']; $travel_peoples = $param['travel_peoples']; //fuhc 2017-11-07 $receive_value = $param['receive_value'];//代收总价 $count_num = $param['count_num']; //订单人数 $id_card = $param['id_card']; //身份证号 $door_price = $param['door_price'] ? $param['door_price'] : 0; //套餐产品--门票价格 $hotel_price = $param['hotel_price'] ? $param['hotel_price'] : 0; //套餐产品--酒店价格 $pay_type = 275; $start_res_id = $param['sub_start_res_id']; //如果上车为区域,传入具体上车站点res_id,否则传 0 $end_res_id = $param['sub_end_res_id']; //如果下车为区域,传入具体下车站点res_id,否则传 0 //customer_info中,手机和联系人只要有1个信息就可以 $tmp = substr($customer_info, 1, -1); $tmpArray = explode(',', $tmp); //前台传过来的顺序不能变 1、联系人 2、手机号 3、备注 4、后期添加的新字段 if (trim($tmpArray[0]) == '' && trim($tmpArray[1]) == '') $customer_info = false; $user_id = $this->user_id; $time = date('Y-m-d H:i:s', time()); if (false === $channel_id || false === $ticket_info || false === $customer_info) { $json['code'] = '2'; $json['info'] = '缺少必要参数'; return $json; } #===================================以下 调用巴士统一下单接口下单===================================================# //1,获取参数 $customer_info_arr = array($tmpArray[0], $tmpArray[1], 150, $id_card, $tmpArray[2]); $customer_info_str = '{' . implode(',', $customer_info_arr) . '}';//联系人信息,格式为{联系人,联系电话,z证件类型,联系人身份证,备注} $order_info_str = '{' . $user_id . ',' . $user_id . ',' . $channel_id . ',' . $channel_order_id . ',1,275,1,' . $salesman . '}';//'订单信息 {下单用户,会员号,渠道id,渠道订单号,是否自动退票(0否1是),支付方式(授信275),是否支付(0否1是),业务员}' $order_append_str = '{' . $door_price . ',' . $hotel_price . '}';//订单附加 ,格式为{门票价格,酒店价格} $sin_rec = round($receive_value / $count_num, 2);//单价 $receiver_value_str = '{' . $sin_rec . ',' . $receive_value . '}';//代收,格式为{代收单价,代收总价} $buy_insurance = $param['buy_insurance'];//购买保险; //2,整理参数 $url = 'http://' . CS1_DOMAIN . '/api/submit-order'; $data = array(); $data['action'] = 'submit_bus_order'; $data['prod_str'] = $ticket_info;//购买票种列表 格式为{去程/返程标志(1:去程 2:返程),去程/返程班次ID,票种ID,票种单价,预定数量,车号}... $data['order_info_str'] = $order_info_str;//'订单信息 {下单用户,会员号,渠道id,渠道订单号,是否自动退票(0否1是),支付方式(授信275),是否支付(0否1是),业务员}' $data['customer_info_str'] = $customer_info_str;//联系人信息,格式为{联系人,联系电话,z证件类型,联系人身份证,备注} $data['passenger_info'] = $travel_peoples; $data['order_append_str'] = $order_append_str;//订单附加 ,格式为{门票价格,酒店价格} $data['receiver_value_str'] = $receiver_value_str;//代收,格式为{代收单价,代收总价} $data['buy_insurance'] = $buy_insurance;//购买保险 $data['is_send_msg'] = 1;//是否发短信(0否1是) 默认1 //3,发送请求到巴士统一下单接口 $result = httpRequest($url, $data); $final_result = json_decode($result, true); return $final_result; #====================================以上 调用巴士统一下单接口下单==================================================# /*----------------原下单逻辑 //如果修改了存储过程的参数,批量订单的下单的参数也要修改 $sql = "call sp_make_order_xm(" . $user_id . ",'" . $ticket_info . "','" . $customer_info . "'," . $channel_id . ",'" . $channel_order_id . "','" . $salesman . "'," . $pay_type . "," . $start_res_id . "," . $end_res_id . "," . $receive_value . ")"; //$sql = "call sp_make_order_xm(" . $user_id . ",'" . $ticket_info . "','" . $customer_info . "'," . $channel_id . ",'" . $channel_order_id . "','" . $salesman . "'," . $pay_type . "," . $start_res_id . "," . $end_res_id . "," . $receive_value.")"; zzcsUtils::writeLog($sql); //---------------- $res = $this->procQuery($sql); if ($res['code'] != 0) { //存储过程执行出错 $json["code"] = (string)$res['code']; $json["info"] = $res['info']; return $json; } //下单成功后,分单程和往返程对部分信息(1,订单状态,2,联系人身份证号,3,门票价格和酒店价格,4,代收单价总价)进行修改 $order_ids = $res['data'][0][0]['order_id']; $order_arr = explode(',', $order_ids); $update_sql = '';//拼接的sql语句 //得到插入后的订单信息 $get_sql = "SELECT a.order_id, b.run_date, a.outside_sale_org_id, c.supplier_name, b.order_price AS sin_price, a.order_price AS total_price, a.customer_name, a.customer_mobile, a.customer_id_no, a.customer_memo FROM order_main a LEFT JOIN order_main b ON a.order_id = b.PARENT_ORDER_ID left join base_supplier c on a.OUTSIDE_SALE_ORG_ID=c.ID WHERE a.order_id in ($order_ids) AND b.CANCEL_FLAG = 0 AND b.ORDER_VALID_STATUS = 1 group by a.order_id;"; $orders = $this->query($get_sql); if (count($order_arr) == 1) { //单程下单 $sin_rec = round($receive_value / $count_num, 2);//单价 $total_rec = $receive_value;//总价 #0写入订单日志 $detail_extra = ''; //如果有套餐产品,代收单价,代收总价也记录下来 $door_price && ($detail_extra .= '门票价格:' . $door_price); $hotel_price && ($detail_extra .= '酒店价格:' . $hotel_price); $total_rec && ($detail_extra .= '代收单价:' . $sin_rec . ',代收总价:' . $total_rec); $opera_detail = "创建订单,出发日期{$orders[0]['run_date']},订单渠道:{$orders[0]['supplier_name']},人数:{$count_num},金额{$orders[0]['sin_price']}总额{$orders[0]['total_price']}" . $detail_extra . ",联系人信息:{$orders[0]['customer_name']},{$orders[0]['customer_mobile']},{$id_card},备注信息:{$orders[0]['customer_memo']}"; $update_sql .= "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$orders[0]['order_id']},$user_id,1,'{$time}','{$opera_detail}','CS系统');"; #1修改代收价(主订单代收总价,子订单代收单价) $update_sql .= "UPDATE order_main SET RECEIVE_VALUE=$total_rec WHERE order_id in ($order_ids) ;UPDATE order_main SET RECEIVE_VALUE=$sin_rec WHERE parent_order_id in($order_ids);"; #2修改订单状态和联系人身份证号 $update_sql .= "UPDATE order_main SET update_user_id = " . $user_id . ", update_time = '" . $time . "', order_status = 146, customer_id_no ='$id_card' WHERE order_id in ($order_ids) OR parent_order_id in ($order_ids);"; #3对order_extra_info表插入(如果门票价格和酒店价格有一个不为空则插入) if ($hotel_price || $door_price) { $update_sql .= "INSERT INTO order_extra_info ( order_id, hotel_price, gate_price ) VALUES ($order_arr[0], $hotel_price, $door_price);"; } zzcsUtils::writeLog($update_sql); $res2 = $this->exec($update_sql); if (false === $res2) { $json['code'] = '1'; $json['info'] = '增加单程订单项失败'; return $json; } //region 短信发送模块 #对时间和班次发车时间做判断,如果当前时间小于发车时间则发送短信 $time_diff = $this->get_time_diff($order_arr[0]); if ($time_diff >= 0) { //$res_content = $this->send_msg($order_arr[0]); $url = 'http://' . CS1_DOMAIN . '/api/msg/order-send-msg'; $sendInfo = array(); $sendInfo['order_id'] = $order_arr[0]; $sendInfo['msg_type'] = 'cs'; $res_content = httpRequest($url, $sendInfo); } //endregion } else if (count($order_arr) == 2) { //往返程下单 $sin_rec = round($receive_value / (2 * $count_num), 2);//单价 $total_rec = $receive_value / 2;//总价 #0写入订单日志 $detail_extra = ''; //如果有套餐产品,代收单价,代收总价也记录下来 $door_price && ($detail_extra .= '门票价格:' . $door_price); $hotel_price && ($detail_extra .= '酒店价格:' . $hotel_price); $total_rec && ($detail_extra .= '代收单价:' . $sin_rec . ',代收总价:' . $total_rec); $opera_detail1 = "创建订单,出发日期{$orders[0]['run_date']},订单渠道:{$orders[0]['supplier_name']},人数:{$count_num},金额{$orders[0]['sin_price']}总额{$orders[0]['total_price']}" . $detail_extra . ",联系人信息:{$orders[0]['customer_name']},{$orders[0]['customer_mobile']},{$id_card},备注信息:{$orders[0]['customer_memo']}"; $opera_detail2 = "创建订单,出发日期{$orders[1]['run_date']},订单渠道:{$orders[1]['supplier_name']},人数:{$count_num},金额{$orders[1]['sin_price']}总额{$orders[1]['total_price']}" . $detail_extra . ",联系人信息:{$orders[1]['customer_name']},{$orders[1]['customer_mobile']},{$id_card},备注信息:{$orders[1]['customer_memo']}"; $update_sql .= "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$orders[0]['order_id']},$user_id,1,'{$time}','{$opera_detail1}','CS系统'),({$orders[1]['order_id']},$user_id,1,'{$time}','{$opera_detail2}','CS系统');"; #1修改代收价(主订单总价,子订单单价) $update_sql .= "UPDATE order_main SET RECEIVE_VALUE=$total_rec WHERE order_id in ($order_ids) ;UPDATE order_main SET RECEIVE_VALUE=$sin_rec WHERE parent_order_id in($order_ids);"; #2修改订单状态和联系人身份证号 $update_sql .= "UPDATE order_main SET update_user_id = " . $user_id . ", update_time = '" . $time . "', order_status = 146, customer_id_no ='$id_card' WHERE order_id in ($order_ids) OR parent_order_id in ($order_ids);"; #3对order_extra_info表插入(如果门票价格和酒店价格有一个不为空则插入) if ($hotel_price || $door_price) { $update_sql .= "INSERT INTO order_extra_info ( order_id, hotel_price, gate_price ) VALUES ($order_arr[0], $hotel_price, $door_price), ($order_arr[1], $hotel_price, $door_price);"; } zzcsUtils::writeLog($update_sql); $res2 = $this->exec($update_sql); if (false === $res2) { $json['code'] = '1'; $json['info'] = '增加往返程订单项失败'; return $json; } //往返订单需要插入关联表 $sql = "insert into to_from(to_orderid,back_orderid) VALUES ({$order_arr[0]},{$order_arr[1]})"; $result = $this->exec($sql); //region 短信发送模块 #对时间和班次发车时间做判断,如果当前时间小于发车时间则发送短信 $time_diff1 = $this->get_time_diff($order_arr[0]); if ($time_diff1 >= 0) { //$res_content1 = $this->send_msg($order_arr[0]); $url = 'http://' . CS1_DOMAIN . '/api/msg/order-send-msg'; $sendInfo = array(); $sendInfo['order_id'] = $order_arr[0]; $sendInfo['msg_type'] = 'cs'; $res_content = httpRequest($url, $sendInfo); } $time_diff2 = $this->get_time_diff($order_arr[1]); if ($time_diff2 >= 0) { //$res_content2 = $this->send_msg($order_arr[1]); $url = 'http://' . CS1_DOMAIN . '/api/msg/order-send-msg'; $sendInfo = array(); $sendInfo['order_id'] = $order_arr[1]; $sendInfo['msg_type'] = 'cs'; $res_content = httpRequest($url, $sendInfo); } //endregion } //添加订单状态记录 $post_data['order_id'] = $order_ids; $post_data['order_status'] = "451,452,453"; $res = $this->post2("http://" . CS_DOMAIN . "/st-xm/Api/add_order_status_log.php", $post_data);//这里线下测试时应该屏蔽掉,否则会把数据插入到正式数据库 $final_json["code"] = '0'; $final_json["info"] = '下单成功'; return $final_json;*/ } /** * Function Description:根据订单id得到 【(班次发车时间-现在时间)的时间戳差值】 * Function Name: get_run_time * @param $order_id * @author 温依莅 */ public function get_time_diff($order_id) { $now = time(); //$sql="select b.run_date,b.RUN_MINUTES,(UNIX_TIMESTAMP(b.run_date)+b.run_minutes*60) as stamp from order_main a left join run_main b on a.run_id=b.run_id where a.PARENT_ORDER_ID=$order_id limit 1"; $sql = "select b.run_date,b.RUN_MINUTES,(UNIX_TIMESTAMP(b.run_date)) as stamp from order_main a left join run_main b on a.run_id=b.run_id where a.PARENT_ORDER_ID=$order_id limit 1"; $res = $this->query($sql); $run_stamp = $res[0]['stamp']; return ($run_stamp + 3600 * 24) - $now; } /** * Function Description:发短信 * Function Name: send_msg * @param $ORDER_ID * * @return array|bool|string * */ public function send_msg($ORDER_ID) { $order_id = $ORDER_ID; $res_content = $this->get_msg_info($order_id); if (false == $res_content) { return false; } //$url = BASE_TICKET_URL.$order_id; //$short_url = sinaShortenUrl(filterUrl($url)); //根据传入的长网址生产短网址 $name = $res_content[0]; $tel = $res_content[1]; $content = $res_content[2]; //$content .= "或者点击以下链接生成二维码:".$short_url; $response = null; $send_success = "-100"; // 默认-100 zzcsUtils::writeLog("短信模板内容:" . $name . "tel" . $tel . "【" . $content . "】"); if ($tel != "-1") { //..发短信 $send_success = "-90"; // 说明手机号不是-1 $response = sendTelMessage($tel, $name, $content, $order_id); zzcsUtils::writeLog(json_encode($response)); } else { $send_success = "-1"; // 说明手机号为-1 zzcsUtils::writeLog('send_msg==tel===' . $tel . ":内容:==》" . $content); } $comment_type = 0; $comment_text = ""; $current_time = date("Y-m-d H:i:s"); $user_id = $this->user_id; if ($response != null) { //$send_success = (int)$response;//原代码 //这里用正则处理返回的xml信息得到error值 $pattern = "/\([-0-9]*?)\<\/error\>/"; preg_match($pattern, $response, $match); $send_success = $match[1]; } $sql1 = "insert into order_send_message(ORDER_ID,SEND_MOBILE,SEND_MESSAGE,SEND_TIME,SEND_ERROR,CREATE_USER_ID,CREATE_TIME,UPDATE_USER_ID,UPDATE_TIME) VALUES ({$order_id},'{$tel}', '{$content}','{$current_time}', {$send_success}, {$user_id},'{$current_time}', {$user_id},'{$current_time}' )"; $this->exec($sql1); //zzcsUtils::writeLog("hotel_order_status.php HT_ADD_MSG_COMMENT()::" . $sql1); return $res_content; } /** * Function Description:..短信模板-改为17:30后OK,当天下单也OK * Function Name: get_msg_info * @param $ORDER_ID * * @return array * */ public function get_msg_info($ORDER_ID) { $not_send_prod = array(451023, 451024, 451025, 451026, 451027, 451028, 451623, 451624, 451625, 451626, 451627, 451628, 451629, 451630, 451636, 451637); $msg_pdo = $this->conn_waice(); $msg_sql = "CALL SP_GET_MESSAGE_TEMPLATE('" . $ORDER_ID . "')"; $content = ''; if (is_object($msg_pdo)) { $msg_result = $msg_pdo->query($msg_sql); $i = 1; $data = array(); if ($msg_result) { $data['code'] = "0"; $data['info'] = ""; do { $row = $msg_result->fetchAll(PDO::FETCH_ASSOC); if ($i == 1) { $data['seat'] = isset($row) ? $row : array(); } else if ($i == 2) { $data['run_info'] = isset($row) ? $row : array(); } else if ($i == 3) { $data['driver'] = isset($row) ? $row : array(); } else if ($i == 4) { $data['dsn_prod'] = isset($row) ? $row : array(); } else if ($i == 5) { $data['zhou_su_prod'] = isset($row) ? $row : array(); } $i++; } while ($msg_result->nextRowset()); } $json_obj = json_decode(json_encode($data), TRUE); $seat = isset($json_obj['seat'][0]) ? $json_obj['seat'][0] : array(); $run_info = isset($json_obj['run_info'][0]) ? $json_obj['run_info'][0] : array(); $driver = isset($json_obj['driver'][0]) ? $json_obj['driver'][0] : array(); $dsn_prod = isset($json_obj['dsn_prod']) ? $json_obj['dsn_prod'] : array(); $zhou_su_prod = isset($json_obj['zhou_su_prod']) ? $json_obj['zhou_su_prod'] : array(); $bus_res_id = isset($json_obj['driver'][0]) ? $json_obj['driver'][0]["bus_res_id"] : 0; if (in_array($run_info['parent_prod_id'], $not_send_prod)) { return false; } //出票成功 // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车,车牌号{车牌号},司机电话{司机姓司机电话}。"; // 得到明天的时间 date_default_timezone_set('PRC'); //解决时区问题 $tomorrow = date("Y-m-d", strtotime("+1 day")); $now_time = date('H:i:s', time()); //判断当前时间是否在17:30:00之后 $cur_date = date('Y-m-d', time()); //迪士尼特殊情况parent_prod_id // $dsn_arr_prod = array(152752, 152759, 152763, 152770, 152777, 152784, 152791, 152801, 152808, 152815, 152822, 152832, 152842, 152852, 152859, 152866, 152873, 152877, 152884, 152891, 152898, 152905, 152915, 152922, 152929, 152936, 152946, 152956, 152966, 152973, 152980, 152990, 153003, 153016, 153023, 153033, 153034, 153044, 153057, 153070, 153083, 153090, 153100, 153110); $dsn_arr_prod = array(); //用来保存迪士尼产品的prod_id foreach ($dsn_prod as $temp) { $dsn_arr_prod[] = $temp['prod_id']; } $zhou_su_arr_prod = array(); foreach ($zhou_su_prod as $temp) { $zhou_su_arr_prod[] = $temp['prod_id']; } $short_url = false; $ticket_url = TICKET_QR_URL . $ORDER_ID; $short_url = sinaShortenUrl($ticket_url); $extra_message = ""; if ($short_url != false) { $extra_message = "您的电子车票链接{$short_url},请在上车前点开,扫码乘车。"; } if (($now_time > "18:30:00" && $run_info['start_date'] == $tomorrow) || $cur_date == $run_info['start_date']) {//17:30之后的订单或者下单时间为今天出行为今天下午 发送短信模板 // if("18:30:00">"17:30:00" && $run_info['start_date']==$tomorrow){ //17:30之后的订单 发送短信模板 // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车,车牌号{车牌号},司机电话{司机姓司机电话}。"; $content = "订单号{订单号},{出发地}({上车站点})—{目的地}({下车站点})标准票{张数}张将于{出发日期} {出发时间}准点发车。车牌号{车牌号},司机电话{司机姓司机电话},请提前10分钟抵达上车地点:{上车站点详细地址}并点开电子车票 {$short_url} 进行验票。如有疑问请拨打客服电话021-33280519。"; } else { $content = "订单号{订单号},{出发日期} {出发时间}{出发地}({上车站点})—{目的地}({下车站点})标准票{张数}张预定成功。发车前一天19点会短信通知您车牌号及司机电话,如未收到短信请拨打客服电话021-33280519。"; } $new_message_array3 = array(450517, 450522); if (in_array($run_info['parent_prod_id'], $new_message_array3)) { if ($run_info['parent_prod_id'] == 450517) { $address_txt = "上车地点:吴山广场西侧河坊巷8号(吴山广场旅游集散中心候车室); 上车方式:请至吴山广场旅游集散中心候车室服务台,凭预定姓名和手机号码上车。"; } else { $address_txt = "上车地点:普陀城北长途客运中心;取票方式:请提前到达(学运路18号)普陀城北长途客运中心候车大厅服务台报预订名字和电话取票。"; } $content = "您已成功预定{出发日期} {出发时间} {出发地}-{目的地}汽车票{张数}张(请最晚提前10分钟到达)。{$address_txt}紧急电话:15888866564。"; } $new_message_array4 = array(450588, 450589); if (in_array($run_info['parent_prod_id'], $new_message_array4)) { $content .= "紧急联系电话:18100158199。"; } //$content .= "提前一天19点之前,如未收到司机电话,请速与021-52218088联系。"; $new_message_array5 = array(451437, 451438); if (in_array($run_info['parent_prod_id'], $new_message_array5)) { $content = "车票订单号{订单号}:您预订的{上车站点}-{下车站点}标准票{张数}张已经预订成功,车牌号{车牌号},司机电话{司机姓司机电话}。发车时间为{出发日期} {出发时间},发车地址为:{上车站点详细地址}。 您的电子车票链接 {$short_url} ,请在上车前点开扫码,或凭短信乘车。请关注微信公众号[蜘蛛出行],提前获取车辆信息。司机会提前与您联系,如有疑问,请联系021-33280578 。"; } $new_message_array5 = array(451440, 451441); $new_message_array6 = array(448780, 450008, 448781); if (in_array($run_info['parent_prod_id'], $new_message_array5)) { $content = "订单号{订单号},{出发日期} {出发时间}{上车站点}—{目的地}标准票{张数}张预定成功。发车前一天19点会短信通知您车牌号及司机电话,如未收到短信请拨打客服电话021-33280519。"; } else if (in_array($run_info['parent_prod_id'], $new_message_array6)) { $content = "订单号{订单号},{出发日期} {出发时间}{上车站点}—{目的地}标准票{张数}张预定成功。发车前一天19点会短信通知您乘车信息,如未收到短信请拨打客服电话021-33280519。"; } if ($seat) { $seat_x = isset($seat['seat_x']) ? $seat['seat_x'] : ""; $seat_y = isset($seat['seat_y']) ? $seat['seat_y'] : ""; $seat_name = isset($seat['seat_name']) ? $seat['seat_name'] : ""; $order_main_id = isset($seat['order_main_id']) ? $seat['order_main_id'] : ""; } else { } if ($run_info) { $order_count = $run_info['order_count']; $start_date = $run_info['start_date']; $start_time = $run_info['start_time']; $parent_order_id = $run_info['parent_order_id']; $end_date = $run_info['end_date']; $start_area = $run_info['start_area']; $end_area = $run_info['end_area']; $res_name = $run_info['res_name']; $parent_prod_id = $run_info['parent_prod_id']; $prod_name = $run_info['prod_name']; $prod_name = "标准票"; $customer_name = $run_info['customer_name']; $customer_mobile = $run_info['customer_mobile']; $start_station_address = $run_info['start_station_address']; $start_end_date = $start_date . "," . $start_time; if ($parent_prod_id == 450504 && $start_date >= "2017-01-27" && $start_date <= "2017-02-02") { $res_name = "迪士尼唐老鸭P停车场"; $start_station_address = "上海迪士尼度假区迪士尼唐老鸭P停车场"; } $content = str_replace("{下车站点}", $run_info['end_res_name'], $content); $content = str_replace("{出发日期}", $start_date, $content); $content = str_replace("{出发时间}", $start_time, $content); $content = str_replace("{上车站点}", $res_name, $content); $content = str_replace("{出发地}", $start_area, $content); $content = str_replace("{目的地}", $end_area, $content); $content = str_replace("{票种名}", $prod_name, $content); $content = str_replace("{张数}", $order_count, $content); $content = str_replace("{上车站点详细地址}", $start_station_address, $content); $content = str_replace("{订单号}", $ORDER_ID, $content); } else { $content = str_replace("{下车站点}", "", $content); $content = str_replace("{出发日期}", "", $content); $content = str_replace("{出发时间}", "", $content); $content = str_replace("{出发地}", "", $content); $content = str_replace("{目的地}", "", $content); $content = str_replace("{票种名}", "", $content); $content = str_replace("{张数}", "", $content); $content = str_replace("{订单号}", "", $content); $content = str_replace("{上车站点详细地址}", "", $content); } if ($driver) { $bus_no = isset($driver['bus_no']) ? $driver['bus_no'] : ""; $driver_name = isset($driver['driver_name']) ? $driver['driver_name'] : ""; $driver_mobile = isset($driver['driver_mobile']) ? $driver['driver_mobile'] : ""; if ($bus_no == "") { $content = str_replace(",车牌号{车牌号}", "", $content); } else { $content = str_replace("{车牌号}", $bus_no, $content); } if ($driver_name == "") { $content = str_replace(",司机电话{司机姓司机电话},", "。", $content); } else { $driver_xing = mb_substr($driver_name, 0, 1, 'utf-8'); $driver_name_mobile = $driver_xing . $driver_mobile; $content = str_replace("{司机姓司机电话}", $driver_name_mobile, $content); } } else { $content = str_replace("车牌号{车牌号},", "", $content); $content = str_replace("司机电话{司机姓司机电话},", "", $content); } /* if( $now_time < "18:30:00" ) { //判断是不是苏州或周庄 // 判断如果不是迪士尼的票就不发短信 if (!in_array($run_info['parent_prod_id'], $dsn_arr_prod) && !in_array($run_info['parent_prod_id'], $zhou_su_arr_prod)) { return array("", "-1", "不是迪士尼、苏州、周庄的票,目前不发送短信"); } }*/ return array(isset($customer_name) ? $customer_name : "", isset($customer_mobile) ? $customer_mobile : "", isset($content) ? $content : "短信错误,联系客服!!!", $run_info); } } /** * Function Description:发送post数据 * Function Name: post2 * @param $url * @param $data * * @return string * */ public function post2($url, $data){//file_get_content $postdata = http_build_query( $data ); $opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata ) ); $context = stream_context_create($opts); $result = file_get_contents($url, false, $context); return $result; } /** * 获取渠道的票种销售方式 * @param $channel_id * @param $ticket_id */ public function getTicketChannelSaleType($channel_id, $ticket_id, $line_type) { $sql = "SELECT sale_type, '0' as price FROM base_supplier_sale as a WHERE NOT EXISTS ( SELECT supplier_id FROM opera_tickets_distrib WHERE supplier_id = a.supplier_id AND ticket_id = " . $ticket_id . " AND cancel_flag = 0 ) AND supplier_id = " . $channel_id . " AND parent_type = 310 AND product_type IN (" . $line_type . ", 0) AND cancel_flag = 0 UNION ALL SELECT sale_type, prod_price as price FROM opera_tickets_distrib WHERE supplier_id = " . $channel_id . " AND ticket_id = " . $ticket_id . " AND authority_status = 1 AND cancel_flag = 0"; //zzcsUtils::writeLog($sql); $sale_type = $this->query($sql); if (count($sale_type) == 0) { return false; } $sale_type = $sale_type[0]; return $sale_type; } /** * ////单产品和组合产品订单列表头文件 * //hyk * @param $web_date * @return array */ function singleOrderListHeadInfo($web_date) { ////单产品和组合产品订单列表头文件 //hyk // if (isset($web_date['type']) && $web_date['type'] != 0) { // $res1 = $this->productLine(); // $sql = "SELECT // a.supplier_id, // b.supplier_name // FROM // base_supplier_sale AS a // INNER JOIN base_supplier AS b ON a.supplier_id = b.id // WHERE // a.parent_type = 310 // AND a.product_type in(" . $web_date['type'] . ",0) // AND a.cancel_flag = 0 // AND b.cancel_flag = 0 // AND b.is_disabled = 0 // GROUP BY // a.supplier_id"; // $res = $this->query($sql); // $biller_list = $this->getBiller(); // $json = array(); // $json['code'] = '0'; // $json['info'] = '渠道商和产品线,计调员返回'; // $json['supplier_list'] = $res; // $json['product_line'] = $res1; // $json['biller_list'] = $biller_list; // return $json; // } else { // $res1 = $this->productLine(); // $biller_list = $this->getBiller(); // $sql = "SELECT // a.supplier_id, // b.supplier_name // FROM // base_supplier_sale AS a // INNER JOIN base_supplier AS b ON a.supplier_id = b.id // WHERE // a.parent_type = 310 // AND a.cancel_flag = 0 // AND b.cancel_flag = 0 // AND b.is_disabled = 0 // GROUP BY // a.supplier_id"; // $res = $this->query($sql); // $json = array(); // $json['code'] = '0'; // $json['info'] = '渠道商和产品线,计调员返回'; // $json['supplier_list'] = $res; // $json['product_line'] = $res1; // $json['biller_list'] = $biller_list; // return $json; // } //娄梦宁2017.1.17修改订单列表头部信息获取 $res1 = $this->productLine(); $biller_list = $this->getBiller(); $sql = ''."SELECT a.supplier_id, b.supplier_name FROM base_supplier_sale AS a INNER JOIN base_supplier AS b ON a.supplier_id = b.id WHERE a.parent_type = 310 AND a.cancel_flag = 0 AND b.cancel_flag = 0 AND b.is_disabled = 0 GROUP BY a.supplier_id"; $res = $this->query($sql); //厦门上车区域数组 $sql=''."select id,area_name as name from base_area where parent_id=1161"; $start_area_arr=$this->query($sql); //厦门上车点数组 $sql=''."select id,res_name as name from base_resource where area_id in (select id from base_area where parent_id=1161) and zone_mark =0 and res_type_id=24"; $start_res_arr=$this->query($sql); //车牌号数组 $sql=''."select bus_id as id,bus_no as num from base_bus where bus_no like '闽%'"; $bus_no_arr=$this->query($sql); //司机导游姓名id数组 $sql=''."select guide_id as id ,guide_name as name from base_guide UNION select driver_id as id,driver_name as name from base_driver where org_id in (417,10997)"; $send_driver_arr=$this->query($sql); $json = array(); $json['code'] = '0'; $json['info'] = '渠道商和产品线,计调员返回'; $json['supplier_list'] = $res; $json['product_line'] = $res1; $json['biller_list'] = $biller_list; $json['start_area_arr'] = $start_area_arr; $json['start_res_arr'] = $start_res_arr; $json['bus_no_arr'] = $bus_no_arr; $json['send_driver_arr'] = $send_driver_arr; return $json; } /** * //单产品订单列表 * @param $web_data * @return int */ function singleOrderList1($web_data) { //单产品订单列表 //hyk $user_id = $this->user_id; $time_limit = isset($web_data['time_limit']) ? trim($web_data['time_limit']) : false; $start_time = isset($web_data["start_time"]) ? trim($web_data["start_time"]) : false; $end_time = isset($web_data["end_time"]) ? trim($web_data["end_time"]) : false; $order_source = isset($web_data["order_source"]) ? trim($web_data["order_source"]) : false; $order_status = isset($web_data["order_status"]) ? trim($web_data["order_status"]) : false; $current_page = isset($web_data["current_page"]) ? trim($web_data["current_page"]) : false; $page_size = isset($web_data["page_size"]) ? trim($web_data["page_size"]) : false; $product_line = isset($web_data["product_line"]) ? trim($web_data["product_line"]) : false; $biller = isset($web_data["biller"]) ? trim($web_data["biller"]) : false;//添加计调员id $create_user_id = $biller; $line = isset($web_data["line"]) ? trim($web_data["line"]) : false; $more_search = isset($web_data["more_search"]) ? trim($web_data["more_search"]) : false; $search_type = isset($web_data["search_type"]) ? trim($web_data["search_type"]) : false; if ($time_limit === false || $start_time === false || $end_time === false || $order_source === false || $order_status === false || $current_page === false || $page_size === false || $product_line === false || $search_type === false || $line === false || $more_search === false || $biller === false) { //参数不完整; $json["code"] = '2'; $json["info"] = "缺少必要参数"; return $json; } //此处添加计调员id后存储过程为 /*$sql = "CALL xm_order_get_list_xm(" . $user_id . "," . $time_limit . ",'" . $start_time . "','" . $end_time . "'," . $order_source . "," . $order_status . ",'" . $more_search . "'," . $current_page . "," . $page_size . ",'" . $line . "','',''," . $search_type . "," . $product_line . "," . $biller.")";*/ $sql = "CALL xm_order_get_list_xm(" . $user_id . "," . $create_user_id . "," . $time_limit . ",'" . $start_time . "','" . $end_time . "'," . $order_source . "," . $order_status . ",'" . $more_search . "'," . $current_page . "," . $page_size . ",'" . $line . "','',''," . $search_type . "," . $product_line . ")"; zzcsUtils::writeLog($sql); $res = $this->procQuery($sql); if ($res['code'] != 0) { //执行存储过程出错 $json["code"] = $res['code']; $json["info"] = $res['info']; return $json; } else { $json["code"] = "0"; $json["info"] = "订单列表"; $json["page"]["total_count"] = $res["data"][0][0]["num"]; $json["page"]["page_count"] = $res["data"][0][0]["pagecount"]; $json["page"]["curr_page"] = $res["data"][0][0]["currpage"]; $json["page"]["page_size"] = $res["data"][0][0]["pagesize"]; $json["order_list"] = $res["data"][1]; $label_data = array(); if (empty($res["data"][2])) { // $json["label"]["pay"]=$res["data"][2]; $label_data["pay"] = 0; $label_data["out"] = 0; $label_data["end"] = 0; $label_data["cancle"] = 0; $label_data["all"] = 0; } else { $label_data["pay"] = 0; $label_data["out"] = 0; $label_data["end"] = 0; $label_data["cancle"] = 0; $label_data["all"] = 0; $ttt = 0; foreach ($res["data"][2] as $temp) { $ttt = $ttt + $temp["order_cnt"]; switch ($temp["order_status"]) { case 145: $label_data["pay"] = $temp["order_cnt"]; break; case 146: $label_data["out"] = $temp["order_cnt"]; break; case 147: $label_data["end"] = $temp["order_cnt"]; break; case 148: $label_data["cancle"] = $temp["order_cnt"]; break; } } $label_data["all"] = $ttt; } $json["label"] = $label_data; return $json; } } /** * ZS * 取消订单 */ public function cancelOrder($param) { $order_id = isset($param["order_id"]) ? trim($param["order_id"]) : false; $user_id = $this->user_id; if (!$order_id) { //参数不完整; $json["code"] = '2'; $json["info"] = "缺少必要参数"; return $json; } $sql = "call sp_cancel_order(" . $user_id . "," . $order_id . ")"; zzcsUtils::writeLog($sql); $res = $this->procQuery($sql); if ($res['code'] != 0) { //执行存储过程出错 $json["code"] = $res['code']; $json["info"] = $res['info']; } else { $json["code"] = "0"; $json["info"] = "退票成功"; } return $json; } /** * User: wangxj * * excel导入订单 * * @params * * @return array 返回没有生成订单的数据 */ public function importOrder($param) { $channel_id = 9; //渠道商,目前先固定 渠道商对应业务员sales_man $flag = 0; //1上传全部成功,-1全部失败,2部分成功 $line_id_fly = 0; $line_id_back = 0; $result = array('code' => 0, 'info' => 'sheet名称必须为“专车接机”和“专车送机”', 'data' => array()); $line_id = 0; $sql = "select line_id, line_name from opera_line where cancel_flag = 0 and (line_name='机场接驳接机' or line_name = '机场接驳送机')"; $res = $this->query($sql); if (!$res || count($res) == 0) { foreach ($res as $line) { if (trim($line['line_name']) == '机场接驳接机') $line_id_back = $line['line_id']; else if (trim($line['line_name']) == '机场接驳送机') $line_id_fly = $line['line_id']; } } else { $result['code'] = '2'; $result["info"] = "缺少必要参数"; return $result; } if (isset($_FILES['file']) && file_exists($_FILES['file']['tmp_name'])) { require_once ROOT_PATH . '/ZZCS/Common/PHPExcel/IOFactory.php'; $excel = PHPExcel_IOFactory::load($_FILES['file']['tmp_name']); $allSheet = array('专车接机', '专车送机'); foreach ($allSheet as $type => $sheetName) { //run_main查找run_id取prod_id,在opera_line可以查看line_id if ($sheetName == '专车送机') $line_id = $line_id_fly; //450917; else $line_id = $line_id_back; //450916; $worksheet = $excel->getSheetByName($sheetName); if (!$worksheet || $line_id == 0) continue; $worksheet = $worksheet->toArray(); $worksheet = array_slice($worksheet, 1); //先按酒店排序,再按出发或抵达时间排序 // usort($worksheet, function ($a, $b) { // $c = $a['8'] - $b['8']; // return $c != 0 ? $c : $a['6'] - $b['6']; // }); foreach ($worksheet as $key => $item) { $valid = zzcsUtils::validateParams(array( '1,2,3,4' => 'empty' ), $item); if (!$valid['status']) { continue; } $res = $this->initOrder($line_id, $channel_id, $item, $type); if ($res['code'] != 0) { //为0下单成功 $result['data'][] = $item + array('error' => $res['info'], 'type' => $sheetName); if ($flag == 0) $flag = -1; elseif ($flag == 1) $flag = 2; } else { if ($flag == 0) $flag = 1; elseif ($flag == -1) $flag = 2; } } } if ($flag == "1") { $result['info'] = "批量导入成功"; } else if ($flag == "2") { $result['info'] = "部分导入成功"; } else if ($flag == "-1") { $result['info'] = "导入失败"; } $result['code'] = $flag; } else { $result['code'] = '2'; $result["info"] = "缺少必要参数"; } return $result; } /** * User: wangxj * * 加载接送机数据 * * @params * * @return array */ protected function initOrder($line_id, $channel_id, $params, $type) { $EXCEL_ORDER_ID = 0; $EXCEL_NAME = 3; $EXCEL_TEL = 4; $EXCEL_FLIGHT = 5; $EXCEL_DATE = 6; $EXCEL_FLIGHT_T = 7; $EXCEL_TIME = 8; $EXCEL_MOUNT = 9; $EXCEL_HOTEL = 10; $EXCEL_NOTE = 11; $EXCEL_SUPPLIER = 2; $result = array(); $airport_res_id = 10575; //目前先固定 $pay_type = 275; $supplier_name = $params[$EXCEL_SUPPLIER]; //渠道商ID $sql = "select id from base_supplier where supplier_name = '$supplier_name' and cancel_flag = 0 and SUPPLIER_TYPE = 301 and is_disabled = 0 "; $res = $this->query($sql); if (!$res || count($res) == 0) return array('code' => 2, 'info' => '没有对应渠道商: ' . $supplier_name); else { $channel_id = $res[0]['id']; } //代收金额 $receive_value = 0; $user_id = $this->user_id; $channel_order_id = $params[$EXCEL_ORDER_ID]; // $run_date = date('Y-M-d', strtotime($params[4])); // ::todo 日期格式有待匹配优化 if (DateTime::createFromFormat('m-d-y', $params[$EXCEL_DATE])) $run_date = DateTime::createFromFormat('m-d-y', $params[$EXCEL_DATE])->format('Y-m-d'); else $run_date = date('Y-m-d', strtotime($params[$EXCEL_DATE])); //查看商家自己的订单号在数据库中是否存在,如果已经存在说明已经导入过订单,提示重复 if (trim($params[$EXCEL_ORDER_ID]) != '') { $sql = "select order_id from order_main where cancel_flag = 0 and ORDER_STATUS <> 148 and OUTSIDE_ORDER_NO='" . $params[$EXCEL_ORDER_ID] . "' limit 1"; $res = $this->query($sql); if ($res && !empty($res)) { return array('code' => 2, 'info' => '商家订单号已经录入过订单'); } } $reg = '/^\d?\d:\d?\d/'; $run_minutes = 0; if (!preg_match($reg, $params[$EXCEL_TIME], $run_time)) { return array('code' => 2, 'info' => '时间格式不正确'); } else { //把时间转换为 分钟 $tmpArray = explode(':', $run_time[0]); $run_minutes += $tmpArray[0] * 60 + $tmpArray[1]; } // 去程票种,格式为{去程/返程标志(1:去程 2:返程),去程/返程班次ID,票种ID,票种单价,预定数量} $sql = "select run_id from RUN_MAIN where RUN_DATE='$run_date' and RUN_MINUTES >= '$run_minutes' and PROD_ID = $line_id and RUN_STATUS=138 order by RUN_MINUTES limit 1"; $res = $this->query($sql); if (!$res || empty($res)) { return array('code' => 2, 'info' => '对应线路无该时间段班次'); } $run_id = $res[0]['run_id']; //先获取起始站点和目的站点的res_id, zone_mark:0为站点 1为区域,需要根据具体站点查出区域,票种都是以区域为准 $res_name = trim($params[$EXCEL_HOTEL]); //需要用正则匹配删除部分多余字符 $reg = "/[^\x{4e00}-\x{9fa5}a-zA-Z]/u"; $res_name = preg_replace($reg, '', $res_name); $full_res_name = $res_name; $res_name = str_replace(array("大酒店", "客栈", "酒店"), '', $res_name); $sql = "select parent_id,area_id, res_id from base_resource where cancel_flag = 0 and zone_mark = 0 and res_name like '$res_name%' limit 1"; $res = $this->query($sql); if (!$res || empty($res)) { return array('code' => 2, 'info' => '当前线路没有这个站点: ' . $full_res_name); } $res_station_area_id = $res[0]['parent_id'] != 0 ? $res[0]['parent_id'] : $res[0]['res_id']; $res_station_id = $res[0]['res_id']; $line_type = 256; //穿梭巴士 if ($type == 0) { $start_area_res_id = $airport_res_id; $end_area_res_id = $res_station_area_id; $start_res_id = $airport_res_id; $end_res_id = $res_station_id; } else { $start_area_res_id = $res_station_area_id; $end_area_res_id = $airport_res_id; $start_res_id = $res_station_id; $end_res_id = $airport_res_id; } $ticket_info = $this->getTicketInfo(array( 'channel_id' => $channel_id, 'run_id' => $run_id, 'start_res_id' => $start_area_res_id, 'end_res_id' => $end_area_res_id, 'line_type' => $line_type, )); if ($ticket_info['code'] != 0) return $ticket_info; $ticket_id = $ticket_info['list'][0]['ticket_id']; $ticket_amount = $ticket_info['list'][0]['price']; $count = $params[$EXCEL_MOUNT]; $ticket_info = "{1,$run_id,$ticket_id,$ticket_amount,$count}"; //渠道商信息, $chanel_info = $this->getGoChannel(array( 'run_id' => $run_id, 'start_res_id' => $start_res_id, 'end_res_id' => $end_res_id, 'line_type' => $line_type, 'supplier_id' => $channel_id )); if ($chanel_info['code'] != 0) return $chanel_info; $salesman = $chanel_info['list'][0]['sales_man']; //{联系人,联系电话,备注} $customer_info = "{" . $params[$EXCEL_NAME] . "," . $params[$EXCEL_TEL] . "," . $params[$EXCEL_NOTE] . "_" . $params[$EXCEL_FLIGHT] . "_" . $params[$EXCEL_FLIGHT_T] . "}"; //由于穿梭巴士下单时,票种信息是区域到区域,实际订单其实需要定位到具体站点,所以加2个参数,start_res_id, end_res_id //$sql = "call sp_make_order_xm(" . $user_id . ",'" . $ticket_info . "','" . $customer_info . "'," . $channel_id . ",'" . $channel_order_id . "','" . $salesman . "'," . $pay_type . ")"; $sql = "call sp_make_order_xm(" . $user_id . ",'" . $ticket_info . "','" . $customer_info . "'," . $channel_id . ",'" . $channel_order_id . "','" . $salesman . "'," . $pay_type . "," . $start_res_id . "," . $end_res_id . "," . $receive_value . ")"; $res = $this->procQuery($sql); if ($res['code'] == 0) { $time = date('Y-m-d H:i:s', time()); $json['code'] = '0'; $json['info'] = '录入订单成功'; $json['order_id'] = $res['data'][0][0]['order_id']; $update_status_sql = "UPDATE order_main SET update_user_id = " . $user_id . ", update_time = '" . $time . "', order_status = 146 WHERE order_id in (" . $json["order_id"] . ") OR parent_order_id in (" . $json["order_id"] . ")"; $this->query($update_status_sql); } $result = $res; return $result; } /** * User:温依莅 * 获取计调员信息 * @param */ public function getBiller() { $sql = "select id,user_name,IF(true_name='',user_name,true_name) 'true_name' from base_user where cancel_flag=0 and user_role in(6,7,14)"; $biller_info = $this->query($sql); if (count($biller_info) == 0) { return array(); } return $biller_info; } /** * Function Description:订单列表统一查询入口 * Function Name: singleOrderList1 * @param $web_data * * @return array * * @author 娄梦宁 */ public function singleOrderList($web_data){ $time_limit = isset($web_data["time_limit"]) ? trim($web_data["time_limit"]) : false; $start_time = isset($web_data["start_time"]) ? trim($web_data["start_time"]) : false; $end_time = isset($web_data["end_time"]) ? trim($web_data["end_time"]) : false; $order_source = isset($web_data["order_source"]) ? trim($web_data["order_source"]) : false; $order_status = isset($web_data["order_status"]) ? trim($web_data["order_status"]) : false; $current_page = isset($web_data["current_page"]) ? trim($web_data["current_page"]) : false; $page_size = isset($web_data["page_size"]) ? trim($web_data["page_size"]) : false; $product_line = isset($web_data["product_line"]) ? trim($web_data["product_line"]) : false; $biller = isset($web_data["biller"]) ? trim($web_data["biller"]) : false;//添加计调员id $user_id = $this->user_id; $line = isset($web_data["line"]) ? trim($web_data["line"]) : false; $more_search = isset($web_data["more_search"]) ? trim($web_data["more_search"]) : false; $search_type = isset($web_data["search_type"]) ? trim($web_data["search_type"]) : false; //1.13新增条件参数 $start_area_id=isset($web_data["start_area_id"]) ? trim($web_data["start_area_id"]) : false; $start_res_id=isset($web_data["start_res_id"]) ? trim($web_data["start_res_id"]) : false; $end_area_id=isset($web_data["end_area_id"]) ? trim($web_data["end_area_id"]) : false; $end_res_id=isset($web_data["end_res_id"]) ? trim($web_data["end_res_id"]) : false; $run_length=isset($web_data["run_length"]) ? trim($web_data["run_length"]) : false; $bus_send_no=isset($web_data["bus_send_no"]) ? trim($web_data["bus_send_no"]) : false; $send_driver_name=isset($web_data["send_driver_name"]) ? trim($web_data["send_driver_name"]) : false; $send_driver_mobile=isset($web_data["send_driver_mobile"]) ? trim($web_data["send_driver_mobile"]) : false; if ($time_limit === false || $start_time === false || $end_time === false || $order_source === false || $order_status === false || $current_page === false || $page_size === false || $product_line === false || $search_type === false || $line === false || $more_search === false || $biller === false || $start_area_id === false || $start_res_id === false || $bus_send_no === false ||$send_driver_name === false ||$send_driver_mobile === false ) { //参数不完整; $json["code"] = '2'; $json["info"] = "缺少必要参数"; return $json; } //1. 筛选所有出行信息符合条件的订单 //1.1拼接where语句 if($time_limit==1){//下单时间或者出发时间 $start_time_where=" a.CREATE_TIME between '$start_time' and '$end_time' "; }else{ $start_time_where=" a.prod_start_station_date between '$start_time' and '$end_time' "; } if($order_source==0){//订单渠道 $order_source_where=" "; }else{ $order_source_where=" and a.OUTSIDE_SALE_ORG_ID=$order_source "; } if($product_line==0){//产品线 $product_line_where=" "; }else{ $product_line_where=" and b.product_type=$product_line "; } if($line==''){//线路编号或名称 $line_where=" "; }else{ $line_where=" and ( a.parent_prod_name='$line' or a.PARENT_PROD_ID=$line) "; } if($order_status==0){//订单状态 $order_status_where=" "; }else{ $order_status_where=" and a.order_status=$order_status "; } if($more_search==''){//更多查询 $more_search_where=" "; }else{ $more_search_where=" and ( a.order_id=$more_search or a.customer_name ='$more_search' or a.customer_mobile='$more_search' or a.SALES_MAN='$more_search' or a.OUTSIDE_ORDER_NO='$more_search' ) "; } if($biller==0){//计调 $biller_where=" "; }else{ $biller_where="and a.main_create_user_id=$biller "; } if($search_type==0){//上车区域 $search_type_where=" "; }else{ $search_type_where=" and e.line_type=$search_type "; } if($start_area_id==0){//上车区域 $start_area_id_where=" "; }else{ $start_area_id_where=" and a.PROD_START_STATION_AREA_ID=$start_area_id "; } if($start_res_id==0){//上车点 $start_res_id_where=" "; }else{ $start_res_id_where=" and a.PROD_START_STATION_res_ID=$start_res_id "; } if($end_area_id==0){//下车区域 $end_area_id_where=" "; }else{ $end_area_id_where=" and and a.PROD_end_STATION_AREA_ID=$end_area_id "; } if($end_res_id==0){//下车点 $end_res_id_where=" "; }else{ $end_res_id_where=" and and a.PROD_end_STATION_AREA_ID=$end_area_id "; } if($run_length==0){//行程段 $run_length_where =''; }elseif($run_length==1){ $run_length_where =" and c.parent_prod_name ='岛内接驳' "; }elseif($run_length==2){ $run_length_where =" and c.parent_prod_name != '岛内接驳' and c.prod_start_station_date =a.prod_start_station_date "; }else{ $run_length_where =" and c.prod_start_station_date !=a.prod_start_station_date "; } if($bus_send_no=='请选择'){//车牌号 $bus_send_no_where=" "; }else{ $bus_send_no_where=" AND b.SEND_BUS_NO = '$bus_send_no' "; } if($send_driver_name=='请选择'){//司机或导游名 $send_driver_name_where=" "; }else{ $send_driver_name_where=" AND (b.SEND_DRIVER_NAME = '$send_driver_name' OR b.SEND_TOUR_GUIDE_NAME = '$send_driver_name') "; } if($send_driver_mobile==0){//司机或导游手机号 $send_driver_mobile_where=" "; }else{ $send_driver_mobile_where=" AND (b.SEND_DRIVER_MOBILE = '$send_driver_mobile' OR b.SEND_TOUR_GUIDE_MOBILE = '$send_driver_mobile') "; } $current_page=($current_page-1)*$page_size; //符合条件的订单ID $sql=''."SELECT GROUP_CONCAT(x.M_ID) as arr from( SELECT IFNULL(d.status,2) as status, a.order_id M_ID FROM order_main a inner join order_main c on a.order_id=c.parent_order_id INNER JOIN run_bus b ON c.run_id = b.run_id LEFT JOIN order_unusual_process d on d.order_id= a.order_id LEFT JOIN opera_line e on a.PARENT_PROD_ID= e.line_id where $start_time_where $order_source_where $product_line_where $line_where $order_status_where $more_search_where $biller_where $start_area_id_where $start_res_id_where $end_area_id_where $end_res_id_where and a.PARENT_ORDER_ID=0 $run_length_where $bus_send_no_where $send_driver_name_where $send_driver_mobile_where and a.CANCEL_FLAG=0 and b.CANCEL_FLAG=0 and c.CANCEL_FLAG=0 and e.CANCEL_FLAG=0 $search_type_where GROUP BY a.order_id order by status,a.create_time desc limit $current_page,$page_size )x"; $order_id_arr=$this->query($sql); $id_arr=$order_id_arr[0]['arr']; //查询展示数据 $sql=''."SELECT a.order_id M_ID, a.create_time, ifnull((SELECT true_name FROM base_user WHERE id = a.main_create_user_id),'') create_user_name, ifnull((SELECT supplier_name FROM base_supplier WHERE id = a.OUTSIDE_SALE_ORG_ID),'') org_name, a.outside_order_no, ifnull(a.sales_man,'') as sales_man_name, a.parent_prod_name line, a.order_description, a.PROD_START_STATION_RES_name start_station, a.PROD_START_STATION_area_name AS start_area, a.prod_start_station_date AS travel_time, a.customer_name contacts, a.customer_mobile AS tel, a.order_price AS total_price, ifnull((SELECT type_name FROM dict_type WHERE id = (SELECT pay_type_id_1 FROM order_pay_detail WHERE id = (SELECT id FROM order_pay_main WHERE order_id = a.order_id))),'授信支付') as pay_type_name, a.order_status, (a.receive_value) as receive_value, ifnull(a.customer_memo,'') as memo, IFNULL(d.status,2) as status, ifnull(d.special_state,'') as special_state, a.real_passenger_num real_passager_num FROM order_main a inner join order_main c on a.order_id=c.parent_order_id INNER JOIN run_bus b ON c.run_id = b.run_id LEFT JOIN order_unusual_process d on d.order_id= a.order_id LEFT JOIN opera_line e on a.PARENT_PROD_ID= e.line_id WHERE a.order_id in($id_arr) GROUP BY a.order_id order by status,a.create_time desc "; //获取订单状态分组信息 $order_list=$this->query($sql); $sql=''."SELECT ifnull(SUM(x.145cnt),0) as pay,ifnull(SUM(x.146cnt),0) as `out`, ifnull(SUM(x.147cnt),0) as end,ifnull(SUM(x.148cnt),0) as cancel,ifnull(SUM(1),0) as `all` from( SELECT a.order_id M_ID, if(a.order_status ='145', 1,0) '145cnt', if(a.order_status ='146', 1,0) '146cnt', if(a.order_status ='147', 1,0) '147cnt', if(a.order_status ='148', 1,0) '148cnt', a.order_status FROM order_main a inner join order_main c on a.order_id=c.parent_order_id INNER JOIN run_bus b ON c.run_id = b.run_id LEFT JOIN order_unusual_process d on d.order_id= a.order_id LEFT JOIN opera_line e on a.PARENT_PROD_ID= e.line_id WHERE $start_time_where $order_source_where $product_line_where $line_where $order_status_where $more_search_where $biller_where $start_area_id_where $start_res_id_where $end_area_id_where $end_res_id_where and a.PARENT_ORDER_ID=0 $run_length_where $bus_send_no_where $send_driver_name_where $send_driver_mobile_where and a.CANCEL_FLAG=0 and b.CANCEL_FLAG=0 and c.CANCEL_FLAG=0 and e.CANCEL_FLAG=0 $search_type_where GROUP BY a.order_id )x"; $label=$this->query($sql); $total_count=intval($label[0]['all']); $page_count=ceil($total_count/$page_size); //出行信息内容拼接 foreach ($order_list as $key=>$val){ $order_id=$val['M_ID']; $sql=''."SELECT SEND_BUS_NO, SEND_DRIVER_NAME, SEND_TOUR_GUIDE_NAME, SEND_DRIVER_MOBILE, SEND_TOUR_GUIDE_MOBILE, if(b.parent_prod_name ='岛内接驳','1. ',(if(b.PROD_START_STATION_DATE=c.PROD_START_STATION_DATE,'2. ','3. '))) as seq FROM order_main c,run_bus a INNER JOIN order_main b ON a.run_id = b.run_id WHERE b.parent_order_id = $order_id and b.RUN_BUS_ORDER_ID=a.BUS_ORDER_ID and c.order_id=$order_id GROUP BY a.run_id ORDER BY seq"; $trip_info=$this->query($sql); $trip_str=''; foreach($trip_info as $v){ $trip_str.=$v['seq'].$v['SEND_BUS_NO'].' '.$v['SEND_DRIVER_NAME'].' '.$v['SEND_DRIVER_MOBILE'].' '.$v['SEND_TOUR_GUIDE_NAME'].' '.$v['SEND_TOUR_GUIDE_MOBILE'].'
'; } $order_list[$key]['trip_info']=$trip_str; } $json=array( 'code'=>0, 'info'=>'订单列表', 'page'=>array( 'total_count'=>$total_count, 'curr_page'=>$current_page+1, 'page_size'=>intval($page_size), 'page_count'=>$page_count ), 'label'=>$label[0], 'order_list'=>$order_list ); return $json; } /** * Function Description:校验渠道订单号是否唯一存在 * Function Name: checkOutsideNo * @param $post * * @return array * * @author 娄梦宁 */ public function checkOutsideNo($post){ $ouside_no = isset($post["outside_no"]) ? trim($post["outside_no"]) : false; $sql='select count(1) as cnt from order_main where cancel_flag=0 and outside_order_no = "'.$ouside_no.'"'; $res=$this->query($sql); $cnt=$res[0]['cnt']; if($cnt!=0){ return array( 'code'=>1, 'info'=>'该渠道订单号已存在!', ); } return array( 'code'=>0, 'info'=>'该渠道订单号可添加!' ); } }