芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/airport-back/controllers/SiteController.php
request->getBodyParams(); $departure_time=date('Y-m-d',strtotime($params['departure_time'])); $passengers=$params['passengers']; $destination_id=$params['destination_id']; $q='SELECT DISTINCT f.id, d.name as destination, al.name as airline, ac.model as aircraft, f.departure_time, f.arrival_time, sc.name as flight_class, sc.id as seatclass_id, fr.price as flight_price, (SELECT COUNT(s.id) FROM {{%seat}} s LEFT JOIN {{%booking_item}} bi ON bi.seat_id = s.id WHERE s.aircraft_id = ac.id AND s.active = 1 AND s.id NOT IN ( SELECT seat_id FROM {{%booking_item}} bi JOIN {{%booking}} b ON b.id = bi.booking_id WHERE b.flight_id = f.id )) as available_seats FROM {{%flight}} f JOIN {{%aircraft}} ac ON f.aircraft_id = ac.id JOIN {{%airline}} al ON f.airline_id = al.id JOIN {{%seat_class}} sc ON sc.aircraft_id = ac.id JOIN {{%seat}} s ON ac.id = s.id JOIN {{%destination}} d ON f.destination_id = d.id JOIN {{%flight_rate}} fr ON fr.flight_id = f.id LEFT JOIN {{%booking_item}} bi ON bi.seat_id = s.id WHERE f.destination_id = :destination_id AND DATE(f.departure_time) >= :departure_time AND f.active = 1 AND sc.active = 1 ORDER BY fr.price ASC ; '; $results=Yii::$app->db ->createCommand($q) ->bindValues([ ':destination_id'=>$destination_id, ':departure_time'=>$departure_time, ]) ->queryAll(); return $results; } public function actionGetflight(){ $id=(int)Yii::$app->request->get('id'); $seat_id=(int)Yii::$app->request->get('seat_id'); $q='SELECT f.id as flight_id, d.name as destination, al.name as airline, ac.model as aircraft, f.departure_time, f.arrival_time, sc.name as flight_class, fr.price as flight_price, s.id as seat_id, s.seat_number, s.position, s.row FROM {{%flight}} f JOIN {{%aircraft}} ac ON f.aircraft_id = ac.id JOIN {{%airline}} al ON f.airline_id = al.id JOIN {{%seat_class}} sc ON sc.aircraft_id = ac.id JOIN {{%seat}} s ON s.seat_class_id = sc.id JOIN {{%destination}} d ON f.destination_id = d.id JOIN {{%flight_rate}} fr ON fr.flight_id = f.id AND fr.seatclass_id = sc.id LEFT JOIN {{%booking_item}} bi ON bi.seat_id = s.id WHERE f.id = :id AND sc.id=:seat_id AND s.active = 1 AND f.active = 1 AND s.id NOT IN ( SELECT seat_id FROM {{%booking_item}} bi JOIN {{%booking}} b ON b.id = bi.booking_id WHERE b.flight_id = f.id ) ORDER BY fr.price ASC; '; $flight=[]; $results=Yii::$app->db->createCommand($q)->bindValues([':id'=>$id,':seat_id'=>$seat_id])->queryAll(); foreach($results as $result){ $flight['flight_id']=$result['flight_id']; $flight['destination']=$result['destination']; $flight['airline']=$result['airline']; $flight['aircraft']=$result['aircraft']; $flight['departure_time']=$result['departure_time']; $flight['arrival_time']=$result['arrival_time']; $flight['departure_time']=$result['departure_time']; $flight['flight_class']=$result['flight_class']; $flight['flight_price']=$result['flight_price']; $flight['departure_time']=$result['departure_time']; $flight['seats'][]=['seat_number'=>$result['seat_number'],'id'=>$result['seat_id'],'position'=>$result['position'],'price'=>$result['flight_price']]; } return $flight; } public function actionBookflight(){ } public function actionRegister(){ $data=Yii::$app->request->getBodyParams(); $customer=new Customer; $customer->attributes=$data; $done=$customer->save(); return ['done'=>$done,'customer'=>$customer]; } public function actionCatalogs(){ return $this->getCatalogs(); } public function actionSearchdestinations(){ $key=Yii::$app->request->get('key'); $results=[]; if(!empty($key)){ $results=Destination::find()->where(['like','name',$key])->limit(10)->all(); } return $results; } private function getCatalogs(){ $airlines=Airline::find()->select(['id','name'])->where(['active'=>1,'trash'=>0])->asArray()->all(); $destinations=Destination::find()->select(['id','name','city'])->where(['active'=>1,'trash'=>0])->asArray()->all(); return compact('airlines','destinations'); } }