157 linhas
6.7 KiB

  1. <?php
  2. namespace backend\modules\api\logic;
  3. use backend\modules\api\models\OperaLine;
  4. use backend\modules\api\models\OrderMain;
  5. use backend\modules\api\models\RunMain;
  6. use Yii;
  7. class ChangeSeat
  8. {
  9. /**
  10. * Function Description:获取可换座位数组
  11. * Function Name: getSeatInfo
  12. * @param $order_id
  13. *
  14. * @return array
  15. *
  16. * @author 娄梦宁
  17. */
  18. public function getSeatInfo($order_id)
  19. {
  20. $order_main = new OrderMain();
  21. $opera_line = new OperaLine();
  22. $run_main = new RunMain();
  23. $getBusSeat = $order_main->getBusInfoByOrderId($order_id);
  24. if (empty($getBusSeat['SEAT_MATRIX_ID']) || $getBusSeat['SEAT_MATRIX_ID'] == 0) {
  25. return [
  26. 'code' => 1,
  27. 'info' => '该车为临时外调车辆,暂不支持选座。'
  28. ];
  29. }
  30. #region 1:获取订单相关数据
  31. $order_info = $order_main->getOrderInfoForGetSeat($order_id);
  32. #判断线路是否支持选座#
  33. $line_allow_seat = $opera_line->getLineSeatAllow($order_info['line_id']);
  34. if ($line_allow_seat['allow_select_seat'] == 0) {
  35. return [
  36. 'code' => 1,
  37. 'info' => '该车为临时外调车辆,暂不支持选座。'
  38. ];
  39. }
  40. #run_x表表名#
  41. $run_x = 'run_' . substr($order_info['run_date'], 0, 4) . substr($order_info['run_date'], 5, 2);
  42. #endregion
  43. #region 3:找出run_x表所有该班次车次的座位信息
  44. $run_x_arr = $run_main->getRunxSeatInfo($run_x, $order_info['run_id'], $order_info['run_date'], $order_info['bus_order_id']);
  45. #循环处理车座数组#
  46. $run_seat_arr = [];
  47. foreach ($run_x_arr as $v) {
  48. $run_seat_arr[$v['seat_seq_id']][$v['order_id']]['seat_status'] = $v['seat_status'];
  49. $run_seat_arr[$v['seat_seq_id']][$v['order_id']]['order_main_id'] = $v['order_main_id'];
  50. $run_seat_arr[$v['seat_seq_id']][$v['order_id']]['allow_select_seat'] = $v['allow_select_seat'];
  51. $run_seat_arr[$v['seat_seq_id']][$v['order_id']]['seat_seq_id'] = $v['seat_seq_id'];
  52. $run_seat_arr[$v['seat_seq_id']][$v['order_id']]['area_id'] = $v['area_id'];
  53. $run_seat_arr[$v['seat_seq_id']][$v['order_id']]['seat_x'] = $v['seat_x'];
  54. $run_seat_arr[$v['seat_seq_id']][$v['order_id']]['seat_y'] = $v['seat_y'];
  55. $run_seat_arr[$v['seat_seq_id']][$v['order_id']]['seat_type'] = $v['seat_type'];
  56. $run_seat_arr[$v['seat_seq_id']][$v['order_id']]['seat_name'] = $v['seat_name'];
  57. }
  58. #endregion
  59. #region 4:循环座次数组,得到每个座位的状态
  60. $seat_arr = [];
  61. $self_seat_seq_id = explode(',', $order_info['run_bus_seat_seq_id']);
  62. foreach ($run_seat_arr as $key => $val) {
  63. # ① 订单原来已占座位
  64. if (in_array($val[1]['seat_seq_id'], $self_seat_seq_id)) {
  65. $seat_arr[$val[1]['seat_seq_id']] = [
  66. 'seat_name' => $val[1]['seat_name'],
  67. 'seat_seq_id' => $val[1]['seat_seq_id'],
  68. 'seat_status' => 0,
  69. 'seat_x' => $val[1]['seat_x'],
  70. 'seat_y' => $val[1]['seat_y'],
  71. 'seat_type' => $val[1]['seat_type']
  72. ];
  73. continue;
  74. }
  75. # ② 行程当中的空座位
  76. $tmp_is_empty = 1;
  77. foreach ($val as $k => $v) {
  78. if ($k >= $order_info['start_seq_id'] && $k < $order_info['end_seq_id'])#站点处于行程中
  79. {
  80. if ($v['seat_status'] != 0 or $v['order_main_id'] != 0) {
  81. $tmp_is_empty = 0;
  82. }
  83. }
  84. }
  85. if ($tmp_is_empty == 1) {
  86. $seat_arr[$val[1]['seat_seq_id']] = [
  87. 'seat_name' => $val[1]['seat_name'],
  88. 'seat_seq_id' => $val[1]['seat_seq_id'],
  89. 'seat_status' => 1,
  90. 'seat_x' => $val[1]['seat_x'],
  91. 'seat_y' => $val[1]['seat_y'],
  92. 'seat_type' => $val[1]['seat_type']
  93. ];
  94. continue;
  95. }
  96. # ③ 已被占用座位根据站点查看是否可换
  97. $other_order_arr=[];#当前订单行程内允许换座的子订单号数组
  98. foreach ($val as $k => $v) {
  99. if ($k >= $order_info['start_seq_id'] && $k < $order_info['end_seq_id']) {
  100. if ($v['allow_select_seat'] != 156) {
  101. #当前座位有订单且不允许换座,
  102. $seat_arr[$val[1]['seat_seq_id']] = [
  103. 'seat_name' => $val[1]['seat_name'],
  104. 'seat_seq_id' => $val[1]['seat_seq_id'],
  105. 'seat_status' => 2,
  106. 'seat_x' => $val[1]['seat_x'],
  107. 'seat_y' => $val[1]['seat_y'],
  108. 'seat_type' => $val[1]['seat_type']
  109. ];
  110. continue 2;
  111. }
  112. if($v['order_main_id']!=0){
  113. $other_order_arr[]=$v['order_main_id'];
  114. }
  115. }
  116. }
  117. #检查行程内可换座订单是否还有其他行程;即:本订单所跨站点是否全包含换座订单所有站点
  118. foreach($val as $k=>$v){
  119. if ($k < $order_info['start_seq_id'] || $k >= $order_info['end_seq_id']) {
  120. if(in_array($v['order_main_id'],$other_order_arr)){
  121. #可换座订单有多余站点行程
  122. $seat_arr[$val[1]['seat_seq_id']] = [
  123. 'seat_name' => $val[1]['seat_name'],
  124. 'seat_seq_id' => $val[1]['seat_seq_id'],
  125. 'seat_status' => 2,
  126. 'seat_x' => $val[1]['seat_x'],
  127. 'seat_y' => $val[1]['seat_y'],
  128. 'seat_type' => $val[1]['seat_type']
  129. ];
  130. continue 2;
  131. }
  132. }
  133. }
  134. $seat_arr[$val[1]['seat_seq_id']] = [
  135. 'seat_name' => $val[1]['seat_name'],
  136. 'seat_seq_id' => $val[1]['seat_seq_id'],
  137. 'seat_status' => 1,
  138. 'seat_x' => $val[1]['seat_x'],
  139. 'seat_y' => $val[1]['seat_y'],
  140. 'seat_type' => $val[1]['seat_type']
  141. ];
  142. }
  143. #endregion
  144. return [
  145. 'code' => 0,
  146. 'info' => '获取成功!',
  147. 'list' => $seat_arr,
  148. 'SEAT_MATRIX_ID' => $getBusSeat['SEAT_MATRIX_ID']
  149. ];
  150. }
  151. }