本文整理汇总了PHP中app\models\Users::findByEmail方法的典型用法代码示例。如果您正苦于以下问题:PHP Users::findByEmail方法的具体用法?PHP Users::findByEmail怎么用?PHP Users::findByEmail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Users
的用法示例。
在下文中一共展示了Users::findByEmail方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUser
/**
* Finds user by [[username]]
*
* @return Users|null
*/
public function getUser()
{
if ($this->_user === false) {
$this->_user = Users::findByEmail($this->email);
}
return $this->_user;
}
示例2: getUser
/**
* Finds user by [[email]]
*
* @return User|null
*/
public function getUser()
{
if ($this->_user === false) {
$this->_user = Users::findByEmail($this->email);
if (!$this->_user || !$this->_user->getAttribute('user_mail_valid')) {
return false;
}
// $this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
示例3: sendMoney
/**
* Отправка денег между пользователями
* @param $email
* @param $money
* @throws \yii\db\Exception
*/
public static function sendMoney($email, $money)
{
$userTo = Users::findByEmail($email);
$userFrom = Users::findOne(\Yii::$app->user->id);
$money = (int) ($money * 100) / 100;
$transaction = \Yii::$app->db->beginTransaction();
try {
if ($money <= 0) {
throw new Exception(" Money < 0");
}
if ($userTo && $userTo->user_id != $userFrom->user_id) {
$userMoney = \Yii::$app->db->createCommand("SELECT user_id, user_money FROM public.user WHERE user_id IN (:idFrom, :idTo) FOR UPDATE", array(':idTo' => $userTo->user_id, ':idFrom' => $userFrom->user_id))->queryAll();
if ($userMoney[0]['user_id'] == $userTo->user_id) {
$userMoneyTo = $userMoney[0]['user_money'];
$userMoneyFrom = $userMoney[1]['user_money'];
} else {
$userMoneyTo = $userMoney[1]['user_money'];
$userMoneyFrom = $userMoney[0]['user_money'];
}
if ($userMoneyFrom - $money < 0) {
throw new Exception(" User (id: " . $userFrom->user_id . ") not enough money");
}
$to_balance = $userMoneyTo + $money;
$userTo->user_money = $to_balance;
$from_balance = $userMoneyFrom - $money;
$userFrom->user_money = $from_balance;
if ($userTo->save() && $userFrom->save()) {
self::setOperation($userFrom->user_id, $userTo->user_id, $money, $to_balance, $from_balance);
$transaction->commit();
} else {
throw new Exception(" User (id:" . $userFrom->user_id . ") failed to add money to user (id: " . $userTo->user_id . ")");
}
} else {
throw new Exception(" user (email: " . $email . ") not exist or user (id: " . $userTo->user_id . ") wanted to transfer the money at yourself");
}
} catch (Exception $e) {
$text = date('Y-m-d H:i') . $e->getMessage() . PHP_EOL;
file_put_contents("demoLog.txt", $text, FILE_APPEND);
$transaction->rollBack();
}
}
示例4: actionValidemail
/**
* Проверяем есть ли почта на которую пользователь отправляет деньги
* Хватает ли ему на это денег
*/
public function actionValidemail()
{
$email = Yii::$app->request->post('email');
if (!empty($email)) {
$userSend = Users::findByEmail($email);
$money = Users::getUserInf(Yii::$app->user->id);
$money = $money['user_money'];
$answer['money'] = $money;
if (is_null($userSend)) {
$answer['email'] = 'false';
echo json_encode($answer);
} else {
$answer['email'] = 'true';
echo json_encode($answer);
}
exit;
}
}