public function actionIndex() { $this->layout = false; if (\Yii::$app->request->isAjax) { $user = new User(); $data = \Yii::$app->request->post(); $userInfo = $user->getFindUser(['name' => $data['name']]); $pass = md5(md5($data['password'])); \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; //将响应数据转json格式 if (!$userInfo || $userInfo['password'] != $pass) { //验证用户登录信息 return ['msg' => '用户名或密码错误', 'status' => 0]; } else { if ($member = \common\models\User::getInstance()->getUserByPhone($userInfo['phone'])) { $userInfo['member'] = $member; } $auth = \Yii::$app->authManager; $userRole = $auth->getAssignments($userInfo['id']); $role = ""; foreach ($userRole as $k => $v) { if ($k == 'admin') { $role = "admin"; break; } $role .= "," . $k; } $userInfo['role'] = $role; $user->setUserSession($userInfo); //设置Session return ['msg' => '登录成功', 'status' => 1]; } } return $this->render('index.html'); }
/** * @return string * 编辑用户 */ public function actionEditUser() { $auth = \Yii::$app->authManager; $request = \Yii::$app->request; $userModel = new User(); $user = $userModel->getFindUser(['id' => $request->get('id')]); $userRole = $auth->getAssignments($request->get('id')); $roleList = $auth->getRoles(); //用户已有角色处理 $list = array(); foreach ($roleList as $key => $val) { if (!empty($userRole) && array_key_exists($key, $userRole)) { $list[$key] = 1; } else { $list[$key] = 0; } } if ($request->post()) { if ($userModel->editUser($request->post())) { $this->__success('更新成功', 'list-user'); } else { $this->__error('更新失败'); } } $this->assign('user', $user); $this->assign('list', $list); return $this->render(); }
public function actionInfo() { $userId = \Yii::$app->request->get('id'); $user = User::getInstance()->getUserById($userId); $user['info'] = json_decode($user['info']); $user['auth'] = json_decode($user['auth']); // 获取登陆次数 $loginTime = User::getInstance()->getLoginTimes($userId); $moneyAll = User::getInstance()->getPayAll($userId); // 获取红娘名称 $userModel = new UserModel(); $matchmaker = $userModel->getFindUser(['id' => $user['matchmaker']]); $matchmaking = $userModel->getFindUser(['id' => $user['matchmaking']]); $this->assign('user', $user); $this->assign('loginTime', $loginTime); $this->assign('moneyAll', $moneyAll); $this->assign('matchmaker', $matchmaker['name']); $this->assign('matchmaking', $matchmaking['name']); $this->assign('photoList', UserPhoto::getInstance()->getPhotoList(\Yii::$app->request->get('id'))); // 消息 $messageList = UserMessage::getInstance()->chatList($userId); foreach ($messageList as $k => $v) { $messageList[$k]['info'] = json_decode($messageList[$k]['info']); } $this->assign('messageList', $messageList); // 动态 $dynamicList = UserDynamic::getInstance()->getDynamicList($userId, 0, 1000, -2); $this->assign('dynamicList', $dynamicList); // 认证 $identify = UserPhoto::getInstance()->getPhotoList($userId, [2, 3, 4, 5, 6]); $identifyType = []; foreach ($identify as $k => $v) { if ($v['is_check'] == '0') { unset($identify[$k]); continue; } $identifyType[$v['type']][] = $v; } $this->assign('identify', $identify); $this->assign('identifyType', $identifyType); // 红娘列表 $adminUserList = AuthUser::getInstance()->getUserByRole(['普通服务红娘', 'VIP服务红娘', '贵宾服务红娘', '钻石服务红娘']); $this->assign('adminUserList', $adminUserList); // 配对记录 $pairLogList = \common\models\PairLog::getInstance()->getPairLog($userId); // var_dump($pairLogList);exit(); $this->assign('pairLogList', $pairLogList); return $this->render(); }