import type { ApiResponse } from "../client/types"; import proto from "db://assets/Scripts/proto/proto.pb.js"; import type { IGirlService } from "./IGirlService"; import { ConfigManager, ConfigId } from "../../manager/ConfigManager"; import { GirlConfig } from "../../config/GirlConfig"; import { GirlDetailConfig } from "../../config/GirlDetailConfig"; export class MockGirlService implements IGirlService { private delay(ms = 180) { return new Promise(r => setTimeout(r, ms)); } private randInt(min: number, max: number) { return Math.floor(Math.random() * (max - min + 1)) + min; } private ok(data: T): ApiResponse { return ({ code: proto.cs.EnmRetCode.SUCCESS, data } as unknown) as ApiResponse; } private err(message = "mock error"): ApiResponse { return ({ code: 100, error: { message } } as unknown) as ApiResponse; } private genBrief(id: number, name: string, age: number, tagKey: string, priceType: number, price: number, avatar: string, star: number): proto.cs.IGirlBrief { return { id, name, age, tagKey, priceType, price, avatar, star, }; } private genPhoto(pic: string, isRelease: boolean, price: number): proto.cs.IGirlPhoto { return { pic, isRelease, price, }; } private genDetail(brief: proto.cs.IGirlBrief, desc: string, photos: proto.cs.IGirlPhoto[], isRelease: boolean, chatCount: number): proto.cs.IGirlDetail { return { brief, desc, photos, isRelease, chatCount, }; } // 每日推荐 async reqDailyRecommend(_req: proto.cs.ICSDailyRecommendReq): Promise> { // 延时 await this.delay(180); // 配置数据 const configData = ConfigManager.I.getDataById(ConfigId.Girl); const allId = configData.getAllId(); const recId = allId[0]; let name = configData.getNameById(recId); let age = Number(configData.getAgeById(recId)); let tagKey = configData.getTagKeyById(recId); let priceType = configData.getPriceTypeById(recId); let price = 9.9; let avatar = configData.getAvatarPathById(recId); let star = 3; let oneData = this.genBrief(recId, name, age, tagKey, priceType, price, avatar, star); // 返回数据 const girls = [oneData]; return this.ok({ girls }); } // 获取技师列表 async reqGetGirlList(req: proto.cs.ICSGetGirlListReq): Promise> { // 延时 await this.delay(200); // 配置数据 const configData = ConfigManager.I.getDataById(ConfigId.Girl); const allId = configData.getAllId(); // 按 category 精确匹配 const category = Number(req?.category ?? -1); const filteredIds = category >= 0 ? allId.filter((id: number) => { const cat = Number(configData.getCategoryById(id) ?? -1); return cat === category; }) : allId; // 分页 const page = Math.max(1, Number(req?.page ?? 1)); const limit = Math.max(1, Math.min(Number(req?.limit ?? 10), 50)); const start = (page - 1) * limit; const pageIds = filteredIds.slice(start, start + limit); // 映射为 IGirlBrief const girls: proto.cs.IGirlBrief[] = pageIds.map((id: number) => { const name = configData.getNameById(id); const age = Number(configData.getAgeById(id)); const tagKey = configData.getTagKeyById(id); const priceType = Number(configData.getPriceTypeById(id)); const avatar = configData.getAvatarPathById(id); // 如果有价格配置,就用配置里的,否则给个兜底值 const price = typeof (configData as any).getPriceById === "function" ? Number((configData as any).getPriceById(id) ?? 9.9) : 9.9; // 星级兜底:1~5 const star = (id % 5) + 1; return this.genBrief(id, name, age, tagKey, priceType, price, avatar, star); }); // 返回数据 return this.ok({ girls }); } // 获取技师详细信息 async reqGetGirlDetail(req: proto.cs.ICSGetGirlDetailReq): Promise> { // 延时 await this.delay(160); // 配置数据 const girlConfig = ConfigManager.I.getDataById(ConfigId.Girl); const girlDetailConfig = ConfigManager.I.getDataById(ConfigId.GirlDetail); // id const girlId = req.id; let name = girlConfig.getNameById(girlId); let age = Number(girlConfig.getAgeById(girlId)); let tagKey = girlConfig.getTagKeyById(girlId); let priceType = girlConfig.getPriceTypeById(girlId); let price = 9.9; let avatar = girlConfig.getAvatarPathById(girlId); let star = 3; let briefData = this.genBrief(girlId, name, age, tagKey, priceType, price, avatar, star); let desc = girlDetailConfig.getDetailDescById(girlId); let isRelease = Math.random() < 0.4; let chatCount = 10; let photoData = []; let photoCount = girlDetailConfig.getCommercialImagesCount(girlId); for (let i = 0; i < photoCount; i++) { let imagePath = girlDetailConfig.getImagePathById(girlId, i); let isImageRelease = Math.random() < 0.4; let imagePrice = 9.9; let onePhotoData = this.genPhoto(imagePath, isImageRelease, imagePrice); photoData.push(onePhotoData); } let detail = this.genDetail(briefData, desc, photoData, isRelease, chatCount); return this.ok({ detail }); } }