/** * 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]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['sex' => $this->sex, 'gid' => $this->gid, 'subscribe' => $this->subscribe, 'subscribe_at' => $this->subscribe_at, 'created_at' => $this->created_at]); $query->andFilterWhere(['like', 'openid', $this->openid])->andFilterWhere(['like', 'merchant_id', $this->merchant_id])->andFilterWhere(['like', 'nickname', $this->nickname])->andFilterWhere(['like', 'remark', $this->remark])->andFilterWhere(['like', 'language', $this->language])->andFilterWhere(['like', 'city', $this->city])->andFilterWhere(['like', 'province', $this->province])->andFilterWhere(['like', 'country', $this->country])->andFilterWhere(['like', 'headimgurl', $this->headimgurl]); return $dataProvider; }
/** * 发送红包 * @param $sendId * @param $receiveId * @param $money * @param $bri_message * @return bool|string * @throws \Exception */ public function sendBribery($sendId, $receiveId, $money, $bri_message) { $tran = \Yii::$app->db->beginTransaction(); $model = Base::getInstance('user_bribery'); $model->send_user_id = $sendId; $model->receive_user_id = $receiveId; $model->money = $money; $model->create_time = time(); $model->status = 0; $model->bri_message = $bri_message; if ($model->insert(true)) { $id = \Yii::$app->db->lastInsertID; if (User::getInstance()->changeBalance($sendId, $money)) { $tran->commit(); } return $id; } $tran->rollBack(); return false; }
public function actionQuickLogin() { // QQ登陆 if ($this->get['t'] == 'qq' && isset($this->get['code']) && $this->get['code'] != '') { $qqUser = Qq::getInstance()->getUser($this->get['code']); if ($qqUser) { if (!($user = User::getInstance()->getUser(['username' => $qqUser['openId']]))) { $user = ['username' => $qqUser['openId'], 'password' => $qqUser['openId'], 'login_type' => 2, 'sex' => $qqUser['sex']]; $user['id'] = User::getInstance()->addUser($user); } } } else { if ($this->get['t'] == 'weibo' && isset($this->get['code']) && $this->get['code'] != '') { $weiboUser = Weibo::getInstance()->getUser($this->get['code']); print_r($weiboUser); exit; } } \common\models\User::getInstance()->loginLog($user['id']); Cookie::getInstance()->setLoginCookie($user, '/qt'); return $this->render(); }
/** * 领取红包 */ public function actionOpenBribery() { $get = \Yii::$app->request->get(); $briberyId = $get['bribery_id']; $result = \wechat\models\User::getInstance()->openBribery($briberyId); $this->renderAjax(['status' => $result]); }
/** * Finds the User model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $openid * @param string $merchant_id * @return User the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($openid, $merchant_id) { if (($model = User::findOne(['openid' => $openid, 'merchant_id' => $merchant_id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * 首页是否显示数据 */ public function actionIndexIsShowData() { $user_id = Cookie::getInstance()->getCookie('bhy_id'); $result = User::getInstance()->indexIsShowData($user_id); $this->renderAjax($result); }
/** * 微信登录获取微信用户信息 * @return array|bool */ protected function weChatMember() { $code = \Yii::$app->request->get('code'); if ($code == null) { return false; } else { setcookie('wx_login', 'login', time() + 3600 * 24 * 30, '/wap'); } $memberInfo = \Yii::$app->wechat->getMemberByCode($code); // 从微信获取用户 // $memberInfo['openid'] = 'oEQpts_MMapxllPTfwRw0VfGeLSg'; // 测试 $data = ['wx_id' => $memberInfo['openid'], 'username' => $memberInfo['openid'], 'password' => 'wx_xx', 'login_type' => 3, 'sex' => isset($memberInfo['sex']) && $memberInfo['sex'] == 2 ? 0 : 1]; $user = User::getInstance()->getUser(['wx_id' => $data['wx_id']]); if (!$user) { // 用户不存在,虚拟账号登陆 setcookie('wx_id', $data['wx_id'], time() + 3600 * 24 * 30, '/'); $data['sex'] == 1 ? $user = User::getInstance()->getUserById(10011) : ($user = User::getInstance()->getUserById(10016)); } // 登录日志 \common\models\User::getInstance()->loginLog($user['id']); // 设置登录cookie Cookie::getInstance()->setLoginCookie($user); return $user; }
/** * 首页列表页 */ public function actionUserList() { $list = User::getInstance()->userList($this->get); $this->renderAjax(['status' => 1, 'data' => $list]); }