芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/airport-back/models/Flight.php
10], [['aircraft_id'], 'exist', 'skipOnError' => true, 'targetClass' => Aircraft::class, 'targetAttribute' => ['aircraft_id' => 'id']], [['airline_id'], 'exist', 'skipOnError' => true, 'targetClass' => Airline::class, 'targetAttribute' => ['airline_id' => 'id']], [['destination_id'], 'exist', 'skipOnError' => true, 'targetClass' => Destination::class, 'targetAttribute' => ['destination_id' => 'id']], ]; } public function beforeValidate() { $this->departure_time=date('Y-m-d H:i:s',strtotime($this->departure_time)); $this->arrival_time=date('Y-m-d H:i:s',strtotime($this->arrival_time)); return parent::beforeValidate(); } public function afterSave($insert, $changedAttributes) { $rates=Yii::$app->request->getBodyParam('flight_rates'); foreach($rates as $rate){ $price=(float)$rate['price']; if(isset($rate['id'])){ $id=(int)$rate['id']; $item=FlightRate::findOne($id); if($item){ $item->price=$price; $item->update(); } }else{ $seatclass_id=(int)$rate['seatclass_id']; $item=new FlightRate; $item->price=$price; $item->seatclass_id=$seatclass_id; $item->flight_id=$this->id; $item->save(); } } } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'aircraft_id' => 'Aircraft ID', 'airline_id' => 'Airline ID', 'destination_id' => 'Destination ID', 'departure_time' => 'Departure Time', 'arrival_time' => 'Arrival Time', 'price' => 'Price', 'created' => 'Created', 'updated' => 'Updated', 'active' => 'Active', 'trash' => 'Trash', ]; } /** * Gets query for [[Aircraft]]. * * @return \yii\db\ActiveQuery */ public function getAircraft() { return $this->hasOne(Aircraft::class, ['id' => 'aircraft_id']); } /** * Gets query for [[Airline]]. * * @return \yii\db\ActiveQuery */ public function getAirline() { return $this->hasOne(Airline::class, ['id' => 'airline_id']); } /** * Gets query for [[Bookings]]. * * @return \yii\db\ActiveQuery */ public function getBookings() { return $this->hasMany(Booking::class, ['flight_id' => 'id']); } /** * Gets query for [[Destination]]. * * @return \yii\db\ActiveQuery */ public function getDestination() { return $this->hasOne(Destination::class, ['id' => 'destination_id']); } /** * Gets query for [[FlightRates]]. * * @return \yii\db\ActiveQuery */ public function getFlightRates() { return $this->hasMany(FlightRate::class, ['flight_id' => 'id']); } }