Ejemplo n.º 1
0
 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);
     $name = Yii::$app->request->get('name');
     $isPassed = Yii::$app->request->get('is_passed');
     $status = Yii::$app->request->get('status');
     $startDay = Yii::$app->request->get('start_date') != '' ? trim(Yii::$app->request->get('start_date')) : '';
     $endDay = Yii::$app->request->get('end_date') != '' ? trim(Yii::$app->request->get('end_date')) : '';
     if ($startDay != '' && $endDay == '') {
         $endDay = '2030-01-01';
     }
     if ($startDay == '' && $endDay != '') {
         $startDay = '1970-01-01';
     }
     $query = Project::find()->joinWith('user')->filterWhere(['between', 'end_time', $startDay, $endDay])->andFilterWhere(['is_passed' => $isPassed])->andFilterWhere(['status' => $status])->andFilterWhere(['like', 'name', $name]);
     if (Yii::$app->sh_user->getIdentity()->getUsername() != 'sjh') {
         $query->andFilterWhere(['user_id' => Yii::$app->sh_user->getId()]);
     }
     $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];
 }
Ejemplo n.º 2
0
 public function actionPrint()
 {
     $id = Yii::$app->request->get('id');
     $model = Project::find()->where(['id' => $id])->one();
     if ($id == '' || $model === null) {
         echo '找不到该数据!';
         Yii::$app->end();
     }
     $group = Group::find()->where(['user_id' => $model->user_id])->one();
     return $this->render('print', ['model' => $model, 'group' => $group]);
 }