|
- <?php
-
- /**
- * Created by PhpStorm.
- * User: Steven
- * Date: 2016/10/15
- * Time: 14:39
- * 组合线路票种相关
- */
- class groupTicket extends base
- {
- /**
- * 获取组合线路票种列表
- * @param $param
- * @return mixed
- */
- public function getTicketList($param)
- {
- $line_id = isset($param['line_id']) ? $param['line_id'] : false;
- $current_page = isset($param['current_page']) ? $param['current_page'] : false;
- $page_size = isset($param['page_size']) ? $param['page_size'] : false;
- if (!$line_id || $current_page === false || $page_size === false) {
- $result['code'] = '2';
- $result['info'] = "缺少必要参数";
- return $result;
- }
- $start_row = ($current_page - 1) * $page_size;
- $sql_page = "SELECT COUNT(*) as count FROM opera_tickets as t WHERE cancel_flag = 0 AND line_id = $line_id";
- $res_page = $this->query($sql_page);
- $total_count = $res_page[0]['count'];
- $total_page = ceil($total_count / $page_size);
- $sql = "SELECT
- ticket_id,
- seat_type,
- (select type_name from dict_type where id = t.seat_type) as seat_type_name,
- human_type,
- (select type_name from dict_type where id = t.human_type) as human_type_name,
- prod_price,
- cus_price
- FROM
- opera_tickets as t
- WHERE
- line_id = $line_id
- AND cancel_flag = 0 ORDER BY t.CREATE_TIME DESC LIMIT $start_row,$page_size";
- $res = $this->query($sql);
- $result['code'] = '0';
- $result['info'] = '获取' . $line_id . '线路的票种列表成功';
- $result['page'] = array(
- 'page_size' => $page_size,
- 'current_page' => $current_page,
- 'total_count' => $total_count,
- 'total_page' => $total_page
- );
- $result['ticket'] = $res;
- return $result;
- }
-
- /**
- * 根据票种ID获取票种信息
- * @param $param
- * @return mixed
- */
- public function getTicketById($param)
- {
- $ticketId = isset($param['ticket_id']) ? $param['ticket_id'] : false;
- if (!$ticketId) {
- $result['code'] = '2';
- $result['info'] = "缺少必要参数";
- return $result;
- }
- $sql = "SELECT ticket_id,seat_type,human_type,prod_price,cus_price FROM opera_tickets WHERE cancel_flag = 0 AND TICKET_ID=$ticketId";
- $res = $this->query($sql);
- if ($res) {
- $code = 0;
- $msg = '获取' . $ticketId . '票种信息成功';
- } else {
- $code = 1;
- $msg = '获取' . $ticketId . '票种信息失败';
- }
- $result['code'] = (string)$code;
- $result['info'] = $msg;
- $result['base_info'] = $this->getBaseInfo();
- $result['data'] = $res[0];
-
- return $result;
- }
-
- /**
- * 添加票种信息
- * @param $param
- * @return mixed
- */
- public function addTicket($param)
- {
- $userID = $this->user_id;
- $line_id = isset($param['line_id']) ? $param['line_id'] : false; //线路ID
- $seat_type = isset($param['seat_type']) ? $param['seat_type'] : false; //座位等级
- $human_type = isset($param['human_type']) ? $param['human_type'] : false; //人群类型
- $prod_price = isset($param['prod_price']) ? $param['prod_price'] : false; //分销价
- $cus_price = isset($param['cus_price']) ? $param['cus_price'] : false; //
- if (!$userID || !$line_id || !$seat_type || $human_type === false || !$prod_price || !$cus_price) {
- $result['code'] = '2';
- $result['info'] = "缺少必要参数";
- return $result;
- }
- $sql = "INSERT INTO opera_tickets(TICKET_ID,CREATE_USER_ID,CREATE_TIME,UPDATE_USER_ID,LINE_ID,TICKET_NAME,TICKET_TYPE,SEAT_TYPE,HUMAN_TYPE,PROD_PRICE,CUS_PRICE) VALUES((SELECT MAX(TICKET_ID)+1 FROM opera_tickets ot),$userID,NOW(),$userID,$line_id,(SELECT TYPE_NAME FROM dict_type WHERE ID=$seat_type),1,$seat_type,$human_type,$prod_price,$cus_price)";
- zzcsUtils::writeLog($sql);
- $res = $this->exec($sql);
- if ($res) {
- $code = 0;
- $msg = '添加票种成功';
- } else {
- $code = 1;
- $msg = '添加票种失败';
- }
- $result['code'] = (string)$code;
- $result['info'] = $msg;
- return $result;
- }
-
- /**
- * 更新票种信息
- * @param $param
- * @return mixed
- */
- public function updateTicket($param)
- {
- $user_id = $this->user_id;
- $ticketId = isset($param['ticket_id']) ? $param['ticket_id'] : false;
- $seat_type = isset($param['seat_type']) ? $param['seat_type'] : false;
- $human_type = isset($param['human_type']) ? $param['human_type'] : false;
- $prod_price = isset($param['prod_price']) ? $param['prod_price'] : false;
- $cus_price = isset($param['cus_price']) ? $param['cus_price'] : false;
- if (!$user_id || !$ticketId || !$seat_type || $human_type === false || $prod_price === false || $cus_price === false) {
- $result['code'] = '2';
- $result['info'] = "缺少必要参数";
- return $result;
- }
- $sql = "UPDATE opera_tickets SET UPDATE_USER_ID=$user_id,UPDATE_TIME = NOW(),TICKET_NAME=(SELECT TYPE_NAME FROM dict_type WHERE ID=$seat_type),SEAT_TYPE = $seat_type,HUMAN_TYPE = $human_type,PROD_PRICE = $prod_price,CUS_PRICE = $cus_price WHERE CANCEL_FLAG=0 AND TICKET_ID=$ticketId";
- zzcsUtils::writeLog($sql);
- $res = $this->exec($sql);
- if ($res) {
- $code = 0;
- $msg = '票种信息修改成功';
- } else {
- $code = 1;
- $msg = '票种信息修改失败';
- }
- $result['code'] = (string)$code;
- $result['info'] = $msg;
- $result['data'] = array(
- 'ticket_id' => $ticketId,
- 'seat_type' => $seat_type,
- 'human_type' => $human_type,
- 'prod_price' => $prod_price,
- 'cus_price' => $cus_price
- );
- return $result;
- }
-
- /**
- * 删除票种信息
- * @param $param
- * @return mixed
- */
- public function deleteTicket($param)
- {
- $user_id = $this->user_id;
- $ticket_id = isset($param['ticket_id']) ? $param['ticket_id'] : false;
- if (!$user_id || !$ticket_id) {
- $result['code'] = '2';
- $result['info'] = "缺少必要参数";
- return $result;
- }
- $sql = "UPDATE opera_tickets SET UPDATE_USER_ID=$user_id,UPDATE_TIME=NOW(),CANCEL_FLAG=1 WHERE TICKET_ID=$ticket_id";
- zzcsUtils::writeLog($sql);
- $res = $this->exec($sql);
- if ($res) {
- $code = 0;
- $msg = '票种信息删除成功';
- } else {
- $code = 1;
- $msg = '票种信息删除失败';
- }
- $result['code'] = (string)$code;
- $result['info'] = $msg;
- return $result;
- }
-
- /**
- * 获取基础数据
- */
- public function getBaseInfo()
- {
- $result['code'] = '0';
- $result['info'] = '基础数据获取成功';
- $result['seat_type'] = Dictionary::getSeatType();
- $result['human_type'] = Dictionary::getHumanType();
- return $result;
- }
-
- }
|