|
- <?php
- /**
- * Created by PhpStorm.
- * User: 张帅
- * Date: 2016/10/12
- * Time: 14:30
- */
- class singleTicket extends base
- {
- /**
- * 获取单一线路票种列表
- * @param $param
- * @return mixed
- */
- public function getTicketList($param)
- {
- $line_id = isset($param['line_id'])?trim($param['line_id']):false;//152251
- $page_size = isset($param['page_size'])?trim($param['page_size']):false;
- $current_page = isset($param['current_page'])?trim($param['current_page']):false;
- $start_row = ($current_page-1)*$page_size;
- if(!$line_id || !$page_size || !$current_page)
- {
- $json['code'] = '2';
- $json['info'] = '缺少必要参数';
- return $json;
- }
- $sql = "SELECT
- id as group_id,
- ticket_id,
- station_id,
- station_name,
- seat_type,
- (SELECT type_name FROM dict_type WHERE id = seat_type) AS seat_type_name,
- human_type,
- (SELECT type_name FROM dict_type WHERE id = human_type ) AS human_type_name,
- prod_price,
- cus_price
- FROM
- opera_tickets_group
- WHERE
- line_id = " . $line_id . "
- AND cancel_flag = 0
- LIMIT " . $start_row . "," . $page_size;
- $res = $this->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;
- $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 || $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
- )
- 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 . "')";
- }
- $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
- )
- 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 . "')";
- 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;
- $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 || $group_id === false)
- {
- $json['code'] = '2';
- $json['info'] = '缺少必要参数';
- return $json;
- }
-
- $ticket_sql = "UPDATE opera_tickets
- SET prod_price = '" . $prod_price . "',
- cus_price = '" . $cus_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 . "',
- 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;
- }
-
- $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)
- {
- $json['code'] = '0';
- $json['info'] = '删除票种成功';
- }
- else
- {
- $json['code'] = '1';
- $json['info'] = '后台逻辑有误';
- }
- return $json;
-
- }
-
- }
- ?>
|