|
- <?php
-
- namespace backend\modules\api\logic;
-
- use backend\modules\api\models\OperaLine;
- use backend\modules\api\models\OrderMain;
- use backend\modules\api\models\RunMain;
- use Yii;
-
- class ChangeSeat
- {
- /**
- * Function Description:获取可换座位数组
- * Function Name: getSeatInfo
- * @param $order_id
- *
- * @return array
- *
- * @author 娄梦宁
- */
- public function getSeatInfo($order_id)
- {
- $order_main = new OrderMain();
- $opera_line = new OperaLine();
- $run_main = new RunMain();
-
- $getBusSeat = $order_main->getBusInfoByOrderId($order_id);
- if (empty($getBusSeat['SEAT_MATRIX_ID']) || $getBusSeat['SEAT_MATRIX_ID'] == 0) {
- return [
- 'code' => 1,
- 'info' => '该车为临时外调车辆,暂不支持选座。'
- ];
- }
- #region 1:获取订单相关数据
- $order_info = $order_main->getOrderInfoForGetSeat($order_id);
- #判断线路是否支持选座#
- $line_allow_seat = $opera_line->getLineSeatAllow($order_info['line_id']);
- if ($line_allow_seat['allow_select_seat'] == 0) {
- return [
- 'code' => 1,
- 'info' => '该车为临时外调车辆,暂不支持选座。'
- ];
- }
- #run_x表表名#
- $run_x = 'run_' . substr($order_info['run_date'], 0, 4) . substr($order_info['run_date'], 5, 2);
- #endregion
-
- #region 3:找出run_x表所有该班次车次的座位信息
- $run_x_arr = $run_main->getRunxSeatInfo($run_x, $order_info['run_id'], $order_info['run_date'], $order_info['bus_order_id']);
- #循环处理车座数组#
- $run_seat_arr = [];
- foreach ($run_x_arr as $v) {
- $run_seat_arr[$v['seat_seq_id']][$v['order_id']]['seat_status'] = $v['seat_status'];
- $run_seat_arr[$v['seat_seq_id']][$v['order_id']]['order_main_id'] = $v['order_main_id'];
- $run_seat_arr[$v['seat_seq_id']][$v['order_id']]['allow_select_seat'] = $v['allow_select_seat'];
- $run_seat_arr[$v['seat_seq_id']][$v['order_id']]['seat_seq_id'] = $v['seat_seq_id'];
- $run_seat_arr[$v['seat_seq_id']][$v['order_id']]['area_id'] = $v['area_id'];
- $run_seat_arr[$v['seat_seq_id']][$v['order_id']]['seat_x'] = $v['seat_x'];
- $run_seat_arr[$v['seat_seq_id']][$v['order_id']]['seat_y'] = $v['seat_y'];
- $run_seat_arr[$v['seat_seq_id']][$v['order_id']]['seat_type'] = $v['seat_type'];
- $run_seat_arr[$v['seat_seq_id']][$v['order_id']]['seat_name'] = $v['seat_name'];
- }
- #endregion
-
- #region 4:循环座次数组,得到每个座位的状态
- $seat_arr = [];
- $self_seat_seq_id = explode(',', $order_info['run_bus_seat_seq_id']);
- foreach ($run_seat_arr as $key => $val) {
- # ① 订单原来已占座位
- if (in_array($val[1]['seat_seq_id'], $self_seat_seq_id)) {
- $seat_arr[$val[1]['seat_seq_id']] = [
- 'seat_name' => $val[1]['seat_name'],
- 'seat_seq_id' => $val[1]['seat_seq_id'],
- 'seat_status' => 0,
- 'seat_x' => $val[1]['seat_x'],
- 'seat_y' => $val[1]['seat_y'],
- 'seat_type' => $val[1]['seat_type']
- ];
- continue;
- }
- # ② 行程当中的空座位
- $tmp_is_empty = 1;
- foreach ($val as $k => $v) {
- if ($k >= $order_info['start_seq_id'] && $k < $order_info['end_seq_id'])#站点处于行程中
- {
- if ($v['seat_status'] != 0 or $v['order_main_id'] != 0) {
- $tmp_is_empty = 0;
- }
- }
- }
- if ($tmp_is_empty == 1) {
- $seat_arr[$val[1]['seat_seq_id']] = [
- 'seat_name' => $val[1]['seat_name'],
- 'seat_seq_id' => $val[1]['seat_seq_id'],
- 'seat_status' => 1,
- 'seat_x' => $val[1]['seat_x'],
- 'seat_y' => $val[1]['seat_y'],
- 'seat_type' => $val[1]['seat_type']
- ];
- continue;
- }
- # ③ 已被占用座位根据站点查看是否可换
- $other_order_arr=[];#当前订单行程内允许换座的子订单号数组
- foreach ($val as $k => $v) {
- if ($k >= $order_info['start_seq_id'] && $k < $order_info['end_seq_id']) {
- if ($v['allow_select_seat'] != 156) {
- #当前座位有订单且不允许换座,
- $seat_arr[$val[1]['seat_seq_id']] = [
- 'seat_name' => $val[1]['seat_name'],
- 'seat_seq_id' => $val[1]['seat_seq_id'],
- 'seat_status' => 2,
- 'seat_x' => $val[1]['seat_x'],
- 'seat_y' => $val[1]['seat_y'],
- 'seat_type' => $val[1]['seat_type']
- ];
- continue 2;
- }
- if($v['order_main_id']!=0){
- $other_order_arr[]=$v['order_main_id'];
- }
- }
- }
- #检查行程内可换座订单是否还有其他行程;即:本订单所跨站点是否全包含换座订单所有站点
- foreach($val as $k=>$v){
- if ($k < $order_info['start_seq_id'] || $k >= $order_info['end_seq_id']) {
- if(in_array($v['order_main_id'],$other_order_arr)){
- #可换座订单有多余站点行程
- $seat_arr[$val[1]['seat_seq_id']] = [
- 'seat_name' => $val[1]['seat_name'],
- 'seat_seq_id' => $val[1]['seat_seq_id'],
- 'seat_status' => 2,
- 'seat_x' => $val[1]['seat_x'],
- 'seat_y' => $val[1]['seat_y'],
- 'seat_type' => $val[1]['seat_type']
- ];
- continue 2;
- }
- }
- }
- $seat_arr[$val[1]['seat_seq_id']] = [
- 'seat_name' => $val[1]['seat_name'],
- 'seat_seq_id' => $val[1]['seat_seq_id'],
- 'seat_status' => 1,
- 'seat_x' => $val[1]['seat_x'],
- 'seat_y' => $val[1]['seat_y'],
- 'seat_type' => $val[1]['seat_type']
- ];
- }
- #endregion
- return [
- 'code' => 0,
- 'info' => '获取成功!',
- 'list' => $seat_arr,
- 'SEAT_MATRIX_ID' => $getBusSeat['SEAT_MATRIX_ID']
- ];
- }
- }
|