uni-app 95获取群聊相关信息(一)

简介: uni-app 95获取群聊相关信息(一)


/app/model/group_user.js

// app/model/group_user.js
'use strict';
const crypto = require('crypto');
module.exports = app => {
    const { STRING, INTEGER, DATE, ENUM, TEXT } = app.Sequelize;
    // 配置(重要:一定要配置详细,一定要!!!)
    const GroupUser = app.model.define('group_user', {
        id: {
            type: INTEGER(20).UNSIGNED,
            primaryKey: true,
            autoIncrement: true
        },
        user_id: {
            type: INTEGER(20).UNSIGNED,
            allowNull: false,
            comment: '用户id',
            //  定义外键(重要)
            references: {
                model: 'user', // 对应表名称(数据表名称)
                key: 'id' // 对应表的主键
            },
            onUpdate: 'restrict', // 更新时操作
            onDelete: 'cascade'  // 删除时操作
        },
        group_id: {
            type: INTEGER(20).UNSIGNED,
            allowNull: false,
            comment: '群组id',
            //  定义外键(重要)
            references: {
                model: 'group', // 对应表名称(数据表名称)
                key: 'id' // 对应表的主键
            },
            onUpdate: 'restrict', // 更新时操作
            onDelete: 'cascade'  // 删除时操作
        },
        nickname: {
            type: STRING(30),
            allowNull: false,
            defaultValue: '',
            comment: '在群里的昵称',
        },
        created_at: DATE,
        updated_at: DATE
    });
    // 定义关联关系
    GroupUser.associate = function(model){
        GroupUser.belongsTo(app.model.User,{
            foreignKey:'user_id'
        });
    };
    return GroupUser;
};

app/controller/group.js

// 查看群资料
    async info() {
        const { ctx, app } = this;
        let current_user_id = ctx.authUser.id;
        // 验证参数
        ctx.validate({
            id: {
                required: true,
                type: 'int',
                desc: "群组id"
            }
        });
        let { id } = ctx.params;
        // 群组是否存在
        let group = await app.model.Group.findOne({
            where: {
                status: 1,
                id
            },
            include: [{
                model: app.model.GroupUser,
                attributes: ['user_id', 'nickname'],
                include: [{
                    model: app.model.User,
                    attributes: ['id', 'nickname', 'avatar', 'username']
                }]
            }]
        });
        if (!group) {
            return ctx.apiFail('该群聊不存在或者已被封禁');
        }
        // 当前用户是否是该群成员
        let index = group.group_users.findIndex(item => item.user_id === current_user_id);
        if (index === -1) {
            return ctx.apiFail('你不是该群成员,没有权限');
        }
        ctx.apiSuccess(group);
    }

router.js

// 获取群资料
 router.get('/group_info/:id',controller.group.info);

下图是我测试的结果

感谢大家观看,我们下次见

目录
相关文章
|
JSON API 开发工具
【Azure 应用服务】调用Azure REST API来获取 App Service的访问限制信息(Access Restrictions)以及修改
【Azure 应用服务】调用Azure REST API来获取 App Service的访问限制信息(Access Restrictions)以及修改
317 1
|
存储 监控 API
【Azure App Service】分享使用Python Code获取App Service的服务器日志记录管理配置信息
本文介绍了如何通过Python代码获取App Service中“Web服务器日志记录”的配置状态。借助`azure-mgmt-web` SDK,可通过初始化`WebSiteManagementClient`对象、调用`get_configuration`方法来查看`http_logging_enabled`的值,从而判断日志记录是否启用及存储方式(关闭、存储或文件系统)。示例代码详细展示了实现步骤,并附有执行结果与官方文档参考链接,帮助开发者快速定位和解决问题。
508 22
|
数据库
《仿盒马》app开发技术分享-- 插入积分信息(65)
上一节我们实现了积分页面的大概框架,那么现在我们开始进行数据的填充和查询,积分相关的内容现在之后当回收订单结算之后才会进行积分数据的添加,那我们想查询出对应的积分数据,还需要新增一张积分信息表
281 0
|
Java 应用服务中间件 开发工具
[App Service for Windows]通过 KUDU 查看 Tomcat 配置信息
[App Service for Windows]通过 KUDU 查看 Tomcat 配置信息
372 2
|
Go 开发者
【应用服务 App Service】App Service发生错误请求时,如何查看IIS Freb日志,从中得知错误所发生的模块,请求中所携带的Header信息
【应用服务 App Service】App Service发生错误请求时,如何查看IIS Freb日志,从中得知错误所发生的模块,请求中所携带的Header信息
410 2
|
JavaScript Java 测试技术
基于SpringBoot+Vue+uniapp的电影信息推荐APP的详细设计和实现(源码+lw+部署文档+讲解等)
基于SpringBoot+Vue+uniapp的电影信息推荐APP的详细设计和实现(源码+lw+部署文档+讲解等)
282 6
|
JavaScript Java 测试技术
基于springboot+vue.js+uniapp的电影信息推荐APP附带文章源码部署视频讲解等
基于springboot+vue.js+uniapp的电影信息推荐APP附带文章源码部署视频讲解等
282 1
|
机器学习/深度学习 开发工具 Python
【Azure 应用服务】使用Python Azure SDK 来获取 App Service的访问限制信息(Access Restrictions)
【Azure 应用服务】使用Python Azure SDK 来获取 App Service的访问限制信息(Access Restrictions)
416 0
|
Web App开发 iOS开发
【Azure 应用服务】App Service站点Header头中的中文信息显示乱码?当下载文件时,文件名也是乱码?
【Azure 应用服务】App Service站点Header头中的中文信息显示乱码?当下载文件时,文件名也是乱码?
362 0
|
XML 数据格式
【应用服务 App Service】如何移除App Service Response Header中包含的服务器敏感信息
【应用服务 App Service】如何移除App Service Response Header中包含的服务器敏感信息
281 0

热门文章

最新文章