Ejemplo n.º 1
0
 /**
  * 组管理(编辑组成员)
  */
 public function actionSavegroupuser()
 {
     $request = \Yii::$app->request;
     $identity = Identity::checkIdentity('savegroupuser', '/app-backend/backend/adminmanage/savegroupuser');
     if (is_array($identity)) {
         return $identity;
     }
     $groupId = $request->_get('groupId', 0);
     $userId = $request->_get('userId', 0);
     if (!$groupId || !$userId) {
         return ['code' => 1, 'msg' => '数据非法', 'data' => []];
     }
     $check = UserGroupAdmin::find()->where('groupId=' . $groupId . ' And userId=' . $userId)->one();
     if ($check) {
         $res = UserGroupAdmin::deleteAll('groupId=' . $groupId . ' And userId=' . $userId);
     } else {
         $usergroup = new UserGroupAdmin();
         $usergroup->userId = $userId;
         $usergroup->groupId = $groupId;
         $res = $usergroup->save();
     }
     if ($res !== false) {
         return ['code' => 0, 'msg' => '操作成功', 'data' => []];
     } else {
         return ['code' => 2, 'msg' => '操作失败,请重试', 'data' => []];
     }
 }
Ejemplo n.º 2
0
 /**
  * 管理员组成员
  */
 public function actionGroupuser()
 {
     $view = \Yii::$app->view;
     $view->params['moduleName'] = '管理员分组';
     $request = \Yii::$app->request;
     $groupId = $request->_get('groupId', '');
     $search = $request->_get('search', '');
     $where = 1;
     if (preg_match('/^1[0-9]{10}$/', $search)) {
         $where .= ' AND userMobile LIKE \'%' . $search . '%\'';
     } else {
         $where .= ' AND username LIKE \'%' . $search . '%\'';
     }
     $userModel = UserAdmin::find()->where($where);
     $pageSize = \Yii::$app->params['pageSize'];
     $total = $userModel->count();
     $pagination = new Pagination(['defaultPageSize' => $pageSize, 'totalCount' => $total]);
     $data = $userModel->asArray()->offset($pagination->offset)->limit($pagination->limit)->all();
     $groupuser = UserGroupAdmin::find()->where('groupId=' . $groupId)->asArray()->All();
     foreach ($data as &$user) {
         foreach ($groupuser as $group) {
             if ($user['id'] == $group['userId']) {
                 $user['inGroup'] = 1;
             }
         }
     }
     $token = Token::getToken();
     $userId = \Yii::$app->user->id;
     $savegroupuserIdentity = EasyHelpers::dataEncrypt('savegroupuser,' . $userId);
     return $this->render('groupuser', ['data' => $data, 'search' => $search, 'groupId' => $groupId, 'token' => $token, 'pagination' => $pagination, 'savegroupuserIdentity' => $savegroupuserIdentity]);
 }