コード例 #1
0
ファイル: RoomController.php プロジェクト: jy02511876/wiiphp
 public function actionDelete()
 {
     if (Yii::$app->user->isGuest) {
         $this->ajax_return(false, '登录以后才能进行此操作!');
     }
     if (!in_array(Yii::$app->user->identity->getId(), $this->_admin)) {
         $this->ajax_return(false, '权限不足!');
     }
     $id = intval(Yii::$app->request->getBodyParam('id'));
     $model = MaggieRoom::findOne($id);
     if ($model == null) {
         $this->ajax_return(false, '数据已不存在!');
     }
     if ($model->delete()) {
         $this->ajax_return(true, '操作成功!');
     } else {
         $this->ajax_return(false, '操作失败!');
     }
 }
コード例 #2
0
ファイル: MaggieRoom.php プロジェクト: jy02511876/wiiphp
 public function search()
 {
     $page = Yii::$app->request->get('page', 0);
     $page = $page < 0 ? 0 : $page - 1;
     $limit = Yii::$app->request->get('limit', 25);
     $sorts = json_decode(trim(Yii::$app->request->get('sort')), true);
     $startDay = Yii::$app->request->get('start_date');
     $endDay = Yii::$app->request->get('end_date');
     $locationId = Yii::$app->request->get('location_id');
     $areaId = Yii::$app->request->get('area_id');
     $query = MaggieRoom::find()->filterWhere(['between', 'date', $startDay, $endDay])->andFilterWhere(['location_id' => $locationId, 'area_id' => $areaId]);
     $countQuery = clone $query;
     $pagination = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $limit]);
     if ($sorts != null) {
         foreach ($sorts as $sort) {
             $query->addOrderBy([$sort['property'] => $sort['direction'] == 'ASC' ? SORT_ASC : SORT_DESC]);
         }
     } else {
         $query->addOrderBy(['id' => SORT_DESC]);
     }
     //var_dump($query);exit;
     $model = $query->offset($pagination->offset)->limit($limit)->all();
     return ['count' => $countQuery->count(), 'model' => $model];
 }