技师数据修改
This commit is contained in:
@@ -14,11 +14,14 @@ interface CategoryBucket {
|
||||
girlIds: number[];
|
||||
}
|
||||
|
||||
// 每日推荐专用分类
|
||||
const DAILY_BUCKET = "__daily__";
|
||||
|
||||
export class GirlData extends BaseData {
|
||||
// 大分类
|
||||
private _categories = new Map<string, CategoryBucket>();
|
||||
// 列表索引
|
||||
private _dailyRecommend: number[] = [];
|
||||
// 每日推荐(存放在 DAILY_BUCKET 中,同时保留 id 索引便于 UI 使用)
|
||||
private _dailyRecommendIds: number[] = [];
|
||||
|
||||
public reset(): void {
|
||||
this._categories.clear();
|
||||
@@ -55,6 +58,23 @@ export class GirlData extends BaseData {
|
||||
}
|
||||
return bucket;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并一批简要信息到指定分类;并维护 girlIds 顺序(去重追加)
|
||||
*/
|
||||
public mergeBriefs(categoryId: string, respOrList: proto.cs.IGirlBrief[]): void {
|
||||
if (!respOrList) return;
|
||||
let allData = this.parseAllGirlBrief(respOrList);
|
||||
if (!allData) return;
|
||||
const bucket = this.ensureBucket(categoryId);
|
||||
for (const g of allData) {
|
||||
const id = g.id;
|
||||
bucket.briefs.set(id, g);
|
||||
// TODO,去重
|
||||
bucket.girlIds.push(id);
|
||||
}
|
||||
console.log("保存技师的简要数据: ", bucket);
|
||||
}
|
||||
|
||||
/** 取分类下的全部 girlIds(若分类不存在返回空数组) */
|
||||
public getGirlIds(categoryId: string): number[] {
|
||||
@@ -95,18 +115,7 @@ export class GirlData extends BaseData {
|
||||
|
||||
/** 保存技师的简要数据 */
|
||||
public setGirlBriefs(categoryId: string, data: proto.cs.ICSGetGirlListRes): void {
|
||||
let allData = this.parseAllGirlBrief(data.girls);
|
||||
if (!allData) return;
|
||||
const bucket = this.ensureBucket(categoryId);
|
||||
if (allData) {
|
||||
for (const g of allData) {
|
||||
const id = g.id;
|
||||
bucket.briefs.set(id, g);
|
||||
// TODO,去重
|
||||
bucket.girlIds.push(id);
|
||||
}
|
||||
}
|
||||
console.log("保存技师的简要数据: ", bucket);
|
||||
this.mergeBriefs(categoryId, data.girls);
|
||||
}
|
||||
|
||||
/** 取某分类 + girlId 的简要信息 */
|
||||
@@ -221,19 +230,17 @@ export class GirlData extends BaseData {
|
||||
|
||||
/** 保存技师的详细数据 */
|
||||
public setGirlDetails(categoryId: string, data: proto.cs.ICSGetGirlDetailRes): void {
|
||||
const d = this.parseOneGirlDetail(data.detail);
|
||||
const d = data?.detail;
|
||||
if (!d) return;
|
||||
// 合并简要信息
|
||||
if (d.brief) this.mergeBriefs(categoryId, [d.brief]);
|
||||
|
||||
const oneDetail = this.parseOneGirlDetail(d);
|
||||
const bucket = this.ensureBucket(categoryId);
|
||||
// id
|
||||
const id = d.brief?.id ?? 0;
|
||||
// 合并简要
|
||||
if (d.brief) {
|
||||
bucket.briefs.set(id, d.brief);
|
||||
// TODO,去重
|
||||
bucket.girlIds.push(id);
|
||||
}
|
||||
// 写入详情
|
||||
bucket.details.set(id, d);
|
||||
bucket.details.set(id, oneDetail);
|
||||
console.log("保存技师的详细数据: ", bucket);
|
||||
}
|
||||
|
||||
@@ -298,68 +305,24 @@ export class GirlData extends BaseData {
|
||||
|
||||
/** --------------------------------------------------------- 每日推荐 --------------------------------------------------------- */
|
||||
|
||||
|
||||
/** 每日推荐:只维护 id 索引,实体来自 _briefs */
|
||||
applyDailyRecommend(res: pb.cs.ICSDailyRecommendRes): void {
|
||||
const girls = res.girls ?? [];
|
||||
this.mergeBriefs(girls);
|
||||
this._dailyRecommend = girls.map(g => g.id!);
|
||||
/** 保存每日推荐:放入特殊分类 DAILY_BUCKET,并维护 id 索引 */
|
||||
public setDailyRecommend(res: proto.cs.ICSDailyRecommendRes): void {
|
||||
this.mergeBriefs(DAILY_BUCKET, res.girls);
|
||||
this._dailyRecommendIds = res.girls.map(g => g.id ?? 0);
|
||||
}
|
||||
|
||||
/** 分类分页列表:category + page -> id[] */
|
||||
applyGirlList(category: number, page: number, res: pb.cs.ICSGetGirlListRes): void {
|
||||
const girls = res.girls ?? [];
|
||||
this.mergeBriefs(girls);
|
||||
|
||||
if (!this._categoryPages.has(category)) {
|
||||
this._categoryPages.set(category, new Map());
|
||||
}
|
||||
const pages = this._categoryPages.get(category)!;
|
||||
pages.set(page, girls.map(g => g.id!));
|
||||
}
|
||||
|
||||
/** 详情:合并 brief + detail */
|
||||
applyGirlDetail(res: pb.cs.ICSGetGirlDetailRes): void {
|
||||
const d = res.detail!;
|
||||
const b = d.brief!;
|
||||
this.mergeBriefs([b]);
|
||||
|
||||
const vo: GirlDetailVO = {
|
||||
id: b.id!,
|
||||
desc: d.desc || "",
|
||||
isRelease: !!d.isRelease,
|
||||
chatCount: d.chatCount || 0,
|
||||
photos: (d.photos ?? []).map(p => ({
|
||||
pic: p.pic || "",
|
||||
isRelease: !!p.isRelease,
|
||||
price: p.price || 0,
|
||||
})),
|
||||
};
|
||||
this._details.set(vo.id, vo);
|
||||
}
|
||||
|
||||
/** 页面读取:根据分类+页获取 id 列表 */
|
||||
getPageIds(category: number, page: number): number[] {
|
||||
const pages = this._categoryPages.get(category);
|
||||
return pages?.get(page) ?? [];
|
||||
}
|
||||
|
||||
/** 本地变更:聊天次数变更(成功买次数后) */
|
||||
incChatCount(girlId: number, delta: number) {
|
||||
const d = this._details.get(girlId);
|
||||
if (d) d.chatCount = Math.max(0, d.chatCount + delta);
|
||||
}
|
||||
|
||||
/** 本地变更:解锁技师/照片(例如购买后或服务器回调) */
|
||||
setGirlReleased(girlId: number, v: boolean) {
|
||||
const d = this._details.get(girlId);
|
||||
if (d) d.isRelease = v;
|
||||
}
|
||||
setPhotoReleased(girlId: number, pic: string, v: boolean) {
|
||||
const d = this._details.get(girlId);
|
||||
if (!d) return;
|
||||
const p = d.photos.find(x => x.pic === pic);
|
||||
if (p) p.isRelease = v;
|
||||
}
|
||||
/** 获取每日推荐的简要信息 */
|
||||
private getRecommendGrilBrief(categoryId: string, index: number): proto.cs.IGirlBrief | null {
|
||||
const b = this.ensureCategories().get(categoryId);
|
||||
if (!b) return null;
|
||||
if (index < 0 || index >= b.girlIds.length) return null;
|
||||
return b.briefs.get(b.girlIds[index]) ?? null;
|
||||
}
|
||||
|
||||
/** 获取名字 */
|
||||
public getRecommendGrilName(index: number): string {
|
||||
let oneData = this.getRecommendGrilBrief(DAILY_BUCKET, index);
|
||||
if (!oneData) return "";
|
||||
return oneData.name;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user