/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Service::find(); //关联表 $query->joinWith(['role' => function ($query) { $query->from(['role' => '{{%auth_assignment}}']); }]); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['service_id' => $this->service_id, 'service_active' => $this->service_active, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'service_username', $this->service_username])->andFilterWhere(['like', 'service_password', $this->service_password])->andFilterWhere(['like', 'service_password_salt', $this->service_password_salt])->andFilterWhere(['like', 'service_password_reset_token', $this->service_password_reset_token])->andFilterWhere(['like', 'service_fullname', $this->service_fullname])->andFilterWhere(['like', 'service_company', $this->service_company])->andFilterWhere(['like', 'service_com_address', $this->service_com_address])->andFilterWhere(['like', 'service_position', $this->service_position])->andFilterWhere(['like', 'service_mobile', $this->service_mobile])->andFilterWhere(['like', 'service_phone', $this->service_phone])->andFilterWhere(['like', 'service_email', $this->service_email])->andFilterWhere(['like', 'role.item_name', $this->getAttribute('role.item_name')])->orderBy(['service_id' => SORT_DESC]); return $dataProvider; }
/** * Finds the Service model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Service the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Service::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * undocumented function * * @return void * @author **/ public function actionSignup() { if (Yii::$app->user->getIsGuest()) { $model = new Service(); $mConfig = new Config(); $signup_status = 'invite'; switch ($mConfig->getConfigValue(Config::SIGNUP_STATUS)) { //注册状态 case Config::SIGNUP_OPEN: $signup_status = 'signup'; break; case Config::SIGNUP_INVITE: $signup_status = 'invite'; break; default: Yii::$app->session->setFlash('error', '已关闭注册!'); return $this->redirect('signin'); break; } $model->setScenario($signup_status); if ($model->load($params = Yii::$app->request->post()) && $model->save()) { //邀请码处理 $serviceInfo = $params['Service']; if (isset($serviceInfo['invite']) && $serviceInfo['invite']) { $mInvite = Invite::findOne(['invite_code' => $serviceInfo['invite'] ?: NUll]); $invite['Invite'] = ['invite_service_id' => $model->service_id, 'invite_username' => $model->service_username, 'invite_mobile' => $model->service_mobile, 'invite_active' => 1, 'updated_at' => time()]; $mInvite->load($invite); $mInvite->save(); } //注册成功默认角色 $auth = Yii::$app->authManager; $authorRole = $auth->getRole('service'); $auth->assign($authorRole, $model->service_id); Yii::$app->session->setFlash('success', '您已成功注册,请登录!'); return $this->redirect('signin'); } else { return $this->render('signup', ['model' => $model, 'signup_status' => $signup_status]); } } else { return $this->redirect(['admin/index']); } }