Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

173 righe
5.3 KiB

  1. <?php
  2. namespace backend\modules\api\models;
  3. use yii\db\ActiveRecord;
  4. /**
  5. * This is the model class for table "run_stock".
  6. *
  7. * @property integer $ID
  8. * @property integer $RUN_ID
  9. * @property integer $RES_ID
  10. * @property integer $SEQ_ID
  11. * @property integer $SEAT_TYPE
  12. * @property integer $HOTEL_CONFIRM_TYPE
  13. * @property integer $IF_EXCESS_SALE
  14. * @property integer $PROD_ID
  15. * @property integer $TOTAL_COUNT
  16. * @property integer $SALED_COUNT
  17. * @property integer $CANCEL_FLAG
  18. * @property integer $CREATE_USER_ID
  19. * @property string $CREATE_TIME
  20. * @property integer $UPDATE_USER_ID
  21. * @property string $UPDATE_TIME
  22. */
  23. class RunStock extends ActiveRecord
  24. {
  25. /**
  26. * @inheritdoc
  27. */
  28. public static function tableName()
  29. {
  30. return 'run_stock';
  31. }
  32. /**
  33. * @inheritdoc
  34. */
  35. public function rules()
  36. {
  37. return [
  38. [['RUN_ID', 'RES_ID', 'SEQ_ID', 'SEAT_TYPE', 'HOTEL_CONFIRM_TYPE', 'IF_EXCESS_SALE', 'PROD_ID', 'TOTAL_COUNT', 'SALED_COUNT', 'CANCEL_FLAG', 'CREATE_USER_ID', 'UPDATE_USER_ID'], 'integer'],
  39. [['CREATE_TIME', 'UPDATE_TIME'], 'string', 'max' => 20],
  40. ];
  41. }
  42. /**
  43. * @inheritdoc
  44. */
  45. public function attributeLabels()
  46. {
  47. return [
  48. 'ID' => 'ID',
  49. 'RUN_ID' => 'Run ID',
  50. 'RES_ID' => 'Res ID',
  51. 'SEQ_ID' => 'Seq ID',
  52. 'SEAT_TYPE' => 'Seat Type',
  53. 'HOTEL_CONFIRM_TYPE' => 'Hotel Confirm Type',
  54. 'IF_EXCESS_SALE' => 'If Excess Sale',
  55. 'PROD_ID' => 'Prod ID',
  56. 'TOTAL_COUNT' => 'Total Count',
  57. 'SALED_COUNT' => 'Saled Count',
  58. 'CANCEL_FLAG' => 'Cancel Flag',
  59. 'CREATE_USER_ID' => 'Create User ID',
  60. 'CREATE_TIME' => 'Create Time',
  61. 'UPDATE_USER_ID' => 'Update User ID',
  62. 'UPDATE_TIME' => 'Update Time',
  63. ];
  64. }
  65. /**
  66. * Function Description:获取班次每个站点的库存
  67. * Function Name: getStockListByRunId
  68. * @param array $run_id_arr 班次id数组
  69. *
  70. * @return array|ActiveRecord[]
  71. *
  72. * @author 张帅
  73. */
  74. public function getStockListByRunId($run_id_arr)
  75. {
  76. $result = self::find()
  77. ->select([
  78. 'run_id',
  79. 'res_id',
  80. 'seq_id',
  81. 'total_count',
  82. 'saled_count',
  83. ])
  84. ->where([
  85. 'and',
  86. ['in', 'run_id', $run_id_arr],
  87. ['=', 'cancel_flag', 0],
  88. ['in', 'seat_type', [0, 72]],
  89. ])
  90. ->groupBy(['run_id', 'seq_id'])
  91. ->orderBy(['run_id' => SORT_ASC, 'seq_id' => SORT_ASC])
  92. ->asArray()->all();
  93. return $result;
  94. }
  95. /**
  96. * Function Description:整理数据
  97. * Function Name: execRunTicketArray
  98. * @param array $run_ticket_arr 班次票种数组
  99. * @param array $stock_list 库存数组
  100. *
  101. * @return array
  102. *
  103. * @author 张帅
  104. */
  105. public function execRunTicketArray($run_ticket_arr, $stock_list, $run_station_time)
  106. {
  107. $result = [];
  108. #region 1.整理库存数组
  109. $stock_run_list = [];
  110. foreach ($stock_list as $key => $vel) {
  111. $stock_run_list[$vel['run_id']][$vel['res_id']] = $vel;
  112. }
  113. #endregion
  114. #region 2.获取票种的库存
  115. foreach ($run_ticket_arr as $key => $vel) {
  116. if (!isset($result[$vel['run_id']])) {
  117. $result[$vel['run_id']]['run_id'] = $vel['run_id'];
  118. if( isset($vel['run_date']) ) {
  119. $result[$vel['run_id']]['run_date'] = $vel['run_date'];
  120. }
  121. $result[$vel['run_id']]['run_time'] = $vel['run_time'];
  122. $result[$vel['run_id']]['ticket_list'] = [];
  123. }
  124. $ticket_stock = -100;
  125. $stock_status = 0;
  126. if (isset($stock_run_list[$vel['run_id']])) {
  127. foreach ($stock_run_list[$vel['run_id']] as $stock_key => $stock_vel) {
  128. if ($stock_status == 2) {
  129. break;
  130. }
  131. if ($stock_key == $vel['start_res_id']) {
  132. $stock_status = 1;
  133. }
  134. if ($stock_key == $vel['end_res_id']) {
  135. $stock_status = 2;
  136. }
  137. if ($stock_status == 1) {
  138. $vel_stock = $stock_vel['total_count'] - $stock_vel['saled_count'];
  139. if ($ticket_stock == -100 || $ticket_stock > $vel_stock) {
  140. $ticket_stock = $vel_stock;
  141. }
  142. }
  143. }
  144. } else {
  145. $ticket_stock = 0;
  146. }
  147. $result[$vel['run_id']]['ticket_list'][$vel['ticket_id']]['prod_num'] = $ticket_stock;
  148. foreach ($run_station_time as $k => $v) {
  149. if (isset($result[$v['run_id']]['ticket_list'][$v['ticket_id']])){
  150. $result[$v['run_id']]['ticket_list'][$v['ticket_id']]['start_time'] = $v['start_time'];
  151. $result[$v['run_id']]['ticket_list'][$v['ticket_id']]['end_time'] = $v['end_time'];
  152. }
  153. }
  154. }
  155. #endregion
  156. return $result;
  157. }
  158. }