/** * Finds user by [[email]] * * @return Account|null */ public function getAccount() { if ($this->_account === false) { $this->_account = Account::findByEmail($this->email); } return $this->_account; }
/** * 验证用户是否有足够资金发布项目 */ public function logisfeeRight() { $oneAccount = Account::find()->where("user_id=:user_id", [':user_id' => $this->publis_user_id])->one(); if ($this->logis_fee > $oneAccount->use_money) { $this->addError('logis_fee', '您的可用资金不足以支付佣金。'); return false; } }
/** * set new email * @return bool */ public function changeEmail() { $user = Yii::$app->user->identity; if (!Account::isTokenValid($user->change_email_token)) { $user->generateChangeEmailToken(); } $user->new_email = $this->newEmail; if ($user->save()) { Yii::$app->language = $user->language; $subject = Yii::t('app', '[{APP_NAME}] Please verify your email address', ['APP_NAME' => Yii::$app->name]); return Yii::$app->mailer->compose(['html' => 'change-email-html', 'text' => 'change-email-text'], ['title' => $subject, 'user' => $user])->setFrom([Setting::getValue('outgoingMail')])->setTo($user->new_email)->setSubject($subject)->send(); } return false; }
/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { $user = Account::findOne(['status' => Account::STATUS_ACTIVE, 'email' => $this->email]); if ($user) { if (!Account::isTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } if ($user->save()) { $email = Yii::$app->mailer->compose(['html' => 'password-reset-token-html', 'text' => 'password-reset-token-text'], ['user' => $user])->setFrom([Setting::getValue('outgoingMail') => \Yii::$app->name])->setTo($this->email)->setSubject(Yii::t('app', 'Password reset for {APP_NAME}', ['APP_NAME' => \Yii::$app->name])); return $email->send(); } } return false; }
/** * 用户登录 * @param $post * @return array */ public static function login($post) { $passport = static::findByPhone($post['phone']); if (isset($passport)) { if ($passport->password === $passport->md5($post['password'])) { if (\Yii::$app->user->login($passport, isset($post['rememberMe']) ? 3600 * 24 * 30 : 0)) { $account = Account::find()->where(['passport_id' => $passport->id])->one(); \Yii::$app->session['passport_id'] = $passport->id; \Yii::$app->session['account_id'] = $account->id; return ['code' => 1, 'msg' => '登录成功']; } } else { return ['code' => 0, 'msg' => '密码错误']; } } else { return ['code' => 0, 'msg' => '手机号不存在']; } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Account::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'fullname_changed' => $this->fullname_changed, 'email_verified' => $this->email_verified, 'role' => $this->role, 'status' => $this->status, 'updated_at' => $this->updated_at, 'DATE(FROM_UNIXTIME(`created_at`))' => $this->created_at]); $query->andFilterWhere(['like', 'seo_name', $this->seo_name])->andFilterWhere(['like', 'fullname', $this->fullname])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'new_email', $this->new_email])->andFilterWhere(['like', 'change_email_token', $this->change_email_token])->andFilterWhere(['like', 'language', $this->language])->andFilterWhere(['like', 'timezone', $this->timezone]); //$query->andFilterWhere([ // 'DATE(FROM_UNIXTIME(`created_at`))' => $this->created_at, //]); return $dataProvider; }
/** * create new user * @param $u * @return bool */ protected function createUser($u) { $user = new Account(); $user->fullname = $u['name']; $user->email = $u['email']; return $user->save(); }
/** * @return \yii\db\ActiveQuery */ public function getAuthor() { return $this->hasOne(Account::className(), ['id' => 'created_by']); }
/** * 显示可用资金 */ public function actionBook() { $user_id = \Yii::$app->user->getId(); #获得用户的可用资金 $p_param = Yii::$app->request->get(); if (!isset($p_param['id'])) { echo 1; Yii::$app->end(); } $logis = Logistics::find()->where("id=:id", [':id' => $p_param['id']])->one(); if (!isset($logis)) { echo 1; Yii::$app->end(); } if ($user_id == $logis->publis_user_id) { echo '<p>不允许签订自己的物品</p><button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>'; Yii::$app->end(); } $oneAccount = Account::find()->where("user_id=:user_id", [':user_id' => $user_id])->one(); return $this->renderAjax('ajax_showUserMoney', ['oneAccount' => $oneAccount, 'logis' => $logis]); }
/** * handle */ public function handle() { $attributes = $this->client->getUserAttributes(); // common $continue = false; $id = ArrayHelper::getValue($attributes, 'id'); $fullname = ''; $email = ''; // google if ($this->client->getName() == 'google') { $fullname = ArrayHelper::getValue($attributes, 'displayName'); $emails = ArrayHelper::getValue($attributes, 'emails'); $email = $emails[0]['value']; $continue = true; } // facebook if ($this->client->getName() == 'facebook') { $fullname = ArrayHelper::getValue($attributes, 'name'); $email = ArrayHelper::getValue($attributes, 'email'); $continue = true; } if (!$continue) { // Yii::$app->getSession()->setFlash('info', [ // Yii::t('app', 'Flickr'), // ]); //Yii::$app->user->setReturnUrl(Yii::$app->request->referrer); return; } /* @var Auth $auth */ $auth = Auth::find()->where(['source' => $this->client->getId(), 'source_id' => $id])->one(); if (Yii::$app->user->isGuest) { if ($auth) { // login /* @var Account $user */ $user = $auth->user; $this->updateUserInfo($user); Yii::$app->user->login($user, Setting::getValue('rememberMeDuration')); } else { // signup if ($email !== null && Account::find()->where(['email' => $email])->exists()) { Yii::$app->getSession()->setFlash('error', [Yii::t('app', "User with the same email as in {client} account already exists but isn't linked to it. Login using email first to link it.", ['client' => $this->client->getTitle()])]); } else { $password = Yii::$app->security->generateRandomString(6); $user = new Account(['fullname' => $fullname, 'email' => $email, 'password' => $password]); $user->generateAuthKey(); $user->generatePasswordResetToken(); $transaction = Account::getDb()->beginTransaction(); //file_put_contents('D:\log', json_encode($transaction)); if ($user->save()) { $auth = new Auth(['user_id' => $user->id, 'source' => $this->client->getId(), 'source_id' => (string) $id]); if ($auth->save()) { $transaction->commit(); Yii::$app->user->login($user, Setting::getValue('rememberMeDuration')); } else { $transaction->rollBack(); Yii::$app->getSession()->setFlash('error', [Yii::t('app', 'Unable to save {client} account: {errors}', ['client' => $this->client->getTitle(), 'errors' => json_encode($auth->getErrors())])]); } } else { $transaction->rollBack(); Yii::$app->getSession()->setFlash('error', [Yii::t('app', 'Unable to save user: {errors}', ['client' => $this->client->getTitle(), 'errors' => json_encode($user->getErrors())])]); } } } } else { // user already logged in Yii::$app->user->setReturnUrl(Yii::$app->request->referrer); if (!$auth) { // add auth provider $auth = new Auth(['user_id' => Yii::$app->user->id, 'source' => $this->client->getId(), 'source_id' => (string) $attributes['id']]); if ($auth->save()) { /** @var Account $user */ $user = $auth->user; $this->updateUserInfo($user); Yii::$app->getSession()->setFlash('success', [Yii::t('app', 'Linked {client} account.', ['client' => $this->client->getTitle()])]); } else { Yii::$app->getSession()->setFlash('error', [Yii::t('app', 'Unable to link {client} account: {errors}', ['client' => $this->client->getTitle(), 'errors' => json_encode($auth->getErrors())])]); } } else { // there's existing auth Yii::$app->getSession()->setFlash('error', [Yii::t('app', 'Unable to link {client} account. There is another user using it.', ['client' => $this->client->getTitle()])]); } } }
<?php /* @var $this yii\web\View */ $this->title = '提现'; use yii\helpers\Url; use frontend\services\AccountService; use yii\widgets\ActiveForm; use yii\helpers\Html; use common\models\Account; use common\models\Bankcard; $user_id = Yii::$app->user->getId(); $oneuseraccount = Account::find()->where('user_id=:user_id', [':user_id' => $user_id])->one(); $oneBank = Bankcard::find()->where('user_id=:user_id', [':user_id' => $user_id])->one(); ?> <div class="container no-bottom"> <img class="responsive-image" src="/images/misc/help_server.png" alt="img"> </div> <div class="container"> <div class="tabs"> <a href="<?php echo Url::toRoute('/member/account/tixian'); ?> " class="tab-but tab-but-1 tab-active">申请提现</a> <a href="<?php echo Url::toRoute('/member/account/tixianlog'); ?> " class="tab-but tab-but-2">提现记录</a> </div> </div> <div class="container no-bottom"> <a href="#" style="width:100%;padding-left:13px;" class="button-big-icon-colse button-white">所属银行:<span class="float-right"><?php
/** * @return \yii\db\ActiveQuery */ public function getUpdatedBy() { return $this->hasOne(Account::className(), ['id' => 'updated_by']); }
<?php /* @var $this yii\web\View */ $this->title = '会员中心'; use yii\helpers\Url; use common\models\Account; $user_id = Yii::$app->user->getId(); $thisuserAccount = Account::find()->where(":user_id=user_id", [':user_id' => $user_id])->one(); ?> <div class="container no-bottom" style="background-color: #fae0ca;"> <p class="p_member_t"> 可用资金(元) </p> <p class="p_member_m"> <?php echo ceil($thisuserAccount->use_money * 100) / 100; ?> </p> <div class="one-half"> <p class="qys_member_center"> 今日收益<br> 0.00 </p> </div> <div class="two-half last-column"> <p class="qys_member_center"> 总收益<br> 100.00元 </p> </div>
/** * * @param type $object * @return string */ public static function getAccountClick($object, $weixinuser) { $myAccount = Account::find()->where("user_id=:user_id", [":user_id" => $weixinuser->user_id])->one(); $content = "我的总金额为:" . $myAccount->total . "\n" . "可用资金为:" . $myAccount->use_money; WechatCheck::_transmitText($object, $content); }
/** * Finds the Account model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Account the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Account::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.')); } }
//$js=file_get_contents(__DIR__.'/index.min.js'); //$this->registerJs($js); //$css=file_get_contents(__DIR__.'/index.css'); //$this->registerCss($css); ?> <div class="account-index"> <div class="box box-primary"> <div class="box-body"> <?php Pjax::begin(); ?> <div class="table-responsive sort-ordinal"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['id', 'fullname', 'email:email', ['attribute' => 'created_at', 'value' => 'created_at', 'format' => 'dateTime', 'filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'created_at', 'dateFormat' => 'yyyy-MM-dd', 'options' => ['class' => 'form-control']])], ['attribute' => 'status', 'value' => function ($model) { return $model->statusText; }, 'filter' => Account::getStatusOption()], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {update}']]]); ?> </div> <?php Pjax::end(); ?> <p><?php echo Html::a(Yii::t('app', 'Add New User'), ['create'], ['class' => 'btn btn-success']); ?> </p> </div> <!-- Loading (remove the following to stop the loading)--> <div class="overlay grid-view-overlay hidden"> <?php echo \modernkernel\fontawesome\Icon::widget(['icon' => 'refresh fa-spin']); ?>
public static function addUser($weixinUser) { #注册新用户 $newuser = new User(); $newuser->setAttribute('username', $weixinUser); $newuser->setAttribute('password', $newuser->generatePassword(self::generateRandString())); $newuser->setAttribute('wangwang', $weixinUser); if ($newuser->validate() && $newuser->save()) { $accountarray = array('user_id' => \Yii::$app->db->getLastInsertID(), 'total' => 0, 'use_money' => 0, 'no_use_money' => 0, 'newworth' => 0); $newAccount = new Account(); $newAccount->setAttributes($accountarray); $newAccount->save(); } $user = User::find()->where("username=:username", [":username" => $weixinUser])->one(); return $user; }
/** * 显示可用资金 */ public function actionShowmymoney() { $user_id = \Yii::$app->user->getId(); #获得用户的可用资金 $p_param = Yii::$app->request->get(); if (!isset($p_param['id'])) { echo 1; Yii::$app->end(); } $product = Product::find()->where("product_id=:id", [':id' => $p_param['id']])->one(); if (!isset($product)) { echo 1; Yii::$app->end(); } if ($user_id == $product->product_user_id) { echo '<p>不允许购买自己的商品</p><button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>'; Yii::$app->end(); } $oneAccount = Account::find()->where("user_id=:user_id", [':user_id' => $user_id])->one(); return $this->renderAjax('ajax_showUserMoney', ['oneAccount' => $oneAccount, 'product' => $product]); }
/** * @return \yii\db\ActiveQuery */ public function getUser() { return $this->hasOne(Account::className(), ['id' => 'user_id']); }