query($sql); if(count($res) == 0) { $json['code'] = '0'; $json['info'] = '无票种信息'; $json['ticket_list'] = array(); $json['page']['page_size'] = $page_size; $json['page']['current_page'] = $current_page; $json['page']['total_count'] = '0'; $json['page']['total_page'] = '0'; return $json; } $count_sql = "SELECT count(id) as total_count FROM opera_tickets_group WHERE line_id = " . $line_id . " AND cancel_flag = 0"; $total_count = $this->query($count_sql); $total_count = $total_count[0]['total_count']; $total_page = ceil($total_count/$page_size); $json['code'] = '0'; $json['info'] = '返回促销规则列表成功'; $json['ticket_list'] = $res; $json['page']['page_size'] = $page_size; $json['page']['current_page'] = $current_page; $json['page']['total_count'] = $total_count; $json['page']['total_page'] = $total_page; return $json; } /** * 获取票种配置信息 */ public function getTicketBase($param) { //获取上下车可配置上车站点数据 $line_id = trim($param['line_id']);//152251 if(!$line_id) { $json['code'] = '2'; $json['info'] = '缺少必要参数'; return $json; } $sql = "SELECT res_id,(SELECT res_name FROM base_resource WHERE res_id = s.res_id) AS res_name,order_id FROM opera_station AS s WHERE line_id = " . $line_id . " AND inout_type in (108,109) AND cancel_flag = 0 GROUP BY res_id"; $start_res = $this->query($sql); //获取座位类型 $base_seat = array(72); $seat_type_result = $this->getSeat(); foreach($seat_type_result as $k => $v) { if(in_array($v['id'],$base_seat)) { $seat_type[] = $v; } } //获取人群属性 // $base_human_type = array(159,160,161); // $human_type_result = $this->getPeopleType(); $human_type = array(array('id' => '0','type_name' => '不限')); // foreach($human_type_result as $k => $v) // { // if(in_array($v['id'],$base_human_type)) // { // $human_type[] = $v; // } // } $json['code'] = '0'; $json['info'] = '获取票种配置成功'; $json['start_res'] = $start_res; $json['seat_type'] = $seat_type; $json['human_type'] = $human_type; return $json; } /** *获取下车站点信息 */ public function getTicketEndStation($param) { $line_id = isset($param['line_id'])?trim($param['line_id']):false;//线路ID $start_res_id = isset($param['start_res_id'])?trim($param['start_res_id']):false;//出发站ID if($line_id===false || $start_res_id === false ) { $json['code'] = '2'; $json['info'] = '缺少必要参数'; return $json; } if(empty($line_id) || empty($start_res_id)) { $json['code'] = '2'; $json['info'] = '部分参数为空'; return $json; } $sql = "SELECT order_id,res_id,(SELECT res_name FROM base_resource WHERE res_id = s.res_id) AS res_name FROM opera_station as s WHERE line_id = " . $line_id . " AND order_id > (SELECT order_id FROM opera_station WHERE line_id = s.line_id AND res_id = " . $start_res_id . " AND cancel_flag = 0 LIMIT 1) AND inout_type IN (109, 110) AND res_id != " . $start_res_id . " AND cancel_flag = 0 GROUP BY res_id"; $end_res = $this->query($sql); $json['code'] = '0'; $json['info'] = '获取下车站点成功'; $json['end_res'] = $end_res; return $json; } /** * 添加票种信息 * @param $param * @return mixed */ public function addTicket($param) { //存储过程:SP_SAVE_LINE_TICKET_XM $line_id = isset($param['line_id'])?trim($param['line_id']):false; $station_str = isset($param['station_str'])?trim($param['station_str']):false; $prod_price = isset($param['prod_price'])?trim($param['prod_price']):false; $cus_price = isset($param['cus_price'])?trim($param['cus_price']):false; $cost_price = isset($param['cost_price'])?trim($param['cost_price']):false; $seat_type = isset($param['seat_type'])?trim($param['seat_type']):false; $human_type = isset($param['human_type'])?trim($param['human_type']):false; $human_type=159; $line_type = 1; $user_id = $this->user_id; $create_time = date("Y-m-d H:i:s",time()); if(!$line_id || $station_str === false || $prod_price === false || $cus_price === false || $cost_price === false || $seat_type === false || $human_type === false) { $json['code'] = '2'; $json['info'] = '缺少必要参数'; return $json; } if(empty($line_id) || empty($station_str) || empty($prod_price) || empty($cus_price) || empty($seat_type) || empty($human_type) ) { $json['code'] = '2'; $json['info'] = '部分参数为空'; return $json; } $ticket_name_sql = "select type_name from dict_type where id = " . $seat_type; $ticket_name = $this->query($ticket_name_sql); $ticket_name = $ticket_name[0]['type_name'] . "票"; //获取最大的ticket_id $ticket_id_sql = "select ifnull(max(ticket_id),0) as ticket_id from opera_tickets"; $ticket_id = $this->query($ticket_id_sql); $ticket_id = $ticket_id[0]['ticket_id']; $station_str = substr($station_str,1,-1); $station_array = explode("}{",$station_str); //获取检验是否存在票种的查询条件 foreach($station_array as $k => $v) { $res_group = explode(",",$v); //获取所有的站点id; $res_array[$res_group[0]] = $res_group[0]; $res_array[$res_group[1]] = $res_group[1]; $check_arr[] = "(start_station_res_id = " . $res_group[0] . " and end_station_res_id = " . $res_group[1] . ")"; } $check_str = "(" . implode(" or ",$check_arr) . ")"; //检查是否存在已添加的票种 $check_sql = "SELECT start_station_res_id, (SELECT res_name FROM base_resource WHERE res_id = t.start_station_res_id) as start_station_res_name, end_station_res_id, (SELECT res_name FROM base_resource WHERE res_id = t.end_station_res_id) as end_station_res_name FROM opera_tickets as t WHERE line_id = " . $line_id . " AND cancel_flag = 0 AND seat_type = " . $seat_type . " AND human_type = " . $human_type . " AND " . $check_str; $check_ticket = $this->query($check_sql); if(count($check_ticket) > 0) { foreach($check_ticket as $k => $v) { $info_array[] = $v['start_station_res_name'] . "-" . $v['end_station_res_name']; } $json['code'] = '1'; $json['info'] = implode(",",$info_array) . "的该人群及座位等级已添加过,添加失败"; return $json; } //查询所有站点ID的area_id $area_sql = "SELECT area_id, res_id FROM opera_station WHERE line_id = " . $line_id . " AND res_id in (" . implode(",",$res_array) . ") AND cancel_flag = 0"; $res_area = $this->query($area_sql); //查询所有的站点名称 $area_sql = "SELECT res_id, res_name FROM base_resource WHERE res_id in (" . implode(",",$res_array) . ") AND cancel_flag = 0"; $res_name = $this->query($area_sql); foreach ($res_area as $k => $v) { $res_area_array[$v['res_id']] = $v['area_id']; } foreach ($res_name as $k => $v) { $res_name_array[$v['res_id']] = $v['res_name']; } $insert_ticket_sql = "INSERT INTO opera_tickets ( ticket_id, create_user_id, create_time, update_user_id, cancel_flag, line_id, ticket_name, ticket_type, start_station_res_id, end_station_res_id, start_station_area_id, end_station_area_id, seat_type, human_type, prod_price, cus_price, cost_price, is_onsale ) VALUES "; foreach($station_array as $k => $v) { $ticket_id ++; $ticket_group[] = $ticket_id; $station_res_group = explode(",",$v); $station_id_group[] = $station_res_group[0] . "-" . $station_res_group[1];//站点联系组合 $station_name_group[] = $res_name_array[$station_res_group[0]] . "-" . $res_name_array[$station_res_group[1]];//站点名称联系组合 $ticket_sql_array[] = "(" . $ticket_id . "," . $user_id . ",'" . $create_time . "'," . $user_id . ",0," . $line_id . ",'" . $ticket_name . "',1," . $station_res_group[0] . "," . $station_res_group[1] . "," . $res_area_array[$station_res_group[0]] . "," . $res_area_array[$station_res_group[1]] . "," . $seat_type . "," . $human_type . ",'" . $prod_price . "','" . $cus_price . "','" . $cost_price . "',0)"; } $ticket_sql = implode(",",$ticket_sql_array); $insert_ticket_sql .= $ticket_sql; //添加票种分组 $insert_ticket_group_sql = "INSERT INTO opera_tickets_group ( create_user_id, create_time, update_user_id, update_time, cancel_flag, line_id, ticket_id, station_id, station_name, seat_type, human_type, prod_price, cus_price, cost_price ) VALUES(" . $user_id . ",'" . $create_time . "'," . $user_id . ",'" . $create_time . "',0," . $line_id . ",'" . implode(",",$ticket_group) . "','" . implode(",",$station_id_group) . "','" . implode(",",$station_name_group) . "'," . $seat_type . "," . $human_type . ",'" . $prod_price . "','" . $cus_price . "','" . $cost_price . "')"; zzcsUtils::writeLog($insert_ticket_sql); $result1 = $this->exec($insert_ticket_sql); zzcsUtils::writeLog($insert_ticket_group_sql); $result2 = $this->exec($insert_ticket_group_sql); if($result1 && $result2) { $json['code'] = '0'; $json['info'] = '添加票种成功'; } else { $json['code'] = '1'; $json['info'] = '后台逻辑有误'; } return $json; } /** * 更新票种信息 * @param $param * @return mixed */ public function updateTicket($param) { $line_id = isset($param['line_id'])?trim($param['line_id']):false; $group_id = isset($param['group_id'])?trim($param['group_id']):false; $ticket_id = isset($param['ticket_id'])?trim($param['ticket_id']):false; $prod_price = isset($param['prod_price'])?trim($param['prod_price']):false; $cus_price = isset($param['cus_price'])?trim($param['cus_price']):false; $cost_price = isset($param['cost_price'])?trim($param['cost_price']):false; $user_id = $this->user_id; $update_time = date("Y-m-d H:i:s",time()); if($line_id === false || $ticket_id === false || $prod_price === false || $cus_price === false || $cost_price === false || $group_id === false) { $json['code'] = '2'; $json['info'] = '缺少必要参数'; return $json; } //判断分销价是否改变,改变需要操作下属分销 $get_prod_price="select prod_price from opera_tickets where ticket_id in ($ticket_id) limit 1"; $tmp_prod_price = $this->query($get_prod_price); if($tmp_prod_price[0]['prod_price'] != $prod_price){ $url='http://'.CS1_DOMAIN.'/zzcs/agent-product/upt-status-for-self-sale'; $cookie="user_id=$user_id"; $send_data=array( 'prod_price'=>$prod_price, 'ticket_list'=>$ticket_id, 'is_onsale'=>0 ); $result=$this->httpRequestForYii($url,$send_data,$cookie); $result=unserialize($result); if($result['code']!=0){ return array( 'code'=>1, 'info'=>'票种代售授权失败' ); } } $ticket_sql = "UPDATE opera_tickets SET prod_price = '" . $prod_price . "', cus_price = '" . $cus_price . "', cost_price = '" . $cost_price . "', update_user_id = " . $user_id . ", update_time = '" . $update_time . "' WHERE line_id = " . $line_id . " AND cancel_flag = 0 AND ticket_id IN (" . $ticket_id . ")"; $ticket_group_sql = "UPDATE opera_tickets_group SET prod_price = '" . $prod_price . "', cus_price = '" . $cus_price . "', cost_price = '" . $cost_price . "', update_user_id = " . $user_id . ", update_time = '" . $update_time . "' WHERE line_id = " . $line_id . " AND cancel_flag = 0 AND id = " . $group_id; zzcsUtils::writeLog($ticket_sql); $result1 = $this->exec($ticket_sql); zzcsUtils::writeLog($ticket_group_sql); $result2 = $this->exec($ticket_group_sql); if($result1 && $result2) { $json['code'] = '0'; $json['info'] = '修改价格成功'; } else { $json['code'] = '1'; $json['info'] = '后台逻辑有误'; } return $json; } /** * 删除票种信息 * @param $param * @return mixed */ public function deleteTicket($param) { $line_id = isset($param['line_id'])?trim($param['line_id']):false; $group_id = isset($param['group_id'])?trim($param['group_id']):false; $ticket_id = isset($param['ticket_id'])?trim($param['ticket_id']):false; $user_id = $this->user_id; $update_time = date("Y-m-d H:i:s",time()); if($line_id === false || $ticket_id === false) { $json['code'] = '2'; $json['info'] = '缺少必要参数'; return $json; } $current_day = date("Y-m-d"); $ticket_type_exists_sql = "SELECT count(order_id) as total_num FROM `order_main` WHERE `order_status` IN (145,146) AND `RUN_DATE` >= '{$current_day}' AND `PROD_ID` IN ($ticket_id)"; $run_bus_exists_sql = "SELECT count(id) as total_num2 FROM `run_bus` WHERE `RUN_ID` IN (SELECT `RUN_ID` FROM `run_main` WHERE `PROD_id`= '{$line_id}') AND `RUN_BUS_STATUS` IN (137,138,139)"; $result5 = $this->query($ticket_type_exists_sql); $result6 = $this->query($run_bus_exists_sql); if( $result5[0]["total_num"] > 0 || $result6[0]["total_num2"] > 0 ) { $json['code'] = '3'; $json['info'] = $result5[0]["total_num"] > 0 ? '请将该票种相关未完成的订单全部取消后再执行删除操作' : '请将该线路的未完成班次全部停运后再执行删除操作' ; return $json; }/*else{ $json['code'] = '3'; $json['info'] ='该票种可删除' ; return $json; }*/ $ticket_sql = "UPDATE opera_tickets SET cancel_flag = 1, update_user_id = " . $user_id . ", update_time = '" . $update_time . "' WHERE line_id = " . $line_id . " AND cancel_flag = 0 AND ticket_id IN (" . $ticket_id . ")"; $ticket_group_sql = "UPDATE opera_tickets_group SET cancel_flag = 1, update_user_id = " . $user_id . ", update_time = '" . $update_time . "' WHERE line_id = " . $line_id . " AND cancel_flag = 0 AND id = " . $group_id; //将opera_message_template表的相关数据cancel_flag置为1 $ticket_template_sql = "UPDATE opera_message_template SET cancel_flag = 1, update_user_id = " . $user_id . ", update_time = '" . $update_time . "' WHERE template_type=2 AND cancel_flag = 0 AND ticket_group_id = " . $group_id; zzcsUtils::writeLog($ticket_sql); $result1 = $this->exec($ticket_sql); zzcsUtils::writeLog($ticket_group_sql); $result2 = $this->exec($ticket_group_sql); zzcsUtils::writeLog($ticket_template_sql); $result3 = $this->exec($ticket_template_sql); if($result1 && $result2) { //删除票种后,代售信息删除 $url='http://'.CS1_DOMAIN.'/zzcs/agent-product/delete-ticket'; $user_id = $this->user_id; $cookie="user_id=$user_id"; $send_data=array( 'ticket_list'=>$ticket_id, ); $result4=$this->httpRequestForYii($url,$send_data,$cookie); //return unserialize($result); $json['code'] = '0'; $json['info'] = '删除票种成功'; } else { $json['code'] = '1'; $json['info'] = '后台逻辑有误'; } return $json; } /** * Function Description:ajax发送请求---修改自营票种的上下架 * Function Name: sendInfo * @param $param * * @return mixed * * @author 娄梦宁 */ public function sendInfo($param){ $ticket_list = isset($param['ticket_list'])?trim($param['ticket_list']):false; $is_onsale = isset($param['is_onsale'])?trim($param['is_onsale']):false; if(!$ticket_list || $is_onsale===false){ $json['code'] = '2'; $json['info'] = '缺少必要参数'; return $json; } $url='http://'.CS1_DOMAIN.'/zzcs/agent-product/upt-status-for-self-sale'; $user_id = $this->user_id; $cookie="user_id=$user_id"; $result=$this->httpRequestForYii($url,$param,$cookie); return unserialize($result); } public function httpRequestForYii($url,$data=null,$cookie) { $ch=curl_init(); curl_setopt($ch, CURLOPT_COOKIE, $cookie); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); if (!empty($data)){ curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output=curl_exec($ch); curl_close($ch); return $output; } } ?>