|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
-
- namespace backend\modules\api\models;
-
- use yii\db\ActiveRecord;
-
- /**
- * This is the model class for table "run_stock".
- *
- * @property integer $ID
- * @property integer $RUN_ID
- * @property integer $RES_ID
- * @property integer $SEQ_ID
- * @property integer $SEAT_TYPE
- * @property integer $HOTEL_CONFIRM_TYPE
- * @property integer $IF_EXCESS_SALE
- * @property integer $PROD_ID
- * @property integer $TOTAL_COUNT
- * @property integer $SALED_COUNT
- * @property integer $CANCEL_FLAG
- * @property integer $CREATE_USER_ID
- * @property string $CREATE_TIME
- * @property integer $UPDATE_USER_ID
- * @property string $UPDATE_TIME
- */
- class RunStock extends ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'run_stock';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['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'],
- [['CREATE_TIME', 'UPDATE_TIME'], 'string', 'max' => 20],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'ID' => 'ID',
- 'RUN_ID' => 'Run ID',
- 'RES_ID' => 'Res ID',
- 'SEQ_ID' => 'Seq ID',
- 'SEAT_TYPE' => 'Seat Type',
- 'HOTEL_CONFIRM_TYPE' => 'Hotel Confirm Type',
- 'IF_EXCESS_SALE' => 'If Excess Sale',
- 'PROD_ID' => 'Prod ID',
- 'TOTAL_COUNT' => 'Total Count',
- 'SALED_COUNT' => 'Saled Count',
- 'CANCEL_FLAG' => 'Cancel Flag',
- 'CREATE_USER_ID' => 'Create User ID',
- 'CREATE_TIME' => 'Create Time',
- 'UPDATE_USER_ID' => 'Update User ID',
- 'UPDATE_TIME' => 'Update Time',
- ];
- }
-
- /**
- * Function Description:获取班次每个站点的库存
- * Function Name: getStockListByRunId
- * @param array $run_id_arr 班次id数组
- *
- * @return array|ActiveRecord[]
- *
- * @author 张帅
- */
- public function getStockListByRunId($run_id_arr)
- {
- $result = self::find()
- ->select([
- 'run_id',
- 'res_id',
- 'seq_id',
- 'total_count',
- 'saled_count',
- ])
- ->where([
- 'and',
- ['in', 'run_id', $run_id_arr],
- ['=', 'cancel_flag', 0],
- ['in', 'seat_type', [0, 72]],
- ])
- ->groupBy(['run_id', 'seq_id'])
- ->orderBy(['run_id' => SORT_ASC, 'seq_id' => SORT_ASC])
- ->asArray()->all();
- return $result;
- }
-
- /**
- * Function Description:整理数据
- * Function Name: execRunTicketArray
- * @param array $run_ticket_arr 班次票种数组
- * @param array $stock_list 库存数组
- *
- * @return array
- *
- * @author 张帅
- */
- public function execRunTicketArray($run_ticket_arr, $stock_list, $run_station_time)
- {
- $result = [];
-
- #region 1.整理库存数组
- $stock_run_list = [];
- foreach ($stock_list as $key => $vel) {
- $stock_run_list[$vel['run_id']][$vel['res_id']] = $vel;
- }
- #endregion
-
- #region 2.获取票种的库存
- foreach ($run_ticket_arr as $key => $vel) {
- if (!isset($result[$vel['run_id']])) {
- $result[$vel['run_id']]['run_id'] = $vel['run_id'];
- if( isset($vel['run_date']) ) {
- $result[$vel['run_id']]['run_date'] = $vel['run_date'];
- }
- $result[$vel['run_id']]['run_time'] = $vel['run_time'];
- $result[$vel['run_id']]['ticket_list'] = [];
- }
- $ticket_stock = -100;
- $stock_status = 0;
- if (isset($stock_run_list[$vel['run_id']])) {
- foreach ($stock_run_list[$vel['run_id']] as $stock_key => $stock_vel) {
- if ($stock_status == 2) {
- break;
- }
-
- if ($stock_key == $vel['start_res_id']) {
- $stock_status = 1;
- }
- if ($stock_key == $vel['end_res_id']) {
- $stock_status = 2;
- }
-
- if ($stock_status == 1) {
- $vel_stock = $stock_vel['total_count'] - $stock_vel['saled_count'];
- if ($ticket_stock == -100 || $ticket_stock > $vel_stock) {
- $ticket_stock = $vel_stock;
- }
- }
- }
- } else {
- $ticket_stock = 0;
- }
-
- $result[$vel['run_id']]['ticket_list'][$vel['ticket_id']]['prod_num'] = $ticket_stock;
- foreach ($run_station_time as $k => $v) {
- if (isset($result[$v['run_id']]['ticket_list'][$v['ticket_id']])){
- $result[$v['run_id']]['ticket_list'][$v['ticket_id']]['start_time'] = $v['start_time'];
- $result[$v['run_id']]['ticket_list'][$v['ticket_id']]['end_time'] = $v['end_time'];
- }
-
- }
- }
- #endregion
-
- return $result;
- }
- }
|