"use strict"; /* * 喝酒了么 - 后端接口 API * 小程序:喝酒了么(uni-app 微信小程序) * 基础URL: /api/v1 * * 主要功能模块: * 1. 用户模块 - 微信登录、用户信息管理 * 2. 打卡记录模块 - 饮酒记录创建、查询、日历数据 * 3. 照片上传模块 - 单张/批量照片上传 * 4. 统计模块 - 用户统计、月度统计、酒类分布 * 5. 成就模块 - 成就列表和进度 * 6. 社交模块 - 朋友圈动态、点赞 */ export class Enum { constructor(value) { this.v = value; } toString() { return this.v; } toJSON() { return this.v; } valueOf() { return this.v; }; } /** * 成就条件类型 */ export class AchievementConditionType { /** * 总记录数 */ static TotalRecords = "total_records"; /** * 累计标准杯 */ static TotalStandardCups = "total_standard_cups"; /** * 连续打卡天数 */ static StreakDays = "streak_days"; /** * 某酒类打卡次数 */ static CategoryRecords = "category_records"; /** * 尝试酒类品种数 */ static CategoryVariety = "category_variety"; static entries() { return [ { value: AchievementConditionType.TotalRecords, label: '总记录数' }, { value: AchievementConditionType.TotalStandardCups, label: '累计标准杯' }, { value: AchievementConditionType.StreakDays, label: '连续打卡天数' }, { value: AchievementConditionType.CategoryRecords, label: '某酒类打卡次数' }, { value: AchievementConditionType.CategoryVariety, label: '尝试酒类品种数' }, ]; } static getLabel(v) { switch(v) { case AchievementConditionType.TotalRecords: return '总记录数'; case AchievementConditionType.TotalStandardCups: return '累计标准杯'; case AchievementConditionType.StreakDays: return '连续打卡天数'; case AchievementConditionType.CategoryRecords: return '某酒类打卡次数'; case AchievementConditionType.CategoryVariety: return '尝试酒类品种数'; } } } /** * 酒类分类 */ export class Category { /** * 白酒 */ static Baijiu = "baijiu"; /** * 啤酒 */ static Beer = "beer"; /** * 红酒 */ static Wine = "wine"; /** * 洋酒 */ static Whisky = "whisky"; /** * 黄酒 */ static Huangjiu = "huangjiu"; /** * 清酒 */ static Sake = "sake"; /** * 果酒 */ static Fruit = "fruit"; /** * 调酒 */ static Cocktail = "cocktail"; /** * 其他 */ static Other = "other"; static entries() { return [ { value: Category.Baijiu, label: '白酒' }, { value: Category.Beer, label: '啤酒' }, { value: Category.Wine, label: '红酒' }, { value: Category.Whisky, label: '洋酒' }, { value: Category.Huangjiu, label: '黄酒' }, { value: Category.Sake, label: '清酒' }, { value: Category.Fruit, label: '果酒' }, { value: Category.Cocktail, label: '调酒' }, { value: Category.Other, label: '其他' }, ]; } static getLabel(v) { switch(v) { case Category.Baijiu: return '白酒'; case Category.Beer: return '啤酒'; case Category.Wine: return '红酒'; case Category.Whisky: return '洋酒'; case Category.Huangjiu: return '黄酒'; case Category.Sake: return '清酒'; case Category.Fruit: return '果酒'; case Category.Cocktail: return '调酒'; case Category.Other: return '其他'; } } } /** * 饮用量单位 */ export class Unit { /** * 毫升 */ static Ml = "ml"; /** * 两 */ static Liang = "liang"; /** * 瓶 */ static Bottle = "bottle"; /** * 杯 */ static Cup = "cup"; /** * 听 */ static Can = "can"; /** * shot */ static Shot = "shot"; static entries() { return [ { value: Unit.Ml, label: '毫升' }, { value: Unit.Liang, label: '两' }, { value: Unit.Bottle, label: '瓶' }, { value: Unit.Cup, label: '杯' }, { value: Unit.Can, label: '听' }, { value: Unit.Shot, label: 'shot' }, ]; } static getLabel(v) { switch(v) { case Unit.Ml: return '毫升'; case Unit.Liang: return '两'; case Unit.Bottle: return '瓶'; case Unit.Cup: return '杯'; case Unit.Can: return '听'; case Unit.Shot: return 'shot'; } } } /** * 配餐分类 */ export class FoodCategory { /** * 火锅 */ static Hotpot = "hotpot"; /** * 烧烤 */ static Bbq = "bbq"; /** * 炒菜 */ static Stirfry = "stirfry"; /** * 海鲜 */ static Seafood = "seafood"; /** * 日料 */ static Japanese = "japanese"; /** * 西餐 */ static Western = "western"; /** * 小吃卤味 */ static Snack = "snack"; /** * 零食 */ static Junk = "junk"; /** * 无配餐 */ static None = "none"; static entries() { return [ { value: FoodCategory.Hotpot, label: '火锅' }, { value: FoodCategory.Bbq, label: '烧烤' }, { value: FoodCategory.Stirfry, label: '炒菜' }, { value: FoodCategory.Seafood, label: '海鲜' }, { value: FoodCategory.Japanese, label: '日料' }, { value: FoodCategory.Western, label: '西餐' }, { value: FoodCategory.Snack, label: '小吃卤味' }, { value: FoodCategory.Junk, label: '零食' }, { value: FoodCategory.None, label: '无配餐' }, ]; } static getLabel(v) { switch(v) { case FoodCategory.Hotpot: return '火锅'; case FoodCategory.Bbq: return '烧烤'; case FoodCategory.Stirfry: return '炒菜'; case FoodCategory.Seafood: return '海鲜'; case FoodCategory.Japanese: return '日料'; case FoodCategory.Western: return '西餐'; case FoodCategory.Snack: return '小吃卤味'; case FoodCategory.Junk: return '零食'; case FoodCategory.None: return '无配餐'; } } } /** * 饮用感受 */ export class Feeling { /** * 微醺 */ static Tipsy = "tipsy"; /** * 到位 */ static Buzzed = "buzzed"; /** * 醉了 */ static Drunk = "drunk"; /** * 断片 */ static Blackout = "blackout"; static entries() { return [ { value: Feeling.Tipsy, label: '微醺' }, { value: Feeling.Buzzed, label: '到位' }, { value: Feeling.Drunk, label: '醉了' }, { value: Feeling.Blackout, label: '断片' }, ]; } static getLabel(v) { switch(v) { case Feeling.Tipsy: return '微醺'; case Feeling.Buzzed: return '到位'; case Feeling.Drunk: return '醉了'; case Feeling.Blackout: return '断片'; } } } /** * 可见范围 */ export class Visibility { /** * 公开 */ static Public = "public"; /** * 仅好友 */ static Friends = "friends"; /** * 仅自己 */ static Private = "private"; static entries() { return [ { value: Visibility.Public, label: '公开' }, { value: Visibility.Friends, label: '仅好友' }, { value: Visibility.Private, label: '仅自己' }, ]; } static getLabel(v) { switch(v) { case Visibility.Public: return '公开'; case Visibility.Friends: return '仅好友'; case Visibility.Private: return '仅自己'; } } } /** * 打卡模式 */ export class Mode { /** * 今日喝了 */ static Drank = "drank"; /** * 今日未喝 */ static Abstain = "abstain"; static entries() { return [ { value: Mode.Drank, label: '今日喝了' }, { value: Mode.Abstain, label: '今日未喝' }, ]; } static getLabel(v) { switch(v) { case Mode.Drank: return '今日喝了'; case Mode.Abstain: return '今日未喝'; } } } /** * 饮酒频率 */ export class Frequency { /** * 很少 */ static Rarely = "rarely"; /** * 有时 */ static Sometimes = "sometimes"; /** * 经常 */ static Often = "often"; static entries() { return [ { value: Frequency.Rarely, label: '很少' }, { value: Frequency.Sometimes, label: '有时' }, { value: Frequency.Often, label: '经常' }, ]; } static getLabel(v) { switch(v) { case Frequency.Rarely: return '很少'; case Frequency.Sometimes: return '有时'; case Frequency.Often: return '经常'; } } } /** * 手机号 */ export class Phone { /** * @param regin string * @param number string */ constructor(regin, number) { this.regin = regin; this.number = number; } } /** * 分页请求参数 */ export class PageReq { /** * @param page: number 页码 * @param pageSize: number 每页数量,默认1-100 */ constructor(page,pageSize,) { this.page = page; this.pageSize = pageSize; } static fromObject(o) { return new PageReq(o.page,o.pageSize,); } } /** * 分页响应结构 */ export class PageResp { /** * @param total: number 总数 * @param page: number 当前页码 * @param pageSize: number 每页数量 */ constructor(total,page,pageSize,) { this.total = total; this.page = page; this.pageSize = pageSize; } static fromObject(o) { return new PageResp(o.total,o.page,o.pageSize,); } } /** * */ export class Ok { /** * @param ok: boolean 是否成功 */ constructor(ok,) { this.ok = ok; } static fromObject(o) { return new Ok(o.ok,); } } /** * 微信登录请求参数 */ export class WechatLoginReq { /** * @param code: string 登录时获取的 code, 可通过 wx.login 获取 * @param nickName: string 用户昵称 * @param avatarUrl: string 头像URL */ constructor(code,nickName,avatarUrl,) { this.code = code; this.nickName = nickName; this.avatarUrl = avatarUrl; } static fromObject(o) { return new WechatLoginReq(o.code,o.nickName,o.avatarUrl,); } } /** * 微信登录返回值 */ export class WechatLoginResp { /** * @param token: string JWT Token * @param user: User 用户信息 * @param isNew: boolean 是否新用户 * @param session_key: string 会话密钥 * @param open_id: string 用户唯一标识 * @param union_id: string 用户在开放平台的唯一标识符,若当前小程序已绑定到微信开放平台账号下会返回,详见 UnionID 机制说明。 * @param errcode: number 错误码 * @param errmsg: string 错误信息 * @param refresh_token: string 刷新token */ constructor(token,user,isNew,session_key,open_id,union_id,errcode,errmsg,refresh_token,) { this.token = token; this.user = user; this.isNew = isNew; this.session_key = session_key; this.open_id = open_id; this.union_id = union_id; this.errcode = errcode; this.errmsg = errmsg; this.refresh_token = refresh_token; } static fromObject(o) { return new WechatLoginResp(o.token,o.user,o.isNew,o.session_key,o.open_id,o.union_id,o.errcode,o.errmsg,o.refresh_token,); } } /** * 获取微信手机号 */ export class WechatGetPhoneNumberReq { /** * @param code: string 手机号获取凭证 */ constructor(code,) { this.code = code; } static fromObject(o) { return new WechatGetPhoneNumberReq(o.code,); } } /** * 获取微信手机号返回值 */ export class WechatGetPhoneNumberResp { /** * @param errcode: number 错误码 * @param errmsg: string 错误信息 * @param token: string token:api使用 * @param expires_in: number token 超时时间,单位(秒) * @param refresh_token: string refresh_token:刷新token */ constructor(errcode,errmsg,token,expires_in,refresh_token,) { this.errcode = errcode; this.errmsg = errmsg; this.token = token; this.expires_in = expires_in; this.refresh_token = refresh_token; } static fromObject(o) { return new WechatGetPhoneNumberResp(o.errcode,o.errmsg,o.token,o.expires_in,o.refresh_token,); } } /** * 刷新token请求参数 */ export class RefreshTokenReq { /** * @param refresh_token: string 签发 token 时生成的 refresh_token */ constructor(refresh_token,) { this.refresh_token = refresh_token; } static fromObject(o) { return new RefreshTokenReq(o.refresh_token,); } } /** * 刷新 token 返回值 */ export class RefreshTokenResp { /** * @param token: string 生成的新token * @param expire_in: number token 超时时间,单位(秒) * @param refresh_token: string refresh_token:刷新token */ constructor(token,expire_in,refresh_token,) { this.token = token; this.expire_in = expire_in; this.refresh_token = refresh_token; } static fromObject(o) { return new RefreshTokenResp(o.token,o.expire_in,o.refresh_token,); } } /** * 成就条件 */ export class AchievementCondition { /** * @param type: AchievementConditionType 条件类型 * @param value: number 目标值 */ constructor(type,value,) { this.type = type; this.value = value; } static fromObject(o) { return new AchievementCondition(o.type,o.value,); } } /** * 成就信息 */ export class Achievement { /** * @param id: string 成就ID * @param name: string 成就名称 * @param desc: string 成就描述 * @param icon: string 成就图标 * @param unlocked: boolean 是否已解锁 * @param unlockedAt: string 解锁时间 * @param condition: AchievementCondition 成就条件 * @param progress: number 进度(0-1) */ constructor(id,name,desc,icon,unlocked,unlockedAt,condition,progress,) { this.id = id; this.name = name; this.desc = desc; this.icon = icon; this.unlocked = unlocked; this.unlockedAt = unlockedAt; this.condition = condition; this.progress = progress; } static fromObject(o) { return new Achievement(o.id,o.name,o.desc,o.icon,o.unlocked,o.unlockedAt,o.condition,o.progress,); } } /** * */ export class GetAchievementsReq { /** */ constructor() { } static fromObject(o) { return new GetAchievementsReq(); } } /** * 获取成就列表响应 */ export class GetAchievementsResp { /** * @param data: AchievementsData 成就列表数据 */ constructor(data,) { this.data = data; } static fromObject(o) { return new GetAchievementsResp(o.data,); } } /** * 成就列表数据 */ export class AchievementsData { /** * @param achievements: Array 成就列表 */ constructor(achievements,) { this.achievements = achievements; } static fromObject(o) { return new AchievementsData(o.achievements,); } } /** * 朋友圈动态项 */ export class FeedItem { /** * @param id: string|number 记录ID * @param user: FeedUser 用户信息 * @param date: string 日期 * @param mode: Mode 打卡模式 * @param drinks: Array 酒水列表 * @param food: FoodInfo 配餐信息 * @param feeling: Feeling 感受 * @param photos: Array 照片URL数组 * @param standardCupsTotal: number 标准杯总数 * @param quote: string 酒言酒语 * @param likeCount: number 点赞数 * @param commentCount: number 评论数 * @param liked: boolean 当前用户是否已点赞 * @param createdAt: string 创建时间 */ constructor(id,user,date,mode,drinks,food,feeling,photos,standardCupsTotal,quote,likeCount,commentCount,liked,createdAt,) { this.id = id; this.user = user; this.date = date; this.mode = mode; this.drinks = drinks; this.food = food; this.feeling = feeling; this.photos = photos; this.standardCupsTotal = standardCupsTotal; this.quote = quote; this.likeCount = likeCount; this.commentCount = commentCount; this.liked = liked; this.createdAt = createdAt; } static fromObject(o) { return new FeedItem(o.id,o.user,o.date,o.mode,o.drinks,o.food,o.feeling,o.photos,o.standardCupsTotal,o.quote,o.likeCount,o.commentCount,o.liked,o.createdAt,); } } /** * 朋友圈用户信息 */ export class FeedUser { /** * @param id: string|number 用户ID * @param nickname: string 用户昵称 * @param avatar: string 头像URL */ constructor(id,nickname,avatar,) { this.id = id; this.nickname = nickname; this.avatar = avatar; } static fromObject(o) { return new FeedUser(o.id,o.nickname,o.avatar,); } } /** * 获取朋友圈动态请求 */ export class GetFeedReq { /** * @param lastId: string|number 游标分页,上一页最后一条ID */ constructor(lastId,) { this.lastId = lastId; } static fromObject(o) { return new GetFeedReq(o.lastId,); } } /** * 获取朋友圈动态响应 */ export class GetFeedResp { /** * @param data: FeedPageData 朋友圈动态分页数据 */ constructor(data,) { this.data = data; } static fromObject(o) { return new GetFeedResp(o.data,); } } /** * 朋友圈动态分页数据 */ export class FeedPageData { /** * @param list: Array 动态列表 */ constructor(list,) { this.list = list; } static fromObject(o) { return new FeedPageData(o.list,); } } /** * 点赞/取消点赞请求 */ export class LikeRecordReq { /** * @param id: string|number 记录ID */ constructor(id,) { this.id = id; } static fromObject(o) { return new LikeRecordReq(o.id,); } } /** * 点赞/取消点赞响应 */ export class LikeRecordResp { /** */ constructor() { } static fromObject(o) { return new LikeRecordResp(); } } /** * 上传照片请求 */ export class UploadPhotoReq { /** * @param url: string 图片Url * @param recordId: string|number 关联记录ID */ constructor(url,recordId,) { this.url = url; this.recordId = recordId; } static fromObject(o) { return new UploadPhotoReq(o.url,o.recordId,); } } /** * 上传照片响应 */ export class UploadPhotoResp { /** */ constructor() { } static fromObject(o) { return new UploadPhotoResp(); } } /** * 批量上传照片请求 */ export class UploadPhotosReq { /** * @param urls: Array 图片URL数组(最多9张) * @param recordId: string|number 关联记录ID */ constructor(urls,recordId,) { this.urls = urls; this.recordId = recordId; } static fromObject(o) { return new UploadPhotosReq(o.urls,o.recordId,); } } /** * 批量上传照片响应 */ export class UploadPhotosResp { /** */ constructor() { } static fromObject(o) { return new UploadPhotosResp(); } } /** * 酒水项 */ export class DrinkItem { /** * @param category: Category 酒类分类ID * @param brand: string 品牌名称 * @param product: string 产品名 * @param amount: number 饮用量数值 * @param unit: Unit 单位 * @param degree: number 酒精度数(%) * @param standardCups: number 标准杯数(前端计算,后端应校验) */ constructor(category,brand,product,amount,unit,degree,standardCups,) { this.category = category; this.brand = brand; this.product = product; this.amount = amount; this.unit = unit; this.degree = degree; this.standardCups = standardCups; } static fromObject(o) { return new DrinkItem(o.category,o.brand,o.product,o.amount,o.unit,o.degree,o.standardCups,); } } /** * 配餐信息 */ export class FoodInfo { /** * @param category: FoodCategory 配餐分类ID * @param name: string 具体菜名 */ constructor(category,name,) { this.category = category; this.name = name; } static fromObject(o) { return new FoodInfo(o.category,o.name,); } } /** * 创建打卡记录请求 */ export class CreateRecordReq { /** * @param date: string 日期 YYYY-MM-DD * @param mode: Mode 打卡模式 * @param drinks: Array 酒水列表(mode=abstain时为空数组) * @param food: FoodInfo 配餐信息 * @param feeling: Feeling 感受ID * @param photos: Array 照片URL数组(最多9张) * @param visibility: Visibility 可见范围 * @param quote: string 酒言酒语 */ constructor(date,mode,drinks,food,feeling,photos,visibility,quote,) { this.date = date; this.mode = mode; this.drinks = drinks; this.food = food; this.feeling = feeling; this.photos = photos; this.visibility = visibility; this.quote = quote; } static fromObject(o) { return new CreateRecordReq(o.date,o.mode,o.drinks,o.food,o.feeling,o.photos,o.visibility,o.quote,); } } /** * 打卡记录详情 */ export class Record { /** * @param id: string|number 记录ID * @param date: string 日期 * @param mode: Mode 打卡模式 * @param drinks: Array 酒水列表 * @param food: FoodInfo 配餐信息 * @param feeling: Feeling 感受 * @param photos: Array 照片URL数组 * @param visibility: Visibility 可见范围 * @param quote: string 酒言酒语 * @param standardCupsTotal: number 标准杯总数 * @param createdAt: string 创建时间 */ constructor(id,date,mode,drinks,food,feeling,photos,visibility,quote,standardCupsTotal,createdAt,) { this.id = id; this.date = date; this.mode = mode; this.drinks = drinks; this.food = food; this.feeling = feeling; this.photos = photos; this.visibility = visibility; this.quote = quote; this.standardCupsTotal = standardCupsTotal; this.createdAt = createdAt; } static fromObject(o) { return new Record(o.id,o.date,o.mode,o.drinks,o.food,o.feeling,o.photos,o.visibility,o.quote,o.standardCupsTotal,o.createdAt,); } } /** * 创建打卡记录响应 */ export class CreateRecordResp { /** * @param data: Record 创建的记录详情 */ constructor(data,) { this.data = data; } static fromObject(o) { return new CreateRecordResp(o.data,); } } /** * 获取记录列表请求 */ export class GetRecordsReq { /** * @param page: number 页码 * @param pageSize: number 每页数量,默认1-100 * @param month: string 月份筛选 YYYY-MM * @param mode: Mode 打卡模式筛选 */ constructor(page,pageSize,month,mode,) { this.page = page; this.pageSize = pageSize; this.month = month; this.mode = mode; } static fromObject(o) { return new GetRecordsReq(o.page,o.pageSize,o.month,o.mode,); } } /** * 获取记录列表响应 */ export class GetRecordsResp { /** * @param list: Array 分页数据 */ constructor(list,) { this.list = list; } static fromObject(o) { return new GetRecordsResp(o.list,); } } /** * 获取单条记录详情请求 */ export class GetRecordDetailReq { /** * @param id: string|number 记录ID */ constructor(id,) { this.id = id; } static fromObject(o) { return new GetRecordDetailReq(o.id,); } } /** * 获取单条记录详情响应 */ export class GetRecordDetailResp { /** * @param data: Record 记录详情 */ constructor(data,) { this.data = data; } static fromObject(o) { return new GetRecordDetailResp(o.data,); } } /** * 删除记录请求 */ export class DeleteRecordReq { /** * @param id: string|number 记录ID */ constructor(id,) { this.id = id; } static fromObject(o) { return new DeleteRecordReq(o.id,); } } /** * 删除记录响应 */ export class DeleteRecordResp { /** */ constructor() { } static fromObject(o) { return new DeleteRecordResp(); } } /** * 获取日历打卡数据请求 */ export class GetCalendarReq { /** * @param year: number 年份 * @param month: number 月份(1-12) */ constructor(year,month,) { this.year = year; this.month = month; } static fromObject(o) { return new GetCalendarReq(o.year,o.month,); } } /** * 日历打卡数据 */ export class CalendarData { /** * @param year: number 年份 * @param month: number 月份 * @param days: Array 每天的打卡数据,null表示当天无记录 */ constructor(year,month,days,) { this.year = year; this.month = month; this.days = days; } static fromObject(o) { return new CalendarData(o.year,o.month,o.days,); } } /** * 日历单日打卡数据 */ export class CalendarDayData { /** * @param date: string 日期YYYY-MM-DD * @param hasRecord: boolean 是否有记录 * @param mode: Mode 打卡模式 * @param standardCupsTotal: number 标准杯总数 * @param id: string|number 记录ID * @param drinks: Array 酒水列表 * @param food: FoodInfo 配餐信息 * @param feeling: Feeling 感受 * @param photos: Array 照片URL数组 * @param visibility: Visibility 可见范围 * @param quote: string 酒言酒语 * @param createdAt: string 创建时间 */ constructor(date,hasRecord,mode,standardCupsTotal,id,drinks,food,feeling,photos,visibility,quote,createdAt,) { this.date = date; this.hasRecord = hasRecord; this.mode = mode; this.standardCupsTotal = standardCupsTotal; this.id = id; this.drinks = drinks; this.food = food; this.feeling = feeling; this.photos = photos; this.visibility = visibility; this.quote = quote; this.createdAt = createdAt; } static fromObject(o) { return new CalendarDayData(o.date,o.hasRecord,o.mode,o.standardCupsTotal,o.id,o.drinks,o.food,o.feeling,o.photos,o.visibility,o.quote,o.createdAt,); } } /** * 获取日历打卡数据响应 */ export class GetCalendarResp { /** * @param year: number 年份 * @param month: number 月份 * @param days: Array 每天的打卡数据,null表示当天无记录 */ constructor(year,month,days,) { this.year = year; this.month = month; this.days = days; } static fromObject(o) { return new GetCalendarResp(o.year,o.month,o.days,); } } /** * 用户统计概览数据 */ export class StatsOverview { /** * @param weekDrinkCount: number 本周饮酒天数 * @param weekCups: number 本周标准杯总数 * @param monthDrinkCount: number 本月饮酒天数 * @param monthCups: number 本月标准杯总数 * @param streak: number 当前连续打卡天数 * @param streakType: Mode 连续类型 * @param totalDays: number 总饮酒天数(去重) * @param totalRecords: number 总记录数 * @param totalCups: number 历史累计标准杯 * @param favCategory: Category 最爱酒类ID * @param categoryVariety: number 尝试过的酒类品种数 */ constructor(weekDrinkCount,weekCups,monthDrinkCount,monthCups,streak,streakType,totalDays,totalRecords,totalCups,favCategory,categoryVariety,) { this.weekDrinkCount = weekDrinkCount; this.weekCups = weekCups; this.monthDrinkCount = monthDrinkCount; this.monthCups = monthCups; this.streak = streak; this.streakType = streakType; this.totalDays = totalDays; this.totalRecords = totalRecords; this.totalCups = totalCups; this.favCategory = favCategory; this.categoryVariety = categoryVariety; } static fromObject(o) { return new StatsOverview(o.weekDrinkCount,o.weekCups,o.monthDrinkCount,o.monthCups,o.streak,o.streakType,o.totalDays,o.totalRecords,o.totalCups,o.favCategory,o.categoryVariety,); } } /** * 获取用户统计概览响应 */ export class GetStatsOverviewResp { /** * @param data: StatsOverview 统计概览数据 */ constructor(data,) { this.data = data; } static fromObject(o) { return new GetStatsOverviewResp(o.data,); } } /** * 获取月度统计请求 */ export class GetMonthlyStatsReq { /** * @param year: number 年份,默认当前年 * @param month: number 月份,默认当前月 */ constructor(year,month,) { this.year = year; this.month = month; } static fromObject(o) { return new GetMonthlyStatsReq(o.year,o.month,); } } /** * 月度统计数据 */ export class MonthlyStats { /** * @param year: number 年份 * @param month: number 月份 * @param drinkDays: number 饮酒天数 * @param abstainDays: number 戒酒天数 * @param totalCups: number 总标准杯数 * @param avgCupsPerDay: number 日均标准杯数 * @param categoryBreakdown: Array 酒类分布 * @param feelingBreakdown: Array 感受分布 * @param foodBreakdown: Array 配餐分布 */ constructor(year,month,drinkDays,abstainDays,totalCups,avgCupsPerDay,categoryBreakdown,feelingBreakdown,foodBreakdown,) { this.year = year; this.month = month; this.drinkDays = drinkDays; this.abstainDays = abstainDays; this.totalCups = totalCups; this.avgCupsPerDay = avgCupsPerDay; this.categoryBreakdown = categoryBreakdown; this.feelingBreakdown = feelingBreakdown; this.foodBreakdown = foodBreakdown; } static fromObject(o) { return new MonthlyStats(o.year,o.month,o.drinkDays,o.abstainDays,o.totalCups,o.avgCupsPerDay,o.categoryBreakdown,o.feelingBreakdown,o.foodBreakdown,); } } /** * 酒类分布统计项 */ export class CategoryBreakdown { /** * @param category: Category 酒类分类 * @param count: number 次数 * @param cups: number 标准杯数 */ constructor(category,count,cups,) { this.category = category; this.count = count; this.cups = cups; } static fromObject(o) { return new CategoryBreakdown(o.category,o.count,o.cups,); } } /** * 感受分布统计项 */ export class FeelingBreakdown { /** * @param feeling: Feeling 感受类型 * @param count: number 次数 */ constructor(feeling,count,) { this.feeling = feeling; this.count = count; } static fromObject(o) { return new FeelingBreakdown(o.feeling,o.count,); } } /** * 配餐分布统计项 */ export class FoodBreakdown { /** * @param category: FoodCategory 配餐分类 * @param count: number 次数 */ constructor(category,count,) { this.category = category; this.count = count; } static fromObject(o) { return new FoodBreakdown(o.category,o.count,); } } /** * 获取月度统计响应 */ export class GetMonthlyStatsResp { /** * @param data: MonthlyStats 月度统计数据 */ constructor(data,) { this.data = data; } static fromObject(o) { return new GetMonthlyStatsResp(o.data,); } } /** * 酒类分布统计项 */ export class CategoryStats { /** * @param id: Category 酒类分类ID * @param name: string 酒类名称 * @param recordCount: number 记录次数 * @param totalCups: number 总标准杯数 * @param percentage: number 占比(百分比) */ constructor(id,name,recordCount,totalCups,percentage,) { this.id = id; this.name = name; this.recordCount = recordCount; this.totalCups = totalCups; this.percentage = percentage; } static fromObject(o) { return new CategoryStats(o.id,o.name,o.recordCount,o.totalCups,o.percentage,); } } /** * */ export class GetStatsOverviewReq { /** */ constructor() { } static fromObject(o) { return new GetStatsOverviewReq(); } } /** * */ export class GetCategoryStatsReq { /** */ constructor() { } static fromObject(o) { return new GetCategoryStatsReq(); } } /** * 获取酒类分布统计响应 */ export class GetCategoryStatsResp { /** * @param data: CategoryStatsData 酒类分布统计数据 */ constructor(data,) { this.data = data; } static fromObject(o) { return new GetCategoryStatsResp(o.data,); } } /** * 酒类分布统计数据 */ export class CategoryStatsData { /** * @param categories: Array 酒类分布列表 */ constructor(categories,) { this.categories = categories; } static fromObject(o) { return new CategoryStatsData(o.categories,); } } /** * 用户信息 */ export class User { /** * @param id: string|number 用户ID * @param nickname: string 用户昵称 * @param avatar: string 头像URL * @param joinedAt: string 加入时间 * @param preferences: UserPreferences 用户偏好 */ constructor(id,nickname,avatar,joinedAt,preferences,) { this.id = id; this.nickname = nickname; this.avatar = avatar; this.joinedAt = joinedAt; this.preferences = preferences; } static fromObject(o) { return new User(o.id,o.nickname,o.avatar,o.joinedAt,o.preferences,); } } /** * 用户偏好设置 */ export class UserPreferences { /** * @param favoriteCategories: Array 偏好酒类ID列表 * @param frequency: Frequency 饮酒频率 */ constructor(favoriteCategories,frequency,) { this.favoriteCategories = favoriteCategories; this.frequency = frequency; } static fromObject(o) { return new UserPreferences(o.favoriteCategories,o.frequency,); } } /** * 获取用户信息请求 */ export class GetUserProfileReq { /** */ constructor() { } static fromObject(o) { return new GetUserProfileReq(); } } /** * 获取用户信息响应 */ export class GetUserProfileResp { /** * @param id: string|number 用户ID * @param nickname: string 用户昵称 * @param avatar: string 头像URL * @param joinedAt: string 加入时间 * @param preferences: UserPreferences 用户偏好 */ constructor(id,nickname,avatar,joinedAt,preferences,) { this.id = id; this.nickname = nickname; this.avatar = avatar; this.joinedAt = joinedAt; this.preferences = preferences; } static fromObject(o) { return new GetUserProfileResp(o.id,o.nickname,o.avatar,o.joinedAt,o.preferences,); } } /** * 更新用户偏好请求 */ export class UpdatePreferencesReq { /** * @param favoriteCategories: Array 偏好酒类ID列表 * @param frequency: Frequency 饮酒频率 */ constructor(favoriteCategories,frequency,) { this.favoriteCategories = favoriteCategories; this.frequency = frequency; } static fromObject(o) { return new UpdatePreferencesReq(o.favoriteCategories,o.frequency,); } } /** * 更新用户偏好响应 */ export class UpdatePreferencesResp { /** * @param favoriteCategories: Array 偏好酒类ID列表 * @param frequency: Frequency 饮酒频率 */ constructor(favoriteCategories,frequency,) { this.favoriteCategories = favoriteCategories; this.frequency = frequency; } static fromObject(o) { return new UpdatePreferencesResp(o.favoriteCategories,o.frequency,); } } /** * 上传图片参数 */ export class UploadImageReq { /** * @param image: any 图片 */ constructor(image,) { this.image = image; } static fromObject(o) { return new UploadImageReq(o.image,); } } /** * 上传图片返回 */ export class UploadImageResp { /** * @param id: string|number 图片 id * @param url: string 图片 url */ constructor(id,url,) { this.id = id; this.url = url; } static fromObject(o) { return new UploadImageResp(o.id,o.url,); } } /** * 引用文件参数 */ export class ReferenceFileReq { /** * @param project: string 项目名称 * @param module: string 模块名称 * @param data: number 数据 id * @param urls: Array 文件 urls */ constructor(project,module,data,urls,) { this.project = project; this.module = module; this.data = data; this.urls = urls; } static fromObject(o) { return new ReferenceFileReq(o.project,o.module,o.data,o.urls,); } } /** * 引用文件返回 */ export class ReferenceFileResp { /** * @param ok: boolean 是否成功 */ constructor(ok,) { this.ok = ok; } static fromObject(o) { return new ReferenceFileResp(o.ok,); } } /** * 取消引用文件参数 */ export class DereferenceFileReq { /** * @param module: string 模块 * @param data: number 数据 id * @param urls: Array 文件 urls */ constructor(module,data,urls,) { this.module = module; this.data = data; this.urls = urls; } static fromObject(o) { return new DereferenceFileReq(o.module,o.data,o.urls,); } } /** * 取消引用文件返回 */ export class DereferenceFileResp { /** * @param ok: boolean 是否成功 */ constructor(ok,) { this.ok = ok; } static fromObject(o) { return new DereferenceFileResp(o.ok,); } } /** * 删除数据参数 */ export class DeleteDataReq { /** * @param module: string 模块 * @param data: number 数据 id */ constructor(module,data,) { this.module = module; this.data = data; } static fromObject(o) { return new DeleteDataReq(o.module,o.data,); } } /** * 删除数据返回 */ export class DeleteDataResp { /** * @param ok: boolean 是否成功 */ constructor(ok,) { this.ok = ok; } static fromObject(o) { return new DeleteDataResp(o.ok,); } } /** * * 喝酒了么 - 后端接口 API * 小程序:喝酒了么(uni-app 微信小程序) * 基础URL: /api/v1 * * 主要功能模块: * 1. 用户模块 - 微信登录、用户信息管理 * 2. 打卡记录模块 - 饮酒记录创建、查询、日历数据 * 3. 照片上传模块 - 单张/批量照片上传 * 4. 统计模块 - 用户统计、月度统计、酒类分布 * 5. 成就模块 - 成就列表和进度 * 6. 社交模块 - 朋友圈动态、点赞 */ export default class HaveADrink { constructor(conf) { this.host = conf.host; this.http_request = conf.http_request; this.upload = conf.upload; this.token = conf.token; } /** * 设置 token */ setToken(token) { this.token = token; } /** * 微信登录, 获取openid、unionid、token */ WechatLogin(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/auth/wechat/login`; this.http_request(url, { uri: '/api/have_a_drink/v1/auth/wechat/login', method: 'POST', data: data, responseType: 'json', headers: { 'Content-Type': 'application/json', }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 获取微信手机号 */ WechatGetPhoneNumber(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/auth/wechat/get_phone_number`; this.http_request(url, { uri: '/api/have_a_drink/v1/auth/wechat/get_phone_number', method: 'POST', data: data, responseType: 'json', headers: { 'Content-Type': 'application/json', }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 刷新 token 接口 */ RefreshToken(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/auth/refresh_token`; this.http_request(url, { uri: '/api/have_a_drink/v1/auth/refresh_token', method: 'POST', data: data, responseType: 'json', headers: { 'Content-Type': 'application/json', }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 获取成就列表 */ GetAchievements(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/achievements/list`; const query = Object.keys(data).map((x)=>(`${x}=${data[x]}`)).join('&'); this.http_request(url, { uri: '/api/have_a_drink/v1/achievements/list', method: 'GET', query: query, data: data, responseType: 'json', headers: { }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 获取朋友圈动态 */ GetFeed(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/communication/feed`; const query = Object.keys(data).map((x)=>(`${x}=${data[x]}`)).join('&'); this.http_request(url, { uri: '/api/have_a_drink/v1/communication/feed', method: 'GET', query: query, data: data, responseType: 'json', headers: { }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 点赞 */ LikeRecord(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/communication/records/like`; this.http_request(url, { uri: '/api/have_a_drink/v1/communication/records/like', method: 'POST', data: data, responseType: 'json', headers: { 'Content-Type': 'application/json', }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 取消点赞 */ UnlikeRecord(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/communication/records/unlike`; this.http_request(url, { uri: '/api/have_a_drink/v1/communication/records/unlike', method: 'POST', data: data, responseType: 'json', headers: { 'Content-Type': 'application/json', }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 上传照片 */ UploadPhoto(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/photo/upload/photo`; this.http_request(url, { uri: '/api/have_a_drink/v1/photo/upload/photo', method: 'POST', data: data, responseType: 'json', headers: { 'Content-Type': 'application/json', }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 批量上传照片 */ UploadPhotos(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/photo/upload/photos`; this.http_request(url, { uri: '/api/have_a_drink/v1/photo/upload/photos', method: 'POST', data: data, responseType: 'json', headers: { 'Content-Type': 'application/json', }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 创建打卡记录 */ CreateRecord(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/record/records`; this.http_request(url, { uri: '/api/have_a_drink/v1/record/records', method: 'POST', data: data, responseType: 'json', headers: { 'Content-Type': 'application/json', }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 获取记录列表 */ GetRecords(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/record/records`; const query = Object.keys(data).map((x)=>(`${x}=${data[x]}`)).join('&'); this.http_request(url, { uri: '/api/have_a_drink/v1/record/records', method: 'GET', query: query, data: data, responseType: 'json', headers: { }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 获取单条记录详情 */ GetRecordDetail(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/record/records/detail`; const query = Object.keys(data).map((x)=>(`${x}=${data[x]}`)).join('&'); this.http_request(url, { uri: '/api/have_a_drink/v1/record/records/detail', method: 'GET', query: query, data: data, responseType: 'json', headers: { }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 删除记录 */ DeleteRecord(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/record/records`; this.http_request(url, { uri: '/api/have_a_drink/v1/record/records', method: 'DELETE', data: data, responseType: 'json', headers: { 'Content-Type': 'application/json', }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 获取日历打卡数据 */ GetCalendar(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/record/records/calendar`; const query = Object.keys(data).map((x)=>(`${x}=${data[x]}`)).join('&'); this.http_request(url, { uri: '/api/have_a_drink/v1/record/records/calendar', method: 'GET', query: query, data: data, responseType: 'json', headers: { }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 获取用户统计概览 */ GetStatsOverview(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/statistics/overview`; const query = Object.keys(data).map((x)=>(`${x}=${data[x]}`)).join('&'); this.http_request(url, { uri: '/api/have_a_drink/v1/statistics/overview', method: 'GET', query: query, data: data, responseType: 'json', headers: { }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 获取月度统计 */ GetMonthlyStats(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/statistics/monthly`; const query = Object.keys(data).map((x)=>(`${x}=${data[x]}`)).join('&'); this.http_request(url, { uri: '/api/have_a_drink/v1/statistics/monthly', method: 'GET', query: query, data: data, responseType: 'json', headers: { }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 获取酒类分布统计 */ GetCategoryStats(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/statistics/categories`; const query = Object.keys(data).map((x)=>(`${x}=${data[x]}`)).join('&'); this.http_request(url, { uri: '/api/have_a_drink/v1/statistics/categories', method: 'GET', query: query, data: data, responseType: 'json', headers: { }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 获取用户信息 */ GetUserProfile(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/user/user/profile`; const query = Object.keys(data).map((x)=>(`${x}=${data[x]}`)).join('&'); this.http_request(url, { uri: '/api/have_a_drink/v1/user/user/profile', method: 'GET', query: query, data: data, responseType: 'json', headers: { }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 更新用户偏好 */ UpdatePreferences(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/user/user/preferences`; this.http_request(url, { uri: '/api/have_a_drink/v1/user/user/preferences', method: 'PUT', data: data, responseType: 'json', headers: { 'Content-Type': 'application/json', }, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data); } }).catch((err)=>reject(err)); }); } /** * 上传文件 */ UploadImage(req) { return new Promise((reslove, reject)=>{ let data = req; let url = `${this.host}/api/have_a_drink/v1/upload/image`; this.upload(url, { uri: '/api/have_a_drink/v1/upload/image', method: 'POST', data: data, }).then((data)=>{ if (data.hasOwnProperty("fail")) { if (data.fail) { reject(data.msg); } else { reslove(data.data); } } else { reslove(data.data); } }).catch((err)=>reject(err)); }); } }