/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = User::findByUsername($this->username); } return $this->_user; }
public function actionCalculate() { /* @var $userList \app\modules\cms\models\User[] */ /* @var $partnerList \app\modules\cms\models\Partner[] */ /* @var $historyModel \app\modules\cms\models\BalanceHistory */ /* @var $historyList \app\modules\cms\models\BalanceHistory[] */ //получить всех пользователей $sum = 1000.0; //сумма за каждое зачисление $userList = \app\modules\cms\models\User::find()->all(); $historyModel = new \app\modules\cms\models\BalanceHistory(); foreach ($userList as $user) { $userId = $user->id; // echo $user->username."\r\n"; //получить всех пользователей с партнерки $partnerList = \app\modules\cms\models\Partner::find()->where(['partnerId' => $userId])->all(); //получить историю баланса по юзеру $historyList = \app\modules\cms\models\BalanceHistory::find()->partner()->all(); $historyIdList = $historyModel->idList($historyList); if (sizeof($partnerList) > sizeof($historyList)) { foreach ($partnerList as $partner) { $id = md5($partner->userId . $partner->partnerId); if (!in_array($id, $historyIdList)) { // echo "\t".$id."\r\n"; $historyModel->add($userId, $sum, $partner->user->dateCreate, $id); } } } $balance = $historyModel->getBalanceById($user->id); if (!$user->profile) { continue; } $user->profile->updateBalance($balance); } }
public function actionEmail() { $items = User::find()->select('username')->all(); foreach ($items as $item) { file_put_contents('email-user.txt', $item->username . "\r\n", FILE_APPEND); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = User::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token]); return $dataProvider; }
public function getUser() { return $this->hasOne(User::className(), ['id' => 'userId']); }
public function actionActivate($cvcode) { /** * @var $model \app\modules\discount\models\Card */ $model = Card::findByCvcode($cvcode); if (!$model) { throw new HttpException('404', 'Карта с таким кодом не найдена!'); } $user = new User(); $user->scenario = 'client.create'; $user->role = 'client'; $profile = new Profile(); $profile->scenario = 'client.create'; $partner = new \app\modules\cms\models\Partner(); $partner->scenario = 'card.activate'; $partner->load($_POST); $partnerValidate = $partner->email ? $partner->validate() : true; // var_dump($partnerValidate); if ($user->load($_POST) && $profile->load($_POST) && $partnerValidate) { $model->status = Card::STATUS_ACTIVE; $user->dateCreate = date(DATE_FORMAT_DB); if ($user->save()) { $model->userId = $user->id; $profile->file = UploadedFile::getInstance($profile, 'file'); $profile->userId = $user->id; if ($profile->file) { $filename = $user->id . '.' . $profile->file->extension; $filepath = \Yii::getAlias(Profile::PHOTO_DIR_ALIAS) . '/' . $filename; $profile->file->saveAs($filepath, false); $profile->photo = $filename; } $profile->save(); $model->dateActivate = date('Y-m-d H:i:s'); $model->save(false, ['status', 'userId', 'dateActivate']); if ($partnerValidate) { $partner->create($user); } $loginModel = new \app\models\LoginForm(); $loginModel->username = $user->username; $loginModel->password = $user->password2; $loginModel->login(); $this->redirect(['card', 'cvcode' => $cvcode]); } } return $this->render('activate', ['model' => $model, 'user' => $user, 'profile' => $profile, 'partner' => $partner]); }
$form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'visible')->radioList(['Скрыт', 'Виден']); ?> <div class="col-md-12"> <?php echo \app\modules\cms\components\yandexMap\MapInput::widget(['model' => $model, 'attribute' => 'cords']); ?> </div> <div class="col-md-6"> <?php echo $form->field($model, 'userId')->dropDownList(\app\modules\cms\models\User::getDropDown(), ['rows' => 6]); ?> </div> <div class="col-md-6"> <?php echo $form->field($model, 'parentId')->dropDownList($category->dropDown(), ['rows' => 6]); ?> </div> <div class="row"> <div class="col-md-6"> <?php echo $form->field($model, 'title')->textInput(['maxlength' => 255]); ?>
/** * Finds the User model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return User the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = User::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }