获取可聊天的技师数据
This commit is contained in:
@@ -97,6 +97,21 @@ export class GirlChatData extends BaseData {
|
||||
}
|
||||
}
|
||||
|
||||
/** 是否可聊天 */
|
||||
public isCanChat(): boolean {
|
||||
// 剩余聊天次数
|
||||
let remainCount = this.chatRemainCount;
|
||||
if (remainCount < 0) {
|
||||
// 会员
|
||||
return true;
|
||||
} else if (remainCount === 0) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 解析聊天记录数据,一个
|
||||
private parseOneChatRecord(data: proto.cs.IChatMsg): proto.cs.IChatMsg | null {
|
||||
if (!data) return null;
|
||||
@@ -143,7 +158,6 @@ export class GirlChatData extends BaseData {
|
||||
|
||||
// 排序:根据 msgId 从大到小排序
|
||||
this.chatRecordIds.sort((a, b) => b - a);
|
||||
|
||||
logger.log("当前技师 ", this.id, " ,聊天记录:", this.chatRecord);
|
||||
}
|
||||
|
||||
@@ -152,6 +166,19 @@ export class GirlChatData extends BaseData {
|
||||
return this.chatRecordIds;
|
||||
}
|
||||
|
||||
/** 获取最新的聊天记录的id */
|
||||
public getLatestChatRecordId(): number | null {
|
||||
if (this.chatRecordIds.length === 0) return null;
|
||||
return this.chatRecordIds[0];
|
||||
}
|
||||
|
||||
/** 获取最新的聊天记录的时间戳(毫秒) */
|
||||
public getLatestChatRecordTimestamp(): number | null {
|
||||
if (this.chatRecordIds.length === 0) return null;
|
||||
// 最新一条的 msgId 本身就是时间戳(毫秒)
|
||||
return this.chatRecordIds[0];
|
||||
}
|
||||
|
||||
/** 获取聊天记录,根据 id */
|
||||
private getChatRecordById(id: number): proto.cs.IChatMsg | null {
|
||||
return this.chatRecord.get(id.toString()) ?? null;
|
||||
|
||||
@@ -112,6 +112,23 @@ export class GirlData extends BaseData {
|
||||
logger.log("保存类别 ", categoryId, " 的详细数据: ", bucket);
|
||||
}
|
||||
|
||||
/** 保存可聊天的技师数据 */
|
||||
public setCanChatGirlData(data: proto.cs.ICSGetLastChatListRes): void {
|
||||
if (!data) return;
|
||||
let canChatList = data.LastChatList;
|
||||
// 遍历
|
||||
for (const oneData of canChatList) {
|
||||
let briefData = oneData.girl;
|
||||
let categoryId = briefData.category;
|
||||
this.mergeOneBrief(categoryId.toString(), briefData);
|
||||
this.refreshGirlUnlock(oneData);
|
||||
this.refreshGirlFavorability(oneData);
|
||||
this.refreshGirlChat(oneData);
|
||||
}
|
||||
const cats = this.ensureCategories();
|
||||
logger.log("保存可聊天的技师数据: ", cats);
|
||||
}
|
||||
|
||||
/** --------------------------------------------------------- 技师的简要数据 --------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
@@ -649,30 +666,41 @@ export class GirlData extends BaseData {
|
||||
|
||||
/** --------------------------------------------------------- 技师的解锁数据 --------------------------------------------------------- */
|
||||
|
||||
// 解析技师解锁数据,一个
|
||||
private parseOneGirlUnlock(data: proto.cs.IGirlData): GirlUnlockData | null {
|
||||
if (!data) return null;
|
||||
// 创建一个技师解锁数据
|
||||
private createOneGirlUnlock(id: number, isRelease: boolean, unlockTime: number, unlockedImageIds: number[], unlockedVideoIds: number[]): GirlUnlockData {
|
||||
let oneData = new GirlUnlockData();
|
||||
oneData.init?.(DataId.GirlUnlock);
|
||||
oneData.setId(data.id);
|
||||
oneData.setIsRelease(data.isRelease);
|
||||
if (data.images) {
|
||||
let ids = [];
|
||||
for (let one of data.images) {
|
||||
ids.push(one.resId);
|
||||
}
|
||||
oneData.setUnlockedImageIds(ids);
|
||||
oneData.setId(id);
|
||||
oneData.setIsRelease(isRelease);
|
||||
oneData.setUnlockTime(unlockTime);
|
||||
if (unlockedImageIds) {
|
||||
oneData.setUnlockedImageIds(unlockedImageIds);
|
||||
}
|
||||
if (data.videos) {
|
||||
let ids = [];
|
||||
for (let one of data.videos) {
|
||||
ids.push(one.resId);
|
||||
}
|
||||
oneData.setUnlockedVideoIds(ids);
|
||||
if (unlockedVideoIds) {
|
||||
oneData.setUnlockedVideoIds(unlockedVideoIds);
|
||||
}
|
||||
return oneData;
|
||||
}
|
||||
|
||||
// 解析技师解锁数据,一个
|
||||
private parseOneGirlUnlock(data: proto.cs.IGirlData): GirlUnlockData | null {
|
||||
if (!data) return null;
|
||||
let unlockedImageIds = [];
|
||||
if (data.images) {
|
||||
for (let one of data.images) {
|
||||
unlockedImageIds.push(one.resId);
|
||||
}
|
||||
}
|
||||
let unlockedVideoIds = [];
|
||||
if (data.videos) {
|
||||
for (let one of data.videos) {
|
||||
unlockedVideoIds.push(one.resId);
|
||||
}
|
||||
}
|
||||
let oneData = this.createOneGirlUnlock(data.id, data.isRelease, Number(data.unlockTime), unlockedImageIds, unlockedVideoIds);
|
||||
return oneData;
|
||||
}
|
||||
|
||||
/** 保存技师的解锁数据 */
|
||||
private setGirlUnlock(categoryId: string, data: proto.cs.IGirlData[]): void {
|
||||
if (!data) return;
|
||||
@@ -684,6 +712,27 @@ export class GirlData extends BaseData {
|
||||
}
|
||||
}
|
||||
|
||||
/** 刷新技师的解锁数据 */
|
||||
private refreshGirlUnlock(data: proto.cs.ILastChatData): void {
|
||||
if (!data) return;
|
||||
let briefData = data.girl;
|
||||
let categoryId = briefData.category;
|
||||
let girlId = briefData.id;
|
||||
let unlockData = this.getGrilUnlock(categoryId.toString(), girlId);
|
||||
if (unlockData) {
|
||||
// 已存在数据,刷新
|
||||
unlockData.setIsRelease(data.isRelease);
|
||||
unlockData.setUnlockTime(Number(data.unlockTime));
|
||||
} else {
|
||||
// 不存在数据,创建
|
||||
const bucket = this.ensureBucket(categoryId.toString());
|
||||
let oneData = this.createOneGirlUnlock(data.id, data.isRelease, Number(data.unlockTime), [], []);
|
||||
if (oneData) {
|
||||
bucket.unlocks.set(data.id, oneData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 取某分类 + girlId 的解锁数据 */
|
||||
private getGrilUnlock(
|
||||
categoryId: string,
|
||||
@@ -719,6 +768,20 @@ export class GirlData extends BaseData {
|
||||
oneData.setIsRelease(value);
|
||||
}
|
||||
|
||||
/** 获取 角色解锁时间,时间戳,秒 */
|
||||
public getUnlockTime(categoryId: string, girlId: number): number {
|
||||
let oneData = this.getGrilUnlock(categoryId, girlId);
|
||||
if (!oneData) return 0;
|
||||
return oneData.getUnlockTime();
|
||||
}
|
||||
|
||||
/** 保存 角色解锁时间,时间戳,秒 */
|
||||
public setUnlockTime(categoryId: string, girlId: number, value: number): void {
|
||||
let oneData = this.getGrilUnlock(categoryId, girlId);
|
||||
if (!oneData) return;
|
||||
oneData.setUnlockTime(value);
|
||||
}
|
||||
|
||||
/** 判断图片是否解锁 */
|
||||
public isImageUnlock(
|
||||
categoryId: string,
|
||||
@@ -787,14 +850,20 @@ export class GirlData extends BaseData {
|
||||
|
||||
/** --------------------------------------------------------- 技师的聊天数据 --------------------------------------------------------- */
|
||||
|
||||
// 创建一个技师聊天数据
|
||||
private createOneGirlChat(id: number, chatTotalCount: number, chatRemainCount: number): GirlChatData {
|
||||
let oneData = new GirlChatData();
|
||||
oneData.init?.(DataId.GirlChat);
|
||||
oneData.setId(id);
|
||||
oneData.setChatTotalCount(chatTotalCount);
|
||||
oneData.setChatRemainCount(chatRemainCount);
|
||||
return oneData;
|
||||
}
|
||||
|
||||
// 解析技师聊天数据,一个
|
||||
private parseOneGirlChat(data: proto.cs.IGirlData): GirlChatData | null {
|
||||
if (!data) return null;
|
||||
let oneData = new GirlChatData();
|
||||
oneData.init?.(DataId.GirlChat);
|
||||
oneData.setId(data.id);
|
||||
oneData.setChatTotalCount(data.chatTotalCount);
|
||||
oneData.setChatRemainCount(data.chatRemainCount);
|
||||
let oneData = this.createOneGirlChat(data.id, data.chatTotalCount, data.chatRemainCount);
|
||||
return oneData;
|
||||
}
|
||||
|
||||
@@ -809,6 +878,29 @@ export class GirlData extends BaseData {
|
||||
}
|
||||
}
|
||||
|
||||
/** 刷新技师的聊天数据 */
|
||||
private refreshGirlChat(data: proto.cs.ILastChatData): void {
|
||||
if (!data) return;
|
||||
let briefData = data.girl;
|
||||
let categoryId = briefData.category;
|
||||
let girlId = briefData.id;
|
||||
let chatData = this.getGrilChat(categoryId.toString(), girlId);
|
||||
if (chatData) {
|
||||
// 已存在数据,刷新
|
||||
chatData.setChatTotalCount(data.chatTotalCount);
|
||||
chatData.setChatRemainCount(data.chatRemainCount);
|
||||
chatData.setChatRecord(data.msgs);
|
||||
} else {
|
||||
// 不存在数据,创建
|
||||
const bucket = this.ensureBucket(categoryId.toString());
|
||||
let oneData = this.createOneGirlChat(data.id, data.chatTotalCount, data.chatRemainCount);
|
||||
if (oneData) {
|
||||
oneData.setChatRecord(data.msgs);
|
||||
bucket.chats.set(data.id, oneData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 取某分类 + girlId 的聊天数据 */
|
||||
private getGrilChat(categoryId: string, girlId: number): GirlChatData | null {
|
||||
const b = this.ensureCategories().get(categoryId);
|
||||
@@ -868,17 +960,9 @@ export class GirlData extends BaseData {
|
||||
|
||||
/** 是否可聊天 */
|
||||
public isCanChat(categoryId: string, girlId: number): boolean {
|
||||
// 剩余聊天次数
|
||||
let remainCount = this.getChatRemainCount(categoryId, girlId);
|
||||
if (remainCount < 0) {
|
||||
// 会员
|
||||
return true;
|
||||
} else if (remainCount === 0) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
let oneData = this.getGrilChat(categoryId, girlId);
|
||||
if (!oneData) return false;
|
||||
return oneData.isCanChat();
|
||||
}
|
||||
|
||||
/** 保存聊天记录 */
|
||||
@@ -895,6 +979,20 @@ export class GirlData extends BaseData {
|
||||
return oneData.getChatRecordIds();
|
||||
}
|
||||
|
||||
/** 获取最新的聊天记录的id */
|
||||
public getLatestChatRecordId(categoryId: string, girlId: number): number | null {
|
||||
let oneData = this.getGrilChat(categoryId, girlId);
|
||||
if (!oneData) return null;
|
||||
return oneData.getLatestChatRecordId();
|
||||
}
|
||||
|
||||
/** 获取最新的聊天记录的时间戳(毫秒) */
|
||||
public getLatestChatRecordTimestamp(categoryId: string, girlId: number): number | null {
|
||||
let oneData = this.getGrilChat(categoryId, girlId);
|
||||
if (!oneData) return null;
|
||||
return oneData.getLatestChatRecordTimestamp();
|
||||
}
|
||||
|
||||
/** 获取聊天记录,根据 id,是否是 ai 聊天数据 */
|
||||
public getChatRecordIsAi(categoryId: string, girlId: number, id: number): boolean {
|
||||
let oneData = this.getGrilChat(categoryId, girlId);
|
||||
@@ -907,27 +1005,48 @@ export class GirlData extends BaseData {
|
||||
let oneData = this.getGrilChat(categoryId, girlId);
|
||||
if (!oneData) return "";
|
||||
return oneData.getChatRecordMsg(id);
|
||||
}
|
||||
}
|
||||
|
||||
/** 获取所有可聊天的技师 id */
|
||||
public getAllCanChatGirlIds(): number[] {
|
||||
const result: number[] = [];
|
||||
const cats = this.ensureCategories();
|
||||
|
||||
for (const [categoryId, bucket] of cats.entries()) {
|
||||
for (const girlId of bucket.girlIds) {
|
||||
|
||||
|
||||
|
||||
|
||||
if (this.getIsRelease(categoryId, girlId)) {
|
||||
result.push(girlId);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 返回结果
|
||||
return result;
|
||||
}
|
||||
|
||||
/** --------------------------------------------------------- 技师的好感度数据 --------------------------------------------------------- */
|
||||
|
||||
// 解析技师好感度数据,一个
|
||||
private parseOneGirlFavorability(
|
||||
data: proto.cs.IGirlData
|
||||
): GirlFavorabilityData | null {
|
||||
if (!data) return null;
|
||||
// 创建一个技师好感度数据
|
||||
private createOneGirlFavorability(id: number, star: number): GirlFavorabilityData {
|
||||
let oneData = new GirlFavorabilityData();
|
||||
oneData.init?.(DataId.GirlFavorability);
|
||||
oneData.setId(data.id);
|
||||
oneData.setStar(data.star);
|
||||
oneData.setId(id);
|
||||
oneData.setStar(star);
|
||||
return oneData;
|
||||
}
|
||||
|
||||
// 解析技师好感度数据,一个
|
||||
private parseOneGirlFavorability(data: proto.cs.IGirlData): GirlFavorabilityData | null {
|
||||
if (!data) return null;
|
||||
let oneData = this.createOneGirlFavorability(data.id, data.star);
|
||||
return oneData;
|
||||
}
|
||||
|
||||
/** 保存技师的好感度数据 */
|
||||
private setGirlFavorability(
|
||||
categoryId: string,
|
||||
data: proto.cs.IGirlData[]
|
||||
): void {
|
||||
private setGirlFavorability(categoryId: string,data: proto.cs.IGirlData[]): void {
|
||||
if (!data) return;
|
||||
const bucket = this.ensureBucket(categoryId);
|
||||
for (const g of data) {
|
||||
@@ -937,11 +1056,28 @@ export class GirlData extends BaseData {
|
||||
}
|
||||
}
|
||||
|
||||
/** 刷新技师的好感度数据 */
|
||||
private refreshGirlFavorability(data: proto.cs.ILastChatData): void {
|
||||
if (!data) return;
|
||||
let briefData = data.girl;
|
||||
let categoryId = briefData.category;
|
||||
let girlId = briefData.id;
|
||||
let favData = this.getGrilFavorability(categoryId.toString(), girlId);
|
||||
if (favData) {
|
||||
// 已存在数据,刷新
|
||||
favData.setStar(data.star);
|
||||
} else {
|
||||
// 不存在数据,创建
|
||||
const bucket = this.ensureBucket(categoryId.toString());
|
||||
let oneData = this.createOneGirlFavorability(data.id, data.star);
|
||||
if (oneData) {
|
||||
bucket.favorability.set(data.id, oneData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 取某分类 + girlId 的好感度数据 */
|
||||
private getGrilFavorability(
|
||||
categoryId: string,
|
||||
girlId: number
|
||||
): GirlFavorabilityData | null {
|
||||
private getGrilFavorability(categoryId: string,girlId: number): GirlFavorabilityData | null {
|
||||
const b = this.ensureCategories().get(categoryId);
|
||||
if (!b) return null;
|
||||
return b.favorability.get(girlId) ?? null;
|
||||
|
||||
@@ -9,7 +9,9 @@ export class GirlUnlockData extends BaseData {
|
||||
// id
|
||||
private id: number;
|
||||
// 付费技师是否已经解锁
|
||||
private isRelease: boolean;
|
||||
private isRelease: boolean;
|
||||
// 角色解锁时间,时间戳,秒
|
||||
private unlockTime: number;
|
||||
// 解锁图片 id
|
||||
private unlockedImageIds: number[];
|
||||
// 解锁视频 id
|
||||
@@ -19,6 +21,7 @@ export class GirlUnlockData extends BaseData {
|
||||
super();
|
||||
this.id = 0;
|
||||
this.isRelease = false;
|
||||
this.unlockTime = 0;
|
||||
this.unlockedImageIds = [];
|
||||
this.unlockedVideoIds = [];
|
||||
}
|
||||
@@ -26,6 +29,7 @@ export class GirlUnlockData extends BaseData {
|
||||
public reset(): void {
|
||||
this.id = 0;
|
||||
this.isRelease = false;
|
||||
this.unlockTime = 0;
|
||||
this.unlockedImageIds = [];
|
||||
this.unlockedVideoIds = [];
|
||||
}
|
||||
@@ -33,6 +37,7 @@ export class GirlUnlockData extends BaseData {
|
||||
public clear(): void {
|
||||
this.id = 0;
|
||||
this.isRelease = false;
|
||||
this.unlockTime = 0;
|
||||
this.unlockedImageIds = [];
|
||||
this.unlockedVideoIds = [];
|
||||
}
|
||||
@@ -41,6 +46,7 @@ export class GirlUnlockData extends BaseData {
|
||||
super.destroy();
|
||||
this.id = null;
|
||||
this.isRelease = null;
|
||||
this.unlockTime = null;
|
||||
this.unlockedImageIds = null;
|
||||
this.unlockedVideoIds = null;
|
||||
}
|
||||
@@ -65,6 +71,17 @@ export class GirlUnlockData extends BaseData {
|
||||
this.isRelease = value;
|
||||
}
|
||||
|
||||
/** 获取 角色解锁时间,时间戳,秒 */
|
||||
public getUnlockTime(): number {
|
||||
return this.unlockTime;
|
||||
}
|
||||
|
||||
/** 保存 角色解锁时间,时间戳,秒 */
|
||||
public setUnlockTime(value: number): void {
|
||||
this.unlockTime = value;
|
||||
// logger.log("设置角色 ", this.id, " 的解锁时间:", this.unlockTime);
|
||||
}
|
||||
|
||||
/** 判断图片是否解锁,根据 id */
|
||||
public isImageUnlock(id: number): boolean {
|
||||
for (let i = 0; i < this.unlockedImageIds.length; i++) {
|
||||
|
||||
@@ -48,4 +48,9 @@ export class GirlService implements IGirlService {
|
||||
public async reqUnlockGirlRes(req: proto.cs.ICSUnlockResourceReq): Promise<ApiResponse<proto.cs.ICSUnlockResourceRes>> {
|
||||
return this.impl.reqUnlockGirlRes(req);
|
||||
}
|
||||
|
||||
// 获取可聊天的技师数据
|
||||
public async reqCanChatGirlData(req: proto.cs.ICSGetLastChatListReq): Promise<ApiResponse<proto.cs.ICSGetLastChatListRes>> {
|
||||
return this.impl.reqCanChatGirlData(req);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,4 +61,15 @@ export class HttpGirlService implements IGirlService {
|
||||
};
|
||||
return this.api.call(epData, req);
|
||||
}
|
||||
|
||||
// 获取可聊天的技师数据
|
||||
async reqCanChatGirlData(req: proto.cs.ICSGetLastChatListReq): Promise<ApiResponse<proto.cs.ICSGetLastChatListRes>> {
|
||||
let epData: Endpoint<proto.cs.ICSGetLastChatListReq, proto.cs.ICSGetLastChatListRes> = {
|
||||
path: "api/logic/getLastChat",
|
||||
method: "POST",
|
||||
codec: "json",
|
||||
needsAuth: true
|
||||
};
|
||||
return this.api.call(epData, req);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,6 @@ export interface IGirlService {
|
||||
reqUnlockGirl(req: proto.cs.ICSUnlockGirlReq): Promise<ApiResponse<proto.cs.ICSUnlockGirlRes>>;
|
||||
// 解锁资源
|
||||
reqUnlockGirlRes(req: proto.cs.ICSUnlockResourceReq): Promise<ApiResponse<proto.cs.ICSUnlockResourceRes>>;
|
||||
// 获取可聊天的技师数据
|
||||
reqCanChatGirlData(req: proto.cs.ICSGetLastChatListReq): Promise<ApiResponse<proto.cs.ICSGetLastChatListRes>>;
|
||||
}
|
||||
|
||||
@@ -300,5 +300,16 @@ export class MockGirlService implements IGirlService {
|
||||
vipExpire,
|
||||
};
|
||||
return this.ok(res);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取可聊天的技师数据
|
||||
async reqCanChatGirlData(req: proto.cs.ICSGetLastChatListReq): Promise<ApiResponse<proto.cs.ICSGetLastChatListRes>> {
|
||||
// TODO
|
||||
|
||||
// 返回数据
|
||||
const res: proto.cs.ICSGetLastChatListRes = {
|
||||
LastChatList: [],
|
||||
};
|
||||
return this.ok(res);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user